var site_url = 'http://www.cooperbmw.co.uk/';

function gotodealership() {
	document.location.href='dealerships/';
}


/* 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],'#3379A4')
				);
				
				// set listener
				GEvent.addListener(markers[subarray[3]], 'mouseout',
					(function(id,colour) {
						return function() {
							display(id,colour);
						};
					})(subarray[3],'#cccccc')
				);
				
				var theloc = dnamearray[i];
				
				// set listener
				GEvent.addListener(markers[subarray[3]], 'click',
					(function(theloc) {
						return function() {
							document.location.href=theloc;
						};
					})('http://www.cooperbmw.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 signup(dealerid) {
	if(document.getElementById('signemail').value == '' | document.getElementById('signname').value == '') {
		alert('Please enter your name and a valid email address.');
	} else {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
	
		thestring = '&id='+dealerid;
	
		try {
			if (document.getElementById('signemail').value != '') {
				thestring = thestring+'&signemail='+document.getElementById('signemail').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('signname').value != '') {
				thestring = thestring+'&signname='+document.getElementById('signname').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('signtel').value != '') {
				thestring = thestring+'&signtel='+document.getElementById('signtel').value;
			}
		} catch (err) {}
		
		try {
			if (document.getElementById('signcomments').value != '') {
				thestring = thestring+'&signcomments='+document.getElementById('signcomments').value;
			}
		} catch (err) {}	
		
		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','queryform.cfm'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('contactus');
			resultbox.innerHTML = liveSearchReq.responseText;
		}		
	}
}


function service() {
	if(document.getElementById('servicefullname').value == '' | document.getElementById('servicetel').value == '' | document.getElementById('serviceemail').value == '' | document.getElementById('servicecarreg').value == '' | document.getElementById('servicedealership').value == 'XXXX') {
		alert('Please enter your name, a valid email address, contact number 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('servicefullname').value != '') {
				thestring = thestring+'&servicefullname='+document.getElementById('servicefullname').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicetel').value != '') {
				thestring = thestring+'&servicetel='+document.getElementById('servicetel').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('serviceemail').value != '') {
				thestring = thestring+'&serviceemail='+document.getElementById('serviceemail').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicepref_date').value != '') {
				thestring = thestring+'&servicepref_date='+document.getElementById('servicepref_date').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicepref_time').value != '') {
				thestring = thestring+'&servicepref_time='+document.getElementById('servicepref_time').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicecarreg').value != '') {
				thestring = thestring+'&servicecarreg='+document.getElementById('servicecarreg').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicemodel_range').value != '') {
				thestring = thestring+'&servicemodel_range='+document.getElementById('servicemodel_range').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicemodel_var').value != '') {
				thestring = thestring+'&servicemodel_var='+document.getElementById('servicemodel_var').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicedealership').value != '') {
				thestring = thestring+'&servicedealership='+document.getElementById('servicedealership').value;
			}
		} catch (err) {}


		try {
			if (document.getElementById('servicequery').value != '') {
				thestring = thestring+'&servicequery='+document.getElementById('servicequery').value;
			}
		} catch (err) {}

		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','service_process.cfm'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('booking');
			resultbox.innerHTML = parseScript(liveSearchReq.responseText);
		}
	}
}


function getvariant(type,thestring) {
	if (type != 'XXXX') {
		if (window.XMLHttpRequest) {
			liveSearchReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
	
		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','variant_div.cfm'+thetime+'&type='+type+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('variantdiv');
			resultbox.innerHTML = liveSearchReq.responseText;
		}
	} else {
		alert('Please select a Valid Model Type')
	}
}


function newcar(model,thewidth) {
	if(document.getElementById('newname').value == '' | document.getElementById('newemail').value == '' | document.getElementById('newdealership').value == '') {
		resultbox = document.getElementById('enquire');
		resultbox.style.borderColor = '#3379A4';
		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();
		if (thewidth == 'wide'){
			liveSearchReq.open('GET','new_enquire_process.cfm'+thetime+thestring,false);
		} else {
			liveSearchReq.open('GET','new_enquire_process_wide.cfm'+thetime+thestring,false);
		}
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox.innerHTML = 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 = '#3379A4';
		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');
		}

		thestring = '&carreg='+document.getElementById('formatereg').value;

		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);
		}
	}
}


/* handles the search */
function dosearch(howmany){
	// if doing a model/var search
	if (document.forms.thesearch.type) {
		var thepage = document.forms.thesearch.type.value;
	} else {
		var thepage = 'XXXX';
	}
	
	if (document.forms.repage) {
		var repage = document.forms.repage.toshow.value;
	} else {
		var repage = 5;
	}
	
	var  res = document.getElementById("results");
	res.innerHTML = '<div style="width:150px; margin: 0 auto; padding-top:150px;" align="center"><img src="1.gif" alt="Loading cars"><br /><br />Loading next '+repage+' cars</div>';
	
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	/* check for special or used age listings OR crit values OR model_type - set thestring as a default blank */
	var thestring =""
	
	try {
		if (document.forms.thesearch.used) {
			var thestring = thestring+"&used="+document.forms.thesearch.used.value
		}
	} catch (err) {}
	
	try {
		if (document.forms.thesearch.special) {
			var thestring = thestring+"&special="+document.forms.thesearch.special.value
		}
	} catch (err) {}
	
	try {
		if (document.forms.thesearch.model_type) {
			var thestring = thestring+"&model_type="+document.forms.thesearch.model_type.value
		}
	} catch (err) {}
	
	try {
		if (document.forms.thesearch.type) {
			var thestring = thestring+"&type="+document.forms.thesearch.type.value
		}
	} catch (err) {}	
	
	try {
		if (document.forms.thesearch.topvar_type) {
			var thestring = thestring+"&topvar_type="+document.forms.thesearch.topvar_type.value
		}
	} catch (err) {}	
	
	try {
		if (document.forms.thesearch.the_dealername.value) {
			var thestring = thestring+"&the_dealername="+document.forms.thesearch.the_dealername.value
		}
	} catch (err) {}	
	
	
	var thecolours = ""
	
	/* 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+",";
	}
	
	// does the search nhave colours? if so append to thestring
	if (thecolours.length) {
		var thestring = thestring+"&colours="+thecolours
	}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReq.open("GET","dosearch.html?reg_date="+document.forms.thesearch.reg_date.value
					   +"&page="+thepage
					   +"&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);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		res.innerHTML = liveSearchReq.responseText;
	}
	
	
	/* populate the variants_row div */
	if (window.XMLHttpRequest) {
		variantsliveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		variantsliveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var thetime= "&thetime="+new Date().getTime();
	try {
		if (document.forms.thesearch.model_type) {
			var thetime = thetime+"&selectedvar="+document.forms.thesearch.model_type.value
		}
	} catch (err) {}
	
	try {
		if (document.forms.thesearch.special) {
			var thetime = thetime+"&special=true"
		}
	} catch (err) {}	
	
	// if doing a model/var search get relevant dropdown for that model
	if (thepage != 'XXXX') {
		variantsliveSearchReq.open("GET","variant_only_drop.cfm?type="+document.forms.thesearch.type.value+thetime,false);
		variantsliveSearchReq.send(null);
	
		if (variantsliveSearchReq.readyState == 4) {
			var  res = document.getElementById("variants_row");
			res.innerHTML = variantsliveSearchReq.responseText;
	
			var  res2 = document.getElementById("variants_desc");
			res2.innerHTML = 'Variant';
		}
	}
	resetshowsperpagenosearch();
}


function resetshowsperpagenosearch(){
	/* check the form exists before you try to use it */
	try {
		if (document.forms.repage.toshow && document.forms.sortby.recordcount) {
			if (window.XMLHttpRequest) {
					liveSearchReqcounter = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
				}

			var thetime= "&thetime="+new Date().getTime();
			liveSearchReqcounter.open("GET","resetshowsperpage.html?shows="+document.forms.repage.toshow.value
							   +"&records="+document.forms.sortby.recordcount.value
							   +thetime
							   ,false);
			liveSearchReqcounter.send(null);
		
			if (liveSearchReqcounter.readyState == 4) {
				var  resultbox = document.getElementById("pageslist");
				resultbox.innerHTML = liveSearchReqcounter.responseText;
			}
		}
	} 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.forms.sortby.sortbyint.value+thetime,false);
	liveSearchReqcounter.send(null);
	dosearch(1);
}


