///////////////////////// COMMON JAVASCRIPT FILE ////////////////////////////
//																		   //
// 	  COMMON JAVASCRIPT FILE FOR ALL THE SCRIPTS USED ALLOVER THE SITE     //
//																		   //
/////////////////////////////////////////////////////////////////////////////


/******************* Visual SEO More Info *****************************/
function moreinfo()
{
document.getElementById("content").style.display="block";
document.getElementById("moreinfodiv1").style.display="block";
document.getElementById("moreinfodiv").style.display="none";
}
function moreinfohide()
{
document.getElementById("content").style.display="none";
document.getElementById("moreinfodiv").style.display="block";
document.getElementById("moreinfodiv1").style.display="none";
}
/******************* Visual SEO More Info *****************************/

/******************* Menu Color Change *****************************/
function overColor(myheader)
{
document.getElementById(myheader).className='headerMainLinksOver';
document.getElementById(myheader).style.color="#333C00";
}
function outColor(myheader)
{
document.getElementById(myheader).className='headerMainLinks';
document.getElementById(myheader).style.color="#FFFFFF";
}
/******************* Menu Color Change *****************************/
function changeColor(obj, ftColor)	// Change Button Color
{
	if (document.getElementById)
	{
		obj.style.color = ftColor;
	}
}
/******************* Common Scripts *****************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { // pop opens a browser window
  	window.open(theURL,winName,features);
}
/******************* Common Scripts *****************************/


//////////////////////////// Data Entry Validation /////////////////////////////////

function alphanumeric(obj)
{

if (event.keyCode==46 || event.keyCode==126 || event.keyCode==32) 
		event.returnValue = false; 
	if ((event.keyCode >=33 && event.keyCode <=47) || (event.keyCode >=58  &&  event.keyCode <=64) || (event.keyCode >=91 && event.keyCode <=96 ) ||(event.keyCode >=123 && event.keyCode <=127 ) ) 
		event.returnValue = false; 

}
function validalphabet(e) 
	{
	var mykey = window.event ? e.keyCode : e.which; 
	
		if (mykey==46 || mykey==126) 
		{ 
			return false; 
		}
		
		if (((mykey > 32 && mykey < 48) || (mykey > 57 && mykey < 65) || (mykey > 90 && mykey < 97) || (mykey > 45 && mykey <= 57)))
		{ 
			return false; 
		}
	return true;
} 
function validatenumber(e) 
{
	var mykey = window.event ? e.keyCode : e.which; 
	
	if ((mykey <= 47 || mykey > 57) && mykey !=13 && mykey !=0 && mykey != 8) 
	
	{ 
	//alert ("Enter number only"); 
	return false; 
	} 
	return true;
	}

function reversetabphone(f1,f2,e)
{
	phone1 = f1;
    phone2 = f2;
    var mykey = window.event ? e.keyCode : e.which;
 
 if (mykey == 8 || mykey == 46 ) 
	{
	if( document.getElementById(phone2).value.length ==0)
	   {
		document.getElementById(phone1).focus();
		document.getElementById(phone1).value=document.getElementById(phone1).value;
	   }
	}
	
}
function validemail(mailStr)
{
	var matchStr=mailStr;
 	var isValid = (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(matchStr));

	if(isValid) 
	{
 		return true;
	}
	else
	{
		return false;
	}
} 
function isValidState(State)
{
	
	if ((State.selectedIndex==0))
		{
			alert("Select State");
			State.focus();
			return false;

		}
return true;
}
function tabvalidatePhone(phfield1,phfield2)
{
	if(document.getElementById(phfield1).value.length==3) 
		document.getElementById(phfield2).focus();
}
function removeLeadingAndTrailingChar(inputString)
{
	var removeChar = " ";
	var returnString = inputString;
	if (removeChar.length)
   		{
		  while(''+returnString.charAt(0)==removeChar)
			{
			  returnString=returnString.substring(1,returnString.length);
			}
    	  while(''+returnString.charAt(returnString.length-1)==removeChar)
	 	    {
	  	      returnString=returnString.substring(0,returnString.length-1);
			} 
		}
		return returnString;
}

 /****** My ValidNumber & TabValidationForPhoneNumbers with Cross Browser Compatiblity ******/
