function ValidateMakeSelection(frmObject)
{
	ss = document.vehicleSelectForm.make;
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].selected) {
			if(ss[i].value.length) // If the value has some sort of length send them to the next step.
			{
				location=document.vehicleSelectForm.make.options[document.vehicleSelectForm.make.selectedIndex].value+".html";
				return true;
			}
		}
	}
	alert('Please select a vehicle.');
	return false;
}
function ValidateModelSelection(frmObject)
{
	ss = document.vehicleSelectForm.model;
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].selected) {
			if(ss[i].value.length) // If the value has some sort of length send them to the next step.
			{
				location=document.vehicleSelectForm.make.value+"--"+document.vehicleSelectForm.model.options[document.vehicleSelectForm.model.selectedIndex].value+".html";
				return true;
			}
		}
	}
	alert('Please select a vehicle.');
	return false;
}
function ValidateYearSelection(frmObject)
{
	ss = document.vehicleSelectForm.year;
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].selected) {
			if(ss[i].value.length) // If the value has some sort of length send them to the next step.
			{
				location=document.vehicleSelectForm.make.value+"--"+document.vehicleSelectForm.model.value+"--"+document.vehicleSelectForm.year.options[document.vehicleSelectForm.year.selectedIndex].value+".html";
				return true;
			}
		}
	}
	alert('Please select a vehicle.');
	return false;
}

// create an instance of the Date object
var now = new Date();

fixDate(now);
now.setTime(now.getTime() + 14 * 24 * 60 * 60 * 1000);

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date)
{
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
	date.setTime(date.getTime() - skew);
}


/*
name - name of the cookie
value - value of the cookie
[expires] - expiration date of the cookie (defaults to end of current session)
[path] - path for which the cookie is valid (defaults to path of calling document)
[domain] - domain for which the cookie is valid (defaults to domain of calling document)
[secure] - Boolean value indicating if the cookie transmission requires a secure transmission
*/
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


function AskUser(userName)
{
	var answer = confirm ("Save Email / Username for Next Login");
	if (answer)
	{
		setCookie("login", userName, now);
		return true;
	}
	else
	{
		setCookie("noLogin", userName, now);
		return true;
	}
}


/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function handleEnter (field, event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	return false;
	else
	return true;
}

var tip = 1;
var totalNumOfTips = 10;  // total number of current tips to loop through

function enableTipAfterWait()  // Wait for AJAX to create the span id before enableing the tooltip
{
	enableTooltips('indexTip');
}

function showTip (direction, userTypeStr) // values (1 or -1)
{
	// Calculate which tip to display and set it to bTipNum
	tip = tip + direction;  	// calculate the number of the new tip to display

	if(userTypeStr == 'JOBBER')
	{
		if(tip == 3 || tip == 4)
			tip = 5;
		if(tip == 9)
			tip = 10;
	}
	
	if(tip > totalNumOfTips)	// if the tip is greater than max set it to 1
		tip = 1;
	if(tip < 1)  				// if the tip is 0 or negative set it to the top of the stack
		tip = totalNumOfTips;

	// Run the ajax to display the tip
	HTML_AJAX.replace('pricklysTips','index.php?page='+tip);
	if(tip == 8) // then we need to enable tool tips
	{
		//tell it to sleep for a second
		setTimeout('enableTipAfterWait()',1000);
	}
}

//if user selects a make, populate the model combo box...
function getModels(makeSelect)
{
	var make = makeSelect.value;

	//set the model combo with correct combo's for the given make
	HTML_AJAX.replace('divModel','index.php?getModels=' + make);

	//clear the years combo by passing blank
	HTML_AJAX.replace('divYear','index.php?getYears=');


	MM_swapImgRestore(); //set all lights back to off

	if(make.length > 0) //if a valid selection turn on the yullow light, else turn on red light
	MM_swapImage('trafficLightYellow','','images/trafficLightYellow-on.jpg',1);
	else
	MM_swapImage('trafficLightRed','','images/trafficLightRed-on.jpg',1);


	return true;
}

//if user selects a model, populate the year combo box...
function getYears(modelSelect)
{
	var make = document.getElementById('make').value;
	var model = document.getElementById('model').value;

	HTML_AJAX.replace('divYear','index.php?getYears=' + model + '&make=' + make);

	MM_swapImgRestore(); //set all lights back to off

	if(model.length > 0) //if a valid selection turn on the green light, else turn on yellow light
	MM_swapImage('trafficLightGreen','','images/trafficLightGreen-on.jpg',1);
	else
	MM_swapImage('trafficLightYellow','','images/trafficLightYellow-on.jpg',1);

	return true;
}

