
var advancedSearch = false;

function popImage(which) {
	window.open(root + "imobiliare/gallery.php?id=" + which, null, "width=800, height=700, resizable=yes, menubar=no, location=no, status=no, scrollbars=no, toolbar=no");
}

function showContainer(which) {
	document.getElementById(which).style.display = 'block';
}

function hideContainer(which) {
	document.getElementById(which).style.display = 'none';
}

function setListingType(type) {
	if (type == 'inchiriez') {
		document.getElementById('inputTipAnunt').value = 'rent';
		document.getElementById('btnInchiriez').src = root + 'imobiliare/imgs/btn.inchiriez.on.gif';
		document.getElementById('btnCumpar').src = root + 'imobiliare/imgs/btn.cumpar.off.gif';
	} else if (type == "cumpar") {
		document.getElementById('inputTipAnunt').value = 'sale';
		document.getElementById('btnInchiriez').src = root + 'imobiliare/imgs/btn.inchiriez.off.gif';
		document.getElementById('btnCumpar').src = root + 'imobiliare/imgs/btn.cumpar.on.gif';
	}
	if (advancedSearch == true) {
		goAdvancedSearch();
	}
}

function setPropertyType(type) {
	types = new Array("office","living","industrial","commercial","land");
	docObjs = new Array("btnOffice","btnLiving","btnIndustrial","btnCommercial","btnLand");
	classes = new Array("reOfficeButton","reLivingButton","reIndustrialButton","reCommercialButton","reLandButton");
	for (idx in types) {
		myObj = docObjs[idx];
		if (types[idx] == type) {
			document.getElementById(myObj).className = classes[idx] + 'On';
			document.getElementById('inputTipProprietate').value = types[idx];
		} else {
			document.getElementById(myObj).className = classes[idx] + 'Off';
		}
	}
	if (advancedSearch == true) {
		goAdvancedSearch();
	}
}

function goAdvancedSearch() {
	advancedSearch = true;
	if (document.getElementById('inputTipProprietate').value == "") {
		document.getElementById('reMesajEroareSearch').style.display = "block";
		document.getElementById('reMesajEroareSearchText').innerHTML = "Pentru a cauta anunturi trebuie sa specificati tipul de spatiu pe care il doriti folosind butoanele de mai sus.";
		alert("Specificati: birouri, locuinte, spatii industriale, spatii comerciale sau terenuri.");
	} else if (document.getElementById('inputTipAnunt').value == "") {
		document.getElementById('reMesajEroareSearch').style.display = "block";
		document.getElementById('reMesajEroareSearchText').innerHTML = "Pentru a cauta anunturi trebuie sa specificati daca doriti sa cumparati sau sa inchiriati o proprietate.";
		alert("Specificati: inchiriez sau cumpar.");
	} else {
		document.getElementById('reMesajEroareSearch').style.display = "none";
		document.getElementById('reMesajEroareSearchText').innerHTML = "";
		showAdvancedSearch(document.getElementById('inputTipProprietate').value);
	}
}

function showAdvancedSearch(which) {
	var ASFblocks = new Array("reASFCity","reASFIncaperi","reASFTipImobilLiving","reASFTipImobilOffice","reASFTipImobilIndustrial","reASFSpatiiBirouri","reASFTipImobilCommercial","reASFTipTeren","reASFLocTeren");
	var officeASFblocks = new Array("reASFCity","reASFTipImobilOffice");
	var livingASFblocks = new Array("reASFCity","reASFTipImobilLiving","reASFIncaperi");
	var industrialASFblocks = new Array("reASFCity","reASFTipImobilIndustrial","reASFSpatiiBirouri");
	var commercialASFblocks = new Array("reASFCity","reASFTipImobilCommercial");
	var landASFblocks = new Array("reASFCity","reASFTipTeren","reASFLocTeren");
	showContainer('advancedSearchForm');
	for (key in ASFblocks) {
		document.getElementById(ASFblocks[key]).style.display = "none";
	}
	if (which == 'office') {
		for (key in officeASFblocks) {
			document.getElementById(officeASFblocks[key]).style.display = "block";
		}
	} else if (which == 'living') {
		for (key in livingASFblocks) {
			document.getElementById(livingASFblocks[key]).style.display = "block";
		}
	} else if (which == 'industrial') {
		for (key in industrialASFblocks) {
			document.getElementById(industrialASFblocks[key]).style.display = "block";
		}
	} else if (which == 'commercial') {
		for (key in commercialASFblocks) {
			document.getElementById(commercialASFblocks[key]).style.display = "block";
		}
	} else if (which == 'land') {
		for (key in landASFblocks) {
			document.getElementById(landASFblocks[key]).style.display = "block";
		}
	}
}

