var site_url = 'http://www.coopermini.co.uk/';

/* START MAP */
/* enable jscript in returned ajax content */
function parseScript(_source) {
	var source = _source;
	var scripts = new Array();

	/* Strip out tags */
	while(source.indexOf('<script') > -1 || source.indexOf('</script') > -1) {
		var s = source.indexOf('<script');
		var s_e = source.indexOf('>', s);
		var e = source.indexOf('</script', s);
		var e_e = source.indexOf('>', e);

		/* Add to scripts array */
		scripts.push(source.substring(s_e+1, e));
		/* Strip from source */
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	
	/* Loop through every script collected and eval it */
	for(var i=0; i<scripts.length; i++) {
		try {
			eval(scripts[i]);
		}
		catch(ex) {}
	}
	/* Return cleaned source */
	return source;
}


var map;

function initialize() {
	if(document.getElementById("mapdiv")){
		if (GBrowserIsCompatible()) {
			/* set up map and navigation */
			map = new GMap(document.getElementById("mapdiv"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.centerAndZoom(new GLatLng(53.52895,-2.2336), 11);
			
			GEvent.addListener(map, "movestart", function() {
				map.clearOverlays();
			});
			
			GEvent.addListener(map, "moveend", function() {
				checkpostcodes(map);
			});
			// load the icons
			checkpostcodes(map);
		}
	}
}


function checkpostcodes(map){
	/* Get Map Boundaries */
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var nelat = northEast.lat();
	var nelong = northEast.lng();
	var swlat = southWest.lat();
	var swlong = southWest.lng();

	/* query postcodes in view at current zoom level */
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");	
	}
	var thetime= "?thetime="+new Date().getTime();
	liveSearchReq.open("GET","boundaries.html"+thetime+"&nelat="+nelat+"&nelong="+nelong+"&swlat="+swlat+"&swlong="+swlong,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		var res = document.getElementById("theout");
		res.innerHTML = parseScript(liveSearchReq.responseText);

		if(document.getElementById("thestring")) {
			var array = document.getElementById("thestring").value.split(',');
			var dnamearray = document.getElementById("thedealerstring").value.split(',');
			
			// start from i=1 to ignore the first item in the list (XXX,)
			// set array to hold markers
			markers = {};
			//array for each point
			for(var i=1; i<array.length; i++){ 
				//split array into 4 parts data for each point
				var subarray = array[i].split('^');
				var point = new GLatLng(subarray[0],subarray[1]);
				
				// custom icon shennanegins
				var useIcon = new GIcon(G_DEFAULT_ICON);
				useIcon.iconSize = new GSize(20,23);
				useIcon.iconAnchor = new GPoint(10, 23);
				useIcon.shadow = null;	
				useIcon.image = site_url+'images/pegs/peg_'+subarray[2]+'_off.png';
				
				markerOptions = {icon:useIcon};
				
				//set variable marker name
				var marker = new GMarker(point,markerOptions);
				
				//add on map
				map.addOverlay(marker);
				
				//add to array				
				markers[subarray[3]] = marker;

				// set listener
				GEvent.addListener(markers[subarray[3]], 'mouseover',
					(function(id,colour) {
						return function() {
							display(id,colour);
						};
					})(subarray[3],'#636363')
				);
				
				// set listener
				GEvent.addListener(markers[subarray[3]], 'mouseout',
					(function(id,colour) {
						return function() {
							display(id,colour);
						};
					})(subarray[3],'#000000')
				);
				
				var theloc = dnamearray[i];
				
				// set listener
				GEvent.addListener(markers[subarray[3]], 'click',
					(function(theloc) {
						return function() {
							document.location.href=theloc;
						};
					})('http://www.coopermini.co.uk/'+theloc+'/')
				);				
			}
		}
	}		
}


function display(id,colour) {
	var thediv = "dealer"+id;
	document.getElementById(thediv).style.backgroundColor=colour;
}


// clear point array
var markers = {};
/* END MAPS */



function newcar(model,thewidth) {
	if(document.getElementById('newname').value == '' | document.getElementById('newemail').value == '' | document.getElementById('newdealership').value == '') {
		resultbox = document.getElementById('enquire');
		resultbox.style.borderColor = '#EB1B28';
		alert('Please enter your name, a valid email address and select a dealership.');		
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
	
		thestring = '&model='+model;
	
		try {
			if (document.getElementById('newname').value != '') {
				thestring = thestring+'&newname='+document.getElementById('newname').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('newtel').value != '') {
				thestring = thestring+'&newtel='+document.getElementById('newtel').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('newemail').value != '') {
				thestring = thestring+'&newemail='+document.getElementById('newemail').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('newdealership').value != '') {
				thestring = thestring+'&newdealership='+document.getElementById('newdealership').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('newcomments').value != '') {
				thestring = thestring+'&newcomments='+document.getElementById('newcomments').value;
			}
		} catch (err) {}		

		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','new_enquire_process.html'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('enquire');
			resultbox.innerHTML = parseScript(liveSearchReq.responseText);
		}		
	}
}


function stocksearch(id){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "?thetime="+new Date().getTime();
	liveSearchReq.open("GET","set_dealer_stock.html"+thetime+"&dealerid="+id,false);
	liveSearchReq.send(null);
	
	if (liveSearchReq.readyState == 4) {
		document.location.href='used/'
	}
}


/* handles the search */
function dosearch(howmany){
	var srch = document.getElementById("carlists");
	srch.innerHTML = '<div style="width:180px; margin: 0 auto; padding-top:180px;" align="center"><img src="1.gif" alt="Loading cars"><br /><br />Loading matching cars</div>';

	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	/* check for special or used page listings - set thestring as a default blank */
	var thestring = "";
	
	try {
		if (document.forms.thesearch.special) {
			var thestring = "&special="+document.forms.thesearch.special.value
		}
	} catch (err) {}
	
	try {
		if (document.forms.thesearch.the_dealername) {
			var thestring = "&the_dealername="+document.forms.thesearch.the_dealername.value
		}
	} catch (err) {}	
	
	var thecolours = "";
	
	try {
		if (document.forms.thesearch.chosencolours) {
			/* build a string of colour selections */
			for (i=0; i<document.forms.thesearch.chosencolours.length; i++){
			if (document.forms.thesearch.chosencolours[i].checked==true)
				var thecolours = thecolours+document.forms.thesearch.chosencolours[i].value+",";
			}
		}
	} catch (err) {}
	
	// does the search have colours? if so append to thestring
	if (thecolours.length) {
		var thestring = thestring+"&colours="+thecolours
	}
	
	var thetime= "&thetime="+new Date().getTime();
	
	// if colour choices are avalable - its a normal search
	if (document.getElementById('xx').value == 'used'){
		liveSearchReq.open("GET","dosearch.html?page="+document.forms.thesearch.type.value
		   +"&type="+document.forms.thesearch.type.value
		   +"&reg_date="+document.forms.thesearch.reg_date.value
		   +"&max_price="+document.forms.thesearch.max_price.value
		   +"&min_price="+document.forms.thesearch.min_price.value
		   +"&transmission="+document.forms.thesearch.transmission.value
		   +"&fuel="+document.forms.thesearch.fuel.value
		   +"&max_miles="+document.forms.thesearch.max_miles.value
		   +"&avail_status="+document.forms.thesearch.avail_status.value
		   +"&rows="+howmany
		   +thestring
		   +thetime
		   ,false);
	} else if (document.getElementById('xx').value == 'pre-reg'){
		liveSearchReq.open("GET","pre_reg_search.html?page="+document.forms.thesearch.type.value
		   +"&type="+document.forms.thesearch.type.value
		   +"&reg_date="+document.forms.thesearch.reg_date.value
		   +"&max_price="+document.forms.thesearch.max_price.value
		   +"&min_price="+document.forms.thesearch.min_price.value
		   +"&transmission="+document.forms.thesearch.transmission.value
		   +"&fuel="+document.forms.thesearch.fuel.value
		   +"&max_miles="+document.forms.thesearch.max_miles.value
		   +"&avail_status="+document.forms.thesearch.avail_status.value
		   +"&rows="+howmany
		   +thestring
		   +thetime
		   ,false);
	} else {
			liveSearchReq.open("GET","dosearch.html?"
			+"page=specialonly"
			+"&rows=1"
			,false);
	}

	liveSearchReq.send(null);
	
	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("carlists");
		res.innerHTML = liveSearchReq.responseText;
	}
	
	if (document.forms.repage){
		resetshowsperpagenosearch();
	}
	addclear();
}



