var load_image = "<div style=margin-top:148px;><img src='" + this_domain + "/images/common/loading1.gif' align=middle/></div>";
var load_image_small = "<div style=margin-top:25px;><img src='" + this_domain + "/images/common/loading1.gif' align=middle/></div>";
var load_img = "<img style='position:relative; top:4px;' src='" + this_domain + "/images/common/loading1.gif' align=middle/>";
var version = navigator.userAgent;
var findIE6 = version.indexOf('MSIE 6');

function changeViewTab(selectedTab,loadPage,select_tab)
{
	selector = I("this_selector").value;
	I("secondTabContent").innerHTML = load_image;
	$(".view_tabs_selected").removeClass().addClass("view_tabs");
	I(selectedTab).className = "";
	I(selectedTab).className = "view_tabs_selected";
	page_link = this_domain + "/body/view/cached_"+loadPage+".php";
	if(loadPage == "view_contact" || loadPage == "view_documents" || loadPage == "view_clients_details")
		page_link = this_domain + "/body/view/"+loadPage+".php";
		
	if(select_tab)
	{
		page_link = page_link + "?tab=" + select_tab;
	}
	$.get(page_link , {selector:selector,ptype:"ajax"},
	function(str)
	{
		I("secondTabContent").innerHTML = str;
		if(loadPage == "property_description")
		{
			if(I("listing_images_slider") != null)
			I("listing_images_slider").style.display = "block";
			$("#listing_images_slider").jCarouselLite({
				  btnNext: "#next_listing_images",
				  btnPrev: "#prev_listing_images",
				  visible:1,
				  circular:true,
				  speed:800
			});
			lat = I("lat_start").value;lon = I("lng_start").value;
			if(function_exists("init"))
				init("",lat,lon,11,"view_small","","","","","","property_description_gmap");
			$("#property_description_gmap div").css({cursor:"pointer"});	
		}
		if(loadPage == "property_description" || loadPage == "edgallery_Gallery")
		{
			$.ImageBox.init(
			{
				loaderSRC: this_domain + '/images/common/loading.gif',
				closeHTML: "<img src=\""+this_domain+"/images/common/mailbox_del_hover.gif\" border=\"0\" />"
			}); 	
		}
		if(select_tab)
		{
			switch_contact_forms(select_tab);
		}
		
	});
	return false;
}

$("#mail_friend").cluetip(
{
	local:false,
	activation:'click',
	sticky:true,
	width:'400px',
	height:'360px',
	positionBy:'mouse',
	attribute: 'name',
	closePosition: 'title',
	closeText:'<img src="'+this_domain+'/images/common/cross.jpg" />'
});
  
function form_submit()
{
	
	var new_div_top = $("#send_btn").offset().top +10;
	var new_div_left = $("#send_btn").offset().left +20;
	$("#mail_send_res").css({'display':'block','position':'absolute','top':new_div_top,'left':new_div_left,'border':'1px solid','background':'#DCDCDC','z-index':'1000','width':'200px'});
	
	var mailTo = $("#mail_to").val();	
	var mailFrom =  $("#mail_from").val();
	var mailSub =  $("#mail_subject").val();
	var mailMsg =  $("#mail_msg").val();
	$("#mail_send_res").html('');
	if((mailTo!='') && (mailMsg!=''))
	{	
		$("#mail_frm").ajaxSubmit(function(str)
		 { 
			$("#mail_send_res").html(str);
		});
		$("#mail_to").val("");
		$("#mail_from").val("");
		$("#mail_subject").val("");
		$("#mail_msg").val("");
	}
	else
	{
		$("#mail_frm").ajaxSubmit(function(str)
		 { 
			$("#mail_send_res").html(str);
		});
	}	
}

function show_pricedown(txt,title)
{
return overlib(txt,STICKY,CLOSECLICK,CAPTION, title,WIDTH,500,OFFSETX,-400,OFFSETY,-100,VAUTO,HAUTO);
}
  
  
function contact_form_submit()
{
	var new_div_top = $("#send_mail_link").offset().top -10;
	var new_div_left = $("#send_mail_link").offset().left +50;
	$("#send_mail_waiting").html("<span style='margin-left:10px;'>" + load_img + " &nbsp;Submitting</div>");
	$("#send_mail_link").css({"display":"none"});
	
	$("#frm_mail_contact").ajaxSubmit(function(str)
	{ 
			$("#send_mail_waiting").html("");
			$("#send_mail_link").css({"display":"inline"});
			jobj = eval(str);
			overlib(jobj[0]["obtext"],CAPTION,"Status",STICKY,CLOSECLICK,WIDTH,400,OFFSETX,-140,OFFSETY,-200);
			I("div_display_message").style.width = "auto";
			I("div_display_message").style.margin = "0px";
			I("div_display_message").style.height = "220px";
			I("errDiv").style.fontWeight = "normal";
			if(jobj[0]["status"] == "success")
			{
				image = jobj[0]["image"];
				I("mail_from").value = "";
				I("mail_tel").value = "";
				I("mail_name").value = "";
				I("security").value = "";
				$(".ques_text").val("");
				$(".ques_detail").val("");
				$(".prop_amount").val("");
				$(".mail_msg").val("");
				$("#accept_chkbox").attr('checked', false);
				if(image != "")
				{
					I("lb_capimage").innerHTML = image;
				}
			}
	});  
} 

