//0 means disabled; 1 means enabled;


var map = null;
    var geocoder = null;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(40.266044,-74.718479), 13);
        geocoder = new GClientGeocoder();
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());			
      }
    }



var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(Type){
	//alert("calling loadpopup");
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#"+Type).fadeIn("fast");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(Type){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#"+Type).fadeOut("fast");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(Type){
	//alert("call center popup");
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+Type).height();
	var popupWidth = $("#"+Type).width();
	//centering
	$("#"+Type).css({
		"position": "absolute"/*,
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2*/
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}





function submitNewsletter(emailid,baseurl)
{
	if(emailid=="")
	{
		$("#news_msg").css({'color':"#ffffff"});
		$("#news_msg").css({'font-size':"13px"});
		$("#news_msg").html("Please enter email id.");
		$("#news_msg").fadeIn("5000");
		
		//alert("Please enter email id.");
		setTimeout("hideNewsMsg()",5000);
		document.getElementById("email").focus();
		return false;
	}
	else
	{
		defaulthttpPost(baseurl+"scripts/jxNewsletter.php?emailid="+emailid,"news_msg");
		document.getElementById("email").value="";
		return false;
	}
	
}
 function hideNewsMsg(){
	 $("#news_msg").fadeOut(5000);
   }
   
   

function paging(page_id)
{
	$.ajax({ 
	type: "POST", 
	url: "jxCommon.php", 
	data: "action=paging&page_id="+page_id, 
	success: function(msg){ 
	//alert( "Data Saved: " + msg ); 
	var split_msg = msg.split('::');
	//alert(split_msg[0]);
	$(".paging").html(split_msg[0]);
	$(".gallery_listing").html(split_msg[1]);
	} 
	});

}



function showMLS_search()
{
	centerPopup('popupContact');
	loadPopup('popupContact');
}

function showSendFriend()
{
	centerPopup('popupSend');
	loadPopup('popupSend');
}

function showMap()
{
	centerPopup('popupMap');
	loadPopup('popupMap');
	var prop_address = $("#property_location").val();
	load();
	showAddress(prop_address);
}



function submitSearch(formName)
{
	//alert(formName+"test for search");
	//$("#inner_body_container").html('<img src="images/ajax.gif" border="0" alt="Loading...">');
	var data_str = jQuery("#"+formName).serialize();
	
	$.ajax({ 
		type: "POST", 
		url: "jxCommon.php", 
		data: data_str, 
		success: function(msg){ 
			//alert( "Data Saved: " + msg ); 
			
			$("#inner_body_container").html(msg);
			//$("#inner_body_container").focus();
			
		} 
	});
}


function send_emailNew(){
	var	frn_name =$("#frd_name").val();
	var	to_email =$("#to_email").val();
	var	from_email =$("#from_email").val();
	var	message =$("#message").val();
	var	curpage_url =$("#curpage_url").val();
	//alert(curpage_url); return false;

	$.ajax({
	   type: "POST",
	   url: "scripts/jxEmail_print.php",
	   data: "name="+frn_name+"&to_email="+to_email+"&from_email="+from_email+"&msg="+message+"&curpage_url="+curpage_url,
	   success: function(msg){
		$("#email_sendMailmsg").html(msg);
		//alert(msg);
		var msg_str = jQuery.trim(msg);

		if(msg_str!="Please fill all Required fileds")
		{
		document.getElementById('email_form').reset()
		setTimeout(function(){
						disablePopup('popupSend')	
						}, 5000);
		}
	
		
	  
	   }
	 });


	//ajaxcall(divname,strurl);
	//resetemailform();
}




function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }
