isClick=" ";
checksp = 0;

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function runcertificate()
{
	window.open('http://www.aceimports.com/includes/popup-certificatemlist.asp','','width=600,height=485,left=200,top=200').blur();
	window.focus();
}

function runpreloader()
{
	MM_preloadImages('/images/nav-home-ovr.gif','/images/nav-aboutus-ovr.gif','/images/nav-search-ovr.gif','/images/nav-vehiclerequest-ovr.gif','/images/nav-contact-ovr.gif','/images/nav-links-ovr.gif','/images/nav-email-ovr.gif','/images/nav-financing-ovr.gif','/images/nav-showroom-ovr.gif');	
}

function switchnavoff(iID,iSRC)
{
	for( i=0; i<=document.images.length-1; i++)
	{			
		checkSRC = document.images[i].src;
		checkID = document.images[i].id;		
		v = checkSRC.length;
		n = checkID.length;
		checkimgSRC = checkSRC.substr(0, v-8);
		checkimgID = checkID.substr(0, (v+3)-v);
		
		//alert(iID + "=" + iSRC + "<br>" + checkSRC + " = " + checkimgSRC + "<br>" + checkID + " = " + checkimgID);
		if( checkimgID == "nav" && checkID !== iID)
		{
			document.images[i].src = checkimgSRC + "-off" + extension;									
		}
		else if( checkID == iID && iSRC != isClick )
		{
			document.images[iID].src = iSRC + "-ovr" + extension;
			isClick = iSRC + "-ovr" + extension;
		} 		
	}	
}

function runSubscriber()
{
	openWindow2('includes/popup-subscribemlist.asp', '', '', 1, 160, 285, 0);
}

function menunav(which, what, where)
{		
	imgSRC = document.images[which].src;
		
	v = imgSRC.length;
	oldimgSRC = imgSRC.substr(0, v-8);
	extension = ".gif";
											
	if( what == 1 )
	{			
		document.images[which].src = oldimgSRC + "-ovr" + extension; 		
	}
	else if( what == 2 )
	{			
		for( i=0; i<=document.images.length-1; i++)
		{					
			checkSRC = document.images[i].src;			
			checkID = document.images[i].id;		
			v = checkSRC.length;
			n = checkID.length;
			checkimgSRC = checkSRC.substr(0, v-8);
			checkimgID = checkID.substr(0, (v+3)-v);
						
			if( checkimgID == "nav" && checkID !== which)
			{
				document.images[i].src = checkimgSRC + "-off" + extension;									
			}
			else if( checkID == which )
			{
				if( where != "" )
				{
					//alert(parent.document.frames["main"].document.location);
					parent.document.frames["main"].document.location.href=where;
				}
				document.images[which].src = oldimgSRC + "-ovr" + extension;
				isClick = oldimgSRC + "-ovr" + extension;				
			} 		
		}		
	}
	else if( what == 0 )
	{		
		if( imgSRC != isClick )
		{ 
			newimgSRC = oldimgSRC + "-off" + extension; 
			document.images[which].src = newimgSRC;
		}
	}
	else
	{
		alert("error: please contact administrator.");
	}	
}

function sendform(fname,x)
{
	//alert(fname);
	nosubmit=0;
	
	if (x == "savebutton")
	{			
		if(fname == "feedback_mail" )
		{
			nosubmit = validatedata(fname);			
		}
		if(fname == "popup_email" )
		{
			nosubmit = validatedata(fname);			
		}
		if(fname == "popup_semail" )
		{
			nosubmit = validatedata(fname);			
		}
		if(fname == "popup_certificate" )
		{
			nosubmit = validatedata(fname);			
		}
		if(fname == "finance_form" )
		{	
		    //alert("before call");
		    //alert(document.all(fname).length);
			nosubmit = validatedata(fname);
			//alert("after nosubmit=" + nosubmit);
		}
		if(fname == "requestform" )
		{
			nosubmit = validatedata(fname);
		}
		if(fname == "vehicle_search" )
		{		    
			if( search_by.value == 0 )
			{
				alert("Please Select a Search Field");
				nosubmit = -1;
			}
			else if( search_txt.value == 0)
			    {
			        alert("Please Enter Search Criteria");
				    nosubmit = -1;
			    }
			
			if( search_and_txt.value.length >= 1 )
			{
				if( search_and_by.value == 0 )
				{
					alert("Please Select an AND Search Field");
					nosubmit = -1;
				}
			}
		}
	}			
	else if (x == "clearbutton")
	{
		for (i=0; i<=document.all(fname).elements.length-1; i++)
		{
			if( document.all(fname).elements[i].type == "text" || document.forms(fname).elements[i].type == "file" )
			{
				document.all(fname).elements[i].value = "";				
			}										
			if( document.all(fname).elements[i].type == "textarea")
			{
				document.all(fname).elements[i].value = "";				
			}			
		}		
		return;
	}
		
	if( nosubmit != -1 )
	{
		document.all(fname).submit();	
		
		if( fname == "popup_email" )
		{
			window.close();
		}	
	}
}

