
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var gleft = 0;
var gtop = 0;
var gstr = 'xxx';
var gid =0 ;

function getposOffset(overlay, offsettype)
{
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
function showhide(obj, e, visible, hidden, menuwidth)
{
	if (ie4||ns6)
	dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!="")
	{
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	obj.visibility=visible
	else if (e.type=="click")
	obj.visibility=hidden
}

var sftObj = "superArea";

function overlay(curobj, subobjstr, opt_position, isdivfordisplay)
{

	if (document.getElementById)
	{
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		
		sftObj = curobj.id;

		if(isdivfordisplay)
		{
			var divfordisplay = document.getElementById('divfordisplay');
			var divTopPos = divfordisplay.style.top;

			if( divTopPos == '290px' )	// for no cluster
			{
				if(screen.width == "800")
				ypos = ypos - 285;
				else
				ypos = ypos - 290;

			}
			else if( (divTopPos == '422px') || (divTopPos == '410px'))	// less cluster
			{
				if(screen.width == "800")
				ypos = ypos - 418;
				else
				ypos = ypos - 410;

			}
			else if( (divTopPos == '475px') || (divTopPos == '488px') )	// for more cluster
			{
				if(screen.width == "800")
				ypos = ypos - 482;
				else
				ypos = ypos - 475;

			}
			else if( (divTopPos == '310px'))	// for Browse Property Section
			{
				if(screen.width == "800")
				ypos = ypos - 305;
				else
				ypos = ypos - 310;

			}

			if(gstr != isdivfordisplay)
			{
				gleft = 0;
				gtop = 0;
			}
			gstr = isdivfordisplay;
			gid = isdivfordisplay;

			if(gleft == 0 && gtop == 0)
			{

			}
			else
			{

				xpos = gleft;
				ypos = gtop;
			}

			subobj.style.left="150px"
			gleft = xpos;
			gtop = ypos;

		}
		else
		{
			subobj.style.left=xpos+"px"
		}
		subobj.style.top=ypos+"px"
		return false
	}
	else
	return true
}

function overlayclose(subobj)
{
	document.getElementById(subobj).style.display="none"
}

function MM_openBrWindow(theURL,winName,features) //v2.0
{
	window.open(theURL,winName,features);
}
/* Javascript functions for images on subheader and their mouseover effects....
Added by Sumit on 13 Aug 2005                                        */

function MM_preloadImages() { //v3.0
	//Function Call added to check whether Residential or Commercial cookie is set
	cookie_start();
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*
name - cookie name
value - cookie value
[expires] - expiry date of the cookie
(defaults to end of current session)
[path] - path for which the cookie is valid
(defaults to path of calling document)
[domain] - domain for which the cookie is valid
(defaults to domain of calling document)
[secure] - Boolean value indicating if the cookie transmission requires a secure transmission
* an argument defaults when it is assigned null as a placeholder
* a null placeholder is not required for trailing omitted arguments
*/

function setCookie_exp(name, value, expires, path, domain, secure) {

	var curCookie = name + "=" + escape(value) +((expires) ? "; expires=" + expires.toGMTString() : "") +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
function setCookie()
{
	if(document.browse_property.Mode[0].checked)
	var value='S';
	else
	var value='R';

	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	setCookie_exp('deal_mode', value, now,'/')
	return true;
}
/*
name - name of the desired cookie
return string containing value of specified cookie or null
if cookie does not exist
*/
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
/*
name - name of the cookie
[path] - path of the cookie (must be same as path used to create cookie)
[domain] - domain of the cookie (must be same as domain used to
create cookie)
path and domain default if assigned null or omitted if no explicit
argument proceeds
*/

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
function cookie_start()
{
	var now = new Date();
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	current = getCookie('RES_COM');
	if(current == 'RES')
	{
		if(document.search_form)
		{
			if(document.search_form.type)
			document.search_form.type.options[0].value = 'R';
			if(document.search_form.Mode.options)
			document.search_form.Mode.options[1].text = 'Rent';
		}
		setStyleByClass('*','formcomm','background-color','#000000','formres');
	}
	else if(current == 'COM')
	{
		if(document.search_form)
		{
			if(document.search_form.Mode.options)
			document.search_form.Mode.options[1].text = 'Lease';
			if(document.search_form.type)
			document.search_form.type.options[0].value = 'C';
		}
		setStyleByClass('*','formres','background-color','#000000','formcomm');
	}
	else
	setCookie_exp('RES_COM','RES',now,'/')
}
function toggleCookie(arg)
{
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	setCookie_exp('RES_COM', arg, now,'/')

}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - old class name
//  p - CSS property
//  v - value
//  w - new class name
function setStyleByClass(t,c,p,v,w)
{
	var ie = (document.all) ? true : false;
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	if(w == 'formres')
	{
		setCookie_exp('RES_COM', 'RES', now,'/')
		/*if(document.getElementById("bedroomtag"))
		document.getElementById("bedroomtag").style.visibility="visible";*/
	}
	else
	{
		setCookie_exp('RES_COM', 'COM', now,'/');
		/*if(document.getElementById("bedroomtag"))
		document.getElementById("bedroomtag").style.visibility="hidden";*/
	}
}
function changetype(type,check)
{
	var restype = new Array(),comtype= new Array(),rescount=0,comcount=0;
	var cookiecol = getCookie('RES_COM');
	var flag = 0;
	if(document.search_form)
	var typedd = document.search_form.type;
	switch(type)
	{
		case 'com':
		if(check == 1)
		return;
		if(cookiecol == 'COM')
		return;
		break;
		case 'res':
		if(check == 1)
		break;
		if(cookiecol == 'RES')
		return;
		break;
	}
	if(typedd)
	{

		switch(cookiecol)
		{
			case 'RES':
			var diff = 'C';
			break;
			case 'COM':
			var diff = 'R';
			break;
		}
		if(check == 1)
		var diff='C';
		for(var i=0;i<typedd.options.length-1;i++)
		{
			if(typedd.options[i].value == 'L')
			break;
			if(typedd.options[i].value == diff)
			flag = 1
			switch(flag)
			{
				case 0:
				restype[rescount++] = typedd.options[i];
				break;
				case 1:
				comtype[comcount++] = typedd.options[i];
				break;
			}
		}
		var a=0,b=0;
		var total = typedd.options.length;
		for(var i=0;i<total-1;i++)
		{
			if(typedd.options[i].value == 'L')
			break;
			if(i < comcount)
			{
				typedd.options[i] = new Option(comtype[a++].text);
				typedd.options[i].value = comtype[a-1].value;
				typedd.options[i].selected = comtype[a-1].selected;
			}
			if(i >= comcount)
			{
				typedd.options[i] = new Option(restype[b++].text);
				typedd.options[i].value = restype[b-1].value;
				typedd.options[i].selected = restype[b-1].selected;
			}
			if(typedd.options[i].value == 'L' || typedd.options[i].value == 'R' || typedd.options[i].value== 'C')
			typedd.options[i].className = 'boldclass';

		}
		if(check != 1)
		typedd.options[0].selected = true;
	}
}
function change_images(){}
function onmousechangesrc(){}
function overmousechangesrc(){}
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
	date.setTime(date.getTime() - skew);
}
/*3 Functions copied from propadmin.js for reloading parent*/
function reloadParent()
{
	var func = "Reload()";
	window.opener.Timer(func);
}
function Timer(func)
{
	setTimeout(func,1000);
}
function Reload()
{
	window.location.href = window.location.href;
}
function replaceAll( str, from, to )
{
	var idx = str.indexOf( from );
	while ( idx > -1 )
	{
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}
	return str;
}
//Function for appending cat_code....
function change_value(new_code)
{
	docF= window.opener.document.form1;
	docF.cat_code.value= docF.cat_code.value+','+new_code;
	prop_id=docF.PROP_ID.value;
	str= window.opener.location.href;
	end= str.indexOf('&from');
	if(end == -1)
	original_href=str;
	else
	original_href=str.substr(0,end-1);
	window.opener.location.href= original_href+'&from=popup&PROP_ID='+prop_id+'&cat_code='+docF.cat_code.value;
	this.close();
}
/*
Function to open a given script in a new window
saurabh:edited to open custom sized window for clicks from quick search page
flag:'QS'	Clicks from quick search page
flag:
to add custom sizes for popup window from different pages add TAG and description here
*/
function open_new_window(path,flag)
{
	if(!flag)
	{
		window.open(path,'','width=800,height=570,scrollbars=yes,resizable=1');
		return false;
	}
	else if(flag=='QS')	//to open window from quick search page
	{
		if((screen.width <= 800) && (screen.height <= 600))
		{
			window.open(path,'','width=784,height=543,scrollbars=1,resizable=1');
		}
		else
		{
			window.open(path,'','width=958,height=702,scrollbars=1,resizable=1');
		}
		return false;
	}
	else if(flag=='LAD')	//to open window for LAD
	{
		if((screen.width <= 800) && (screen.height <= 600))
		{
			window.open(path,'','width=790,height=426,scrollbars=1,resizable=1,location=1,toolbar=1,menubar=1');
		}
		else
		{
			window.open(path,'','width=958,height=592,scrollbars=1,resizable=1,location=1,toolbar=1,menubar=1');
		}
		return false;
	}
	else if(flag=='DP')	//to open window for LAD
	{
		if((screen.width <= 800) && (screen.height <= 600))
		{
			window.open(path,'','width=790,height=570,scrollbars=1,resizable=1');
		}
		else
		{
			window.open(path,'','width=958,height=702,scrollbars=1,resizable=1');
		}
		return false;
	}else if(flag=='FullWindow')
	{
		if((screen.width <= 800) && (screen.height <= 600))
		{
			window.open(path,'','width=800,height=600,scrollbars=1,resizable=1');
		}
		else
		{
			window.open(path,'','width=1024,height=768,scrollbars=1,resizable=1');
		}
		return false;
	}

}


/** Functions for change city dropdown in subheader **/

function show(va_l) {
	var coors = findPosit(va_l);
	d_n=document.getElementById("dropmenudiv").style;
	d_n.top=coors[1]+coors[3]+5 +'px';
	d_n.left=coors[0] +'px';
	d_n.display="";
	var value_=false;
	d_i=document.getElementById("iframeshim");
	d_i.style.top=d_n.top;
	d_i.style.left=d_n.left;
	d_i.style.width=d_n.width;
	d_i.style.height=d_n.height;
	d_i.style.display="";
	document.getElementById("dropmenudiv").onmouseover=function() {
		d_n.display="";
		d_i.style.display="";
		value_=true;
		clearTimeout(a)
	}
	document.getElementById("dropmenudiv").onmouseout=function() {
		d_n.display="none";
		d_i.style.display="none"
	}
	a=setTimeout("chk("+value_+")",2000)
}

function findPosit(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		curW = obj.offsetWidth
		curH = obj.offsetHeight
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop,curW,curH];
}

function chk(value_) {
	if(value_==false) {
		d_n.display="none";
		d_i.style.display="none"
	} else {
		d_n.display=""
	}
}
/** Functions for change city dropdown in subheader END**/


/*
Moved from homepage.js
Function name   :       setTypevalue
Created by      :       Gunjan Kathuria
Date            :       19 Dec 2006
Description     :       This function sets the cookie and reloads the page when a property type is selected from select and cookie RES_COM is not of Property Type
*/
function setTypevalue()
{
	var type_search=document.search_form.type.value;
	resarray= new Array('R','1','2','3','4','5','22','23','80');
	comarray= new Array('C','26','6','7','9','10','11','12','13','14','15','16','17','18','19','20','21','81');
	var x = getCookie("RES_COM")
	if(x=='COM')
	for(var i=0;i<resarray.length;i++)
	if(resarray[i]==type_search)
	{
		setCookie_exp('getType',type_search);
		location.href="/Residential";
	}
	if(x=='RES')
	for(var i=0;i<comarray.length;i++)
	if(comarray[i]==type_search)
	{
		setCookie_exp("getType",type_search);
		location.href="/Commercial";
	}
}
function fillSelectFromArray_alert(sel)
{
 	if(document.form1.preference)
	{	
		var selectCtrl=document.form1.Budget;
		if(document.form1.preference[1].checked)
		{
			var itemArray=team[1];
		}
		else
		{	
			var itemArray=team[0];
		}
		var i, j;
		var prompt;
		// empty existing items
		if(selectCtrl!="")
		for (i = selectCtrl.options.length-1; i >= 0; i--)
		{
			selectCtrl.options[i] = null;
		}
		goodPrompt="Budget";
		badPrompt="Budget";
		prompt = (itemArray != null) ? goodPrompt : badPrompt;
		if (prompt == null) 
		{
			j = 0;
		}	
		else 
		{
			if(selectCtrl!="")
			{
				selectCtrl.options[0] = new Option(prompt);
				selectCtrl.options[0].value="0";
			}
			j = 1;
		}
		if (itemArray != null) 
		{
			// add new items
			for (i = 0; i < itemArray.length; i++) 
			{
				selectCtrl.options[j] = new Option(itemArray[i][0]);
				if (itemArray[i][1] != null) 
				{
					selectCtrl.options[j].value = itemArray[i][1];
					if (sel == itemArray[i][1])
					{
						selectCtrl.options[j].selected = true;
					}
				}
				j++;
			}
			// select first item (prompt) for sub list
			if(sel == null)
			selectCtrl.options[0].selected = true;
		}
	}	
}
function resizeHeight(the_iframe)
{
  document.getElementById(the_iframe).height=document.getElementById(the_iframe).contentWindow.document.body.scrollHeight;
}

