///////////////////////// COMMON JAVASCRIPT FILE ////////////////////////////
//																		   //
// 	  COMMON JAVASCRIPT FILE FOR ALL THE SCRIPTS USED ALLOVER THE SITE     //
//																		   //
/////////////////////////////////////////////////////////////////////////////

//for Home Page

///////////////////////////////////////Setting Position of layers//////////////////
////////////////////////////////////////////////////////////////////////////////

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
			// Handle all the the FSCommand messages in a Flash movie
			function fscommand_DoFSCommand(command, args) 
			{
				document.DetailedInfo.ExtColor.value=args;
				document.DetailedInfo.ExtColor1.value=args;
				document.DetailedInfo.IntColor.value=command;
			}

// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub fscommand_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call fscommand_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}


function MM_openBrWindow(theURL,winName,features) { // pop opens a browser window
  	window.open(theURL,winName,features);
}

function dot(obj)
{
	if (event.keyCode==190 || event.keyCode==110)
	{

var i=0;j=0;text="";total="";
var len=obj.value.length;
for(i=0;i<len;i++)
{
	text=obj.value.charAt(i);
	if(text==".")
	{
		j=j+1;
	}
	if(j>1){text='';}
	total=total+text;
}
obj.value=total;
	}
}

function validalphanumeric(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 > 122 && mykey <= 127)))
		{ 
			return false; 
		}
	return true;
}



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 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 formatDollarzero(obj)
{
	var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	//alert(num);
	num.substring(num.length-(4*i+3));
	var temp=((sign)?'':'-') + '$' + num + '.' + cents;
	if(temp!="$0.00") {
		//alert(sign);
		obj.value=((sign)?'':'-') + '$' + num + '.' + cents;
		//alert(obj.value);
		return true;
	}else if(temp=="$0.00"){
		//alert('djfdshfjdj')	;
		obj.value=("$0.00")
	}
	else {
		obj.value="";
		return false;
	}
}

function formatDollarNew(obj)
{
	
	//alert(obj);
	
	
	
	var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	//alert(num);
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	//alert(sign);
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	//alert(num);
	num.substring(num.length-(4*i+3));
	var temp=((sign)?'':'-') + '$' + num + '.' + cents;
	if(temp!="") {
		obj.value=((sign)?'':'-') + '$' + num + '.' + cents;
		//alert(obj.value);
		return true;
	}	
	else { //alert('3');
		obj.value="";
		return false;
	}
}


function getYears() {
   	var years = new Array(2002,2003,2004,2005)
   	for (var i = 0; i < document.serviceappointment.BestDateToDriveYear.length; i++) {
    	document.serviceappointment.BestDateToDriveYear.options[0] = null;
	}
	document.serviceappointment.BestDateToDriveYear.options[0] = new Option("years");
    timeC = new Date();
    currYear = timeC.getFullYear();
    for (var i = 0; i < years.length; i++) {
    	document.serviceappointment.BestDateToDriveYear.options[i] = new Option(years[i]);
  	}
    document.serviceappointment.BestDateToDriveYear.options[0].selected=true;
}

function alertSubmit() {
leftPos = 0;
topPos = 0;
	if (screen) {
		leftPos = (screen.width / 2) - 171;
		topPos = (screen.height / 2) - 2;
	}


	submitProcess=window.open('../process.jsp','name','height=120,width=300,left='+leftPos+',top='+topPos);

return true;
}


function formatDollar(obj)
{
	var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	//alert(num);
	num.substring(num.length-(4*i+3));
	var temp=((sign)?'':'-') + '$' + num + '.' + cents;
	if(temp!="$0.00") {
		obj.value=((sign)?'':'-') + '$' + num + '.' + cents;
		//alert(obj.value);
		return true;
	}	
	else {
		obj.value="";
		return false;
	}
}
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;
}


function validmileage(obj)
{
	var num = obj.value;
    if(num==0)
	{
	obj.value="";
	//alert("Enter Mileage");
	return false;
	}
	else 
	{
		for(var i=0; i<obj.value.length+6; i++)
		{
				
				if(obj.value.indexOf("0")==0) 
				{
						//alert(obj.value);
						obj.value = obj.value.substring(1,obj.value.length);
			
				}
		}
	}
	return true;
}
function formatDollar1(obj)
{
	//alert(obj.value);
	var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num;
	var temp=((sign)?'':'-') + '$' + num + '.' + cents;
	if(temp!="$0.00")
	{
		obj.value=num;
		return true;
	}
	else
	{
		obj.value="";
		//obj.focus();
		return false;
	}
}
//-->


