	
	window.onload = attach;
	
	function attach() {
		var objInput = document.getElementsByTagName('input');
		for (var iCounter=0; iCounter<objInput.length; iCounter++)
		objInput[iCounter].onkeydown = function(){return isreturn;} //attach the onchange to each input field
	}
	
	function isreturn() {
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		alert("keycode: " + keycode);
	}
	
	function updatetext($field, $pk, $pkval, $table) {
		http = getHTTPObject();
		var url = 'process.php';
		var $text = escape(document.getElementById($field + '_edit').value);
		var $fullurl = url + '?field=' + $field + '&val=' + $text + '&pkval=' + $pkval + '&pk=';
		var $fullurl = $fullurl + $pk + '&table=' + $table +"&sid="+Math.random();
		http.open("GET", $fullurl, true);
		http.send(null);
		http.onreadystatechange = handleStateChange;
		//alert($fullurl);
	}
	
	function updateradio($field, $pk, $pkval, $table, $valuebtn) {
		http = getHTTPObject();
		var url = 'process.php';
		var $fullurl = url + '?field=' + $field + '&val=' + $valuebtn + '&pkval=' + $pkval + '&pk=';
		var $fullurl = $fullurl + $pk + '&table=' + $table +"&sid="+Math.random();
		http.open("GET", $fullurl, true);
		http.send(null);
	}
	
	function colorupdate( $valuebtn ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $fullurl = url + '?val=' + $valuebtn + "&sid="+ Math.random() + "&action=colorupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}
	
	function specupdate( $valuebtn ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $fullurl = url + '?val=' + $valuebtn + "&sid="+ Math.random() + "&action=specupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}
	
	function solutationupdate( $field ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $text = document.getElementById($field + '_edit').value;
		var $fullurl = url + '?val=' + $text + "&sid="+ Math.random() + "&action=solutationupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}
	
	function stateupdate( $field ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $text = document.getElementById($field + '_edit').value;
		var $fullurl = url + '?val=' + $text + "&sid="+ Math.random() + "&action=stateupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}

	function dealerstateupdate( $field ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $text = document.getElementById($field + '_edit').value;
		var $fullurl = url + '?val=' + $text + "&sid="+ Math.random() + "&action=dealerstateupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}

	function dealerupdate( $valuebtn ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $fullurl = url + '?val=' + $valuebtn + "&sid="+ Math.random() + "&action=dealerupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}

	function accessoriesupdate( $valuebtn ) {
		http = getHTTPObject();
		var url = 'process.php';
		var $fullurl = url + '?val=' + $valuebtn + "&sid="+ Math.random() + "&action=accessoriesupdate";
		http.open("GET", $fullurl, true);
		http.send(null);
	}

	function showDealer( $str ) {
		http = getHTTPObject();
		var url = 'dealerstate.php';
		var $fullurl = url + '?val=' + $str + "&sid="+Math.random();
		http.onreadystatechange=stateResponse; 
		http.open("GET", $fullurl, true);
		http.send(null);
		//alert($fullurl);
	}

	function stateResponse() 
	{ 
		if (http.readyState==4 || http.readyState=="complete")
			{ 
				document.getElementById("dealerstate").innerHTML=http.responseText 
			} 
		else if ( http.readyState<4 ) 
			{
				document.getElementById("dealerstate").innerHTML="<center></br></br></br><img src='images/loading.gif' /> Requesting content...</center>";
			}
	} 


	function showModel( $str ) {
		httpmodel = getHTTPObject();
		var url = 'ajaxcarmodel.php';
		var $fullurl = url + '?spec=' + $str + "&sid="+Math.random();
		httpmodel.onreadystatechange=modelResponse; 
		httpmodel.open("GET", $fullurl, true);
		httpmodel.send(null);
		//alert($fullurl);
	}

	function modelResponse() 
	{ 
		if (httpmodel.readyState==4 || httpmodel.readyState=="complete")
			{ 
				document.getElementById("carmodel").innerHTML=httpmodel.responseText 
			} 
	} 


	function showPrice( $str,$accessories,$price,$action ) {
		httpprice = getHTTPObject();
		var url = 'ajaxcarprice.php';
		var $fullurl = url + '?spec=' + $str + "&accessories=" + $accessories + "&price=" + $price + "&sid="+Math.random() + "&action=" + $action;
		httpprice.onreadystatechange=priceResponse; 
		httpprice.open("GET", $fullurl, true);
		httpprice.send(null);
		//alert($fullurl);
	}

	function priceResponse() 
	{ 
		if (httpprice.readyState==4 || httpprice.readyState=="complete")
			{ 
				document.getElementById("carprice").innerHTML=httpprice.responseText 
			} 
	} 


	function login( $str ) {
		httplogin = getHTTPObject();
		var url = 'bookmarks.php';
		var $fullurl = url + '?step=' + $str + "&sid="+Math.random();
		httplogin.onreadystatechange=loginResponse; 
		httplogin.open("GET", $fullurl, true);
		httplogin.send(null);
		//alert($fullurl);
	}

	function loginResponse() 
	{ 
		if (httplogin.readyState==4 || httplogin.readyState=="complete")
			{ 
				document.getElementById("login").innerHTML=httplogin.responseText 
			} 
	} 


	function logincheck( $user,$pass ) {
		httpcheck = getHTTPObject();
		var url = 'bookmarks.php';
		var $parameters = 'user=' + $user + '&pass=' + $pass;
		httpcheck.onreadystatechange=loginCheck; 
		httpcheck.open("POST", url, true);
	    httpcheck.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpcheck.send($parameters);
		//alert($fullurl);
	}

	function loginCheck() 
	{ 
		if (httpcheck.readyState==4 || httpcheck.readyState=="complete")
			{ 
				document.getElementById("login").innerHTML=httpcheck.responseText 
			} 
	} 


	//http.open('post',  'back_end.php');
	//http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//http.send('arg1=val1&arg2=val2&arg3=val3');


function handleStateChange() {
	if (http.readyState == 4) {
		
	 	if (http.responseXML.getElementsByTagName('field')[0].getAttribute("error") != '') {
			var field = http.responseXML.getElementsByTagName('field')[0].getAttribute('name');
			document.getElementById(field + '_error').innerHTML = http.responseXML.getElementsByTagName('field')[0].getAttribute("error");
			s1 = document.getElementById(field + '_error').style;
			s1.display = "block";
			givefocus(field + '_edit');
		} else {
			node= http.responseXML.getElementsByTagName('field');		
			var field = node[0].getAttribute("name");
			var textvalue = node[0].getAttribute("value");
			
			document.getElementById(field).innerHTML = textvalue;
			document.getElementById(field + '_edit').value = textvalue;
			
			s1 = document.getElementById(field + '_error').style;
			s1.display = "none";
			
			toggle (field, field + '_edit');
		}
	}
}

	function givefocus($field) {
		document.getElementById($field).focus();
	}
	
	function getHTTPObject()
	{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
	objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
	} 

function toggle(layeron, layeroff) {
	if (document.getElementById) {
		// this is the way the standards work
		var s1 = document.getElementById(layeron).style;
		s1.display = "block";
		
		var s2 = document.getElementById(layeroff).style;
		s2.display = "none";

	} else if (document.all) {
		// this is the way old msie versions work
		var s1 = document.getElementById(layeron).style;
		s1.display = "block";
		
		var s2 = document.getElementById(layeroff).style;
		s2.display = "none";

	} else if (document.layers)	{
		// this is the way nn4 works
		var s1 = document.getElementById(layeron).style;
		s1.display = "block";
		
		var s2 = document.getElementById(layeroff).style;
		s2.display = "none";
	}	
}