



var strInitialErrMessage,strErrEmpty,strErrExceed,strErrLess,strErrChar,strErrDigit;
var strErrEnter,strErrIn,strErrDate,strErrDate1,strErrEmail,strErrEmail1,strErrNotMatch; 
var strErrMessage,objFocus;

/******************** Change Standard Error Messages here ********************/
strErrMessage = ""
strInitialErrMessage = "\n    ";
strErrEmpty = "Enter"
strErrExceed = "should not exceed"
strErrLess = "should be minimum of"
strErrChar = "characters"
strErrDigit = "digits"
strErrEnter = "Enter"
strErrIn = "in"
strErrDate = "year should be between 1900 to 2079"
strErrDate1 = "is invalid date."
strErrEmail = "Invalid Email Address."
strErrEmail1 = "Invalid Email Address."
strErrNotMatch = "not match with"
strErrValidCurrency = "should be a valid Decimal Value"

/******************************************************************************
1.This function is used to display Error Alert and it is called from front end.
Ex: return fnDisplayError();
******************************************************************************/

function fnDisplayError(){
	if (strErrMessage != ""){
		alert(strInitialErrMessage + strErrMessage);
		eval(objFocus).focus();
		if ((eval(objFocus).type == "text")||(eval(objFocus).type == "textarea")){
			eval(objFocus).select();
		}
		objFocus = "";
		strErrMessage = ""
		return false;
	}
	else
	{
	    return true;
	}	
}

/*****************************************************************************
2.This function is used to Check blank spaces and it is used by other functions.
Ex: return fnIsEmpty("Chandru")	
******************************************************************************/
function fnIsEmpty(str){
	for (var i = 0; i < str.length; i++) 
		if (" " != str.charAt(i)) return false;
	return true;	
}

/*****************************************************************************
3.This function is used to Check Textbox/Textarea/select box for the Empty,
Maximum length,Minimum length.
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Note2:MinLength should be 0 when no minimum length validation required.
Ex: fnCheckString("document.frmAddEdit.txtName","Name",25,0,true);	
******************************************************************************/
function fnCheckString(ObjectName,ObjectCaption,MaxLength,MinLength,Required){
	var strErr = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	if (Required==true ||(Required==false && l>0)){
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n    " ;
		}else if (l>MaxLength){
			strErr = ObjectCaption + " " + strErrExceed + " " + MaxLength + " " + strErrChar + "\n\    " ;
		}else if (MinLength > 0){
			if (ObjectName.value.length < MinLength){
				strErr = ObjectCaption + " " + strErrLess + " " + MinLength + " " + strErrChar + "\n\    ";
			}
		} 
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else{return true;}
}

/*****************************************************************************
4.This function is used to Check Textbox/Textarea/select box for the Numeric value
along with Empty,Maximum length,Minimum length.
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Note2:MinLength should be 0 when no minimum length validation required.Below Ex
validates for Zip code with 6 digit number
Ex: fnCheckNumbers("document.frmAddEdit.txtZip","Zip Code",6,6,true);	
******************************************************************************/
function fnCheckNumbers(ObjectName,ObjectCaption,MaxLength,MinLength,Required){
	var strErr = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
    if (Required==true || (Required==false && l>0)){
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}
		else if (l>MaxLength){
			strErr = ObjectCaption + " " + strErrExceed + " " + MaxLength + " " + strErrDigit + "\n\    " ;  
		}
		else if (MinLength > 0){
			if (ObjectName.value.length < MinLength){
				strErr = ObjectCaption + " " + strErrLess + " " + MinLength + " " + strErrDigit + "\n\    ";
			}
		}//else{
			for (var i = 0; i < ObjectName.value.length; i++){
				if (ObjectName.value.charAt(i) < '0' || ObjectName.value.charAt(i) > '9'){
					strErr = ObjectCaption + " should contain digits\n\    "
				}
			}
		
		//} 
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else{return true;}
}
function fnCheckPhoneNumbers(ObjectName,ObjectCaption,MaxLength,MinLength,Required){
	var strErr = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	var strValidChar = '0123456789 ()-';
    if (Required==true || (Required==false && l>0)){
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}
		else if (l>MaxLength){
			strErr = ObjectCaption + " " + strErrExceed + " " + MaxLength + " " + strErrChar + "\n\    " ;  
		}
		else if (MinLength > 0){
			if (ObjectName.value.length < MinLength){
				strErr = ObjectCaption + " " + strErrLess + " " + MinLength + " " + strErrChar + "\n\    ";
			}
		}//else{
			for (var i = 0; i < ObjectName.value.length; i++){
				if(strValidChar.indexOf(ObjectName.value.charAt(i)) == -1)
				{
					strErr = ObjectCaption + " should contain digits or space or ( or ) or -\n\    "
				}
				//if (ObjectName.value.charAt(i) < '0' || ObjectName.value.charAt(i) > '9' || ObjectName.value.charAt(i) != '(' || ObjectName.value.charAt(i) != ')' || ObjectName.value.charAt(i) != ' ' ){
				//	strErr = ObjectCaption + " should contain digits.\n\    "
				//}
			}
		
		//} 
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else{return true;}
}