var myphfield1;
var myphfield2;
var myval;
function mytabvalidatePhone(p1,p2,e)
{
  phfield1 = p1;
  phfield2 = p2;
var mykey = window.event ? e.keyCode : e.which;
if ((mykey <= 47 || mykey > 57) && mykey !=13 && mykey !=0 && mykey != 8) 
	{
	myval=""
//	alert ("Enter number only");
	return false;
	}
	if( (document.getElementById(phfield1).value.length==3) && (mykey > 47 && mykey <= 57) )
	{
	myval= String.fromCharCode(mykey);
	setTimeout("document.getElementById(phfield2).focus(); if(document.getElementById(phfield1).value.length < 3) { setTimeout('document.getElementById(phfield1).focus();  document.getElementById(phfield1).value=myval;  ',10); } else { document.getElementById(phfield2).value=myval; } ",10);
	}
return true;
}

function myvalidnumber(e)
{
var mykey = window.event ? e.keyCode : e.which;
		if ((mykey <= 47 || mykey > 57) && mykey !=13 && mykey !=0 && mykey != 8) 
			{
//			alert ("Enter number only");
		return false;
			}
return true;			
}
//////////////////////////// Data Entry Validation /////////////////////////////////
/******************* Form Common Scripts *****************************/
function isValidSelTitle(Title)
{
/*	if (Title.selectedIndex==0)
	{
		alert("Select Title");
		Title.focus();
		return false;
	}*/
return true;
}						  
// First Name Validation
function isValidFirstName(FirstName)
{
	FirstName.value=removeLeadingAndTrailingChar(FirstName.value);
	if ((FirstName.value==""))
		{
			alert("Enter First Name ");
			FirstName.focus();
			return false;
		}
return true;
}
  // Last Name Validation
function isValidLastName(LastName)
{
	LastName.value=removeLeadingAndTrailingChar(LastName.value);
	if ((LastName.value==""))
		{
			alert("Enter Last Name ");
			LastName.focus();
			return false;

		}
return true;
}

// Email Validation

function isValidEmail(Email)
{
	if (Email.value=="")
	{
		alert("Enter E-mail Id");
		Email.focus();
		return false;
	}

	if (Email.value!="" && !validemail(Email.value))
	{ 
		alert("Enter Valid E-mail Id");
		Email.focus();
		return false;		
	}
return true;
}
 // Mandatory Phone Validation
 function isValidMPhone(ph1,ph2,ph3,ph,phtype)
 {
	if (phtype == undefined)  { phtype =' Phone '  ; }
	ph1.value=removeLeadingAndTrailingChar(ph1.value);	
	ph2.value=removeLeadingAndTrailingChar(ph2.value);	
	ph3.value=removeLeadingAndTrailingChar(ph3.value);

	if(isNaN(ph1.value))
		{
			alert(phtype +" should be Numeric");	
			ph1.select();
			return false;
		}
	if(isNaN(ph2.value))
		{
			alert(phtype +" should be Numeric");	
			ph2.select();
			return false;
		}
	if(isNaN(ph3.value))
		{
			alert(phtype +" should be Numeric");	
			ph3.select();
			return false;
		}		

	if (ph1.value.length<3)
	{
		alert("Enter " + phtype);
		ph1.focus();
		return false;
	}
	if (ph2.value.length<3)
	{
		alert("Enter " + phtype);
		ph2.focus();
		return false;
	}
	if (ph3.value.length<4)
	{
		alert("Enter " + phtype);
		ph3.focus();
		return false;
	}	
	if(ph1.value.length==3 &&ph2.value.length==3 && ph3.value.length==4) {
		ph.value="("+ph1.value+") "+ph2.value+"-"+ph3.value;
	}
return true;
 }

 function isValidNMPhone(ph1,ph2,ph3,ph, typ)
{
	var a = ph1.value=removeLeadingAndTrailingChar(ph1.value);	
	var b = ph2.value=removeLeadingAndTrailingChar(ph2.value);	
	var c = ph3.value=removeLeadingAndTrailingChar(ph3.value);	
	var merged = a+''+b+''+c;
	if(merged.length>0 && merged.length<10) {
		alert('Invalid '+ typ);
		if(a.length!=3) ph1.select();
		else if(b.length!=3) ph2.select();
		else ph3.select();
		return false;
	}
	if(ph1.value.length==3 &&ph2.value.length==3 && ph3.value.length==4) {
		ph.value="("+ph1.value+") "+ph2.value+"-"+ph3.value;
	}
return true;
}

function isValidStreet(Street)
 {
	 if (Street.value!="")
	{
		  Street.value=removeLeadingAndTrailingChar(Street.value);
	}
return true;
 }
function isValidCity(City)
 {
	 if (City.value!="")
	{
		  City.value=removeLeadingAndTrailingChar(City.value);
	}
return true;
 }
