
function fnValidateNumber(objNumber)
{
	var i;
	var	strNumber = objNumber.value;
	if (strNumber == "") return true;
	for (i = 0; i < strNumber.length; i++)
	{
		if ((strNumber.charCodeAt(i) > 47) && (strNumber.charCodeAt(i) < 58) || (strNumber.charCodeAt(i) == 45 ))
		{
			continue;
		}
		else
		{
			//alert(" Enter the value in Numbers");
			return false;
		}
	}				
	return true;
}


function ValidateNullTextField(objField)
{
	var strValue = objField;
	
	if(strValue == "" || strValue.length=="0")
	{
		//alert("Value of" + strValue +" is null");
		objField.select();
		objField.focus();
		return false;
	}	
	return true;
}

/*Check For Numerals*/
function fnChkNumeral(objName){
	
	
	var i;
	var strVar = objName.value;
	fnRemoveSpaces(objName);
	if(!(ValidateText(objName)))
	{
		return false;
	}
	if (strVar != ""){
		for(i = 0; i < strVar.length; i++){
			if((strVar.charCodeAt(i) > 47) && (strVar.charCodeAt(i) < 58)){
				continue;
			}
			else
			{
				alert("Enters numerals only");
				objName.select();
				objName.focus();
				return false;
			}
		}return true;
	}return true;
}

/*Check for Null in TextField*/

function ValidateTextField(objField,strMessage)
{
	var strValue = objField.value;
	
	if(strValue == "" || strValue.length=="0")
	{
		alert(strMessage);
		objField.select();
		objField.focus();
		return false;
	}	
	return true;
}



/*Remove The Space from Left side of the string*/

function fnLtrim(strString)
{
 var i=0;
 var intLen = strString.length;

 while((strString.charAt(i) == " ") && ( i < intLen))
  {
   i++;
   }
 strString = strString.substring(i,intLen);
 return  strString;
}

/*Remove The Space From right side of the String*/

function fnRtrim(strString)
{

 var intLen = strString.length;
 var i= intLen-1;

 while((strString.charAt(i) == " ") && ( i > 0 ))
  {
   i--;
   }

 strString = strString.substring(0,i+1);
 return strString;
}

/*Remove Spaces from The Object*/
function fnRemoveSpaces(Field)
{
   strString = Field.value;

   strString = fnLtrim(strString);
   strString = fnRtrim(strString);

   Field.value = strString;
}

/*Function for reseting the element in the form*/

function fnReset(objFormName){
	objFormName.reset();
	return false;
}

/*Function for resetting the elements in the search form */

function fnClear(frm)
{
	
	var i=0;
	
		
	for (i=0;i<frm.length;i++)
	{		
		if (frm.elements[i].type=="text")
			frm.elements[i].value="";
		if (frm.elements[i].type=="password")
			frm.elements[i].value="";
		else if (frm.elements[i].type=="textarea")
			frm.elements[i].value="";
		     else if (frm.elements[i].type=="checkbox") 
			      frm.elements[i].checked=false;
			  else if (frm.elements[i].type=="select-one")
				   frm.elements[i].options[0].selected=true;
			       else if(frm.elements[i].type == "radio")
					frm.elements[i].checked = true;
	}		
	
}	