/*****************************************************************************
5.This function is used to Check Textbox/Textarea/select box for the Phone 
Numbers along with Empty and specific format.
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Note2:Current format suported are "nnn-nnn-nnnn","nnn nnn nnnn","(nnn)nnn-nnnn" and "nnnnnnnnnn"
if you need your own format then alter the regexp of below function
Ex:fnCheckPhoneNumbers("document.frmAddEdit.txtPhone","Phone No","nnn-nnn-nnnn",true);
******************************************************************************/
function fnCheckPhoneNumbersOLD(ObjectName,ObjectCaption,Format,Required){
	var strErr = ""
	var regexp = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	//var regexp = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4})$/;
	if (Required==true || (Required==false && l>0)){
		if (Format == "nnn-nnn-nnnn"){
			regexp = /^(\d{3}-\d{3}-\d{4})$/;
		}else if (Format == "nnn nnn nnnn"){
			regexp = /^(\d{3} \d{3} \d{4})$/;
		}else if (Format == "(nnn)nnn-nnnn"){
			regexp = /^(\(\d{3}\)\d{3}-\d{4})$/;
		}else if (Format == "nnnnnnnnnn"){
			regexp = /^(\d{10})$/;
		}else if (Format == ""){
			regexp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;  //A regular expression to match phone numbers, allowing for an international dialing code at the start and hyphenation and spaces that are sometimes entered. 
			Format = "international format.It may include numbers with any of the following +,- characters"
		} 
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}else if ((regexp == "")||(regexp.test(ObjectName.value)==false)){
			strErr = strErrEnter +" "+ ObjectCaption + " " + strErrIn + " " + Format + "\n\    " ;
		}    
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else {return true;}
}

function fnCheckPhoneNumbersOLD2(ObjectName,ObjectCaption,Format,Required){
	var strErr = ""
	var regexp1 = ""
	var regexp2 = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	//var regexp = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4})$/;
	if (Required==true || (Required==false && l>0)){
		regexp1 = /^(\d{3}-\d{3}-\d{4})$/;
		regexp2 = /^(\d{3} \d{3} \d{4})$/;
		
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}else if (((regexp1 == "")||(regexp1.test(ObjectName.value)==false)) && ((regexp2 == "")||(regexp2.test(ObjectName.value)==false))){
			strErr = strErrEnter +" "+ ObjectCaption + " " + strErrIn + " " + Format + "\n\   ";
		}
			    
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else {return true;}
}

