function loginChk()
{
	var f = document.login;
	
	if(!trim(f.username.value))
	{
		alert("please enter your username!")
		f.username.focus();
		return false;
	}
	if(!trim(f.password.value))
	{
		alert("please enter your password!")
		f.password.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function forgotChk()
{
	var f = document.forgot;
	
	if(!trim(f.username.value))
	{
		alert("please enter your username!")
		f.username.focus();
		return false;
	}
	if(!trim(f.email.value))
	{
		alert("please enter your email!")
		f.email.focus();
		return false;
	}
	if(!is_email(f.email.value))
	{
		alert("please enter valid email!")
		f.email.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chnPassChk()
{
	var f = document.chnPass;
	

	if(!trim(f.old_pass.value))
	{
		alert("please enter your old password!")
		f.old_pass.focus();
		return false;
	}
	if(!trim(f.new_pass.value))
	{
		alert("please enter your new password!")
		f.new_pass.focus();
		return false;
	}
	if(!trim(f.re_new_pass.value))
	{
		alert("please enter confirm new password!")
		f.re_new_pass.focus();
		return false;
	}

	if(trim(f.new_pass.value) != trim(f.re_new_pass.value))
	{
		alert("password and confirm password must be same!")
		f.re_new_pass.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function contactChk()
{
	var f = document.contact;
	

	if(!trim(f.fname.value))
	{
		alert("please enter your first name!")
		f.fname.focus();
		return false;
	}
	if(!trim(f.lname.value))
	{
		alert("please enter your last name!")
		f.lname.focus();
		return false;
	}
	if(!trim(f.organization.value))
	{
		alert("please enter your organisation!")
		f.organization.focus();
		return false;
	}
	if(!trim(f.post_code.value))
	{
		alert("please enter your post code!")
		f.post_code.focus();
		return false;
	}
	if(!trim(f.telephone.value))
	{
		alert("please enter your telephone!")
		f.telephone.focus();
		return false;
	}
	if(!trim(f.email.value))
	{
		alert("please enter your email!")
		f.email.focus();
		return false;
	}
	if(!is_email(f.email.value))
	{
		alert("please enter valid email!")
		f.email.focus();
		return false;
	}
	if(!trim(f.comment.value))
	{
		alert("please enter your comments!")
		f.comment.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkDoc()
{
	var f = document.docCat;
	
	if(!trim(f.cat_id.value))
	{
		alert("please select a document category first")
		f.cat_id.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function trim(inputString) {
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring (0, 1);
    while (ch == " ") { 
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
    }
    ch = retValue.substring (retValue.length-1, retValue.length);
    while (ch == " ") { 
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1 , retValue.length);
    }
    while (retValue.indexOf("  ") != -1) { 
    retValue = retValue.substring(0, retValue.indexOf ("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
    }
    return retValue; 
} 

function is_alpha_numeric(str) {
  if(!str.match(/^[A-Za-z0-9]+$/)) 
   return false;
  return true;
}

function is_number(number) {
  if(!number.match(/^[\-+0-9.1-9]+$/))
   return false;
  return true; 
}

function is_unsign_number(number) {
  if(!number.match(/^[+0-9]+$/))
   return false;
  return true; 
}

function is_email(email) {
  if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/)) 
   return false;
  return true;
}