function compare(id) {
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var res = document.getElementById(id);
	res.innerHTML = '<a href="compare/"><img src="images/compare.gif" at="Add to compare list"></a>';
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","comparelist.html?id="+id+thetime,false);
	liveSearchReqcounter.send(null);
}


function remove(id) {
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","comparelist.html?remove="+id+thetime,false);
	liveSearchReqcounter.send(null);

	var  res = document.getElementById("compared");
	res.innerHTML = parseScript(liveSearchReqcounter.responseText);
}


function refreshcomparison(){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "?thetime="+new Date().getTime();
	liveSearchReq.open("GET","compare_bottomrule.html"+thetime,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("carlists");
		res.innerHTML = liveSearchReq.responseText;
	}
}

function clearcomparisonlist(){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReq.open("GET","compared.html?clear=clear"+thetime,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("comparelist");
		res.innerHTML = '';
	}
	refreshcomparison();
}

function removefromlist(id){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReq.open("GET","compare_list.html?REMOVE="+id+thetime,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("comparelist");
		res.innerHTML = liveSearchReq.responseText;
	}
	refreshcomparison();
	
	try {
		if (document.getElementById("comparedlist")) {
			var  res = document.getElementById("comparedlist");
			res.innerHTML = ''
		}
	} catch (err) {}
}

