
/*
function onKeyPressBlockChacter(event)
{
   var isNS4 = (navigator.appName=="Netscape")?1:0;
    
	if(!isNS4){if( event.keyCode > 57 || event.keyCode == 32 || event.keyCode == 47 || event.keyCode == 39 || event.keyCode == 34 || event.keyCode == 46 || event.keyCode == 44 || event.keyCode == 43) event.returnValue = false;}else{if( event.which > 57 ||  event.which  == 32 ||  event.which  == 47 || event.which  == 39 || event.which  == 34 || event.which  == 46 || event.which  == 44 || event.which  == 43) return false;}
	//if(!isNS4){if(event.keyCode >8 || event.keyCode < 45) event.returnValue = false;}else{if(event.which ==8 || event.which < 45) return false;}
	
}

*/

//alert("A");

var whitespace = " \t\n\r";

function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{  var i;
	// Is s empty?
	if (isEmpty(s)) return true;

	 // Search through string's characters one by one
	 // until we find a non-whitespace character.
	 // When we do, return false; if we don't, return true.
	 for (i = 0; i < s.length; i++)
	 {   
		 // Check that current character isn't whitespace.
		 var c = s.charAt(i);
 
		 if (whitespace.indexOf(c) == -1) return false;
	 }
 
	 // All characters are whitespace.
	 return true;
}

function BuildStr(s, s1)
{
	  if (s.length> 0) s = s + "\n";
	  s = s + s1;
	  return s;
}

function isCharsInBag (s, bag)
{  
  var i;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.

  for (i = 0; i < s.length; i++)
  {   
	  // Check that current character isn't whitespace.
	  var c = s.charAt(i);
	  if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

function IsNumeric(val) {
	var validChars = "0123456789-";
	for (var x=0; x<val.length; x++) {
		if (!(validChars.indexOf(val.charAt(x)) != -1)) {
			return false;
			break;
		}
	}
	return true;
}


function submitme(theForm)
{
 
	var i="";
	var Q1 = ""; // this variable is used to focus on the first blank field
	var errMesg = ""; // this variable is used to display  messages
	var diplayMesg = ""; // this variable is used to display error messages
	var Q = ""; // this block determines lifespan of Q
	
	

	
	if (isWhitespace(theForm.name.value))
		{
		Q += "  Name\n";
		Q1 += "name ";
		}
	else if(!isCharsInBag(document.form1.name.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "))
	{
	  errMesg += "Name contains Invalid Characters\n";
	}

	 
	if (isWhitespace(document.form1.address.value) && isWhitespace(document.form1.address1.value))
	  {
   	  	Q += "  Address\n";
		Q1 += "address ";
	 }
	else if(!isCharsInBag(document.form1.address.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#-_,. "))
	{
	  errMesg += "Address contains Invalid Characters\n";
	}
		
	if(isWhitespace(document.form1.city.value))
	  {
   	  	Q += "  City\n";
		Q1 += "city ";
	  }
	else if(!isCharsInBag(document.form1.city.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{
	  errMesg += "City contains Invalid Characters\n";
	}
	
/*	if (form1.state.value=="")
		{
		Q += "  Select State\n";
		Q1 += "state ";
		}*/		
	if(document.getElementById('state_cd').disabled){
		var state = document.getElementById('state_us').value;
	} else 	if(document.getElementById('state_us').disabled){
		var state = document.getElementById('state_cd').value;
	} else{ var state = '';}
	if (state=="")
		{
		Q += "  Select State\n";
		Q1 += "State ";
		}	
		
	if (isWhitespace(form1.phone.value))
		{
		Q += "  Phone\n";
		Q1 += "Phone ";
		}	
/*	if(form1.phone.value.length > 1)
	{
		if(!IsNumeric(form1.phone.value)){
				 Q += " Please enter numeric value for Phone\n";
			}	
	}*/		

	/*
	else if(!isCharsInBag( form1.phone.value, "0123456789"))
	{
	  errMesg += "Invalid Phone Number.\n";
	}
	*/
	
	if (isWhitespace(document.form1.email.value))
		{
			Q += "  E-mail \n";
			Q1 += "E-mail ";
		}
		
	else if(!echeck(document.form1.email.value))
		{
		 errMesg += "E-mail is Address\n";
		}	
		else if(!isCharsInBag(document.form1.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
		{
		  errMesg += "E-mail contains Invalid Characters\n";
		}
	if(document.form1.chk_access.checked == false && document.form1.chk_trailers.checked == false)	
	{
			Q +="  Interested In\n";
			Q1 +="interested ";
	}
 	if(document.form1.chk_trailers.checked == true)
	{
			var flag = 0;
			for(var i =1; i<=7;i++)
			{
				if(document.getElementById("trailer"+i).checked == true)
				{
					flag = 1;
				}
			}
			if(flag == 0)
			{
				Q += "  Type of Trailers\n";
				Q1 += "Type of Trailers ";
			}
	}
	if(document.form1.chk_access.checked == true)
	{
			var flag = 0;
			for(var i =1; i<=2;i++)
			{
				if(document.getElementById("accessory"+i).checked == true)
				{
					flag = 1;
				}
			}
			if(flag == 0)
			{
				Q += "  Trailers Accessories\n";
				Q1 += "Trailer Accessories";
			}
	}
	 if ( Q.length > 0 )
		{
			diplayMesg = "Please provide Valid values for\n" + Q ;
		}

	if (errMesg == "" && diplayMesg == "")
	{
		return true;
//		document.form1.method="post";
//		document.form1.action="contact-action.php";
//		document.form1.submit();
	}
	else
	{
		if(diplayMesg!="")
		{
			alert(diplayMesg);
		
			i=Q1.split(" ");
						 
			var a = i[0];
							
			if(i[0] == "name"){
			document.form1.name.focus();
			}
			else if(i[0] == "address"){
			document.form1.address.focus();
			}
			 
			else if(i[0] == "city"){
			document.form1.city.focus();
			}
			
			else if(i[0] == "state"){
			document.form1.state.focus();
			}
			
			else if(i[0] == "phone"){
			document.form1.phone.focus();
			}
			
			else if(i[0] == "email"){
			document.form1.email.focus();
			}
		}
		else
		{
			alert(errMesg);
		}	
		return false;			
	}		
}


/*Start : Function for email Check */
function echeck(str) {
	if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
	else
	return false;
	}


/*function forcheck phone */
/*
function phonecheck(str) {
    
	var e=document.order.phone.value;
		var phoneLength=e.length;
		//alert(phoneLength);
		if (phoneLength != 12 ) 
		{
		  //alert("please enter proper phone number");
		  //document.f.phone.focus();
		  return false;
		}
		if (phoneLength == 12 ) 
		{
		   var phoneStr=e.split("-");
		   var p1,p2,p3;
		   var phoneStrLength=phoneStr.length;
		   if (phoneStrLength!=3)
		   {
			 //alert("please enter proper phone number");
			 //document.f.phone.focus();
			 return false;
		   }
		   p1=phoneStr[0];
		   p2=phoneStr[1];
		   p3=phoneStr[2];
		   
		   if(   ((p1.length)!=3) && ((p2.length)!=3) && ((p3.length)!=4) )
		   {
			   // alert("please enter proper phone number");
				//  document.f.phone.focus();
				 return false;
		   } 
			
		}
		return true;
}	



/*code for date validation (mm/dd/yyyy) format */	

/*
	var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


*/

