btnOn = new Array();
btnOn['btnHome'] = new Image(); btnOn['btnHome'].src = root + 'imgs/btn.home.on.gif';
btnOn['btnOferta'] = new Image(); btnOn['btnOferta'].src = root + 'imgs/btn.ofertamasini.on.gif';
btnOn['btnBuyBack'] = new Image(); btnOn['btnBuyBack'].src = root + 'imgs/btn.buyback.on.gif';
btnOn['btnUtile'] = new Image(); btnOn['btnUtile'].src = root + 'imgs/btn.utile.on.gif';
btnOn['btnContact'] = new Image(); btnOn['btnContact'].src = root + 'imgs/btn.contact.on.gif';
btnOn['btnNoutati'] = new Image(); btnOn['btnNoutati'].src = root + 'imgs/btn.noutati.on.gif';

btnOff = new Array();
btnOff['btnHome'] = new Image(); btnOff['btnHome'].src = root + 'imgs/btn.home.off.gif';
btnOff['btnOferta'] = new Image(); btnOff['btnOferta'].src = root + 'imgs/btn.ofertamasini.off.gif';
btnOff['btnBuyBack'] = new Image(); btnOff['btnBuyBack'].src = root + 'imgs/btn.buyback.off.gif';
btnOff['btnUtile'] = new Image(); btnOff['btnUtile'].src = root + 'imgs/btn.utile.off.gif';
btnOff['btnContact'] = new Image(); btnOff['btnContact'].src = root + 'imgs/btn.contact.off.gif';
btnOff['btnNoutati'] = new Image(); btnOff['btnNoutati'].src = root + 'imgs/btn.noutati.off.gif';

function hiLite(which) {
	whichID = which.id;
	document.getElementById(whichID).src = btnOn[whichID].src;
}

function loLite(which) {
	whichID = which.id;
	document.getElementById(whichID).src = btnOff[whichID].src;
}

function homeListingsRefresh(pageNumber,doQuickSearch) {
	myUrl = root + 'listingsbox.php?page=' + pageNumber;
	if (doQuickSearch == true) {
		myUrl += '&doQuickSearch=true';
		myUrl += '&tip_anunt=' + document.getElementById('tip_anunt').value;
		myUrl += '&marcaid=' + document.getElementById('marcaid').value;
		myUrl += '&modelid=' + document.getElementById('modelid').value;
		myUrl += '&pretminim=' + document.getElementById('pretminim').value;
		myUrl += '&pretmaxim=' + document.getElementById('pretmaxim').value;
	}
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			document.getElementById('listingsContainer').innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",myUrl,true);
	xmlHttp.send(null);
}

function rebuildQuickSearch() {
	var tip_anunt = document.getElementById('tip_anunt').value;
	var marcaid = document.getElementById('marcaid').value;
	var modelid = document.getElementById('modelid').value;
	marciSelect = document.getElementById('marcaid');
	modeleSelect = document.getElementById('modelid');
	try {
		carburantSelect = document.getElementById('carburantid');
		var carburantid = document.getElementById('carburantid').value;
	} catch (e) {
		//do nothing
	}
	myUrl = root + 'qsearchdynamics.php?tip_anunt=' + tip_anunt + '&marcaid=' + marcaid + '&modelid=' + modelid;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			myResponse = xmlHttp.responseText;
			myArrays = myResponse.split(":::");
			marci = myArrays[0].split("-:-");
			modele = myArrays[1].split("-:-");
			carburanti = myArrays[2].split("-:-");
			try {
				selectIndexId = 1;
				for (i = 1; i < marciSelect.length; i++) {
					marciSelect.options[i] = null;
				}
				for (k in marci) {
					if (marci[k] != '') {
						tmp = marci[k].split("::");
						if (marcaid != tmp[0]) {
							marciSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],false,false);
						} else {
							marciSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],true,true);
						}
						selectIndexId++;
					}
				}
				selectIndexId = 1;
				for (i = 1; i < modeleSelect.length; i++) {
					modeleSelect.options[i] = null;
				}
				for (k in modele) {
					if (modele[k] != '') {
						tmp = modele[k].split("::");
						if (modelid != tmp[0]) {
							modeleSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],false,false);
						} else {
							modeleSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],true,true);
						}
						selectIndexId++;
					}
				}
				selectIndexId = 1;
				for (i = 1; i < carburantSelect.length; i++) {
					carburantSelect.options[i] = null;
				}
				for (k in carburanti) {
					if (carburanti[k] != '') {
						tmp = carburanti[k].split("::");
						if (carburantid != tmp[0]) {
							carburantSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],false,false);
						} else {
							carburantSelect.options[selectIndexId] = new Option(tmp[1],tmp[0],true,true);
						}
						selectIndexId++;
					}
				}
			} catch(e) {
				// do nothing
			}
		}
	}
	xmlHttp.open("GET",myUrl,true);
	xmlHttp.send(null);
}