function validemail(thisform)
{
	
	with (thisform)
	{
	  	if (validate_email(email)==false)
		{
			
			email.focus();
			return false;
		}
	}
}

// JavaScript Document
/*function validatmile(thisform)
{
with (thisform)
{
if(mileage.value.length > 6)
{
	alert("Mileage-Maximum 6 digits are allowed only");
	mileage.value="";
	mileage.focus();
	mileage.select();
	return false;
	
}
/*else
{
	var StartNumber  = mileage.value;
	var ReplacedNumber = StartNumber.replace(/\,/g,'');
//alert(ReplacedNumber);
v=numberFormat(ReplacedNumber);
mileage.value=v;
}
/*v1=mileage.value;

return v1;
}

return true;
}*/

function validatecar(thisform)
{
	with (thisform)
	{
		if(validate_selectcombo(year)==false)
		{
			alert("Year must be filled out!");						
			year.focus();
			return false;			 
		}
		
		if(validate_selectcombo(make)==false)
		{
			alert("Make must be filled out!");						
			make.focus();
			return false;			 
		}
		
		if(validate_selectcombo(model)==false)
		{
			alert("Model must be filled out!");						
			model.focus();
			return false;			 
		}
		
		if(newtrim.value=="")
		{
			if(validate_selectcombo(trim)==false)
			{
				alert("Trim must be filled out!");						
				trim.focus();
				return false;			 
			}
		}
		
		if (validate_required(mileage,"Mileage must be filled out!")==false)
		  {mileage.focus();return false;}
		
		 if(IsNumeric(mileage.value)==false)
		  {
			  alert("Miles-must be in Numbers Only ");
			  mileage.focus();
			  return false;
		  }
	}
	return true;
}


function validate_form(thisform)
{
	with (thisform)
	{	 
		  //TextBoxes validation		  
		if (validate_required(first_name,"First Name must be filled out!")==false)
		{first_name.focus();return false;}
		
		if (validate_required(last_name,"Last Name must be filled out!")==false)
		{last_name.focus();return false;}
		
		//Email Validation			
		if (validate_email(email)==false)
		{
			email.focus();
			return false;
		}
		
		if (validate_required(phoneno,"Phone No must be filled out!")==false)
		{phoneno.focus();return false;}
		
		if (validate_required(phoneno1,"Phone No must be filled out!")==false)
		{phoneno1.focus();return false;}
		
		if (validate_required(phoneno2,"Phone No must be filled out!")==false)
		{phoneno2.focus();return false;}
		
		if(validatephone(thisform)==false)
		{
		phoneno.focus();
		return false;		
		}		
		
		if (validate_required(username,"User Name must be filled out!")==false)
		{username.focus();return false;}
		
		if (validate_required(password,"Password must be filled out!")==false)
		{password.focus();return false;}
		
		if (validate_required(confirm_password,"Confirm Password must be filled out!")==false)
		{confirm_password.focus();return false;}
		
		if(passwordmatch(password,confirm_password)==false)
		{
			password.focus();
			return false;
		}
		
		if (validate_required(street_address,"Address must be filled out!")==false)
		{street_address.focus();return false;}
		
		if (validate_required(city,"City must be filled out!")==false)
		{city.focus();return false;}
		
		// ComboBox Validation
		if(validate_selectcombo(state)==false)
		{
			alert("State must be filled out!");						
			state.focus();
			return false;			 
		}
		// Zip or Postal Code Validation
		
		if (validatepostal(zip)==false)
		{
			zip.focus();
			return false;
		}
		
		if(validate_selectcombo(year)==false)
		{
			alert("Year must be filled out!");						
			year.focus();
			return false;			 
		}
		
		
		if(validate_selectcombo(make)==false)
		{
			alert("Make must be filled out!");						
			make.focus();
			return false;			 
		}
		
		if(validate_selectcombo(model)==false)
		{
			alert("Model must be filled out!");						
			model.focus();
			return false;			 
		}
		
		if(newtrim.value=="")
		{
		
			if(validate_selectcombo(trim)==false)
			{
				alert("Trim must be filled out!");						
				trim.focus();
				return false;			 
			}
		}
		
		if (validate_required(mileage,"Milage must be filled out!")==false)
		{mileage.focus();return false;}
		
		if(IsNumeric(mileage.value)==false)
		{
			alert("Miles-must be in Numbers Only ");
			mileage.focus();
			return false;
		}
		
	}
return true;
}
///////////////////////end main
// Required Field Validation
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true;}
}
}

//combo validation like state-
function validate_selectcombo(field1)
{
	
if (field1.value=="")
{

return false;
}
else
return true;
}

//Phone Validation
/*function validatephone(field1)  
{
	var v1=field1.value;
//if(checknum(field1)==true)
if (v1=="")
{
	alert("Phone No should be filled out");
	field1.focus();
	return false;	
	
	}
	if (IsNumeric(v1) == false) 
	{	
		alert("Phone No should be in Numeric");
	field1.focus();
	return false;	
	}
return true;
}*/
// Number Validation

function IsNumeric(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;
   }
//Email validation

function validate_email(field)
{

	if (field.value==null||field.value=="")
	{
		alert("Email must be filled out");
		return false;
	}
	else
	{
			apos=field.value.indexOf("@");
			dotpos=field.value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2) 
			 {
			  alert("Invalid Email");
			  return false;
			  }
			else 
			{
				return true;
			}
	}
}
function validatepostal(field1)  
{
	if (validate_required(field1,"Zip must be filled out!")==false)
  {
	  field1.focus();
	  return false;
  }
  
var valid = "0123456789";
var temp="";
var v1=field1.value;
if (v1.length!=5 ) 
{
alert("Zip must be 5 digit.");
field1.focus();
return false;
}
for (var i=0; i < v1.length; i++) {
temp = "" + v1.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in Zip.  Please try again.");
field1.focus();
return false;
}
}
return true;
}


function validatezipnine(field1)  
{
	if (validate_required(field1,"Zip must be filled out!")==false)
  {
	  field1.focus();
	  return false;
  }
  
var valid = "0123456789";
var temp="";
var v1=field1.value;
if (v1.length!=5 ) 
{
alert("Zip must be 5 or 9 digit.");
field1.focus();
return false;
}
for (var i=0; i < v1.length; i++) {
temp = "" + v1.substring(i, i+1);
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in Zip.  Please try again.");
field1.focus();
return false;
}
}
return true;
}
// Validation of Radio button
function valButton(btn)
{
	
    var cnt = 0;
    
    for (var i=1; i<3; i++)
	{
        if (btn[i].checked) 
		{
			alert("yes");
			cnt = 1;
		}
    }
	
    if (cnt > 0) 
	{
	return true;
	}
    else 
	{	
		return false;
	}
	
}
//// for 10 radio buttons

function valButtonRate(btn)
{
	
    var cnt = 0;
    
    for (var i=0; i<10; i++)
	{
        if (btn[i].checked) 
		{
			//alert("yes");
			cnt = 1;
		}
    }
	
    if (cnt > 0) 
	{
	return true;
	}
    else 
	{	
		return false;
	}
	
}
// for 3 radio buttons

function valButtonRate1(btn)
{
	
    var cnt = 0;
    
    for (var i=0; i<3; i++)
	{
        if (btn[i].checked) 
		{
			//alert("yes");
			cnt = 1;
		}
    }
	
    if (cnt > 0) 
	{
	return true;
	}
    else 
	{	
		return false;
	}
	
}

// Validation for password matching

function passwordmatch(pass,pass1)
{
	if(pass.value!=pass1.value)
	{
	alert("password mismatched");
	return false;
	}
	
}

function fnphone(phone)
{
phone = phone.value;
//phoneRegex = /^[0-9]\d{3}-\d{3}-\d{4}$/;
phoneRegex =/(\d\d\d)-\d\d\d-\d\d\d\d/;

if( !phone.match( phoneRegex ) ) {
/*
alert( "Please enter a valid phone number" );

phone.select();*/
return false;
}
return true;
}

function numberFormat(nStr,prefix){
	
	
var prefix = prefix || '';
nStr += '';
x = nStr.split('.');

x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return prefix + x1 + x2;
}


