// Changed 03-02-2010
// Created 25-05-2009
var xmlHttp;
var xmlHttpDispose=(navigator.userAgent.indexOf("MSIE 7.")>=0)||(navigator.userAgent.indexOf("MSIE 6.")>=0);
xmlHttpNew();

function xmlHttpRefresh() {
	if (xmlHttpDispose) {
		xmlHttp=null;
		xmlHttpNew();
	}
}
function xmlHttpNew() {
	try {  // Firefox, Opera 8.0+, Safari, and IE7
		xmlHttp=new XMLHttpRequest();  
	} catch (e) { // IE 8+
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlHttp=null;
			}
		}
	}
}
function findCity() {
	xmlHttpRefresh();
	xmlHttp.onreadystatechange=fillCityField;
	xmlHttp.open("GET","/ajax/zipcode.asp?zip=" + document.Form1.Zip.value,true);
	xmlHttp.send(null);
}
function fillCityField() {
	if(xmlHttp.readyState==4) {
    	if (xmlHttp.responseText.length > 0) {
      		document.Form1.City.value=xmlHttp.responseText;
    	}
	}
}
function findCountry() {
	xmlHttpRefresh();
	xmlHttp.onreadystatechange=fillCountryField;
	xmlHttp.open("GET","/ajax/countrycode.asp?CountryCode=" + document.Form1.CountryCode.value,true);
	xmlHttp.send(null);
}
function fillCountryField() {
	if(xmlHttp.readyState==4) {
    	if (xmlHttp.responseText.length > 0) {
      		document.Form1.Country.value=xmlHttp.responseText;
    	}
	}
}
function favorite(blAdd,intPlaceId) {
	xmlHttpRefresh();
	if (document.getElementById("FavoriteBox") != null ) {
		xmlHttp.onreadystatechange=fillFavoriteField;
	} else {
		xmlHttp.onreadystatechange=null
		document.getElementById("Favorite" + intPlaceId.toString()).innerHTML = "";
	}
	if (blAdd) {
		xmlHttp.open("GET","/ajax/favorite.asp?action=add&placeid=" + intPlaceId.toString(),true);
	} else {
		xmlHttp.open("GET","/ajax/favorite.asp?action=remove&placeid=" + intPlaceId.toString(),true);
	}
	xmlHttp.send(null);
}
function fillFavoriteField() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status==200) {
    		if (xmlHttp.responseText.length > 0) {
		    	document.getElementById("FavoriteBox").innerHTML=xmlHttp.responseText;
    		}
		} else {errorWindow(xmlHttp.responseText)}
	}
}
function ownerCommentEmail(blSend) {
	xmlHttpRefresh();
	xmlHttp.onreadystatechange=fillCommentEmail;
	if (blSend) {
		xmlHttp.open("GET","/ajax/ownersendcommemail.asp?send=yes",true);
	} else {
		xmlHttp.open("GET","/ajax/ownersendcommemail.asp?send=no",true);
	}
	xmlHttp.send(null);
}
function fillCommentEmail() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status==200) {
    		if (xmlHttp.responseText.length > 0) {
		    	document.getElementById("CommentEmails").innerHTML=xmlHttp.responseText;
    		}
		} else {errorWindow(xmlHttp.responseText)}
	}
}
var OwnerStatsLoadingMsg;
function ownerStatsInit() {
	OwnerStatsLoadingMsg=document.getElementById("Statistics").innerHTML;
	ownerStatsLoad(0,false);
}
function ownerStatsLoad(intIdx,blShowProgress) {
	if (blShowProgress) {
		document.getElementById("Statistics").innerHTML=OwnerStatsLoadingMsg;
	}
	xmlHttpRefresh();
	xmlHttp.onreadystatechange=ownerStatsLoadResponse;
	xmlHttp.open("GET","/ajax/ownerstats.asp?placeidx=" + intIdx.toString(),true);
	xmlHttp.send(null);
}
function ownerStatsLoadResponse() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status==200) {
    		if (xmlHttp.responseText.length > 0) {
		    	document.getElementById("Statistics").innerHTML=xmlHttp.responseText;
    		}
		} else {errorWindow(xmlHttp.responseText)}
	}
}
function clickLink(intPlaceId) {
	xmlHttpRefresh();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 && xmlHttp.status!=200) {
			errorWindow(xmlHttp.responseText);
			}
		};
	xmlHttp.open("GET","/ajax/linkcounter.asp?id=" + intPlaceId.toString(),true);
	xmlHttp.send(null);
	return true;
}
function submitForm(fmName,fmAction) {
	var strArg="";
	
	if(true) {
		var fmComment = document.forms[fmName];
		fmComment.elements["fmAction"].value = fmAction;
		
		for (var i=0; i<fmComment.elements.length; i++) {
			if (fmComment.elements[i].name.length > 0) {
				if (fmComment.elements[i].type=="radio") {
					if (fmComment.elements[i].checked) {
						strArg += (strArg.length>0)?"&":"";
						strArg += fmComment.elements[i].name + "=" + escape(fmComment.elements[i].value);
					}
				} else {
					strArg += (strArg.length>0)?"&":"";
					strArg += fmComment.elements[i].name + "=" + escape(fmComment.elements[i].value);
				}
			}
		}
		strArg += "\n";
		xmlHttpRefresh();
		xmlHttp.onreadystatechange=submitForm_response;
		xmlHttp.open("POST",fmComment.action,true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", strArg.length);
        xmlHttp.setRequestHeader("Connection", "close");
    	xmlHttp.send(strArg);
	}
}
function submitForm_response() {
	if(xmlHttp.readyState==4) {
		//errorWindow(xmlHttp.responseText);
		
		if (xmlHttp.status != 200) {
			errorWindow(xmlHttp.responseText);
		} else {
    		if (xmlHttp.responseText.length > 0) {
	    		var intIdx = xmlHttp.responseText.indexOf(";");
	    		if (intIdx < 40 && intIdx != -1) {
	    			var intIdx2 = xmlHttp.responseText.indexOf(";",intIdx+1);
	    			var strBoxId = xmlHttp.responseText.substr(0,intIdx);
	    			var strNextCall = xmlHttp.responseText.substr(intIdx+1,intIdx2-intIdx-1);
	    			//alert(xmlHttp.responseText);
	    			document.getElementById(strBoxId).innerHTML=xmlHttp.responseText.substring(intIdx2+1,xmlHttp.responseText.length);
	    			// alert(innerHTML=xmlHttp.responseText);
	    			// document.getElementById("InputCurrentTags").innerHTML=xmlHttp.responseText;
	    			if (strNextCall != "") {
		    			xmlHttpRefresh();
		    			xmlHttp.onreadystatechange=submitForm_response;
						xmlHttp.open("GET",strNextCall,true);
						xmlHttp.send(null);
	    			}
    			} else {
	    			//alert(xmlHttp.responseText);
	    			errorWindow(xmlHttp.responseText);
				}
    		}
    	}
  	}
}
function hideById(strId) {
	document.getElementById(strId).style.display="none";
}
function errorWindow(strErrorHtml) {
  var winError = window.open("","winError","scrollbars=yes,resizable=yes,location=no,toolbar=no,directories=no,status=no,fullscreen=no,width=800,height=700");
  winError.document.write(strErrorHtml);
}