function isValidZip(Zip)
{
	Zip.value=removeLeadingAndTrailingChar(Zip.value);		
	if(isNaN(Zip.value))
	{
		alert("Zip Code should be Numeric");	
		Zip.select();
		return false;
	}			
	if (Zip.value=="")
	{
		alert("Enter Zip Code");
		Zip.focus();
		return false;
	}
	if(Zip.value.length<5)
	{
		alert("Enter Five Digit Zip Code");
		Zip.focus();
		return false;
	}		
return true;
}

function isValidMakeYear(MakeYear)
{
	MakeYear.value=removeLeadingAndTrailingChar(MakeYear.value);
	
	if(isNaN(MakeYear.value))
	{
		alert("Make Year should be Numeric");	
		MakeYear.select();
		return false;
	}		
	
	if(MakeYear.value=="")
	{
		alert("Enter Make Year");
		MakeYear.focus();
		return false;
	}
	if(MakeYear.value.length<4)
	{
		alert("Enter Four Digit Make Year");
		MakeYear.focus();
		return false;
	}
	if (MakeYear.value <=1960 || MakeYear.value >2015)
		{
			alert("Please Enter Valid Year");
			MakeYear.focus();
			return false;
		}
return true;	
}

function isValidMake(Make)
{
	Make.value=removeLeadingAndTrailingChar(Make.value);
	if(Make.value=="")
	{
		alert("Enter Make");
		Make.focus();
		return false;
	}	
return true;
}
function isValidModel(Model)
{
	Model.value=removeLeadingAndTrailingChar(Model.value);
	if(Model.value=="")
	{
		alert("Enter Model");
		Model.focus();
		return false;
	}	
return true;
}
function isValidTrim(Trim)
{
	Trim.value=removeLeadingAndTrailingChar(Trim.value);
	if(Trim.value=="")
	{
		alert("Enter Trim");
		Trim.focus();
		return false;
	}	
return true;
}
function isValidNMTrim(Trim)
{
 Trim.value=removeLeadingAndTrailingChar(Trim.value);
 return true;
}

function isValidNMMileage(Mileage)
{
	Mileage.value=removeLeadingAndTrailingChar(Mileage.value);
	if(isNaN(Mileage.value))
	{
		alert("Mileage should be Numeric");	
		Mileage.select();
		return false;
	}		
	return true;
}
function isValidMMileage(Mileage)
{
	Mileage.value=removeLeadingAndTrailingChar(Mileage.value);
	/*if(isNaN(Mileage.value))
	{
		alert("Mileage should be Numeric");	
		Mileage.select();
		return false;
	}
	if(Mileage.value=="")
	{
		alert("Enter Mileage");
		Mileage.value="";
		Mileage.focus();
		return false;
	
	}	*/
	return true;
}
function isValidMVIN(VIN)
{
	VIN.value=removeLeadingAndTrailingChar(VIN.value);
	if(VIN.value=="")
	{
		alert("Enter VIN");
		VIN.focus();
		return false;
	}
	if(VIN.value.length!=17)
	{
		alert("Enter valid VIN. It should be 17 characters Length");
		VIN.focus();
		return false;
	}
return true;	
}
function isValidNMComments(Comments)
{
	Comments.value=removeLeadingAndTrailingChar(Comments.value);
 return true;
}
function isValidNMColor(Color)
{
	Color.value=removeLeadingAndTrailingChar(Color.value);
 return true;
}

function isValidPayoff(Payoff)
{
	if(Payoff.value=="")
	{
		alert("Enter Payoff Amount");
		Payoff.focus();
		return false;
	}
	if (Payoff.value!="" && !formatDollar(Payoff))
	{ 
		alert("Enter Valid Payoff Amount");
		Payoff.focus();
		return false;		
	}
 return true;
}
function isValidValue(Value)
{
	if(Value.value=="")
	{
		alert("Enter Value Amount");
		Value.focus();
		return false;
	}
	if (Value.value!="" && !formatDollar(Value))
	{ 
		alert("Enter Valid Value Amount");
		Value.focus();
		return false;		
	}
 return true;
}

function isValidSelectTransmission(Transmission)
{
	if(Transmission.selectedIndex==0)
	{
		alert("Select Transmission");
		Transmission.focus();
		return false;
	}
return true;
}

function isValidSelectMake(Make)
{
	if (Make.selectedIndex==0)
	{
		alert("Select Make");
		Make.focus();
		return false;
	}
return true;
}