function clearsearch() {
	try {
		if (document.forms.thesearch.model_type.value) {
			document.forms.thesearch.model_type.value = 'XXXX'
			document.forms.thesearch.model_type.selected = 'No Preference'
		}
		
		//clear sessions
		if (window.XMLHttpRequest) {
			liveSearchReqcounter = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var thetime= "?&thetime="+new Date().getTime();
		liveSearchReqcounter.open("GET","cleartop.html"+thetime,false);
		liveSearchReqcounter.send(null);			
	} catch (err) {}
}


function resetshowsperpage(recordcount){
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET","resetshowsperpage.html?shows="+document.forms.repage.toshow.value
					   +"&records="+recordcount
					   +thetime
					   ,false);
	liveSearchReqcounter.send(null);
	/*
	if (liveSearchReqcounter.readyState == 4) {
		var  resultbox = document.getElementById("pageslist");
		resultbox.innerHTML = liveSearchReqcounter.responseText;
	}
	*/
	dosearch(1);
}


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);
	} else {
		document.getElementById('thecode').value='Please enter a postode';
	}
}


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.html"><img src="images/compare.jpg" 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 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) {}
		
		try {
			if (document.getElementById('dealership').value != '') {
				thestring = thestring+'&dealership='+document.getElementById('dealership').value;
			}
		} catch (err) {}		

		thetime= '?thetime='+new Date().getTime();
		liveSearchReq.open('GET','compare_process.cfm'+thetime+thestring,false);
		liveSearchReq.send(null);
	
		if (liveSearchReq.readyState == 4) {
			resultbox = document.getElementById('booking');
			resultbox.innerHTML = liveSearchReq.responseText;
		}		
	}
}


