var intCheckError=0;
var strMsg='';
var dtCh= "/";/////////////////////////////////////////////////////NUMERIC,EMPTY VALUE 

function checkEmail()
     {
     
     if (document.getElementById('txtemail').value!="")
     {
       if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('txtemail').value))
        {
        return (true)
        }
        alert("Invalid E-mail Address! Please re-enter.")
        return (false)
    }
    }



function CheckNumeric(AddingText,objTxtBox)
{
	if (objTxtBox.value==null||objTxtBox.value=='')
	{
		strMsg=AddingText+" Should be Entered";
		intCheckError=1;
		alert(strMsg);		objTxtBox.focus();		
	}
	
	else if (isNaN(objTxtBox.value))
	{
		strMsg=AddingText+" Should be Numeric";
		intCheckError=1;
		alert(strMsg);
		objTxtBox.focus();
	}
	else
	{
	intCheckError=0;
	}
}

///////////////////////////////////////////PHONE NO FORMATTING
	function  formatPhone(AddingText,objTxtBox)
	 {
		y=objTxtBox.value;
		abc=/-/gi;
		rep=y.replace(abc,0)
		if (isNaN(rep))
		{
		   
		ab=/(a*)(b*)(c*)(d*)(e*)(f*)(g*)(h*)(i*)(j*)(k*)(l*)(m*)(n*)(o*)(p*)(q*)(r*)(s*)(t*)(u*)(v*)(w*)(x*)(y*)(z*)/gi;
		re=y.replace(ab,"")
		objTxtBox.value="";
		strMsg=AddingText+" Should be numeric or - ";
		intCheckError=1;
		alert(strMsg);
		objTxtBox.focus();
		
		}
		else
		{
		yy=y.length;
		if(yy==3)
		{
		y=y+"-";
		}
		if(yy==7)
		{
		y=y+"-";
		}
		objTxtBox.value=y;
		}
	}
///////////////////////////////////////////ZIP FORMATTING
	function  formatZip(AddingText,objTxtBox)
	 {
		y=objTxtBox.value;
		abc=/-/gi;
		rep=y.replace(abc,0)
		if (isNaN(rep))
		{
		   
		ab=/(a*)(b*)(c*)(d*)(e*)(f*)(g*)(h*)(i*)(j*)(k*)(l*)(m*)(n*)(o*)(p*)(q*)(r*)(s*)(t*)(u*)(v*)(w*)(x*)(y*)(z*)/gi;
		re=y.replace(ab,"")
		objTxtBox.value="";
		strMsg=AddingText+" Should be numeric or - ";
		intCheckError=1;
		alert(strMsg);
		objTxtBox.focus();
		
		}
		else
		{
		yy=y.length;
		if(yy>5)
		{
		strMsg=AddingText+" Cannot exceed 5 digits";
		intCheckError=1;
		alert(strMsg);
		objTxtBox.focus();
		}
		objTxtBox.value=y;
		}
	}/////////////////////////////////////////////////////NUMERIC VALUE ONLY
function CheckOnlyNumeric(AddingText,objTxtBox)
{		if (objTxtBox.value!=null||objTxtBox.value!='')		{
			 if (isNaN(objTxtBox.value))
			{
				strMsg=AddingText+" Should be Numeric";
				intCheckError=1;
				alert(strMsg);
				objTxtBox.focus();				objTxtBox.value="";			
			}
			else
			{
				intCheckError=0;
			}
		}	else		{			intCheckError=0;
		}
}

//////////////////////////////////////////////////DATE VALIDATION
var minYear=1900;
var maxYear=2030;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) 
        {
        alert("Please enter integer values for discount")
        return false;
        }
    }
    // All characters are numbers.
    return true;
}


///////////////////////////////////////////////////////////////EMAIL VALIDATION
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function chkEmail(objText)
{
	var emailID=objText;
	
	if ((emailID.value!=null)&&(emailID.value!=""))
	{
		if (echeck(emailID.value)==false)
		{
			emailID.value="";
			emailID.focus()
			intCheckError=1;
			return false
		}
	}
	intCheckError=0;
	return true
 }
 /////////////////////////////////////INVALID CHARACTERS
 function chkChar(AddingText,objTxtBox)
	{
		intCheckError=0;
		var MyStr=objTxtBox.value;
		var whildChar=new Array(28); //it holds the array of all the invalidcharecters
		whildChar[0]='~';
		whildChar[1]='`';
		whildChar[2]='!';
		whildChar[3]='@';
		whildChar[4]='#';
		whildChar[5]='$';
		whildChar[6]='%';
		whildChar[7]='^';
		whildChar[8]='*';
		whildChar[9]='(';
		whildChar[10]=')';
		whildChar[11]='+';
		whildChar[12]='=';
		whildChar[13]='\\';
		whildChar[14]='/';
		whildChar[15]='<';
		whildChar[16]='>';
		whildChar[17]='?';
		whildChar[18]='|';
		whildChar[19]='.';
		whildChar[20]='\'\'';
		whildChar[21]='\"';
		whildChar[22]='\'';
		whildChar[23]='\.';
		whildChar[24]=';';
		whildChar[25]='-';
		whildChar[26]='_';
		for (i=0;i<27;i++)
		{
		   if (MyStr.indexOf(whildChar[i])!=-1 )
		   {
			strMsg=AddingText+" Can't Contain Invalid Characters";
			intCheckError=1;
			alert(strMsg);
			objTxtBox.value="";			objTxtBox.focus();
			break;
			}
		}
		 
		}
		
		/*Date validation code*/
    
    function checkdate(input)
    {
    
       if(input.value.length==0)
          return;
        var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
        var returnval=false
        if (!validformat.test(input.value))
           alert("Invalid Date Format. Please correct it to (mm/dd/yyyy).")
        else
           { //Detailed check for valid date ranges
            var monthfield=input.value.split("/")[0]
            var dayfield=input.value.split("/")[1]
            var yearfield=input.value.split("/")[2]
            var dayobj = new Date(yearfield, monthfield-1, dayfield)
            if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
               alert("Invalid Day, Month, or Year range detected. Please correct it to (mm/dd/yyyy).")
            else
               returnval=true
           }
        if (returnval==false) input.select()
        return returnval
    }

/*End of Date validation*/


 function hideTreeID(id)
   {
      document.getElementById(id).style.display="none";
   }