function changesort(){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetsort.html?sort="+document.getElementById("sortbyint").value+thetime,false);
	liveSearchReqcounter.send(null);
	
	if (liveSearchReqcounter.readyState == 4) {
		dosearch(1);
	}
}

function changesort2(){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetsort.html?sort="+document.getElementById("sortbyint2").value+thetime,false);
	liveSearchReqcounter.send(null);

	if (liveSearchReqcounter.readyState == 4) {
		dosearch(1);
	}
}


function resetshowsperpage(recordcount){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	try {
		if (document.forms.repage) {
			var  showthis = document.getElementById("toshow").value
			//document.forms.repage.toshow.value
		} else {
			var  showthis = '10'
		}
	} catch (err) {}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetshowsperpage.html?shows="+showthis
					   +"&records="+recordcount
					   +thetime
					   ,false);
	liveSearchReqcounter.send(null);
	
	if (liveSearchReqcounter.readyState == 4) {
		dosearch(1);
	}
}


function resetshowsperpage2(recordcount){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	try {
		if (document.forms.repage) {
			var  showthis = document.getElementById("toshow2").value
		} else {
			var  showthis = '10'
		}
	} catch (err) {}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetshowsperpage.html?shows="+showthis
					   +"&records="+recordcount
					   +thetime
					   ,false);
	liveSearchReqcounter.send(null);
	
	if (liveSearchReqcounter.readyState == 4) {
		dosearch(1);
	}
}



function resetshowsperpagenosearch(){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	try {
		if (document.forms.repage.toshow) {
			var  showthis = document.forms.repage.toshow.value
		} else {
			var  showthis = '10'
		}
	} catch (err) {}	
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetshowsperpage.html?shows="+showthis
					   +"&records="+document.getElementById('recordcount').value
					   +thetime
					   ,false);
	liveSearchReqcounter.send(null);

	if (liveSearchReqcounter.readyState == 4) {
		var  resultbox = document.getElementById("pageslist");
		resultbox.innerHTML = liveSearchReqcounter.responseText;
	}
}



function enquire() {
	if(document.getElementById('enquiryfullname').value == '' | document.getElementById('enquirytel').value == '' | document.getElementById('enquiryemail').value == '') {
		alert('Please enter your name, a valid email address and contact number.');
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
	
		thestring = '';
	
		try {
			if (document.getElementById('enquiryfullname').value != '') {
				thestring = thestring+'&enquiryfullname='+document.getElementById('enquiryfullname').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('enquirytel').value != '') {
				thestring = thestring+'&enquirytel='+document.getElementById('enquirytel').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('enquiryemail').value != '') {
				thestring = thestring+'&enquiryemail='+document.getElementById('enquiryemail').value;
			}
		} catch (err) {}

		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','compare_process.html'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('booking');
			resultbox.innerHTML = liveSearchReq.responseText;
		}		
	}
}

function smallvid(vidurl) {
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
		
	thetime= '?thetime='+new Date().getTime();
	liveSearchReq.open('GET','getvids.html'+thetime+"&thevid="+vidurl+"&autoplay=true",false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		resultbox = document.getElementById('thevid');
		resultbox.style.borderColor = '#3379A4';
		resultbox.innerHTML = parseScript(liveSearchReq.responseText);
	}		
}