function isValidSelectModel(Model)
{
	if (Model.selectedIndex==0)
	{
		alert("Select Model");
		Model.focus();
		return false;
	}
return true;
}
function isValidSelectTrim(Trim)
{
	if (Trim.selectedIndex==0)
	{
		alert("Select Trim");
		Trim.focus();
		return false;
	}
return true;
}
function isValidSelectInterestLevel(InterestLevel)
{
	if (InterestLevel.selectedIndex==0)
	{
		alert("Select Interest Level");
		InterestLevel.focus();
		return false;
	}
return true;
}

function isValidPriceRange(PriceRange)
{
	if (PriceRange.value=="")
	{
		alert("Enter Price Range");
		PriceRange.focus();
		return false;
	}
	if ( PriceRange.value!="" && !formatDollar(PriceRange) ) 
	{
		alert("Enter Valid Price Range");
		PriceRange.focus();
		return false;
	}
	if (PriceRange.value==".")
	{
		alert("Enter Valid Price Range");
		PriceRange.focus();
		return false;
	}
return true;	
}

function isValidRequestDate(ReqDate)
{
	if(ReqDate.selectedIndex==0)
	{
		alert("Select Date to schedule an Appointment");
		ReqDate.focus();
		return false;
	}	
return true;
}
function isValidRequestDate2(ReqDate)
{
	if(ReqDate.selectedIndex==0)
	{
		alert("Select Date to schedule an Collision Appointment");
		ReqDate.focus();
		return false;
	}	
return true;
}

function isValidAppointmentTime(AppoinTime)
{
	if (AppoinTime.selectedIndex==0 )
	{
		alert("Select Drop Off Time");
		AppoinTime.focus();
		return false;
	}
	if (AppoinTime.options[1].value=="Closed" )
	{
		checktime();
		return false;
	}
return true;	
}

function isValidContacttype(Contacttype)
{
	if (Contacttype.selectedIndex==0 )
	{
		alert("Select heard about our website");
		Contacttype.focus();
		return false;
	}
	
return true;	
}

function isValidJobType(JobType)
{
	JobType.value=removeLeadingAndTrailingChar(JobType.value);
	if (JobType.value=="")
	{
		alert("Enter Job Type ");
		JobType.focus();
		return false;
	}
return true;		
}

function isValidJobTitle(JobTitle)
{
	JobTitle.value=removeLeadingAndTrailingChar(JobTitle.value);
	if (JobTitle.value=="")
	{
		alert("Enter Job Title ");
		JobTitle.focus();
		return false;
	}
return true;		
}
function isValidResume(resume)
{
	resume.value=removeLeadingAndTrailingChar(resume.value);
	if (resume.value=="")
	{
		alert("Enter Resume ");
		resume.focus();
		return false;
	}
return true;		
}

function isValidBestTimeToDrive(BestTimeToDrive)
{
		if(BestTimeToDrive.selectedIndex==0)
		{
			alert("Select Best Time To Drive");
			BestTimeToDrive.focus();
			return false;
		}
		return true;
}
function isValidAMPM(AMPM)
{
		if(AMPM.selectedIndex==0)
		{
			alert("Select AM or PM");
			AMPM.focus();
			return false;
		}
return true;		
}
function isValidBestDateToDriveYear(BestDateToDriveYear)
{
		if(BestDateToDriveYear.selectedIndex==0)
		{
			alert("Select Best Date To Drive Year");
			BestDateToDriveYear.focus();
			return false;
		}
		return true;
}

function isValidBestDateToDriveMonth(BestDateToDriveMonth)
{
		if(BestDateToDriveMonth.selectedIndex==0)
		{
			alert("Select Best Date To Drive Month");
			BestDateToDriveMonth.focus();
			return false;
		}
return true;		
}
function isValidReference(Reference)
{
	if(Reference.selectedIndex==0)
		{
			alert("Select Reference");
			Reference.focus();
			return false;
		}
return true;		
}
/******************* Form Common Scripts *****************************/

//////////////////////////// Moreinfo Validation /////////////////////////////////

