var divTarget;
/******************** AJAX POST **********************/
var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
function loadingMessage() {
	document.getElementById(divTarget).innerHTML = "<img alt='...' src='/images/loader.gif' />";
}
function alertContents() {
	loadingMessage();
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            //result = http_request.responseText;
            document.getElementById(divTarget).innerHTML = http_request.responseText;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
 /*
function loadshadowboxpage(page,target){
	document.getElementById("popupwraper").display="block";
	divTarget = target;
	var poststr = "page="+page;
	makePOSTRequest(page, poststr);
}*/
function tellafriendnow(){
	divTarget = "sendafriend";
	var poststr = "action=tellafriend&property_id="+document.getElementById("property_id").value+"&your_name="+escape(encodeURIComponent(document.getElementById("your_name").value))+"&friend_name="+escape(encodeURIComponent(document.getElementById("friend_name").value))+"&friend_email="+escape(encodeURIComponent(document.getElementById("friend_email").value));
	makePOSTRequest("/process", poststr);
}
function closediv(div){
	document.getElementById(div).style.display = "none";
}
/******************** END AJAX POST **********************/
var xmlHttp;
var divTargetGET;
function createXMLHttpRequest() {
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
	
}
function handleStateChange() {
	//loadingMessage();
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status ==200){
			document.getElementById(divTargetGET).innerHTML = xmlHttp.responseText;
		}
	}
}
function loadURL(url,target){
	divTargetGET = target;
	document.getElementById(divTargetGET).innerHTML = "<img alt='loading...' src='/images/loader.gif' />";
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}
function loadshadowboxpage(url,target){
	document.getElementById("popupwraper").style.display = "block";
	divTargetGET = target;
	document.getElementById(divTargetGET).innerHTML = "<img alt='loading...' src='/images/loader.gif' />";
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}
function tellafriend()
{
	document.getElementById("sendafriend").style.display="inline";
	loadURL("/tellafriend","sendafriend");
}