function loadFriendEmailer(webref)
{
//	$('').innerHTML = "";
	new Ajax.Request("?page=property_details&webref=" + webref,
     {
		onSuccess : function(response, json) 
		{
		    $('mail_friend_div').innerHTML = response.responseText;
	       	showFriendEmailer();
		},
		onFailure : function(response)
		{
		    alert('Error loading agents');
		},
		parameters : "doemailfriend=true&content=main&webref=" + webref
	}
    );
}

function showFriendEmailer()
{
	div = $('mail_friend_div');
	var arrayPageSize = get_page_size();
	var arrayPageScroll = get_page_scroll();
	if(div.visible())
	{
		Effect.Fade(div,{queue: 'end', scope: 'togglebar', duration:.5})
		$('backOverlay').style.display = 'none';
		if(div.visible())
		{
			div.style.display = 'none';
			$('backOverlay').style.display = 'none';
		}
	}
	else
	{
		createBackground("showFriendEmailer();");
		div.style.top 		= (arrayPageScroll[1] + (arrayPageSize[3] / 15)) + "px";
		div.style.left 		= (arrayPageSize[2] / 4) + "px";
		Effect.Appear(div,{queue: 'end', scope: 'togglebar', duration:.5})
		$('backOverlay').style.height = (arrayPageSize[1] + 1000) + "px";
		$('backOverlay').style.display = 'block';		
	}
	
}

function createBackground(functionName)
{
	if(!document.getElementById('backOverlay'))
	{
		var objBody = document.getElementsByTagName("body").item(0);
			
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','backOverlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { eval(functionName); return false; }
		objBody.appendChild(objOverlay);
	}
}

function get_page_scroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function get_page_size(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function doEmailSend (webref)
{
	if ($('user_email').value.length < 2 || $('friend_email').value.length < 2 || $('email_subject').value.length < 2) {
		alert("Please be sure to enter your e-mail address, your friends, and a short subject line.");
		return;
	}
	
	new Ajax.Request("?page=property_details&amp;sendfriendemail=true&amp;webref=" + webref,
    {
		onSuccess : function(response, json) 
		{
			alert(response.responseText);
			//contact = new MaJiG_BOX(response.responseText);
		},
		onFailure : function(response)
		{
		    alert('Error loading agents');
		},
		parameters : "sendfriendemail=true&content=main&webref=" + webref + "&user_name="+$('user_name').value+"&friend_name="+$('friend_name').value+"&user_email=" + $('user_email').value + "&friend_email=" + $('friend_email').value + "&email_subject=" + $('email_subject').value + "&email_message=" + $('email_message').value+ "&sendformat_html=" +$('sendformat_html').checked + "&sendformat_text=" + $('sendformat_text').checked
	}
    );
    showFriendEmailer();
}

function TogglePropertyMap()
{
	if (!bMapMode)
	{
		$('propdetail_map').style.display='block';
		$('propdetail_map_back').style.display='block';
		$('propdetail_container').style.display='none';
		
		if (!oMap)
		{
			if (GBrowserIsCompatible()) {
        		oMap = new GMap2(document.getElementById("propdetail_map"));
        	    oMap.addControl(new GLargeMapControl());
				oMap.addControl(new GMapTypeControl());
			}	
    	}
		oMap.setCenter(new GLatLng(iPropLatitude, iPropLongitude), 15);
		if (!oMapMarker && bPropExact)
		{
			// Map marker is global for later usage
			oMapMarker = new GMarker(new GLatLng(iPropLatitude, iPropLongitude));
			oMap.addOverlay(oMapMarker);
		}
		if (bPropExact)
		{
			oMap.closeInfoWindow();
		 	oMapMarker.openInfoWindowHtml(szPropAddress);
		}
    	
		bMapMode=true;
	}
	else
	{
		$('propdetail_map').style.display='none';
		$('propdetail_map_back').style.display='none';
		$('propdetail_container').style.display='block';
		bMapMode=false;
	}
	
	
}