function validatemoreinfo(thisForm) {
	if(!(isValidSelTitle(thisForm.Title))) return false;
	if(!(isValidFirstName(thisForm.FirstName))) return false;
	if(!(isValidLastName(thisForm.LastName))) return false;
	if(!(isValidEmail(thisForm.Email))) return false;
	if(!(isValidMPhone(thisForm.OffPhone1,thisForm.OffPhone2,thisForm.OffPhone3,thisForm.OffPhone,' Day Phone '))) return false;
	if(!(isValidNMPhone(thisForm.ResPhone1,thisForm.ResPhone2,thisForm.ResPhone3,thisForm.ResPhone,' Evening Phone '))) return false;			    		
	
return true;
}
//////////////////////////// Contact Us Validation /////////////////////////////////
function validatecontactus(thisForm)
{
		//alert('1');
	if(!(isValidSelTitle(thisForm.Title))) return false;
	if(!(isValidFirstName(thisForm.FirstName))) return false;
	if(!(isValidLastName(thisForm.LastName))) return false;
	if(!(isValidStreet(thisForm.Street))) return false;
	if(!(isValidCity(thisForm.City))) return false;	
	if(!(isValidZip(thisForm.Zip))) return false;	
	if(!(isValidEmail(thisForm.Email))) return false;
	if(!(isValidMPhone(thisForm.OffPhone1,thisForm.OffPhone2,thisForm.OffPhone3,thisForm.OffPhone,' Day Phone '))) return false;
	if(!(isValidNMPhone(thisForm.ResPhone1,thisForm.ResPhone2,thisForm.ResPhone3,thisForm.ResPhone,' Evening Phone '))) return false;	
	if(!(isValidNMPhone(thisForm.Fax1,thisForm.Fax2,thisForm.Fax3,thisForm.Fax,' Fax '))) return false;
	if(!(isValidReference(thisForm.Reference))) return false;	
	if(!(isValidNMComments(thisForm.Comments))) return false;		
return true;
}
//////////////////////////////// Online Small Form ///////////////////////////

function validateOnline(thisForm)
{
	if(!(isNonMandFirstName(thisForm.FirstName))) return false;
	if(!(isNonMandLastName(thisForm.LastName))) return false;
	if(!(isNonMandValidPhone(thisForm.OffPhone1,thisForm.OffPhone2,thisForm.OffPhone3,thisForm.OffPhone,'Day Phone'))) return false;
	if(!(isValidEmail(thisForm.Email))) return false;
}

function isNonMandFirstName(FirstName)
{
	FirstName.value=removeLeadingAndTrailingChar(FirstName.value);
	return true;
}
  // Last Name Validation
function isNonMandLastName(LastName)
{
	LastName.value=removeLeadingAndTrailingChar(LastName.value);
	return true;
}
function isNonMandValidPhone(ph1,ph2,ph3,ph, typ)
{
	var a = ph1.value=removeLeadingAndTrailingChar(ph1.value);	
	var b = ph2.value=removeLeadingAndTrailingChar(ph2.value);	
	var c = ph3.value=removeLeadingAndTrailingChar(ph3.value);	
	var merged = a+''+b+''+c;
	if(merged.length>0 && merged.length<10) {
		alert('Invalid '+ typ);
		if(a.length!=3) ph1.select();
		else if(b.length!=3) ph2.select();
		else ph3.select();
		return false;
	}
	if(ph1.value.length==3 &&ph2.value.length==3 && ph3.value.length==4) {
		ph.value="("+ph1.value+") "+ph2.value+"-"+ph3.value;
	}
return true;
}
function clear_commentBox()
{
	if (document.onlineSpls.Comments.value == "Please include any additional information or options that you would like")
	document.onlineSpls.Comments.value = "";
}
function disp_commentBox()
{
	if (document.onlineSpls.Comments.value == "")
	document.onlineSpls.Comments.value = "Please include any additional information or options that you would like";
}
//////////////////////////////// Online Small Form ///////////////////////////
//////////////////// Home Coupons and Discounts ///////////////////
function getVal()
{
	return false;
}
function validateCouponsAndDiscounts(thisForm)
{
	if(!(isValidEmail(thisForm.Email))) return false;

	popUpWindow('thankyou.jsp?FirstName=' + document.couponsAndDiscountsForm.FirstName.value + '&LastName=' + document.couponsAndDiscountsForm.LastName.value + '&Email=' + document.couponsAndDiscountsForm.Email.value + '&mypage=' + document.couponsAndDiscountsForm.mypage.value);
	
	//popUpWindow('thankyou.jsp?Email=' + document.couponsAndDiscountsForm.Email.value + '&mypage=' + document.couponsAndDiscountsForm.mypage.value);

		return true;
}

function popUpWindow(urlStr) {
	popUpWin = open(urlStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=400,height=330,left=320,top=240');
	popUpWin.focus();
	
} 
//////////////////// Home Coupons and Discounts ///////////////////