function validatework(frm)
{
	var i=0;
	var cnt=0;
	for (i=0;i<=16;i++)
	{	
		if (frm.cat[i].checked==true)
		{
			alert("in");
			cnt=cnt+1;		
			
		}		
		
		
	}	

	if(cnt==0)
	{
		alert("Please select atleast 1 Category");
		return false;
	}
	else
	{
	alert("count");
	return true;
	
	}
	
}

function validrequest(frm)
{
	with(frm)
{

	
	 if (validate_required(brief,"Summarize the service must be filled out!")==false)
  {brief.focus();return false;}

 if (validate_required(wr1,"Work Request 1 must be filled out!")==false)
  {wr1.focus();return false;}


if(wr1.value.length>1000)
{
	alert("You description is exceed from 10000 characters");
	wr1.focus();
	return false;
	
}

if(cnt.value>1)
{
 if (validate_required(wr2,"Work Request 2 must be filled out!")==false)
  {wr2.focus();return false;}
 
 if(wr2.value.length>1000)
{
	alert("You description is exceed from 10000 characters");
	wr2.focus();
	return false;
	
}
}

if(cnt.value > 2){
 if (validate_required(wr3,"Work Request 3 must be filled out!")==false)
  {wr3.focus();return false;}
 
 if(wr3.value.length>1000)
{
	alert("You description is exceed from 10000 characters");
	wr3.focus();
	return false;
	
}
}


if(cnt.value > 3){
 if (validate_required(wr4,"Work Request 4 must be filled out!")==false)
  {wr4.focus();return false;}
  
	  if(wr4.value.length>1000)
	{
		alert("You description is exceed from 10000 characters");
		wr4.focus();
		return false;
		
	}
}

 if (validate_required(date1,"Date must be filled out!")==false)
  {date1.focus();return false;}
  
  /*if(validate_selectcombo(repair)==false)
{
alert("Car towed to the repair facility must be filled out!");						
repair.focus();
return false;			 
}*/

  if(validate_selectcombo(willingdrive)==false)
{
  alert("Miles must be filled out!");
  {willingdrive.focus();return false;}
}

  if (validate_required(txtCaptcha,"Code number must be filled out!")==false)
  {txtCaptcha.focus();return false;}
  


 if (agree.checked==false)
 {
	 alert("Please review Terms of Use and click on the box to show you agree.");
  agree.focus();return false;
  
  }

  
}
return true;
}

function validrating(thisform)
{
with (thisform)
{

 if (validate_required(finalinvoice,"Final Invoice must be filled out!")==false)
  {finalinvoice.focus();return false;}

if(IsNumeric(finalinvoice.value)==false)
  {
  alert("Invoice Price must be in Numbers Only ");
  finalinvoice.focus();
  return false;
  }

 if (validate_required(finalinvoice1,"Re Enter Final Invoice must be filled out!")==false)
  {finalinvoice1.focus();return false;}
  
  if(IsNumeric(finalinvoice1.value)==false)
  {
  alert("Invoice Price must be in Numbers Only ");
  finalinvoice1.focus();
  return false;
  }

   if (finalinvoice.value!=finalinvoice1.value)
  {alert("Final invoice mismatched");
	  finalinvoice.focus();return false;}
	  
	if(valButtonRate(rateoverall)==false)
	{
		alert("Rating for Overall experience is must");
		return false;
	}
	
	if(valButtonRate(busweb)==false)
	{
		alert("Rating for Ability to communicate with shop is must");
		return false;
	}

	if(valButtonRate(ratework)==false)
	{
		alert("Rating for Shop completed the job on time is must");
		return false;
	}
	
	if(valButtonRate1(busshop)==false)
	{
		alert("Rating for Business with Shop is must");
		return false;
	}
	
	if(commentforshop.value.length>1000)
	{
		alert("Pleae write comments in short, character limit is exceed from maximum");
		commentforshop.focus();
		return false;
		
	}
		if(commentforweb.value.length>1000)
	{
		alert("Pleae write comments in short, character limit is exceed from maximum");
		commentforweb.focus();
		return false;
		
	}

}
return true;
}

