//Begin .js File
var strAlertMsg = ""
var focusField = ""
function isDate(strFieldName,strLabel,strMsg){
    var objFormField = document.forms[0].elements[strFieldName];
    strDate = objFormField.value;
    if(strDate.length>0){
            var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
             var match=strDate.match(dateregex);
             if (match){
                       var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
                  if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10)){ 
                    return true; 
                    }
             }
                    strAlertMsg += "- "+ strMsg +" is Required.\nExample: 01/01/2003\n";
               if(!focusField) focusField =""+ strFieldName +"";
         return false;
    }
    else{
          return true;
    }
}
//========================================================================
//Validate Us Phone. Ex. (999) 999-9999 or (999)999-9999
function isPhone(strFieldName,strMsg)     {
     var objFormField = document.forms[0].elements[strFieldName];
     var strValue = objFormField.value;
     var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
      if(!objRegExp.test(strValue)){
          strAlertMsg += "- "+ strMsg +" is Required.\n    Example:\n(999)999-9999 or (999) 999-9999\n";
     if(!focusField) focusField=""+ strFieldName +"";
          return false;
          }
     return true;
}
//========================================================================
//Validate US zip code in 5 digit format or zip+4 format. 99999 or 99999-9999
function isZipCode(strFieldName,strMsg)     {
     var objFormField = document.forms[0].elements[strFieldName];
     var strValue = objFormField.value;
     var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
     if(!objRegExp.test(strValue)){
          strAlertMsg += "- "+ strMsg +" is Required.\n";
     if(!focusField) focusField =""+ strFieldName +"";
          return false;
          }
     return true;
}
//==========================================================================
//Validate the Select
function hasSelection(strFieldName,strMsg)     {
     var objFormField = document.forms[0].elements[strFieldName];
     if(objFormField.selectedIndex ==0)     {
          strAlertMsg += "- "+ strMsg +" is Required.\n";
           return false; 
           }
     return true; 
}
//========================================================================
//Validate Check Box
function isChecked(strFieldName,strMsg) {
     var objFormField= document.forms[0].elements[strFieldName];
     var strValue= objFormField.checked;
     if (!strValue) {
          //alert("The \""+ strMsg +"\" box is checked!")
          //} else {
          strAlertMsg += "- "+ strMsg +" is Required.\n";
     if(!focusField) focusField =""+ strFieldName +"";
          return false;
          }
     return true;
}
//========================================================================
//Validate Text Box
function isEmpty(strFieldName,strMsg){
     var objFormField = document.forms[0].elements[strFieldName];
     var strValue = objFormField.value;
     strValue = strValue.split(" ").join("")
     if(strValue.length<1){
          strAlertMsg += "- "+ strMsg +" is Required.\n";
     if(!focusField) focusField =""+ strFieldName +"";
          return false;
          }
     return true;
}
//========================================================================
//Validate Email
function isEmail(strFieldName,strMsg){
     var objFormField = document.forms[0].elements[strFieldName]
     var strEmail = objFormField.value;
     var bolValid = true;
          if(strEmail.length < 7){
          bolValid = false;
          }
          if(strEmail.lastIndexOf(" ") >0){
          bolValid = false;
          }
          var intLastDot = strEmail.lastIndexOf(".")
          if(intLastDot == -1 ||  strEmail.length - intLastDot >4){
          bolValid = false;
          }
          var intAt = strEmail.lastIndexOf("@")
          if(intAt == -1 ||  strEmail.length - intAt < 5){
          bolValid = false;
          }
          if(!bolValid){
          strAlertMsg += "- "+ strMsg +" is Required.\n";
     if(!focusField) focusField =""+ strFieldName +"";
          }
     return bolValid;
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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 ValidateFormEmail(emailID){
	if (emailID == null) return false;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true
 }
//========================================================================
function ValidateFormName(nameID){
	if (nameID == null) return false;
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please Enter your Name");
		nameID.focus();
		return false;
	}
	return true;
 }
 
 function ValidateFormDate(dateID){
	 if (dateID == null) return false;
	 if ((dateID.value==null)||(dateID.value=="")){
		alert("Please Enter Date");
		dateID.focus();
		return false;
	}
	return true;
 }
//Validate Radio Button
function checkRadioControl(strFieldName,strMsg){
          var objFormField = document.forms[0].elements[strFieldName]
          intControlLength = objFormField.length
          bolSelected = false;
          for (i=0;i<intControlLength;i++){
          if(objFormField[i].checked){
          bolSelected = true;
          break;
          }
     }     
     if(! bolSelected){
          strAlertMsg += "- "+ strMsg +" is Required.\n";
          return false;
          }
     return true;
}
//========================================================================
//Compare the Fields
function compareFields(strFieldName1,strFieldName2,strMsg){
          var objFormField1= document.forms[0].elements[strFieldName1];
          var objFormField2= document.forms[0].elements[strFieldName2];
          var strValue1= objFormField1.value;
          var strValue2= objFormField2.value;
     if(strValue1 != strValue2){
          strAlertMsg +="The "+ strMsg +" fields do not match, please try again.\n"; 
     if(!focusField) focusField =""+ strFieldName1 +"";
          return false; 
          }
     return true;
}
//========================================================================
//Format Phone Number 9999999999 = (999)999-9999
//Call the function like so onKeyPress="javascript:formatPhone(this);
function formatPhone(objFormField){
     intFieldLength = objFormField.value.length;
     if(intFieldLength == 3){
          objFormField.value = "(" + objFormField.value + ") ";
          return false;
          }
    if(intFieldLength >= 9 && intFieldLength <= 10){
        objFormField.value = objFormField.value + "-";
        return false;
        }
}
//========================================================================
//End .js File