// JavaScript Document
function valcontact()
{
  if(isEmpty(document.getElementById('name'),"Please enter your name")==false)
  {
	    return false;
        document.getElementById('name').select();
		document.getElementById('name').focus();
  }
  if(echeck(document.getElementById('email').value)==false)	
  {
	 	document.getElementById('email').select();
	  	document.getElementById('email').focus();
	  	return false;
  }
  if(IsNumeric(document.getElementById('phone').value)==false)
  {
	  document.getElementById('phone').select();
	  document.getElementById('phone').focus();
	  return false;
  }
  /*if(IsNumeric1(document.getElementById('fax').value)==false)
  {
	  document.getElementById('fax').select();
	  document.getElementById('fax').focus();
	  return false;
  }*/
  if(isEmpty(document.getElementById('street'),"Please enter your street")==false)
  {
	    return false;
        document.getElementById('street').select();
		document.getElementById('street').focus();
  }
  if(isEmpty(document.getElementById('city'),"Please enter your city")==false)
  {
	    return false;
        document.getElementById('city').select();
		document.getElementById('city').focus();
  }
  if(isEmpty(document.getElementById('state'),"Please enter your state")==false)
  {
	    return false;
        document.getElementById('state').select();
		document.getElementById('state').focus();
  }  
  if(isAlphanumeric(document.getElementById('zipcode'),"Please enter your zipcode")==false)
  {
	    return false;
        document.getElementById('zipcode').select();
		document.getElementById('zipcode').focus();
  }
  if(isEmpty(document.getElementById('country'),"Please enter your country")==false)
  {
	    return false;
        document.getElementById('country').select();
		document.getElementById('country').focus();
  }
  if(document.frm_contact.ContactBy[0].checked==false && document.frm_contact.ContactBy[1].checked==false && document.frm_contact.ContactBy[2].checked==false && document.frm_contact.ContactBy[3].checked==false)
  {
	    alert("Please select your contact method");
		return false;
  }
  if(isAlphanumericAll(document.getElementById('QuestionComments'),"Please enter your comments")==false)
  {
	    return false;
        document.getElementById('QuestionComments').select();
		document.getElementById('QuestionComments').focus();
  }
}

//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=='')
			{
			alert("Please enter your E-mail ID")
			return false;
			}
		if (str.indexOf(at)==-1)
		{
		   alert("Please enter valid E-mail ID")
		   return false
		}

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

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

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

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

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

//Check empty validation
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	else
	{
		 return true;
	}
}

//Alphanumeric validation All Values
function isAlphanumericAll(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z \ \.\~\`\!\@\#\$\%\^\&\*\(\)\_\+\|\{\}\[\]\\\:\;\"\'\/\?\-\n\r\t\b\f\,\=]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		elem.select();
		return false;
	}
}

//Alphanumeric validation
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z / /.]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		elem.select();
		return false;
	}
}

// Numeric Validation for Phone Number
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0)
   		{ 
   			alert("Please enter your phone number")
   			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)
         {
		 alert("Please enter valid phone number")
         blnResult = false;
         }
      }
   return blnResult;
}   

// Numeric Validation for Fax Number
function IsNumeric1(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0)
   		{ 
   			alert("Fax number should not be left blank!")
   			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)
         {
		 alert("Fax number should be numeric value!")
         blnResult = false;
         }
      }
   return blnResult;
}  