function gotodealership() {
	dealerships();
}

function dealerships() {
	document.location.href=site_url+'dealerships/';
}

function gotoused() {
	document.location.href=site_url+'used/';
}

function eventbanner(theURL,winName,features){
	window.open(theURL,winName,features);
}


function vid(vidurl) {
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
		
	thetime= '?thetime='+new Date().getTime();
	liveSearchReq.open('GET','getbigvids.html'+thetime+"&thevid="+vidurl+"&autoplay=true",false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		resultbox = document.getElementById('thevid');
		resultbox.style.borderColor = '#3379A4';
		resultbox.innerHTML = parseScript(liveSearchReq.responseText);
	}		
}

function contactus() {
	if(document.getElementById('firstname').value == '' | document.getElementById('email').value == '' | document.getElementById('dealership').value == '' | document.getElementById('query').value == '') {
		alert('Please enter your first name, a valid email address and choose a dealership.');
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
	
		thestring = '';
	
		try {
			if (document.getElementById('title').value != '') {
				thestring = thestring+'&title='+document.getElementById('title').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('firstname').value != '') {
				thestring = thestring+'&firstname='+document.getElementById('firstname').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('surname').value != '') {
				thestring = thestring+'&surname='+document.getElementById('surname').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('tel').value != '') {
				thestring = thestring+'&tel='+document.getElementById('tel').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('email').value != '') {
				thestring = thestring+'&email='+document.getElementById('email').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('dealership').value != '') {
				thestring = thestring+'&dealership='+document.getElementById('dealership').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('query').value != '') {
				thestring = thestring+'&query='+document.getElementById('query').value;
			}
		} catch (err) {}			

		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','contact_overrule.html'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('booking');
			resultbox.innerHTML = parseScript(liveSearchReq.responseText);
		}		
	}
}


function mailto() {
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
		
	thetime= '?thetime='+new Date().getTime();
	liveSearchReq.open('GET','formate.cfm'+thetime,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		resultbox = document.getElementById('enquire');
		resultbox.style.borderColor = '#FF9900';
		resultbox.innerHTML = liveSearchReq.responseText;
	}		
}


