 var flag = false;

function clear(element){
	element.value = "";
	element.focus();
}

/* This function is invoked to validate contact us details*/  
function contactUs(){
    var valid=true;
	var incidentDate= new Date(document.getElementById('incidentDate').value);
    var expiryDate= new Date();
    var form = document.getElementsByTagName("form")[0];	
	form.setAttribute("target", "_parent");
    if(isBlank(document.getElementById('firstName').value)){
        alert(firstNameNull);
        document.getElementById('firstName').focus();
        return false;
    }else if(isBlank(document.getElementById('lastName').value)){
        alert(lastNameNull);
        document.getElementById('lastName').focus();
        return false;
    }else if(isBlank(document.getElementById('email').value)){
        alert(emailNull);
        document.getElementById('email').focus();
        return false;
    }else if(checkemail(document.getElementById('email'))){
        alert(emailInvalid);
        document.getElementById('email').focus();
        return false;
    }else if(!isBlank(document.getElementById('country').value)&&!isAlpha(document.getElementById('country').value)){
        alert(countryAlpha);
        document.getElementById('country').focus();
        return false;
    }else if(!isBlank(document.getElementById('zip').value) && !checkLength(document.getElementById('zip').value, 5)){
        alert(zipLength);
        document.getElementById('zip').focus();
        return false;
    }else if (!isBlank(document.getElementById('zip').value) && !checkValidZip(document.getElementById('zip').value, 5)){
        alert(zipInvalid);
        document.getElementById('zip').focus();
        return false;
    }else if(!isBlank(document.getElementById('zipLast').value) && !isNumericOnly(document.getElementById('zipLast').value)){
        alert(zipLastOnlyNumber);
        document.getElementById('zipLast').focus();
        return false;
    }else if(checkZipLast(document.getElementById('zipLast'))){
        alert(zipLastLength);
        document.getElementById('zipLast').focus();
        return false;
    }else if(!isBlank(document.getElementById('phone').value) && !checkLength(document.getElementById('phone').value, 3)){
        alert(phoneInvalid);
        document.getElementById('phone').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneMiddle').value) && isBlank(document.getElementById('phone').value)){
        alert(phoneNull);
        document.getElementById('phone').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneLast').value) && isBlank(document.getElementById('phone').value)){
        alert(phoneNull);
        document.getElementById('phone').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneMiddle').value) && !checkLength(document.getElementById('phoneMiddle').value, 3)){
        alert(phoneInvalid);
        document.getElementById('phoneMiddle').focus();
        return false;
    }else if(!isBlank(document.getElementById('phone').value) && isBlank(document.getElementById('phoneMiddle').value)){
        alert(phoneNull);
        document.getElementById('phoneMiddle').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneLast').value) && isBlank(document.getElementById('phoneMiddle').value)){
        alert(phoneNull);
        document.getElementById('phoneMiddle').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneLast').value) && !checkLength(document.getElementById('phoneLast').value, 4)){
        alert(phoneInvalid);
        document.getElementById('phoneLast').focus();
        return false;
    }else if(!isBlank(document.getElementById('phone').value) && isBlank(document.getElementById('phoneLast').value)){
        alert(phoneNull);
        document.getElementById('phoneLast').focus();
        return false;
    }else if(!isBlank(document.getElementById('phoneMiddle').value) && isBlank(document.getElementById('phoneLast').value)){
        alert(phoneNull);
        document.getElementById('phoneLast').focus();
        return false;
    }else if(!timeOfContact(document.getElementById('timeOfContact').value)){
        alert(timeOfContactInvalid);
        document.getElementById('timeOfContact').focus();
        return false;
    }else  if(!isBlank(document.getElementById('incidentDate').value)&& checkDate(document.getElementById('incidentDate').value)){
        alert(InvalidDate);
        document.getElementById('incidentDate').focus();
        return false;
    }else if(isBlank(document.getElementById('incidentDate').value)&&(document.getElementById('incidentTime').options[document.getElementById('incidentTime').selectedIndex].value!="Choose")&& checkTime(document.getElementById('incidentTime').value)){
        alert(InvalidDateValidTime);
        document.getElementById('incidentDate').focus();
        return false;
    }else if(!isBlank(document.getElementById('incidentDate').value) && (document.getElementById('incidentTime').options[document.getElementById('incidentTime').selectedIndex].value=="Choose")){
 		alert(InvalidTimeValidDate);
  		document.getElementById('incidentTime').focus();
   		return false;
	}else if(!isBlank(document.getElementById('incidentDate').value)&&(expiryDate.getYear() == incidentDate.getYear())&&(expiryDate.getMonth() == incidentDate.getMonth())&&(expiryDate.getDate() == incidentDate.getDate())
		&& !checkTime(document.getElementById('incidentTime').value)){
		alert(InvalidTime);
		document.getElementById('incidentTime').focus();
		return false;
	}else if(isBlank(document.getElementById('comments').value)){
        alert(commentsNull);
        document.getElementById('comments').focus();
        return false;
    }else if(lTrim(document.getElementById('comments').value)==""){
        alert(commentsNull);
        document.getElementById('comments').focus();
        return false;
    }else if((document.getElementById('comments').value.length )> '2000'){
        alert(TextLongInvalid);
        document.getElementById('comments').focus();
        return false;
    }else{ 
        document.forms[0].submit();
        return true;
    }       
}
 
