//Function to browser sniff ** Parameters: none ** Returns: true if Mozilla family, else false for IE, Opera etc. family
function browserIsNav()
{
	var agt=navigator.userAgent.toLowerCase();
  is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  if(is_nav)
    return true; 
  else
    return false;
}  

//Function to rollover image
function imgOn(strImageName)
{
	if(document.images)
  	document.images[strImageName].src = strGlobalImagePath + "button/" + strImageName + "roll.gif";
}
//Function to roll off image
function imgOff(strImageName)
{
	if(document.images)
		document.images[strImageName].src = strGlobalImagePath + "button/" + strImageName + ".gif";
}

//Function to roll over promo images
function promoButtonOn(imgTagName,fileName)
{
	if(document.images) {
		document.images[imgTagName].src = strGlobalPromoImagePath + "roll/" + fileName + "roll.gif";

		}
}
//Function to roll off promo images
function promoButtonOff(imgTagName,fileName)
{
	if(document.images) {
		document.images[imgTagName].src = strGlobalPromoImagePath + fileName + ".gif";
		}
}

//Function to fill dropdown ** Parameters: Dropdown object and array of data
function fillDropDown(objDropDown, arrData)
{
	objDropDown.length = 0;
	for(i = 0; i < arrData.length; i++)
	{
		var strData = arrData[i];
	  var intCommaIndex = strData.indexOf(',');
	  var strModelName = strData.substring(intCommaIndex+1);
	  var strModelCode = strData.substring(0,intCommaIndex);
	  objDropDown[i] = new Option(strModelName, strModelCode);
	}
	objDropDown[0].selected = true;
}

function fillModelsDD(makeDD,modelDD)
{
	makeCode = makeDD.options[makeDD.selectedIndex].value;
	fillDropDown(modelDD, arrModels[makeCode]);
	if(makeCode == "none")
		modelDD.disabled = true;
	else 
		modelDD.disabled = false;
}

//Function to check search car form that both dropdowns have option selected
function submitQuickSearch(form)
{
	if(form.mCode.value != 'none')
	{
		makeCode = form.mCode.options[form.mCode.selectedIndex].value;
	  modelCode = form.rCode.options[form.rCode.selectedIndex].value;
		document.location.href = root + "/drives/" + makeCode + '/' + modelCode + '/';
	}
	else
	{
		alert("please select a make and model")
	}
}

//Function to redirect users once they've selected a car
function doCarSearch(form)
{
	window.location = '{#{root}#}/drives/' + form.mCode.value + '/' + form.rCode.value + '/';
}
	 
//Function to Show Div ** Parameters: name of div
function showDiv(strDivName)
{
	document.getElementById(strDivName).style.visibility = "visible"; 
	document.getElementById(strDivName).style.display = "block";
}
//Function to Hide Div **  Parameters: name of div
function hideDiv(strDivName)
{
	document.getElementById(strDivName).style.visibility = "hidden"; 
	document.getElementById(strDivName).style.display = "none";
}
//Function to go to url based on select choice ** Parameters: select object
function switchURL(objSelect) 
{
	var intSelectedIndex = objSelect.selectedIndex; 
	if (intSelectedIndex == 0 ) 
  {
		alert("please select an option"); 
    return false;
  }
	else 
  {
		var strUrl = objSelect.options[intSelectedIndex].value; 
		window.location = strUrl; 
    return false;
	} 
}
//Function to popup URL ** Parameters: Popup url, width, height of popup
function popUp(strURL, intWidth, intHeight, bScroll) 
{
	if (bScroll == 0) {
		var scroll = 0;
		} else {
		var scroll = 1;
		}
	var intScreenCenterWide = ((screen.width) / 2) - (intWidth);
  var intScreenCenterLong = ((screen.height) / 2) - (intHeight / 2);
	window.open(strURL,'topgear','toolbar=0,scrollbars=' + scroll + ',location=0,statusbar=0,menubar=0,resizable=0,width='+intWidth+',height='+intHeight+',left='+intScreenCenterWide+',top='+intScreenCenterLong+'').focus();
}
//Function to clear cookie
function clearCompareCookie()
{
	document.cookie = "compareCars=; expires=Fri, 02-Jan-1970 00:00:00 GMT; path=/;";
}
//Function to enable/disable input item ** Parameters: true or false for the diabled status, the object to be disabled and optional: hidden input object, new value of this hidden input
function disableInput(bolDisable, objDisableItem)
{
	objDisableItem.disabled = bolDisable;
  if(arguments.length > 2)
  {
		objHiddenInput = arguments[2]; 
    strHiddenValue = arguments[3]; 
    objHiddenInput.value = strHiddenValue;
  }
}

//Validation for a valid e-mail address - ** Used by form validation functions 
function checkEmail(obj_name)
{
	var addresspos = -1;
	var dotpos = -1;
	var checkstr = "";
	email = obj_name.value;
	addresspos = email.indexOf("@",0);
	if ((addresspos == -1) || (addresspos == 0) || (addresspos == email.length-1)) {return false;}
	dotpos = email.indexOf(".",addresspos);	
	if ((dotpos == email.length-1) || (dotpos == -1)) {return false;}
	return true;
}
