// JavaScript Document
function showPage(page) {
	document.getElementById("page").value = page;
	document.forms["search"].submit();
}
function order(orderBy) {
	var sort = document.getElementById("sort");
	var order = document.getElementById("order");
	if (sort.value != orderBy) {
		sort.value = orderBy;
		order.value = 'asc';
	} else if (order.value == 'asc') {
		order.value = 'desc';
	} else {
		order.value = 'asc';
	}
	document.forms["search"].submit();
}
function repopulate(selectObj, selectObjName, populate, populateName, showSelect) {
	var obj = document.getElementById(selectObj);
	var repopObj = document.getElementById(populate);
	//alert(repopObj.options);
	for (var i = repopObj.childNodes.length-1; i >= 0; i--) {
		repopObj.removeChild(repopObj.childNodes[i]);
	}
	if (showSelect) {
		var oOption = document.createElement("OPTION");
		oOption.value = "0";
	}
	if (!isNaN(obj.options[obj.selectedIndex].value) && obj.options[obj.selectedIndex].value > 0) {
		if (showSelect) {
			oOption.text = "-- "+ populateName +" --";
			oOption.innerText = "-- "+ populateName +" --";
			repopObj.appendChild(oOption);
		}
		var id = obj.options[obj.selectedIndex].value;
		if (list["list"+id] != "") {
			for (i = 0; i < list["list"+id].length; i++) {
				oOption = document.createElement("OPTION");
				temp = list["list"+id][i].split("|");
				oOption.value = temp[0];
				oOption.text = temp[1];
				oOption.innerText = temp[1];
				repopObj.appendChild(oOption);
			}
		}
	} else if (showSelect) {
		oOption.text = "-- Please Select a "+ selectObjName +" First --";
		oOption.innerText = "-- Please Select a "+ selectObjName +" First --";
		repopObj.appendChild(oOption);
	}
}
function showSearch() {
	if (openCloseDiv("hidesearch")) document.getElementById('advanced').innerHTML = "[Hide Advanced Search]";
	else document.getElementById('advanced').innerHTML = "[Advanced Search]";
	return false;
}
function closeAd() {
	document.getElementById('overad').style.display = "none";
}
function openCloseDiv(obj) {
	var temp = document.getElementById(obj);
	if (temp.style.display != "block") temp.style.display = "block";
	else temp.style.display = "none";
	//return false;
}
function openKeyFeatures() {
	openCloseDiv("features");	
}
function typeMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function deleteModel() {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to delete this model?");
}
function deleteVehicle() {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to delete this vehicle?\n\nNote that this will also delete all the models associated with this vehicle");
}
function deleteNearlyNew() {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to delete this vehicle?");
}
function deleteCategory() {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to delete this vehicle range?\n\nNote that this will also delete all the vehicles, models, and nearly new vehicles associated with this category");
}
function deleteManufacturer() {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to delete this manufacturer?\n\nNote that this will also delete all the ranges, vehicles, models, and nearly new vehicles associated with this manufacturer");
}
var phoneTimer = Array();
var phoneCounter = Array();
function startPhoneAnim(id) {
	document.getElementById(id).className = "grey";
	phoneCounter[id] = 0;
	window.clearTimeout(phoneTimer[id]);
	phoneTimer[id] = window.setTimeout("highlightPhone('"+id+"');", 500);
}
function highlightPhone(id) {
	var obj = document.getElementById(id);
	//alert(document.getElementById(id).style.color +' '+ phoneFlash);
	if (obj.className == "red") {
		phoneCounter[id]++;
		obj.className = "grey";
		if (phoneCounter[id] > 2) {
			window.clearInterval(phoneTimer[id]);
			phoneTimer[id] = window.setTimeout("startPhoneAnim('"+id+"');", 8000);
		} else {
			phoneTimer[id] = window.setTimeout("highlightPhone('"+id+"');", 400);
		}
	} else {
		obj.className = "red";
		phoneTimer[id] = window.setTimeout("highlightPhone('"+id+"');", 400);
	}
}
function resetCategories() {
	if (document.getElementById("catSelect")) {
		document.getElementById("catSelect").selectedIndex = 0;
	}
}
function checkSpec(theform) {
	var items = document.forms[theform].getElementsByTagName("INPUT");
	var checked = false;
	for (var i =0; i < items.length; i++) {
		if (items[i].type == "checkbox" && items[i].checked) {
			checked = true;
			break;
		}
	}
	if (checked) {
		return true;
	} else {
		alert("Please choose which purchase type(s) you wish to request a quote for");
		return false;
	}
}
function changeType() {
	document.getElementById("manNav").selectedIndex = 0;
	document.getElementById("catNav").selectedIndex = 0;
	document.forms["vehiclenav"].submit();
}
function showTab(obj) {
	var items = document.getElementById("tab").getElementsByTagName("A");
	for (var i = 0; i < items.length; i++) {
		items[i].className = "tabOff";
		document.getElementById(items[i].id+"Content").style.display = "none";
	}
	document.getElementById(obj).className = "tabOn";
	document.getElementById(obj+"Content").style.display = "block";
	return false;
}
function popUp(obj) {
	var items = new Array(800, 600, false);
	var href = obj.href ? obj.href : obj;
	for (var i = 0; i < arguments.length-1; i++) items[i] = arguments[i+1];
	if (items[2] == true) {
		if (items[1] >= 600) {
			items[1] = screen.availHeight;
			var newwin2 = window.open(href, "svlWin", "status,resizable,scrollbars,width="+items[0]+",height="+items[1]);
			newwin2.focus();
		} else {
			var newwin = window.open(href, "newWin", "resizable,width="+items[0]+",height="+items[1]);
			newwin.focus();
		}
	} else {
		var newwin = window.open(href, "newWin", "toolbar,status,menubar,scrollbars,resizable,location,width="+items[0]+",height="+items[1]);
	}
	return false;
}
function activateUser(activate, userName) {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm("Are you sure you want to "+activate+" '"+userName+"'?");
}
function sendMsg(text) {
	if (window.event) window.event.cancelBubble = true;
	return window.confirm(text);
}
function closeWindow() {
	opener.location.reload(true);
	window.close();
	return false;
}
function refreshParent(url, shut) {
	opener.location.href = url;
	if (shut) window.close();
	return false;
}
function closeButton() {
	window.close();
	return false;
}
var submitted = false;
function lockButton(obj, msg) {
	if (!submitted) {
		obj = document.getElementById(obj);
		obj.value = msg;
		submitted = true;
		return true;
	}
	return false;
}
function queryUrl(text, url) {
	if (window.event) {
		window.event.cancelBubble = true;
	}
	if (window.confirm(text) == true) { 
		goToURL('parent', url);	
	}
	return document.returnValue;
}
function goToURL() { //v3.0
  var i, args=goToURL.arguments; document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function checkAll(type) {
	var inputs = document.getElementsByTagName('input');
	var checkboxes = [];
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == 'checkbox') {
			if (type == 'invert') {				
				if (inputs[i].checked == false) inputs[i].checked = true;
				else inputs[i].checked = false;
			} else if (type == 'none') {
				inputs[i].checked = false;
			} else if (type == 'all') {
				inputs[i].checked = true;
			} else {
				inputs[i].checked = true;
			}
		}
	}
}