/*Prints the current screen displayed in the browser.*/
function fnPrint()
{		
	window.print();		
}
/*validates the given email format is correcr or not*/
function validEmail(objEmail) {

		email = objEmail.value;
			invalidChars = " /:,;"
			if (email == "") {			// cannot be empty
				alert("Email id cannot be empty");
				return false;
				
			}
			for (i=0; i<invalidChars.length; i++) {
// does it contain any invalid characters?
				badChar = invalidChars.charAt(i);
				if (email.indexOf(badChar,0) > -1) {
					alert("Email id contains invalid characters");
					return false;
					
				}
			}
			atPos = email.indexOf("@",1);
// there must be one "@" symbol
			if (atPos == -1) {
				alert("Invalid Email id ");
				return false;
			}
			if (email.indexOf("@",atPos+1) != -1) {
				alert("Invalid Email id ");
// and only one "@" symbol
				return false;
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {
				alert("Invalid Email id ");
// and at least one "." after the "@"
				return false;
			}
			if (periodPos+3 > email.length)	{
				alert("Invalid Email id ");
// must be at least 2 characters after the "."
				return false;
			}
			return true;
}

/*validates the given phone number is valid or not*/

function fnValidatePhoneNumber(objPhone)
{
	var i;
	var	strPhone = objPhone.value;
	if (strPhone == "") return true;
	for (i = 0; i < strPhone.length; i++)
	{
		if ((strPhone.charCodeAt(i) > 47) && (strPhone.charCodeAt(i) < 58) || (strPhone.charCodeAt(i) == 45 ))
		{
			
			continue;
		}
		else
		{
			alert("Invalid Phone Number");
			objPhone.select();
			objPhone.focus();
			return false;
		}
	}				
	return true;
}

/*Function for Validating Object Address*/

function fnValidateAddress(objAddress)
{
	var i;
	var	strAddress = objAddress.value;
	var strReplace = "";
	if (strAddress != "")
	{
		for (i = 0; i < strAddress.length; i++)
		{
			if ((strAddress.charCodeAt(i) > 43) && (strAddress.charCodeAt(i) < 58) || (strAddress.charCodeAt(i) > 64) && (strAddress.charCodeAt(i) < 94) || (strAddress.charCodeAt(i) > 94) && (strAddress.charCodeAt(i) < 126) || (strAddress.charCodeAt(i) == 32) || (strAddress.charCodeAt(i) == 35) || (strAddress.charCodeAt(i) == 39) || (strAddress.charCodeAt(i) == 95))
			{
				continue;
			}
			else return false;
		}				
		strReplace=/\'/gi;
		objAddress.value = strAddress.replace(strReplace,"''");
		return true;
	}
	return true;
}
/*Function for Validating State Code*/
function fnValidateState(objState)
{
	var i;
	var strState = objState.value;
	if (strState == "") return true;
	if (strState != "")
	{
		if (strState.length != "2") return false;
		else if (strState.length == "2")
		{		
			strState = strState.toUpperCase(strState);	
			for(i = 0; i < strState.length; i++)
			{
				if (strState.charAt(i) < "A" || strState.charAt(i) > "Z")  return false;		
			}		
			return true;
		}
	}
	return true;
}
/*Function for Validating City Code*/
function fnValidateCity(objCity)
{
	var i;
	var strCity = objCity.value;
	var strReplace = "";
	if (strCity == "") return true;
	if (strCity != "")
	{
		for(i = 0; i < strCity.length; i++)
		{
			if ((strCity.charCodeAt(i) > 44) && (strCity.charCodeAt(i) < 47) || (strCity.charCodeAt(i) > 64) && (strCity.charCodeAt(i) < 91) || (strCity.charCodeAt(i) > 96 ) && (strCity.charCodeAt(i) < 123) || (strCity.charCodeAt(i) == 32) || (strCity.charCodeAt(i) == 39))
			{
				continue;
			}
			else return false;
		}		
		strReplace=/\'/gi;
		objCity.value = strCity.replace(strReplace,"''");
		return true;
	}
	return true;
}
/*Function for Validating Zip Code*/

function fnValidateZipCode(objZip)
{
  var  i;
  var numZip = objZip.value;
  if (numZip == "") return true;
  if(numZip != "")
	{
	  if(numZip.length != "5") return false;
	}
  for(i = 0; i < numZip.length; i++)
	{
		if(numZip.charAt(i) < "0" || numZip.charAt(i) > "9")
			{
				return false;
			}
	}
  return true;
}
/*Function for Validating Object Name*/
function fnValidateName(objName)
{
	var i;
	var	strName = objName.value;
	var strReplace = "";
	
	for (i = 0; i < strName.length; i++)
	{
		if ((strName.charCodeAt(i) > 44) && (strName.charCodeAt(i) < 47)  || (strName.charCodeAt(i) > 64) && (strName.charCodeAt(i) < 91) || (strName.charCodeAt(i) > 96 ) && ( strName.charCodeAt(i) < 123) || (strName.charCodeAt(i)==32) || (strName.charCodeAt(i) == 39)  || (strName.charCodeAt(i) == 95))
		{
			continue;
		}
		else return false;
	}
	strReplace=/\'/gi;
	objName.value = strName.replace(strReplace,"''");
	
	
	return true;
}

/*Function for checking if the date is less than current date*/
function isPriorToCurrentDate(ObjDate,strMsg)
{
	
	var txtDate = ObjDate.value;
	var calDate = new Date(txtDate);
	var dtcurrDate = new Date();
	
	if(calDate.getYear() < dtcurrDate.getYear())
	{
		alert(strMsg);
		ObjDate.focus();
		ObjDate.select();
		return true;
	}
	else
	{
		if(calDate.getYear() == dtcurrDate.getYear())
		{
			if(calDate.getMonth() < dtcurrDate.getMonth())
			{
				alert(strMsg);
				ObjDate.focus();
				ObjDate.select();
				return true;
			}
			else
				if(calDate.getMonth() == dtcurrDate.getMonth())
				{
					if(calDate.getDate() < dtcurrDate.getDate())
					{
						alert(strMsg);
						ObjDate.focus();
						ObjDate.select();
						return true;
					}
				}
		}
	}
	return false;
}
