/*
*************************************************************************
*	Sample of Open Window 												*
*************************************************************************
function openADViewWindow(ad_id, width, height){
	if(ad_id!=0){
		var args = 'width='+(String)(parseFloat(width)+20)+',height='+(String)(parseFloat(height)+20)+',status=0,address=0,resize=0';
		var popwindow = window.open('index.php?view=ad_view&ad_id='+ad_id,'ad_stat', args);
		if(!popwindow){
			alert("Your POP UP Blocker blocking a new window\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
		}
	}else{
		alert('Invalid operation !!');
	}
}
*************************************************************************


*************************************************************************
*	Sample of Ajax Usage												*
*************************************************************************
function toggle_user_status(user_id, stat){
	if(user_id!=0 && (stat==0 || stat==1)){
		new ajax ('ajax.php', {postBody: 'method=toggle_user_status&user_id='+user_id+'&stat='+stat, onComplete: toggle_user_status_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}else{
		alert("Invalid operation. Please try later on !!");
	}
}

function toggle_user_status_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			alert("The users status has been changed successfully !!\n\nYou need to refresh this page to see the updated status");
			window.location.reload();
		}else{
			alert("We were not able to process your request\n\nPlease try later on");
		}
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}
*************************************************************************
*/

//All global variables
var map;
// end of variable declaration


function initialize() {

	  if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
		map.setUIToDefault();
		//map.setZoom(10);
		var uiOptions = map.getDefaultUI();
		uiOptions.zoom.scrollwheel = true;
		//uiOptions.controls.overviewmapcontrol = true;
		map.setUI(uiOptions);

		GEvent.addListener(map,"click", function (marker, latlong){
											if(marker){
												//alert("marker");
											}
									});
      }
	}

function loadMarker(category,id){

	var url = "index.php?view=functions&act="+category+"&property_id="+id;
	var bounds = new GLatLngBounds();

	new Ajax.Request(url,{
					 method:"post",
					 postBody:"",
					 onComplete:function(transport){

						 	//alert(transport.responseText);
							//return false;
							var data = transport.responseText.evalJSON();
							var latlng = new GLatLng(data.markerInfo.lat,data.markerInfo.lng);
							//alert(data.markerInfo.address);
							var icon = new GIcon(G_DEFAULT_ICON, "");
							var marker = new GMarker(latlng, {icon: icon});
							//marker.bindInfoWindowHtml("<table><tr><td><img src='"+data.markerInfo.propImage+"' width='75px' height='80px' /></td><td valign='top' style='padding:5px; font-family:Verdana, Geneva, sans-serif; font-size:12px'><strong>"+data.markerInfo.listType+"</strong><br><br>"+data.markerInfo.bedroom+" Beds | "+data.markerInfo.bathroom+" Baths<br>$"+data.markerInfo.listPrice+"<br>"+data.markerInfo.address+"</td></tr></table>");

							if((data.markerInfo.bedroom==0 || data.markerInfo.bedroom==null) || (data.markerInfo.bathroom==0 || data.markerInfo.bathroom==null)){

								marker.bindInfoWindowHtml("<table><tr><td><img src='"+data.markerInfo.propImage+"' width='75px' height='80px' /></td><td valign='top' style='padding:5px; font-family:Verdana, Geneva, sans-serif; font-size:12px'><strong>"+data.markerInfo.listType+"</strong><br><br>$"+data.markerInfo.listPrice+"<br>"+data.markerInfo.address+"</td></tr></table>");

							}else{

								marker.bindInfoWindowHtml("<table><tr><td><img src='"+data.markerInfo.propImage+"' width='75px' height='80px' /></td><td valign='top' style='padding:5px; font-family:Verdana, Geneva, sans-serif; font-size:12px'><strong>"+data.markerInfo.listType+"</strong><br><br>"+data.markerInfo.bedroom+" Beds | "+data.markerInfo.bathroom+" Baths<br>$"+data.markerInfo.listPrice+"<br>"+data.markerInfo.address+"</td></tr></table>");

							}

							bounds.extend(latlng);
							map.addOverlay(marker);

							map.setCenter(bounds.getCenter(),10);
	  						//map.setZoom(map.getBoundsZoomLevel(bounds));

						 }
					 });}

