function addShortList(adid) {
//alert('add '+adid);
	from = '';
	updateShortlistLink("add", adid, from);
	//updateCompareListShortlistLink();
	//updateShortlistPortlet();
}

function removeShortList(adid) {
//alert('rem '+adid);
	from = '';
	updateShortlistLink("remove", adid, from);
	//updateCompareListShortlistLink();
	//updateShortlistPortlet();
}

function addListingShortList(adid) {
//alert('add '+adid);
	from = 'listings';
	updateShortlistLink("add", adid, from);
	//updateCompareListShortlistLink();
	//updateShortlistPortlet();
}

function removeListingShortList(adid) {
//alert('rem '+adid);
	from = 'listings';
	updateShortlistLink("remove", adid, from);
	//updateCompareListShortlistLink();
	//updateShortlistPortlet();
}

function updateShortlistLink(action, adid, from) {
	//var ad_id = adid;
//alert('action='+action+', adid='+adid);
	var url = "ajax_shortlist_link.php?shortlist_adid="+adid+"&action="+action+"&from="+from;
	var xmlHttp1 = createXmlHttpRequestObject();
	if(xmlHttp1) {
		xmlHttp1.open("GET", url, true);
		xmlHttp1.onreadystatechange = function() {
			if(xmlHttp1.readyState == 4 && xmlHttp1.status == 200) {
				document.getElementById('ads_shortlist_link'+adid).innerHTML = xmlHttp1.responseText;
				updateCompareListShortlistLink();
				updateShortlistPortlet();
			}
		}
		xmlHttp1.send(null);
	}
}

function updateCompareListShortlistLink() {
//alert('update');
	var url = "ajax_compare_shortlist_link.php";
	var xmlHttp2 = createXmlHttpRequestObject();
	if(xmlHttp2) {
		xmlHttp2.open("GET", url, true);
		xmlHttp2.onreadystatechange = function() {
			if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200) {
				document.getElementById('shortlist_compare_link').innerHTML = xmlHttp2.responseText;
			}
		}
		xmlHttp2.send(null);
	}
}

function updateShortlistPortlet() {	
	var xmlHttp = createXmlHttpRequestObject();
	if(xmlHttp) {
		var url = "ajax_shortlist_portlet.php";
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				document.getElementById('preowned_shortlisted_portlet').innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(null);
	}
}

//to be depre
function changeButton(adid, remove) {
	//var xmlHttp = getHTTPObject();
	var ad_id = adid;
	var url = "../preowned/ajax_shortlist_button.php?adid="+adid+"&remove="+remove;
	var xmlHttp2 = createXmlHttpRequestObject();
	
	if(xmlHttp2) {
		xmlHttp2.open("GET", url, true);
		xmlHttp2.onreadystatechange = function() {
			if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200) {
//alert('cb-'+remove);
				document.getElementById('Shortlist'+adid).innerHTML = xmlHttp2.responseText;
			}
		}
		xmlHttp2.send(null);
	}
}

function compareCar(adid){
	var ad_id = adid;
	var state = "0";
	
	if(document.getElementById("checkbox"+adid).checked == true) {
		state = "1";
	}
	
	var url = "../preowned/ajax_comparecar.php?adid="+adid+"&state="+state;
	if(xmlHttp) {
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4  && xmlHttp2.status == 200) {
				document.getElementById('compareCar').innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(null);
	}
}