function submitSearchForm() {
	if (document.getElementById('inputTipProprietate').value == "") {
		document.getElementById('reMesajEroareSearch').style.display = "block";
		document.getElementById('reMesajEroareSearchText').innerHTML = "Pentru a cauta anunturi trebuie sa specificati tipul de spatiu pe care il doriti folosind butoanele de mai sus.";
		alert("Specificati: birouri, locuinte, spatii industriale, spatii comerciale sau terenuri.");
	} else if (document.getElementById('inputTipAnunt').value == "") {
		document.getElementById('reMesajEroareSearch').style.display = "block";
		document.getElementById('reMesajEroareSearchText').innerHTML = "Pentru a cauta anunturi trebuie sa specificati daca doriti sa cumparati sau sa inchiriati o proprietate.";
		alert("Specificati: inchiriez sau cumpar.");
	} else {
		document.getElementById('inputJudetId').value = document.getElementById('judetid').value;
		myUrl = root + "imobiliare/searchpath.php";
		params = "judetid=" + document.getElementById('inputJudetId').value;
		params += "&tip_proprietate=" + document.getElementById('inputTipProprietate').value;
		params += "&tip_anunt=" + document.getElementById('inputTipAnunt').value;
		if (advancedSearch == true) {
			params += "&orasid=" + document.getElementById('reOrasid').value;
			params += "&keys=" + encodeURIComponent(document.getElementById('reZone').value);
			if (document.getElementById('inputTipProprietate').value == "living") {
				params += "&incaperi=" + document.getElementById('reIncaperi').value;
				params += "&tip_imobil=" + document.getElementById('reTipImobilLiving').value;
			}
			if (document.getElementById('inputTipProprietate').value == "office") {
				params += "&tip_imobil=" + document.getElementById('reTipImobilOffice').value;
			}
			if (document.getElementById('inputTipProprietate').value == "industrial") {
				params += "&tip_imobil=" + document.getElementById('reTipImobilIndustrial').value;
				params += "&spatii_birouri=" + document.getElementById('reSpatiiBirouri').value;
			}
			if (document.getElementById('inputTipProprietate').value == "commercial") {
				params += "&tip_imobil=" + document.getElementById('reTipImobilCommercial').value;
			}
			if (document.getElementById('inputTipProprietate').value == "land") {
				params += "&loc_teren=" + document.getElementById('reLocTeren').value;
				params += "&tip_teren=" + document.getElementById('reTipTeren').value;
			}
		}
		var xmlHttp;
		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.open("POST",myUrl,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4) {
				if (xmlHttp.responseText != "0") {
					location.href = xmlHttp.responseText;
				}
			}
		}
		xmlHttp.send(params);
	}
}

function submitMessage(which) {
	myUrl = root + "imobiliare/bin/sendtofriend.php";
	params = 'enforcer=send&listingid=' + which;
	params += '&sender_name=' + encodeURIComponent(document.getElementById('sender_name').value);
	params += '&sender_email=' + encodeURIComponent(document.getElementById('sender_email').value);
	params += '&recipient_name=' + encodeURIComponent(document.getElementById('recipient_name').value);
	params += '&recipient_email=' + encodeURIComponent(document.getElementById('recipient_email').value);
	params += '&message=' + encodeURIComponent(document.getElementById('message').value);
	var xmlHttp;
	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.open("POST",myUrl,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	document.getElementById('reMsgContainer').innerHTML = 'Va rugam asteptati...';
	document.getElementById('reSendToFriendMessage').style.display = 'block';
	document.getElementById('reSendToFriend').style.display = 'none';
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if (xmlHttp.responseText == 1) {
				document.getElementById('reMsgContainer').innerHTML = '<font color="#009900">Mesajul a fost trimis cu succes.</font>';
				document.getElementById('sender_name').value = '';
				document.getElementById('sender_email').value = '';
				document.getElementById('recipient_name').value = '';
				document.getElementById('recipient_email').value = '';
				document.getElementById('message').value = '';
				setTimeout('hideContainer("reSendToFriendMessage")',5000);
			} else {
				document.getElementById('reMsgContainer').innerHTML = '<font color="#CF0000">' + xmlHttp.responseText + '</font>';
				document.getElementById('reSendToFriend').style.display = 'block';
			}
		}
	}
	xmlHttp.send(params);
}

function printListing(which) {
	window.open(root + "imobiliare/printlisting.php?id=" + which, null, "width=800, height=700, resizable=yes, menubar=no, status=no, scrollbars=yes, toolbar=no");
}

function extendListing(which) {
	myUrl = root + "imobiliare/bin/extendlisting.php";
	params = "which=" + which;
	var xmlHttp;
	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.open("POST",myUrl,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			responseText = xmlHttp.responseText;
			messageLineID = 'lnkExtendListing_' + which;
			document.getElementById(messageLineID).innerHTML = 'Cererea de prelungire a anuntului a fost trimisa.';
		}
	}
	xmlHttp.send(params);
}

