function openWin(url,w,h,s){
	var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;

	if(window.thiswin != undefined){
		thiswin.close();
	}
	thiswin = window.open(url,"popupwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+s+',resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}

function viewImg(url,w,h){
	var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;

	if(window.thiswin != undefined){
		thiswin.close();
	}
	thiswin = window.open(url,"imagewin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}

function checkDelete(url,desc) {
	temp = window.confirm("Are you sure you want to delete "+desc+"?");
	if (temp == true){
		window.location=url;
	}
}

function dispNav(area,display){
	if(display == 1){
		document.getElementById("nav_link_area"+area).style.display = "";
	}else{
		document.getElementById("nav_link_area"+area).style.display = "none";
	}
}

function showHide(id,display){
    if(display == 1){
		document.getElementById(id).style.visibility = "visible";
	}else{
		document.getElementById(id).style.visibility = "hidden";
	}
}

function showHideDisplay(id,display){
    if(display == 1){
		document.getElementById(id).style.display = "";
	}else{
		document.getElementById(id).style.display = "none";
	}
}

function showHideScroll(id){
    if(document.getElementById(id+'_scroll').value == 0){
		document.getElementById(id+'_scroll').value = 1;
		if(document.getElementById(id).style.display == "none"){
			$(id).blindDown({ duration: 1 });
		}else{
			$(id).blindUp({ duration: 1 });
		}
		setTimeout('document.getElementById(\''+id+'_scroll\').value = 0',1000);
	}
}

function changeText(id,string1,string2){
	if(document.getElementById(id).style.display == "none"){
		document.getElementById(id+'_text').innerHTML = string1;
	}else{
		document.getElementById(id+'_text').innerHTML = string2;
	}
}

function get_range_array(index){
	var tab = document.forms.quicksearch.tab_sel.value;
    if(tab == 2 || tab == 5){
		//New car models:
		var models = models_nc;
	}else if(tab == 3){
		//New van models:
		var models = models_nv;
	}else if(tab == 4){
		//Used van models:
		var models = models_uv;
	}else{
		//Used car models:
		var models = models_uc;
	}
	get_range(models[index]);
}

function changeSearchTab(tab){
	var ntabs = 5;
	if(tab <= ntabs && document.getElementById("search_area"+tab).style.display == "none"){
		//Unselect all search tabs:
		for(var i=1;i<=ntabs;i++){
			document.getElementById("search_tab"+i).style.backgroundImage = "url(/images/search_tab"+i+".gif)";
			document.getElementById("search_tab"+i).className = "search_box_tab search_box_tab_unsel";
			document.getElementById("search_area"+i).style.display = "none";
		}

		//Set clicked tab to be selected:
		document.getElementById("search_tab"+tab).style.backgroundImage = "url(/images/search_tab"+tab+"_sel.gif)";
		document.getElementById("search_tab"+tab).className = "search_box_tab search_box_tab_sel";

		//Get make and models:
		if(tab == 2 || tab == 5){
			//New car values:
			var array_type = "nc";
			var make_value = make_value_nc;
			var make_display = make_display_nc;
			var models = models_nc;
		}else if(tab == 3){
			//New van values:
			var array_type = "nv";
            var make_value = make_value_nv;
			var make_display = make_display_nv;
			var models = models_nv;
		}else if(tab == 4){
			//Used van values:
			var array_type = "uv";
            var make_value = make_value_uv;
			var make_display = make_display_uv;
			var models = models_uv;
		}else{
			//Used car values:
			var array_type = "uc";
            var make_value = make_value_uc;
			var make_display = make_display_uc;
			var models = models_uc;
		}
		doLists('','',make_value,make_display,models,1);

		//Get bodystyles, fuel types, and gearboxes:
		searchGetBodystyle(array_type,'');
		searchGetFueltype(array_type,'');
		searchGetGearbox(array_type,'');
		document.forms.quicksearch.description.value = "Keywords";
		document.forms.quicksearch.max_price.selectedIndex = 0;
		document.forms.quicksearch.mileage.selectedIndex = 0;
		document.forms.quicksearch.age.selectedIndex = 0;
		document.forms.quicksearch.cotwo.selectedIndex = 0;
		document.forms.quicksearch.mpg.selectedIndex = 0;

		//Show or hide form areas:
		if(tab == 1 || tab == 4){
			//New vehicle actions:
			document.getElementById("search_area_used").style.display = "";
			var this_action = "/used_vehicles/results.php";
		}else{
			//Used vehicle actions:
			document.getElementById("search_area_used").style.display = "none";
			var this_action = "/new_vehicles/results.php";
		}
        if(tab == 1 || tab == 2 || tab == 5){
			//Car vehicle actions:
			document.getElementById("search_area_cars").style.display = "";
		}else{
			//Van vehicle actions:
			document.getElementById("search_area_cars").style.display = "none";
		}

		//Change form action:
        if(tab == 5){
			var this_vehtype = "motab";
		}else if(tab == 3 || tab == 4){
			var this_vehtype = "vans";
		}else{
			var this_vehtype = "";
		}
		document.forms.quicksearch.vehtype.value = this_vehtype;
		document.forms.quicksearch.action = this_action;

		//Change form title:
		document.getElementById("search_area"+tab).style.display = "";
		document.forms.quicksearch.tab_sel.value = tab;
	}
}

function changeBoxBotTab(tab,extra){
	var ntabs = 4;
	if(tab <= ntabs && document.getElementById("special_area_"+extra+tab).style.display == "none"){
        //Unselect all tabs:
		for(var i=1;i<=ntabs;i++){
			if(i == ntabs){ var tabtype = 2; }else{ var tabtype = 1; }
			document.getElementById("special_tab_"+extra+i).style.backgroundImage = "url(/images/special_tab_bot"+tabtype+".gif)";
			document.getElementById("special_tab_"+extra+i).className = "box_bot_tab box_bot_tab_type"+tabtype+" box_bot_tab_unsel";
			document.getElementById("special_area_"+extra+i).style.display = "none";
		}
		//Set clicked tab to be selected:
		if(tab == ntabs){ var tabtype = 2; }else{ var tabtype = 1; }
        document.getElementById("special_tab_"+extra+tab).style.backgroundImage = "url(/images/special_tab_bot"+tabtype+"_sel.gif)";
		document.getElementById("special_tab_"+extra+tab).className = "box_bot_tab box_bot_tab_type"+tabtype+" box_bot_tab_sel";
		document.getElementById("special_area_"+extra+tab).style.display = "";
	}
}

function floatBoxContent(area){
	if(document.getElementById('floatprocess').value == 0){
		document.getElementById('floatprocess').value = 1;
		if(document.getElementById('floatarea'+area).style.display == "none"){
			var nareas = document.getElementById('floatnareas').value;
			for(var i=1;i<=nareas;i++){
				if(document.getElementById('floatarea'+i).style.display == ""){
					$('floatarea'+i).blindUp({ duration: 1 });
					document.getElementById('floattext'+i).innerHTML = "More Details";
				}
			}
			$('floatarea'+area).blindDown({ duration: 1 });
			document.getElementById('floattext'+area).innerHTML = "Hide Details";
		}else{
            $('floatarea'+area).blindUp({ duration: 1 });
			document.getElementById('floattext'+area).innerHTML = "More Details";
		}
		setTimeout("document.getElementById('floatprocess').value = 0",1000);
	}
}

function floatBoxOffer(){
    if(document.getElementById('sideofferfloatprocess').value == 0){
		document.getElementById('sideofferfloatprocess').value = 1;
		if(document.getElementById('sideofferfloatarea').style.display == "none"){
			$('sideofferfloatarea').blindDown({ duration: 1 });
			document.getElementById('sideofferfloattext').innerHTML = "Hide All Offers";
		}else{
            $('sideofferfloatarea').blindUp({ duration: 1 });
			document.getElementById('sideofferfloattext').innerHTML = "Show All Offers";
		}
		setTimeout("document.getElementById('sideofferfloatprocess').value = 0",1000);
	}
}

function showBoxOffer(){
	if(document.getElementById('sideofferfloatres').style.display == "none"){
		document.getElementById('sideofferfloatres').style.display = ""
	}else{
		document.getElementById('sideofferfloatres').style.display = "none"
	}
}

function sideOfferDisplay(){
	if(document.getElementById("sideoffershow")){
		var thisheight = document.getElementById("sideoffershow").offsetHeight;
		document.getElementById("sideoffercont").style.height = (thisheight + 8) + "px";
	}
}

function addInterest(type,id,details){
	if(document.getElementById("addbutval_"+type+"_"+id).value == 0){
		var amount = document.getElementById("nintdisp").innerHTML;
		document.getElementById("nintdisp").innerHTML = parseFloat(amount)+1;
		document.getElementById("addbutval_"+type+"_"+id).value = 1;
		document.getElementById("intbutton").style.display = "";
		if(details == 1){
			document.getElementById("addbut_"+type+"_"+id).className = "dt_interest_button_added";
		}else{
			document.getElementById("addbut_"+type+"_"+id).src = "/images/but-res-addedlist.gif";
			document.getElementById("addbut_"+type+"_"+id).className = "results-full-details-addlist";
		}
		frames["interestlistframe"].location.href = "/interest_add.php?type="+type+"&id="+id;
	}
}

function removeInterest(type,id){
	temp = window.confirm("Are you sure you want to remove this vehicle from your Interest List?");
	if (temp == true){
		document.getElementById("introw_"+type+"_"+id).style.display = "none";
        var amount = document.getElementById("nintdisp").innerHTML;
		document.getElementById("nintdisp").innerHTML = parseFloat(amount)-1;
		if(document.getElementById("nintdisp").innerHTML == 0){
			document.getElementById("inticons").style.display = "none";
		}
		frames["interestlistframe"].location.href = "/interest_add.php?type="+type+"&id="+id+"&remove=1";
		window.opener.location.reload(true);
	}
}

function clearInterest(){
    temp = window.confirm("Are you sure you want to clear your whole Interest List?");
	if (temp == true){
		window.location = "/interest_add.php?clear=1";
	}
}

function openInterest(url){
	window.opener.location.href=url;
	window.opener.focus();
}

function changeThumb(img){
	for(var i=1;i<=4;i++){
		document.getElementById("new_image_"+i).style.display="none";
	}
	if(img != 0){
		document.getElementById("new_image_"+img).style.display="";
	}
}

function viewImage(id,img){
	var w=850;
	var h=700;
    var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;

	if(window.thiswin != undefined){
		thiswin.close();
	}
	thiswin = window.open("/enlarge_images.php?id="+id+"&num="+img,"popupwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}

function viewfuelcalc(vehicle,mpg,fuel){
    var w=590;
	var h=630;
    var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;
	if(window.fuelwin != undefined){
		fuelwin.close();
	}
	fuelwin = window.open("/new_vehicles/fuelcalc/index.php?vehicle="+vehicle+"&mpg="+mpg+"&fuel="+fuel,"popupwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}

function sendtofriend(vehicle,enq_type){
    var w=430;
	var h=255;
    var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;
	if(window.fuelwin != undefined){
		fuelwin.close();
	}
	fuelwin = window.open("/enquiry/sendtofriend.php?reg="+vehicle+"&enq_type="+enq_type+"","popupwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}

function getDirections(id){
	if(document.getElementById("yourpostcode"+id).value==""){
		window.alert("Please enter your postcode!");
		document.getElementById("yourpostcode"+id).focus();
	}else{
		window.open("http://www.google.co.uk/maps?f=d&source=s_d&saddr="+document.getElementById("yourpostcode"+id).value+"&daddr="+document.getElementById("destpostcode"+id).value+"&hl=en&geocode=&mra=ls&sll=53.800651,-4.042969&sspn=18.388688,38.100586&ie=UTF8&t=h&z=7","openDirWin","width="+screen.width+",height="+screen.height+",menubar=1,resizable=1,location=1,status=1,scrollbars=1,toolbar=1");
	}
}

function homepopDisplay(){
	var thisheight = document.getElementById("homepopwindowcont").offsetHeight;
	document.getElementById("homepop_shadowinner").style.height = (thisheight + 1) + "px";
	document.getElementById("homepopwin").style.visibility = "visible";
}