function propertyswitch(which,val,fname)
{	
	if( val != 0 )
	{
		for (i=0; i<=document.all.length-1; i++)
		{
			oID = document.all[i].id;
			v = oID.length;							
			fID = oID.substr(v-5, v);
			sID = oID.substr(v-10, v);
							
			if( fID == '_form' || sID == '_selectbox')
			{
				if( which == 'model' )
				{
					if( oID !== 'make_selectbox' && oID !== 'model_form' && oID !== 'customer_add_form' ) 
					{
						document.all(oID).className="hidesubt";										
					}				
				}
				else
				{				
					document.all(oID).className="hidesubt";										
				}
			}
		}
			
		if( which !== 'model' ) 
		{
			if( which !== 'make' )
			{
				document.all(which + "_form").className="show_properties_selectbox";
			}
			else
			{
				document.all("model_form").className="show_properties_selectbox";
			}
			document.all(which + "_selectbox").className="show_properties_selectbox";	
		}
		else
		{
			document.all(which + val + "_selectbox").className="show_properties_selectbox";	
			
			if( fname == 'vehicleform' )
			{
				document.all("MAKE_ID").value=val;
			}
			else
			{			
				if( which == 'model' )
				{
					document.all("MAKE_ID").value=val;
				}
				else
				{
					document.all("MODEL_MAKE_ID").value=val;
				}			
				//document.forms("modelform").all("MODEL_MAKE_ID").value=val;
				//document.forms("modelform").all("MODEL_MAKE_ID_TXT").value=document.all("make_selectbox").innerText;		
			}
		}
		if( fname !== "popup_wizard" && fname !== "requestform" )
		{
			statusmessage();
		}
	}
}

