
var ddfocus = false;

function droptoggle(divid) {
	ddfocus = true;
	var divobj = document.getElementById(divid);
	if(divobj.style.display == "none") {
		divobj.style.display = "block";
	}
	else {
		divobj.style.display = "none";
		ddfocus = false;
	}
}

function dropunfocus() {
	ddfocus = false;
}

function dropclearAll() {
	if(!ddfocus) {
		if(ddelem['ddcountry'] && ddelem['ddstate'] && ddelem['ddcity']) {
			ddelem['ddcountry'].style.display = "none";
			ddelem['ddstate'].style.display = "none";
			ddelem['ddcity'].style.display = "none";
		}
	}
	if(document.getElementById('ls_state')) {
		document.getElementById('ls_state').style.display = "none";
		document.getElementById('ls_city').style.display = "none";
		document.getElementById('ls_neighborhood').style.display = "none";
	}
}

document.onclick = dropclearAll;

function setVal(newValue, ddid, maskVal) {
	var ddlink = ddid + "link";
	var ddinput = ddid + "val";
	ddlinkobj = document.getElementById(ddlink);
	ddinputobj = document.getElementById(ddinput);
	if(maskVal != undefined) {
		ddlinkobj.innerHTML = maskVal;
	}
	else {
		ddlinkobj.innerHTML = newValue;
	}
	ddinputobj.value = newValue;
	if(ddid == "ddcountry") {
		document.getElementById('ddstatelink').innerHTML = "(Select State)";
		document.getElementById('ddstateval').value = "";
		document.getElementById('ddcitylink').innerHTML = "(Select City)";
		document.getElementById('ddcityval').value = "";
		document.getElementById('expandlist').innerHTML = "";
	}
	if(ddid == "ddstate") {
		document.getElementById('ddcitylink').innerHTML = "(Select City)";
		document.getElementById('ddcityval').value = "";
	}
}

function processGetPost_ddstate() {
	var myajax = ajaxpack.ajaxobj;
	var myfiletype = ajaxpack.filetype;
	if(myajax.readyState == 4) {
		// if request of file completed
		if(myajax.status == 200 || window.location.href.indexOf("http") == -1) {
			// if request was successful or running script locally
			if(myfiletype == "txt") {
				response_value = myajax.responseText;
			}
			else {
				response_value = myajax.responseXML;
			}
			document.getElementById('ddstate').innerHTML = response_value;
		}
	}
}

function processGetPost_ddcity() {
	var myajax = ajaxpack.ajaxobj;
	var myfiletype = ajaxpack.filetype;
	if(myajax.readyState == 4) {
		// if request of file completed
		if(myajax.status == 200 || window.location.href.indexOf("http") == -1) {
			// if request was successful or running script locally
			if(myfiletype == "txt") {
				response_value = myajax.responseText;
			}
			else {
				response_value = myajax.responseXML;
			}
			document.getElementById('ddcity').innerHTML = response_value;
			propList();
		}
	}
}

var propListArg = "";

function propDrop(targetDrop, filterVal, listVal) {
	
	if(targetDrop == "state") {
		var postStr = "filterval=" + encodeURI(filterVal) + "&drop=" + targetDrop;
		ajaxpack.postAjaxRequest("/propdrop.php", postStr, processGetPost_ddstate, "txt");
	}
	if(targetDrop == "city") {
		if(listVal) {
			document.getElementById('propListArg').value = listVal;
		}
		else {
			document.getElementById('propListArg').value = document.getElementById('ddstateval').value;
		}
		var postStr = "filterval=" + encodeURI(filterVal) + "&drop=" + targetDrop;
		ajaxpack.postAjaxRequest("/propdrop.php", postStr, processGetPost_ddcity, "txt");
	}
	
	
}

function processGetPost_elist() {
	var myajax = ajaxpack.ajaxobj;
	var myfiletype = ajaxpack.filetype;
	if(myajax.readyState == 4) {
		// if request of file completed
		if(myajax.status == 200 || window.location.href.indexOf("http") == -1) {
			// if request was successful or running script locally
			if(myfiletype == "txt") {
				response_value = myajax.responseText;
			}
			else {
				response_value = myajax.responseXML;
			}
			document.getElementById('expandlist').innerHTML = response_value;
		}
	}
}

function propList() {
	filterVal = document.getElementById('propListArg').value;
	var postStr = "filterval=" + encodeURI(filterVal);
	ajaxpack.postAjaxRequest("/proplist.php", postStr, processGetPost_elist, "txt");
}

function viewStores(cSpec, nSpec) {
	var val1 = document.getElementById('ddcountryval').value;
	var val2 = document.getElementById('ddstateval').value;
	var val3 = document.getElementById('ddcityval').value;
	if(cSpec == undefined) {
		window.location = "/list.php?country=" + encodeURI(val1) + "&state=" + encodeURI(val2) + "&city=" + encodeURI(val3);
	}
	else {
		window.location = "/list.php?country=" + encodeURI(val1) + "&state=" + encodeURI(val2) + "&city=" + encodeURI(cSpec) + "&neighborhood=" + encodeURI(nSpec);
	}
}

