var xhr=false;
var xhdets=false;
var ec=new Array();
var current=false;
var dirtyFlag=0;
var initialRender=0;

if (!XMLHttpRequest) {  window.XMLHttpRequest = function() {    return new ActiveXObject('Microsoft.XMLHTTP');  }}

function changeimg(user,pictag,picnumber){
document.getElementById(pictag).src='http://imageserver.autoexposure.co.uk/autoedit/'+user+'/'+pictag+'_'+picnumber+'a.jpg';
}

function initAll(){
if(document.getElementById('searchmake')){
document.getElementById('searchmake').onchange=getModels;
}
}

function expand(t){
	var im='TAGFOR'+t;
//check to see if has been opened
	if(ec[t]=='open'){
 		ec[t]=null;
 		document.getElementById(t).innerHTML='';
 		document.getElementById(im).src='images/enlarge.gif';
	}else{
		ec[t]='open';
		current=t;
		document.getElementById(im).src='images/cancel.gif';
		document.getElementById(t).innerHTML="<img src='images/LOADING.gif'>";
		xhdets= new XMLHttpRequest();
/*
		if(window.XMLHttpRequest){
			xhdets= new XMLHttpRequest(); 
		}else{
			if(window.ActiveXObject){
				try{
					xhdets=new ActiveXobject("Microsoft.XMLHttp");
				}
				catch (e){}
				}
				
		//}//end of else
		}
		*/
	if(xhdets){
		xhdets.onreadystatechange=displaycontents;
		var url="getdetails.php?t=8&id="+t;
		//var url="model.xml";
		xhdets.open('GET',url,true);
		//alert(make.value);
		xhdets.send(null);
	}else{
			alert('cant expand, sorry');
	
	}
//code here for opening tab
}
}

function expandCOM(t){
	var im='TAGFOR'+t;
//check to see if has been opened
	if(ec[t]=='open'){
 		ec[t]=null;
 		document.getElementById(t).innerHTML='';
 		document.getElementById(im).src='images/enlarge.gif';
	}else{
		ec[t]='open';
		current=t;
		document.getElementById(im).src='images/cancel.gif';
		document.getElementById(t).innerHTML="<img src='images/LOADING.gif'>";
		xhdets= new XMLHttpRequest();
/*
		if(window.XMLHttpRequest){
			xhdets= new XMLHttpRequest(); 
		}else{
			if(window.ActiveXObject){
				try{
					xhdets=new ActiveXobject("Microsoft.XMLHttp");
				}
				catch (e){}
				}
				
		//}//end of else
		}
		*/
	if(xhdets){
		xhdets.onreadystatechange=displaycontents;
		var url="getdetailsCOM.php?t=8&id="+t;
		//var url="model.xml";
		xhdets.open('GET',url,true);
		//alert(make.value);
		xhdets.send(null);
	}else{
			alert('cant expand, sorry');
	
	}
//code here for opening tab
}
}

function displaycontents(){
	if(xhdets.readyState==4){
		if(xhdets.status==200){
			var xmlDoc=xhdets.responseText;
			document.getElementById(current).innerHTML=xmlDoc;
			//tester();
			//updateGUI();
			}
	}
}

//var shim=document.getElementById("mainClient").clientHeight;
//document.getElementById("leftshim").height=(shim-900);
//alert(shim-900);
//looking for 1557 base amount

//alert('ALTERED TO:'+dif);


function getModels(){
makeRequest(this.options[this.selectedIndex]);
}
function makeRequest(make){
	if(window.XMLHttpRequest){
		xhr=new XMLHttpRequest();
		 if (xhr.overrideMimeType){ 
      		req.overrideMimeType('text/xml');
			} 
		}else{
			if(window.ActiveXObject){
				try{
					xhr=new ActiveXobject("Microsoft.XMLHttp");
					 if (xhr.overrideMimeType){ 
      						xhr.overrideMimeType('text/xml'); 
	  					}
				}
				catch (e){}
			}
		}//end of else
	if(xhr){
		xhr.onreadystatechange=showContents;
		var url="getmodels.php?make="+make.value;
		//var url="model.xml";
		xhr.open('GET',url,true);
		//alert(make.value);
		xhr.send(null);
	}else{
			alert('cant get models, sorry');
	
	}
}

function showContents(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var xmlDoc=xhr.responseText;
			document.getElementById("modeloptions").innerHTML=xmlDoc;
		}
	}else{
	document.getElementById("modeloptions").innerHTML="Loading, wait...";
	
	}
}

function showblowup(imageref){

	
	document.getElementById('blowupwindow').style.height=screen.availHeight;
	document.getElementById('blowupwindow').style.width=screen.availWidth;
	document.getElementById('blowupwindow').style.visibility='visible';
	var image=document.getElementById('blowupimage');
	//image.height=50;
	//image.width=50;
	//image.src='images/ajax-loader.gif';
	//image.height=480;
	//image.width=640;
	image.src=imageref;	
	//document.style='opacity: 0.5;';
}
function showEquip(){
	document.getElementById('interior').style.visibility='hidden';
	document.getElementById('stdequip').style.visibility='visible';
	document.getElementById('techspec').style.visibility='hidden';
}
function showTech(){
	document.getElementById('interior').style.visibility='hidden';
	document.getElementById('stdequip').style.visibility='hidden';
	document.getElementById('techspec').style.visibility='visible';
}
function showInterior(){
	document.getElementById('interior').style.visibility='visible';
	document.getElementById('stdequip').style.visibility='hidden';
	document.getElementById('techspec').style.visibility='hidden';
}
function requestDistance(distance){
	if(window.XMLHttpRequest){
		xhr2=new XMLHttpRequest();
		 if (xhr2.overrideMimeType){ 
      		req.overrideMimeType('text/xml');
			} 
		}else{
			if(window.ActiveXObject){
				try{
					xhr2=new ActiveXobject("Microsoft.XMLHttp");
					 if (xhr2.overrideMimeType){ 
      						xhr2.overrideMimeType('text/xml'); 
	  					}
				}
				catch (e){}
			}
		}//end of else
	if(xhr2){
		xhr2.onreadystatechange=showDistance;
		var url="bin/distance.php?postcode="+distance;
		//var url="model.xml";
		xhr2.open('GET',url,true);
		//alert(make.value);
		xhr2.send(null);
	}else{
			alert('cant get distance, sorry');
	
	}
}
function showDistance(){

	if(xhr2.readyState==4){
		if(xhr2.status==200){
			var xmlDoc=xhr2.responseText;
			document.getElementById("deliverydistance").innerHTML=xmlDoc;
		}
	}else{
	document.getElementById("deliverydistance").innerHTML="Loading, wait...";
	
	}
}
var z = 10;
function showHideFront(id) {
  document.getElementById(id).style.zIndex = z++;
}