/*function validatephone(ph1,ph2,ph3)  
{
	alert("in");
	var v1=ph1;
	var v2=ph2;
	var v3=ph3;
	
	
if (v1.length!=3 || v2.length!=3 || v3.length!=4) 
{
return false;
}
return true;
}
*/
function validatephone(frm)  
{
	with(frm)
	{
	var v1=phoneno.value;
	var v2=phoneno1.value;
	var v3=phoneno2.value;
	
if (v1.length!=3 || v2.length!=3 || v3.length!=4) 
{
	
alert("phone no is not in 3 - 3 - 4 format.");


phoneno1.value="";
phoneno2.value="";
phoneno.value="";
phoneno.focus();

return false;
}
if((isNaN(v1)==true) || (isNaN(v2)==true) ||(isNaN(v3)==true))
{
alert("Phone No must be numeric.");

phoneno1.value="";
phoneno2.value="";
phoneno.value="";
phoneno.focus();
return false;
}
}

return true;
}

/*function tabset(thisfrm)
{
with (thisfrm)
{

if (phoneno.value.length==3)	
phoneno1.focus();

if (phoneno1.value.length==3)	
phoneno2.focus();
return true;
}
}
*/

function autoTab(element, nextElement) {
    if (element.value.length == element.maxLength && nextElement != null) {
        element.form.elements[nextElement].focus();
    }
}


function validcontactus(frm)
{
	
	with (frm)
	{
	  	if (validate_email(email)==false)
		{
			
			email.focus();
			return false;
		}
	 if (validate_required(message,"Comment must be filled out!")==false)
	  {message.focus();return false;}
	  
	  if(message.value.length>10000)
	  {
		alert("Character limit exceed from 1000");
		message.focus();return false;
	   }
	
	
	}
	
}

///////////////////for paypal validation /////////////////
function validate_paypal(frm)
{
	with (frm)
	{
	  	
		
		if (validate_required(firstName,"First Name must be filled out!")==false)
		{firstName.focus();return false;}
		
		if (validate_required(lastName,"Last Name must be filled out!")==false)
		{lastName.focus();return false;}
		
		 if(validate_selectcombo(creditCardType)==false)
			{
			  alert("Credit Card Type must be filled out!");
			  {creditCardType.focus();return false;}
			}
		
		if (validate_required(creditCardNumber,"Credit Card Number must be filled out!")==false)
		{creditCardNumber.focus();return false;}
		
	
	
		 if(validate_selectcombo(expDateMonth)==false)
			{
			  alert("Exp Date Month must be filled out!");
			  {expDateMonth.focus();return false;}
			}
			
		 if(validate_selectcombo(expDateYear)==false)
			{
			  alert("Exp Date Year must be filled out!");
			  {expDateYear.focus();return false;}
			}
			if (validate_required(cvv2Number,"cvv2Number must be filled out!")==false)
		{cvv2Number.focus();return false;}
		
		if (validate_required(address1,"Address1 must be filled out!")==false)
		{address1.focus();return false;}
	
	
	/*if (validate_required(city,"Address1 must be filled out!")==false)
		{city.focus();return false;}*/
		
		 /*if(validate_selectcombo(state)==false)
			{
			  alert("State must be filled out!");
			  {state.focus();return false;}
			} 
			*/
		/*if (validatezipnine(zip)==false)
		{
			zip.focus();
			return false;
		}*/
	}//with
	
}


//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePage; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }   
}

//Called every time our XmlHttpRequest objects state changes
function updatePage() {
 //Check if our response is ready
 if (receiveReq.readyState == 4) {
   //Set the content of the DIV element with the response text
   document.getElementById('result').innerHTML = receiveReq.responseText;
   //Get a reference to CAPTCHA image
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = 'create_image.php?' + Math.random();
 }
}

//Called every time when form is perfomed
function getParam(theForm) {
	alert("in");
 //Set the URL
 var url = 'captcha.php';
 //Set up the parameters of our AJAX call
 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
 //Call the function that initiate the AJAX request
 makeRequest(url, postStr);
}