function formate() {
	if(document.getElementById('email1').value == '' && document.getElementById('email2').value == '') {
		alert('Please complete at least one email address.');
	} else {
		if (window.XMLHttpRequest) {
			call12 = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			call12 = new ActiveXObject('Microsoft.XMLHTTP');
		}
		
		var thestring = '';

		try {
			if (document.getElementById('xx')) {
				thestring = thestring+'&carreg='+document.getElementById('xx').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('email1').value != '') {
				thestring = thestring+'&email1='+document.getElementById('email1').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('email2').value != '') {
				thestring = thestring+'&email2='+document.getElementById('email2').value;
			}
		} catch (err) {}

		thetime= '?thetime='+new Date().getTime();
		call12.open('GET','mailfull.cfm'+thetime+thestring,false);
		call12.send(null);

		if (call12.readyState == 4) {
			resultbox = document.getElementById('enquire');
			resultbox.innerHTML = parseScript(call12.responseText);
		}
	}
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


function getdist() {
	if (document.getElementById('thecode').value != '') {
		if (window.XMLHttpRequest) {
			liveSearchReqcounter = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var thetime= "&thetime="+new Date().getTime();
		liveSearchReqcounter.open("GET","resetsort.html?sort=distance&postcode="+document.getElementById('thecode').value+thetime,false);
		liveSearchReqcounter.send(null);
	
		dosearch(1);
	}
}



function clearall() {
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
		
	thetime= '?thetime='+new Date().getTime();
	liveSearchReq.open('GET','clear_query.html',false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		document.location.href='used/'
	}
}


function addclear() {
	if (document.getElementById('clearoff')){
		resultbox = document.getElementById('clearoff');
		resultbox.innerHTML = '<img src="images/Clearcriteriabutton.gif" onclick="clearall()" style="cursor:pointer;">';
	}
}


function updateprefs() {
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","store_colprefs.html?colby="+document.forms.colprefs.colby.value+"&orderby="+document.forms.colprefs.orderby.value+"&theid="+document.forms.colprefs.theid.value+thetime,false);
	liveSearchReqcounter.send(null);
	
	if (liveSearchReqcounter.readyState == 4) {
		document.forms.colprefs.submit();
	}
}

function changelinkref(theimage,id) {
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var thetime= "&thetime="+new Date().getTime();
	liveSearchReq.open("GET","setlink.cfm?theimage="+theimage+"&id="+id+thetime,false);
	liveSearchReq.send(null);
	
	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("thediv");
		res.innerHTML =  liveSearchReq.responseText;
	}
}


function getdealerships(){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
		
	thetime= '&thetime='+new Date().getTime();
	liveSearchReq.open("GET","closest_dealers.html?postcode="+document.getElementById('formpostcode').value+thetime,false);
	liveSearchReq.send(null);
	
	if (liveSearchReq.readyState == 4) {
		resultbox = document.getElementById('theresults');
		resultbox.innerHTML = parseScript(liveSearchReq.responseText);
	}
}


function getdata(){
	resultbox = document.getElementById('carinfo');
	if (document.getElementById('carreg').value != '') {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
			
		thetime= '&thetime='+new Date().getTime();
		liveSearchReq.open("GET","hpi.html?thereg="+document.getElementById('carreg').value+thetime,false);
		liveSearchReq.send(null);
		
		if (liveSearchReq.readyState == 4) {
			resultbox.innerHTML = parseScript(liveSearchReq.responseText);
		}
	} else {
		resultbox.innerHTML = '';
	}
}


function specialcontact() {
	var e = document.getElementById("dealership");
	var theval = e.options[e.selectedIndex].value;
	
	if(document.getElementById('firstname').value == '' | document.getElementById('email').value == '' | theval == '') {
		resultbox = document.getElementById('contact');
		resultbox.style.borderColor = '#FFCC33';
		alert('Please enter your name, a valid email address and select a dealership.');
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
		
		thestring = '';		
	
		try {
			if (document.getElementById('title').value != '') {
				thestring = thestring+'&title='+document.getElementById('title').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('firstname').value != '') {
				thestring = thestring+'&firstname='+document.getElementById('firstname').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('surname').value != '') {
				thestring = thestring+'&surname='+document.getElementById('surname').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('tel').value != '') {
				thestring = thestring+'&tel='+document.getElementById('tel').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('email').value != '') {
				thestring = thestring+'&email='+document.getElementById('email').value;
			}
		} catch (err) {}
		
		try {
			if (theval != '') {
				thestring = thestring+'&dealership='+theval;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('query').value != '') {
				thestring = thestring+'&query='+document.getElementById('query').value;
			}
		} catch (err) {}
		
		thetime= '?thetime='+new Date().getTime();
		
		liveSearchReq.open('GET','special_contact_process.html'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('contact');
			resultbox.innerHTML = liveSearchReq.responseText;
		}		
	}
}


function preregcontact() {
	var e = document.getElementById("dealership");
	var theval = e.options[e.selectedIndex].value;
	
	if(document.getElementById('firstname').value == '' | document.getElementById('email').value == '' | theval == '') {
		resultbox = document.getElementById('contact');
		resultbox.style.borderColor = '#FFCC33';
		alert('Please enter your name, a valid email address and select a dealership.');
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
		
		thestring = '';		
	
		try {
			if (document.getElementById('title').value != '') {
				thestring = thestring+'&title='+document.getElementById('title').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('firstname').value != '') {
				thestring = thestring+'&firstname='+document.getElementById('firstname').value;
			}
		} catch (err) {}

		try {
			if (document.getElementById('surname').value != '') {
				thestring = thestring+'&surname='+document.getElementById('surname').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('tel').value != '') {
				thestring = thestring+'&tel='+document.getElementById('tel').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('email').value != '') {
				thestring = thestring+'&email='+document.getElementById('email').value;
			}
		} catch (err) {}
		
		try {
			if (theval != '') {
				thestring = thestring+'&dealership='+theval;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('query').value != '') {
				thestring = thestring+'&query='+document.getElementById('query').value;
			}
		} catch (err) {}
		
		thetime= '?thetime='+new Date().getTime();
		
		liveSearchReq.open('GET','prereg_contact_process.html'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('contact');
			resultbox.innerHTML = liveSearchReq.responseText;
		}		
	}
}

function youvid(thevid){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
	}

	thetime= '?thetime='+new Date().getTime();
	liveSearchReq.open('GET','youvid.cfm'+thetime+'&vid='+thevid,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		resultbox = document.getElementById('theatre');
		resultbox.innerHTML = liveSearchReq.responseText;
	}
}