function formatDollar2(obj)
{
var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+
	num.substring(num.length-(4*i+3));
	//alert("out  "+cents);
	if(cents==00)
	{
	//alert("if  "+cents);
	var temp=((sign)?'':'-') + '' + num;
	}
	else
	{
		//alert("else  "+cents);
	var temp=((sign)?'':'-') + '' + num+ '.' + cents;
	}
	if(temp!="0.00" || temp!="00") {
				if(cents==00)
				{
			//	alert("not 00"+cents);
				obj.value=((sign)?'':'-') + '' + num;
				}
				else
				{
				//alert("00"+cents);
				obj.value=((sign)?'':'-') + '' + num + '.' + cents;
				return true;
				}
	}	
	else {
		obj.value="";
		return false;
	}
}


 
 /// 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);
		if(navigator.appName=="Netscape")
		{
		document.getElementById(phfield2).value=myval;
		
		}
		document.getElementById(phfield2).focus();
		
	
	//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;			
}
 /////////////the code ends here/////////////
 
                   						  
			  
// First Name Validation
function isValidFirstName(FirstName)
{
	FirstName.value=removeLeadingAndTrailingChar(FirstName.value);
	if ((FirstName.value==""))
		{
			alert("Enter Name ");
			FirstName.focus();
			return false;
		}
return true;
}
  // Company Validation
function isValidCompany(Company)
{
	Company.value=removeLeadingAndTrailingChar(Company.value);
	if ((Company.value==""))
		{
			alert("Enter Company Name ");
			Company.focus();
			return false;

		}
return true;
}
function isValidServiceAdvisor(ServiceAdvisor)
{
	if (ServiceAdvisor.selectedIndex==0)
	{
		alert("Select Service Advisor");
		ServiceAdvisor.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 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 isValidStreet(Street)
 {
	 if(Street.value=="")
	{
		alert("Enter Address");
		Street.focus();
		return false;
	}
	 
	 if (Street.value!="")
	{
		  Street.value=removeLeadingAndTrailingChar(Street.value);
	}
return true;
 }
function isValidCity(City)
 {
	 if(City.value=="")
	{
		alert("Enter City");
		City.focus();
		return false;
	}
	 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 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 isValidNMComments(Comments)
{
	Comments.value=removeLeadingAndTrailingChar(Comments.value);
 return true;
}
function isValidNMColor(Color)
{
	Color.value=removeLeadingAndTrailingChar(Color.value);
 return true;
}


function isValidSelectMake(Make)
{
	if (Make.selectedIndex==0)
	{
		alert("Select Make");
		Make.focus();
		return false;
	}
return true;
}

function isValidSelectTerm(Term)
{
	if (Term.selectedIndex==0)
	{
		alert("Select Term");
		Term.focus();
		return false;
	}
return true;
}
function isValidSelectMilesYear(MilesYear)
{
	if (MilesYear.selectedIndex==0)
	{
		alert("Select Miles Per Year");
		MilesYear.focus();
		return false;
	}
return true;
}


//////////////////////////// Contact Us Validation /////////////////////////////////
function validateleasequote(thisForm)
{
		//alert('1');
	if(!(isValidFirstName(thisForm.FirstName))) return false;
	if(!(isValidCompany(thisForm.Company))) return false;
	if(!(isValidStreet(thisForm.Street))) return false;
	if(!(isValidCity(thisForm.City))) return false;	
	if(!(isValidZip(thisForm.Zip))) return false;	
	if(!(isValidMPhone(thisForm.OffPhone1,thisForm.OffPhone2,thisForm.OffPhone3,thisForm.OffPhone,' Work Phone '))) return false;
	if(!(isValidNMPhone(thisForm.ResPhone1,thisForm.ResPhone2,thisForm.ResPhone3,thisForm.ResPhone,' Cell Phone '))) return false;
    if(!(isValidEmail(thisForm.Email))) return false;	
	if(!(isValidMake(thisForm.Make))) return false;		
	if(!(isValidModel(thisForm.Model))) return false;	
    if(!(isValidSelectTerm(thisForm.Term))) return false;		
    if(!(isValidSelectMilesYear(thisForm.MilesYear))) return false;			
	//thankYouOnSamePage(thisForm);
return true;
}

/*******************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";
}