var xmlHttp;

function clearcompare()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if

	var url = 'clearcompare.php';
	
	xmlHttp.onreadystatechange=stateChanged5;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);


}	


function addtocompare1(obj)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if

	var url = 'compare1.php?id=' + obj;
	
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);


}	

function addtocompare2(obj)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if

	var url = 'compare2.php?id=' + obj;
	
	xmlHttp.onreadystatechange=stateChanged4;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);


}	


function saveSearch (user, subCat, make, model, minPrice, maxPrice)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if

	var url = 'save_search.php?userid='+ user +'&s='+ subCat + '&mk='+ make + '&md='+ model +'&min='+ minPrice +'&max='+ maxPrice;
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
	
}

function saveKeywordSearch (user, keyword)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if
	
	var url = 'save_search.php?userid='+ user +'&k='+ keyword;
	
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);

}

function saveItem (user, listing)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}// end if
	
	var url = 'save_item.php?userid='+ user +'&listing='+ listing;
	
	
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);

}


// function to set the content of the object once the state has changed
function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("savedSearches").innerHTML=xmlHttp.responseText;
		//document.myForm.time.value=xmlHttp.responseText;
	}// end if
}// end function stateChanged()

function stateChanged2()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("savedItems").innerHTML=xmlHttp.responseText;
		//document.myForm.time.value=xmlHttp.responseText;
	}// end if
}// end function stateChanged()

function stateChanged3()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("compareoutput").innerHTML=xmlHttp.responseText;
		//document.myForm.time.value=xmlHttp.responseText;
	}// end if
}// end function stateChanged()

function stateChanged4()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("compare").innerHTML=xmlHttp.responseText;
		//document.myForm.time.value=xmlHttp.responseText;
	}// end if
}// end function stateChanged()

function stateChanged5()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("cleared").innerHTML=xmlHttp.responseText;
		//document.myForm.time.value=xmlHttp.responseText;
	}// end if
}// end function stateChanged()

// set the XML HTTP Object
function GetXmlHttpObject()
{
	var xmlHttp=null;

	// ***************
	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari, ...
        xmlHttp = new XMLHttpRequest();

		if (xmlHttp.overrideMimeType)
		{
            xmlHttp.overrideMimeType('text/xml');
        }// close if
    }else if (window.ActiveXObject) {
		// IE
        try
		{
        	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }// end try

		catch (e)
		{
        	try
			{
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }// end try

			catch (e) {}// end catch
        }// end catch
    }// end if else
    // ****************



	return xmlHttp;
}// end function GetXmlHttpObject
