//<!--
// Ajax (JavaScript) - October 2011
// J Matthew Gaskill ©2009-2011 Cobalt Horizons Corporation

if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
  throw new Error( "This browser does not support XMLHttpRequest." )
};

setTimeout("Animate('truck')",500)

function UpdateStage(id){
	PanelWidth = '250px';

	var xhReq = new XMLHttpRequest();
	switch(id){
		case "Pricing":
		xhReq.open("GET", "content/pricing.php", true);
		break;
		
		case "About":
		xhReq.open("GET", "content/about.php", true);
		break;
		
		case "Biography":
		xhReq.open("GET", "content/biography.php", true);
		break;

		case "Testimonials":
		xhReq.open("GET", "content/testimonials.php", true);
		break;
		
		case "FAQ":
		xhReq.open("GET", "content/faq.php", true);
		break;
		
		case "Rinnai":
		xhReq.open("GET", "content/rinnai.php", true);
		break;
		
		case "Noritz":
		xhReq.open("GET", "content/noritz.php", true);
		break;
		
		case "Takagi":
		xhReq.open("GET", "content/takagi.php", true);
		break;

		case "Eternal":
		xhReq.open("GET", "content/eternal.php", true);
		break;
		
		case "Nuvo":
		xhReq.open("GET", "content/nuvo.php", true);
		break;
		
		case "Falsken":
		xhReq.open("GET", "content/falsken.php", true);
		break;

		case "Ondemand":
		xhReq.open("GET", "content/ondemand.php", true);
		break;

		case "Baxi":
		xhReq.open("GET", "content/baxi.php", true);
		break;
		
		case "RootX":
		xhReq.open("GET", "content/rootx.php", true);
		break;
		
		case "BioClean":
		xhReq.open("GET", "content/bioclean.php", true);
		break;
		
		case "Newsletter":
		xhReq.open("GET", "content/newsletter.php", true);
		break;
		
		case "Employment":
		xhReq.open("GET", "content/employment.php", true);
		PanelWidth = '1px';
		break;
		
		default:
		alert('unknown menu item');
		break;
	}

	xhReq.onreadystatechange = function(){
		if(xhReq.readyState != 4){ return; }
		Stage.innerHTML = xhReq.responseText;
		Panel.style.width = PanelWidth;
	};
	xhReq.send(null);
}

function Animate(id){
// animate vehicles

	if(id == "truck"){
		if(parseInt(truck.style.left) > -145 && parseInt(truck.style.left) < 156){
			truck.style.left = parseInt(truck.style.left) - 2 + "px";
		}else{
			truck.style.left = parseInt(truck.style.left) - 5 + "px";
		}
		
//		if(parseInt(truck.style.left) != 150){
			if(parseInt(truck.style.left) < -1000){
				truck.style.left = 1000 + "px";
				clearTimeout(t);
				var v = setTimeout("Animate('van')",3000);
			}
//			if(parseInt(truck.style.left) > -1000){
				var t = setTimeout("Animate('truck')",40);
//			}
//		}
	}

	if(id == "van"){
		if(parseInt(van.style.left) > 370 && parseInt(van.style.left) < 383){
			van.style.left = parseInt(van.style.left) - 1 + "px";
		}else{
			van.style.left = parseInt(van.style.left) - 7 + "px";
		}
		
		if(parseInt(van.style.left) != 375){
			if(parseInt(van.style.left) < -1000){
				van.style.left = 1000 + "px";
				clearTimeout(v);
			}
//			if(parseInt(van.style.left) > -1000){
				var v = setTimeout("Animate('van')",40);
//			}
		}
	}
}

function Send(id,action){
	if(typeof action == 'undefined'){ action = ''; }
//	if(!action){ var action = ''; }

	var output = document.getElementById(id + "_output");
	output.innerHTML = "Processing Request...";

	var xhReqSend = new XMLHttpRequest();
	var params = Serialize(id);

	xhReqSend.open("POST", "content/process.php", true); 
	xhReqSend.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  

	xhReqSend.onreadystatechange = function(){
		if(xhReqSend.readyState != 4){ return; }
		output.innerHTML = xhReqSend.responseText;
	};
	xhReqSend.send(params + "&action=" + action);

	return(false);
}
//-->