/*****************************************************************************
6.This function is used to Check Textbox/Textarea/select box for the Date along 
with Empty and specific format.
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Note2:Current format suported are "dd/mm/yyyy" and "mm/dd/yyyy"
if you need your own format then alter the regexp of below function
Ex:fnCheckDate("document.frmAddEdit.txtDate","Date","dd/mm/yyyy",true);
******************************************************************************/
function fnCheckDate(ObjectName,ObjectCaption,Format,Required){
//	^\d{1,2}\/\d{1,2}\/\d{4}$ 
//  ^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$ 
// The above expression validates dates in the US m/d/y format from 1/1/1600 - 12/31/9999. Checks for valid days for a given month. The days are validated for the given month and year. Leap years are validated for all 4 digits years from 1600-9999, and all 2 ... 
	var strErr = ""
	var regexp1 = ""
	var regexp2 = ""
	var regexp3 = ""
	var regexp4 = ""
	var l,da,dd,mm,yy,strLeft,strCenter,strLast
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	da=ObjectName.value
	if ((Required==true) || (Required==false && l>0)){
		if ((Format == "dd/mm/yyyy")||(Format == "mm/dd/yyyy")){
			regexp1 = /^(\d{2}\/\d{2}\/\d{4})$/;
			regexp2 = /^(\d{1}\/\d{1}\/\d{4})$/;
			regexp3 = /^(\d{1}\/\d{2}\/\d{4})$/;
			regexp4 = /^(\d{2}\/\d{1}\/\d{4})$/;
		}else if ((Format == "dd-mm-yyyy")||(Format == "mm-dd-yyyy")){
			regexp1 = /^(\d{2}\-\d{2}\-\d{4})$/;
			regexp2 = /^(\d{1}\-\d{1}\-\d{4})$/;
			regexp3 = /^(\d{1}\-\d{2}\-\d{4})$/;
			regexp4 = /^(\d{2}\-\d{1}\-\d{4})$/;
		}else if ((Format == "dd.mm.yyyy")||(Format == "mm.dd.yyyy")){
			regexp1 = /^(\d{2}\.\d{2}\.\d{4})$/;
			regexp2 = /^(\d{1}\.\d{1}\.\d{4})$/;
			regexp3 = /^(\d{1}\.\d{2}\.\d{4})$/;
			regexp4 = /^(\d{2}\.\d{1}\.\d{4})$/;
		}
		
		if (regexp1 == ""){
			strErr = strErrEnter +" "+ ObjectCaption + " " + strErrIn + " " + Format + "\n\    " ;
		}else if (regexp1.test(ObjectName.value)==true){
			strLeft=da.substr(0,2);
			strCenter=da.substr(3,2);
			strLast=da.substr(6,4);
		}else if (regexp2.test(ObjectName.value)==true){	
			strLeft="0" + da.substr(0,1);
			strCenter="0" + da.substr(2,1);
			strLast=da.substr(4,4);
		}else if (regexp3.test(ObjectName.value)==true){	
			strLeft="0" + da.substr(0,1);
			strCenter=da.substr(2,2);
			strLast=da.substr(5,4);
		}else if (regexp4.test(ObjectName.value)==true){	
			strLeft=da.substr(0,2);
			strCenter="0" + da.substr(3,1);
			strLast=da.substr(5,4);
		}else{
			strErr = strErrEnter +" "+ ObjectCaption + " " + strErrIn + " " + Format + "\n\    " ;
		}
		
		if ((Format == "dd/mm/yyyy")||(Format == "dd-mm-yyyy")||(Format == "dd.mm.yyyy")){
			dd = strLeft
			mm = strCenter
			yy = strLast
		}else if ((Format == "mm/dd/yyyy")||(Format == "mm-dd-yyyy")||(Format == "mm.dd.yyyy")){
			dd = strCenter
			mm = strLeft
			yy = strLast
		}
		
		if (strErr == ""){
			if((parseInt(yy) < 1900)||(parseInt(yy) > 2079)){
				strErr = ObjectCaption + " " + strErrDate + "\n\    " ;
			}else if ((dd=="00" || mm=="00")){
				strErr = ObjectCaption + " " + strErrDate1 + "\n\    " ;
			}else if ((dd>31 || mm>12) || ((mm == 1 || mm == 3 || mm ==5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd > 31) || ((mm == 04 || mm == 06 || mm == 9 || mm == 11) && dd > 30)  || ((yy % 4) == 0 && mm==2 && dd > 29) || ((yy % 4) != 0 && mm==2 && dd > 28)){
				strErr = ObjectCaption + " " + strErrDate1 + "\n\    " ;
			}
			
		}
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}			
	
	}
}