function variant(type) {
	if (window.XMLHttpRequest) {
		liveSearchReqcounter = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReqcounter = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReqcounter.open("GET",type+"_drop.cfm?type="+thetime,false);
	liveSearchReqcounter.send(null);	
	
	res1 = document.getElementById('onename');
	res1.innerHTML = type;

	res2 = document.getElementById('onedrop');
	res2.innerHTML = liveSearchReqcounter.responseText;
	
	if (type == 'Variant') {
		res1 = document.getElementById('variants_desc');
		res1.innerHTML = '';
	
		res2 = document.getElementById('variants_row');
		res2.innerHTML = '';	
	}
}


function ValidateForm(form){
	if(form.firstname.value == "" || form.surname.value == "" || form.tel.value == "" || form.email.value == "" || form.dealership.value == ""){
	alert('Please enter a Firstname,Surname,Telephone Number, Email Address and select your nearest dealership');
	return false;
	}
	return true;
}


function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


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 generate() {
	var res = document.getElementById("pdficon");
	res.innerHTML = '<strong>Generating file please wait.</strong><br />The file will prompt you to save it, this process may take up to around 30 seconds depending on the quality of your internet connection.';
}


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 quickvars() {
	if (window.XMLHttpRequest) {
		quickvar = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		quickvar = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var thetime= "&thetime="+new Date().getTime();
	quickvar.open("GET","quick_variant_only_drop.cfm?type="+document.forms.quickform.type.value+thetime,false);
	quickvar.send(null);
		
	var  res = document.getElementById("quick_variants_row");
	res.innerHTML = quickvar.responseText;

	var  res2 = document.getElementById("quick_variants_desc");
	res2.innerHTML = 'Variant';
}


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','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);
	}		
}