function showHide(result){


	if(result=="CI" || result=="LD" || result == "BU"){
		//alert($('bed').style.display);
		//alert(document.getElementById('bed').style.display);
		document.getElementById('bedText').style.display="none";
		document.getElementById('bedVal').style.display="none";
		document.getElementById('bathText').style.display="none";
		document.getElementById('bathVal').style.display="none";

	}else{
		document.getElementById('bedText').style.display="block";
		document.getElementById('bedVal').style.display="block";
		document.getElementById('bathText').style.display="block";
		document.getElementById('bathVal').style.display="block";
	}



}
function zipValid(){

	var valid = true;

	var Num = document.getElementById("snumber").value;
	var Name = document.getElementById("sname").value;
	var Zip = document.getElementById("zip").value;

	if(Zip!= "" && Name!= ""){
		valid = true;
		//alert(valid);

	}
	if(Zip!= "" && Num!= ""){
		valid = true;
		//alert(valid);

	}

	return valid;
}
function removeDuplicateElement(arrayName)
      {
        var newArray=new Array();
        label:for(var i=0; i<arrayName.length;i++ )
        {
          for(var j=0; j<newArray.length;j++ )
          {
            if(newArray[j]==arrayName[i])
            continue label;
          }
          newArray[newArray.length] = arrayName[i];
        }
        return newArray;
      }


Array.prototype.inArray = function (value,caseSensitive)
// Returns true if the passed value is found in the
// array. Returns false if it is not.
{
	var i;
	for (i=0; i < this.length; i++) {
	// use === to check for Matches. ie., identical (===),
		if(caseSensitive){ //performs match even the string is case sensitive
			if (this[i].toLowerCase() == value.toLowerCase()) {
				return true;
			}
		}else{
			if (this[i] == value) {
				return true;
			}
		}
	}
return false;
};

function check_captcha_value1(capch){
		//alert(captcha_value);
		//return false;
		//alert("js");
		//alert(hidden_value);
		//new Ajax.Request("
		new ajax("ajax.php",{postBody:'method=check_captcha&value='+capch, onComplete: check_captcha_bcc_valueCallBack});
		return false;
	}
function check_captcha_bcc_valueCallBack(request,uservar){
	//alert(request.responseText);
	//return false;
	if(request.responseText == "FAIL"){
	 //alert("test");
			alert('Captcha Code Does Not Match.')
		document.getElementById('captcha_value').focus();

	}else{
		document.getElementById('frm_registration').submit();
		return false;
	}
}
function check_captcha_value_broker(captcha_value){
		//alert(captcha_value);
		//return false;
		//alert("js");
		//alert(hidden_value);
		//new Ajax.Request("
		new ajax("ajax.php",{postBody:'method=check_captcha_broker&value='+captcha_value, onComplete: check_captcha_broker_valueCallBack});
		return false;
	}
function check_captcha_broker_valueCallBack(request,uservar){
	//alert(request.responseText);
	//return false;
	if(request.responseText == "FAIL"){
	 //alert("test");
			alert('Captcha Code Does Not Match.')
		document.getElementById('captcha_value').focus();

	}else{
		document.getElementById('frm_broker_registration').submit();
		return false;
	}
}

function check_captcha_testimonial(captcha_value){
		//alert(captcha_value);
		//return false;
		//alert("js");
		//alert(hidden_value);
		//new Ajax.Request("
		new ajax("ajax.php",{postBody:'method=check_captcha_test&value='+captcha_value, onComplete: check_captcha_test_valueCallBack});
		return false;
	}
function check_captcha_test_valueCallBack(request,uservar){
	//alert(request.responseText);
	//return false;
	if(request.responseText == "FAIL"){
	 //alert("test");
			alert('Captcha Code Does Not Match.')
		document.getElementById('captcha_value').focus();

	}else{
		document.getElementById('testimonial').submit();
		return false;
	}
}



function check_captcha_contact(captcha_value){
		new ajax("ajax.php",{postBody:'method=check_captcha_contact&value='+captcha_value, onComplete: check_captcha_contact_valueCallBack});
		return false;
	}
