// JavaScript Document
function check()
{
document.getElementById('resultshere').style.display ='Block';
document.getElementById('resultshere').innerHTML ='Your credentials did not match, please try again.';
}



function validateEmail(addr,man,db){
		if (addr == '' && man) {
		   if (db) //alert('email address is mandatory');
		   return false;
		}
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			  if (db) //alert('email address contains invalid characters');
			  return false;
		   }
		}
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
			  if (db) //alert("email address contains non ascii characters.");
			  return false;
		   }
		}

		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   if (db) //alert('email address must contain an @');
		   return false;
		}
		if (atPos == 0) {
		   if (db) //alert('email address must not start with @');
		   return false;
		}
		if (addr.indexOf('@', atPos + 1) > - 1) {
		   if (db) //alert('email address must contain only one @');
		   return false;
		}
		if (addr.indexOf('.', atPos) == -1) {
		   if (db) alert('email address must contain a period in the domain name');
		   return false;
		}
		if (addr.indexOf('@.',0) != -1) {
		   if (db) //alert('period must not immediately follow @ in email address');
		   return false;
		}
		if (addr.indexOf('.@',0) != -1){
		   if (db) alert('period must not immediately precede @ in email address');
		   return false;
		}
		if (addr.indexOf('..',0) != -1) {
		   if (db) //alert('two periods must not be adjacent in email address');
		   return false;
		}
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		   if (db) //alert('invalid primary domain in email address');
		   return false;
		}
		return true;
	}



function checkForm(frmName){  //               Common Java Script Files   

	var cntError = 0;
	var errorMsg = Array();
	var errorField = Array();
	var frm = document.frmName;
	//var frm = document.frmName;
    if(document.getElementById('name').value==""){
		errorMsg[cntError] = 'name';
		errorField[cntError] = 'name';
		document.getElementById('name_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('name_label').style.color = "";
	}
		
	if(document.getElementById('address').value==""){
		errorMsg[cntError] = 'address';
		errorField[cntError] = 'address';
		document.getElementById('address_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('address_label').style.color = "";
	}
	
	if(document.getElementById('phone').value==""){
		errorMsg[cntError] = 'phone';
		errorField[cntError] = 'phone';
		document.getElementById('phone_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('phone_label').style.color = "";
	}
	
	if(document.getElementById('city').value==""){
		errorMsg[cntError] = 'city';
		errorField[cntError] = 'city';
		document.getElementById('city_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('city_label').style.color = "";
	}
	
	if(document.getElementById('state').value==""){
		errorMsg[cntError] = 'state';
		errorField[cntError] = 'state';
		document.getElementById('state_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('state_label').style.color = "";
	}
	
	if(document.getElementById('zip').value==""){
		errorMsg[cntError] = 'zip';
		errorField[cntError] = 'zip';
		document.getElementById('zip_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('zip_label').style.color = "";
	}
	
	if(!validateEmail(document.getElementById('email').value,1,1)){
		errorMsg[cntError] = 'Email is not in Proper format';
		errorField[cntError] = 'email';
		document.getElementById('email_label').style.color = "#FF0000"
		cntError++;
	}
	else
	{
		document.getElementById('email_label').style.color = "";
		}
		
	
	// If there are errors, then print them
	if(errorMsg.length > 0){
		
		        var Output2 = "Please fill all mandatory fields";
        		document.getElementById("errDiv").innerHTML = Output2;
				document.getElementById("errDiv").style.display="block";
	
		return false;
	}else{
		var url="process-contact.php";
		var myAjax = new Ajax.Request(url, {method: 'post', 
											parameters:  $('frmContact').serialize(), 
											onSuccess: function(transport){ 
												if(transport.responseText='yes'){
													document.getElementById('frm-cont').innerHTML="";
													document.getElementById('frm-cont').innerHTML="Thank you for contacting us. One of our representatives will contact you shortly.";
													document.getElementById('frm-cont').className="cont-succ-msg";
													setTimeout("gotopage();",5000);
												}
												else{
													document.getElementById('frm-cont').innerHTML="";
													document.getElementById('frm-cont').innerHTML="Error Sending Mail";
													document.getElementById('frm-cont').className="cont-succ-msg";
													}
											}
									      }
										);
	}
}

////////////////////


////////////////

function numericValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}
function phoneValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=45 && charCode!=46 && charCode!=37 && charCode!=39) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}

// By Nikhil
function nameValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
	//alert(charCode);
    //if ((charCode > 32 && charCode < 65) || (charCode > 90 && charCode < 97) || (charCode > 122 && charCode < 127) && charCode != 39 && charCode != 45) {
	if (charCode > 32 && ((charCode < 65 || charCode > 122) || (charCode > 90 && charCode < 97)) && charCode!=45 && charCode!=39 && charCode!=46 && charCode!=37) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}


function costValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}


function IsPhone(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function ty(){
	document.getElementById('frm-cont').innerHTML="";
	document.getElementById('frm-cont').innerHTML="Thank You";
	document.getElementById('frm-cont').className="cont-succ-msg";
}

function gotopage(){
		window.location="contact.php"; 
	}