//navigates to searchByVehicle with proper search criteria
function gotoPartsSearchPage()
{
	var make = document.getElementById('make').value;
	var model = document.getElementById('model').value;
	var yearInt = document.getElementById('year').value;

	if(yearInt != '')
	window.location = 'searchByVehicleResults_Master.php?makeStr=' + make + '&modelStr=' + model + '&yearInt=' + yearInt + '&getParts=Next';
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
		else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 scanAlertNoRightClick(e)
{
	var disableRightClickBool = false;
	
	//disable for ie
	if(window.event)
	{
		if(event.button == 2)
			disableRightClickBool = true;
	}
	else //firefox
	{
		if(e.which && e.which == 3)
			disableRightClickBool = true;
	}
	
	//alert then that it is prohibited to take this image
	if(disableRightClickBool)
	{
		document.getElementById('userName').click();
		alert('Copying Prohibited by Law - HACKER SAFE is a Trademark of ScanAlert');
		return false;
	}
	
	return true;
}

function resetLoginForm()
{
	document.getElementById('userName').value = '';
	document.getElementById('password').value = '';
	return false;
}

//used to ask the user if they want to switch to a different order type if they have more than 34 pieces
function triggerNewInterfaceWelcomePopover()
{
	var formHTMLStr = "<p style='font-size:14px;'>Performance Radiator&reg; is excited to introduce you to an enhanced version of our famously popular website, <b>PerformanceRadiator.com</b>.</p><br><p style='font-size:14px;'>Begin a new kind of browsing experience that allows you to shop across an increased number of product categories when searching by vehicle.  Parts are organized by sections that include air conditioning, cooling system, fuel system, and mirrors.</p><br><p style='font-size:14px;'>A few more benefits to the re-designed site include:<br><br>&nbsp;&nbsp;&nbsp;•&nbsp;Simplified menus for easy site navigation.<br>&nbsp;&nbsp;&nbsp;•&nbsp;Enhanced checkout for a quicker and more convenient buying experience.<br>&nbsp;&nbsp;&nbsp;•&nbsp;Drop ship capability for stock and container orders.<br>&nbsp;&nbsp;&nbsp;•&nbsp;A complete line of air conditioning parts <b>AVAILABLE NOW</b> in select markets.</p><br><p style='font-size:14px;'>We truly appreciate the feedback you provide us and work hard to earn your respect and business!</p><br><br><input type='button' value='Close' onclick='removeCustomAlert();showStepDisplay();'>";
	
	document.getElementById('make').style.display = 'none';
	document.getElementById('model').style.display = 'none';
	document.getElementById('year').style.display = 'none';
	createCustomAlert('Welcome to the new Interface', formHTMLStr, 600, 330);
}

//Memorial Day Closure Announcement
function triggerMemorialDayWelcomePopover()
{
	var formHTMLStr = "<p style='font-size:14px;'>Performance Radiator&reg; locations in the United States will be closed Monday May 26th in observance of Memorial Day.  All orders placed on the web after your local cutoff time on Saturday will be shipped Tuesday May 27th. Thank you for choosing Performance Radiator&reg;.</p><br><br><input type='button' value='Close' onclick='removeCustomAlert();showStepDisplay();'>";
	
	document.getElementById('make').style.display = 'none';
	document.getElementById('model').style.display = 'none';
	document.getElementById('year').style.display = 'none';
	createCustomAlert('Welcome to the new Interface', formHTMLStr, 535, 140);
}

//4th of July Closure Announcement
function trigger4thOfJulyWelcomePopover()
{
	var formHTMLStr = "<p style='font-size:14px;'>Performance Radiator&reg; locations in the United States will be closed Friday July 4th in observance of Independence Day.  All orders placed on the web after your local cutoff time on Thursday will be shipped Saturday July 5th. Thank you for choosing Performance Radiator&reg;.</p><br><br><input type='button' value='Close' onclick='removeCustomAlert();showStepDisplay();'>";
	
	document.getElementById('make').style.display = 'none';
	document.getElementById('model').style.display = 'none';
	document.getElementById('year').style.display = 'none';
	createCustomAlert('Welcome to the new Interface', formHTMLStr, 535, 140);
}

function showStepDisplay()
{
	document.getElementById('make').style.display = 'block';
	document.getElementById('model').style.display = 'block';
	document.getElementById('year').style.display = 'block';
}