/*****************************************************************************
7.This function is used to Check Textbox/Textarea/select box for the Empty,
Maximum length,Minimum length and valid email.
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Note2:MinLength should be 0 when no minimum length validation required.
Note3:Email address must be of form a@b.c 
	  There must be at least one character before the @,There must be at least one character before and after the .
	  The characters @ and . are both required
Ex: fnCheckEmail("document.frmAddEdit.txtEmail","Email Address",50,0,true);	
******************************************************************************/
function fnCheckEmail(ObjectName,ObjectCaption,MaxLength,MinLength,Required){
	var strErr = ""
	ObjectName=eval(ObjectName)
	l=ObjectName.value.length;
	txt=ObjectName.value
	if (Required == true || (Required==false && l>0)){
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}else if (l>MaxLength){
			strErr = ObjectCaption + " " + strErrExceed + " " + MaxLength + " " + strErrChar + "\n\    " ;
	    }else if (MinLength > 0){
			if (ObjectName.value.length < MinLength){
				strErr = ObjectCaption + " " + strErrLess + " " + MinLength + " " + strErrChar + "\n\    ";
			}
		}else {
			var i = 1;
			if(!isEmail(ObjectName,"Email Address"))
			{
				strErr = strErrEmail +"\n\    " ;
			}
			
			// look for @
		    /*while ((i < l) && (txt.charAt(i) != "@"))
			{
				 i++
			}
			if ((i >= l) || (txt.charAt(i) != "@")){
				strErr = strErrEmail +"\n\    " ;
			}else{
				i += 2;
			}	

			// look for .
			if(strErr ==""){
				while ((i < l) && (txt.charAt(i) != "."))
				{ 
					i++
				}
				// there must be at least one character after the .
				if ((i >= l - 1) || (txt.charAt(i) != ".")){
					strErr = strErrEmail1 +"\n\    " ;
				}
			 }*/
		}
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}			 
	}else{return true;}
}
// New Function for Email Checking
function isEmail(objEmail,strObjectName)
{
/* 
 Name:isEmail (function)
   Parameters
       Name          Datatype        Description
     objEmail   object   Object that contain EmailId to be checked
  strObjectName  string   Name of Onject
 return value:
        boolean
   Description:
        Both @ & dot is required in string,if not then alert message displayed else check that 
  there must be at least  one character before @ & one character before & after dot.
  if not then alert message is displayed  else return true.
*/ 
 var strEmail;   //store the value of object
 var chrAt;    //store the @ characetr
 var chrDot;    //store the "." character
 var intIndexOfAt;  //store the index of @
 var intIndexOfDot;  //store the index of "."
 strEmail=objEmail.value;
 chrAt="@";
 chrDot=".";
 intIndexOfAt=strEmail.indexOf(chrAt);
 intIndexOfDot=strEmail.indexOf(chrDot)
 /*if(ForceEntry(objEmail,strObjectName)==false)
 {
  return false;
 }*/
 //if @ not specified
 if (strEmail.indexOf(chrAt)==-1)
 {
    //PromptErrorMsg(strObjectName,"Invalid");
    return false;
 }
 //if @ not specified or @ at first position or at last position
 if (strEmail.indexOf(chrAt)==-1 || strEmail.indexOf(chrAt)==0 || strEmail.indexOf(chrAt)==strEmail.length)
 {
    //PromptErrorMsg(strObjectName,"Invalid");
    return false;
 }
 //if "." not specified or . at first position or at last position
 if (strEmail.indexOf(chrDot)==-1 || strEmail.indexOf(chrDot)==0 || strEmail.indexOf(chrDot)==strEmail.length-1)
 {
     //PromptErrorMsg(strObjectName,"Invalid");
     return false;
 }
 if (strEmail.indexOf(chrAt,(intIndexOfAt+1))!=-1)
 {
	//PromptErrorMsg(strObjectName,"Invalid");
     return false;
 }
 if (strEmail.substring(intIndexOfAt-1,intIndexOfAt)==chrDot || strEmail.substring(intIndexOfAt+1,intIndexOfAt+2)==chrDot)
 {
     //PromptErrorMsg(strObjectName,"Invalid");
     return false;
 }
 if (strEmail.indexOf(chrDot,(intIndexOfAt+2))==-1)
 {
     //PromptErrorMsg(strObjectName,"Invalid");
     return false;
 }
 if (strEmail.indexOf(" ")!=-1)
 {
     //PromptErrorMsg(strObjectName,"Invalid");
     return false;
 }
 return true;     
}
// End New Function