function toggleExpand(aObj, menuId) {
	menuObj = document.getElementById(menuId);
	if(aObj.className == "listplus") {
		aObj.className = "listminus";
		menuObj.style.display = "block";
	}
	else {
		aObj.className = "listplus";
		menuObj.style.display = "none";
	}
}

function toggleProfilePage(pagename) {
	if(pagename == "enlargemap") {
		var linkon = document.getElementById('open1on');
		var linkoff = document.getElementById('open1off');
		var link2on = document.getElementById('open2on');
		var link2off = document.getElementById('open2off');
	}
	if(pagename == "storephotos") {
		var linkon = document.getElementById('open2on');
		var linkoff = document.getElementById('open2off');
		var link2on = document.getElementById('open1on');
		var link2off = document.getElementById('open1off');
	}
	var page1 = document.getElementById('storedesc');
	var page2 = document.getElementById('fullmap');
	var page3 = document.getElementById('morephotos');
	if(linkon.style.display == "block") {
		var turnSet = "off";
	}
	else {
		var turnSet = "on";
	}
	if(turnSet == "off") {
		linkon.style.display = "none";
		linkoff.style.display = "block";
		link2on.style.display = "block";
		link2off.style.display = "none";
		if(pagename == "enlargemap") {
			page1.style.display = "none";
			page2.style.display = "block";
			page3.style.display = "none";
		}
		if(pagename == "storephotos") {
			page1.style.display = "none";
			page2.style.display = "none";
			page3.style.display = "block";
		}
	}
	else {
		linkon.style.display = "block";
		linkoff.style.display = "none";
		link2on.style.display = "block";
		link2off.style.display = "none";
		page1.style.display = "block";
		page2.style.display = "none";
		page3.style.display = "none";
	}
}

function hideFullMap() {
	if(document.getElementById('fullmap')) {
		document.getElementById('fullmap').style.display = "none";
		document.getElementById('fullmap').style.visibility = "visible";
	}
}

var ddelem = new Array();

function registerDDelements() {
	if(document.getElementById('ddcountry')) {
		ddelem['ddcountry'] = document.getElementById('ddcountry');
	}
	if(document.getElementById('ddstate')) {
		ddelem['ddstate'] = document.getElementById('ddstate');
	}
	if(document.getElementById('ddcity')) {
		ddelem['ddcity'] = document.getElementById('ddcity');
	}
}

function bodyLoad() {
	if(hideFullMap) {
		hideFullMap();
	}
	if(registerDDelements) {
		registerDDelements();
	}
}

function showLivesearch(divId) {
	document.getElementById(divId).style.display = "block";
}

function ratingHover(setID) {
	var star1 = document.getElementById('star1');
	var star2 = document.getElementById('star2');
	var star3 = document.getElementById('star3');
	var star4 = document.getElementById('star4');
	var star5 = document.getElementById('star5');
	if(setID == "1") {
		star1.className = "ratingon";
		star2.className = "ratingoff";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(setID == "2") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(setID == "3") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(setID == "4") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingoff";
	}
	if(setID == "5") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingon";
	}
}

function ratingClear() {
	var star1 = document.getElementById('star1');
	var star2 = document.getElementById('star2');
	var star3 = document.getElementById('star3');
	var star4 = document.getElementById('star4');
	var star5 = document.getElementById('star5');
	var ratingval = document.getElementById('ratingval').value;
	if(ratingval == '') {
		star1.className = "ratingoff";
		star2.className = "ratingoff";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(ratingval == '1') {
		star1.className = "ratingon";
		star2.className = "ratingoff";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(ratingval == '2') {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(ratingval == '3') {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
	}
	if(ratingval == '4') {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingoff";
	}
	if(ratingval == '5') {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingon";
	}
}

function ratingClick(setID) {
	var star1 = document.getElementById('star1');
	var star2 = document.getElementById('star2');
	var star3 = document.getElementById('star3');
	var star4 = document.getElementById('star4');
	var star5 = document.getElementById('star5');
	if(setID == "1") {
		star1.className = "ratingon";
		star2.className = "ratingoff";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
		document.getElementById('ratingval').value = "1";
	}
	if(setID == "2") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingoff";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
		document.getElementById('ratingval').value = "2";
	}
	if(setID == "3") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingoff";
		star5.className = "ratingoff";
		document.getElementById('ratingval').value = "3";
	}
	if(setID == "4") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingoff";
		document.getElementById('ratingval').value = "4";
	}
	if(setID == "5") {
		star1.className = "ratingon";
		star2.className = "ratingon";
		star3.className = "ratingon";
		star4.className = "ratingon";
		star5.className = "ratingon";
		document.getElementById('ratingval').value = "5";
	}
}

function validateForm(textarea, formname) {
	if(textarea.value == '') {
		alert("You must enter a review.");
	}
	else {
		formname.submit();
	}
}

function confirmDeleteReview(formId) {
	formobj = document.getElementById(formId);
	var confirmTxt = "Are you sure you want to delete this review?";
	var answer = confirm(confirmTxt);
	if(answer) {
		formobj.submit();
	}
}