/**************************
/ -1 = invalid character (not number)
/ -2 = insufficient num of characters
/
/ strInput = the value to check
/ forwhat = check for 'num' or 'str'
/ strsize = minimum length of value
**************************/
function checkTo(strInput,forwhat,strsize) 
{		
isemail=0;
isdate=0;
isdatecount=0;

	for( ic=0; ic<strInput.length; ic++ ) 
	{
		x = strInput.charAt(ic);
	
		if( forwhat == 'num' ) 
		{	
			if(x <= " " || x == "," || x == "(" || x == "-" || x == "_" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == "`" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" ||
				(x >= "a" && x <= "z") || (x >= "A" && x <= "Z")) 
			{
				return -1;
				break;
			}			
		}		
		else if( forwhat == 'str' ) 
		{
		//alert(x);
			if(x == " " || x == "(" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" || x == ".") 
			{
				return -1;
				break;
			}			
		}
		else if( forwhat == 'spacedstr' ) 
		{
			if(x == "<" || x == ">" || x == "@" || x == "'" || x == "\\" || x == "\"" || x== "[" || x == "]") 
			{
				return -1;
				break;
			}			
		}
		else if( forwhat == 'email' ) 
		{	
			if(x == "@") 
			{
				isemail = 1;				
			}					
		}
		else if( forwhat == 'date' ) 
		{	
			if(x <= " " || x == "(" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == "`" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" ||
				(x >= "a" && x <= "z") || (x >= "A" && x <= "Z")) 
			{
				return -1;
				break;
			}
			else if(x == "/") 
			{
				isdatecount = isdatecount + 1;				
			}		
	}
	}
	
	//finishing date check..
	if( forwhat == 'date' && isdatecount != 2 )
	{
		return -1;		
	}	
		
	//finishing email check..
	if( forwhat == 'email' && strInput.length <= 7)
	{
		return -1;
	}
	else if( forwhat == 'email' && isemail != 1 )
	{
		return -1;		
	}	
		
	//checking regular string length for blanks. 		
	if( strInput.length < strsize ) 
	{
		return -1;			
	}
	else if( strInput.length <= 0 )
	{
		return -1;
	}
	else
	{
		return 1;		
	}
}

function validatedata(fname)
{			
    //alert("in func. validatedata");
	if( fname == "feedback_mail" )
	{
		for( i=0; i<document.all(fname).length-1; i++ )
		{
			fid=document.all(fname).item(i).id;
			fvalue=document.all(fname).item(i).value;
			flength=document.all(fname).item(i).value.length;		
					
			if( fid == "FEEDBACK_NAME" || fid == "FEEDBACK_SUBJECT")
			{								
				if( checkTo(fvalue,"spacedstr") == -1 )
				{
					alert('Field Requires a Character Value.');
					return -1;	
				}
			}		
			if( fid == "FEEDBACK_EMAIL")
			{
				if( checkTo(fvalue,"email") == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}
			if( fid == "FEEDBACK_MESSAGE")
			{								
				if( checkTo(fvalue,"spacedstr",1) == -1 )
				{
					alert('Please Enter A Message.');
					return -1;	
				}
			}		
		}
	}
	if( fname == "requestform" )
	{
		for( i=0; i<document.all(fname).length-1; i++ )
		{
			fid=document.all(fname).item(i).id;
			fvalue=document.all(fname).item(i).value;
			flength=document.all(fname).item(i).value.length;		
					
			if( fid == "REQUEST_FNAME" || fid == "REQUEST_LNAME")
			{								
				if( checkTo(fvalue,"str",1) == -1 )
				{
					alert('Field Requires a Character Value, First/Last Name.');
					return -1;	
				}
			}		
			if( fid == "REQUEST_EMAIL")
			{
				if( checkTo(fvalue,"email",1) == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}		
			if( fid == "REQUEST_YEAR")
			{
				if( flength > 0 && checkTo(fvalue,"num",4) == -1 )
				{
					alert('Field Requires a Numeric Value.');
					return -1;
				}
			}		
			if( fid == "REQUEST_HPHONE" || fid == "REQUEST_WPHONE")
			{								
				if( checkTo(fvalue,"num",10) == -1 )
				{
					alert('Field Requires a Numeric Value, H/W Phone.');
					return -1;	
				}
			}			
		}
	}
	if( fname == "finance_form" )
	{
		fwmy=0;
		//alert(document.all(fname).length);
		// Changing ALL document.forms to document.all -- 
		// to work w FIREFOX - 05/03/07
		fcollect=document.getElementsByTagName('input');
		
		for( i=0; i<fcollect.length-1; i++ )
		{
			fid=fcollect[i].name;
			fvalue=fcollect[i].value;
			flength=fvalue.length;		
			//alert("fid=" + fid + " fvalue=" + fvalue + " flength= " + flength);
	    
	    	if( fid == "FINANCE_FNAME" || fid == "FINANCE_LNAME")
			{								
				if( checkTo(fvalue,"str") == -1 )
				{
					alert('Field Requires a Character Value, First/Last Name.');
					return -1;	
				}
			}		
			if( fid == "FINANCE_EMAIL")
			{
				if( checkTo(fvalue,"email") == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}
			if( fid == "FINANCE_ADDRESS" || fid == "FINANCE_CITY" || fid == "FINANCE_STATE")
			{								
				if( checkTo(fvalue,"spacedstr",1) == -1 )
				{
					alert('Field Requires a Value, Address/City/State.');
					return -1;	
				}
			}
			if( fid == "FINANCE_ZIPCODE")
			{								
				if( checkTo(fvalue,"num",5) == -1 )
				{
					alert('Field Requires a Numeric Value, ZipCode.');
					return -1;	
				}
			}		
			if( fid == "FINANCE_HPHONE" || fid == "FINANCE_WPHONE")
			{								
				if( checkTo(fvalue,"num",10) == -1 )
				{
					alert('Field Requires a Numeric Value, H/W Phone.');
					return -1;	
				}
			}
			if( fid == "FINANCE_DOB")
			{								
				if( checkTo(fvalue,"date",10) == -1 )
				{
					alert('Field Requires a Valid, (01/01/2001) DOB.');
					return -1;	
				}
			}
			if( fid == "FINANCE_SS")
			{								
				if( checkTo(fvalue,"num",9) == -1 )
				{
					alert('Field Requires a Valid, SS#.');
					return -1;	
				}
			}
			if( fid == "FINANCE_DL")
			{								
				if( checkTo(fvalue,"num",8) == -1 )
				{
					alert('Field Requires a Valid, DL#.');
					return -1;	
				}
			}			
			if( fid == "FINANCE_INCOME")
			{								
				if( checkTo(fvalue,"num",3) == -1 )
				{
					alert('Field Requires a Numeric Value, Gross Income.');
					return -1;	
				}
			}
			if( fid == "FINANCE_OTHERINCOME")
			{								
				if( flength > 0 && checkTo(fvalue,"num",3) == -1 )
				{
					alert('Field Requires a Numeric Value, Other Income.');
					return -1;	
				}
			}
			if( fid == "FINANCE_EMPLOYERNAME")
			{								
				if( checkTo(fvalue,"spacedstr",3) == -1 )
				{
					alert('Field Requires a Value, Employer Name.');
					return -1;	
				}
			}
			if( fid == "FINANCE_TIMEONJOBYEARS")
			{								
				if( checkTo(fvalue,"num",1) == -1 )
				{
					alert('Field Requires a Numeric Value, Time on Job: Years.');
					return -1;	
				}
			}
			if( fid == "FINANCE_TIMEONJOBMONTHS")
			{								
				if( checkTo(fvalue,"num",1) == -1 )
				{
					alert('Field Requires a Numeric Value, Time on Job: Months.');
					return -1;	
				}
			}
			if( fid == "FINANCE_WMY")
			{	
				if( fcollect[i].checked == false )
				{
					fwmy = fwmy + 1;
				}
				if( fwmy > 2 )
				{
					alert('Field Requires a Value, Gross Income: Weekly / Monthly / Yearly.');
					return -1;	
				}
			}
		//---- SPOUCE STARTS HERE..................//
		//--- MORE SPOUCE / CO APPLICATION CHECKS
			
			if( checksp == 1 )
			{				
				if( fid == "FINANCE_SP_FNAME" || fid == "FINANCE_SP_LNAME")
				{								
					if( checkTo(fvalue,"str") == -1 )
					{
						alert('Field Requires a Character Value, CoApplicant/Spouce: First/Last Name.');
						return -1;	
					}
				}		
				if( fid == "FINANCE_SP_EMAIL")
				{
					if( checkTo(fvalue,"email") == -1 )
					{
						alert('Field Requires an Email Address, CoApplicant/Spouce.');
						return -1;
					}
				}
				if( fid == "FINANCE_SP_ADDRESS" || fid == "FINANCE_SP_CITY" || fid == "FINANCE_SP_STATE")
				{								
					if( checkTo(fvalue,"spacedstr",1) == -1 )
					{
						alert('Field Requires a Value, CoApplicant/Spouce: Address/City/State.');
						return -1;	
					}
				}
				if( fid == "FINANCE_SP_ZIPCODE")
				{								
					if( checkTo(fvalue,"num",5) == -1 )
					{
						alert('Field Requires a Numeric Value, CoApplicant/Spouce: ZipCode.');
						return -1;	
					}
				}		
				if( fid == "FINANCE_SP_HPHONE" || fid == "FINANCE_SP_WPHONE")
				{								
					if( checkTo(fvalue,"num",10) == -1 )
					{
						alert('Field Requires a Numeric Value, CoApplicant/Spouce: H/W Phone.');
						return -1;	
					}
				}
				if( fid == "FINANCE_SP_DOB")
				{								
					if( checkTo(fvalue,"date",10) == -1 )
					{
						alert('Field Requires a Valid, CoApplicant/Spouce: (01/01/2001) DOB.');
						return -1;	
					}
				}
				if( fid == "FINANCE_SP_SS")
				{								
					if( checkTo(fvalue,"num",9) == -1 )
					{
						alert('Field Requires a Valid, CoApplicant/Spouce: SS#.');
						return -1;	
					}
				}
				if( fid == "FINANCE_SP_DL")
				{								
					if( checkTo(fvalue,"num",8) == -1 )
					{
						alert('Field Requires a Valid, CoApplicant/Spouce: DL#.');
						return -1;	
					}
				}
				if( fid == "FINANCE_SP_INCOME")
				{								
					if( checkTo(fvalue,"num",3) == -1 )
					{
						alert('Field Requires a Numeric Value, CoApplicant/Spouce: Annual Income.');
						return -1;	
					}
				}						
			}
		}
	}
	if( fname == "popup_email" )
	{
		for( i=0; i<document.all(fname).length-1; i++ )
		{
			fid=document.all(fname).item(i).id;
			fvalue=document.all(fname).item(i).value;
			flength=document.all(fname).item(i).value.length;		
					
			if( fid == "email" )
			{								
				if( checkTo(fvalue,"email") == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}				
		}
	}
	//popup subscribers mailing list
	if( fname == "popup_semail" )
	{
		for( i=0; i<document.all(fname).length-1; i++ )
		{
			fid=document.all(fname).item(i).id;
			fvalue=document.all(fname).item(i).value;
			flength=document.all(fname).item(i).value.length;		
					
			if( fid == "emailtxt" )
			{								
				if( checkTo(fvalue,"email") == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}
			if( fid == "fnametxt" )
			{								
				if( checkTo(fvalue,"txt") == -1 )
				{
					alert('Field Requires a Character Value, First Name.');
					return -1;
				}
			}								
			if( fid == "lnametxt" )
			{								
				if( checkTo(fvalue,"txt") == -1 )
				{
					alert('Field Requires a Character Value, Last Name.');
					return -1;
				}
			}				
		}
	}
	//popup certificate mailing list
	if( fname == "popup_certificate" )
	{
		for( i=0; i<document.all(fname).length-1; i++ )
		{
			fid=document.all(fname).item(i).id;
			fvalue=document.all(fname).item(i).value;
			flength=document.all(fname).item(i).value.length;		
					
			if( fid == "emailtxt" )
			{								
				if( checkTo(fvalue,"email") == -1 )
				{
					alert('Field Requires an Email Address.');
					return -1;
				}
			}
			if( fid == "fnametxt" )
			{								
				if( checkTo(fvalue,"txt") == -1 )
				{
					alert('Field Requires a Character Value, First Name.');
					return -1;
				}
			}								
			if( fid == "lnametxt" )
			{								
				if( checkTo(fvalue,"txt") == -1 )
				{
					alert('Field Requires a Character Value, Last Name.');
					return -1;
				}
			}	
			if( fid == "phonenum")
			{								
				if( checkTo(fvalue,"num",10) == -1 )
				{
					alert('Field Requires a Numeric Value, H/W Phone.');
					return -1;	
				}
			}				
		}
	}
return 1;
}

function highlite(which,what,set)
{		
	oldCLASS = document.all(which).className;	
	if( set == 1 )
	{
		oldimgCLASS = document.all("img" + which).className;	
		oldCLASSb = document.all("b" + which).className;
		oldCLASSc = document.all("c" + which).className;
	}
		
	if( what == 1 ) 
	{
		//set 1 = showroom, also targets thumbnail class
		if( set == 1 )
		{
			document.all("img" + which).className = oldimgCLASS + "_on";
			document.all("b" + which).className = oldCLASSb + "_on";
			document.all("c" + which).className = oldCLASSc + "_on";			
		}
		document.all(which).className = oldCLASS + "_on";
	}
	else
	{
		v = oldCLASS.length;
		oldCLASS = oldCLASS.substr(0, v-3);		
		document.all(which).className = oldCLASS;
		
		if( set == 1 )
		{
			v = oldimgCLASS.length;
			oldimgCLASS = oldimgCLASS.substr(0, v-3);
			v = oldCLASSb.length;
			oldCLASSb = oldCLASSb.substr(0, v-3);
			v = oldCLASSc.length;
			oldCLASSc = oldCLASSc.substr(0, v-3);
			
			document.all("img" + which).className = oldimgCLASS;
			document.all("b" + which).className = oldCLASSb;
			document.all("c" + which).className = oldCLASSc;
		}	
	}
}

function loadvehicle(which)
{
	document.location.href="vehicledetails.asp?ID=" + which;
}

function imageviewer(which)
{
	openWindow2("vehicledetailsIMG.asp?SRC=" + which, '', '', 1, 480, 640);
}

function openWindow2(URL, QS, windowName, center, theHeight, theWidth, scroll) 
{	
	if (theHeight == 0) {
		theHeight = 350
	}
	if (theWidth == 0) {
		theWidth = 300
	}
	if (windowName == 0) 
	{
		windowName = 'SEARCH'
	}
	if (scroll == 0) 
	{
		scroll = 0
	} 
	else
	{
		scroll = 1
	}	
	if (center == 1)
	{
		wheight = window.screen.height;
		wwidth = window.screen.width;
		wheight = (wheight/2)-(theHeight/2);
		wwidth = (wwidth/2)-(theWidth/2);		
	}
	else
	{
		wheight = 0;
		wwidth = 0;
	}
	
	if ( windowName == "new" )
	{
		window.open(URL+QS,"NEW","")
	}
	else
	{
		window.open(URL+QS,"LOGIN","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scroll + ",resizable=0,left="+wwidth+",top="+wheight+",width="+theWidth+",height="+theHeight)
	}
}

function showFINANCEco(which,what)
{
	if( what == true ) 
	{
		checksp = 1;	
		document.all(which).value=1;		
				
		for(i=1; i<9; i++)
		{
			field = "row" + i;
			document.all(field).className = "showsubt";
		}
	}
	else
	{
		checksp = 0;
		document.all(which).value=0;		
		
		for(i=1; i<9; i++)
		{
			field = "row" + i;
			document.all(field).className = "hidesubt";
		}
	}
}