function checkDate(date){
	var incidentDate= new Date(date);
	var expiryDate= new Date();
	if(incidentDate.getYear()>expiryDate.getYear())
	{
	return true;
	} 
	else if(incidentDate.getYear()<expiryDate.getYear())
	{
	return false;
	}
	else
	if((incidentDate.getMonth()+1<expiryDate.getMonth()+1)){
	return false;
	}
	else if(incidentDate.getMonth()==expiryDate.getMonth()){
		if(incidentDate.getDate()>expiryDate.getDate())
			return true;
			else
			return false;
	}
	else
	return true;
}
 
function checkTime(time){
	var incidentTime= new Date();
	var newTime=parseInt(time.substring(0,time.indexOf(".")));
	if(time.indexOf("AM")==-1){
		newTime=newTime+12;
	}
    if(time.indexOf("AM") && time=="12.00AM"){
        return true;
    }
    if(newTime!=12 && newTime > incidentTime.getHours()){
        return false;
    }
    else{
    return true;
    }
} 


function checkName(field){
    var testresults=false;
    var filter=/^([a-zA-Z]+((?:\-*)*[a-zA-Z]+)*)(( )*) ([a-zA-Z]+((?:\-*)*[a-zA-Z]+)*)$/i
    //var filter=/^([a-zA-Z]+(?:\.[a-zA-Z]+)*)(( )*) ([a-zA-Z]+(?:\-[a-zA-Z]+)*)$/i
     field = trimText(field);
     if((field.length==0)){
        testresults=false;
    }
    else{
    if (filter.test(field)){
      testresults=false;
    }
    else{
       testresults=true;
    }
   }
   return testresults;
}


function checkAlpha(field){
    var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
    var temp = trimText(field);
    var al = true;
    var ret = true;
    var retu = 1;
    if(temp.length==0){
        ret = false;
        retu = 3;
    }
    else{
        for(i=0;i<temp.length;i++)
            {
                 for(j=0;j<alpha.length;j++){
                    if(temp.charAt(i) == alpha.charAt(j)){
                        retu = 1;
                        break;
                    }
                    if(j==alpha.length-1){
                        retu=3;
                        break;
                    }
                    if(retu==3){
                       break;
                    }
                    }
            }
    
        if(retu!=3){
            for(i=0;i<temp.length;i++)
            {   
                if(temp.charAt(i) == ' '){
                    retu = 1;
                    break;
                }
                if(i == temp.length-1){
                retu =2;
                break;
                }
            }
        }        
    }
    return retu;
}