/*****************************************************************************
8.This function is used to varifiy the password entered in two Textbox.
Note: if CaseSencitive is true ,it verifiys for case in both text boxes
Ex: fnVerifyPWD("document.frmAddEdit.txtPass1","Password1","document.frmAddEdit.txtPass2","Password2",true);	
******************************************************************************/
function fnVerifyPWD(ObjectName1,ObjectCaption1,ObjectName2,ObjectCaption2,CaseSensitive){
	var strErr = ""
	ObjectName1=eval(ObjectName1)
	ObjectName2=eval(ObjectName2)
	if (fnIsEmpty(ObjectName1.value)){
		strErr = strErrEmpty +" "+ ObjectCaption1 + "\n\    " ;
		ObjectName1.value="";
        ObjectName2.value=""; 
	}else if (fnIsEmpty(ObjectName2.value)){
		strErr = strErrEmpty +" "+ ObjectCaption2 + "\n\    " ;
		ObjectName1.value="";
        ObjectName2.value="";     
	}else if (CaseSensitive==false){
	   if ((ObjectName1.value.toUpperCase()) != (ObjectName2.value.toUpperCase())){
           strErr = ObjectCaption2 +" " + strErrNotMatch +" "+ ObjectCaption1 + "\n\    " ;  
           ObjectName1.value="";
           ObjectName2.value="";  
      }
    }else if (ObjectName1.value != ObjectName2.value){
		strErr = ObjectCaption2 +" "+ strErrNotMatch +" "+ ObjectCaption1 + "\n\    " ;    
		ObjectName1.value="";
		ObjectName2.value="";
    }
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName1
			}
		}
					 
}

/*****************************************************************************
9.This function is used to Handle the Javascript Error.
******************************************************************************/
function ErrorHandler(message, url, lineno){
strErrHandlerMessage = "An Unhandled Javascript Error has accured in the application"
alert(strErrHandlerMessage);
return true;
} 

/*****************************************************************************
10.This function is used to Check for Currency entry  in Textbox/Textarea/select box for the Empty,
Maximum value
Note1:If Required is set to false,then it validates only if you enter in the 
input boxes.
Ex: fnCheckCurrency("document.frmAddEdit.txtCurrency","Amount","99999999.99",true);	
******************************************************************************/
function fnCheckCurrency(ObjectName,ObjectCaption,MaxVal,Required){
	var strErr = ""
	ObjectName=eval(ObjectName)
	if(ObjectName.value == "0.00"){
		l = 0;
	}else{
		l=ObjectName.value.length;
	}
	if (Required==true ||(Required==false && l>0)){
		if ((fnIsEmpty(ObjectName.value))||(ObjectName.value.length <= 0)){
			strErr = strErrEmpty +" "+ ObjectCaption + "\n\    " ;
		}else{
			var curEntered = Replace(ObjectName.value,",","");
			if (isNaN(curEntered)||fnIsEmpty(curEntered)){
				strErr = ObjectCaption + " " + strErrValidCurrency + " \n\    " ;
			}else{
				curEntered = parseFloat(curEntered)
				if (curEntered > MaxVal){
					strErr = ObjectCaption + " " + strErrExceed + " " + MaxVal + " \n\    " ;
				}	
			}
		} 
		if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
		}		
	}else{return true;}
}

/*****************************************************************************
11.This function is used to Compare Dates
******************************************************************************/
function fnCompareDates(ObjectName,ObjectCaption,DateToCompare,ObjectCaption1,Operator)
{
	ObjectName=eval(ObjectName)
	var strErr = "";
	var FromArr, FromVar;
	var ToArr, ToVar
	
	FromVar = ObjectName.value ;
	if (DateToCompare==""){
		ToVar = "";
	}else{
		ToVar = DateToCompare ;
	}
		
	FromArr = FromVar.split("/");
	ToArr = ToVar.split("/");
	
	FromVar = parseInt(FromArr[2]+FromArr[1]+FromArr[0]);
	ToVar = parseInt(ToArr[2]+ToArr[1]+ToArr[0]);
			
	if (Operator == ">"){
		if(FromVar > ToVar){
			strErr = ObjectCaption + " should not be greater than " + ObjectCaption1 +"\n\    " ;
		}
	}

	if (Operator == "<"){
		if(FromVar < ToVar){
			strErr = ObjectCaption + " should not be less than "+ ObjectCaption1 +"\n\    " ;
		}
	}
	
	if (Operator == "="){
		if(FromVar < ToVar){
			strErr = ObjectCaption + " should be equal to "+ ObjectCaption1 +"\n\    " ;
		}
	}
	
	if (Operator == "<="){
		if(FromVar <= ToVar){
			strErr = ObjectCaption + " should be less than or equal to "+ ObjectCaption1 +"\n\    " ;
		}
	}
	
	if (Operator == ">="){
		if(FromVar >= ToVar){
			strErr = ObjectCaption + " should be grater than or equal to "+ ObjectCaption1 +"\n\    " ;
		}
	}
	
	if (strErr != ""){
			strErrMessage = strErrMessage + strErr;
			if ((objFocus == undefined)||(objFocus == "")){
				objFocus = ObjectName
			}
	}else{
		return true;
	}
}

