
/*
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;}
	
}

*/

 
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 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.Type.value))
		{
		Q += "  Trailer Type\n";
		Q1 += "Type ";
		}
	
	if (isWhitespace(theForm.width1.value))
		{
		Q += "  Width\n";
		Q1 += "width1 ";
		}
	
	else if(!isCharsInBag(document.enquiry.width1.value, "0123456789."))
	{
	  errMesg += "Width contains Invalid Characters\n";
	}
	
	if (isWhitespace(theForm.length1.value))
		{
		Q += "  Length\n";
		Q1 += "length1 ";
		}
	
	else if(!isCharsInBag(document.enquiry.length1.value, "0123456789."))
	{
	  errMesg += "Length contains Invalid Characters\n";
	}
	
	var radio=document.getElementsByName("Coating");
	if(radio[0].checked==false && radio[1].checked==false)
	{
		Q += "  Coating\n";
		Q1 += "Coating ";
	
	}
	
	if (enquiry.Colour.value=="")
		{
		Q += "  Color Options\n";
		Q1 += "Colour ";
		}		

	
	if (isWhitespace(theForm.name.value))
		{
		Q += "  Name\n";
		Q1 += "name ";
		}
	else if(!isCharsInBag(document.enquiry.name.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "))
	{
	  errMesg += "Name contains Invalid Characters\n";
	}
	
	if (isWhitespace(document.enquiry.address.value))
	  {
   	  	Q += "  Mailing Address\n";
		Q1 += "address ";
	 }
	else if(!isCharsInBag(document.enquiry.address.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#-_,. "))
	{
	  errMesg += "Address contains Invalid Characters\n";
	}
		
	if(isWhitespace(document.enquiry.city.value))
	  {
   	  	Q += "  City\n";
		Q1 += "city ";
	  }
	else if(!isCharsInBag(document.enquiry.city.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{
	  errMesg += "City contains Invalid Characters\n";
	}
	
	if (isWhitespace(theForm.state.value))
		{
		Q += " Select State\n";
		Q1 += "State ";
		}
		
		
	if (isWhitespace(enquiry.phone.value))
		{
		Q += "  Phone\n";
		Q1 += "phone ";
		}	
	/*		
	else if(!isCharsInBag( enquiry.phone.value, "0123456789"))
	{
	  errMesg += "Invalid Phone Number.\n";
	}
   */
	if (isWhitespace(enquiry.cellphone.value))
		{
		Q += "  Cell Phone\n";
		Q1 += "cellphone ";
		}	
			
	/*
	else if(!isCharsInBag( enquiry.cellphone.value, "0123456789"))
	{
	  errMesg += "Invalid Cell Phone Number.\n";
	}
 */
	if (isWhitespace(document.enquiry.email.value))
		{
			Q += "  Email Address\n";
			Q1 += "email ";
		}
	if (isWhitespace(document.enquiry.captcha.value))
		{
			Q += "  Security Code\n";
			Q1 += "security code ";
		}
		
	else if(!echeck(document.enquiry.email.value))
		{
		 errMesg += "Invalid Email Address\n";
		}	
		else if(!isCharsInBag(document.enquiry.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
		{
		  errMesg += "Email Address contains Invalid Characters\n";
		}
	
		
	/*
	if (isWhitespace(theForm.cellphone.value))
		{
		Q += "  Cell Phone\n";
		}	
		
	else if(!isCharsInBag(theForm.cellphone.value, "0123456789"))
	{
	  Q += "Invalid Cell Phone Number.\n";
	}
	//else if (phonecheck(theForm.cellphone.value)==false)
	//{
	//   Q += "Enter Proper Phone number\n";
	//}				
		*/		
				
	 if ( Q.length > 0 )
		{
			diplayMesg = "Please provide Valid values for\n" + Q ;
		}

	if (errMesg == "" && diplayMesg == "")
	{
		//theForm.submit();
	}
	else
	{
			if(diplayMesg!="")
			{
				alert(diplayMesg);
				
				i=Q1.split(" ");
							 
				var a = i[0];
				
				if(i[0] == "Type"){
				document.enquiry.Type.focus();
				}
				
				if(i[0] == "width1"){
				document.enquiry.width1.focus();
				}
				if(i[0] == "length1"){
				document.enquiry.length1.focus();
				}
				//if(i[0] == "Coating"){
				//document.enquiry.radio[0].focus();
				//}
				if(i[0] == "Colour"){
				document.enquiry.Colour.focus();
				}
				if(i[0] == "name"){
				document.enquiry.name.focus();
				 
				}
				
				else if(i[0] == "address"){
				document.enquiry.address.focus();
				}
				
				else if(i[0] == "city"){
				document.enquiry.city.focus();
				}
				
				else if(i[0] == "state"){
				document.enquiry.state.focus();
				}
				
				else if(i[0] == "phone"){
				document.enquiry.phone.focus();
				}
				
				else if(i[0] == "cellphone"){
				document.enquiry.cellphone.focus();
				}
				
				else if(i[0] == "email"){
				document.enquiry.email.focus();
				}
				
				//alert(Q1);
				//} 
				return false;			
			}
			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
}


*/