/* This function is invoked to validate the zipcode*/    
/*function zip(){
   var formValid = true ;
   var str ="Please enter valid"+"\n";
   if(isBlank(document.zipCheckForm.zipCode.value)||isZipCode(document.zipCheckForm.zipCode)){
        formValid = false;
    }
    if(!formValid) {
        str = str+"-ZipCode"+"\n";
        alert(str);
        return false;  
    }
    else if(formValid) {
      return true;
    }
}
*/


function zip() //Used
{   
    var formValid = true;
    var zipLength = true;
    var str ="Please enter valid"+"\n";
    var regZip = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    if (document.zipCheckForm.zipCode.value == '')
    {
    	
        formValid = false;
        document.zipCheckForm.zipCode.focus();
        
    }
    
    else if (document.zipCheckForm.zipCode.value != '' && !regZip.test(document.zipCheckForm.zipCode.value))
    {
        zipLength = false;
        document.zipCheckForm.zipCode.focus();
        
    }
    
    else if (document.zipCheckForm.zipCode.value.indexOf("00000") != -1)
    {
        formValid = false;
        document.zipCheckForm.zipCode.focus();
        
    }
    else if(document.zipCheckForm.zipCode.value.charAt(0)=="0" && document.zipCheckForm.zipCode.value.charAt(1)=="0")
    {
       formValid = false;
       document.zipCheckForm.zipCode.focus();
      
    }
    else if(isZipCode(document.zipCheckForm.zipCode))
    {
       formValid = false;
       document.zipCheckForm.zipCode.focus();
      
    }
    if(!zipLength) {
        alert("Your zip code must be five digits long. Please re-enter your zip code");
        return false;  
    }
    if(!formValid) {
        str = str+"-Zip Code"+"\n";
        alert(str);
        return false;  
    }
    else if(formValid || zipLength) {
      return true;
    }
}

/* This function is invoked to check for last 4 digits of the zipcode*/    
function checkZipLast(field){
    //var invalid = false;
    var checkOK = "0123456789";
    if((field.value.length==0)) {
      return  false;
    }
    else {
    if ((field.value.length < 4) ) {
      return  true;
    }
    else{
        for(i=0; i < field.value.length; i++){
            ch = field.value.charAt(i);
            for (j = 0;  j < checkOK.length;  j++) {
                if (ch == checkOK.charAt(j)){
                    break;
                }
                if (j == (checkOK.length-1)){
                  return  true;
                    break;
                }
            }        
        }
    }
   } 
}

/* This function is invoked to check for first 5 digits of the zipcode*/    
function isZipCode(field){
    var invalid = false;
    var checkOK = "0123456789";
    if ((field.value.length != 5) ){
        invalid = true;
    }    
    return invalid; 
}




/* This function is invoked to validate the reset email*/ 
function resetforemail(email){
	email.value = "";
	email.focus();
}

/* This function is invoked to validate the reset hint answer*/ 
function resetforhintanswer()
{
	document.forms[0].hintAnswer.value = "";
	document.forms[0].hintAnswer.focus();
}

/* This function is invoked to check for integer*/    
function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

/* This function is invoked to strip the characters*/    
function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}



/* This function is invoked to check for valid date*/    
function isDate(dtStr){

	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
    
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1);
    var daysInMonth = new Array(11);
    for (var i = 0; i < daysInMonth.length; i++) {
        daysInMonth[i] = 31;
        if (i==3 || i==5 || i==8 || i==10) {daysInMonth[i] = 30;}
        if (i==1) {daysInMonth[i] = 29;}
   }
    
    strYr=strYear;
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=parseInt(strMonth)-1
    day=parseInt(strDay)
    year=parseInt(strYr);    
    if (pos1==-1 || pos2==-1){
        return false;
    }
    if (strMonth.length<1 || month<0 || month>12){

       return false;
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert(day > daysInMonth[month]);             
           return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

        return false;
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
    
        return false;
    }
