var xmlHttp,action,id,value;

function vis_switch(id)
{
	if(document.getElementById(id).style.display=="none")
	{
		document.getElementById(id).style.display="block";
	}
	else
	{
		document.getElementById(id).style.display="none";
	}
}

function doubleAjax(func1, func2) {
	func1();
	setTimeout(func2, 0500);
}

function ajaxAction(action,id,value) {
	var url = "ajax.php?action=" + action;

	if (action>0 && action<=3) { //Select necessary vars
		var drop1 = document.getElementById("drop1").value; //Make OR Part#
		var drop2 = document.getElementById("drop2").value; //Model OR Category
		var drop3 = document.getElementById("drop3").value; //Type OR Transponder
		var drop4 = document.getElementById("drop4").value; //Year OR Cloneable
		var drop5 = document.getElementById("drop5").value; //Bmy OR Obp
		var drop6 = document.getElementById("drop6").value; //Emy OR Tool
		url=url+"&drop1=" + drop1 + "&drop2=" + drop2 + "&drop3=" + drop3 + "&drop4=" + drop4 + "&drop5=" + drop5 + "&drop6=" + drop6;
	}

	if(action == 2 || action == 4) {
		url=url+"&value=" + value;
	}

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function(){stateChanged(id)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged(id) {
	if (xmlHttp.readyState==3) {
		document.getElementById(id).innerHTML='<hr style="visibility: hidden;" /><img src="images/loading.gif" />';
	} else if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(id).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function checkEnter(e)
{ //e is event object passed from function invocation
	var characterCode // literal character code will be stored in this variable

	if(e && e.which)
	{
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		ajaxAction(4,'results',document.getElementById('text1').value); //submit the form
		return false
	}
	else
	{
		return true
	}
}