//The below function Replaces all characters in 'strFind' to 'strReplace'
function Replace(strInput,strFind,strReplace) {
    var output = "";  // initialise output string
    for (var i=0; i < strInput.length; i++){
		if (strFind.indexOf(strInput.charAt(i)) == -1){
			output += strInput.charAt(i);
		}else{
			output += strReplace;
		}
    }
    return output;
}
function ValidateGST(strRateString,dtEnteredDate,objGSTName,dblEnteredAmount){
	var strErr = ""
	objGSTName = eval(objGSTName)
	var dblEnteredGST = parseFloat(Replace(objGSTName.value,",",""));
	if (isNaN(dblEnteredGST)){
		dblEnteredGST = 0;
	}
	if (dblEnteredGST == 0){
		return true;
	}
	var dblLocAmount = parseFloat(Replace(dblEnteredAmount,",",""))
	if (isNaN(dblLocAmount)){
		dblLocAmount = 0;
	}
	var arrDateRate = new Array()
	arrDateRate = strRateString.split(":");
	var ThisArr = dtEnteredDate.split("/");
	var strThisDate = parseInt(ThisArr[2]+ThisArr[1]+ThisArr[0]);
					
	var intCount = 0;
	var dblvalidRate = 0;
	for(intCount=0;intCount < arrDateRate.length;intCount++){	
		var strRate = 0
		var RateArr = arrDateRate[intCount].split("|");
		var strFromDate = RateArr[0];
		strRate = parseFloat(RateArr[1]);
		var strToDate;
						
		if(intCount == arrDateRate.length-1){
			strToDate = strFromDate;
		}else{
			var NextRateArr = arrDateRate[intCount+1].split("|");
			strToDate = NextRateArr[0];	
		}
						
		if (((strThisDate >= strFromDate) && (strThisDate < strToDate))||(strThisDate == strFromDate)){
			dblvalidRate = strRate;
		}
	}
	
	var OldRateArr = arrDateRate[0].split("|");
	var strOldDate = OldRateArr[0];	
	if((dblvalidRate == 0)&&(strThisDate > strOldDate)){
		var LatestRateArr = arrDateRate[arrDateRate.length-1].split("|");
			dblvalidRate = LatestRateArr[1];	
	}
	//alert(dblvalidRate);
	var dblDiff = (dblLocAmount * dblvalidRate) - dblEnteredGST;
	var bolValid = true;
	var dblValidRateAmt = (dblvalidRate * 100)
	if ((dblDiff  < -1)||(dblDiff  > 1)){
		bolValid = false;
	}else if (((dblDiff*100)  < (-1 * dblValidRateAmt))||((dblDiff*100)  > dblValidRateAmt)){
		bolValid = false;
	}
					
	if (bolValid == false){
		strErr = "You have selected Incorrect GST amount.\n\    " ;
	}
	
	if (strErr != ""){
		strErrMessage = strErrMessage + strErr;
		if ((objFocus == undefined)||(objFocus == "")){
			objFocus = objGSTName
		}
	}else{
		return true;
	}
}

function fnValidateIP(ObjectValue) {
var validChars = '.0123456789';

    if (!ObjectValue)
        return false;
    dots = 0;

    for (var i = 0; i < ObjectValue.length; i++) {
       var chr = ObjectValue.substring(i,i+1);
       if (validChars.indexOf(chr) == -1)
           return false;
       if (chr == '.') {
           dots++;
           eval('dot' + dots + ' = ' + i);
       }
    }

    if (dots != 3)
        return false;
    
    if (ObjectValue.substring(0,1) == '.' || ObjectValue.substring(ObjectValue.length,ObjectValue.length+1) == '.')
        return false;

    ip1 = ObjectValue.substring(0,dot1);
    if (!ip1 || ip1 >255)
        return false;
    ip2 = ObjectValue.substring(dot1+1,dot2);
    if (!ip2 || ip2 >255)
        return false;
    ip3 = ObjectValue.substring(dot2+1,dot3);
    if (!ip3 || ip3 >255)
        return false;
    ip4 = ObjectValue.substring(dot3+1,ObjectValue.length+1);
    if (!ip4 || ip4 >255)
        return false;

    if (ip1 == 0 && ip2 == 0 && ip3 == 0 && ip4 == 0)
        return false;

    return true;
}