return true;
}
/* This function is invoked to check for days in February*/    
function daysInFebruary (year){

    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

/* This function is invoked to check for the number of days in a month*/    
function DaysArray(n) {
    var arr = new Array(11);
    for (var i = 0; i < n; i++) {
        eval("arr["+i+"] = 31");
        if (i==3 || i==5 || i==8 || i==10) {eval("arr["+i+"] = 30");}
        if (i==1) {eval("arr["+i+"] = 29");}
   } 
    return arr;
}

//Function to check the text length for Description of Technical Problems
//function used nowhere
  /*function isTextLong(form,txtName){
   
  var str = eval("document."+form+"."+txtName+".value");
  if(str.length >254){
    alert(TextLongInvalid);
  }
   else{
     document.forms[0].submit();
   }
  }*/

//Function to check the text length for Comments
  function isTextLongMax(form,txtName){
   
  var str = eval("document."+form+"."+txtName+".value");
  if(str.length >2000){
    alert(TextLongInvalid);
  }
   else{
     document.forms[0].submit();
   }
  }
  
//Function to trim the blank space of a string at the  beginning and at end 
  function trimText(str)
  {
     str = str.value  
     strlen = str.length;
      for(i=0;i<strlen;i++)
        {  
       if(str.charAt(i)!=" "){
            str = str.substring(i,strlen);
            break;
         }
      }
      strlen = str.length;
      
      return str;
  }

function timeOfContact(str)
{
    //var str=trim(str);
    var ctrI;
    var strLength = str.length;
    var validStr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:. ";
    for (ctrI = 0; ctrI < strLength; ctrI++) {
       if (validStr.indexOf(str.charAt(ctrI)) == -1){
          return false;
        }
    }
   return true;
}


function onkeymyacc(that,num,e) {
           var key = e.keyCode;
  
           if(navigator.userAgent.indexOf('Opera') == -1 ){
               if(!(key == "8" || key=="46" || key == "9" || key == "16" || key == "13")){
	                if(flag == true){
                        that.value='';
	                    flag = false;
	                }
                 if (that.value.length == 3 && flag == false) {
                    var txtName = eval("document.forms[0]."+num);
                    if(txtName.value.length > 0){
                        txtName.value='';
                    }
                    txtName.focus(); 
                }
              }
           }else{
               if(!(key == '0' || key == "8" || key == "9" || key == "16" || key == "13")){
                if(flag == true){
                    that.value='';
                    flag = false;
                }
                if (that.value.length == 3 && flag == false) {
                    var txtName = eval("document.forms[0]."+num);
                    if(txtName.value.length > 0){
                        txtName.value='';
                    }
                    txtName.focus(); 
                }
            }
           }   
    }
    
    
    //contact us
    var firstNameNull = "Please enter first name.";
    var lastNameNull = "Please enter last name.";
    var nameNull="Please enter the name.";
    var nameInvalid="Please enter valid name.";
    var incidentDateInvalid="Please enter in date format.";
    var commentsNull="Please enter your comments.";
    var streeNull="Please enter your street address.";
    var incidentDateInvalid="Please enter a valid Incident Date.";
    var commentsNull="Please enter the comments.";
    var unitInvalid="You entered special characters that cannot be read by our system.";
    var zipLastInvalid="Please enter a valid zip code 2 add-on.";
    var timeOfContactInvalid="Best Time to contact can contain only alphabets and time information. Please re-enter.";
    var TextLongInvalid="The text in the Comments field cannot exceed 2000 characters.";
    var invalidDescription="The text in the Description field cannot exceed 254 characters.";
    var InvalidDate="Incident date should not be after current date.";
    var InvalidTime="Incident time should not be after current time.";    
    var phoneEmpty="Please enter your phone number.";
    var pscNumberInvalid = "Please enter valid PSC number.";
    var InvalidTimeValidDate = "Please enter valid time.";
    var InvalidDateValidTime = "Please enter valid date.";
    var CommentsInval = "Comments can contain only alpha-numeric characters and some special characters like (-!,@*\"()'$&%:). Please re-enter.";  
    var DescInval = "Description of the problem can contain only alpha-numeric characters and some special characters like (-!,@*\"()'$&%). Please re-enter.";
    var NoteInsructInval = "Notes & Instructions of the problem can contain only alpha-numeric characters and some special characters like ?$\"\\,()&<>@|;+ . Please re-enter.";    
    var storeAddressAlphaNumeric="Store Address can contain only alpha-numeric characters and special characters like &. Please re-enter.";
    var emailInvalid="Please enter a valid E-mail address, using the format username@subdomain.domain.";
    var firstNameAlphaNumeric="You entered special characters that cannot be read by our system. Please re-enter your first name.";
    var lastNameNull="Please enter your last name.";
    var lastNameAlphaNumeric="You entered special characters that cannot be read by our system. Please re-enter your last name.";
    var firstNameOnlyNumber="First Name should not contain only numbers.";
    var middleNameOnlyNumber="Middle Name should not contain any number.";
    var lastNameOnlyNumber="Last Name should not contain only numbers.";
    var emailNull="Please enter your e-mail address.";
    var streetNull="Please enter your street address.";
    var streetNumeric="Your street address cannot contain only numeric characters. Please re-enter";
    var streetInvalid="Your street address cannot contain any special characters. Please re-enter your address using letters and numbers.";
    var cityNull="Please enter your city of residence.";
    var cityAlpha="Your city can contain only alphabets. Please re-enter."; 
    var countryAlpha="Your country can contain only alphabets. Please re-enter.";
    var phoneNull="Please enter your phone number.";
    var phoneInvalid="Please enter a valid phone number."; 
    var stateNull="Please select your state of residence.";
    var zipNull="Please enter your zip code.";
    var zipLength="Your zip code must be five digits long. Please re-enter your zip code.";
    var zipInvalid="Please enter a valid zip code.";
    var zipLastInvalid="Please enter a valid zip code 2 add-on.";
    var zipLastLength="Your zip code 2 add-on must be four digits long. Please re-enter your zip code add-on.";
    var zipLastOnlyNumber="Your zip code 2 add-on must be numeric. Please enter only numbers."

function isAlphaNumeric(str)
{
    //var str=trim(str);  
    var ctrI; 
    var strLength = str.length;
    var validStr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ";
    for (ctrI = 0; ctrI < strLength; ctrI++) {
       if (validStr.indexOf(str.charAt(ctrI)) == -1){
          return false;
        }
    }
   return true;
}

function isBlank(str)
{
    if(str.length == 0)
        return true;
    else{
        var strblank ="";
        for(i=0; i<str.length; i++)
            strblank = strblank + " " ;

        if(str == strblank)
            return true;
        else 
            return false;
    }

}

function checkemail(field){
    var testresults=false;
    field.value=field.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if((field.length==0)){
        testresults=false;
    }else{
        if (filter.test(field.value)){
            testresults=false;
        }else{
            testresults=true;
        }
     }
return testresults;
}
function isNumericOnlyWithSpace(str)
{
    //var str = trim(str);
    var ctrI;
    var counter = 0;
    var strLength = str.length;
    var validStr = "1234567890 ";
    if(strLength == 0){
    return false;
    }
    for (ctrI = 0;ctrI < strLength;ctrI++){
    if (validStr.indexOf(str.charAt(ctrI)) != -1){
    counter++;}
    }if(strLength == counter){
   return true;
   }
   return false;
}
function isNumericOnly(str)
{
    
    //var str = trim(str);
    var ctrI;
    var counter = 0;
    var strLength = str.length;
    var validStr = "1234567890";
    if(strLength == 0){
    return false;
    }
    for (ctrI = 0;ctrI < strLength;ctrI++){
    if (validStr.indexOf(str.charAt(ctrI)) != -1){
    counter++;}
    }if(strLength == counter){
   return true;
   }
   return false;
} 
function validateStreetAddress(addr){
    var isValidAddr = false;
    //newAddr = replaceAll(addr,'.','');
    isValidAddr = isAlphaNumeric(addr);
    return isValidAddr;
}

// To check if the variable contains only alphabets.  Returns true if the variable contains only alphabets
function isAlpha(str)
{
    //var str=trim(str);
    var ctrI;
    var strLength = str.length;
    var validStr='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';
    for (ctrI = 0; ctrI < strLength; ctrI++) {
       if (validStr.indexOf(str.charAt(ctrI)) == -1){
          return false;
        }
    }
   return true;
}

///checks if a number
function isNumber(s){
   // var s=trim(s);
    var ctrI;
    var tempChar;
    for (ctrI = 0; ctrI < s.length; ctrI++){   
        // Check that current character is number.
        tempChar = s.charAt(ctrI);
        if (((tempChar < '0') || (tempChar > '9')))
           return false;
    }
    // All characters are numbers.
    return true;
} 

function checkLength(param, len)
{ 
    //var param=trim(param);
    var num="0123456789";
    var tempChar;
    if (param.length != len){        
        return false;
    }else{
  return true;
  }
}

function checkValidZip(param, len)
{ 
    //var param=trim(param);
    var num="0123456789";
    var tempChar;
    
        if (param.length== len ){
        if(param.charAt(0)=="0" && param.charAt(1)=="0"){
            return false;
        }
        else{
        for(ctrI=0; ctrI < param.length; ctrI++){
             if (num.indexOf(param.charAt(ctrI)) == -1){
                 return false;
             }
         }
         }
         }
          return true;
}


function checkPhoneFirst(field)
{
    var invalid = false;
    var checkOK = "0123456789";
    if ((field.value.length != 3)){
        invalid = true;
    }
    else{
        if (field.value.charAt(0)=="0"){
            invalid = true;
        }
        for(i=0; i < field.value.length; i++) {
            ch = field.value.charAt(i);
            for (j = 0;  j < checkOK.length; j++) {
                if (ch == checkOK.charAt(j)) {
                    break;
                }
                if (j == (checkOK.length-1)) {
                    invalid = true;
                    break;
                }
            }        
        }
    }
    return invalid;
}

function checkPhoneMiddle(field){
    var invalid = false;
    var checkOK = "0123456789";
    if ((field.value.length != 3) ) {
        invalid = true;
    }
    else {
        //if (field.value.charAt(0)=="0") {
       //     invalid = true;
       // }
        for(i=0; i < field.value.length; i++) {
            ch = field.value.charAt(i);
            for (j = 0;  j < checkOK.length;  j++) {
                if (ch == checkOK.charAt(j)) {
                    break;
                }
                if (j == (checkOK.length-1)) {
                    invalid = true;
                    break;
                }
            }        
        }
    }
    return invalid;
}

function checkPhoneLast(field){
    var invalid = false;
    var checkOK = "0123456789";
    if ((field.value.length != 4) ){
        invalid = true;
    }
    else {
        //if (field.value.charAt(0)=="0") {
            //invalid = true;
       // }
        for(i=0; i < field.value.length;i++) {
            ch = field.value.charAt(i);
            for (j = 0;  j < checkOK.length;j++) {
                if (ch == checkOK.charAt(j)){
                    break;
                }
                if (j == (checkOK.length-1)) {
                    invalid = true;
                    break;
                }
            }        
        }
    }
    return invalid;
}

function checkValidFirst(field)
{
    var valid = true;
    var checkOK = "0123456789";
    if (
          (field.value.substr(0,1) == 1 || field.value.substr(0,1) == 0
        || field.value.substr(0,3) ==  800 || field.value.substr(0,3) ==  877
        || field.value.substr(0,3) ==  888 || field.value.substr(0,3) ==  900
        || field.value.substr(0,3) ==  976) )
    {
        valid = false;
    }
    else
    {
        if (field.value.charAt(0)=="0")
        {
            valid = false;
        }
       
    }
     return valid;
    }
    
 function lTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1) {
            var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;
            s = s.substring(j, i);
        }
        return s;
}   
 