function check_captcha_contact_valueCallBack(request,uservar){
	if(request.responseText == "FAIL"){
			alert('Captcha Code Does Not Match.')
		document.getElementById('captcha_value').focus();
	}else{
		document.getElementById('contact_us').submit();
		return false;
	}
}

////function check_captcha_valuetest(captcha_value){
//		//alert(captcha_value);
//		//return false;
//		//alert("js");
//		//alert(hidden_value);
//		//new Ajax.Request("
//		//new ajax("ajax.php",{postBody:'method=check_captcha_test&value='+captcha_value, onComplete: check_captcha_test_valueCallBack});
//		/return false;
//	}
//
//function check_captcha_test_valueCallBack(request,uservar){
//
//	//alert(request.responseText);
//     if(request.responseText == "FAIL"){
//	 //alert("test");
//			alert('Captcha Code Does Not Match.')
//		document.getElementById('captcha_value').focus();
//
//	}else{
//		//ocument.getElementById('frm_testimonial1').submit();
//		document.frm.submit();
//
//		return false;
//	}
//}

function Add_to_favorate(status,id){

	//document.getElementById("tel1").style.display = "block";
	   document.getElementById('fav_msg').innerHTML = "<img src='images/ajax-loading.gif' width='15' >";
	new ajax("ajax.php",{postBody:'method=add_to_favorate&id='+id+'&status='+status, onComplete: add_to_favorateCallBack});
  	return false;
}

 function add_to_favorateCallBack(request,uservar){
	 var result;
	 result = request.responseText;
	/* alert(result);
	 return false;*/

	  if(result=="INSERT"){
			document.getElementById('fav_msg').innerHTML = "Remove from my favorite";

		}
		else if(result=="DELETE"){
			document.getElementById('fav_msg').innerHTML = "Add to my favorite";
        }else{
			alert("please try again.")
			document.getElementById('fav_msg').innerHTML = "";
		}
}


function Remove_favorite(id){
	   // alert(id);return false;
	new ajax("ajax.php",{postBody:'method=remove_from_favorate&id='+id, onComplete: remove_from_favorateCallBack});
  	return false;
}

 function remove_from_favorateCallBack(request,uservar){
          if(request.responseText == "FAIL"){
          	//alert('Captcha Code Does Not Match.')
          	document.getElementById('fail_remove').style.display="";
			//document.getElementById('fail1').style.display="";
          }else if(request.responseText == "OK"){
			 // document.getElementById('property_display').load();
			  //document.getElementById("tel2").style.display = "block";
          	document.getElementById('success_remove').style.display="";
			//document.getElementById('success1').style.display="";

          	//return false;
          }else if(request.responseText == "not"){
          	document.getElementById('note').style.display="";
          	//return false;
          }
}

 function toggle_faq(elemId){
 var a = document.getElementById(elemId);
 //get all the divs inside the topHeadContentWrap div (I gave it an id, it did not have one before)
 var b = document.getElementById("faqs").getElementsByTagName('div');
 //loop through all the divs in the topHeadContentWrap id'd div
 for (var i = 0; i < b.length; i++) {
  //if they don't have an identical id to the div we want to show, hide them. The && b[i].id != elemId allows to toggle the div later
  if (b[i].className === "sub_list_show" && b[i].id != elemId) {
   b[i].className = "sub_list_hide";
  }
 }
 //toggle the div we are showing - if it is already shown, successive clicks will hide or show it
 a.className = (a.className === "sub_list_show")?"sub_list_hide":"sub_list_show";
}


 function toggle_brokerconfig(elemId){
 var a = document.getElementById(elemId);
 //get all the divs inside the topHeadContentWrap div (I gave it an id, it did not have one before)
 var b = document.getElementById("faqs").getElementsByTagName('div');
 //loop through all the divs in the topHeadContentWrap id'd div
 for (var i = 0; i < b.length; i++) {
  //if they don't have an identical id to the div we want to show, hide them. The && b[i].id != elemId allows to toggle the div later
  if (b[i].className === "sub_list_show1" && b[i].id != elemId) {
   b[i].className = "sub_list_hide";
  }
 }
 //toggle the div we are showing - if it is already shown, successive clicks will hide or show it
 a.className = (a.className === "sub_list_show1")?"sub_list_hide":"sub_list_show1";
}



