	
	req_type = "";
	var browserType;
	var thisID;
	var thisTab;
	var totalBudget;
	var repayments;
	var thisModel;
	var lastContent;
	var car=new Array();
	var price=new Array();
	var lastRadioValue;
	thisModel = "";

	if (document.layers) {browserType = "nn4"}
	if (document.all) {browserType = "ie"}
	if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   	browserType= "gecko";
	}
	function ValidEmail(stremail) {
		if ((stremail.indexOf("'") != -1) || (stremail.indexOf("!") != -1)) return false;
		if ((stremail.indexOf("@") != -1) && (stremail.indexOf(".") != -1)) return true;
		return false;
	}
	
	function newCarFinanceSetup() {
		document.finance.carprice.value = price[thisID - 1];
		adjust_finance();
	}

	function submitNewCarFinance() {
		formInputs = document.getElementsByTagName("input");
		optionsText = "";
	  	for (var i = 0; i < formInputs.length; i++) {
	  		if ((formInputs.item(i).type == "checkbox" || formInputs.item(i).type == "radio") && formInputs.item(i).checked) {
	  			if (optionsText.length > 0) optionsText = optionsText + ", "
	  			optionsText = optionsText + formInputs.item(i).name + " €" + formInputs.item(i).value;
	  		}
	  	}
		document.finance.optionstext.value = optionsText;
		//if (check_finance()) {
			document.finance.car.value = carName + " " + car[thisID-1];
			document.finance.submit();
		//}
	}

	function hide(layerId) {
	  if (browserType == "gecko") document.poppedLayer = eval('getObj(layerId)');
	  else if (browserType == "ie") document.poppedLayer = eval('getObj(layerId)');
	  else document.poppedLayer = eval('document.layers[layerId]');
	  document.poppedLayer.style.visibility = "hidden";
	}
	
	function show(layerId) {
	  if (browserType == "gecko") document.poppedLayer = eval('getObj(layerId)');
	  else if (browserType == "ie") document.poppedLayer = eval('getObj(layerId)');
	  else document.poppedLayer = eval('document.layers[layerId]');
	  document.poppedLayer.style.visibility = "visible";
	 }

	function updatePrice(obj) {		
		var id = thisID - 1;
		if (obj.type == "radio") {
			if (lastRadioValue != 0) {
				price[id] = parseInt(price[id]) - lastRadioValue;
			}
		}
		if (obj.checked) {
			price[id] = parseInt(price[id]) + parseInt(obj.value);
		} else {
			price[id] = parseInt(price[id]) - parseInt(obj.value);
		}
		getObj("price").innerHTML = addCommas(price[id]);
		if (obj.type == "radio") { lastRadioValue = parseInt(obj.value); }
		document.finance.carprice.value = price[thisID - 1];
		adjust_finance();
	}

	function show_finance_details() {
		strText = repayments + " " + document.finance.term.value + " " + document.finance.deposit.value + " " + totalBudget;
		alert(strText);
	}	

	function select_brand(strBrand) {
		thisLocation = false;
		if ((document.location.href != "http://appleyard.silverink.net/") && (document.location.href != "http://www.appleyard.net/") && (document.location.href != "http://www.appleyard.net/#") && (document.location.href != "http://www.appleyard.net/default.html") && (document.location.href != "https://www.appleyard.net/") && (document.location.href != "http://www.appleyard.net/?promo=peugeot") && (document.location.href != "http://www.appleyard.net/?promo=seat")) {
			thisLocation = true;
		}		
		if (strBrand == "ford") {
			load_newcars(strBrand);
		}			
	}

