//******************************************************************************
// ********************** DO NOT DELETE ****************************************
//
// COPYRIGHT NOTICE: Copyright 2001 Harris Susanto, ID 50496269.
//
// This code is not for non-commercial use. Any commercial usage or 
// duplication requires a licensing agreement from the author who may be 
// contacted at the following email address: harris78@yahoo.com
//
// The author assumes no responsibility for any damage caused by the 
// proper or inproper use of this code.
// 
// Revision History: Sep 17, 2001
// Revision History: Feb 25, 2004
//
// ********************** DO NOT DELETE ****************************************
//******************************************************************************

function validLength(item,len){
	return (item.length >= len);
}

function error(elem,text){
	if (errFound) return;
	window.alert(text);
	//elem.select();
	elem.focus();
	errFound = true;
}

function popup(pufile,puname,height,width,scrolls)
{
	var proto = location.protocol;
	var openerhost = location.host;
	var win=open(proto + pufile,puname,"resizable=no,height=" + height + ",width=" + width + ",scrollbars=" + scrolls);
	win.focus();
	win.resizeTo(width,height);
}
function popup_resize(pufile,puname,height,width,scrolls)
{
	var proto = location.protocol;
	var openerhost = location.host;
	var win=open(proto + pufile,puname,"resizable=yes,height=" + height + ",width=" + width + ",scrollbars=" + scrolls);
	win.focus();
	win.resizeTo(width,height);
}

function popup_ext(pufile,puname,height,width,scrolls)
{
	var win=open(pufile,puname,"resizable=yes,height=" + height + ",width=" + width + ",scrollbars=" + scrolls);
	win.focus();
	win.resizeTo(width,height);
}

function showPopUp(url,width,height,top,left){
	sHeight = screen.height;
	sWidth = screen.width
	var boxWidth, boxHeight, boxLeft, boxTop;
	boxWidth = width;
	boxHeight = height;
	boxLeft = (screen.width - boxWidth) / 2;
	boxTop = (screen.height - boxHeight) / 2;

	window.open(url,'_blank','height=boxHeight,width=' + boxWidth + ',top=' + boxTop + ',left=' + boxLeft + ',toolbars=0,statusbar=0,scrollbars=1,resizable=1',false); 
}
	
function validEmail(item){
	if (!validLength(item,5)) return false;
	if ((!validLength(item,2)) ||
	   (item.indexOf('@') == -1) || (item.indexOf('.') == -1 )) return false;
	return true;
}

function validExtention(item){
	posLastSlash = item.lastIndexOf("\\");
	filename = item.substring(posLastSlash+1, item.length);
	postLastDot = filename.lastIndexOf(".");
	extention = filename.substring(postLastDot, filename.length);
	return extention;	
}

function validContact(item){
	errFound = false;
	var i;
	
	if (!validLength(item.txtName.value,5)) 
		error(item.txtName,"Please type your name completely");
	if (!validEmail(item.txtEmail.value)) 
		error(item.txtEmail,"Please type your email correctly");		
	if (!validLength(item.txtAddress1.value,5)) 
		error(item.txtAddress1,"Please type your address completely");
		return !errFound;
}

function validSender(item){
	errFound = false;
	var i;
	
	if (!validLength(item.txtName.value,5)) 
		error(item.txtName,"Please type your name completely");
	if (!validEmail(item.txtEmail.value)) 
		error(item.txtEmail,"Please type your email correctly");		
	if (!validLength(item.txtEmail2.value,5)) 
		error(item.txtEmail2,"Please type your email completely");
		return !errFound;
}


function validLogin(item){
	errFound = false;
	var i;
	
	if (!validLength(item.txtUsername.value,5)) 
		error(item.txtUsername,"Please type your username completely");	
	if (!validLength(item.txtPassword.value,5)) 
		error(item.txtPassword,"Please type your password completely");
		return !errFound;
}

function validForum(item){
	errFound = false;
	var i;
	
	if (!validLength(item.txtTopic.value,10)) 
		error(item.txtTopic,"Please type your topic completely");	
	if (!validLength(item.txtIsi.value,10)) 
		error(item.txtIsi,"Please type your comments completely");
		return !errFound;
}

function validPost(item){
	errFound = false;
	var i;
	
	if (!validLength(item.txtIsi.value,10)) 
		error(item.txtIsi,"Please type your comments completely");
		return !errFound;
}

