var ErrMsg = "";
var retval=false;
var ok;

function ShowDilog()
        {
        
            document.getElementById('light').style.visibility = "visible";
            document.getElementById('fade').style.visibility = "visible";
            document.getElementById('light').style.display = "block";
            document.getElementById('fade').style.display = "block";
           // document.getElementById('fade').style.height = "800px";
            document.getElementById('fade').style.height = document.documentElement.scrollHeight + "px";
            document.getElementById('fade').style.width = document.documentElement.scrollWidth + "px";
            document.getElementById('light').style.height = "200px";
            document.getElementById('light').style.width = "400px";
            
            makecenter('light');
         //   document.getElementById('DivAddStu').style.visibility = 'hidden';
            
            return false;    
        }

function makecenter(id)
{
       
       var brSize = getBRSize();
	    
	    var WWidth='';
        WWidth=document.getElementById(id).style.width;
        WWidth=parseInt(WWidth.substring(0,WWidth.length-2));
       
        var Wheight='';
        Wheight=document.getElementById(id).style.height;
        Wheight=parseInt(Wheight.substring(0,Wheight.length-2));
        
	    document.getElementById(id).style.left=((brSize[0]-WWidth)/2)+'px';
	    document.getElementById(id).style.top=((brSize[1]-Wheight)/2)+'px';
    
}