$("#contact_mail_closePopup").livequery(function()
{
	$(this).click(function()
	{
		var entered_sec_code = $("#security").val();
		var original_sec_code = $("#security_code").val()
		if(entered_sec_code == original_sec_code)
			var matched = 1;
		else
			var matched = 2;
		
		if($("#mail_from").val()!='' && $("#mail_tel").val()!='' && $("#mail_name").val()!='' && $("#security").val()!='' && matched==1 && $("#accept_chkbox").is(":checked")=='true')
		{
			$("#mail_from").val('');
			$("#mail_tel").val('');
			$("#mail_name").val('');
			$("#security").val('');
			$("#accept_chkbox").val('');
		}
		else
		if(matched!=1)
		{
			$("#security").val('');
		}
		$("#mail_send_contact").css({'display':'none'});
	});
});


$(".view_nb_caption_unselected a").livequery("click",function()
{
	$(".view_nb_caption span").removeClass();
	$(".view_nb_caption span").addClass("view_nb_caption_unselected"); 
	$(this).parent().parent().removeClass();	
	$(this).parent().parent().addClass("view_nb_caption_selected"); 

});

function show_breakdown(div_id,positionby,defualt_display)
{
	var div_display = I(div_id).style.display;
	if(typeof defualt_display !== "undefined")
	{
		div_display = defualt_display;	
	}
	div = I('backgroundFilter');
	if(div_display == "none")
	{
		winH = I("footer").offsetTop;
		div.style.height = winH + "px";
		div.style.display = 'block'; 
		
		positionp = typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
		positionp = positionp + 15;
		leftp =  window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
		if(findIE6 != -1)
		{	
			I("menu4iframe").style.display = "block";
			I("menu4iframe").style.height = "100%";
		}
		
		leftp = leftp/4;
		if(div_id == "areadown_main")
		{
			positionp = positionp + 30;
		}
		I(div_id).style.display = "block";
		I(div_id).style.top = positionp + "px";
		I(div_id).style.left = leftp + "px";
	}
	else
	{
		I(div_id).style.display = "none";
		div.style.height = "0px";
		div.style.display = "none";
		if(div_id == "pricedown_main")
		{
			var fprice = I("tsale_price").innerHTML;
			fprice = $.trim(fprice);
			//fprice = fprice.replace(",","");
			 f_array = fprice.split(",");
			 var fprice_len = f_array.length;
			 fprice = "";
			 for(i=0;i<fprice_len;i++)
			 {
				 fprice += f_array[i]; 
			 }
			$("#prices").val(fprice);
			
			$("#stext").html(getPriceText(fprice));
			//toggle_pricediv("else");
		}
	}
}

function toggle_pricediv(a_id)
{
	if(a_id == "clue_installment")
	{
		I("price_breakdown").style.display = "none";
		I("div_install_info").style.display = "block";
		I("clue_installment").className = "selected";
		I("clue_price").className = "";
	}
	else
	{
		I("div_install_info").style.display = "none";
		I("price_breakdown").style.display = "block";
		I("clue_price").className = "selected";
		I("clue_installment").className = "";
	}
	return false;
}

$(document).ready(function()
{
	$.ImageBox.init(
	{
		loaderSRC: this_domain + '/images/common/loading.gif',
		closeHTML: "<img src=\""+this_domain+"/images/common/mailbox_del_hover.gif\" border=\"0\" />"
	});  
});

function autofill_propertyemail()
{
	I("mail_name").value = I("h_name").value;
	I("mail_from").value = I("h_email").value;
	I("mail_tel").value = I("h_tel").value;
	if(I("mail_msg").innerHTML == "")
		I("mail_msg").innerHTML = I("h_desc").value;
}

$("form .prop_amount").livequery("blur",function(){
	var def_text = $("form .prop_amount_default_txt").val();
	var el = $(this);
	var curr_text = el.val();
	if( curr_text == "" )
	{
		el.css({"color":"#999999"});
		el.val(def_text);
	}
});

/* $("form .prop_amount").livequery("click",function(event){
	var def_text = $("form .prop_amount_default_txt").val();
	var el = $(this);
	var curr_text = el.val();
	if(def_text == curr_text)
	{
		el.css({"color":"#000000"});
		el.val("");
	}
});
 */
$("form .prop_amount").livequery("focus",function(event){
	var def_text = $("form .prop_amount_default_txt").val();
	var el = $(this);
	var curr_text = el.val();
	if(def_text == curr_text)
	{
		el.css({"color":"#000000"});
		el.val("");
	}
});