// JavaScript Document


function isBlank(s){
	var len=s.length;
	var cnt;
	if(s.length==0){return true;}
	return false;
}

//Validate e-mail address
function validateEmail(str){
	if(str.value.length>0){
		if(!checkEmail(str.value)){
			//str.select();
			//str.focus();
			return false;
		}
	}
	return true;
}
function checkEmail(email){
    var splitted = email.match("^(.+)@(.+)$");
	 if(splitted == null) return false;
    if(splitted[1] != null ){
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null){
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null){
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
	return false;
}

//this function checks for the validity of data the user enters.
//this function is used with form fields which are to accept only characters eg: a,A,s,S,D

function checkName(fieldName){
	var strValue ;      //store the value of the field
	var cnt;		  //counter for the loop to check the length of the string
	strValue=fieldName;
	for(var cnt=0;cnt<strValue.length; cnt++){
		if(!(strValue.charAt(cnt)>='A' && strValue.charAt(cnt) <='z') && strValue.charAt(cnt)=='' && strValue.charAt(cnt)!='"' && strValue.charAt(cnt)!='\'' && strValue.charAt(cnt)!='-') {
			return false;
		}
	/*	else
		{
			alert(strValue.charAt(cnt));
		}*/
	}
	return true;		
}
function locationName(fieldName){
	var strValue;       
	var cnt;		 
	strValue=fieldName;
	for(var cnt=0;cnt<strValue.length; cnt++)
	{
		if(!(strValue.charAt(cnt)>='A' && strValue.charAt(cnt) <='z') && !((strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9')) && strValue.charAt(cnt)!=' ' && strValue.charAt(cnt)!='(' && strValue.charAt(cnt)!=')' && strValue.charAt(cnt)!=',' && strValue.charAt(cnt)!='\'' && strValue.charAt(cnt)!='-' && strValue.charAt(cnt)!='.' ) 
			{
			  
				return false;
			}
	}
	return true;		
}
function checkSpecialchar(fieldValue){
	var strValue=fieldValue;
	var cnt;
	
	for(var cnt=0;cnt<strValue.length; cnt++){
		if(!(strValue.charAt(cnt)>='A' && strValue.charAt(cnt) <='z') && !((strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9')) ) {
			return false;
		}
	}
	return true;
}

function isSpecialchar(fieldValue){
	var strValue=fieldValue;
	var cnt;
	
	for(var cnt=0;cnt<strValue.length; cnt++){
		if(!(strValue.charAt(cnt)>='A' && strValue.charAt(cnt) <='z')  ) {
			return false;
		}
	}
	return true;
}

//Trim leading and trailing spaces in a string
String.prototype.trim=function (s) {
	s = this != window? this : s;
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function searchvalidate() {
	
	
	var x = document.getElementById("fld_search").value;
	
	if(isBlank(x)) {alert ("Please enter text in search box"); 
	document.getElementById("fld_search").focus();
	return false;}
	
}

function isValidPass(x)
{
	if(x.length<6)
	{
		return true;
	}
	else
	{
		return false;
	}
}