function getBRSize()
    {
	    var bodyWidth = document.documentElement.clientWidth;
	    var bodyHeight = document.documentElement.clientHeight;
    	
	    var bodyWidth, bodyHeight; 
	    if (self.innerHeight){ // all except Explorer 
	       bodyWidth = self.innerWidth; 
	       bodyHeight = self.innerHeight; 
	    }  else if (document.documentElement && document.documentElement.clientHeight) {
	       // Explorer 6 Strict Mode 		 
	       bodyWidth = document.documentElement.clientWidth; 
	       bodyHeight = document.documentElement.clientHeight; 
	    } else if (document.body) {// other Explorers 		 
	       bodyWidth = document.body.clientWidth; 
	       bodyHeight = document.body.clientHeight; 
	    } 
	   var nav4=window.event?true:false;
       if (nav4) {
                 x =  document.documentElement.scrollLeft + document.body.scrollLeft;
                 y = document.documentElement.scrollTop + document.body.scrollTop;
            }
        else {
                 x =window.scrollX;
                 y = window.scrollY;
            }
        if(x == 'undefined' || x == null) x =0;    
        if(y == 'undefined' || y == null) y =0;    

        bodyWidth=bodyWidth+x;
        bodyHeight=bodyHeight+y
  
	    return [bodyWidth,bodyHeight];		
		
    }

    function ValidateForm(theForm) {

        ErrMsg = "";
        //ErrMsg = "The following errors are occured\n\n";
        ok = true;

        var Validations = new Array()
        var FieldsToValidate = new Array();
        try {
            FieldsToValidate = theForm.Validation.value.split("^");
        }
        catch (e) {
            FieldsToValidate = document.getElementById("Validation").value.split("^");
        }

        for (i = 0; i < FieldsToValidate.length; i++) {

            var FieldAttribs = new Array();
            FieldAttribs = FieldsToValidate[i].split("|");

            Validations[i] = new Array(FieldAttribs.length);
            for (j = 0; j < FieldAttribs.length; j++) {

                var values = new Array();
                values = FieldAttribs[j].split("=");

                Attrib = trim(values[0]);
                AttribValue = trim(values[1]);
                Validations[i][Attrib] = AttribValue;

            }
        }

        for (i = 0; i < Validations.length; i++) {

            switch (Validations[i]["Validate"].toUpperCase()) {

                case "COMPARE":
                    ValidateCompare(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "BLANK":
                    ValidateBlank(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "CONFIRMPASSWORD":
                    ValidateConfirmPassword(theForm, theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "EMAIL":
                    ValidateEmail(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "SELECT":
                    ValidateRadio(theForm, Validations[i]["Field"], Validations[i]);
                    break;
                case "MULTISELECT":

                    ValidateCheckBox(theForm, Validations[i]["Field"], Validations[i]);
                    break;
                case "TOPMINUSMULTISELECT":
                    ValidateListBox(theForm, Validations[i]["Field"], Validations[i]);
                    break;
                case "COMBO":
                    ValidateComboBox(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "NUMERIC":
                    ValidateNumeric(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "DECIMAL":
                    ValidateDecimal(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "ALPHA":
                    ValidateAlpha(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "ALPHANUMERIC":
                    ValidateAlphaNumeric(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "FILEEXTENSION":
                    ValidateFileExtension(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "STRINGMATCH":
                    ValidateString(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "REGULAREXPRESSION":
                    ValidateRegExp(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "DATE":
                    ValidateDate(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "COMPAREDATE":
                    ValidateCompareDate(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "USSTATE":
                    ValidateUSState(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "USZIP":
                    ValidateUSZIP(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "ZIP":
                    ValidateZIP(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "PHONE":
                    ValidatePhone(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "USPHONE":
                    ValidateUSPhone(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "URL":
                    ValidateURL(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "PERCENTAGERANGE":
                    ValidatePercentageRange(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "CHECKLENGTH":
                    checkLength(theForm[Validations[i]["Field"]], Validations[i]);
                    break;
                case "COMPAREDATEANOTHER":
                    {  
                        ValidateCompareDateAnother(theForm[Validations[i]["Field"]], Validations[i]);
                        break;
                    }
            }

        }

        if (!ok)
            alert(ErrMsg);

        return ok;
    }


function rightTrim(strValue) {
var objRegExp = /^([\w\W]*)(\b\s*)$/;
      if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}

function leftTrim(strValue) {
var objRegExp = /^(\s*)(\b[\w\W]*)$/;
 
      if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function trim(strValue) {
 var objRegExp = /^(\s*)$/;
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}
function checkBlank(Element, FieldAttrib)
{
	if(trim(Element.value)=="")
	{
		ErrMsg+="- Please enter the value of "+FieldAttrib["Alias"]+"\n";
		ok=false;		
		SetFocus(Element);        
		return false;
		
	}
	else
	{
	    Element.className ='TextBox';        
		return true;
    }
}
function checkLength(Element, FieldAttrib)
{
	if(FieldAttrib["Length"])
	{
		if(Element.value.length>FieldAttrib["Length"])
		{
		    
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be less than or equals to "+FieldAttrib["Length"]+" character\n";
			ok=false;
			SetFocus(Element);            
			return false;
		}
		else
		{
		    Element.className ='TextBox';
			return true;
		}
	}
}

function CompareTo(Element, FieldAttrib)
{
	if(FieldAttrib["CompareTo"])
	{
		if(Element.value!=FieldAttrib["CompareTo"])
		{
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be same as "+FieldAttrib["Alias1"]+"\n";
			ok=false;
			SetFocus(Element);            
			return false;
		}
		else
		{
			Element.className ='TextBox';
			return true;
		}
		
	}
}

function checkPhone(Element, FieldAttrib)
{
	StringToMatch = FieldAttrib["Characters"];
	var totaldigits = 0;
	for(var i=0;i<Element.value.length;i++)
	{
		if(StringToMatch.indexOf(Element.value.charAt(i))<0)
		{
			ErrMsg+="- Please enter a valid value for "+FieldAttrib["Alias"]+"\n";
			ok=false;
			SetFocus(Element);            
			return false;
			break;
		}
		if(!isNaN(Element.value.charAt(i)))
			totaldigits++
	}
	if(totaldigits<FieldAttrib["MinDigits"])
	{
		ErrMsg+="- "+FieldAttrib["Alias"]+" should contain at least "+ FieldAttrib["MinDigits"] +" digits\n";
		ok=false;
			SetFocus(Element);            
		return false;
	}
	else
	{
	    Element.className ='TextBox';
		return true;
	}
}

function checkRegExp(Element, RegExpString, FieldAttrib)
{
	
	
	if(!RegExpString.test(Element.value))
	{
	   	ErrMsg+="- Please enter a proper value of "+FieldAttrib["Alias"]+"\n";
		ok=false;
		SetFocus(Element);        
		return false;
	}
	else
	{
	    Element.className ='TextBox';
		return true;
	}
}

function compareDate(Element,strValue, Format, FieldAttrib,MinDate)
{
  	if(MinDate != "")
	{
	    strValue =  Date.parse(strValue);
	    MinDate =  Date.parse(MinDate);

	    if (FieldAttrib["MESSAGE"] == "") {

	        if (strValue < MinDate) {
	            ErrMsg += "- " + FieldAttrib["Alias"] + " should not less then Today's Date\n";
	            ok = false;
	            SetFocus(Element);
	            return ok;
	        }
	        else {

	        }
	    }
	    else {
	        if (strValue < MinDate) {	            
	            ErrMsg += "- " + FieldAttrib["MESSAGE"] + " \n";
	            ok = false;
	            SetFocus(Element);
	            return ok;
	        }
	    }
	    
	}	
}

function checkDate(Element,strValue, Format, FieldAttrib)
{
	
	if(FieldAttrib["FullYear"]){
		if(FieldAttrib["FullYear"]=="Yes"){
			var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,4}$/;
		}else{
			var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
		}
	}
	else
	{
			
		var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
	}
  	if(!objRegExp.test(strValue))
	{
		ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
		ok=false;	
		SetFocus(Element);     	
		return ok;
	}
  	else
	{
		var arrayDate = strValue.split("\/"); //split date into month, day, year
	    
		if(Format=="mm/dd/yy" || Format=="mm/dd/yyyy")
		{
			var intDay = parseInt(arrayDate[1],10); 
			var intYear = parseInt(arrayDate[2],10);
			var intMonth = parseInt(arrayDate[0],10);
		}
		else if(Format=="dd/mm/yy" || Format=="dd/mm/yyyy")
		{	
			var intDay = parseInt(arrayDate[0],10); 
			var intYear = parseInt(arrayDate[2],10);
			var intMonth = parseInt(arrayDate[1],10);
		}
		if(intMonth > 12 || intMonth < 1) {
			ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
			ok=false;
			SetFocus(Element);     
			return ok;
		}
		else
		{
			var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
								'8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}
			if(intMonth != 2) {
			  if(intDay <= arrayLookup[intMonth] && intDay != 0)
				return true;
			}
			else
			{
				if(FieldAttrib["FullYear"]=="Yes"){
					var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
					if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
					  return true;
				}else{
					return true;
				}
			}
		}
	}
	ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
	ok=false;
	SetFocus(Element);     
  	return false;
}

function checkStringMatch(Element, FieldAttrib)
{
	StringToMatch = FieldAttrib["StringToMatch"];
	for(var i=0;i<Element.value.length;i++)
	{
		if(StringToMatch.indexOf(Element.value.charAt(i))<0)
		{
			ErrMsg+="- Please enter a valid value for "+FieldAttrib["Alias"]+"\n";
			ok=false;
			SetFocus(Element);            
			return false;
			break;
		}
	}
	return true;
}


function ValidateCompare(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			CompareTo(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			CompareTo(Element, FieldAttrib);
	}
}


function ValidatePhone(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkPhone(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkPhone(Element, FieldAttrib);
	}
}
function ValidateUSPhone(Element, FieldAttrib)
{
	var objRegExp  = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	
}

function ValidateURL(Element, FieldAttrib)
{
   	//var objRegExp  =/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
   	var objRegExp  =/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	
}

function ValidateBlank(Element, FieldAttrib)
{    
	if(FieldAttrib["Optional"])
	{		
		if(trim(Element.value)!="")
			checkLength(Element, FieldAttrib);
			
	}
	else
	{	    
		if(checkBlank(Element, FieldAttrib))
		    CompareTo(Element, FieldAttrib);
	}
	
   
}

function ValidateZIP(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z0-9]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}
function ValidateUSState(Element, FieldAttrib)
{
	var objRegExp = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; 
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}


function ValidateUSZIP(Element, FieldAttrib)
{
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateEmail(Element, FieldAttrib)
{

	var objRegExp  = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/i;
	//var objRegExp= \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}
function ValidateNumeric(Element, FieldAttrib)
{
	var objRegExp  = /(^-?\d\d*$)/;
	if(FieldAttrib["Optional"])
	{	
		if(trim(Element.value)!="")
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						SetFocus(Element);                        
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						ok=false;
						//SetFocus(Element);                        
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						SetFocus(Element);                        
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						ok=false;
						//SetFocus(Element);                        
						return false;
					}
				}
			}
	}
}

function ValidateDecimal(Element, FieldAttrib)
{
	//alert(element);
	
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						SetFocus(Element);                        						
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						ok=false;
						SetFocus(Element);                        
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(parseFloat(Element.value)<parseFloat(FieldAttrib["Minimum"])){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						SetFocus(Element);                        
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
				
					if(parseFloat(Element.value) > parseFloat(FieldAttrib["Maximum"])){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						ok=false;
						SetFocus(Element);                        
						return false;
					}
				}
			}
	}
}






function ValidateAlphaNumeric(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z0-9\s]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateAlpha(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z\s]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateDate(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			
			checkDate(Element,Element.value, FieldAttrib["Format"], FieldAttrib,FieldAttrib["MINDATE"]);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))			
			checkDate(Element,Element.value, FieldAttrib["Format"], FieldAttrib,FieldAttrib["MINDATE"]);
	}
}
function ValidateCompareDate(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			
			compareDate(Element,Element.value, FieldAttrib["Format"], FieldAttrib,FieldAttrib["MINDATE"]);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))			
			compareDate(Element,Element.value, FieldAttrib["Format"], FieldAttrib,FieldAttrib["MINDATE"]);
	}
}

// New Added - 16-09-2010 - Start

function ValidateCompareDateAnother(Element, FieldAttrib) {    
    if (FieldAttrib["Optional"]) {
        if (trim(Element.value) != "")          
            compareDate(Element, Element.value, FieldAttrib["Format"], FieldAttrib, FieldAttrib["MINDATE"],FieldAttrib["Message"]);
    }
    else {        
        if (checkBlank(Element, FieldAttrib))
            compareDate(Element, Element.value, FieldAttrib["Format"], FieldAttrib, FieldAttrib["MINDATE"], FieldAttrib["Message"]);
    }
}

// New Added - 16-09-2010 - End



function ValidateRegExp(Element, FieldAttrib)
{
	
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
	else
	{
		
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
}

function ValidateString(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkStringMatch(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkStringMatch(Element, FieldAttrib);
	}	
}

function ValidateRadio(theForm, Element, FieldAttrib)
{
	for(var i=0;i<theForm[Element].length;i++)
	{
		if(theForm[Element][i].checked==true)
		{
			return true;
			break;
		}
	}
	ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
	ok=false;
	SetFocus(Element);    
	return false;
}

function ValidateCheckBox(theForm, Element, FieldAttrib)
{	  
	ElementName=Element;
	var NoOfChecked=0;
	if(FieldAttrib["Optional"])
	{
		if(FieldAttrib["Max"])
		{
			for(var i=0;i<theForm[ElementName].length;i++)
			{
				if(theForm[ElementName][i].checked==true)
					NoOfChecked++;
			}
			if(NoOfChecked!=0)
			{
				if(NoOfChecked>FieldAttrib["Max"])
				{
					ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
					ok=false;
					SetFocus(Element);                    
					return false;
				}
			}
		}
	}
	else
	{
		
		if(theForm[ElementName].length)
		{
			for(var i=0;i<theForm[ElementName].length;i++)
			{
				if(theForm[ElementName][i].checked==true)
					NoOfChecked++;
			}
		}
		else{
				
				if(theForm[ElementName].checked==true)
					NoOfChecked++;
					
					
		}
		if(NoOfChecked==0)
		{
		    
			ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
			
			ok=false;
			//SetFocus(Element);  
			return false;
		}
		else if(FieldAttrib["Max"])
		{
			if(NoOfChecked>FieldAttrib["Max"])
			{
				ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
				ok=false;
				SetFocus(Element);                
				return false;
			}
		}
	}
}
//function ValidateCheckBox(theForm, Element, FieldAttrib)
//{
//	ElementName=Element;
//	var NoOfChecked=0;
//	if(FieldAttrib["Optional"])
//	{
//		if(FieldAttrib["Max"])
//		{
//			for(var i=0;i<theForm[ElementName].length;i++)
//			{
//				if(theForm[ElementName][i].checked==true)
//					NoOfChecked++;
//			}
//			if(NoOfChecked!=0)
//			{
//				if(NoOfChecked>FieldAttrib["Max"])
//				{
//					ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
//					ok=false;
//					SetFocus(Element);                    
//					return false;
//				}
//			}
//		}
//	}
//	else
//	{
//		if(theForm[ElementName].length){
//			for(var i=0;i<theForm[ElementName].length;i++)
//			{
//				if(theForm[ElementName][i].checked==true)
//					NoOfChecked++;
//			}
//		}
//		else{
//				if(theForm[ElementName].checked==true)
//					NoOfChecked++;
//		}
//		if(NoOfChecked==0)
//		{
//			ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
//			ok=false;
//			SetFocus(Element);            
//			return false;
//		}
//		else if(FieldAttrib["Max"])
//		{
//			if(NoOfChecked>FieldAttrib["Max"])
//			{
//				ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
//				ok=false;
//				SetFocus(Element);                
//				return false;
//			}
//		}
//	}
//}

function ValidateComboBox(Element, FieldAttrib)
{
    
	if(Element.value<0 || Element.value==0)
	{
		ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
		ok=false;
		// SetFocus(Element);        
		return false;
	}
	else
	{
		Element.className ='TextBox';
	}
}

function ValidateConfirmPassword(theForm, Element, FieldAttrib)
{
	if(checkBlank(Element, FieldAttrib))
	{
		if(Element.value!=theForm[FieldAttrib["CompareTo"]].value)
		{
			ErrMsg+="- Password and Confirm Password should be same\n";
			ok=false;
			SetFocus(Element);            
			return false;
		}
		else
		{
		    Element.className ='TextBox';
		}
	}
}

function ValidateFileExtension(Element, FieldAttrib)
{

	
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
		{
			if(Element.Extensions)
			{
					
				ArrExt = new Array();
				ArrExt = FieldAttrib["Extensions"].split(",");
				Ext = Element.value.toUpperCase;
				for(var i=0;i<ArrExt.length;i++)
				{
					if(ArrExt[i].toUpperCase ==Ext.toUpperCase)
					return true;
					break;
				}
				
				ErrMsg+="- Only";
				for(var i=0;i<ArrExt.length;i++)
				{
					ErrMsg+=" "+ArrExt[i].toUpperCase();
				}
				ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
				ok=false;
				SetFocus(Element);                
				return false;
			}
		}
		
	}
	else
	{
		if(FieldAttrib["Extensions"])
		{
		
			ArrExt = new Array();
			
			ArrExt = FieldAttrib["Extensions"].split(",");
            
			Ext = Element.value.substr(Element.value.lastIndexOf(".")+0);
			
			for(var i=0;i<ArrExt.length;i++)
			{
			    
				if(ArrExt[i].toUpperCase()==Ext.toUpperCase())
				{
				    return true;
				    break;
				}
			}
			
			ErrMsg+="- Only";
			for(var i=0;i<ArrExt.length;i++)
			{
				ErrMsg+=" "+ArrExt[i].toUpperCase();
			}
			
			ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
			ok=false;
			//SetFocus(Element);            
			return false;
		}
	}
}
function isDateValid(fieldValue) 
{

	var doc = "document."
   // str=eval(doc+formName+"."+fieldName+".value");
	
	var dateStr=fieldValue;
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) 
	{
		//alert(msg);
		//eval(doc+formName+"."+fieldName + ".focus()");
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	
	if (month < 1 || month > 12) 
	{
		alert("Month must be between 1 and 12.");
		return false;
	}
	
	if (day < 1 || day > 31) 
	{
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	if (month == 2)
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
   		}
	}
	return true;
}
function isDecimal(fieldValue)
	{
		//formName='Form1';
		//msg='Invalid price';

		//var     doc = "document."
		//a=eval(doc+formName+"."+fieldName);
		//fieldValue=eval(doc+formName+"."+fieldName + ".value");
		
			if (fieldValue.length<1)
			{ return false;}
			//alert(fieldValue.length);
			if (fieldValue.length==1){chr=fieldValue.charAt(0);if(chr == '.'){ return false;}}

			chk1="123456789.0";
			var dot=0;
                for(i=0;i!=fieldValue.length;i++)
				{
						ch1=fieldValue.charAt(i);
						if (ch1 == '.')
						 {
							dot = dot + 1;
						 }
						rtn1=chk1.indexOf(ch1);
						if((rtn1==-1) || (dot>1))
						{
							 	//eval(doc+formName+"."+fieldName + ".focus()")
								return false;
								break;
						}
		        }
		    return true
	}
	
function changetoobject(Fieldname,FieldType)
{
	var	ret;
	var	i;
	//alert('Fieldname: '+ Fieldname);
	//alert('FieldType: '+ FieldType);
	//alert('frmname: '+ document.forms[0].name);
	var length = document.forms[0].elements.length;
	//alert('length: '+ length);
	
	for(i=1; i<=length-1;i++)
	{	
	          var obj=document.forms[0].elements[i];
			
				if(FieldType == 0)
				{
					var isobj = obj.name.indexOf(Fieldname)
					if(isobj >= 0) 
					{
						ret=obj;
						break;
					}
				}
				else
				{
					//alert('Id type');
					
					var isobj = obj.id.indexOf(Fieldname);
					//alert('id working');
					if(isobj >= 0) 
					{
					   // alert('id working................ yahooooooooooooooo');
						ret=obj;
						break;
					}
				}
		
	}
	
	return ret;
}



function getobjectstring(Fieldname,FieldType)
{
	//FieldType=1 = Object ID
	//FieldType=0 = Object Name
	var	ret;
	var	i;
	//alert('Fieldname: '+ Fieldname);
	//alert('FieldType: '+ FieldType);
	///alert('frmname: '+ document.forms[0].name);
	var length = document.forms[0].elements.length;
	
	
	for(i=1; i<=length;i++)
	{	
	          var obj=document.forms[0].elements[i];
	          
			  if(obj)
			  {
				if(FieldType == 0)
				{
					var isobj = obj.name.indexOf(Fieldname)
					if(isobj >= 0) 
					{   
						ret=obj.name;						
						break;
					}
				}
				else
				{
					
					
//					var isobj = obj.id.indexOf(Fieldname);
//					if(isobj >= 0) 
                    if(obj.id.substring(obj.id.length-Fieldname.length,obj.id.length)==Fieldname)
					{
						ret=obj.id;
						break;
					}
				}
			  }
		
	}
	
	return ret;
	
}


function numbersonly(e)
{
	//alert('hi');
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(e.keyCode);
	if (unicode!=8)
	{ //if the key isn't the backspace key (which we should allow)
	if (unicode!=46)
	{ //if the key is "."
	if (unicode<48||unicode>57) //if not a number
	return false //disable key press
	}
	}
}

function ChangeCheckBoxState(id, checkState)
{
  var cb = document.getElementById(id);
  if (cb != null)
	 cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState)
{
  // Toggles through all of the checkboxes defined in the CheckBoxIDs array
  // and updates their value to the checkState input parameter
  if (CheckBoxIDs != null)
  {
	 for (var i = 0; i < CheckBoxIDs.length; i++)
		ChangeCheckBoxState(CheckBoxIDs[i], checkState);
  }
}

function PressTextbox(TextCase, args)
{
	var key;
	
	key = event.keyCode;
	//This is Restricting to Enter '
	
	if (key == 39)
	{
		event.keyCode = 0;
		return false;
	}
	if(window.event || !event.which)
	{
		switch (TextCase)
		{
			case('0'): //Text = 0
			{
				break;
			}
			case('1'): //Upper = 1
			{
				if(key >= 97 && key <= 122)
				{
					event.keyCode = key - 32;
					return true;
				}
				break;
			}
			case('2'): //Lower = 2
			{
				if(key >= 65 && key <= 91)
				{
					event.keyCode = key + 32;
					return true
				}
				break;
			}
			case('3'): //Character = 3
			{
				if (!((key >= 65 && key <= 91) || (key >= 97 && key <= 122) || key == 32))
				{
					event.keyCode = 0;
					return true; 
				}
				break;
			}
			case('4'): //CharacterUpper = 4
			{
				if(key >= 97 && key <= 122)
				{
					event.keyCode = key - 32;
					key = key - 32;
				}
				if(!((key >= 65 && key <= 91) || (key == 32)))
				{
					event.keyCode = 0;
					return true; 
				}
				break;
			}
			case('5'): //CharacterLower = 5
			{
				if(key >= 65 && key <= 91)
				{
					event.keyCode = key + 32;
					key = key + 32;
				}
				if(!((key >= 97 && key <= 122) || (key == 32)))
				{
					event.keyCode = 0;
					return true; 
				}
				break;
			}
			case('6'): //Number = 6
			case('7'): //TwoDecimal = 7
			case('8'): //ThreeDecimal = 8
			case('9'): //Round = 9
			case('10'):  //PositiveNumber = 10
			case('11'): //PositiveTwoDecimal = 11
			case('12'): //PositiveThreeDecimal = 12
			case('13'): //PositiveRound = 13
			{
				var TextboxValue = new String();
				TextboxValue = args.value;
				//This if Condition for Positive Number if Not Positive Select then '-' is allowed
				if (TextCase != '10' && TextCase != '11' && TextCase != '12' && TextCase != '13')
				{
					if(key == 45)
					{
						if (TextboxValue == '')
						{
							return true;
						}
						else
						{
							return false;
						}
					}
				}
				//This if Condition for Positive Number if Not Positive Select then '-' is allowed
				
				//This if Condition for Decimal Number if Not Decimal Select then '.' is allowed
				if(TextCase != '9' && TextCase != '13')
				{
					if(key == 46)
					{
						if(TextboxValue.indexOf('.') == -1)
						{
							return true;
						}
						else
						{
							return false;
						}
					}
				}
				//This if Condition for Decimal Number if Not Decimal Select then '.' is allowed
				
				//This is basic checking of Numeric Number
				
				if(!(key >= 48 && key <= 57))
				{
					event.keyCode = 0;
					return true;
				}
				//This is basic checking of Numeric Number
				
				//This is Retriction of After '.'
				if (TextCase == '7' || TextCase == '8' || TextCase == '11' || TextCase == '12')
				{
					if(TextboxValue.indexOf('.') >= 0)
					{
						if (((TextboxValue.indexOf('.') == TextboxValue.length - 3) && (TextCase == '7' || TextCase == '11')) || ((TextboxValue.indexOf('.') == TextboxValue.length - 4) && (TextCase == '8' || TextCase == '12')))
						{
							event.keyCode = 0;
							return true;
						}
					}
				}
				//This is Retriction of After '.'
				break;
			}
			case('14'): //Financial Year
			{
				if(!(key >= 48 && key <= 57))
				{
					if(key!=45)
					{
						event.keyCode = 0;
						return true;
					}
				}
				break;
			}
			case('15'): //EMail
			{
				var i;
			    i = 1;
			    strVal=new String();
			    strVal=document.getElementById(args).value;
			    TextboxValue=document.getElementById(args).value;
			    
			    if(strVal.length == 0)
				    return true;
			    if (TextboxValue.indexOf('@') < 0)
				    i = 0;
			    if (TextboxValue.indexOf('.') < 0)
				    i = 0;
			    if (TextboxValue.indexOf('.') < TextboxValue.indexOf('@'))
				    i = 0;
			    if ((TextboxValue.indexOf('@') + 1) == TextboxValue.indexOf('.'))
				    i = 0;
			    if ((TextboxValue.indexOf('.') + 1) == TextboxValue.length)
				    i = 0;
			    if(i == 0)
			    {
				    alert("Invalid Email Id");	
				    document.getElementById(args).focus();
				    return false;
			    }
			    return true;
			    break;
			}
		}
	}
}
function CheckMaxLength(ControlName,MaxLen,ErrMesage)
{

    if(document.getElementById(ControlName).value.length>MaxLen)
    { 
        alert(ErrMesage);  
        document.getElementById(ControlName).focus(); 
        return false;
    }
     return true;
}

function SetFocus(Element)
{    
      
     Element.className ='TextBoxError';
     //Element.focus();
          
}
function numbersWithOutDotonly(e)
{
	//alert('hi');
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(e.keyCode);
	if (unicode!=8)
	{ //if the key isn't the backspace key (which we should allow)
//	if (unicode==46)
//	{ //if the key is "."
	if (unicode<48||unicode>57) //if not a number
	return false //disable key press
	//}
	}
}

function numbersWithDotonly(e)
{
	//alert('hi');
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(e.keyCode);
	if (unicode!=8)
	{ //if the key isn't the backspace key (which we should allow)
   if (unicode!=46)
	{ //if the key is "."
	if (unicode<48||unicode>57) //if not a number
	return false //disable key press
	}
	}
}
 function GetLatLong(websitepath)
 {
         url = websitepath+"ajaxfunctions.aspx?zip="+txt_zip.value+"&f=4";
     	 MM_findObj('divaddress').style.display='';
		 MM_findObj('divchildaddress').innerHTML = "<p align='center'>Looking for Longitue and Latitue .... <BR>Please wait</p>";
		 fetch_remote_page(url, "divchildaddress", '', '4');
 }  
 
function toggleLangPanel(link_id, panel_id)
{
     var link_element = document.getElementById(link_id);
     var panel_element = document.getElementById(panel_id);

     if (panel_element.style.display == 'none' || panel_element.style.display == '') {
     link_coords = getLangCoords(link_id);

     panel_top = (link_coords.y + link_element.offsetHeight) + 'px';
     panel_left = link_coords.x - 100 + 'px';

     panel_element.style.top = panel_top;
     panel_element.style.left = panel_left;

     panel_element.style.visibility = 'visible';
     panel_element.style.display = 'block';
     } else {
     panel_element.style.display = 'none';
     panel_element.style.visibility = 'hidden';
     }

     if (parent.calcHeight) {
     parent.calcHeight();
     }

     link_element.blur();
}
function getLangCoords(id)
{
     var x = 0
     var y = 0;

     element = document.getElementById(id);

     if (element.offsetParent){
     while (element.offsetParent){
     x += element.offsetLeft;
     y += element.offsetTop;
     element = element.offsetParent;
     }
     } else if (element.x || element.y) {
     x = element.x;
     y = element.y;
     }

     /* IE bug */
     x += document.body.offsetLeft;
     y += document.body.offsetTop;

     return { x:x, y:y };
}

function AlertMessage(CtrlValue, ErrNo)
{
	var ErrStrg=new Array();
//	ErrStrg[0]=CtrlValue;
//	ErrStrg[1]=CtrlValue + ' ' + "should not be blank";
//	ErrStrg[2]=CtrlValue + ' ' + "already exist, Duplicate not allowed";
//	ErrStrg[3]=CtrlValue + ' ' + "should be between " + MinValue + " and " + MaxValue + "";
//	ErrStrg[4]=CtrlValue + ' ' + "should be less than " + MinValue + "";
//	ErrStrg[5]=CtrlValue + ' ' + "should be greater than " + MaxValue + "";
//	ErrStrg[6]=CtrlValue + ' ' + "should be selected";	
//	ErrStrg[7]="Invalid" + ' ' + CtrlValue;
//	ErrStrg[8]=CtrlValue + ' ' + "record not found";
//	ErrStrg[9]=CtrlValue + ' ' + ", Delete not allowed";
//	ErrStrg[10]=CtrlValue + ' ' + ", Edit not allowed";
//	ErrStrg[11]="Delete not allowed"; // Grid
//	ErrStrg[12]="Edit not allowed"; //Grid
//	ErrStrg[13]="Selected record does not exist, it may be already deleted"; // Grid
//	ErrStrg[14]="Selected record does not exist, it may be already deleted, can not edit "; //Grid
//	
//	ErrStrg[15]=CtrlValue + ' ' + "should be less or equal to " + MinValue + "";
//	ErrStrg[16]=CtrlValue + ' ' + "should be greater or equal to " + MaxValue + "";
	alert(CtrlValue);
}
function SpecialCharkeypress(event)
    {    
	    var key;
	   // alert('in fun');
	    key = event.keyCode || event.which;	  	    
	    // alert('key: ' + key);
	    if(event.which == 0)
	           key = event.which;
	
	    //key == 37 || key == 39 || key == 8 || key == 46 || key == 34
	    	    
	    if (key == 33 || key == 64 || (key >= 35 && key <= 38) || key == 94 || key == 34 || key == 126)
	    {   
		    return false;
	    }
	    else
	    {   
		    return true;
	    }
    }
    
    	var i, j, strlen; 
	var strchar = new String("");
	
function LTrim(StringToTrim)
{
	StringToTrim = new String(StringToTrim);

//	This function trims a string from the left edge
	for(i = 0 ;i < StringToTrim.length; i++)
	{
		strchar = StringToTrim.charAt(i);
		if ( (strchar == " ") || (strchar == "\t") || (strchar == "\n") || (strchar == "\r") )
		{
			StringToTrim = StringToTrim.substr(i+1);
			i--;
		}
		else
			break;
	}
	return StringToTrim;
}

function RTrim(StringToTrim)
{
//	alert("In RTrim");
	StringToTrim = new String(StringToTrim);
//	alert("After");
//	alert(StringToTrim.length);
	
//	This function trims a string from the right edge
	for(i = StringToTrim.length - 1 ; i > -1 ; i--)
	{
//		alert("In For");
		strchar = StringToTrim.charAt(i);
		if ( (strchar == " ") || (strchar == "\t") || (strchar == "\n") || (strchar == "\r") )
		{
			StringToTrim = StringToTrim.substr(0,i);
		}
		else
			break;
	}
	return StringToTrim;
}

function Trim(StringToTrim)
{
//	This function trims a string
//	for triming a string it will call the LTrim and RTrim function
	return  LTrim(RTrim(StringToTrim));
}

function isValidInteger(strNumber)
{
	if(strNumber<0)
	{	  
		strNumber=strNumber.substring(1)  
	}   
	strNumber = new String(strNumber);
	strlen = strNumber.length;
	for( i = 0;i < strlen ;i++)
	{
		strchar = strNumber.charAt(i);
		if (isNaN(strchar) == true)
			return false;
	}
	// Valid Integer number
	return true;
}

function validateNNInteger(objControl)
{
	// Checking that the passing Number Should Be Integer And Should Be Greater Than Or Equal To 1
	
	// If The Function Is Called And The Control Is Not Exist
	// Then Simply Return From This Function
	if(!objControl)
	{
		return;
	}
	
	if(objControl.readOnly)
		return true;
		
	strNumber = objControl.value;
 	var num = BackToMoney(strNumber);
 	
 	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	if(parseFloat(num) < 0)
	{
		objControl.value = num;
		objControl.select();
		alert("The IRS does not permit a negative number in this field. Please re-enter your data.");
		objControl.value = "0";	
		setTimeout(function(){ objControl.focus(); objControl.select(); },1);
		return false;
	}
	
/*	if(num<0)
	{	  
		num=num.substring(1)  
	}   
	num = new String(num);
	strlen = num.length;
	for( i = 0;i < strlen ;i++)
	{
		strchar = num.charAt(i);
		if (isNaN(strchar) == true)
		{	
			objControl.value = 0;		
			return false;
		}
	}	*/
	// Valid Integer number
	objControl.value = parseInt(num);
	return true;
}
function RoundDecimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)

    if (isNaN(result3))
		return "0.00";
	else
		return pad_with_zeros(result3, decimals);
}

function validateNNFLOAT(objControl)
{
	// ============================================================================================
	// Added By Amit On 5th October, 04
	// So The Negative Number Error Don't Show On A ReadOnly Textbox
	// That Error Virtually Hang The Browser
	// To Solve This We Just Return From The Function If The Caller
	// TextBox Is ReadOnly
	
	// If The Function Is Called And The Control Is Not Exist
	// Then Simply Return From This Function
	alert(objControl);
	if(!objControl)
	{
		return;
	}
	
	if(objControl.readOnly)
		return true;
	
	// End Of Comment By Amit On 5th October, 04
	// ============================================================================================
		
	strNumber = objControl.value;
//	alert ("B:strNumber = " + strNumber)
 	var num = strNumber;
//	var vName;
 	
 	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	if(parseFloat(num) < 0)
	{
		objControl.value = num;
		objControl.select();
		//vName = objControl.name;
		//alert("The IRS does not permit a negative number in this field. Please re-enter your data. ("+vName +")");
		alert("The IRS does not permit a negative number in this field. Please re-enter your data.");
		objControl.value = "0";	
		setTimeout(function(){ objControl.focus(); objControl.select(); },1);
		return false;
	}

	num = Math.abs(num);
	
	num = Math.floor(num*100+0.50000000001);
//	cents = num%100;
	num = Math.floor(num/100).toString();

//	if(cents<10)
//		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	
	num.substring(num.length-(4*i+3));
	
	var rtnValue;
	
//	rtnValue = num + '.' + cents;
	rtnValue = num;
	
	objControl.value = rtnValue;
//	objControl.value = Math.round(rtnValue);
	return true;
}
function BackToMoney(num) 
{

	//*** ===================================================================================================
	//*** Added By Amit On 6th May, 05
	
	//*** Added To Remove Decimal(.) From The End Of The Number (I.e 3000. To 3000)
	
	num = new String(num);
	if(num.lastIndexOf('.') > 0)
	{
		if(num.lastIndexOf('.') == (num.length-1))
		{
			num = num.substr(0,(num.length-1));
		}
	}

	//*** End Of Addition By Amit On 6th May, 05
	//*** ===================================================================================================

//	alert("num = " + num);
	num = num.toString().replace(/\$|\,/g,'');
	
	//*** ===================================================================================================
	//*** Added By Amit On 17th November, 04
	
	//*** Based On Ticket No. 256 (Add calculator to system) On Zentrack
	
	//*** The Below Code Will Calculate The Value If The Value Contain Any Of The
	//*** Four Simple Arithmetic Sign (+,-,* and /). Than That Calculate Value
	//*** Will Be Used For Further Processing.
	
	//var valid="1234567890.+-*/()%";
	var valid="1234567890.+-*/";
	var validSign = "+-*/.";
	var invalidSignFirstPos = "*/";
	var intValidSignPos, boolValidSignPos;
	intValidSignPos = 0;
	boolValidSignPos = false;
	var strnum = String(num);
	if(strnum.length == 0 || invalidSignFirstPos.indexOf(strnum.charAt(0))!= -1 || (strnum.length == 1 && validSign.indexOf(strnum.charAt(0))!= -1) || (validSign.indexOf(strnum.charAt(strnum.length -1))!= -1) )
	{	
		strnum = "0";
		num = 0;
	}
	var boolValid = true;
	for(i=0;i<strnum.length;i++)
	{
		if(valid.indexOf(strnum.charAt(i))==-1)
		{
			boolValid = false;
			i = strnum.length;
		}
		else
		{
			if(validSign.indexOf(strnum.charAt(i))!= -1)
			{
				if(boolValidSignPos == false)
				{
					intValidSignPos = i
					boolValidSignPos = true;
				}
				else
				{
					if(i - intValidSignPos <= 1)
					{
						boolValid = false;
						i = strnum.length;
					}
					else
					{
						intValidSignPos = i;
						boolValidSignPos = true;
					}
				}
			}
		}
	}	
	if(boolValid == true)
		num = eval(num);
	
	//*** End Of Addition By Amit On 17th November, 04
	//*** ===================================================================================================

//	alert("num = " + num);
	if(isNaN(num))
		num = "0";
		
	num = (Math.round(num));
//	alert("num = " + num);
	
	if(parseFloat(num) < 0)
		sign = "-"
	else
		sign = ""
	//sign = (num == (num = Math.abs(num)));
	num = Math.abs(num);
//	alert("sign = " + sign);
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num.substring(num.length-(4*i+3));
		
//	alert("num = " + num);
//	alert("cents = " + cents);
	
	var rtnValue;
	
	if(sign == "")
		rtnValue = num + '.' + cents;
	else
		rtnValue = '-' + num + '.' + cents;

//	rtnValue = num + '.' + cents;
	
//	alert(rtnValue);
	
	return rtnValue;
	
//	return (((sign)?'':'-') + num + '.' + cents);
}

function validateNumberLength(strNumber, intLen)
{
	strNumber = new String(strNumber);
	if (strNumber.length != intLen)
		return false;
	else
		return isValidInteger(strNumber);
}

function IsDecimalNumeric(obj)

{
   var sText  = obj.value;
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
    
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   if (IsNumber == false)
        obj.value = '0.00';
   if (sText=='')
        obj.value = '0.00';
   }
function IsNumeric(obj)

{
   var sText  = obj.value;
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      
      if (ValidChars.indexOf(Char) == -1) 
         {
            IsNumber = false;
         }
     }
     if (IsNumber == false)
        obj.value = '0';
   if (sText=='')
        obj.value = '0';
   }
   
function addCommas(obj)
{
    // alert(obj);
    var nStr = obj.value;
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	obj.value = (x1 + x2);
}

function CheckNumeric(e,cnt) {
var k;
document.all ? k = e.keyCode : k = e.which;
var srcVal = e.srcElement != null ? e.srcElement.value : e.target.value ;

if(srcVal.indexOf('.') > -1)
{
    if(k == 46) return false;
    if(srcVal.substring(srcVal.indexOf('.'),srcVal.length).length>cnt)
    {
        return false;
    }
}
return ((k >= 48 && k <= 57) || k == 45 || k == 46 || k == 8 || k==0);
}