function openPromo(strBrand) {
		if (strBrand == "peugeot") {
			newWin = window.open("http://www.appleyardmotors.ie/templates/peugeot06_dealer/images/dealerpromos/appleyard07peugeots.html", 'newWindowId','width=750,height=580,top=100,left=250');
		}
		else {
			newWin = window.open("/promos/roadtax.htm", 'newWindowId','width=490,height=320,top=100,left=250');
		}
	}

	function load_newcars(strBrand) {		
		if (strBrand == "ford") {
			getObj("brand").innerHTML = "<img alt='New Ford cars' src='/images/logo-ford.jpg'><br>Select your new car"
			getObj("caricon1").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/NewKa/Overview'><img alt='Ford Ka' onmouseover='rollover(1)' onmouseout='rollout(1)' src='/images/ford-icons/ka.png'>Ka</a>"
			getObj("caricon2").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/NewFiesta/Overview'><img alt='Ford Fiesta' onmouseover='rollover(2)' onmouseout='rollout(2)' src='/images/ford-icons/fiesta.png'>Fiesta</a>"
			getObj("caricon3").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/Fusion'><img alt='Ford Fusion' onmouseover='rollover(3)' onmouseout='rollout(3)' src='/images/ford-icons/fusion.png'>Fusion</a>"
			getObj("caricon4").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/Focus'><img alt='Ford Focus' onmouseover='rollover(4)' onmouseout='rollout(4)' src='/images/ford-icons/focus.png'>Focus</a>"
			getObj("caricon5").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/Mondeo'><img alt='Ford Mondeo' onmouseover='rollover(5)' onmouseout='rollout(5)' src='/images/ford-icons/mondeo.png'>Mondeo</a>"
			getObj("caricon6").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/Kuga'><img alt='Ford Kuga' onmouseover='rollover(6)' onmouseout='rollout(6)' src='/images/ford-icons/kuga.png'>Kuga</a>"
			getObj("caricon7").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/S-MAX'><img alt='Ford S-MAX' onmouseover='rollover(7)' onmouseout='rollout(7)' src='/images/ford-icons/smax.png'>S-MAX</a>"
			getObj("caricon8").innerHTML = "<a target='ford' href='http://www.ford.ie/Cars/Galaxy'><img alt='Ford Galaxy' onmouseover='rollover(8)' onmouseout='rollout(8)' src='/images/ford-icons/galaxy.png'>Galaxy</a>"
			show("caricon4");
			show("caricon5");
			show("caricon6");
			show("caricon7");
			show("caricon8");
		}		
	}

	function rollover(intdiv) {
		getObj("caricon" + intdiv).style.backgroundImage = "url('/images/caricon-bg-hover.jpg')";
		fixHighlight();
	}
	
	function fixHighlight() {
		if (thisModel != "") { getObj(thisModel).parentNode.parentNode.style.backgroundImage = "url('/images/caricon-bg-selected.jpg')"; }
	}
	
	function rollout(intdiv) {
		getObj("caricon" + intdiv).style.backgroundImage = "url('/images/caricon-bg.jpg')";	
		fixHighlight();
	}
	
	function testdriveDate() {		
		//alert(new Date().getDay());
		document.testdrive.day.selectedIndex = new Date().getDate();
		document.testdrive.month.selectedIndex = new Date().getMonth();		
	}
	
	function zoom(strImage) {
		getObj("used-main").style.backgroundImage = "url('http://www.appleyard.net/images/usedcars/366x275/" + strImage + "')";
	}
	
	function populate_type() {
		document.form_usedcar.select_type[0] = new Option("Select type", "0", false);
		for (i = 0; i < bodytype.length; i++) {
			isSelected = false;
			//alert(req_type);
			if (req_type == bodytype[i]) isSelected = true;
			document.form_usedcar.select_type[i + 1] = new Option(bodytype[i], bodytype[i], isSelected, isSelected);
		}
	}
	
	function search_year() {
		strMake = document.form_usedcar.select_make[document.form_usedcar.select_make.selectedIndex].value;
		strModel = document.form_usedcar.select_model[document.form_usedcar.select_model.selectedIndex].value;
		strYear = document.form_usedcar.select_year[document.form_usedcar.select_year.selectedIndex].value;
		if (strModel != '') {
			document.location.href = "/used-cars.html?make=" + strMake + "&model=" + strModel + "&year=" + strYear
		}
	}
	
	function search_model() {
		strMake = document.form_usedcar.select_make[document.form_usedcar.select_make.selectedIndex].value;
		strModel = document.form_usedcar.select_model[document.form_usedcar.select_model.selectedIndex].value;
		//if (strModel == 'all') {
			//document.location.href = "/used-cars.html?make=" + strMake;
		//} else
		document.location.href = "/used-cars.html?make=" + strMake + "&model=" + strModel + "&year=any";
	}
	
	function search_type() {
		if (document.form_usedcar.select_type[document.form_usedcar.select_type.selectedIndex].value != "0") document.location.href = "/used-cars.html?type=" + document.form_usedcar.select_type[document.form_usedcar.select_type.selectedIndex].value;
	}

	function populate_make() {
		document.form_usedcar.select_make[0] = new Option("Make..", "0", false);
		document.form_usedcar.select_model[0] = new Option("Model..", "0", false);
		for (i = 0; i < make.length; i++) {
			document.form_usedcar.select_make[i + 1] = new Option(make[i], make[i], false);
		}
	}
	
	function populate_model() {		
		document.form_usedcar.select_model.options.length = 0;
		//document.form_usedcar.select_model[0] = new Option("Select model..", "0", false);		
		if (document.form_usedcar.select_make.selectedIndex != 0) {
			document.form_usedcar.select_model[0] = new Option("All " + document.form_usedcar.select_make[document.form_usedcar.select_make.selectedIndex].value, "all", false);
			for (i = 0; i < model[document.form_usedcar.select_make.selectedIndex - 1].length; i++) {
				//alert("adding " + model[document.form_usedcar.select_make.selectedIndex - 1][i]);
				document.form_usedcar.select_model[i + 1] = new Option(model[document.form_usedcar.select_make.selectedIndex - 1][i], model[document.form_usedcar.select_make.selectedIndex - 1][i], false);
			}
		}
	}
	function populate_model_home() {		
		document.form_usedcar.select_model.options.length = 0;
		document.form_usedcar.select_model[0] = new Option("Select model", "0", false);		
		if (document.form_usedcar.select_make.selectedIndex != 0) {
			document.form_usedcar.select_model[1] = new Option("All " + document.form_usedcar.select_make[document.form_usedcar.select_make.selectedIndex].value, "all", false);
			for (i = 0; i < model[document.form_usedcar.select_make.selectedIndex - 1].length; i++) {
				//alert("adding " + model[document.form_usedcar.select_make.selectedIndex - 1][i]);
				document.form_usedcar.select_model[i + 2] = new Option(model[document.form_usedcar.select_make.selectedIndex - 1][i], model[document.form_usedcar.select_make.selectedIndex - 1][i], false);
			}
		}
	}
	
	function check_testdrive() {
		if (document.testdrive.customer_name.value == "") { alert("Please enter your name") }
		else {
			if (!ValidEmail(document.testdrive.customer_email.value)) { alert("Please enter a valid email address") }
			else {
				if (document.testdrive.customer_telephone.value == "" || isNaN(document.testdrive.customer_telephone.value)) { alert("Please enter a contact number") }	
				else {
					document.testdrive.customer_vehicle.value = carName + " " + car[thisID];
					document.testdrive.submit();
				}				
			}
		}		
	}
	
		function check_servicebooking() 
		{
			if (document.servicebooking.customer_name.value == "") 
			{ 
				alert("Please enter your name") 
			}
			else if (document.servicebooking.customer_telephone.value == "")
			{
				alert("Please enter your telephone number")
			}
			else if (document.servicebooking.car_reg.value == "")
			{
				alert("Please enter your car registration")
			}
			else
			{
				document.servicebooking.submit();
			}
		}
	
	
	
	
	
	function check_finance() {
		if (document.finance.budget.value == "") { alert("Please enter a monthly budget") }
		else {
			if (isNaN(document.finance.budget.value)) { alert("Please enter a valid monthly budget") }
			else {
				if (document.finance.deposit.value == "") { alert("Please enter a deposit/trade-in amount") }
				else {
					if (isNaN(document.finance.deposit.value)) { alert("Please enter a valid deposit/trade-in") }
					else {
						// ok to calc finance						
						totalBudget = Math.round((document.finance.budget.value/document.finance.term.value) * 1000);
						totalBudget = totalBudget + parseFloat(document.finance.deposit.value);
						//document.location.href = "http://appleyard.webzone.ie/usedcars/index.cfm?fuseaction=search&sortby=PriceDesc&maxrows=100&Price_Max=" + totalBudget + "&BusinessID=193&GroupID=738"
						document.location.href = "/used-cars.html?max=" + totalBudget;
					}
				}				
			}
		}		
	}

	function check_zero() {
		if ((document.finance.deposit.value) == "") document.finance.deposit.value = "0";
		adjust_finance();
	}

	function adjust_finance() {
		totalBudget = parseFloat(document.finance.carprice.value) - parseFloat(document.finance.deposit.value);
		repayments = Math.round((totalBudget * document.finance.term.value) / 1000);
		document.finance.budget.value = repayments;
	}	

	function checkForm1() {
		//alert(document.application1.years_at_address.value);
		if (document.application1.years_at_address.value == "") {
			alert("Please enter a valid number of years at your current address");
			return false;		
		}
		if (isNaN(document.application1.years_at_address.value)) {
			alert("Please enter a valid number of years at your current address");
			return false;
		}
		if ((document.application1.years_at_address.value < 3) && (document.application1.previous_address.value == "")) {
			alert("Please enter your previous address");
			return false;
		}
		if (document.application1.date_of_birth.value == "") {
			alert("Please enter your date of birth");
			return false;
		}
		if ((document.application1.telephone_home.value == "") && (document.application1.telephone_work.value == "")) {
			alert("Please enter at least one landline number");
			return false;
		}
	}
	
	function checkForm2() {
		if (document.application2.employer_name.value == "") {
			alert("Please enter your employer's name");
			return false;
		}
		return true;
	}
	
	function checkForm3() {
		if (document.application3.bank_name.value == "") {
			alert("Please enter your bank name");
			return false;
		}
		if (document.application3.dataprotection.checked == false) {
			alert("You have not agreed to the terms and conditions of this application");
			return false;
		}
		return true;
	}

	function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(getObj("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        appleyard = new GLatLng(53.278263,-6.217961);
        map.setCenter(appleyard, 16);
        map.addOverlay(createMarker(appleyard, "Appleyard Motors Ltd.<br>Sandyford Motorpark<br>Sandyford<br>Dublin 18"));
        //map.addOverlay(new GMarker(new GLatLng(53.278263,-6.217961)));
      }
      //init_makemodel(frmUsedCar);
    }
	
	function createMarker(point, text) {
    	var marker = new GMarker(point);
    	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });
    	return marker;
   }

	function tab(strTab) {
		getObj("tab-standard").style.backgroundImage = "url('/images/tab-shade.jpg')";
		getObj("tab-technical").style.backgroundImage = "url('/images/tab-shade.jpg')";
		getObj("tab-colours").style.backgroundImage = "url('/images/tab-shade.jpg')";
		//getObj("tab-caroptions").style.backgroundImage = "url('/images/tab-shade.jpg')";
		getObj("text-standard").style.color = "";
		getObj("text-technical").style.color = "";
		getObj("text-colours").style.color = "";
		//getObj("text-caroptions").style.color = "";
		getObj("tab-" + strTab).style.backgroundImage = "url('/images/tab-normal.jpg')";
		getObj("text-" + strTab).style.color = "#000000";

		if (lastContent != "") { getObj(lastContent).innerHTML = getObj("displayContent").innerHTML; }

		if (testForObject(strTab + "-" + thisID)) {
			// store current content			
			getObj("displayContent").innerHTML = getObj(strTab + "-" + thisID).innerHTML;
			lastContent = strTab + "-" + thisID;
		} else {
			getObj("displayContent").innerHTML = getObj(strTab).innerHTML;
			lastContent = strTab;
		}
		thisTab = strTab;		
	}
	
	function addCommas(nStr) {
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
	function loadNewCars() {
		lastContent = "";
		strTemp = "<select class='bozo' onchange='selectNewCar(this.value)'>"
		//alert("1");
		for (i = 0; i < car.length; i++) {
			strTemp = strTemp + "<option value='" + i + "'>" + car[i] + "</option>"
		}
		//alert("2");
		strTemp = strTemp + "</select>"
		getObj("newcar-info").innerHTML = "<font color='#000000'>" + carName + "</font>&nbsp;&nbsp;" + strTemp + "&nbsp;&nbsp;Price: <font color='#000000'>€<span id='baseprice'>" + addCommas(price[0]) + "</span></font><br>Total Price (including delivery): <font color='#000000'>€<span id='price'>" + addCommas(price[0]) + "</span></font>";
		//alert("3");
		thisID = "1";	
		thisTab = "standard";
		tab(thisTab);
		//alert("4");
		fixHighlight();
		lastRadioValue = 0;		
	}
	
	function selectNewCar(id) {
		thisID = parseInt(id) + 1;
		getObj("price").innerHTML = addCommas(price[id]);
		getObj("baseprice").innerHTML = addCommas(price[id]);
		lastContent = "";
		tab(thisTab);
		lastRadioValue = 0;
		parent_node = document;
		formInputs = parent_node.getElementsByTagName("input");
	  	for (var i = 0; i < formInputs.length; i++) {
	  		if (formInputs.item(i).type == "checkbox") formInputs.item(i).checked = false;
	  		if (formInputs.item(i).type == "radio") formInputs.item(i).checked = false;
	  	}
	  	document.finance.carprice.value = price[thisID - 1];
	  	adjust_finance();
	}
	
	function testForObject(Id, Tag) {
	  var o = getObj(Id);
	  if (o) {
	    if (Tag) {
	      if (o.tagName.toLowerCase() == Tag.toLowerCase()) {
	        return o;
	      }
	    } else return o;
	  }
	  return null;
	}

	function getObj(objId, formId) {
		var fullId = objId;
		if (formId != null && formId.length > 0) {
			fullId = formId + ':' + objId;
		}
		var elem = null;
		if (document.getElementById) {
			elem = document.getElementById(fullId);
		} else if (document.all) {
			elem = document.all[fullId];
		} else if (document.layers) {
			elem = document.layers[fullId];
		}
		return elem;
	}
	
