/** 
 * @fileoverview This javascript file contains the common functions. 
 * @author Hardik Shah
 * @author Pankit Bhanushali
 * @version 0.1 
 */
var goToMap = false;
var imgThmPath = "../../wt/"+bkTheme+"/images/";
var isIE = document.all?1:0;
var isIE6 = (window.XMLHttpRequest)?0:1;
var usrAgt = navigator.userAgent.toLowerCase();
var isFF = (usrAgt.indexOf('firefox')!=-1)?1:0;
var isOpera = (usrAgt.indexOf('opera')!=-1)?1:0;
var isSafari = ((usrAgt.indexOf('safari')!=-1)&&(usrAgt.indexOf('mac')!=-1))?1:0;
//enables background image cache for internet explorer 6
if (isIE6) try {document.execCommand("BackgroundImageCache", false, true);} catch(e){};
// Global Variables
//var leadEmailDlg1;
var maindivid	= 'middle';
var url			= '';
var queryString	= '';
var lastToggled	;
var sessid	= '';
var YAHOO;
var jsPath = '../../';
var totalImgs;
var latLong = (getCookie("latLongCk")!=null)?(eval(getCookie("latLongCk"))[0]):null;
var isCountySearchEnabled = "0";
//lmsre specific
var lmsreDshbrdBitz= '{"mortgagerates" : "50","mcalc":"24","equity":"57","weather":"19","climate":"19","demographics" : "28","localnews" : "20","marketsnapshot":"46","crimestats":"49","valuehome":"58","afford":"51","localSearch":"39","crimestats":"49"}';
//var leadEmailDlg1;
/*metrospecific*/
var agtOffDlgBox = "";
//----------
/**
 * set new session id
 *
 */
function setSessid()
{
	var queryString  = "PHPSESSID="+sessid;
	var url = jsPath+"../classes/sessionSwitch.php";
	ajaxRequest(url,queryString,setID);
};

function setID(originalRequest)
{
	sessid = originalRequest.responseText;
};
function pageReload(originalRequest)
{
	if(originalRequest==null)originalRequest="";
	window.location.href = window.location.pathname+window.location.search;
};
/**
 * This is the Ajax function that requests the url and loads the HT response to particular Div/container
 * @param {String} url The url called by the Ajax request
 * @param {String} queryString The parameter String passed to the url 
 * @param {String} inDiv The Div/Container in which the response to be set
 * @param {String} callbackfn The callback function name
 */
 
function loadToDiv(url,queryString,inDiv,callbackfn,classNm)
{

	if(classNm==null)
		classNm = false;
		
	inDiv = typeof(inDiv) != 'undefined' ? inDiv : maindivid; 
	if(queryString=='')
	{
		queryString = "PHPSESSID="+sessid;
	}
	else
	{
		queryString = "PHPSESSID="+sessid+"&"+queryString;
	}
	/*
	var callbackfn = function(myAjaxObjext)
	{
		alert(inDiv+" :: "+$(inDiv)+" :: "+$(inDiv).innerHTML);
		alert(myAjaxObjext.responseText);
	}
	*/ 
	if(callbackfn==null)
	{
		var objAjax = new Ajax.Updater({success: inDiv},url, {method: 'post', parameters: queryString, onFailure: showError,onlyLatestOfClass:classNm,evalScripts: true});
	}
	else
	{
		var objAjax = new Ajax.Updater({success: inDiv},url, {method: 'post', parameters: queryString, onFailure: showError,onlyLatestOfClass:classNm,onSuccess: callbackfn, evalScripts: true});
	}
};

/**
 * This is the Ajax function that request the particular url 
 * @param {String} url The url called by the Ajax request
 * @param {String} queryString The parameter String passed to the url 
 * @param {String} callbackfn The callback function name
 * @param {boolean} requestType The type of the request to be made should synchronous or asynchronous(default)
 */
 
function ajaxRequest(url,queryString,callbackfn,requestType,classNm)
{

	if(classNm==null)
		classNm = false;
		
	if(requestType==null)
	{
		requestType=true;
	}

	if(queryString=='')
	{
		queryString = "PHPSESSID="+sessid;
	}
	else
	{
		queryString = "PHPSESSID="+sessid+"&"+queryString;
	}
	if(typeof(callbackfn) == 'undefined')
	{
		var objAjaxReq = new Ajax.Request(url, {method: 'post',asynchronous:requestType, parameters: queryString, onlyLatestOfClass:classNm, onFailure: showError, evalScripts: true});
	}
	else
	{
		var objAjaxReq = new Ajax.Request(url, {method: 'post',asynchronous:requestType, parameters: queryString, onlyLatestOfClass:classNm, onFailure: showError, onSuccess: callbackfn, evalScripts: true});
	}
};

/**
 * Display the Error message when the Ajax request fails 
 * @param {String} originalRequest the request object
 */
function showError(originalRequest)
{
	if (originalRequest.status == 999)
	{
		window.location.href = "../auth/sessionExpire.php";
	}
	else
	{
		var response = originalRequest.responseText;
		$(maindivid).innerHTML = response;
		alert(response);
	}
};


/***********************General Section********************/

/**
 * Includes the single javaScript file dynamically
 * @param {String} jsFile the javscript filename
 */

function includeJS(jsFile)
{
	
	var fileName = jsFile.substr(eval(jsFile.lastIndexOf('/')+1),eval(jsFile.lastIndexOf('\.')-eval(jsFile.lastIndexOf('/')+1)));
	var myScript = $(fileName+"Script");
	if(myScript==null)
	{
		var myScr = document.createElement('script');
		myScr.id= fileName+"Script";
		myScr.src = jsFile;
		document.getElementsByTagName('head')[0].appendChild(myScr);
	}
};
/**
 * Includes the single css file dynamically
 * @param {String} cssFile the css filename
 */

function includeCSS(cssFile)
{
	var fileName = cssFile.substr(eval(cssFile.lastIndexOf('/')+1),eval(cssFile.lastIndexOf('\.')-eval(cssFile.lastIndexOf('/')+1)));
	var myStyle = $(fileName+"Css");
	
	if(myStyle==null)
	{
		var myCss = document.createElement('link');
		myCss.id= fileName+"Css";
		myCss.href = cssFile;
		myCss.rel = "stylesheet";
		myCss.type = "text/css";
		document.getElementsByTagName('head')[0].appendChild(myCss);
	}
};
/**
 * Includes the multiple css files dynamically
 * @param {Array} cssFileArr the array of css filenames
 */
function includeMultiCSS(cssFileArr)
{
	var insrtCssFileArr = $A(cssFileArr);
	insrtCssFileArr.each(function(node) {
		includeCSS(node);
	});
};

/**
 * Function for flipping images on mouse over
 * (Normal images should be with suffix '_n' and hoverimages should be with suffix '_h')
 * @requires changeImgOnHover The changeImgOnHover function
 */

function revealThumbnail()
{
	imgsrc = this.src;
	newimgsrc=(imgsrc.replace("_n","_h"));
	this.src=newimgsrc;
};

/**
 * Function for flipping images on mouse out
 * (Normal images should be with suffix '_n' and hoverimages should be with suffix '_h')
 * @requires changeImgOnHover The changeImgOnHover function
 */	
function hideThumbnail()
{
	imgsrc = this.src;
	newimgsrc=(imgsrc.replace("_h","_n"));
	this.src=newimgsrc;
};
/**
 * Function for Toggle Divs using Effect for showing details
 * @param {id} id current Div id to be opened
 */
var sameFlag = false;
function menuToggle(id)
{
    if (lastToggled == null || $(lastToggled) == null) 
	{
		//Effect.toggle(id,'blind',{duration:0.2});
		lastToggled = id;
		//Element.Toggle(id);
		$(id).style.display = "block";
    }
    else if (lastToggled == id) 
	{     		       
		//Effect.toggle(id,'blind',{duration:0.2});	
		//Element.Toggle(id);
		if(sameFlag==false)
		{
			$(id).style.display = "none";
			sameFlag = true;
		}
		else
		{
			$(id).style.display = "block";
			sameFlag = false;
		}
    }  
    else
	{
	   $(lastToggled).style.display = "none";
       lastToggled = id;
       $(id).style.display = "block";
    }
    
};


/**
 * InPlace Editor function for Textbox
 * @param {TextBox Id} elementId The current element ID
 * @param {Button Id}  edtBtn The button id
 * @param {fileToCommunicate} The file that is call on click of edit button
 */
function createInplaceEditorText(elementId,fileToCommunicate,fieldName,tableName,condition,edtBtn,validation,size)
{
	
	if(elementId==null || fileToCommunicate == null || fieldName==null || tableName == null || condition == null)
	{
		alert("Parameters missing: elementId, fileToCommunicate, fieldName, tableName, and condition are mendatory");	
	}
	else
	{
		
		if(validation==null){validation="";}
		
		if(edtBtn==null){edtBtn="";}
		
		if(size==null)
			var inplaceEditorTxt =new Ajax.InPlaceEditor(elementId, fileToCommunicate,{ clickToEditText : "You can Edit this by clicking on it.", callback: function(form, value) { return 'value=' + escape(value)+'&fieldName='+escape(fieldName)+'&tableName='+escape(tableName)+'&condition='+escape(condition) },validate:validation,externalControl:edtBtn,highlightcolor:'#74AACF'});
		else
			var inplaceEditorTxt =new Ajax.InPlaceEditor(elementId, fileToCommunicate,{ clickToEditText : "You can Edit this by clicking on it.", size:size, callback: function(form, value) { return 'value=' + escape(value)+'&fieldName='+escape(fieldName)+'&tableName='+escape(tableName)+'&condition='+escape(condition) },validate:validation,externalControl:edtBtn,highlightcolor:'#74AACF'});
	
		return inplaceEditorTxt;
	}
};

/**
 * InPlace Editor function for TextArea
 * @param {TextArea Id} elementId The current element ID
 * @param {Button Id}  edtBtn The button id
 * @param {fileToCommunicate} The file that is call on click of edit button
 */
function createInplaceEditorTextArea(elementId,fileToCommunicate,fieldName,tableName,condition,edtBtn)
{
	if(elementId==null || fileToCommunicate == null || fieldName==null || tableName == null || condition == null)
	{
		alert("Parameters missing: elementId, fileToCommunicate, fieldName, tableName, and condition are mendatory");	
	}
	else
	{
		if(Ajax.InPlaceEditor == null)
		{
			alert("Please include Scriptaculous.js from vendor folder for using inplace Editor");
		}
		else
		{
			if(edtBtn==null){edtBtn="";}
			var inplaceEditorTA = new Ajax.InPlaceEditor(elementId, fileToCommunicate, { clickToEditText : "You can Edit this by clicking on it.", callback: function(form, value) { return 'value=' + escape(value)+'&fieldName='+escape(fieldName)+'&tableName='+escape(tableName)+'&condition='+escape(condition) },externalControl:edtBtn,rows:4,cols:60,highlightcolor:'#74AACF'});
			return inplaceEditorTA;
		}
	}
};

/**
 * InPlace Editor function for ComboBox
 * @param {ComboBox Id} elementId The current element ID
 * @param {Button Id}  edtBtn The button id
 * @param {fileToCommunicate} The file that is call on click of edit button
 */
function createInplaceEditorCombo(elementId,fileToCommunicate,optionArray,fieldName,tableName,condition,edtBtn)
{
	if(elementId==null || fileToCommunicate == null || fieldName==null || tableName == null || condition == null)
	{
		alert("Parameters missing: elementId, fileToCommunicate, fieldName, tableName, and condition are mendatory");	
	}
	else
	{
		if(Ajax.InPlaceEditor == null)
		{
			alert("Please include Scriptaculous.js from vendor folder for using inplace Editor");
		}
		else
		{
			var queryString = '&combo=1&fieldName='+escape(fieldName)+'&tableName='+escape(tableName)+'&condition='+escape(condition);
			if(edtBtn==null){edtBtn=""}
			var inplaceEditorTA = new Ajax.InPlaceCollectionEditor (elementId,fileToCommunicate,{collection:optionArray, ajaxOptions: {parameters: queryString },externalControl:edtBtn,highlightcolor:'#74AACF'} );
			return inplaceEditorTA;
		}
	}
};

function StringBuffer() { this.buffer = []; }
StringBuffer.prototype.append = function(string)
{
	this.buffer.push(string);
	return this;
}

StringBuffer.prototype.toString = function()
{
	return this.buffer.join("");
}

// YUI Related Functions 
/**
 * Create the YAHOO Panel dynamically
 * @param {id} elid The div id of the Yahoo Panel
 * @return Panel object
 */
 function setDlgPos(elid)
{
	
	if(elid=="initWithMe")
		return;
	if($(elid))
	{
		var f_cw = f_clientWidth();
		var f_ch = f_clientHeight();
		var el_H = $(elid).getHeight();
		var el_W = $(elid).getWidth();
		$(elid).style.position = "static";
		$(elid).style.top = eval(Math.abs(f_ch/2) - Math.abs(el_H/2))+"px";
		$(elid).style.left = eval(Math.abs(f_cw/2) - Math.abs(el_W/2))+"px";
		var myObj = document.getElementsByClassName('underlay');
		if(myObj != null)
		{
			var myLen = myObj.length;
			for(var i=0;i<myLen;i++)
			{
				myObj[i].removeClassName('underlay');
			}
		}			
	}	
}
function createDialog(elid)
{
	var useShim;
	var ua = navigator.userAgent.toLowerCase();
	if (isIE){
		useShim = true;
	}else{
		useShim = false;
		setDlgPos(elid);
	}
	if(YAHOO==null)
	{
		alert("Please include yahoo.js");
	}
	else
	{			
		dlgBox = new YAHOO.widget.Panel(elid, {modal:true, visible:false, fixedcenter:true, constraintoviewport:true, shim:useShim, draggable:false} );
		dlgBox.render();
		if (!isIE6)
			dlgBox.beforeShowEvent.subscribe(function(){setDlgPos(elid);}, this);					
		return dlgBox;
	}
};

/**
 * Create the YAHOO TabView dynamically
 * @param {id} parentDiv The div id that will contain the Tabs
 * @param {Array} keyValArr the Key:Value paired array of Labels:Urls
 * @param {String} orientation the Tab Orientation ie. left,right,top or bottom
 * @return TabView object
 */
function loadTabs(parentDiv,keyValArr,orientation,noOfTabs)
{
	if(noOfTabs!=null)
	{
		loadTabsDynamically(parentDiv,keyValArr,orientation,noOfTabs);
		return;
	}
	orientation = typeof(orientation) != 'undefined' ? orientation : 'top';

	var hashArrLabels = $A($H(keyValArr).keys());
	var hashArrURLs   = $A($H(keyValArr).values());

    var tabView = new YAHOO.widget.TabView({id: parentDiv , orientation: orientation});
    var activate = false;
	for(i=0;i<hashArrLabels.length;i++)
	{
		if(i==0)
			activate = true;
		else
			activate = false;

		if(hashArrURLs[i]==null || hashArrURLs[i]=="")
		{
			dataSource = hashArrURLs[i];
		}
		else
		{
			if(hashArrURLs[i].search(/\?/)<0)
			{
				dataSource = hashArrURLs[i]+"?PHPSESSID="+sessid;
			}
			else
			{
				dataSource = hashArrURLs[i]+"&PHPSESSID="+sessid;
			}
		}
		tabView.addTab(new YAHOO.widget.Tab({
			label: hashArrLabels[i],
			dataSrc: dataSource,
			active: activate,
			cacheData: false /******************To be kept true in production *************/
	 	 }));
	}
    
    YAHOO.util.Event.onContentReady(parentDiv, function() {
        tabView.appendTo(parentDiv);
    });
    
  	for(i=0;i<$A($H(keyValArr)).length;i++)
	{
		tabView.getTab(i).addListener('contentChange',function (){
				this.get('content').evalScripts();
			});
	}
	return tabView;
};

var start = 1;
function addTabs(tabElem,keyValArr,enableArr)
{
	var hashArrLabels = $A($H(keyValArr).keys());
	var hashArrURLs   = $A($H(keyValArr).values());

	for(i=0;i<hashArrLabels.length;i++)
	{

		tabElem.addTab(new YAHOO.widget.Tab({
			label: hashArrLabels[i],
			dataSrc: hashArrURLs[i],
			active: true,
			disabled : enableArr[i],
			cacheData: false /******************To be kept true in production *************/
	    }));
	}
	var noOfTabs = 0;
	while(tabElem.getTab(noOfTabs))
	{
		noOfTabs = noOfTabs + 1;
	}
	for(i=1;i<noOfTabs;i++)
	{
		tabElem.getTab(i).addListener('contentChange',function (){
					this.get('content').evalScripts();
			});

	}
	return tabElem;
};
/************************************************************************/
/**
* Create Custom Confirm Dialog Box
*/
		var popupMessageBoxForm;
    function popupMessageBox (title, message, icon, buttons,wth,hgt) 
    {
    		if(!wth || wth == null)
    			wth = "300px";
    		if(!hgt || hgt == null)
    			hgt = "100px";
        // our container must exist for this to work				
        if (!YAHOO.util.Dom.inDocument('popupMessageBoxContainer'))
					return;
				
        // create the confirm dialog
        var ybuttons = [];
        for (var i=0; i<buttons.length; i++) 
        {
            ybuttons[i] = { text:buttons[i].label, handler:buttons[i].func, isDefault:(i==0?true:false) };
        }

	    	popupMessageBoxForm = new YAHOO.widget.SimpleDialog("popupMessageBoxContainer1", 
				{
	            modal: true,
	     			  width: wth+"px",
	     			  height:hgt+"px",
	            fixedcenter: true,
	            visible: false,
	            draggable: false,
	            close: true,
	            text: message,
	            icon: icon,
	            constraintoviewport: true,
	            buttons: ybuttons
	           
	      });
		    popupMessageBoxForm.setHeader(title);
		    popupMessageBoxForm.render("popupMessageBoxContainer");     
		    popupMessageBoxForm.show();

    }

    function popupMessageBoxHide() 
    {
        popupMessageBoxForm.hide();
    }

    function YAlert (title, msg, icon,button,wth,hgt) 
    {
        if (icon === undefined) icon = YAHOO.widget.SimpleDialog.ICON_ALARM;
        popupMessageBox (title, msg, icon,[{label:button,func:popupMessageBoxHide}],wth,hgt);        
    }

    function YConfirm (msg, yeshandler,nohandler,button1,button2,wth,hgt) 
    {
        popupMessageBox('Please Confirm...', msg,YAHOO.widget.SimpleDialog.ICON_HELP, [{label:button1,func:function(){popupMessageBoxHide();yeshandler();}},{label:button2,func:function(){popupMessageBoxHide();nohandler();}}],wth,hgt);
    } 
/************************************************************************/    
/** 
 * Function that returns the string in particular Language
 * @param {String} str The string to be converted in the selected language
 * @return String of the language currently set. 
 */

function getText(str) /* Returns Related Language from Language Array String */
{
	//below line, which uses Localisation variable, is commented by pratik as hardik removed line for loading of individual Language.JS file in code clean up
	//if (Localisation[str]) str = Localisation[str];
	return str;
};

/**************************Added Without Comments *******************/
function _alert(str) 
{
	alert(getText(str));
};
function _confirm(str)
{
	return confirm(getText(str));
};

/*************************Added Functions ************************/
/**
 * @author Shah Pratik
 * @date 31/01/2007
 * @param {String | Int} search string or integer
 * @return {boolean} return index of needle if needle is found in array else return false
 */
Array.prototype.in_array = function ( needle ) 
{
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) 
	{
		if ( this[x] == needle ) 
		{
			return x;
		}
	}
	return false;
};

/**
 * Function that sets the cookie.
 * @author Sanjev Dutta
 * @date 31/01/2007
 * @param {String} name of the cookie
 * @param {String} value of the cookie
 * @param {String} expires expiry time for the cookie
 * @param {String} path path
 * @param {String} domain domain
 * @param {String} secure Secure cookie (SSL)
 */
function setCookie(name, value, expires, path, domain, secure)
{
	//alert(name+" "+value);
	if (name == "msgboxCK" || name == "msgboxCKSignin" || name == "msgboxtutorialcook" || name == "rememberIdPassword" || name == "Cpanel_rememberIdPassword" || name == "pv" || name == "strWidgetCookie")
	{
		if (expires)
		{
			expires = expires.toGMTString();
		}
	}
	else
		expires = null;

  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "; path=/") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
};

/**
 * Function that gets the cookie value for given name.
 * @author Sanjev Dutta
 * @date 31/01/2007
 * @param {String} name of the cookie
 * @return (String) returns the value for the given cookie name.
 */
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;
	var returnCookie = unescape(dc.substring(begin + prefix.length, end));
	if((returnCookie == null) || (returnCookie == 'null'))
	{
		returnCookie = "";
	}

	return returnCookie;
	
};

/**
 * Function that deletes the cookie.
 * @author Sanjev Dutta
 * @date 31/01/2007
 * @param {String} name of the cookie
 * @param {String} path path
 * @param {String} domain domain
 * @return (void)
 */
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" + ((path) ? "; path=" + path : "path=/") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
};
/********in place editor code******/


/******************************** Thanks To Scriptaculaus****************************/
// script.aculo.us effects.js v1.7.0_beta2, Mon Dec 18 23:38:56 CET 2006

// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// Contributors:
//  Justin Palmer (http://encytemedia.com/)
//  Mark Pilgrim (http://diveintomark.org/)
//  Martin Bialasinki
// 
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/ 

/************************** Ajax Inplace Editor ********************************/	
Ajax.InPlaceEditor = Class.create();
Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
Ajax.InPlaceEditor.prototype = {
  initialize: function(element, url, options) {
    this.url = url;
    this.element = $(element);

    this.options = Object.extend({
      paramName: "value",
      okButton: true,
      okText: "save",
      cancelLink: true,
      cancelText: "cancel",
      savingText: "Saving...",
      clickToEditText: "Click to edit",
      rows: 1,
      onComplete: function(transport, element) {
        new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
      },
      onFailure: function(transport) {
        alert("Error communicating with the server: " + transport.responseText.stripTags());
      },
      callback: function(form) {
        return Form.serialize(form);
      },
      handleLineBreaks: true,
      loadingText: 'Loading...',
      savingClassName: 'inplaceeditor-saving',
      loadingClassName: 'inplaceeditor-loading',
      formClassName: 'inplaceeditor-form',
      highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
      highlightendcolor: "#E2E2DF",
      externalControl: null,
      submitOnBlur: false,
      ajaxOptions: {},
      evalScripts: false
    }, options || {});

    if(!this.options.formId && this.element.id) {
      this.options.formId = this.element.id + "-inplaceeditor";
      if ($(this.options.formId)) {
        // there's already a form with that name, don't specify an id
        this.options.formId = null;
      }
    }
    
    if (this.options.externalControl) {
      this.options.externalControl = $(this.options.externalControl);
    }
    
    this.originalBackground = Element.getStyle(this.element, 'background-color');
    if (!this.originalBackground) {
      this.originalBackground = "transparent";
    }
    
    this.element.title = this.options.clickToEditText;
    
    this.onclickListener = this.enterEditMode.bindAsEventListener(this);
    this.mouseoverListener = this.enterHover.bindAsEventListener(this);
    this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
    Event.observe(this.element, 'click', this.onclickListener);
    Event.observe(this.element, 'mouseover', this.mouseoverListener);
    Event.observe(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.observe(this.options.externalControl, 'click', this.onclickListener);
      Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  },
  enterEditMode: function(evt) {
    if (this.saving) return;
    if (this.editing) return;
    this.editing = true;
    this.onEnterEditMode();
    if (this.options.externalControl) {
      Element.hide(this.options.externalControl);
    }
    Element.hide(this.element);
    this.createForm();
    this.element.parentNode.insertBefore(this.form, this.element);
    // stop the event to avoid a page refresh in Safari
    
    if (evt) {
      Event.stop(evt);
    }
    return false;
  },
  createForm: function() {
    this.form = document.createElement("form");
    this.form.id = this.options.formId;
    var uid = this.options.formId;
	var arrid = uid.split('-');    
    var txtid = arrid[0];
    Element.addClassName(this.form, this.options.formClassName)
    this.form.onsubmit = this.onSubmit.bind(this,txtid);

    this.createEditField();

    if (this.options.textarea) {
      var br = document.createElement("br");
      this.form.appendChild(br);
    }

    if (this.options.okButton) {
      okButton = document.createElement("input");
      okButton.type = "submit";
      okButton.value = this.options.okText;
      okButton.className = 'editor_ok_button';
	  okButton.style.fontSize  = '13px';
	  okButton.style.height ='25px';
	  okButton.style.paddingTop = '7px' ;
	  this.form.appendChild(okButton);
    }
    if (this.options.cancelLink) {
      cancelLink = document.createElement("a");
      cancelLink.href = "#";
      cancelLink.appendChild(document.createTextNode(this.options.cancelText));
      cancelLink.onclick = this.onclickCancel.bind(this);
      cancelLink.style.fontSize  = '13px';
	  cancelLink.style.fontWeight  = 'normal';
	  cancelLink.className = 'editor_cancel';      
	  this.form.appendChild(cancelLink);
    }
  },
  hasHTMLLineBreaks: function(string) {
    if (!this.options.handleLineBreaks) return false;
    return string.match(/<br/i) || string.match(/<p>/i);
  },
  convertHTMLLineBreaks: function(string) {
    return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
  },
  createEditField: function() {
    var text;
    if(this.options.loadTextURL) {
      text = this.options.loadingText;
    } else {
    	if(this.getText()=="none")
    	 	text="";
    	else
      		text = this.getText();
    }

    var obj = this;
    
    if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
      this.options.textarea = false;
      var textField = document.createElement("input");
      textField.obj = this;
      textField.type = "text";
      textField.name = this.options.paramName;
      textField.value = text;
      textField.style.backgroundColor = this.options.highlightcolor;
      textField.className = 'editor_field';
      textField.style.backgroundColor = 'white';
      var size = this.options.size || this.options.cols || 0;
      if (size != 0) textField.size = size;
      if (this.options.submitOnBlur)
        textField.onblur = this.onSubmit.bind(this);
      this.editField = textField;
    } else {
      this.options.textarea = true;
      var textArea = document.createElement("textarea");
      textArea.obj = this;
      textArea.name = this.options.paramName;
      textArea.value = this.convertHTMLLineBreaks(text);
      textArea.rows = this.options.rows;
      textArea.cols = this.options.cols || 40;
      textArea.className = 'editor_field_ta';   
      textArea.style.backgroundColor = 'white';   
      if (this.options.submitOnBlur)
        textArea.onblur = this.onSubmit.bind(this);
      this.editField = textArea;
    }
    
    if(this.options.loadTextURL) {
      this.loadExternalText();
    }
    this.form.appendChild(this.editField);
  },
  getText: function() {
    return this.element.innerHTML;
  },
  loadExternalText: function() {
    Element.addClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = true;
    new Ajax.Request(
      this.options.loadTextURL,
      Object.extend({
        asynchronous: true,
        onComplete: this.onLoadedExternalText.bind(this)
      }, this.options.ajaxOptions)
    );
  },
  onLoadedExternalText: function(transport) {
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText.stripTags();
    Field.scrollFreeActivate(this.editField);
  },
  onclickCancel: function() {
  	var erArr = document.getElementsByClassName("errMsg")
	$A(erArr).each(function(node){
			node.innerHTML="&nbsp;";
	});
  	if(this.editField.value=="")
  	{
  		this.editField.value=="none"
  	}
  	if ($('selTag'))
  	{
	  	if($('selTag').options[$('selTag').selectedIndex].value=="A" && $('divOH')!=null)
	  		$('divOH').style.display = "none";
  	}  	
    this.onComplete();
    this.leaveEditMode();
    return false;
  },
  onFailure: function(transport) {
    this.options.onFailure(transport);
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
      this.oldInnerHTML = null;
    }
    return false;
  },
  onSubmit: function(id,id2) {
	var erArr;
  	if(!this.validate(id))
  	{
  		if(navigator.appName=="Microsoft Internet Explorer")
		  	this.editField.className = "textboxRedIn";
		 else
		 	this.editField.style.border = "1px solid red";
  		
  		erArr = document.getElementsByClassName("errMsg")
  		$A(erArr).each(function(node){
				node.innerHTML=alertErrorMsg;
  		});
  		
  		return false;
  	}
  	else
  	{
  		erArr = document.getElementsByClassName("errMsg")
  		$A(erArr).each(function(node){
				node.innerHTML="&nbsp;";
  		});
	    // onLoading resets these so we need to save them away for the Ajax call
	    var form = this.form;
	    var value = this.editField.value;
	    // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
	    // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
	    // to be displayed indefinitely
	    this.onLoading();
	    if (this.options.evalScripts) {
	    	this.options.ajaxOptions.parameters = this.options.callback(form, value);
	      new Ajax.Request(
	        this.url, Object.extend({
	          parameters: this.options.callback(form, value),
	          onComplete: this.onComplete.bind(this),
	          onFailure: this.onFailure.bind(this),
	          asynchronous:true, 
	          evalScripts:true
	        }, this.options.ajaxOptions));
	    } else  {
    	 this.options.ajaxOptions.parameters = this.options.callback(form, value);
	      new Ajax.Updater(
	        { success: this.element,
	          // don't update on failure (this could be an option)
	          failure: null }, 
	        this.url, Object.extend({
	          parameters: this.options.callback(form, value),
	          onComplete: this.onComplete.bind(this),
	          onFailure: this.onFailure.bind(this)
	        }, this.options.ajaxOptions));
	    }
	    // stop the event to avoid a page refresh in Safari
	    if (arguments.length > 1) {
	      Event.stop(arguments[0]);
	    }
	    return false;
  	}
  },
  onLoading: function() {
    this.saving = true;
    this.removeForm();
    this.leaveHover();
    this.showSaving();
  },
  showSaving: function() {
    this.oldInnerHTML = this.element.innerHTML;
    this.element.innerHTML = this.options.savingText;
    Element.addClassName(this.element, this.options.savingClassName);
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
  },
  removeForm: function() {
    if(this.form) {
      if (this.form.parentNode) Element.remove(this.form);
      this.form = null;
    }
  },
  enterHover: function() {
    if (this.saving) return;
    this.element.style.backgroundColor = this.options.highlightcolor;
    if (this.effect) {
      this.effect.cancel();
    }
    Element.addClassName(this.element, this.options.hoverClassName)
  },
  leaveHover: function() {
    if (this.options.backgroundColor) {
      this.element.style.backgroundColor = this.oldBackground;
    }
    Element.removeClassName(this.element, this.options.hoverClassName)
    if (this.saving) return;
    this.effect = new Effect.Highlight(this.element, {
      startcolor: this.options.highlightcolor,
      endcolor: this.options.highlightendcolor,
      restorecolor: this.originalBackground
    });
  },
  leaveEditMode: function() {
    Element.removeClassName(this.element, this.options.savingClassName);
    this.removeForm();
    this.leaveHover();
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
    if (this.options.externalControl) {
      Element.show(this.options.externalControl);
    }
    this.editing = false;
    this.saving = false;
    this.oldInnerHTML = null;
    this.onLeaveEditMode();
  },
  onComplete: function(transport) {
    this.leaveEditMode();
    this.options.onComplete.bind(this)(transport, this.element);
  },
  onEnterEditMode: function() {},
  onLeaveEditMode: function() {
  		onLeaveEditMd = window.onLeaveEditMd || false;
  	    if(onLeaveEditMd==false)
  	    	return;
  	    else
	    	onLeaveEditMd();
  },
  
  validate:function(id)
  {
	    validArg=this.options.validate;
		if(validArg!="" && typeof(validArg)!="undefined" && validArg!=null)
			id=validArg;
		
		switch(id)
		{
			case "ufname" : 
				return albhabetIsValid(this.editField,"Only alphabets allowed.","name");
				break; 

			case "umname" : 
				return albhabetIsValid(this.editField,"Only alphabets allowed.","name");
				break; 

			case "ulname" : 
				return albhabetIsValid(this.editField,"Only alphabets allowed.","name");
				break; 

			case "name" : 
				return (isBlank(this.editField,"value"))
				break; 
				
			case "uemail":
			case "email":
				return emailIsValid(this.editField);
				break;

			case "ualtemail":
				return chkOnlyEmailIsValid(this.editField);
				break;

			case "uMobile":
			case "cell":
				return (mobileIsValid(this.editField,"Number"));
				break;

			case "uPhone":
			case "phone":
				return (phoneIsValid(this.editField,"Number"));
				break;

			case "uFax":
			case "fax":
				return (faxIsValid(this.editField,"Number"));
				break;
			case "site":
				return isValidURL(this.editField);
				break;
				
			case "uZip":
			case "zip":
				return zipIsValid(this.editField,"msg");
				break;
			
			case "uCity":
				//return isOfLength(this.editField,2);
				return albhabetIsValid(this.editField,"Only alphabets allowed.","City ");
				break;

			case "uState":
			case "state":
				//return isOfLength(this.editField,2);
				return albhabetIsValid(this.editField,"Only alphabets allowed.","State ",2,2);
				break;
			case "year":
				return isYear(this.editField);
				break;
			case "room":
				return (isOfLength(this.editField,3,"max") && numberIsValid(this.editField,"Enter valid Number",""));
				break;
			case "sqft":
				return isSqft(this.editField);
				break;
			default:
				return true;
		}
  	},  
 
  dispose: function() {
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
    }
    this.leaveEditMode();
    Event.stopObserving(this.element, 'click', this.onclickListener);
    Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
    Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
      Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  }
};


/************************** Ajax Inplace Editor Ends ********************************/	
/***************************Ajax Inplace collectin Editor*******************************/

Ajax.InPlaceCollectionEditor = Class.create();
Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype);
Object.extend(Ajax.InPlaceCollectionEditor.prototype, {
createEditField: function() {
if (!this.cached_selectTag) {
var selectTag = document.createElement("select");
selectTag.id = "selTag";
var collection = this.options.collection || [];
var optionTag;
collection.each(function(e,i) {
optionTag = document.createElement("option");
optionTag.value = (e instanceof Array) ? e[0] : e;
if((typeof this.options.value == 'undefined') &&
((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true;
if(this.options.value==optionTag.value) optionTag.selected = true;
optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e));
selectTag.appendChild(optionTag);
}.bind(this));
this.cached_selectTag = selectTag;
}
this.editField = this.cached_selectTag;
if(this.options.loadTextURL) this.loadExternalText();
this.form.appendChild(this.editField);

value2 = this.options.ajaxOptions.parameters;
//alert(value2);
this.options.callback = function(form, value) {
	if(value2.indexOf('value=')>=0)
	{
		value2 = value2.substr(value2.indexOf('&'),eval(value2.length-value2.indexOf('&')))
	}
	newVal = "value=" + encodeURIComponent(value)+value2;
//alert(newVal);	
	//this.options.ajaxOptions.parameters = "value=" + encodeURIComponent(value)+value2;
return newVal;
}
}
});


/*******************************Ajax Inplace collectin Editor Ends********************************/
/************************** Basic Effect For Inplace Editor *********************************/
String.prototype.parseColor = function() {  
  var color = '#';
  if(this.slice(0,4) == 'rgb(') {  
    var cols = this.slice(4,this.length-1).split(',');  
    var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);  
  } else {  
    if(this.slice(0,1) == '#') {  
      if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();  
      if(this.length==7) color = this.toLowerCase();  
    }  
  }  
  return(color.length==7 ? color : (arguments[0] || this));  
};

/*--------------------------------------------------------------------------*/

Element.collectTextNodes = function(element) {  
  return $A($(element).childNodes).collect( function(node) {
    return (node.nodeType==3 ? node.nodeValue : 
      (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
  }).flatten().join('');
};

Element.collectTextNodesIgnoreClass = function(element, className) {  
  return $A($(element).childNodes).collect( function(node) {
    return (node.nodeType==3 ? node.nodeValue : 
      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 
        Element.collectTextNodesIgnoreClass(node, className) : ''));
  }).flatten().join('');
};

Element.setContentZoom = function(element, percent) {
  element = $(element);  
  element.setStyle({fontSize: (percent/100) + 'em'});   
  if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
  return element;
};

Element.getOpacity = function(element){
  return $(element).getStyle('opacity');
};

Element.setOpacity = function(element, value){
  return $(element).setStyle({opacity:value});
} ; 
 
Element.getInlineOpacity = function(element){  
  return $(element).style.opacity || '';
};

Element.forceRerendering = function(element) {
  try {
    element = $(element);
    var n = document.createTextNode(' ');
    element.appendChild(n);
    element.removeChild(n);
  } catch(e) { }
};

/*--------------------------------------------------------------------------*/

Array.prototype.call = function() {
  var args = arguments;
  this.each(function(f){ f.apply(this, args) });
};

/*--------------------------------------------------------------------------*/

var Effect = {
  _elementDoesNotExistError: {
    name: 'ElementDoesNotExistError',
    message: 'The specified DOM element does not exist, but is required for this effect to operate'
  },
  tagifyText: function(element) {
    if(typeof Builder == 'undefined')
      throw("Effect.tagifyText requires including script.aculo.us' builder.js library");
      
    var tagifyStyle = 'position:relative';
    if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1';
    
    element = $(element);
    $A(element.childNodes).each( function(child) {
      if(child.nodeType==3) {
        child.nodeValue.toArray().each( function(character) {
          element.insertBefore(
            Builder.node('span',{style: tagifyStyle},
              character == ' ' ? String.fromCharCode(160) : character), 
              child);
        });
        Element.remove(child);
      }
    });
  },
  multiple: function(element, effect) {
    var elements;
    if(((typeof element == 'object') || 
        (typeof element == 'function')) && 
       (element.length))
      elements = element;
    else
      elements = $(element).childNodes;
      
    var options = Object.extend({
      speed: 0.1,
      delay: 0.0
    }, arguments[2] || {});
    var masterDelay = options.delay;

    $A(elements).each( function(element, index) {
      new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
    });
  },
  PAIRS: {
    'slide':  ['SlideDown','SlideUp'],
    'blind':  ['BlindDown','BlindUp'],
    'appear': ['Appear','Fade']
  },
  toggle: function(element, effect) {
    element = $(element);
    effect = (effect || 'appear').toLowerCase();
    var options = Object.extend({
      queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
    }, arguments[2] || {});
    Effect[element.visible() ? 
      Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
  }
};

/* ------------- core effects ------------- */

Effect.ScopedQueue = Class.create();
Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), {
  initialize: function() {
    this.effects  = [];
    this.interval = null;
  },
  _each: function(iterator) {
    this.effects._each(iterator);
  },
  add: function(effect) {
    var timestamp = new Date().getTime();
    
    var position = (typeof effect.options.queue == 'string') ? 
      effect.options.queue : effect.options.queue.position;

    switch(position) {
      case 'front':
        // move unstarted effects after this effect  
        this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
            e.startOn  += effect.finishOn;
            e.finishOn += effect.finishOn;
          });
        break;
      case 'with-last':
        timestamp = this.effects.pluck('startOn').max() || timestamp;
        break;
      case 'end':
        // start effect after last queued effect has finished
        timestamp = this.effects.pluck('finishOn').max() || timestamp;
        break;
    }
    
    effect.startOn  += timestamp;
    effect.finishOn += timestamp;

    if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
      this.effects.push(effect);
    if(!this.interval) 
      this.interval = setInterval(this.loop.bind(this), 15);
  },
  remove: function(effect) {
    this.effects = this.effects.reject(function(e) { return e==effect });
    if(this.effects.length == 0) {
      clearInterval(this.interval);
      this.interval = null;
    }
  },
  loop: function() {
    var timePos = new Date().getTime();
    this.effects.invoke('loop', timePos);
  }
});

Effect.Queues = {
  instances: $H(),
  get: function(queueName) {
    if(typeof queueName != 'string') return queueName;
    
    if(!this.instances[queueName])
      this.instances[queueName] = new Effect.ScopedQueue();
      
    return this.instances[queueName];
  }
};
Effect.Queue = Effect.Queues.get('global');

Effect.DefaultOptions = {
  duration:   1.0,   // seconds
  fps:        60.0,  // max. 60fps due to Effect.Queue implementation
  sync:       false, // true for combining
  from:       0.0,
  to:         1.0,
  delay:      0.0,
  queue:      'parallel'
};



Effect.Base = function() {};
Effect.Base.prototype = {
  position: null,
  start: function(options) {
    this.options      = Object.extend(Object.extend({},Effect.DefaultOptions), options || {});
    this.currentFrame = 0;
    this.state        = 'idle';
    this.startOn      = this.options.delay*1000;
    this.finishOn     = this.startOn + (this.options.duration*1000);
    this.event('beforeStart');
    if(!this.options.sync)
      Effect.Queues.get(typeof this.options.queue == 'string' ? 
        'global' : this.options.queue.scope).add(this);
  },
  loop: function(timePos) {
  	  	
    if(timePos >= this.startOn) {
      if(timePos >= this.finishOn) {
        this.render(1.0);
        this.cancel();
        this.event('beforeFinish');
        if(this.finish) this.finish(); 
        this.event('afterFinish');
        return;  
      }
      var pos   = (timePos - this.startOn) / (this.finishOn - this.startOn);
      var frame = Math.round(pos * this.options.fps * this.options.duration);
      if(frame > this.currentFrame) {
        this.render(pos);
        this.currentFrame = frame;
      }
    }
  },
  render: function(pos) {
    if(this.state == 'idle') {
      this.state = 'running';
      this.event('beforeSetup');
      if(this.setup) this.setup();
      this.event('afterSetup');
    }
    if(this.state == 'running') {
      if(this.options.transition) pos = this.options.transition(pos);
      pos *= (this.options.to-this.options.from);
      pos += this.options.from;
      this.position = pos;
      this.event('beforeUpdate');
      if(this.update) this.update(pos);
      this.event('afterUpdate');
    }
  },
  cancel: function() {
    if(!this.options.sync)
      Effect.Queues.get(typeof this.options.queue == 'string' ? 
        'global' : this.options.queue.scope).remove(this);
    this.state = 'finished';
  },
  event: function(eventName) {
    if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
    if(this.options[eventName]) this.options[eventName](this);
  },
  inspect: function() {
    return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>';
  }
};

/************************** Basic Effect For Inplace Editor Ends *********************************/

Effect.Scale = Class.create();
Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
  initialize: function(element, percent) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      scaleX: true,
      scaleY: true,
      scaleContent: true,
      scaleFromCenter: false,
      scaleMode: 'box',        // 'box' or 'contents' or {} with provided values
      scaleFrom: 100.0,
      scaleTo:   percent
    }, arguments[2] || {});
    this.start(options);
  },
  setup: function() {
    this.restoreAfterFinish = this.options.restoreAfterFinish || false;
    this.elementPositioning = this.element.getStyle('position');
    
    this.originalStyle = {};
    ['top','left','width','height','fontSize'].each( function(k) {
      this.originalStyle[k] = this.element.style[k];
    }.bind(this));
      
    this.originalTop  = this.element.offsetTop;
    this.originalLeft = this.element.offsetLeft;
    
    var fontSize = this.element.getStyle('font-size') || '100%';
    ['em','px','%','pt'].each( function(fontSizeType) {
      if(fontSize.indexOf(fontSizeType)>0) {
        this.fontSize     = parseFloat(fontSize);
        this.fontSizeType = fontSizeType;
      }
    }.bind(this));
    
    this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
    
    this.dims = null;
    if(this.options.scaleMode=='box')
      this.dims = [this.element.offsetHeight, this.element.offsetWidth];
    if(/^content/.test(this.options.scaleMode))
      this.dims = [this.element.scrollHeight, this.element.scrollWidth];
    if(!this.dims)
      this.dims = [this.options.scaleMode.originalHeight,
                   this.options.scaleMode.originalWidth];
  },
  update: function(position) {
    var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
    if(this.options.scaleContent && this.fontSize)
      this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
    this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
  },
  finish: function(position) {
  	if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
  },
  setDimensions: function(height, width) {
    var d = {};
    if(this.options.scaleX) d.width = Math.round(width) + 'px';
    if(this.options.scaleY) d.height = Math.round(height) + 'px';
    if(this.options.scaleFromCenter) {
      var topd  = (height - this.dims[0])/2;
      var leftd = (width  - this.dims[1])/2;
      if(this.elementPositioning == 'absolute') {
        if(this.options.scaleY) d.top = this.originalTop-topd + 'px';
        if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
      } else {
        if(this.options.scaleY) d.top = -topd + 'px';
        if(this.options.scaleX) d.left = -leftd + 'px';
      }
    }
    this.element.setStyle(d);
  }
});


Effect.Highlight = Class.create();
Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    // Prevent executing on elements not in the layout flow
    if(this.element.getStyle('display')=='none') { this.cancel(); return; }
    // Disable background image during the effect
    this.oldStyle = {
      backgroundImage: this.element.getStyle('background-image') };
    this.element.setStyle({backgroundImage: 'none'});
    if(!this.options.endcolor)
      this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
    if(!this.options.restorecolor)
      this.options.restorecolor = this.element.getStyle('background-color');
    // init color calculations
    this._base  = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
    this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
  },
  update: function(position) {
    this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
      return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) });
  },
  finish: function() {
    this.element.setStyle(Object.extend(this.oldStyle, {
      backgroundColor: this.options.restorecolor
    }));
  }
});



Effect.BlindUp = function(element) {
	
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false, 
      scaleX: false, 
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      } 
    }, arguments[1] || {})
  );
};

Effect.BlindDown = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleX: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: false,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({height: '0px'}).show(); 
      if(effect.element.id=="toggleDiv" && isIE)
      	setTimeout(function(){effect.element.style.display="block";},200);
    },  
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || {}));
};


Effect.SlideDown = function(element) {
  element = $(element).cleanWhitespace();
  // SlideDown need to have the content of the element wrapped in a container element with fixed height!
  var oldInnerBottom = element.down().getStyle('bottom');
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleX: false, 
    scaleFrom: window.opera ? 0 : 1,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makePositioned();
      effect.element.down().makePositioned();
      if(window.opera) effect.element.setStyle({top: ''});
      effect.element.makeClipping().setStyle({height: '0px'}).show(); 
    },
    afterUpdateInternal: function(effect) {
      effect.element.down().setStyle({bottom:
        (effect.dims[0] - effect.element.clientHeight) + 'px' }); 
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping().undoPositioned();
      effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); }
    }, arguments[1] || {})
  );
};

Effect.SlideUp = function(element) {
  element = $(element).cleanWhitespace();
  var oldInnerBottom = element.down().getStyle('bottom');
  return new Effect.Scale(element, window.opera ? 0 : 1,
   Object.extend({ scaleContent: false, 
    scaleX: false, 
    scaleMode: 'box',
    scaleFrom: 100,
    restoreAfterFinish: true,
    beforeStartInternal: function(effect) {
      effect.element.makePositioned();
      effect.element.down().makePositioned();
      if(window.opera) effect.element.setStyle({top: ''});
      effect.element.makeClipping().show();
    },  
    afterUpdateInternal: function(effect) {
      effect.element.down().setStyle({bottom:
        (effect.dims[0] - effect.element.clientHeight) + 'px' });
    },
    afterFinishInternal: function(effect) {
      effect.element.hide().undoClipping().undoPositioned().setStyle({bottom: oldInnerBottom});
      effect.element.down().undoPositioned();
    }
   }, arguments[1] || {})
  );
};



/************************************Slide Show Related *****************************************/



	var displayWaitMessage=true;	// Display a please wait message while images are loading?
	var activeImage = false;
	var imageGalleryLeftPos = false;
	var imageGalleryWidth = false;
	var imageGalleryObj = false;
	var maxGalleryXPos = false;
	var slideSpeed = 0;
	var imageGalleryCaptions = new Array();
	function startSlide(e)
	{
		//alert('start slide');
		slideSpeed = 0;
		if(document.all)e = event;
		var id = this.id;
		if(this.getElementsByTagName('IMG')[0].src.indexOf('Over')<0)
			this.getElementsByTagName('IMG')[0].src = this.getElementsByTagName('IMG')[0].src.replace('.gif','Over.gif');
		if(this.id=='arrowRight'){
			slideSpeed = -4;
		}else{
			slideSpeed = 6;
		}
	};
	
	function releaseSlide()
	{
		var id = this.id;
		
		this.getElementsByTagName('IMG')[0].src = this.getElementsByTagName('IMG')[0].src.replace('Over','')			
		slideSpeed=0;
	};
	function fastSlide(event)
	{

		var arrow = Event.element(event).parentNode.id;
		imageGalleryWidth = $('galleryContainer').offsetWidth - 80;
		if(arrow.search('Left') != -1)
		{
			var leftPos = imageGalleryObj.offsetLeft;
				leftPos = leftPos + imageGalleryWidth;
			if(leftPos>maxGalleryXPos)
			{				
				leftPos = maxGalleryXPos;
			}
			if(leftPos<minGalleryXPos)
			{
				leftPos = minGalleryXPos;
			}
			
			imageGalleryObj.style.left = leftPos + 'px';
		}
		else
		{
			
			var leftPos = imageGalleryObj.offsetLeft;
				leftPos = leftPos - imageGalleryWidth;
			if(leftPos>maxGalleryXPos)
			{
				leftPos = maxGalleryXPos;
			}
			if(leftPos<minGalleryXPos)
			{
				leftPos = minGalleryXPos;
			}
			imageGalleryObj.style.left = leftPos + 'px';
		}
	}
	function gallerySlide()
	{
		
		if(slideSpeed!=0){
			var leftPos = imageGalleryObj.offsetLeft;
				
			leftPos = eval(leftPos + slideSpeed);
			
			if(leftPos>maxGalleryXPos){
				
				leftPos = maxGalleryXPos;
				slideSpeed = 0;
			}
			if(leftPos<minGalleryXPos){
				leftPos = minGalleryXPos;
				slideSpeed=0;
				//alert("here else");
			}
			
			imageGalleryObj.style.left = leftPos + 'px';
		}
		setTimeout('gallerySlide()',20);
		
	};
	
	function initSlideShow()
	{
		if($('arrowLeft')&& $('arrowRight'))
		{
			
			$('arrowLeft').onmousemove = startSlide;
			$('arrowLeft').onmouseout = releaseSlide;
			$('arrowRight').onmousemove = startSlide;
			$('arrowRight').onmouseout = releaseSlide;
			
			Event.observe($('arrowLeft'), 'click', function(event) {
				fastSlide(event);
			});
			Event.observe($('arrowRight'), 'click', function(event) {
				fastSlide(event);
			});
		}
		totalImgs = $A(document.getElementsByClassName('dashIconsDrag')).length;
		imageGalleryObj = $('theImages');
		imageGalleryLeftPos = imageGalleryObj.offsetLeft;
		imageGalleryWidth = $('galleryContainer').offsetWidth - 80;
		
		maxGalleryXPos = imageGalleryObj.offsetLeft; 
		minGalleryXPos = imageGalleryWidth - $('slideEnd').offsetLeft;		
		
		if(isIE)
		{
		
			var arrAllIcons = $('divIconCollect').getElementsByTagName('img');
			var lenAllIcons = arrAllIcons.length;
			//alert(lenAllIcons);
			var widthImages = 0;
			for(var i =0;i<lenAllIcons;i++)
			{
				var divWidth = $(arrAllIcons[i].id.replace('img','divImg')).style.width.replace('px','');
				divWidth = (isNaN(parseInt(divWidth)))?0:parseInt(divWidth); 
				widthImages = widthImages + divWidth;
			}
					//alert("widthImages : " + widthImages);	
			minGalleryXPos = imageGalleryWidth - widthImages;
			maxGalleryXPos = imageGalleryObj.offsetLeft;
			//minGalleryXPos += 1550;
		}
		
		var slideshowImages = imageGalleryObj.getElementsByTagName('IMG');
		for(var no=0;no<slideshowImages.length;no++){
			slideshowImages[no].onmouseover = revealThumbnail;
			slideshowImages[no].onmouseout = hideThumbnail;
		}
		gallerySlide();
	};
	
/***********************************************End Slide Show*********************************/







function selectAll(parentdiv,all,myObj)
{
	if(all==null)
		all = true;

	if(myObj!=null && myObj.checked)
		all = true;
	else
		all = false;
		
	chkbxArr = $A($(parentdiv).getElementsByTagName("input"));
	chkbxArr.each(
		function(node)
		{
			if(node.type=="checkbox")
				node.checked=all;
		});
};

/******************Number To Money Format******************/
function num2money(n_value,prefix,elementId,dec,retval)
{
	
	dec = (dec)?dec:false;
	retval = (retval)?true:false;
	oNval = n_value.toString();
	if(typeof(n_value) == "string")
	{
		n_value = money2num(n_value);
	}
	if(n_value=="")
	{
		if(elementId!=null)
		{
			if($(elementId).type == "text")
			{
				if(retval)
				{
					$(elementId).value = "";
				}
				else
				{
					$(elementId).value = prefix+"0";
				}
			}
		else
			$(elementId).innerHTML = prefix+"0";
		}
		return;
	}
	var pre = (!prefix)?"$":prefix;
	
	if (isNaN(Number(n_value)))
	return 'ERROR';

	var b_negative = Boolean(n_value < 0);
	n_value = Math.abs(n_value);
	
	// round to 1/100 precision, add ending zeroes if needed
	if(dec && dec>2)
	{
		dec = parseInt(oNval.substr(oNval.indexOf('.')).length-1);
		divd = parseInt(eval('1e'+dec));
		var roundPt = (Math.round(n_value*divd)%divd>9)?(Math.round(n_value*divd)%divd):('0'+Math.round(n_value*divd)%divd);
	}
	else
		var roundPt = (Math.round(n_value*1e2)%1e2>9)?(Math.round(n_value*1e2)%1e2):('0'+Math.round(n_value*1e2)%1e2);
	var s_result = String(roundPt + '00').substring(0,dec);
	// separate all orders
	var b_first = true;
	var s_subresult;
	while (n_value >= 1) 
	{
		s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
		s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
		b_first = false;
		n_value = n_value/1e3;
	}
	
	// add at least one integer digit
	if (b_first)
	s_result = '0.' + s_result;

	// apply formatting and return
	if(!dec)
	{
		s_result = s_result.substring(0,s_result.indexOf("."));
	}
	if(elementId!=null)
	{
		if($(elementId).type == "text")
			$(elementId).value = b_negative ? '-'+pre + s_result + '' : pre + s_result;
		else
			$(elementId).innerHTML = b_negative ? '-'+pre + s_result + '' : pre + s_result;
	}
	
	return b_negative
	? '-'+pre + s_result + ''
	: pre + s_result;
};
/******************* String To number************/

function money2num(strMoney) 
{
	var strArr = strMoney.toArray();
	var newnum = "";
	strArr.each(function(i) {
		if(i=="-"||i=="1"||i=="2"||i=="3"||i=="4"||i=="5"||i=="6"||i=="7"||i=="8"||i=="9"||i=="0"||i==".")
		{
			newnum += i;
		}
	});
	newnum = parseFloat(newnum);
	if(!isNaN(newnum))
		return(newnum);
	else
		return "";
};
function numTotal(strMoney)
{
	var strArr = strMoney.toArray();
	var newnum = "";
	strArr.each(function(i) {
		if(i=="1"||i=="2"||i=="3"||i=="4"||i=="5"||i=="6"||i=="7"||i=="8"||i=="9"||i=="0")
		{
			newnum += i;
		}
	});
	newnum = parseFloat(newnum);
	if(!isNaN(newnum))
		return(newnum);
	else
		return "";
}
/**
 * Function For Changing inplace Edit Link
 */
function trim(str)
{ 
	if((str == null) || ( str != null && str.length == 0))
		return "";
	else if (typeof(str) != "string")
		return "";

	return(str.replace(/^\s+|\s+$/g, ''));
};



Array.prototype.find = function(searchStr, from, strict) 
{
	 if(from == undefined || from >= this.length) from = 0;
	   strict = strict == undefined ? false : strict;

	  var returnArray = false;
	  for (i=from; i<this.length; i++) 
	{
		if (typeof(searchStr) == 'function') 
		{
		  if (searchStr.test(this[i]))
			{
				if (!returnArray)
					{ returnArray = [] }
				returnArray.push(i);
			}
		} 
		else
		{
			if(strict)
			{
					if (this[i]===searchStr) 
					{
							if (!returnArray) 
								{ returnArray = [] }
							returnArray.push(i);
					}
			}
			else
			{
				if (this[i]==searchStr) 
				{
					if (!returnArray) 
						{ returnArray = [] }
					returnArray.push(i);
				}
			 }
		}
		
	  }
	  return returnArray;
};
/*
a = ["0",1,2,3,4,5,'',7,"0",1,"1",1,"1",1]
	result1 = a.find ("1"); // return 1,9,10,11,12,13
	result2 = a.find ("1",3);//return 9,10,11,12,13
	result3 = a.find ("1",3,true);//return 10,12
	*/
	
function toggleSlider()
{
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	Element.toggle('toggleDiv');
	if($('after')&&$('before'))
    {
		Element.toggle('after');
		Element.toggle('before');	
    }
    var menuDivArr = document.getElementsByClassName("widgetMenuDiv");
	$A(menuDivArr).each(function(node){
		$(node).style.display = "none";
		oldidMenu = null;
	});
	if($("tabArrow") && $("tabArrow").className.include("_up"))
	{
		$("tabArrow").className ="dashboard_tab_arrow_down";
		document.getElementsByClassName("tabCss").each(function(node){
			node.className = "tabCssCl";
		});
		if($("divSuperParent"))
			$("divSuperParent").addClassName("divSuperParentCl");
	}
	else if($("tabArrow") && $("tabArrow").className.include("_down"))
	{
		$("tabArrow").className ="dashboard_tab_arrow_up";
		document.getElementsByClassName("tabCssCl").each(function(node){
			node.className = "tabCss";
		});
		if($("divSuperParent"))
			$("divSuperParent").removeClassName("divSuperParentCl");
	}
};


function chooseChecked(parentDiv,chkd)
{
	var selectedArr = new Array();
	var selectArr = new Array();
	if($(parentDiv)==null)
	{
		return false;
	}
	parentDiv = $(parentDiv);
	chkbxArr = $A(parentDiv.getElementsByTagName("input"));
	var i=0;
	var j = 0;
	chkbxArr.each(
		function(node)
		{
			if(node.type=="checkbox" && node.id!="sel")
			{
				selectedArr[i]=node.value;
				if(chkd!=null && node.checked)
				{
					selectArr[j] = node.value;
					j++;
				}
				i++;
			}
		});
		if(chkd!=null)
			return selectArr;
		else
			return selectedArr;	
};
function getPositionLeft(element)
{
     var el = $(element);
	 var pL = 0;
     while(el)
     {
           pL += el.offsetLeft;
           el = el.offsetParent;
     }
     return pL;
};
// To find the top position, add this snippet to your code:
function getPositionTop(element)
{
     var el = $(element);var pT = 0;
     while(el)
     {
        pT += el.offsetTop;
        el = el.offsetParent;
     }
     return pT;
};
function showTooltip(tipStr,evnt,xpos)
{
	var e = evnt;
	var xpos = (xpos==null || xpos == "undefined")?50:xpos;
	var element = Event.element(e);
	var leftpos = e.clientX-xpos;
	var toppos = getPositionTop(element)+20;
	if(tipStr!=null || tipStr!="")
	{
		toppos = getPositionTop(element)+5;
		if($("titleInner"))
			$("titleInner").innerHTML = tipStr;
	}
	else
	{
		if($("titleInner"))
			$("titleInner").innerHTML = $("titleInner").title;
	}
	if($("titleDiv"))
	{
		$("titleDiv").style.width = "50px";
		$("titleDiv").style.left = leftpos+"px";
		$("titleDiv").style.top = eval(toppos+50)+"px";
		$("titleDiv").style.display = "inline";
	}
};
function hideTooltip()
{
	if($("titleDiv"))
	{
		$("titleDiv").style.display = "none";
		$("titleDiv").style.left = "0px";
		$("titleDiv").style.top = "0px";
	}
};


function getGeoAdd(lat,lng,city,state,zip,page,action,otherArgs)
{
	//alert(page);
		//alert("4"+zip);
		var myState = '';
		if(state.indexOf('|')>-1)
		{
			var arrState = state.split('|');
			myState = arrState[0];	
		}
		
		if(city.indexOf('|')>-1)
		{
			var arrCity = city.split('|');
			city = arrCity[0];	
		}
		
		var geoCodeResp = function(geoResponse)//response function for ajax call from getGeoAdd
		{
			var geoArr = eval('('+geoResponse.responseText+')');
			var geoStatus = geoArr[0].status;
			if(geoStatus!=0)
			{
				var geoCity = "";
				var geoState = "";
				var geoZip = "";
				//alert(lat+","+lng+","+city+","+state+","+zip+","+page+","+action);
				//alert('Sorry, We couldn\'t find a location for "' + geoArr[0].originaladdress + '"');
				switch(action)
				{
					case 'start':
						//alert('startNo');
						getGeoAdd(lat,lng,city,state,zip,page,'zip');
					break;
					case 'zip':
						//alert('zipNo');
						getGeoAdd(lat,lng,city,state,zip,page,'end');
					break;
				}
				return;
			}
			else
			{
				//alert('bye');
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoAddress = geoArr[0].address;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				if(geoCity=="" && geoZip=="")
				{
					alert('Please specify City or Zip');
					return;
				}
				else if((geoLat == "0" && geoLong == "0") || (geoLat == 0 && geoLong == 0))
				{
					//alert('else if');
					switch(action)
					{
						case 'start':
							//alert('startNo');
							getGeoAdd(lat,lng,city,state,zip,page,'zip');
						break;
						case 'zip':
							//alert('zipNo');
							getGeoAdd(lat,lng,city,state,zip,page,'end');
						break;
					}
					return;	
				}
				
				if(geoState == "")
					geoState = state;
				setSearchCookie("searchAddress",geoAddress);
				/*setSearchCookie("city",geoCity);
				setSearchCookie("state",geoState);
				setSearchCookie("zip",geoZip);*/
				//var cszFromCookie = setCSZValue (getSearchCookie("city"), state, getSearchCookie("zip"));
				/*if($("searchCSZ") && page != "ListMyHome")
					$("searchCSZ").value = cszFromCookie;*/
				
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var latLongStr = "[{'lat':'"+geoLat+"','lng':'"+geoLong+"'}]";
				var now = new Date();
				now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
				setCookie("latLongCk",latLongStr,now);
				latLong = eval(getCookie("latLongCk"))[0];
			}
			
			setSearchCookie("city",listAllCity);
			setSearchCookie("state",state);
			
			if(page.include("METRO"))
			{
				var strFromWhere = page.split("|");
				var mapit=strFromWhere[1];
				var widgetName =strFromWhere[2]; 
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var url;
				if(isZip)
				{	
					if(geoZip == "")
						geoZip = zip;
				}
				else
					geoZip = '';
				//alert(state);
				//return;
				if(mapit=="mapitAddr")
				{
					var geoAddress = geoArr[0].address;
					if(listAllCity != false)
					{
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1) 
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+",,,,,"+geoLat+","+geoLong;
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong;
					}
					else
					 	url = "app/listing/singlePropertyLanding.php?PHPSESSID=&status=EXP&address="+geoAddress+","+geoCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong;
					 //url = "app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
				}
				else if(mapit=="mapit")
				{						
					 if(listAllCity != false)
					 {
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1)
						 {
							url = "Search/"+state+"/"+geoCity;
							 if(zip != "")
								url += "/"+geoZip;
							//url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+",,,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
						 }
						else
						 {
							url = "Search/"+state+"/"+geoCity;
							 if(zip != "")
								url += "/"+geoZip;
							//url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
						 }
					 }
					 else
					{
						 url = "Search/"+state+"/"+geoCity;
						 if(zip != "")
							url += "/"+geoZip;
					 	//url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;//+",jbfeaturedlistings";
					}
				}
				else if(mapit=="multicity")
				{
					setSearchCookie("city",listAllCity);
					setSearchCookie("state",state);
					//cszFromCookie = setCSZValue (getSearchCookie("city"), myState);
					
					 if(listAllCity != false)
					 {
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1) 
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+",,,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
					 }
					 else
					 	url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+state+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;//+",jbfeaturedlistings";
				}
				//alert(url);
				if(otherArgs!= null)
					url = url + otherArgs;
				location.href = url;
				return;
			}
			else if(page.include("LMSRE"))
			{
				var address="";
				//alert(geoArr);
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				if(geoState == "")
					geoState = state;
				
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var url;
				if(Exclusiveflag==1)
					url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+geoLat+","+geoLong+"&widgetnames=exclusivelisting";
				else
					url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+geoLat+","+geoLong+"&widgetnames=mlsCountySearch";

				if(otherArgs!= null)
					url = url + otherArgs;
				location.href = url;
				return;			
			}	
		}
		
		if(lat != "0" || lng != "0")
		{
			//alert(lat+","+lng)
			if(page.include("METRO"))
			{
				var strFromWhere = page.split("|");
				var mapit=strFromWhere[1];
				var widgetName =strFromWhere[2];
				var url;

				var latLongStr = "[{'lat':'"+lat+"','lng':'"+lng+"'}]";
				var now = new Date();
				now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
				setCookie("latLongCk",latLongStr,now);
				if(!isZip)
					zip = '';
				
				setSearchCookie("city",listAllCity);
				setSearchCookie("state",state);
				//var	cszFromCookie = setCSZValue (getSearchCookie("city"), state);
				if(mapit=="mapitAddr")
				{
					var geoAddress;
					
					
					if($("txtAddress"))
						geoAddress = $("txtAddress").value;
					else
						geoAddress="";
						
					if(listAllCity != false)
					{
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1) 
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+",,,,,"+lat+","+lng;
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+","+zip+",,,,"+lat+","+lng;
					}
					else
						url = "app/listing/singlePropertyLanding.php?PHPSESSID=&status=EXP&address="+geoAddress+","+city+","+state+","+zip+",,,,"+lat+","+lng;
				
				}
				else if(mapit=="mapit")
				{					
					removeSearchCookie("city");
					removeSearchCookie("state");
					 //alert("2"+ zip+" , "+isZip);					
					 url = "Search/"+state+"/"+city;
	    			 if(zip != "")
						url += "/"+zip;
					 /*if(listAllCity != false)
					 {
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1) 
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames="+widgetName;
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;
					 }
					 else
					 	//url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+city+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;//+",jbfeaturedlistings";*/
				}
				else if(mapit=="multicity")
				{
					 if(listAllCity != false)
					 {
						var tempArr = listAllCity.split('|');
						//alert(tempArr.length);
						if(tempArr.length != 1) 
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames="+widgetName;
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;
					 }
					 else
					 	url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+city+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;//+",jbfeaturedlistings";
				}
				//if(otherArgs!= null)
				//	url = url + otherArgs;
				location.href = url;
			}
			else if(page.include("LMSRE"))
			{
				var address="";
				var url;
//				alert("LMSRE : "+lat+","+lng);
				if(Exclusiveflag==1)
					url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames=exclusivelisting";
				else
					url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames=mlsCountySearch";
				
				setSearchCookie("city",listAllCity);
				setSearchCookie("state",state);
				var latLongStr = "[{'lat':'"+lat+"','lng':'"+lng+"'}]";
				var now = new Date();
				now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
				setCookie("latLongCk",latLongStr,now);
				if(otherArgs!= null)
					url = url + otherArgs;
				location.href = url;
				//return;			
			}	
		}
		else
		{
			//alert('else');
			var geoAddress;
			var geoUrl = "/classes/getCSZ.php";
			
			if($("txtAddress"))
				geoAddress = $("txtAddress").value;
			else
				geoAddress="";
			
			var geoQueryString;
			switch(action)
			{
				case 'start':
					geoQueryString = "csz="+city+","+myState+"&address="+geoAddress;	
					//alert('start');
					ajaxRequest(geoUrl,geoQueryString,geoCodeResp);
				break;
				case 'zip':
					geoQueryString = "csz="+city+","+myState+","+zip+"&address="+geoAddress;	
					//alert('zip');
					ajaxRequest(geoUrl,geoQueryString,geoCodeResp);
				break;
				case 'end':
					//alert('Ends');
					if(page.include("METRO"))
					{
						var strFromWhere = page.split("|");
						var mapit=strFromWhere[1];
						var widgetName =strFromWhere[2];
						var url;
						if(!isZip)
							zip = '';
						if(mapit=="mapitAddr")
						{
							var geoAddress;
							if($("txtAddress"))
								geoAddress = $("txtAddress").value;
							else
								geoAddress="";
								
							 if(listAllCity != false)
							 {
								var tempArr = listAllCity.split('|');
								//alert(tempArr.length);
								if(tempArr.length != 1) 
									url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+",,,,,"+lat+","+lng;
								else
									url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+listAllCity+","+state+","+zip+",,,,"+lat+","+lng;
							 }
							 else
								 url = "app/listing/singlePropertyLanding.php?PHPSESSID=&status=EXP&address="+geoAddress+","+city+","+state+","+zip+",,,,"+lat+","+lng;
						}
						else if(mapit=="mapit")
						{
							 //alert("3"+ zip+" , "+isZip);
							 if(listAllCity != false)
							 {
								var tempArr = listAllCity.split('|');
								//alert(tempArr.length);
								if(tempArr.length != 1)
								{
									//alert('e');
									url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames="+widgetName;
								}
								else
								{
									//alert('d');
									url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address=,"+listAllCity+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;
								}
							 }
							 else
							 url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+city+","+state+","+zip+",,,,"+lat+","+lng+"&widgetnames="+widgetName;//+",jbfeaturedlistings";
						}
						if(otherArgs!= null)
							url = url + otherArgs;
						location.href = url;
					}
					else if(page.include("LMSRE"))
					{
						var address="";
						if(Exclusiveflag==1)
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames=exclusivelisting";
						else
							url ="../../../app/listing/singlePropertyLanding.php?status=EXP&address="+address+","+listAllCity+","+state+",,,,,"+lat+","+lng+"&widgetnames=mlsCountySearch";
						//alert(url);
						if(otherArgs!= null)
							url = url + otherArgs;
						location.href = url;
					}
				break;
			}
			//var geoQueryString = "csz="+city+","+state+","+zip+"&address="+geoAddress;
		}
}


function getGeocodeAddress(csz,page)
{
		var geoCbFn = function(geoResponse)
		{
			var geoArr = eval('('+geoResponse.responseText+')');
			var geoStatus = geoArr[0].status;
			if(geoStatus!=0)
			{
				var geoCity = "";
				var geoState = "";
				var geoZip = "";
				alert('Sorry, We couldn\'t find a location for "' + geoArr[0].originaladdress + '"');
				if (page=="ValueMyHome")
				{
					$('btnSearchEstimateAddress').style.display = "";
					$('statusMsg').style.display = "none";
				}
				
				return;
			}
			else
			{

				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoAddress = geoArr[0].address;
				if(geoCity=="" && geoZip=="")
				{
					alert('Please specify City or Zip');
					return;
				}
				if($("searchCity"))
					$("searchCity").value = geoCity;
				if($("searchState"))
					$("searchState").value = geoState;
				if($("searchZip"))
					$("searchZip").value = geoZip;
				if($("searchAddress")  && page != "ListMyHome")
					$("searchAddress").value = geoAddress;
					
				
				setSearchCookie("searchAddress",geoAddress);
				setSearchCookie("city",geoCity);
				setSearchCookie("state",geoState);
				setSearchCookie("zip",geoZip);
				setSearchCookie("county","");
				
				var cszFromCookie = setCSZValue (getSearchCookie("city"), getSearchCookie("state"), getSearchCookie("zip"));
				if($("searchCSZ") && page != "ListMyHome")
					$("searchCSZ").value = cszFromCookie;
				
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var latLongStr = "[{'lat':'"+geoLat+"','lng':'"+geoLong+"'}]";
				var now = new Date();
				now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
				setCookie("latLongCk",latLongStr,now);
				latLong = eval(getCookie("latLongCk"))[0];
				
				
			}
			//alert(page);
			if(page != "campaign" && page != "landing" && page != "ListMyHome" && page != "snapShot" && page != "VOH" && page != "BST" && page != "FAH" && page != "FAO" && page != "VH" && !(page.include("LMSRE")) && page != "LMSRE_SmartWin" && page != "METRO_AssOff" &&!(page.include("METRO")))
			{
				if(trim($('searchAddress').value) == "")$('searchAddress').value = "optional";	

				if(document.cookie=="")
					pageReload();
			}
			if(page=="dashboard")
			{
				funQckUpdateWidgets();		
			}
			else if(page=="singleProp")
			{
				funExploreOnMapit();//alert("Please add your function call for MapIt in common.js");
			}
			else if(page=="landing")
			{
				window.location.href = './app/dashboard/dashboardIndex.php';
			}
			else if(page == "dashboardbitz")
			{
				window.location.href = '../../app/dashboard/dashboardIndex.php?setDsh=1';
			}
			else if(page=="campaign")
			{

				lat = latLong.lat;
				lng = latLong.lng;

				if (geoArr[0].city !="")
					var geoCityStr = geoArr[0].city;
				if (geoArr[0].state !="")
					geoCityStr += ", "+geoArr[0].state;
				if (geoArr[0].zip !="")
					geoCityStr += ", "+geoArr[0].zip;
				//return geoCityStr;
				if(trim(geoCityStr)=="") 
					alert("Please refine your search criteria");
				else
					sendDashboard(geoCity,geoState,geoZip,lat,lng);
			}
			else if(page=="ValueMyHome")
			{
				var url = "../feed/homeEstimate.php?pid=&address="+geoAddress+","+geoCity+","+geoState+","+geoZip;
				window.open(url,"_blank");
				$('btnSearchEstimateAddress').style.display = "";
				$('statusMsg').style.display = "none";
			}
			
			else if(page=="ExploreNeighborhood")
			{
				
				var url = './dshbrdExplore.php';
				var qryStr = 'geoAddress=1&exploreAddress='+geoAddress+'&exploreCity='+geoCity+'&exploreState='+geoState+'&exploreZip='+geoZip;
				ajaxRequest(url,qryStr,function(respObj)
				{
					if (respObj.responseText=="0")
					{
						alert("Sorry, Not Able To Resolve Address");
						$('btnSearchExplore').style.display = "";
						$('expStatusMsg').style.display = "none";
					}
					else
					{
						var url = respObj.responseText;
						window.open(url,"_blank");
						$('btnSearchExplore').style.display = "";
						$('expStatusMsg').style.display = "none";
					}
				});
			}
			
			else if(page=="ListMyHome")
			{
				$('btnGetBids').style.display = "none";
				$('statusMsgListHome').style.display = "";

				var url = './dshbrdLMH.php';
				var qryStr = 'validateAddress=1&address='+geoAddress+'&city='+geoCity+'&state='+geoState+'&zip='+geoZip+'&expt='+exptdSales+'&name='+names+'&email='+email+'&timel='+timeLine;
				var divid = $('listHome').id;
				loadToDiv(url,qryStr,divid);			
			}
			else if(page=="snapShot")
			{
				getListingSnapshots();
			}
			else if(page=="FAH")
			{
				var url = "app/dashboard/dashboardIndex.php";
				location.href = url;
			}
			else if(page=="BST")
			{
				var url = "app/dashboard/dashboardIndex.php";
				location.href = url;
			}
			else if(page=="VOH")
			{
				var url = "app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong;
				location.href = url;
			}
			else if (page=="VH")
			{
				var csz = geoCity+","+geoState+","+geoZip;
				var url = "app/feed/homeEstimate.php?pid=&address="+escape(geoAddress)+","+escape(csz);
				location.href = url; 				
			}
			else if(page=="FAO")
			{
				var url = "app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong;
				location.href = url;
			}
			else if(page=="METRO_AssOff")
			{
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				
				var url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames=brokeragents,brokeroffices";
				location.href = url;
			}
			else if(page=="METRO_AssAgtOff")
			{
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var qs = "";
				var wdNm = "brokeragents";
				var isOthSet = false;
				if(isBlank('txtFname','First Name'))
				{
					qs += "&fname="+$F('txtFname');
					isOthSet= true;
				}
				
				if(isBlank('txtLname','Last Name'))
				{
					qs += "&lname="+$F('txtLname');
					isOthSet= true;
				}
				
				if(isBlank('txtCityName','City'))
				{
					qs += "&cityName="+escape($F('txtCityName'));
					wdNm = wdNm + ",officeLocation";
					isOthSet= true;
				}
				
				if($F('txtOffice') != "")
				{
					//qs += "&office="+escape($F('txtOffice'));
					qs += "&office="+escape($("txtOffice").options[$("txtOffice").selectedIndex].value);
					wdNm = wdNm + ",brokeroffices";
					isOthSet= true;
				}
				
				if($F('txtOfficeLoc') != "")
				{
					//qs += "&office="+escape($F('txtOffice'));
					qs += "&officeLoc="+escape($("txtOfficeLoc").options[$("txtOfficeLoc").selectedIndex].value);
					//alert($F('txtOfficeLoc'));return;
					/*if(isOthSet)
						wdNm = wdNm + ",officeLocation";
					else
						wdNm = "officeLocation";*//*old*/
					
					if(!wdNm.include("officeLocation"))
						wdNm = wdNm + ",officeLocation";/*new*/	
				}				
				var showDialog="";
				if(wdNm != "officeLocation")
					showDialog = "&showAgentDialog=some";
				else
					showDialog = "&showAgentDialog=";
				var url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+wdNm+showDialog+qs;
				
				//var url = "./app/listing/singlePropertyLanding.php?status=EXP&address=,denver,CO,,,,,39.755092,-104.988123&widgetnames=brokeragents,brokeroffices&showAgentDialog=1";
				//alert(url);
				location.href = url;
			}
			else if(page=="LMSRE_SmartWin")
			{
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				sendAddressFldsToLMSRE(geoCity,geoState,geoLat,geoLong);
			}
			else if(page.include("LMSRE"))
			{
				var strFromWhere = page.split("|");
				var mapit=strFromWhere[1];
				var widgetName =strFromWhere[2]; 
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				var url;
				var moreWidgets="";
				moreWidgets = getCookie("strMapitCK");
				if(widgetName=="terabitzMap")
				{
					url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames=";
				}
				else if(mapit=="mapit")
				{
					var ps = "";
					if(typeof(powerSearch) != 'undefined' && powerSearch == '1' && (uRole == 'EA' || uRole == 'A'))
						var ps = "&ps=1";

					if(moreWidgets == "" || moreWidgets == null)
					{
						url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+ps;
					}
					else
					{
						url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+","+moreWidgets+ps;
					}
					if(uid != "")
						setCookie("strMapitCK","");
				}
				else if(mapit=="fromMapIt")
				{
					if(moreWidgets == "" || moreWidgets == null)
					{
						url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName;
					}
					else
					{
						url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+","+moreWidgets;
					}
				}
				else if(mapit=="dashboard")
				{
					//url = "/app/dashboard/dashboardIndex.php?loadnow=1&code=searchAddress=:::city="+geoCity+":::state="+geoState+":::county=:::neighborhood=:::minPrice=:::maxPrice=:::searchBeds=:::minSize=:::maxSize=:::searchBaths=:::searchType=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::zip=&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
					url = "/app/dashboard/dashboardIndex.php";
				}
				else if(mapit=="dashboardindex")
				{
					eval("var hashDshbrdBitz="+lmsreDshbrdBitz); 
					if(eval("hashDshbrdBitz['"+widgetName+"']")!=null)
	 				{	
	 					hashVal = eval("hashDshbrdBitz['"+widgetName+"']");
	 					url = "/app/dashboard/dashboardIndex.php?loadnow=1&code=searchAddress=:::city="+geoCity+":::state="+geoState+":::county=:::neighborhood=:::minPrice=:::maxPrice=:::searchBeds=:::minSize=:::maxSize=:::searchBaths=:::searchType=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::zip=&id=:::"+hashVal+",1,2&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
 					}
	 			}
				location.href = url;
			}
			else if(page.include("METRO"))
			{
				var strFromWhere = page.split("|");
				var mapit=strFromWhere[1];
				var widgetName =strFromWhere[2]; 
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				if(geoState!="CO")
				{
					alert("Sorry, we do not support any other state then CO.");
					return;
				}
				var url;
				var extra = "";
				if(widgetName == "exclusivecol")
				{
					extra = "&mapZoomLevel=9";
					var now = new Date();
					now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
					setCookie("mapSearchSelect","1",now);
				}

				if(mapit=="mapitAddr")
				{
					var geoAddress = geoArr[0].address;
					 widgetName = 'mlsaddrsearch';
					 url = "app/listing/singlePropertyLanding.php?status=EXP&address="+geoAddress+","+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+extra;
				}
				else if(mapit=="mapit")
				{
					//alert(3);
					var dist = "";
					var distStr = "";
					if($("distanceChk").checked)
					{
						dist = $F("distance");
						distStr = "&mapZoomLevel=" + dist;//"&distance="+dist;
					}

					if(widgetName == "exclusivecol")
					{
						distStr = "&mapZoomLevel=9";
					}

					//url = "app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+distStr;//+",jbfeaturedlistings";
					url = "Search/"+geoState+"/"+geoCity;
					if(geoZip != "")
						url += "/"+geoZip;
					
					removeSearchCookie("city");
					removeSearchCookie("state");
				}
				else if(mapit=="fromMapIt")
				{
					url = "/app/listing/singlePropertyLanding.php?status=EXP&address=,"+geoCity+","+geoState+","+geoZip+",,,,"+geoLat+","+geoLong+"&widgetnames="+widgetName+extra;
				}
				else if(mapit=="dashboard")
				{
					url = "/app/dashboard/dashboardIndex.php?loadnow=1&code=searchAddress=:::city="+geoCity+":::state="+geoState+":::county=:::neighborhood=:::minPrice=:::maxPrice=:::searchBeds=:::minSize=:::maxSize=:::searchBaths=:::searchType=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::zip=&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
				}
				else if(mapit=="dashboardindex")
				{
					if(widgetName=="demographics")
						url = "app/dashboard/dashboardIndex.php?loadnow=1&code=searchAddress=:::city="+geoCity+":::state="+geoState+":::county=:::neighborhood=:::minPrice=:::maxPrice=:::searchBeds=:::minSize=:::maxSize=:::searchBaths=:::searchType=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::zip=&id=28,1,1:::&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
					if(widgetName=="climate")
						url = "app/dashboard/dashboardIndex.php?loadnow=1&code=searchAddress=:::city="+geoCity+":::state="+geoState+":::county=:::neighborhood=:::minPrice=:::maxPrice=:::searchBeds=:::minSize=:::maxSize=:::searchBaths=:::searchType=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::zip=&id=19,1,1:::&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
					if(widgetName=="mortgage rates")
						url = "app/dashboard/dashboardIndex.php?loadnow=1&code=city="+geoCity+":::state="+geoState+":::county=:::minsqft=:::maxsqft=:::minSize=:::maxSize=:::searchType=:::searchAddress=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::minPrice=:::maxPrice=:::searchBeds=:::searchBaths=:::zip=&id=50,1,1:::&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;;
					if(widgetName=="mcalc")
						url = "app/dashboard/dashboardIndex.php?loadnow=1&code=city="+geoCity+":::state="+geoState+":::county=:::minsqft=:::maxsqft=:::minSize=:::maxSize=:::searchType=:::searchAddress=:::searchSortType=ph:::ckLFDate=:::ckLTDate=:::minPrice=:::maxPrice=:::searchBeds=:::searchBaths=:::zip=&id=24,1,1:::&fe=&f=1&propLatitude="+geoLat+"&propLongitude="+geoLong;
				}
				location.href = url;
			}
			else if(page == "METRO_GOTLL")
			{
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoZip = geoArr[0].zip;
				sendAddressForLatLong(geoCity,geoState,geoZip);
			}
			else if(page=="METRO_SmartWin")
			{
				var geoCity = geoArr[0].city;
				var geoState = geoArr[0].state;
				var geoLat = geoArr[0].latitude;
				var geoLong = geoArr[0].longitude;
				sendAddressFldsToMETRO(geoCity,geoState,geoLat,geoLong);
			}
			else
			{
				submitSearchForm();
			}
		}
		
		if (page == 'ValueMyHome')
		{
			var geoAddress = $("valueHomeAddress").value;
		}
		else if (page == 'ExploreNeighborhood')
		{
			var geoAddress = $("exploreAddress").value;
		}
		else if (page == 'ListMyHome')
		{
			var geoAddress = $("listHomeAddress").value;
			var exptdSales = $("expectedSale").value;
			var names = $("listHomeName").value;
			var email = $("listHomeEmail").value;						
			var timeLine = $("timeLine").value;									
		}
		else if (page == 'landing')
		{
			if ($('searchAddress').value == "optional")
			{
				var geoAddress = "";
			}
			else
			{
				var geoAddress = $("searchAddress").value;
			}

			if  ($('searchCSZ').value == "required")
			{
				alert ('Please enter a location.');
				return;
			}
		}
		else if(page == 'campaign')
		{
			var geoAddress ="";
		}
		else if(page == "FAH" || page == "BST" || page == "VOH" || page == "VH" || page == "FAO")
		{
			if ($('searchAddress').value == "optional")
			{
				var geoAddress = "";
			}
			else
			{
				var geoAddress = $("searchAddress").value;
			}
		}
		else if(page.include("LMSRE") || page=="LMSRE_SmartWin" || page.include("METRO") || page=="METRO_SmartWin" || page == 'Metro')
		{
			var geoAddress; 
			if($("txtAddress"))
				geoAddress = $("txtAddress").value;
			else
				geoAddress="";
		}
		else
		{
			var geoAddress = $("searchAddress").value;
		}
		
	
		var geoUrl = "/classes/getCSZ.php";
		var geoQueryString = "csz="+csz+"&address="+geoAddress;
		if (page == 'METRO')
		{
			ajaxRequest(geoUrl,geoQueryString,geoCbFn,false);
		}
		else
		{
			ajaxRequest(geoUrl,geoQueryString,geoCbFn);
		}

}


//--------------------------- Search Funtions -----------------------------//

function isNumeric(strValue)
{
	var objRegExp  = /(^-?\d\d*$)/;
	return objRegExp.test(strValue);
};

function submitSearchForm()
{
	if (($F('searchCity') == "") && ($F('searchZip') == ""))
	{
		alert ("Atleast one of 'City' or 'Zip' is requied");
		return false;
	}

	if(!zipValid('searchZip'))
	{
		alert("Zip is invalid");
		return false;
	}
	if(!numberIsValid('yearFrom',"Please enter valid year value","Year From",null,null))
	{
		alert ("Please enter valid year value");
		return false;
	}
	else
	{
		 if($('yearFrom').value!="" && $('yearFrom').value!=" ")
		 {
			 if($('yearFrom').value.length < 4)
			 {
				alert ("Year From should be 4 charcters long.");
				return false;
			 }
		}
	}
	
	if(!numberIsValid('yearTo',"Please enter valid year value","Year To",null,null))
	{
		alert ("Please enter valid year value");
		return false;
	}
	else
	{
		if($('yearTo').value!="" && $('yearTo').value!=" ")
		{
			 if($('yearTo').value.length < 4)
			 {
				alert ("Year To should be 4 charcters long.");
				return false;
			 }
		}
	}
	var contextArray = new Array("onSale","openHouse","newHomes","allHomes");
	var searchAddress = $F('searchAddress');
	if($('srchPopInDiv'))
		Element.toggle('srchPopInDiv');

	var saleable = "3";
	var userContext = "allHomes";
	var queryString = "address=" + escape(searchAddress);
		queryString = queryString + "&city=" + escape(trim($F("searchCity")));
		queryString = queryString + "&state=" + escape(trim($F("searchState")));
		queryString = queryString + "&zip=" + escape(trim($F("searchZip")));
		queryString = queryString + "&minprice=" + escape(money2num($F("minPrice")));
		queryString = queryString + "&maxprice=" + escape(money2num($F("maxPrice")));
		queryString = queryString + "&minsqft=" + escape($F("minSize"));
		queryString = queryString + "&maxsqft=" + escape($F("maxSize"));
		queryString = queryString + "&beds=" + escape($F("searchBeds"));
		queryString = queryString + "&baths=" + escape($F("searchBaths"));
		queryString = queryString + "&searchType=" + escape($F("searchType"));
		queryString = queryString + "&saleable=" + escape(saleable);
		queryString = queryString + "&usercontext=" + escape(userContext);
		setCookie("checkedType",saleable,now);
		
	//-------------------setting client side cookies--------------------//
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	setAllToCookie();
	url = "../listing/checkRecords.php";
	if ($('signInDiv')) Element.toggle('signInDiv');
	if ($('srchDiv')) Element.toggle('srchDiv');
	ajaxRequest(url,queryString,evalResponce);	
};

function evalResponce(originalRequest)
{
	var recCount = parseInt(originalRequest.responseText);
	if (recCount < 0)
	{
		if ($('srchDiv')) Element.toggle('srchDiv');
		if ($('signInDiv')) Element.toggle('signInDiv');
		alert("Sorry cannot connect to server");
	}	
	else if (recCount == 0)
	{
		if ($('srchDiv')) Element.toggle('srchDiv');
		if ($('signInDiv')) Element.toggle('signInDiv');
		alert("Sorry no records found");
		if($('srchPopInDiv'))
			Element.toggle('srchPopInDiv');
	}	
	else
	{
		window.location.href = "../listing/searchResult.php?PHPSESSID="+sessid;
	}
};

//--------------------------- Search Funtions -----------------------------//
function contactUs(type)
{
	alert ("For technical issues, please contact us at support@terabitz.com"+'\n'+"Broker-Agents contact us at brokeragentsupport@terabitz.com"+'\n'+"For all other inquiries, please contact us at info@terabitz.com");
}
/*********************************************************************************
 * Getting window size and scroll bars position in JavaScript/DHTML
 * http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
 * author : Hi Pratik!
 * Date	: 15th May 2007
 * 
 ********************************************************************************** 
 */

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function Querystring(qs) { 
	this.qs = qs;
	this.params = new Object();
	this.get=Querystring_get;
	this.set = Querystring_set;
	if (this.qs == null)
		this.qs=location.search.substring(1,location.search.length)

	if (this.qs.length == 0) return

	this.qs = this.qs.replace(/\+/g, ' ')
	var args = this.qs.split('&') // parse out name/value pairs separated via &
	
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0]);
        if(i==0)
		{
			name = name.substr(eval(name.indexOf('?')+1),name.length);
		}
		if (pair.length == 2)
			value = unescape(pair[1]);
		else
			value = name;
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) 
{
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	return value;
}
function Querystring_set(key,value)
{
	if(key == null)
		return;
	if(value == null)
		value = "";	
	this.params[key] = unescape(value);
	var paramKeys = Object.keys(this.params);
	var myQS = "";
	for(var i=0;i<paramKeys.length;i++)
	{
		myQS = myQS + "&" + paramKeys[i] + "=" + escape(this.params[paramKeys[i]]);
	}
	myQS = myQS.substr(1,myQS.length);
	this.qs = myQS;
}
Element.addMethods({
  hasAttributeValue: function(element, attrName, attrVal, separator) {
    element = $(element);
    attrName = trim(attrName);
    separator = (separator)?(separator):" ";
    var attr = element.readAttribute(attrName);
    if(attr==null || attr =="")
    	return false;
    attrVal = trim(attrVal);
    if(attr!="" || trim(attr)!="")
    {
    	attr = attr.replace (/^\s+/g, "").replace (/\s+$/g, "").replace (/\s+/g, " ");
    	var attrArr = attr.split(separator);
    	var retVal = attrArr.find(attrVal);
    	if(retVal===false)
    		return false;
    	else
    		return true;
    }
    return false;
  }
});
  
document.getElementsByAttributeVal = function(attrName,attrVal, parentElement) {
  if (Prototype.BrowserFeatures.XPath) {
    var q = ".//*[contains(concat(' ', @"+ attrName +", ' '), ' " + attrVal + " ')]";
    return document._getElementsByXPath(q, parentElement);
  } else {
    var children = ($(parentElement) || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if ($(child).hasAttributeValue(attrName, attrVal))
      {
        elements.push(Element.extend(child));
      }
    }
    return elements;
  }
};
//("groupid","3","galleryContainer")
var lastArrow = false;
function searchAddressFormat(event,defaultText)
{
	if(typeof(event)!="string")
	{
		var element = Event.element(event);
			if(event.type=="blur")
	{
		var srchVal = element.value.replace (/^\s+/g, '').replace (/\s+$/g, '').replace (/\s+/g, ' ');
		if(srchVal == '')
		{
			element.value=defaultText;
			element.className = element.className.gsub("N","");
		}
		else
		{
			element.value=srchVal;
			if(element.className.indexOf("N")==-1)
				element.className = String(element.className+"N");
		}
	}
	if(event.type=="focus")
	{
		if(element.value==defaultText)
		{
			element.value='';
			if(element.className.indexOf("N")==-1)
				element.className = String(element.className+"N");
		}
	}
		
	}
	else
	{
		var element = $(event);
		var srchVal = element.value.replace (/^\s+/g, '').replace (/\s+$/g, '').replace (/\s+/g, ' ');
		if(srchVal == '')
		{
			element.value=defaultText;
			element.className = element.className.gsub("N","");
		}
		else
		{
			element.value=srchVal;
			if(element.className.indexOf("N")==-1)
				element.className = String(element.className+"N");
		}
	}	
}
function findBitFormat()
{
	if(trim($("findBitTxt").value) == "")
	{
		$("findBitTxt").value = "Find Bit";
		$("findBitTxt").className = "textboxstyle";
	}
	else if(trim($("findBitTxt").value) == "Find Bit")
	{
		$("findBitTxt").value = "";
		$("findBitTxt").className = "textboxstyleN";
	}
	else
	{
		$("findBitTxt").className = "textboxstyleN";
		findBit();
	}
}
var arrLoadedTabs = new Array();
function showWidgetGrp(gid)
{
	if(gid==null || typeof(gid)=='undefined')
		return;
	if($("toggleDiv").style.display=="none")
	{
		toggleSlider();
	}
	
	$A(document.getElementsByClassName("dashIconsDrag","galleryContainer")).each(Element.hide);
	if(gid=="All")
	{
		var gidArr = document.getElementsByClassName("dashIconsDrag","galleryContainer");
		gidArr.each(function(nd)
		{
			$(nd).style.display = "inline";
		});
		$('theImages').style.left = 25 + 'px';
		if($("arrowLeft"))
		{
			$("arrowLeft").show();
			$("arrowRight").show();
			$("arrowLeftDis").hide();
			$("arrowRightDis").hide();
		}
		initSlideShow();
		return;
	}
	gid = gid.toString();
	var gidArr = document.getElementsByAttributeVal("groupid",gid,"galleryContainer");
	var len = gidArr.length;
	for(var i=0;i<len;i++)
	{
		if((arrLoadedTabs.in_array(gid) === false) && ($(gidArr[i]) != null))
		{
			var divImgId = $(gidArr[i]).id;
			var widgetName = divImgId.gsub('divImg_','');
			var imgId =  'img_'+widgetName;
			$(imgId).src = $(imgId).src.gsub('spacer.gif',eval('widgetsData.'+widgetName+'.img_n'));
		}	
		if($(gidArr[i]))
			$(gidArr[i]).style.display = "inline";
	}
	if(arrLoadedTabs.in_array(gid) === false)
		arrLoadedTabs[arrLoadedTabs.length] = parseInt(gid);
	
	if(len>=9)
	{
		lastArrow = true;
		if($("arrowLeft"))
		{
			$("arrowLeft").show();
			$("arrowRight").show();
			$("arrowLeftDis").hide();
			$("arrowRightDis").hide();
		}
	}
	else
	{
		lastArrow = false;
		if($("arrowLeft"))
		{
			$("arrowLeft").hide();
			$("arrowRight").hide();
			$("arrowLeftDis").style.display = "inline";
			$("arrowRightDis").style.display = "inline";
		}
	}
	$('theImages').style.left = 25 + 'px';
	if(!isIE)
		initSlideShow();
}

function findHash(myObjFind,key)
{
	var h  = $H(myObjFind);
	var arrKeys = h.keys().sort();
	
	key = trim(key).toLowerCase();
	var keyLen = key.length;
	
	var arrRes = Array();
	for(var i=0;i<arrKeys.length;i++)
	{
		//if(key==((arrKeys[i].toLowerCase().substring(0,keyLen)).toLowerCase()))
		if((arrKeys[i].toLowerCase()).include(key))
			arrRes.push(h[arrKeys[i]]);
	}
	return arrRes;
}
function findBit()
{
	var gidArr = document.getElementsByClassName("dashIconsDrag","galleryContainer");
	var key=$("findBitTxt").value;
	if(trim(key)!="")
	{
		gidArr.each(function(nd)
		{
			$(nd).style.display = "none";
		});
		var findArr = findHash(myObjFind[0],key);
		$A(findArr).each(
			function(node)
			{
				if($("divImg_"+node) && node!="mapit")
					$("divImg_"+node).show();
			}
		);
	}
	else
	{
		gidArr.each(function(nd)
		{
			if(nd!="divImg_mapit")
				$(nd).style.display = "inline";
		});
	}
}

function changeTabCls(type,event)
{
	var gidArr = document.getElementsByClassName("tabTdCls",event);
	if(type=="over")
	{
		gidArr.each(function(nd)
		{
			if(!(nd.className.include("_blue_h")))
				nd.className = nd.className.gsub("_blue_n","_blue_h");
		});
	}
	else if(type=="out")
	{
		gidArr.each(function(nd)
		{
			if((nd.className.include("_blue_h")))
				nd.className = nd.className.gsub("_blue_h","_blue_n");
		});
	}
	else
	{
		var gidArrAll = document.getElementsByClassName("tabTdCls","grpDiv");
		gidArrAll.each(function(nd)
		{
			if((nd.className.include("_blue_cl")))
			{
				nd.className = nd.className.gsub("_blue_cl","_blue_n");
			}
		});
		gidArr.each(function(nd)
		{
			if(!(nd.className.include("_blue_cl")))
			{
				nd.className = nd.className.gsub("_blue_h","_blue_cl");
				nd.className = nd.className.gsub("_blue_n","_blue_cl");
			}
		});
	}
	
}

function trimToRect(w, h, str, strApp, strClass, bTrimToWords, bAlwaysAppend,id)
{
	h=parseInt(h);
	str=str.replace(/<=>/g,"'");
	str=str.replace(/<==>/g,'"');
// element with id "ruler" must exist in the document, e.g.:
// <div id=ruler style="position:absolute; left:-5000px;"><!-- --></div>
	elR = document.getElementById(id);
	elR.className = strClass;
	elR.style.width = w;
	
	if(bAlwaysAppend)
		strResult = str + strApp;
	else
		strResult = str;

	// fits already? opt out early
	elR.innerHTML = strResult;
	if(elR.clientHeight <= h)
		return strResult;

	with(Math) position = nextOffset = pow(2,floor(log(str.length) / LN2));

	do
	{
		nextOffset = nextOffset / 2;
		elR.innerHTML = str.substr(0, position) + strApp;
		position = position + (elR.clientHeight > h? -nextOffset:nextOffset);
	} while(nextOffset!= 1);

	elR.innerHTML = str.substr(0, position) + strApp;
	if(elR.clientHeight > h)
		position--;

	if(bTrimToWords)
		while(str.substr(--position, 1)!= " ");

	return str.substr(0, position) + strApp;
}

function highlightMapTypeBtn(maparg)
{
	if (maparg)
		mapType = maparg.getCurrentMapType().getName(true);
	if(mapType=="Map")
	{
		document.getElementById("btnMap").className="mapTypeButtonSelect";
		document.getElementById("btnSat").className="mapTypeButton";
//		document.getElementById("btnHyb").className="mapTypeButton";
		document.getElementById("btnTer").className="mapTypeButton";
	}
	else if(mapType=="Sat")
	{
		document.getElementById("btnMap").className="mapTypeButton";
		document.getElementById("btnSat").className="mapTypeButtonSelect";
//		document.getElementById("btnHyb").className="mapTypeButton";
		document.getElementById("btnTer").className="mapTypeButton";
	}
/*	else if(mapType=="Hyb")
	{
		document.getElementById("btnMap").className="mapTypeButton";
		document.getElementById("btnSat").className="mapTypeButton";
		document.getElementById("btnHyb").className="mapTypeButtonSelect";
		document.getElementById("btnTer").className="mapTypeButton";
	}
*/
	else if(mapType=="Ter")
	{
		document.getElementById("btnMap").className="mapTypeButton";
		document.getElementById("btnSat").className="mapTypeButton";
//		document.getElementById("btnHyb").className="mapTypeButton";
		document.getElementById("btnTer").className="mapTypeButtonSelect";
	};
}
//Funtions for getting the all the MapIT bits that are currently loaded on the dashboard

function getMapItBitsLoadedOnDashboard(expURL,uid)
{
	if (typeof(uid) != "undefined")
	{
		var url = "/app/dashboard/dshbrdProcess.php";
		var qryStr = "fetchdata=1";
		ajaxRequest(url,qryStr,function(objRequest){

			var response = trim(objRequest.responseText);
			if(response == '{}')
			{
				return;
			}
			else
			{
				var responseArr = eval(response);
				widgetNames = '';
				for(var i=0;i<responseArr.length;i++)
				{
					var rowNo = responseArr[i].rowNo;
					var colNo = responseArr[i].colNo;
					var widgetName = responseArr[i].widgetName;
					var divChildId = "divChild"+rowNo+"X"+colNo; 
					widgetNames = widgetNames + widgetName + ',';	
				}
				widgetNames = widgetNames.substr(0, widgetNames.length - 1);
				window.open(expURL+"&widgetnames=" + widgetNames,"_self");
			}
		});
	}
	else
	{
		widgetNames = '';
		for (var i=1 ; i<=3 ; i++)
		{
			for (var j=1 ; j<=3 ; j++)
			{
				if(getCookie("widget"+i+"X"+j))
				{
					var widgetName;
					widgetName = getCookie("widget"+i+"X"+j).split(':::')[0];
					if (widgetName != "undefined")
					{
						widgetNames = widgetNames + widgetName + ',';
					}
				}
				
			}
		}		
		widgetNames = widgetNames.substr(0, widgetNames.length - 1);
		window.open(expURL+"&widgetnames=" + widgetNames,"_self");
	}
}

function getMapItBits(objRequest,expURL)
{
	var MapitBitzName = trim(objRequest.responseText);
	MapitBitzName = MapitBitzName.substr(0, MapitBitzName.length - 1);
	window.open(expURL+"&widgetnames=" + MapitBitzName,"_self");
}

var timeDiff  =  {
    setStartTime:function (){
        d = new Date();
        time  = d.getTime();
    },

    getDiff:function (){
        d = new Date();
        return (d.getTime()-time);
    }
}
var bitzTabPrev="";
var bitzTabNew="";
function changeTabImg(newTabVal)
{
	if(bitzTabNew!="")
	{
		bitzTabPrev = bitzTabNew;
		bitzTabNew = newTabVal;
	}
	else
	{
		var dgidArrAll = document.getElementsByClassName("tabSelected","tabDiv");
		dgidArrAll.each(function(nd)
		{
		   bitzTabPrev = nd.id;
		});
		bitzTabNew = newTabVal;
	}
	$(bitzTabPrev).className = "tabs";	
	$(bitzTabNew).className = "tabSelected";
	/*
		var dgidArrAll = document.getElementsByClassName("tabSelected");
		dgidArrAll.each(function(nd)
		{
				$(nd.id).className = "tabs";
			
		});
		var gidArrAll = document.getElementsByClassName("tabs");
		gidArrAll.each(function(nd)
		{
			if((nd.id==event))
			{
				$(nd.id).className = "tabSelected";
			}
		});
	*/ 
}
function funMakeChatWindow(userType,toChatType)
{
	if(typeof(flagB)!=='undefined' && flagB)
		document.getElementById('tooltipMainB').style.display = 'none';
	if(typeof(flag)!=='undefined' && flag)
		document.getElementById('tooltipMain').style.display = 'none';
	initResizePanel("widgetPanel");
	$('widgetPanel_h').style.display='none';
	if(typeof(initResizePanel)!='undefined')
	{
		/*if(userType=="C")
		{
			$('msgerDiv').style.display="none";
			$('loginDiv').style.display="none";
			$('registerDiv').style.display="block";
		}
		else*/ if(userType=="SP")
		{
			location.href = "../../app/ajaxim/support.php";
		}
		else
		{
			pingTimer = setInterval(ping, pingFrequency);
			$('msgerDiv').style.display="block";
			/*$('loginDiv').style.display="none";
			$('registerDiv').style.display="none";*/
		}
	}
	else
	{
		alert("include Chat Window");
	}
		
}

// function for view a singleproperty landing page from the index page on go button, buyers and renters click
function callMapIt(callValue)
 {
	 if (callValue == "openhouse")
	 {
		if ($("houseCSZ") && ($("houseCSZ").value == "" || $F("houseCSZ").toLowerCase() == "required"))
		{
			alert ("Please enter a location.");
			return;
		}
	 }
	 else
	 {
 		if ( $("searchCSZ") && ($("searchCSZ").value == "" || $F("searchCSZ").toLowerCase() == "required"))
		{
			alert ("Please enter a location.");
			return;
		}
	 }

	if( $("searchCSZ") && (checkMultiCity() && (bkTheme == 'jonathan' || bkTheme == 'century21ah' || bkTheme == 'patrick') ) )
	{
		if (callValue == 'lSearch') {
			alert ('Please select single city location for Local Search.');
			return;
		}
		else if (callValue == 'rSearch') {
			alert ('Please select single city location for Recent Sales.');
			return;
		}
	}

	var strSearchCookie = getCookie("strSearchCookie");
	var latLong = eval(getCookie("latLongCk"))[0];
	var latitude = latLong.lat;
	var	longitude = latLong.lng;
	var addressVar = '';
	var cityVar = '';
	var stateVar = '';
	var zipVar = '';
	var priceVar = '';
	var bedVar = '';
	var bathVar = '';

	searchQueryString = 'status=EXP&address=';

	if(getSearchCookie("searchAddress") && getSearchCookie("searchAddress") != "")
		addressVar = escape(getSearchCookie("searchAddress").replace(/[,]/g, " "));

	if(getSearchCookie("city") && getSearchCookie("city") != "")
		cityVar = escape(getSearchCookie("city").replace(/[,]/g, " "))

	if(getSearchCookie("state") && getSearchCookie("state") != "")
		stateVar = escape(getSearchCookie("state").replace(/[,]/g, " "));

	if(getSearchCookie("zip") && getSearchCookie("zip") != "")
		zipVar = escape(getSearchCookie("zip").replace(/[,]/g, " "));

	searchQueryString = searchQueryString + addressVar + "," + cityVar + "," + stateVar + "," + zipVar + "," + priceVar + "," + bedVar + "," + bathVar+ "," + latitude+ "," + longitude;

	if (addressVar!="optional" && addressVar!="" && (!callValue) )
	{
		widgetNames = "mlsaddrsearch";
	}
	else
	{
		if(bkTheme == 'terabitz')
		{
			if(callValue == 'buyers')
				widgetNames = "forsalelisting,fsbo";
			else if(callValue == 'renters')
				widgetNames = "craiglistRental,apartments";
			else if(callValue == 'localsearch')
				widgetNames = "yelp,panoramio";	
			else if(callValue == 'foreclosures')
				widgetNames = "foreclosures";		
			else
			{
				// Check MLS access
				/* COMMENTED AS PER NEW INSTRUCTIONS
				var redirectRes = "";
				var redirectUrl = '/app/dashboard/findMlsAccess.php';
				var redirectQs = "city=" + cityVar + "&state=" + stateVar + "&zip=" + zipVar + "&propLat=" + latitude + "&propLong=" + longitude; 
				ajaxRequest(redirectUrl, redirectQs, function getPartnerRedirectUrl(originalRequest)
					{
						redirectRes = originalRequest.responseText;
						if (redirectRes != "0")
						{
							window.location.href = redirectRes;
							return;
						}
					}, false
				)
				*/
				var redirectRes = 0;
				// We dont have MLS access in this city
				if (redirectRes == "0")
				{
					var url = '/app/feed/selectDefaultBitz.php';
					var queryString = "";
					ajaxRequest(url,queryString,function resDefaultBitz(originalRequest)
						{
							 var response = originalRequest.responseText;
							 if(response!=0)
							 {
								widgetNames = response;
							 }
							 else
								widgetNames = "googlebase";
						},false
					);
				}
				else
				{
					// We already have MLS access, so dont execute next code
					return;
				}
			}
		}
		else if (bkTheme == 'jonathan' || bkTheme == 'century21ah' || bkTheme == 'patrick' || bkTheme == 'remax' || bkTheme == 'moneyworld' || bkTheme == 'ajcre' || bkTheme == 'ibr')
		{
			if(callValue == 'aSearch'){
				widgetNames = "brokeragents";
			}
			else if(callValue == 'lSearch' && bkTheme == 'moneyworld'){
				widgetNames = "panoramio";
			}
			else if(callValue == 'lSearch'){
				widgetNames = "yelp,panoramio";
			}
			else if(callValue == 'pSearch'){
				widgetNames = "mlsSearch,jbfeaturedlistings";
				if(bkTheme == 'remax' || bkTheme == 'moneyworld' || bkTheme == 'ibr')
				{
					widgetNames = "mlsCountySearch";
				}
			}
			else if(callValue == 'rSearch'){
				widgetNames = "recentsales";
			}
			else if (bkTheme == 'moneyworld' && callValue == 'fHome')
				widgetNames = "jbfeaturedlistings";
			else if(callValue == 'fHome'){
				widgetNames = "mlsfeatured";
			}
			else if(callValue == 'lServices' && bkTheme == 'patrick'){
				widgetNames = "contractors,mortgagecompanies,lshomeinspector,titleCompanies,moving";
			}
			else if(callValue == 'lServices' && bkTheme == 'jonathan'){
				widgetNames = "appraiser,attorney";
			}
			else if(callValue == 'lServices' && bkTheme == 'remax'){
				widgetNames = "appraiser,inspection";
			}
			else if(callValue == 'lServices'){
				widgetNames = "appraiser,attorney,inspection";
			}
			else if(callValue == 'baSearch'){
				widgetNames = "brokeragents";
			}
			else
			{
				var url = '/app/feed/selectDefaultBitz.php';
				var queryString = "";
				ajaxRequest(url,queryString,function resDefaultBitz(originalRequest)
					{
						var response = originalRequest.responseText;
						if(response!=0)
						{
							widgetNames = response;
						}
						else
						{
							widgetNames = "mlsSearch";
							if (bkTheme == 'remax')
							{
								widgetNames = "mlsCountySearch&mapZoomLevel=14";
							}
							else if(bkTheme == 'moneyworld' || bkTheme == 'ajcre')
							{
								widgetNames = "mlsCountySearch";
							}
						}
					},false
				);
			}
		}
		else if(bkTheme == 'lmsre')
		{
			if(callValue == 'airports')
				widgetNames = "airports";
			if(callValue == 'colleges')
				widgetNames = "colleges";
		}
		else
		{
			var url = '/app/feed/selectDefaultBitz.php';
			var queryString = "";
			ajaxRequest(url,queryString,function resDefaultBitz(originalRequest)
				{
					 var response = originalRequest.responseText;
					 if(response!=0)
					 {
						widgetNames = response;
					 }
					 else
					 {
						 if (bkTheme=='intero')
							widgetNames = "mlsCountySearch,jbfeaturedlistings&mapZoomLevel=14";
						 else if (bkTheme == "acbre" || bkTheme == "remax" || bkTheme == "moneyworld")
							 widgetNames = "mlsCountySearch&mapZoomLevel=14";
						 else
							widgetNames = "mlsSearch";
					}
				},false
			);		
		}
		
		//condition for intero from landing page to open homes in two pane
		if(callValue == "openhouse")
			widgetNames = "mlsopenhomes";
		
		//condition for acbre reo search
		if(callValue == "reolisting")
			widgetNames = "reolistings&valChkMapSearchSelect=0";

		if (widgetNames != '')
			widgetNames = widgetNames.substr(0, widgetNames.length);
	}
	
	if ( $('hdnOuid') ) 
	{
		ouid = $('hdnOuid').value;
		widgetNames = widgetNames + '&frm=frch&ouid='+ouid;
	}	
	location.href = '../../app/listing/singlePropertyLanding.php?' + searchQueryString + "&widgetnames=" + widgetNames;
 };

 //remove value of advance option value


//function for searching by mlsno from index page header//

function funReloadAdvertise()
{
	//if(window.frames['iframeAdvertise'])
	//{
	//	window.frames['iframeAdvertise'].location.href = "/getAdvertise.php";
	//}
}

function setSearchCookie(ckName,ckValue)
{
	var strSearchCookie = getCookie("strSearchCookie");
	var arrSearchCookie = new Array();
	if(strSearchCookie != null && strSearchCookie != "")
	{
		arrSearchCookie = strSearchCookie.split(':::');
	}
	var arrNameSearchCookie = new Array();
	var arrValueSearchCookie = new Array();
	
	if(arrSearchCookie.length > 0)
	{
		for(var i=0;i<arrSearchCookie.length;i++)
		{
			var arrKeyVal = arrSearchCookie[i].split('=');
			arrNameSearchCookie[arrNameSearchCookie.length] = trim(arrKeyVal[0]);
			arrValueSearchCookie[arrValueSearchCookie.length] = trim(arrKeyVal[1]);
		}	
	}
	if(arrNameSearchCookie.find(ckName) !== false )
	{
		var ckIndex = arrNameSearchCookie.find(trim(ckName));
		arrValueSearchCookie[ckIndex] = escape(ckValue);
	}	
	else
	{
		arrNameSearchCookie[arrNameSearchCookie.length] = trim(ckName);
		arrValueSearchCookie[arrValueSearchCookie.length] = trim(escape(ckValue));
	}
	
	var strSearchCookie = "";
	for(var j=0;j<arrNameSearchCookie.length;j++)
	{
		if(j==0)
			strSearchCookie = strSearchCookie + trim(arrNameSearchCookie[j]) + '=' + trim(arrValueSearchCookie[j]); 
		else
			strSearchCookie = strSearchCookie + ':::' + trim(arrNameSearchCookie[j]) + '=' + trim(arrValueSearchCookie[j]);
	}
	
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	
	setCookie("strSearchCookie",strSearchCookie,now);
}

function getSearchCookie(ckName)
{
	var strSearchCookie = getCookie("strSearchCookie");
	var arrSearchCookie = new Array();
	if(strSearchCookie != null && strSearchCookie != "")
	{
		arrSearchCookie = strSearchCookie.split(':::');
	}
	var arrNameSearchCookie = new Array();
	var arrValueSearchCookie = new Array();
	
	if(arrSearchCookie.length > 0)
	{
		for(var i=0;i<arrSearchCookie.length;i++)
		{
			var arrKeyVal = arrSearchCookie[i].split('=');
			arrNameSearchCookie[arrNameSearchCookie.length] = trim(arrKeyVal[0]);
			arrValueSearchCookie[arrValueSearchCookie.length] = trim(arrKeyVal[1]);
		}	
	}
	
	var returnCKValue = "";
	if(arrNameSearchCookie.find(trim(ckName)) !== false)
	{
		var ckIndex = arrNameSearchCookie.find(ckName);
		returnCKValue = trim(unescape(arrValueSearchCookie[ckIndex]));
	}
	return returnCKValue;
	
}

function removeSearchCookie(ckName)
{
	var strSearchCookie = getCookie("strSearchCookie");
	var arrSearchCookie = new Array();
	if(strSearchCookie != null && strSearchCookie != "")
	{
		arrSearchCookie = strSearchCookie.split(':::');
	}
	
	var arrNameSearchCookie = new Array();
	var arrValueSearchCookie = new Array();
	
	if(arrSearchCookie.length > 0)
	{
		for(var i=0;i<arrSearchCookie.length;i++)
		{
			var arrKeyVal = arrSearchCookie[i].split('=');
			if(arrKeyVal[0] != ckName)
			{
				arrNameSearchCookie[arrNameSearchCookie.length] = trim(arrKeyVal[0]);
				arrValueSearchCookie[arrValueSearchCookie.length] = trim(arrKeyVal[1]);
			}	
		}
		var strSearchCookie = "";
		for(var j=0;j<arrNameSearchCookie.length;j++)
		{
			if(j==0)
				strSearchCookie = strSearchCookie + trim(arrNameSearchCookie[j]) + '=' + trim(arrValueSearchCookie[j]); 
			else
				strSearchCookie = strSearchCookie + ':::' + trim(arrNameSearchCookie[j]) + '=' + trim(arrValueSearchCookie[j]);
		}
	
		var now = new Date();
		now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
		setCookie("strSearchCookie",strSearchCookie,now);
	}
}
function funClrQckLocSrchCookies()
{
	removeSearchCookie("searchAddress");
	removeSearchCookie("city");
	removeSearchCookie("state");
	removeSearchCookie("zip");
	removeSearchCookie("county");
	removeSearchCookie("neighborhood");
}
function funClrQckSrchCookies()
{
	removeSearchCookie("spanHTML");
	removeSearchCookie("spanStyleHTML");
	removeSearchCookie("searchAddress");
	removeSearchCookie("city");
 	removeSearchCookie("state");
	removeSearchCookie("zip");
	removeSearchCookie("county");
	removeSearchCookie("neighborhood");
	removeSearchCookie("minPrice");
	removeSearchCookie("maxPrice");
	removeSearchCookie("searchBeds");
	removeSearchCookie("minSize");
	removeSearchCookie("maxSize");
	removeSearchCookie("searchBaths");
	removeSearchCookie("searchType");
	removeSearchCookie("searchSortType");
	removeSearchCookie("ckLFDate");
	removeSearchCookie("ckLTDate");
	removeSearchCookie("propStyle");
	removeSearchCookie("neighborhood");
	//removeSearchCookie("parkingType");
	
	// for power search
	removeSearchCookie("mlsSource");
	removeSearchCookie("propType");
	removeSearchCookie("propStatus");
	removeSearchCookie("area");
	removeSearchCookie("polygon");
	removeSearchCookie("salePriceFrom");
	removeSearchCookie("salePriceTo");
	removeSearchCookie("minPSize");
	removeSearchCookie("maxPSize");
	removeSearchCookie("ckPLFDate");
	removeSearchCookie("ckPLTDate");
	removeSearchCookie("listAgentFnm");
	removeSearchCookie("listAgentLnm");
	removeSearchCookie("minLotSize");
	removeSearchCookie("maxLotSize");
	removeSearchCookie("fromAge");
	removeSearchCookie("toAge");
	removeSearchCookie("fromYear");
	removeSearchCookie("toYear");
	removeSearchCookie("marketDaysFrom");
	removeSearchCookie("marketDaysTo");
	removeSearchCookie("garage");
	removeSearchCookie("stories");
	removeSearchCookie("eleSchool");
	removeSearchCookie("midSchool");
	removeSearchCookie("highSchool");
	removeSearchCookie("saleDateFrom");
	removeSearchCookie("saleDateTo");
	removeSearchCookie("saleAgentFnm");
	removeSearchCookie("saleAgentLnm");
	removeSearchCookie("salePriceFrom");
	removeSearchCookie("salePriceTo");
	removeSearchCookie("powerradial");
	removeSearchCookie("listagtid");
	removeSearchCookie("saleagtid");
	removeSearchCookie("listoff");
	removeSearchCookie("saleoff");
	removeSearchCookie("fire");
	removeSearchCookie("pool");
	removeSearchCookie("roof");
	
	setAllCookieValue("mlssource");
	setAllCookieValue("proptype");
	setAllCookieValue("propstatus");
	setAllCookieValue("sqftp");
	setAllCookieValue("listdatep");
	setAllCookieValue("listagent");
	setAllCookieValue("lotsize");
	setAllCookieValue("age");
	setAllCookieValue("yearbuilt");
	setAllCookieValue("daysonmarket");
	setAllCookieValue("garage");
	setAllCookieValue("stories");
	setAllCookieValue("eleschool");
	setAllCookieValue("midschool");
	setAllCookieValue("highschool");
	setAllCookieValue("saledate");
	setAllCookieValue("saleprice");
	setAllCookieValue("saleagent");
	setAllCookieValue("area");
	setAllCookieValue("polygon");
	setAllCookieValue("listagtid");
	setAllCookieValue("listoff");
	setAllCookieValue("saleagtid");
	setAllCookieValue("saleoff");
	setAllCookieValue("roof");
	setAllCookieValue("fire");
	setAllCookieValue("pool");
	//---------------------------------

	setAllCookieValue(null);
	headerContent(null);
	funCloseAdvanceSearch();
	
	removeSearchCookie("spanStyleHTML");
	removeSearchCookie("propStyle")
	if($('prpStyleText')) $('prpStyleText').innerHTML = "";

	if(typeof(srTabs) != "undefined" && srTabs.getTab(0).get("active"))
	{
		srTabs.set('activeTab',srTabs.getTab(0),true);
		srTabs.getTab(0).refresh();
	}
}

/**
 * add and remove the MapIt cookie
 * @param bitzNm = BitName
 * @param oprn = 'add' to add cookie 'del' to remove cookie 
 */
function setMapItCookie(bitzNm,oprn)
{
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	var strMapitCK = getCookie("strMapitCK");
	var ckAr = new Array();
	if(strMapitCK == null || trim(strMapitCK) == "")
	{
		strMapitCK = "";
		ckAr.length = 0;
	}
	else
	{
		ckAr = strMapitCK.split(',').compact();
	}
	if(oprn == "add")
	{
		var isBitz = ckAr.in_array(bitzNm);
		if(isBitz === false)
		{
			ckAr[ckAr.length] = bitzNm;
			strMapitCK = "";
			for(var i=0;i<ckAr.length;i++)
			{
				if(strMapitCK != "")
				{
					strMapitCK = strMapitCK + ',';
				}
				strMapitCK = strMapitCK + ckAr[i]; 
			}
			if ( (bitzNm == "brokeragents" || bitzNm == "brokeroffices" ) && ( bkTheme == "intero" || bkTheme == "garygreene" || bkTheme == "raveis") );
			else
				setCookie("strMapitCK",strMapitCK,now);
		}
	}
	else if (oprn == "del")
	{
		var isBitz = ckAr.in_array(bitzNm);
		if(isBitz === false)
		{
			return;
		}
		else
		{
			ckAr.splice(isBitz,1);
		}
		strMapitCK = "";
		for(var i=0;i<ckAr.length;i++)
		{
			if(strMapitCK != "")
			{
				strMapitCK = strMapitCK + ',';
			}
			strMapitCK = strMapitCK + ckAr[i]; 
		}
		setCookie("strMapitCK",strMapitCK,now);
	}
}

/**
 * returns all the mapable bits in form of an array
 */
function getAllMapItCookie()
{
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	var strMapitCK = getCookie("strMapitCK");
	var ckAr = new Array();
	if(strMapitCK == null || trim(strMapitCK) == "")
	{
		strMapitCK = "";
		ckAr.length = 0;
	}
	else
	{
		ckAr = strMapitCK.split(',').compact();
	}
	return ckAr;
}

/**
 * set the mapit cookie to the list of mapable bits passed as an array
 */
function setAllMapItCookie(mapitBitsArray)
{
	for(i=0;i<mapitBitsArray.length;i++)
		setMapItCookie(mapitBitsArray[i],"add");
}

/**
 * set the mapit cookie to the list of mapable bits passed as an array
 */
function removeAllMapItCookie()
{
	var now = new Date();
	now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
	var strMapitCK = "";
	setCookie("strMapitCK",strMapitCK,now);
}


function setCSZValue(city, state, zip)
{
	var geoCSZStr = "";
	var multiCity = false;
	if ((city  == null) || (city =="") || (city  =="undefined"))
	{
		// Do nothing
	}
	else
	{
		if (city.indexOf('|') != -1)
			multiCity = true;
	}

	if (!multiCity && (zip  == null) || (zip =="") || (zip  =="undefined"))
	{
		// Do nothing
	}
	else
	{
		if (zip.indexOf('|') != -1)
			multiCity = true;
	}
	
	if (multiCity)
	{
		var cityArr = new Array();
		var stateArr = new Array();
		var zipArr = new Array();
		if ((city  == null) || (city =="") || (city  =="undefined"))
		{}
		else
		{
			cityArr = city.split('|');
		}
		if (state  =="" || state  =="undefined" || state  == null)
		{}
		else
		{
			stateArr = state.split('|');
		}
		if (zip =="" || zip  =="undefined" || zip  == null)
		{}
		else
		{
			zipArr = zip.split('|');
		}
		
		for (var i=0; i<cityArr.length; i++)
		{
			var currentCsz = "";
			if (cityArr[i]  == null || cityArr[i] == "")
			{}
			else
			{
				currentCsz += cityArr[i] + ", ";
			}
			if (stateArr[i]  == null || stateArr[i] == "")
			{}
			else
			{
				currentCsz += stateArr[i] + " ";
			}
			if (zipArr[i]  == null || zipArr[i] == "")
			{}
			else
			{
				currentCsz += zipArr[i];
			}
			
			if (currentCsz != "")
				geoCSZStr += trim(currentCsz) + ";";
				
			var geoCity 	= cityArr[i];
			var geoState 	= stateArr[i];
			var geoZip 		= zipArr[i];
			var geoCSZ 		= setCSZValue(geoCity, geoState,geoZip);
			var idTxtObj = 'searchCSZ'+ eval(i+1);
			if($(idTxtObj) != null)
				$(idTxtObj).value = trim(geoCSZ).replace (/^\s+/g, "").replace (/\s+$/g, "").replace (/\s+/g, " ");
		}
		if (geoCSZStr != "")
			geoCSZStr = geoCSZStr.substr(0, geoCSZStr.length-1);
	}
	else
	{
	 	if(city!=null)
	 	{
			if ((city  == null) || (city =="") || (city  =="undefined"))
			{
				
			}
			else
			{
				geoCSZStr = city + ", ";
			}
	 	}
	 	if(state!=null)
	 	{
			if (state  =="" || state  =="undefined" || state  == null)
			{
				
			}
			else
			{
				geoCSZStr += state +" ";
			}
	 	}
	 	if(zip!=null)
	 	{
			if (zip =="" || zip  =="undefined" || zip  == null)
			{
				
			}
			else
			{
				geoCSZStr += zip;
			}
	 	}
	}
	
 	if(trim(geoCSZStr) == "" )
 	{
 		geoCSZStr = "required";
 	}
 	return trim(geoCSZStr);
}
function funWrapText(str,len)
{
	if(str.length > len)
	{
		str = str.substr(0,len)+' ...';
	}
	return str;
}

function explore(page)
{	

	/* */
	// IF NEW LISTING THEN LAST 15 DAYS DATE DURATION WOULD BE SET
	if($('bit_select_box') && $F('bit_select_box') == 'newListing')
	{
		$("RStxtLFDate").value = listDate1;
		$("RStxtLTDate").value = listDate2;
		setSearchCookie("listType",$F('bit_select_box'));
	}
	else if($('bit_select_box') && $F('bit_select_box') != 'newListing')
	{
		lfDate = ''; ltDate = '';
		$("RStxtLFDate").value = '';
		$("RStxtLTDate").value = '';
		setSearchCookie("listType",$F('bit_select_box'));
	}
	setSearchCookie("ckLFDate",($("RStxtLFDate"))?($F("RStxtLFDate")):"");
	setSearchCookie("ckLTDate",($("RStxtLTDate"))?($F("RStxtLTDate")):"");



	if (countySearchEnabled == "0" && checkMultiCity() == false && trim(getSearchCookie("neighborhood")) != "")
	{
		setSearchCookie("county", "");
	}
	if ( bkTheme != "terabitz" && trim($("searchMLS").value) != "")
	{
		var allBitz = getAllMapItCookie().toString();
		allBitz = allBitz.split(",");

		if(allBitz.length >= 10)
		{	
			alert("Please close atleast one bit, then enter MLS Number.");
			return;
		}

		if (page=="agentSiteListing")
			searchByMlsNoAgentSite();
		else if(page == "singlePropPower")
		{
			if(typeof(powerSearch) != 'undefined' && powerSearch == "1" && (uRole == "EA" || uRole == "A"))
			{
				var mlsurl = "../../app/dashboard/mlsSearch.php";
			    var mlsstr = "mlsno="+trim($("searchMLS").value)+ "&forAlert=1&mlsSource="+getSearchCookie('mlsSource')+"&ignorestatus=1&theme="+bkTheme+"&aid="+uid;
				
				ajaxRequest(mlsurl,mlsstr,function(r){
					response = trim(r.responseText);
					if(response == '0')	           
					{
						alert('MLS NO. not found.');
						return;
					}
					else
					{
						dataArr = response.split("&")[1].split("=")[1].split(",");
						var city = dataArr[1];
						var state = dataArr[2];
						var zip = dataArr[3];
						var lat = dataArr[7];
						var lng = dataArr[8];

						setSearchCookie("city",city);
						setSearchCookie("state",state);
						setSearchCookie("zip",zip);

						var latLongStr = "[{'lat':'"+lat+"','lng':'"+lng+"'}]";
						var now = new Date();
						now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
						setCookie("latLongCk",latLongStr,now);

						setSearchCookie("mlsno",trim($("searchMLS").value));
						setSearchCookie("area","");
						setSearchCookie("polygon","");
						funExplorePowerSearch();
					}
				});
			}
		}
		else
			searchByMlsNo();
		return;
	}
	else if($("searchMLS").value != "" && ($("searchCSZ").value == "" || $F("searchCSZ").toLowerCase() == "required"))
	{
		alert("Please enter City,State or Zip along with MLS Number.");
		return;
	}
	else if($("searchMLS").value != "")
	{
		var myStatus = funCheckContradict();
		if(myStatus != null && myStatus != 0)
		{
			if (page=="agentSiteListing")
				searchByMlsNoAgentSite();
			else
				searchByMlsNo();
		}
		return;
	}
	var csz = $("searchCSZ").value.replace (/^\s+/g, '').replace (/\s+$/g, '').replace (/\s+/g, ' ');
	var addr= $("searchAddress").value.replace (/^\s+/g, '').replace (/\s+$/g, '').replace (/\s+/g, ' ');
	/*if (trim(csz) == "")
	{
		alert ("Please specify either City & State or Zip");
		return false;
	}
	else */
	if (trim(csz) == "" || trim(csz).toLowerCase() == "required")
	{
		if(page == "singlePropPower")
		{
			if($("txtArea") && $("txtArea").value == "")
			{
				alert ("Please specify either City & State or Zip");
				return false;
			}
			else
			{				
				var status = funSaveAdvanceSearch("power","singlePropPower");
				
				if(status == true)
				{
					if(getSearchCookie("mlsno") && getSearchCookie("mlsno") != "")
						setSearchCookie("mlsno","");
					funExplorePowerSearch();
				}
			}
		}
		else
		{
			alert ("Please specify either City & State or Zip");
			return false;
		}
	}
	else if ( addr!="optional" && addr!="")
	{
		var contradict = funCheckContradict();
		if(contradict != null && contradict != 0)
		{
			var contradict = funReloadAdvertise();

			if(typeof(powerSearch) != 'undefined' && powerSearch == "1" && (uRole == "EA" || uRole == "A"))
			{		
				/*
				[{"status":"0","originaladdress":"4214 E Arch Rd, Stockton, CA ","statuscode":"200","country":"US","accuracy":"8","address":"4214 E Arch Rd","state":"CA","city":"Stockton","zip":"95215","latitude":"37.905234","longitude":"-121.214809"}]
				*/
				var url = "../../classes/getCSZ.php";
			    var qs = "csz="+trim($("searchCSZ").value)+"&address="+addr;
				
				ajaxRequest(url,qs,function(r){
					response = eval('(' + trim(r.responseText) + ')');

					if(response[0].status == "0")
					{
						var addr = response[0].address;
						var city = response[0].city;
						var state = response[0].state;
						var zip = response[0].zip;
						var lat = response[0].latitude;
						var lng = response[0].longitude;

						setSearchCookie("searchAddress",addr);
						setSearchCookie("city",city);
						setSearchCookie("state",state);
						setSearchCookie("zip",zip);

						var latLongStr = "[{'lat':'"+lat+"','lng':'"+lng+"'}]";
						var now = new Date();
						now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
						setCookie("latLongCk",latLongStr,now);
							
						funExplorePowerSearch();
					}
				});
			}
			else
			{
				var allBitz = getAllMapItCookie().toString();
				allBitz = allBitz.split(",");

				if(allBitz.length >= 10)
				{	
					alert("Please close atleast one bit, then enter Address.");
					return;
				}
				funExploreMlsAddrMap();
			}
			
			return;
		}
	}
	else
	{
		var cszFromCk = setCSZValue(getSearchCookie("city"), getSearchCookie("state"), getSearchCookie("zip"));
		var contradict = funCheckContradict();
		if(contradict != null && contradict != 0)
		{
			var contradict = funReloadAdvertise();
			if(page == "index")
			{
				gotoDashBrd();
			}	
			else if(page=="dashboard")
			{
				funQckUpdateWidgets();		
			}
			else if(page=="singleProp")
			{
				funExploreOnMapit();
			}
			else if(page=="singlePropPower")
			{
				var status = funSaveAdvanceSearch("power","singlePropPower");
				
				if(status == true)
				{
					if(getSearchCookie("mlsno") && getSearchCookie("mlsno") != "" && $("searchCSZ").value != "")
					{
						setSearchCookie("mlsno","");
					}
					else
					{
						if($('searchCSZ') != null)
						{
							$('searchCSZ').value = $('searchCSZ').value.replace (/^\s+/g, "").replace (/\s+$/g, "").replace (/\s+/g, " ");
							if (trim(cszFromCk).toUpperCase() != trim($('searchCSZ').value).toUpperCase())
							{
								if(getSearchCookie("area") && getSearchCookie("area") == $("txtArea").value)
								{
									setSearchCookie("area","");
									setSearchCookie("polygon","");
								}
							}
						}	
					}
					funExplorePowerSearch();
				} 
			}
			else if(page=="agentSiteListing")
			{
				funAgentSiteSearch();
			}
		}	
	}	
}
function funAgentSiteSearch(page,valOrderBy,typeOrderBy,searchByMlsNo)
{
	var cbfnAgentSite = function(reqObj)
	{
		var response = trim(reqObj.responseText);
		var arrResponseCount = response.split('|==|');
		var responseCount = arrResponseCount[0];
		var responseHTML = arrResponseCount[1];
		$('listDiv').innerHTML = responseHTML;
		if(parseInt(responseCount) > 0)
		{
			$('propSortBar').style.display = 'block';
		}
	}
	var url = "./getListing.php";
	var qs = funGetSearchQueryString();

	var objQS = new Querystring();
	var aid = objQS.get('aid');
	
	qs = qs + "&aid="+aid;

	if(page != null)
	{
		qs = qs + "&page="+page;
	}
	else
	{
		qs = qs + "&page=1";
	}
	if(valOrderBy != null)
	{
		qs = qs + "&valOrderBy="+valOrderBy;
	}
	else
	{
		qs = qs + "&valOrderBy=price";
	}
	if(typeOrderBy != null)
	{
		qs = qs + "&typeOrderBy="+typeOrderBy;
	}
	else
	{
		qs = qs + "&typeOrderBy=asc";
	}
	if(searchByMlsNo != null)
	{
		qs = qs + "&MlsSearch="+searchByMlsNo;
	}
	else
	{
		qs = qs + "&MlsSearch=0";
	}
	$('listDiv').innerHTML = '';
	ajaxRequest(url,qs,cbfnAgentSite);
}

function searchByMlsNoAgentSite()
{
	var cbfnAgentSite = function(reqObj)
	{
		var response = trim(reqObj.responseText);
		var arrResponseCount = response.split('|==|');
		var responseCount = arrResponseCount[0];
		var responseHTML = arrResponseCount[1];
		$('listDiv').innerHTML = responseHTML;
		if(parseInt(responseCount) > 0)
		{
			$('propSortBar').style.display = 'block';
		}
	}
	var url = "./getListing.php";
	var qs = "";
        var objQS = new Querystring();
        var aid = objQS.get('aid');
        qs = qs + "&aid="+aid;


	var mlsNo = objQS.get('mlsno');
	if(mlsNo!=null && mlsNo!='')
	{
		qs = qs + "&MlsSearch="+mlsNo;
	}
	else
	{
		qs = qs + "&MlsSearch="+trim($("searchMLS").value);
	}

	//qs = qs + "&MlsSearch=1";
    qs = qs + "&valOrderBy=price";
    qs = qs + "&typeOrderBy=asc";

	$('listDiv').innerHTML = '';
	ajaxRequest(url,qs,cbfnAgentSite);
}

var	recordDialogBox = "";
var	agtOffDlgBox = "";
function searchByMlsNo()
{
	if ($("searchMLS").value == "")
	{
		alert("Please input MLS number to search.");
		$("searchMLS").value = "";
		$("searchMLS").focus();
		return;
	}
	var mlsno = trim($("searchMLS").value);
	var qStr = "mlsno="+escape(mlsno);
	qStr += "&city="	+ trim(getSearchCookie("city"));
	qStr += "&state="	+ trim(getSearchCookie("state"));
	qStr += "&zip="		+ trim(getSearchCookie("zip"));
	var myQs = new Querystring();
	var frm = myQs.get("frm");
	var aid = myQs.get("aid");
	var ouid = myQs.get("ouid");
	if(frm != null && trim(frm) == 'agt' && aid != null && trim(aid) != "")
	{
		if(typeof(strAgtMlsSrc) != 'undefined' && strAgtMlsSrc != null && strAgtMlsSrc.length > 0)
			qStr = qStr + "&mlsSource="	+ 	escape((trim(strAgtMlsSrc)));
		else
			qStr = qStr + "&mlsSource=";
		qStr = qStr + "&aid="		+ 	escape((trim(aid)));

		//agentsite statistics
		var city = getSearchCookie("city");
		var ad = getSearchCookie("searchAddress");
		var beds = getSearchCookie("searchBeds");
		var baths = getSearchCookie("searchBaths");
		var type = getSearchCookie("searchType");
		var minprice = getSearchCookie("minPrice");
		var maxprice = getSearchCookie("maxPrice");

		var url = "../../classes/emailStats.php";
		var qs = "from=search&aid="+aid+"&city="+city+"&type="+type+"&beds="+beds+"&baths="+baths+"&price="+minprice+"-"+maxprice+"&addr="+ad+"&mlsno="+mlsno;

		ajaxRequest(url,qs);
		//statistics done
	}
	else if (frm != null && trim(frm) == 'frch' && ouid != null && trim(ouid) != "")
	{
		if(typeof(strAgtMlsSrc) != 'undefined' && strAgtMlsSrc != null && strAgtMlsSrc.length > 0)
			qStr = qStr + "&mlsSource="	+ 	escape((trim(strAgtMlsSrc)));
		else
			qStr = qStr + "&mlsSource=";
		qStr = qStr + "&ouid="		+ 	escape((trim(ouid)));

		//agentsite statistics
		var city = getSearchCookie("city");
		var ad = getSearchCookie("searchAddress");
		var beds = getSearchCookie("searchBeds");
		var baths = getSearchCookie("searchBaths");
		var type = getSearchCookie("searchType");
		var minprice = getSearchCookie("minPrice");
		var maxprice = getSearchCookie("maxPrice");

		var url = "../../classes/emailStats.php";
		var qs = "from=search&ouid="+ouid+"&city="+city+"&type="+type+"&beds="+beds+"&baths="+baths+"&price="+minprice+"-"+maxprice+"&addr="+ad+"&mlsno="+mlsno;

		ajaxRequest(url,qs);
		//statistics done
	}
	var url  = "/app/dashboard/mlsSearch.php";
	ajaxRequest(url,qStr,cbfnSearchByMlsNo);
}

function funRedirectToMLS(urlMLS)
{
	funClrQckLocSrchCookies();
	removeAllMapItCookie();	
	var myQs = new Querystring();
	var frm = myQs.get("frm");
	var aid = myQs.get("aid");
	var	ouid = '';
	if ( $('hdnOuid') ) 
		ouid = $('hdnOuid').value;
	
	if(frm != null && trim(frm) == 'agt' && aid != null && trim(aid) != "")
	{
		urlMLS = urlMLS + '&frm=agt&aid='+aid;
	}
	else if(ouid != null && trim(ouid) != "")
	{
		urlMLS = urlMLS + '&frm=frch&ouid='+ouid;
	}
	
	window.location.href = unescape(urlMLS);
}

function cbfnSearchByMlsNo(originalRequest)
{
	var response = originalRequest.responseText;
	if (response == 0)
	{
		alert("MLS Number Not found.");
		$("searchMLS").value = "";
		$("searchMLS").focus();
		return;
	}
	else
	{
		if(response.include("|^|"))
		{
			var arrResponse = response.split("|^|");
			var strIH = new StringBuffer();
			strIH.append(' <div id="divMLSConfirmBox" style="background-color:#B0B0B0;display: none;border: 0px solid rgb(0, 0, 0); padding: 20px; height: 150px; width: 530px; position: fixed; top: 225px; left: 255px; visibility: inherit;" >');
			strIH.append(' 	<table cellspacing="0" cellpadding="0" bordercolor="red" border="0" style="width: 100%; height: 100%;">');
			strIH.append(' 		<tr style="height: 8px;">');
			strIH.append(' 			<td valign="bottom" class="crvTopLeft"></td>');
			strIH.append(' 			<td valign="bottom" class="crvTopMid" style="width: 500px;"></td>');
			strIH.append(' 			<td valign="bottom" class="crvTopRight"></td>');
			strIH.append(' 		</tr>');
			strIH.append(' 		<tr style="height: 90%;width:520px;">');
			strIH.append(' 			<td style="background-color: rgb(255, 255, 255);" class="crvLeftMid"></td>');
			strIH.append(' 			<td style="background-color: rgb(255, 255, 255);">');

			strIH.append('<table style="width:100%;height:100%">');
			strIH.append('<tr>');
			strIH.append('<td>');
			strIH.append('<img src="../../wt/'+bkTheme+'/images/common/imgConfirm.gif" alt="conform" />');
			strIH.append('</td>');
			strIH.append('<td  class="moduleDescText">');
			strIH.append('<div style="position: relative;font-size:11px;width: 79%;float: left;display: inline;padding-left: 5px;height:100%;vertical-align: middle;" align="left" id="divMLSConfirmMessageText">');
			strIH.append('&nbsp;');
			strIH.append('</div>');
			strIH.append('</td>');
			strIH.append('<tr>');
			strIH.append('<td colspan="2" align="center" valign="top">');
			strIH.append('<button style="width:50px;" onclick="javascript:myPopup();" class="lang" type="button" name="btnOK" id="btnOK">Yes</button>');
			strIH.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="lang" type="button" name="btnCancel" id="btnCancel" onclick="dlgMLSConfirmBox.hide();" style="width:50px;">No</button>');
			strIH.append('</td>');
			strIH.append('</tr>');
			strIH.append('</table>');

			strIH.append(' 			</td>');
			strIH.append(' 			<td style="background-color: rgb(255, 255, 255);" class="crvRightMid"></td>');
			strIH.append(' 		</tr>');
			strIH.append(' 		<tr style="height: 8px;">');
			strIH.append(' 			<td class="crvBotLeft"></td>');
			strIH.append(' 			<td class="crvBotMid"></td>');
			strIH.append(' 			<td class="crvBotRight"></td>');
			strIH.append(' 		</tr>');
			strIH.append(' 	</table>');
			strIH.append(' </div><style type="text/css">.closeMy{background-image:url(../../wt/'+bkTheme+'/images/common/close_dlgLog.gif);}</style>');
			
			myPopup = function()
			{
				response = arrResponse[1];
				dlgMLSConfirmBox.hide();
				loadMlsNumberProp(response);
				
			}

			function funRedirectToOther()
			{
				response = arrResponse[1];
				loadMlsNumberProp(response);
			}

			function funCnfrmRedirectToOther()
			{
				var closeBox = document.getElementsByClassName("close","divMLSConfirmBox")[0];
				if(closeBox)
				{
					closeBox.removeClassName("nonsecure");
					closeBox.addClassName("closeMy");
				}
				$('divMLSConfirmMessageText').innerHTML = "Redirecting to our Partners Site: <b>"+arrResponse[0]+"</b>";
				$("divMLSConfirmBox").style.display="block";	
				dlgMLSConfirmBox.show();
			}
			if($("divMLSConfirmBox") == null)
			{
				var myIH = strIH.toString();var myDiv = document.createElement("div");myDiv.innerHTML = myIH;document.body.appendChild(myDiv);							
				dlgMLSConfirmBox = createDialog('divMLSConfirmBox');
				
			}
			//funCnfrmRedirectToOther();				
			funRedirectToOther();
			//alert("Redirecting to our Partner's site '" + arrResponse[0] +"'");
			
		}
		else
		{
			loadMlsNumberProp(response);
		}
	}
}

function loadMlsNumberProp(response)
{
	var arrMlsRecords = new Array();	
	var arrRecords = new Array();	
	arrMlsRecords = response.split('\n');

	if(arrMlsRecords.length == 1)
	{
		arrRecords = arrMlsRecords[0].split('|');
		funRedirectToMLS(arrRecords[8]);
	}
	else
	{
		var mlsNumber;
		var detailRecords="";
		var startRecords;
		var recLen = arrMlsRecords.length;
		// Build table for div
		
		for(var i=0;i<recLen;i++)
		{
			arrRecords = arrMlsRecords[i].split('|');
			mlsNumber  = arrRecords[0];
			detailRecords += "<tr style=\"height:25px\"><td width=\"60%\" class=\"mlsLightBoxDescText\" align=\"left\" valign=\"top\">&nbsp;<a class=\"mlsHeadDis\" href=\"javascript:void(0);\" onclick=\"javascript:funRedirectToMLS(\'"+arrRecords[8]+"\');\"><b><span class=\"crsr\">"+arrRecords[1]+", "+arrRecords[2]+", "+arrRecords[3]+", "+arrRecords[4]+"</span></b></a></td><td width=\"15%\" class=\"mlsLightBoxDescText\" valign=\"top\">&nbsp;<a class=\"mlsHeadDis\" href=\"javascript:void(0);\" onclick=\"javascript:funRedirectToMLS(\'"+arrRecords[8]+"\');\"><b><span class=\"crsr\">"+num2money(arrRecords[5])+"</span></b></a></td><td width=\"15%\" class=\"mlsLightBoxDescText\" valign=\"top\">&nbsp;<a class=\"mlsHeadDis\" href=\"javascript:void(0);\" onclick=\"javascript:funRedirectToMLS(\'"+arrRecords[8]+"\');\"><b><span class=\"crsr\">"+arrRecords[6]+"-Br/"+arrRecords[7]+"-Ba</span></b></a></td></tr>";
		}			
		
		startRecords = "<table width=\"100%\" height=\"98%\" class=\"mlsLightBoxLableText\">";
		startRecords += "<tr style=\"height:25px\"><td class=\"mlsLightBoxTopLableText\" colspan=\"3\" align=\"left\" style=\"height:20px\">Total "+recLen+" listings were found. For more details, click on below link.</td></tr>";
		startRecords += "<tr><td height=\"5px\" colspan=\"3\"></td></tr>";
		startRecords = startRecords+detailRecords;
		startRecords += "</table>";
		
		if(typeof(recordDialogBox) == "string")
		{
			recordDialogBox = createDialog("recordsDialog");	
		}
		
		var ht = (recLen+1)*25;
		if(recLen>3)
			ht = "100%";
		else
		{
			if(isIE)
				ht = "85%";//ht+"px";
			else
				ht = "80%";//ht+"px";
		}
		$("recordsDialog").getElementsByClassName("bd")[0].style.height = ht;
		$("recordsDialog").getElementsByClassName("bd")[0].innerHTML = startRecords;
		$("recordsDialog").getElementsByClassName("hd")[0].innerHTML = "Listing Of MLS Number : "+mlsNumber;			
		$("recordsDialog").style.display="block";
		recordDialogBox.show();			
	}
}
function setAllToCookie(srchcrt,from)
{
	if(srchcrt == null)
	{
		if ($F("searchAddress").toLowerCase() == "optional" || $F("searchAddress") == "undefined" || $F("searchAddress") == null)
		{
			setSearchCookie("searchAddress","");
		}
		else
		{
			setSearchCookie("searchAddress",($("searchAddress"))?$F("searchAddress"):"");
		}
	}
	if(srchcrt == "neighborhood")
	{			
		if(typeof(from)!="undefined")
		{
			divId = "divNHood";
			chkAllId = "chbRSNHAll";
		}
		else
		{
			divId = "divSHDataNeighborHood";
			chkAllId = "chbSHNHAll";
		}
		var arrChkBox = $(divId).getElementsByTagName("input");
		var lenArrChkBox = arrChkBox.length;
		var strCKNH = "";
		for(var i=0;i<lenArrChkBox;i++)
		{
	    	if(arrChkBox[i].id == chkAllId && arrChkBox[i].checked == true)
	    	{
	    		strCKNH = 'all';
	    		break;
	    	}
			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
			{
				var valChkBox = arrChkBox[i].value;
				strCKNH = strCKNH + valChkBox + ",";  	
			}
		}
		if(strCKNH.charAt(strCKNH.length-1) == ',')
		{
			strCKNH = strCKNH.substr(0,eval(strCKNH.length-1));
		}
		setSearchCookie("neighborhood",strCKNH);
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == "county")
	{		
		var dv = "";
		if(typeof(from) != "undefined")
			dv = "divRSCounty";
		else
			dv = "divSHDataCounty";

		if($(dv))
		{
			var arrChkBox = $(dv).getElementsByTagName("input");
			var lenArrChkBox = arrChkBox.length;
			var strCKCounty = "";
			for(var i=0;i<lenArrChkBox;i++)
			{
				if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
				{
					var valChkBox = arrChkBox[i].value;
					strCKCounty = strCKCounty + valChkBox + ",";  	
				}
			}
			
			if(strCKCounty.charAt(strCKCounty.length-1) == ',')
			{
				strCKCounty = strCKCounty.substr(0,eval(strCKCounty.length-1));
			}

			if(trim(strCKCounty) != "")
			{
				setSearchCookie("county",strCKCounty);
				removeSearchCookie("neighborhood");
				headerContent("neighborhood");
			}
			else
			{
				// If no County selected then just remove county from cookie
				removeSearchCookie("county");
			}
		}
		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "price")
	{			
		setSearchCookie("minPrice",($("minPrice"))?(money2num($F("minPrice"))):"");
		setSearchCookie("maxPrice",($("maxPrice"))?(money2num($F("maxPrice"))):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "beds")
	{			
		var srchBds = "";
		var minBeds = trim($("searchBedsMin").value);
		if(minBeds == "0") minBeds = "";
		if(minBeds != "" && minBeds.indexOf(".") == (minBeds.length-1)) minBeds = minBeds+"0";
		if(minBeds != "" && minBeds.indexOf(".") == 0) minBeds = "0"+minBeds;

		var maxBeds = trim($("searchBedsMax").value)
		if(maxBeds == "0") maxBeds = "";
		if(maxBeds != "" && maxBeds.indexOf(".") == (maxBeds.length-1)) maxBeds = maxBeds+"0";
		if(maxBeds != "" && maxBeds.indexOf(".") == 0) maxBeds = "0"+maxBeds;

		srchBds = minBeds+"-"+maxBeds;
		if(trim(srchBds) == "-")
			srchBds = "";
		setSearchCookie("searchBeds",srchBds);

		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sqft")
	{			
		setSearchCookie("minSize",($("minSize"))?$F("minSize")==0?"":$F("minSize"):"");
		setSearchCookie("maxSize",($("maxSize"))?$F("maxSize")==0?"":$F("maxSize"):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "baths")
	{			
		var srchBths = "";
		var minBath = trim($("searchBathsMin").value);
		if(minBath == "0") minBath = "";
		if(minBath != "" && minBath.indexOf(".") == (minBath.length-1)) minBath = minBath+"0";
		if(minBath != "" && minBath.indexOf(".") == 0) minBath = "0"+minBath;

		var maxBath = trim($("searchBathsMax").value);
		if(maxBath == "0") maxBath = "";
		if(maxBath != "" && maxBath.indexOf(".") == (maxBath.length-1)) maxBath = maxBath+"0";
		if(maxBath != "" && maxBath.indexOf(".") == 0) maxBath = "0"+maxBath;

		srchBths = minBath+"-"+maxBath;
		if(trim(srchBths) == "-")
			srchBths = "";
		setSearchCookie("searchBaths",srchBths);

		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "type")
	{
		if(typeof(from)!="undefined")
		{
			divId = "divRSType";
			chkAllId = "RSchbSHTypeAll";
		}
		else
		{
			divId = "divPopUpSHType";
			chkAllId = "chbSHTypeAll";
		}
		var arrChkBox = $(divId).getElementsByTagName("input");
		var lenChkBox = arrChkBox.length;		
		var strChkBox = "";
		var allChked = true;		
		for(var i=0;i<lenChkBox;i++)
		{			
	    	if(arrChkBox[i].id == chkAllId)
	    	{
	    		continue;
	    	}
	    	if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
	    	{
	    	    var valChkBox = arrChkBox[i].value;
	    	    strChkBox = strChkBox + valChkBox + ':';				
	    	}
	    	else if(arrChkBox[i].type == "checkbox")
	    	{
	    	    allChked = false;    
	    	}
		}
		if(allChked == true)
		{
	    	strChkBox = "";
		}
		else if(strChkBox.charAt(strChkBox.length-1) == ':')
		{
			strChkBox = strChkBox.substr(0,eval(strChkBox.length-1));
		}		
		setSearchCookie("searchType",strChkBox);		
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sortby")
	{			
		setSearchCookie("searchSortType",($("searchSortType"))?$F("searchSortType"):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "listdate")
	{			
		setSearchCookie("ckLFDate",($("txtLFDate"))?($F("txtLFDate")):"");
		setSearchCookie("ckLTDate",($("txtLTDate"))?($F("txtLTDate")):"");
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "mlssource")
	{
		setSearchCookie("mlsSource",($("mlsSource"))?($F("mlsSource")):"");
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "proptype" && $("divPType"))
	{			
		//setSearchCookie("propType",($("propTypes"))?($F("propTypes")):"");			
		var arrChkBox = $("divPType").getElementsByTagName("input");
		var strChkd = "";

		for(i=0;i<arrChkBox.length;i++)
		{
			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
	    	{
				strChkd += arrChkBox[i].value + ':';
			}
		}
		
		if(strChkd.charAt(strChkd.length-1) == ':')
			strChkd = strChkd.substr(0,eval(strChkd.length-1));

		setSearchCookie("propType",strChkd);

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "propstatus" && $("divPStatus"))
	{
		/*setSearchCookie("propStatus",($("propStatus"))?($F("propStatus")):"");
		if(srchcrt != null)
		{
			return;
		}*/

		var arrChkBox = $("divPStatus").getElementsByTagName("input");
		var strChkd = "";

		for(i=0;i<arrChkBox.length;i++)
		{
			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
	    	{
				strChkd += arrChkBox[i].value + ':';
			}
		}
		
		if(strChkd.charAt(strChkd.length-1) == ':')
			strChkd = strChkd.substr(0,eval(strChkd.length-1));

		setSearchCookie("propStatus",strChkd);

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "sqftp")
	{
		setSearchCookie("minPSize",($("minPSize"))?$F("minPSize")==0?"":$F("minPSize"):"");
		setSearchCookie("maxPSize",($("maxPSize"))?$F("maxPSize")==0?"":$F("maxPSize"):"");
		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "listagent")
	{
		if($('txtAgtFName').value != 'First Name')
			setSearchCookie("listAgentFnm",($("txtAgtFName"))?($F("txtAgtFName")):"");
		else
			setSearchCookie("listAgentFnm","");

		if($('txtAgtLName').value != 'Last Name')				
			setSearchCookie("listAgentLnm",($("txtAgtLName"))?($F("txtAgtLName")):"");
		else
			setSearchCookie("listAgentLnm","");

		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "listdatep")
	{			
		setSearchCookie("ckPLFDate",($("txtPLFDate"))?($F("txtPLFDate")):"");
		setSearchCookie("ckPLTDate",($("txtPLTDate"))?($F("txtPLTDate")):"");
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "lotsize")
	{
		setSearchCookie("minLotSize",($("minLotSize"))?$F("minLotSize")==0?"":$F("minLotSize"):"");
		setSearchCookie("maxLotSize",($("maxLotSize"))?$F("maxLotSize")==0?"":$F("maxLotSize"):"");
		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "age")
	{			
		setSearchCookie("fromAge",($("txtAgeFrom"))?(money2num($F("txtAgeFrom"))):"");
		setSearchCookie("toAge",($("txtAgeTo"))?(money2num($F("txtAgeTo"))):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "yearbuilt")
	{			
		setSearchCookie("fromYear",($("txtYearBuiltFrom"))?(money2num($F("txtYearBuiltFrom"))):"");
		setSearchCookie("toYear",($("txtYearBuiltTo"))?(money2num($F("txtYearBuiltTo"))):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "daysonmarket")
	{			
		setSearchCookie("marketDaysFrom",($("txtDaysMarketFrom"))?(money2num($F("txtDaysMarketFrom"))):"");
		setSearchCookie("marketDaysTo",($("txtDaysMarketTo"))?(money2num($F("txtDaysMarketTo"))):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "garage")
	{			
		if(typeof(from)!="undefined")
			var cmbId = "RScmbGarage";
		else
			var cmbId = "cmbGarage";

		setSearchCookie("garage",($(cmbId))?$F(cmbId)==0?"":$F(cmbId):"");

		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "stories")
	{			
		setSearchCookie("stories",($("txtStories"))?($F("txtStories")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "bankowned")
	{			
		setSearchCookie("bankowned",$("chkBankOwned").checked);
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "shortsales")
	{			
		setSearchCookie("shortsales",$("chkShortSales").checked);
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "schooldist")
	{			
		setSearchCookie("schooldist",($("txtSchoolDist"))?($F("txtSchoolDist")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "eleschool")
	{			
		setSearchCookie("eleSchool",($("txtEleSchool"))?($F("txtEleSchool")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "midschool")
	{			
		setSearchCookie("midSchool",($("txtMidSchool"))?($F("txtMidSchool")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "highschool")
	{			
		setSearchCookie("highSchool",($("txtHighSchool"))?($F("txtHighSchool")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saledate")
	{			
		setSearchCookie("saleDateFrom",($("txtSFDate"))?($F("txtSFDate")):"");
		setSearchCookie("saleDateTo",($("txtSTDate"))?($F("txtSTDate")):"");
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleprice")
	{			
		setSearchCookie("salePriceFrom",($("txtSalePriceFrom"))?(money2num($F("txtSalePriceFrom"))):"");
		setSearchCookie("salePriceTo",($("txtSalePriceTo"))?(money2num($F("txtSalePriceTo"))):"");
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "saleagent")
	{
		if($('txtSaleAgentFname').value != 'First Name')
			setSearchCookie("saleAgentFnm",($("txtSaleAgentFname"))?($F("txtSaleAgentFname")):"");
		else
			setSearchCookie("saleAgentFnm","");

		if($('txtSaleAgentLname').value != 'Last Name')				
			setSearchCookie("saleAgentLnm",($("txtSaleAgentLname"))?($F("txtSaleAgentLname")):"");
		else
			setSearchCookie("saleAgentLnm","");

		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "area")
	{			
		setSearchCookie("area",($("txtArea"))?($F("txtArea")):"");		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "polygon")
	{			
		setSearchCookie("polygon",($("txtPolygon"))?($F("txtPolygon")):"");		
		//alert(getSearchCookie("polygon"))
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "powerradial")
	{			
		setSearchCookie("powerradial",$F("cmbradial"));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "listagtid")
	{			
		setSearchCookie("listagtid",trim($F("txtListAgtId")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "listoff")
	{			
		setSearchCookie("listoff",trim($F("txtListOff")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleagtid")
	{			
		setSearchCookie("saleagtid",trim($F("txtSaleAgtId")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleoff")
	{			
		setSearchCookie("saleoff",trim($F("txtSaleOff")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "roof")
	{			
		setSearchCookie("roof",trim($F("txtRoof")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "fire")
	{			
		setSearchCookie("fire",trim($F("cmbFire")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "pool")
	{			
		setSearchCookie("pool",trim($F("cmbPool")));

		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "propstyle")
	{		
		if(typeof(from)!="undefined")
		{
			divId = "RSpropStyleDv";
			chkAllId = "RSchkStyleAll";
		}
		else
		{
			divId = "propStyleDv";
			chkAllId = "chkStyleAll";
		}

		if($(divId))
		{
			var arrChkBox = $(divId).getElementsByTagName("input");
			var lenChkBox = arrChkBox.length;
			var strChkBox = "";
			var allChked = true;
			for(var i=0;i<lenChkBox;i++)
			{
				if(arrChkBox[i].id == chkAllId)
				{
					continue;
				}
				if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
				{
					var valChkBox = arrChkBox[i].value;
					strChkBox = strChkBox + valChkBox + ':';
				}
				else if(arrChkBox[i].type == "checkbox")
				{
					allChked = false;    
				}
			}
			if(allChked == true)
			{
				strChkBox = "";
			}
			else if(strChkBox.charAt(strChkBox.length-1) == ':')
			{
				strChkBox = strChkBox.substr(0,eval(strChkBox.length-1));
			}
			setSearchCookie("propStyle",strChkBox);
		}
		else
			setSearchCookie("propStyle","");

		if(srchcrt != null)
		{
			return;
		}
	}
	/*if(srchcrt == null || srchcrt == "parkingtype")
	{
		if($("parkingStyleDv"))
		{
			var arrChkBox = $("parkingStyleDv").getElementsByTagName("input");
			var lenChkBox = arrChkBox.length;
			var strChkBox = "";
			var allChked = true;
			for(var i=0;i<lenChkBox;i++)
			{
				if(arrChkBox[i].id == "chkParkingStyleAll")
				{
					continue;
				}
				if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
				{
					var valChkBox = arrChkBox[i].value;
					strChkBox = strChkBox + valChkBox + ':';
				}
				else if(arrChkBox[i].type == "checkbox")
				{
					allChked = false;    
				}
			}
			if(allChked == true)
			{
				strChkBox = "";
			}
			else if(strChkBox.charAt(strChkBox.length-1) == ':')
			{
				strChkBox = strChkBox.substr(0,eval(strChkBox.length-1));
			}
			setSearchCookie("parkingType",strChkBox);
		}
		else
			setSearchCookie("parkingType","");

		if(srchcrt != null)
		{
			return;
		}
	}*/
}
function setAllCookieValue(srchcrt)
{
	
	if(srchcrt == null)
	{
		if($("searchAddress"))
		{
			
			$("searchAddress").value = (trim(getSearchCookie("searchAddress")) == "")?"optional":trim(getSearchCookie("searchAddress"));
			$("searchAddress").className = "textboxDashHdN";
		}
		if($('searchCSZ'))
		{
			var cszFromCookie = setCSZValue(getSearchCookie("city"), getSearchCookie("state"), getSearchCookie("zip"));
			$('searchCSZ').value = trim(cszFromCookie).replace (/^\s+/g, "").replace (/\s+$/g, "").replace (/\s+/g, " ");
			if(trim(getSearchCookie('city')) == "" && trim(getSearchCookie('zip')) == "")
			{
				for(var i=0;i<20;i++)
				{
					var idTxtObj = 'searchCSZ'+ eval(i+1);
					if($(idTxtObj) != null)
						$(idTxtObj).value = "";
				}
			}	
		}
		if($('searchMLS'))
		{
			$('searchMLS').value = "";
		}
	}	
	if(srchcrt == null || srchcrt == "price")
	{
		if($("minPrice"))
		{
			if(getSearchCookie("minPrice") != 0)
				$("minPrice").value = addCommas(getSearchCookie("minPrice"));
			else 
				$("minPrice").value = '';
		}
		if($("maxPrice"))
		{
			if(getSearchCookie("maxPrice") != 0)
				$("maxPrice").value = addCommas(getSearchCookie("maxPrice"));
			else 
				$("maxPrice").value = '';
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "beds")
	{
		if(getSearchCookie("searchBeds") && $("searchBedsMin") && $("searchBedsMax"))
		{
			var beds = getSearchCookie("searchBeds");
			if(trim(beds) == "")
			{
				$("searchBedsMin").value = "";
				$("searchBedsMax").value = "";
			}
			else
			{
				var bdArr = beds.split("-");
				$("searchBedsMin").value = bdArr[0];
				$("searchBedsMax").value = bdArr[1];
			}
		}
		else
		{
			if($("searchBedsMin") && $("searchBedsMax"))
			{
				$("searchBedsMin").value = "";
				$("searchBedsMax").value = "";
			}
		}		
		
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sqft")
	{
		if(getSearchCookie("minSize") && $("minSize"))
		{
			$("minSize").value = getSearchCookie("minSize");
		}
		else if($("minSize"))
		{
			$("minSize").selectedIndex = 0;
		}
		if(getSearchCookie("maxSize") && $("maxSize"))
		{
			$("maxSize").value = getSearchCookie("maxSize");
		}
		else if($("maxSize"))
		{
			$("maxSize").selectedIndex = 0;
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "baths")
	{
		if(getSearchCookie("searchBaths") && $("searchBathsMin") && $("searchBathsMax"))
		{
			var baths = getSearchCookie("searchBaths");
			if(trim(baths) == "")
			{
				$("searchBathsMin").value = "";
				$("searchBathsMax").value = "";
			}
			else
			{
				var bthArr = baths.split("-");
				$("searchBathsMin").value = bthArr[0];
				$("searchBathsMax").value = bthArr[1];
			}
		}
		else
		{
			if($("searchBathsMin") && $("searchBathsMax"))
			{
				$("searchBathsMin").value = "";
				$("searchBathsMax").value = "";
			}
		}

		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "type")
	{
		if(getSearchCookie("searchType") || trim(getSearchCookie("searchType")) == "")
		{
			if($("divPopUpSHType"))
			{
				var arrChkBox = $("divPopUpSHType").getElementsByTagName("input");
				var lenChkBox = arrChkBox.length;
				var strChkBox = getSearchCookie("searchType");
				if(trim(strChkBox) == "")
				{
					
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chbSHTypeAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == false)
		    			{
		    				arrChkBox[i].checked = true;
		    			}
					}	
				}
				else
				{
					var arrStrChkBox = strChkBox.split(":");
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chbSHTypeAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox")
		    			{
		    				var valChkBox = arrChkBox[i].value;
		    				if(arrStrChkBox.in_array(valChkBox) !== false)
		    				{
		    					arrChkBox[i].checked = true;
		    				}
							else
							{
								arrChkBox[i].checked = false;
							}
		    			}
					}	
				}
			}
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sortby")
	{
		if(getSearchCookie("searchSortType") && $("searchSortType"))
		{
			$("searchSortType").value = getSearchCookie("searchSortType");
		}
		else if($("searchSortType"))
		{
			$("searchSortType").selectedIndex = 0;
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "listdate")
	{
		if(getSearchCookie("ckLFDate") && $("txtLFDate"))
		{
			$("txtLFDate").value = getSearchCookie("ckLFDate");
		}
		else if($("txtLFDate"))
		{
			$("txtLFDate").value = '';
		}
		if(getSearchCookie("ckLTDate") && $("txtLTDate"))
		{
			$("txtLTDate").value = getSearchCookie("ckLTDate");
		}
		else if($("txtLTDate"))
		{
			$("txtLTDate").value = '';
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "propstyle")
	{
		if(getSearchCookie("propStyle") || trim(getSearchCookie("propStyle")) == "")
		{
			if($("propStyleDv"))
			{
				var arrChkBox = $("propStyleDv").getElementsByTagName("input");
				var lenChkBox = arrChkBox.length;
				var strChkBox = getSearchCookie("propStyle");
				if(trim(strChkBox) == "")
				{					
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chkStyleAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == false)
		    			{
		    				arrChkBox[i].checked = true;
		    			}
					}	
				}
				else
				{
					var arrStrChkBox = strChkBox.split(":");
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chkStyleAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox")
		    			{
		    				var valChkBox = arrChkBox[i].value;
		    				if((arrStrChkBox.in_array(valChkBox) !== false) && (arrChkBox[i].checked == false))
		    				{
		    					arrChkBox[i].checked = true;
		    				}
		    			}
					}	
				}
			}
		}

		if(srchcrt != null)
		{
			return;
		}
	}
	/*if(srchcrt == null || srchcrt == "parkingtype")
	{
		if(getSearchCookie("parkingType") || trim(getSearchCookie("parkingType")) == "")
		{
			if($("parkingStyleDv"))
			{
				var arrChkBox = $("parkingStyleDv").getElementsByTagName("input");
				var lenChkBox = arrChkBox.length;
				var strChkBox = getSearchCookie("parkingType");
				if(trim(strChkBox) == "")
				{					
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chkParkingStyleAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == false)
		    			{
		    				arrChkBox[i].checked = true;
		    			}
					}	
				}
				else
				{
					var arrStrChkBox = strChkBox.split(":");
					for(var i=0;i<lenChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chkParkingStyleAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox")
		    			{
		    				var valChkBox = arrChkBox[i].value;
		    				if((arrStrChkBox.in_array(valChkBox) !== false) && (arrChkBox[i].checked == false))
		    				{
		    					arrChkBox[i].checked = true;
		    				}
		    			}
					}	
				}
			}
		}

		if(srchcrt != null)
		{
			return;
		}
	}*/
	
	if(srchcrt != null && srchcrt == "mlssource")
	{
		if(getSearchCookie("mlsSource") && $("mlsSource"))
		{
			$("mlsSource").value = getSearchCookie("mlsSource").replace(/[+]/g, ' ');
		}
		else if($("mlsSource"))
		{
			$("mlsSource").selectedIndex = 0;
		}
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt != null && srchcrt == "propstatus")
	{
		/*if(getSearchCookie("propStatus") && $("propStatus"))
		{
			$("propStatus").value = getSearchCookie("propStatus");
		}
		else if($("propStatus"))
		{
			//$("propStatus").selectedIndex = 0;
			len = $("propStatus").options.length;
			var j;
			var status = 0;
			var defaultStatus = "";
			if(len>0)
			{
				for(j=0;j<len;j++)
				{
					if($("propStatus").options[j].value == 'Active')
					{
						defaultStatus = $("propStatus").options[j].value;
						status = 1;
					}
					else if(status==0)
					{
						defaultStatus = $("propStatus").options[0].value;
					}
				}
			}
			$("propStatus").value = defaultStatus;
		}
		if(srchcrt != null)
		{
			return;
		}*/

		var status = getSearchCookie("propStatus");

		if(status != '')
		{
			if($('divPStatus'))
			{				
				var dataArr = status.split(":");
				chkbxArr = $A($('divPStatus').getElementsByTagName("input"));
				chkbxArr.each(
					function(node)
					{				
						if(node.type == "checkbox" && node.checked == true)
							node.checked = false;

						if(node.type == "checkbox" && dataArr.indexOf(node.value) != -1)
							node.checked = true;
					});			
			}
		}
		else
		{
			if($('divPStatus'))
			{
				var stat = 0;
				chkbxArr = $A($('divPStatus').getElementsByTagName("input"));
				chkbxArr.each(
					function(node)
					{
						if(node.type=="checkbox" && (node.id == 'Active'))
						{
							node.checked = true;
							stat = 1;
						}
						else
							node.checked = false;
					});
					
				if(stat == 0)
				{
					var unstat = 0;
					$A($('divPStatus').getElementsByTagName("input")).each(function(node)
					{
						if(node.type=="checkbox" && unstat == 0)
						{
							node.checked = true;
							unstat = 1;
						}
					});
				}
			}
		}

		if(srchcrt != null)
		{
			return;
		}
	}
	
	if(srchcrt != null && srchcrt == "proptype")
	{		
		var types = getSearchCookie("propType");	

		if(types != '')
		{
			if($('divPType'))
			{
				var dataArr = types.split(":");
				chkbxArr = $A($('divPType').getElementsByTagName("input"));
				chkbxArr.each(
					function(node)
					{				
						if(node.type == "checkbox" && node.checked == true)
							node.checked = false;

						if(node.type == "checkbox" && dataArr.indexOf(node.value) != -1)
							node.checked = true;
					});			
			}
		}
		else
		{
			if($('divPType'))
			{
				chkbxArr = $A($('divPType').getElementsByTagName("input"));
				chkbxArr.each(
					function(node)
					{
						if(node.type=="checkbox" && (node.id == 'Single Family Residential' || node.id == 'Residential' || node.id == 'Single Family' || node.id == 'Single Family Homes'))
							node.checked = true;
						else
							node.checked = false;
					});			
			}
		}

		if(srchcrt != null)
		{
			return;
		}
	}
	
	if(srchcrt != null && srchcrt == "sqftp")
	{
		if(getSearchCookie("minPSize") && $("minPSize"))
		{
			$("minPSize").value = getSearchCookie("minPSize");
		}
		else if($("minPSize"))
		{
			$("minPSize").value = "";
		}
		if(getSearchCookie("maxPSize") && $("maxPSize"))
		{
			$("maxPSize").value = getSearchCookie("maxPSize");
		}
		else if($("maxPSize"))
		{
			$("maxPSize").value = "";
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	
	if(srchcrt != null && srchcrt == "listdatep")
	{
		if(getSearchCookie("ckPLFDate") && $("txtPLFDate"))
		{
			$("txtPLFDate").value = getSearchCookie("ckPLFDate");
		}
		else if($("txtPLFDate"))
		{
			$("txtPLFDate").value = '';
		}
		if(getSearchCookie("ckPLTDate") && $("txtPLTDate"))
		{
			$("txtPLTDate").value = getSearchCookie("ckPLTDate");
		}
		else if($("txtPLTDate"))
		{
			$("txtPLTDate").value = '';
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	
	if(srchcrt != null && srchcrt == "listagent")
	{
		if(getSearchCookie("listAgentFnm") && $("txtAgtFName"))
		{
			$("txtAgtFName").value = getSearchCookie("listAgentFnm");
		}
		else if($("txtAgtFName"))
		{
			$("txtAgtFName").value = 'First Name';
		}
		
		if(getSearchCookie("listAgentLnm") && $("txtAgtLName"))
		{
			$("txtAgtLName").value = getSearchCookie("listAgentLnm");
		}
		else if($("txtAgtLName"))
		{
			$("txtAgtLName").value = 'Last Name';
		}
		if(srchcrt != null)
		{
			return;
		}		
	}	
	
	if(srchcrt != null && srchcrt == "lotsize")
	{
		if(getSearchCookie("minLotSize") && $("minLotSize"))
		{
			$("minLotSize").value = getSearchCookie("minLotSize");
		}
		else if($("minLotSize"))
		{
			$("minLotSize").value = "";
		}
		
		if(getSearchCookie("maxLotSize") && $("maxLotSize"))
		{
			$("maxLotSize").value = getSearchCookie("maxLotSize");
		}
		else if($("maxLotSize"))
		{
			$("maxLotSize").value = "";
		}
		
		if(srchcrt != null)
		{
			return;
		}		
	}
	
	if(srchcrt != null && srchcrt == "age")
	{			
		if(getSearchCookie("fromAge") && $("txtAgeFrom"))
		{
			$("txtAgeFrom").value = getSearchCookie("fromAge");
		}
		else if($("txtAgeFrom"))
		{
			$("txtAgeFrom").value = '';
		}
		
		if(getSearchCookie("toAge") && $("txtAgeTo"))
		{
			$("txtAgeTo").value = getSearchCookie("toAge");
		}
		else if($("txtAgeTo"))
		{
			$("txtAgeTo").value = '';
		}
		
		if(srchcrt != null)
		{
			return;
		}
	}
	
	if(srchcrt != null && srchcrt == "yearbuilt")
	{			
		if(getSearchCookie("fromYear") && $("txtYearBuiltFrom"))
		{
			$("txtYearBuiltFrom").value = getSearchCookie("fromYear");
		}
		else if($("txtYearBuiltFrom"))
		{
			$("txtYearBuiltFrom").value = '';
		}
		
		if(getSearchCookie("toYear") && $("txtYearBuiltTo"))
		{
			$("txtYearBuiltTo").value = getSearchCookie("toYear");
		}
		else if($("txtYearBuiltTo"))
		{
			$("txtYearBuiltTo").value = '';
		}
		
		if(srchcrt != null)
		{
			return;
		}
	}	
	
	if(srchcrt != null && srchcrt == "daysonmarket")
	{			
		if(getSearchCookie("marketDaysFrom") && $("txtDaysMarketFrom"))
		{
			$("txtDaysMarketFrom").value = getSearchCookie("marketDaysFrom");
		}
		else if($("txtDaysMarketFrom"))
		{
			$("txtDaysMarketFrom").value = '';
		}
		if(getSearchCookie("marketDaysTo") && $("txtDaysMarketTo"))
		{
			$("txtDaysMarketTo").value = getSearchCookie("marketDaysTo");
		}
		else if($("txtDaysMarketTo"))
		{
			$("txtDaysMarketTo").value = '';
		}
		
		if(srchcrt != null)
		{
			return;
		}
	}
			
	if(srchcrt != null && srchcrt == "garage")
	{	
		if(getSearchCookie("garage") && $("cmbGarage"))
		{
			$("cmbGarage").value = getSearchCookie("garage").replace(/[+]/g, ' ');
		}
		else if($("cmbGarage"))
		{
			$("cmbGarage").selectedIndex = 0;
		}
		
		if(srchcrt != null)
		{
			return;
		}		
	}	

	if(srchcrt != null && srchcrt == "stories")
	{			
		if(getSearchCookie("stories") && $("txtStories"))
		{
			$("txtStories").value = getSearchCookie("stories");
		}
		else if($("txtStories"))
		{
			$("txtStories").value = '';
		}	
		if(srchcrt != null)
		{
			return;
		}
	}
	
	if(srchcrt != null && srchcrt == "schooldist")
	{			
		if(getSearchCookie("schooldist") && $("txtSchoolDist"))
		{
			$("txtSchoolDist").value = getSearchCookie("schooldist").replace(/[+]/g, ' ');
		}
		else if($("txtSchoolDist"))
		{
			$("txtSchoolDist").value = '';	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "eleschool")
	{			
		if(getSearchCookie("eleSchool") && $("txtEleSchool"))
		{
			$("txtEleSchool").value = getSearchCookie("eleSchool").replace(/[+]/g, ' ');
		}
		else if($("txtEleSchool"))
		{
			$("txtEleSchool").value = '';	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "midschool")
	{			
		if(getSearchCookie("midSchool") && $("txtMidSchool"))
		{
			$("txtMidSchool").value = getSearchCookie("midSchool").replace(/[+]/g, ' ');
		}
		else if($("txtMidSchool"))
		{
			$("txtMidSchool").value = '';	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "highschool")
	{			
		if(getSearchCookie("highSchool") && $("txtHighSchool"))
		{
			$("txtHighSchool").value = getSearchCookie("highSchool").replace(/[+]/g, ' ');
		}
		else if($("txtHighSchool"))
		{
			$("txtHighSchool").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt != null && srchcrt == "bankowned")
	{			
		if(getSearchCookie("bankowned") && $("chkBankOwned"))
		{
			if(getSearchCookie("bankowned") == "true")
				$("chkBankOwned").checked = true;
			else
				$("chkBankOwned").checked = false;
		}
		else if($("chkBankOwned"))
		{
			$("chkBankOwned").checked = false;	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt != null && srchcrt == "shortsales")
	{			
		if(getSearchCookie("shortsales") && $("chkShortSales"))
		{
			if(getSearchCookie("shortsales") == "true")
				$("chkShortSales").checked = true;
			else
				$("chkShortSales").checked = false;
		}
		else if($("chkShortSales"))
		{
			$("chkShortSales").checked = false;	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt != null && srchcrt == "listagtid")
	{			
		if(getSearchCookie("listagtid") && $("txtListAgtId"))
		{
			$("txtListAgtId").value = getSearchCookie("listagtid");
		}
		else if($("txtListAgtId"))
		{
			$("txtListAgtId").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "listoff")
	{			
		if(getSearchCookie("listoff") && $("txtListOff"))
		{
			$("txtListOff").value = getSearchCookie("listoff").replace(/[+]/g, ' ').replace("__",'#');
		}
		else if($("txtListOff"))
		{
			$("txtListOff").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleagtid")
	{			
		if(getSearchCookie("saleagtid") && $("txtSaleAgtId"))
		{
			$("txtSaleAgtId").value = getSearchCookie("saleagtid");
		}
		else if($("txtSaleAgtId"))
		{
			$("txtSaleAgtId").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleoff")
	{			
		if(getSearchCookie("saleoff") && $("txtSaleOff"))
		{
			$("txtSaleOff").value = getSearchCookie("saleoff").replace(/[+]/g, ' ');
		}
		else if($("txtSaleOff"))
		{
			$("txtSaleOff").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "roof")
	{			
		if(getSearchCookie("roof") && $("txtRoof"))
		{
			$("txtRoof").value = getSearchCookie("roof").replace(/[+]/g, ' ');
		}
		else if($("txtRoof"))
		{
			$("txtRoof").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "fire")
	{	
		if(getSearchCookie("fire") && $("cmbFire"))
		{
			$("cmbFire").value = getSearchCookie("fire");
		}
		else if($("cmbFire"))
		{
			$("cmbFire").selectedIndex = 0;
		}
		
		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "pool")
	{	
		if(getSearchCookie("pool") && $("cmbPool"))
		{
			$("cmbPool").value = getSearchCookie("pool");
		}
		else if($("cmbPool"))
		{
			$("cmbPool").selectedIndex = 0;
		}
		
		if(srchcrt != null)
		{
			return;
		}		
	}
	
	if(srchcrt != null && srchcrt == "saledate")
	{			
		if(getSearchCookie("saleDateFrom") && $("txtSFDate"))
		{
			$("txtSFDate").value = getSearchCookie("saleDateFrom");
		}
		else if($("txtSFDate"))
		{
			$("txtSFDate").value = '';
		}
		if(getSearchCookie("saleDateTo") && $("txtSTDate"))
		{
			$("txtSTDate").value = getSearchCookie("saleDateTo");
		}
		else if($("txtSTDate"))
		{
			$("txtSTDate").value = '';
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "saleprice")
	{			
		if(getSearchCookie("salePriceFrom") && $("txtSalePriceFrom"))
		{
			$("txtSalePriceFrom").value = getSearchCookie("salePriceFrom");
		}
		else if($("txtSalePriceFrom"))
		{
			$("txtSalePriceFrom").value = '';
		}
		if(getSearchCookie("salePriceTo") && $("txtSalePriceTo"))
		{
			$("txtSalePriceTo").value = getSearchCookie("salePriceTo");
		}
		else if($("txtSalePriceTo"))
		{
			$("txtSalePriceTo").value = '';
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt != null && srchcrt == "saleagent")
	{
		if(getSearchCookie("saleAgentFnm") && $("txtSaleAgentFname"))
		{
			$("txtSaleAgentFname").value = getSearchCookie("saleAgentFnm");
		}
		else if($("txtSaleAgentFname"))
		{
			$("txtSaleAgentFname").value = 'First Name';
		}
		if(getSearchCookie("saleAgentLnm") && $("txtSaleAgentLname"))
		{
			$("txtSaleAgentLname").value = getSearchCookie("saleAgentLnm");
		}
		else if($("txtSaleAgentLname"))
		{
			$("txtSaleAgentLname").value = 'Last Name';
		}
		if(srchcrt != null)
		{
			return;
		}		
	}
	if(srchcrt != null && srchcrt == "area")
	{			
		if(getSearchCookie("area") && $("txtArea"))
		{
			$("txtArea").value = getSearchCookie("area");
		}
		else if($("txtArea"))
		{
			$("txtArea").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt != null && srchcrt == "polygon")
	{			
		if(getSearchCookie("polygon") && $("txtPolygon"))
		{
			$("txtPolygon").value = getSearchCookie("polygon").replace(/\+/g, " ");
		}
		else if($("txtPolygon"))
		{
			$("txtPolygon").value = '';	
		}		
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt != null && srchcrt == "powerradial")
	{	
		if(getSearchCookie("powerradial") && $("cmbradial"))
		{
			$("cmbradial").value = getSearchCookie("powerradial");
		}
		else if($("cmbradial"))
		{
			$("cmbradial").selectedIndex = 0;
		}
		
		if(srchcrt != null)
		{
			return;
		}		
	}
}

function funGetSearchQueryString()
{
	var lfDate = "";
	var ltDate = "";

	var tempDate = escape(trim(getSearchCookie("ckLFDate")));
	if (tempDate != "")
	{
		var arrTempDate = tempDate.split ("-");
		lfDate = arrTempDate[2] + "-" + arrTempDate[0] + "-" + arrTempDate[1];
	}

	var tempDate = escape(trim(getSearchCookie("ckLTDate")));
	if (tempDate != "")
	{
		var arrTempDate = tempDate.split ("-");
		ltDate = arrTempDate[2] + "-" + arrTempDate[0] + "-" + arrTempDate[1];
	}

	searchQueryString = "";
	searchQueryString = searchQueryString + "qckWidgetUpdate=1";
	searchQueryString = searchQueryString + "&address=" 		+ 	escape(getSearchCookie("searchAddress"));
	if(getSearchCookie("city") && getSearchCookie("city") != "")
	{
		searchQueryString = searchQueryString + "&city=" 			+ 	escape(getSearchCookie("city"));
	}
	if(getSearchCookie("state") && getSearchCookie("state") != "")
	{
		searchQueryString = searchQueryString + "&state=" 			+ 	escape(getSearchCookie("state"));
	}
	if(getSearchCookie("zip") && getSearchCookie("zip") != "")
	{
		searchQueryString = searchQueryString + "&zip=" 			+ 	escape(getSearchCookie("zip"));
	}
	searchQueryString = searchQueryString + "&minprice=" 		+ 	escape(money2num(getSearchCookie("minPrice")));
	searchQueryString = searchQueryString + "&maxprice=" 		+ 	escape(money2num(getSearchCookie("maxPrice")));
	searchQueryString = searchQueryString + "&beds=" 			+ 	escape(getSearchCookie("searchBeds"));
	searchQueryString = searchQueryString + "&minsqft=" 		+ 	escape(getSearchCookie("minSize"));
	searchQueryString = searchQueryString + "&maxsqft=" 		+ 	escape(getSearchCookie("maxSize"));
	searchQueryString = searchQueryString + "&baths=" 			+ 	escape(getSearchCookie("searchBaths"));
	searchQueryString = searchQueryString + "&searchType=" 		+ 	escape(getSearchCookie("searchType"));
	searchQueryString = searchQueryString + "&searchSortType=" 	+ 	escape(trim(getSearchCookie("searchSortType"))==""?"ph":trim(getSearchCookie("searchSortType")));
	searchQueryString = searchQueryString + "&lfDate="			+ 	escape(lfDate);
	searchQueryString = searchQueryString + "&ltDate="			+ 	escape(ltDate);
	searchQueryString = searchQueryString + "&county="			+ 	escape(trim(getSearchCookie("county")));
	
	var setPropStyle  = getSearchCookie("propStyle");
	setPropStyle 	  = setPropStyle.replace(":",",");
	searchQueryString = searchQueryString + "&propStyle="		+ 	escape(trim(setPropStyle));
	
	if(trim(getSearchCookie("garage")) == 'All')
		searchQueryString = searchQueryString + "&garage=";
	else
		searchQueryString = searchQueryString + "&garage="		+ 	escape(trim(getSearchCookie("garage")));
		
	if(trim(getSearchCookie("neighborhood")) == 'all')
		searchQueryString = searchQueryString + "&neighborhood=";
	else
		searchQueryString = searchQueryString + "&neighborhood="	+ 	escape((trim(getSearchCookie("neighborhood"))));
	
	var myQs = new Querystring();
	var frm = myQs.get("frm");
	var aid = myQs.get("aid");

	if(frm != null && trim(frm) == 'agt' && aid != null && trim(aid) != "")
	{
		if(typeof(strAgtMlsSrc) != 'undefined' && strAgtMlsSrc != null && strAgtMlsSrc.length > 0)
			searchQueryString = searchQueryString + "&mlsSource="	+ 	escape((trim(strAgtMlsSrc)));
		else
			searchQueryString = searchQueryString + "&mlsSource=";
		searchQueryString = searchQueryString + "&aid="			+ 	escape((trim(aid)));
	}	
	if(latLong)
		searchQueryString = searchQueryString+"&propLatitude="+latLong.lat+"&propLongitude="+latLong.lng;
	return searchQueryString;
}

function funGetAdvSearchQueryString()
{
	var lfDate = "";
	var ltDate = "";

	var tempDate = escape(trim(getSearchCookie("ckLFDate")));
	if (tempDate != "")
	{
		var arrTempDate = tempDate.split ("-");
		lfDate = arrTempDate[2] + "-" + arrTempDate[0] + "-" + arrTempDate[1];
	}

	var tempDate = escape(trim(getSearchCookie("ckLTDate")));
	if (tempDate != "")
	{
		var arrTempDate = tempDate.split ("-");
		ltDate = arrTempDate[2] + "-" + arrTempDate[0] + "-" + arrTempDate[1];
	}

	searchQueryString = new StringBuffer();
	searchQueryString.append("qckWidgetUpdate=1");
	searchQueryString.append("&minprice=" 		+ 	escape(money2num(getSearchCookie("minPrice"))));
	searchQueryString.append("&maxprice=" 		+ 	escape(money2num(getSearchCookie("maxPrice"))));
	searchQueryString.append("&beds=" 			+ 	escape(getSearchCookie("searchBeds")));
	searchQueryString.append("&minsqft=" 		+ 	escape(getSearchCookie("minSize")));
	searchQueryString.append("&maxsqft=" 		+ 	escape(getSearchCookie("maxSize")));
	searchQueryString.append("&baths=" 			+ 	escape(getSearchCookie("searchBaths")));
	searchQueryString.append("&searchType=" 		+ 	escape(getSearchCookie("searchType")));
	searchQueryString.append("&searchSortType=" 	+ 	escape(trim(getSearchCookie("searchSortType"))==""?"ph":trim(getSearchCookie("searchSortType"))));
	searchQueryString.append("&lfDate="			+ 	escape(lfDate));
	searchQueryString.append("&ltDate="			+ 	escape(ltDate));
	searchQueryString.append("&county="			+ 	escape(trim(getSearchCookie("county"))));
		
	if(trim(getSearchCookie("neighborhood")) == 'all')
		searchQueryString.append("&neighborhood=");
	else
		searchQueryString.append("&neighborhood="	+ 	escape((trim(getSearchCookie("neighborhood")))));

	var myQs = new Querystring();
	var frm = myQs.get("frm");
	var aid = myQs.get("aid");
	var ouid = myQs.get("ouid");
	if(frm != null && trim(frm) == 'agt' && aid != null && trim(aid) != "")
	{
		if(typeof(strAgtMlsSrc) != 'undefined' && strAgtMlsSrc != null && strAgtMlsSrc.length > 0)
			searchQueryString.append("&mlsSource="	+ 	escape((trim(strAgtMlsSrc))));
		else
			searchQueryString.append("&mlsSource=");
		searchQueryString.append("&aid="			+ 	escape((trim(aid))));
	}	
	else if(frm != null && trim(frm) == 'frch' && ouid != null && trim(ouid) != "")
	{
		if(typeof(strAgtMlsSrc) != 'undefined' && strAgtMlsSrc != null && strAgtMlsSrc.length > 0)
			searchQueryString.append("&mlsSource="	+ 	escape((trim(strAgtMlsSrc))));
		else
			searchQueryString.append("&mlsSource=");
		searchQueryString.append("&ouid="			+ 	escape((trim(ouid))));
	}	
	
	return searchQueryString.toString();
}

function funCompareSearchCookie()
{
	if($('searchCSZ') != null)
	{
		var cszFromCookie = setCSZValue(getSearchCookie("city"), getSearchCookie("state"), getSearchCookie("zip"));
		$('searchCSZ').value = $('searchCSZ').value.replace (/^\s+/g, "").replace (/\s+$/g, "").replace (/\s+/g, " ");
		if (trim(cszFromCookie).toUpperCase() != trim($('searchCSZ').value).toUpperCase())
		{
			return 1;		
		}
	}		
	if(($("searchAddress") != null) && (getSearchCookie("searchAddress") != $F("searchAddress").replace('optional','')))
	{
		return 1;
	}
	if($("minPrice") && (getSearchCookie("minPrice") != money2num($F("minPrice"))))
	{
		return true;
	}
	if($("maxPrice") && (getSearchCookie("maxPrice") != money2num($F("maxPrice"))))
	{
		return true;
	}
	if($("searchBedsMin") && $("searchBedsMax") && trim(getSearchCookie("searchBeds")) != "" && (trim(getSearchCookie("searchBeds")) != trim($F("searchBedsMin"))+"-"+trim($F("searchBedsMax"))))
	{
		return true;
	}
	if($("minSize") && ((trim(getSearchCookie("minSize")) == "" && $F("minSize") != 0) || ((trim(getSearchCookie("minSize")) != "") && (trim(getSearchCookie("minSize")) != $F("minSize")))))
	{
		return true;
	}
	if($("maxSize") && ((trim(getSearchCookie("maxSize")) == "" && $F("maxSize") != 0) || ((trim(getSearchCookie("maxSize")) != "") && (trim(getSearchCookie("maxSize")) != $F("maxSize")))))
	{
		return true;
	}
	if($("searchBathsMin") && $("searchBathsMax") && trim(getSearchCookie("searchBaths")) != "" && (trim(getSearchCookie("searchBaths")) != trim($F("searchBathsMin"))+"-"+trim($F("searchBathsMax"))))
	{
		return true;
	}
	if($("divPopUpSHType") != null)
	{
		var arrChkBox = $("divPopUpSHType").getElementsByTagName("input");
		var lenChkBox = arrChkBox.length;
		var strChkBox = getSearchCookie("searchType");
		if(trim(strChkBox) == "")
		{
			for(var i=0;i<lenChkBox;i++)
			{
		    	if(arrChkBox[i].id == "chbSHTypeAll")
		    	{
		    		continue;
		    	}
		    	if((arrChkBox[i].type == "checkbox") && (arrChkBox[i].checked === false))
		    	{
		    		return true;
		    	}
			}	
		}
		else
		{
			var arrStrChkBox = strChkBox.split(":");
			for(var i=0;i<lenChkBox;i++)
			{
		    	if(arrChkBox[i].type == "checkbox")
		    	{
		    		var valChkBox = arrChkBox[i].value;
		    		if(arrStrChkBox.in_array(valChkBox) != false && arrChkBox[i].checked == false)
		    		{
		    			return true;
		    		}
		    	}
			}	
		}
	}
	if($("searchSortType") && (((trim(getSearchCookie("searchSortType"))!= "") && (getSearchCookie("searchSortType") !== $F("searchSortType"))) || (((trim(getSearchCookie("searchSortType")) == "") && ($F("searchSortType") != "ph")))))
	{
		return true;
	}
	return false;
}

function funCheckContradict()
{
	var retValue;
	var geoCbFn = function(reqObj)
	{
		for(var i=0;i<20;i++)
		{
			var idTxtObj = 'searchCSZ'+ eval(i+1);
			if($(idTxtObj) != null)
				$(idTxtObj).value = "";
		}
		var geoResponse = reqObj.responseText;
		var allCity = "";
		var allState = "";
		var allZip = "";
		var geoArrResponse = eval(geoResponse);
		var boolGetSingleCity = false;
		for(var i=0;i<geoArrResponse.length;i++)
		{
			if(geoArrResponse[i].status == 0)
			{	
				boolGetSingleCity = true;
				var geoCity = geoArrResponse[i].city;
				allCity += geoCity + '|';
				var geoState = geoArrResponse[i].state;
				allState += geoState + '|';
				var geoZip = geoArrResponse[i].zip;
				allZip += geoZip + '|';
				var geoAddress = geoArrResponse[i].address;
				setSearchCookie("searchAddress",geoAddress);
				$("searchAddress").value = geoAddress;
				
				
				setSearchCookie("county","");
				setSearchCookie("neighborhood","");
				arrDataCounty.length = 0;
				arrDataNeighborHood.length = 0;
				headerContent("county");
				headerContent("neighborhood");
				
				var now = new Date();
				now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
				var latLongStr = "[{'lat':'"+geoArrResponse[i].latitude+"','lng':'"+geoArrResponse[i].longitude+"'}]";
				setCookie("latLongCk",latLongStr,now);
				latLong = eval(getCookie("latLongCk"))[0];
				if(trim(getCookie("lpid")) != "" && isContradict === 1)
				{
					setCookie("lpid","");
					if(window.location.pathname.indexOf("dashboard") > 0)
					{
						funCloseWidget("divChild1X2");
						funCloseWidget("divChild1X3");
						funCloseWidget("divChild2X1");
						funCloseWidget("divChild2X2");
						funCloseWidget("divChild2X3");
						funCloseWidget("divChild3X1");
						funCloseWidget("divChild3X2");
						funCloseWidget("divChild3X3");
					}	
				}
			}
		}
		if(boolGetSingleCity == false)
		{			
			if(geoArrResponse.length > 1)
			{
				alert('Sorry, We couldn\'t find any location from "' + $('searchCSZ').value + '"');
			}
			else
			{				
				alert('Sorry, We couldn\'t find a location for "' + geoArrResponse[0].originaladdress + '"');
				setSearchCookie("searchAddress","");
				if($("searchAddress")) $("searchAddress").value = "optional";
				if(typeof(srTabs) != "undefined" && srTabs.getTab(0).get("active"))
				{
					srTabs.set('activeTab',srTabs.getTab(0),true);
					srTabs.getTab(0).refresh();
				}
			}
			retValue = "0";
			return;
		}
		else
		{
			if (allCity != "")
			{
				setSearchCookie ("city", allCity.substr(0, allCity.length-1));			
			}
			if (allState != "")
			{
				setSearchCookie ("state", allState.substr(0, allState.length-1));			
			}
			if (allZip != "")
			{
				setSearchCookie ("zip", allZip.substr(0, allZip.length-1));			
			}
			$('searchCSZ').value = setCSZValue(getSearchCookie('city'),getSearchCookie('state'),getSearchCookie('zip'));
			retValue = "2";
			return;
		}	
	}
	var isContradict = funCompareSearchCookie();
	if(isContradict === 1)
	{
		var geoUrl = "/classes/getCSZ.php";
		var geoAddress = "";
		if((trim($("searchAddress").value).toLowerCase() != "optional") && (trim($('searchCSZ').value).search(';') === -1))
		{
			geoAddress = $("searchAddress").value;
		}
		var geoQueryString = "csz="+escape($('searchCSZ').value)+"&address="+escape(geoAddress);
		ajaxRequest(geoUrl,geoQueryString,geoCbFn,false);
		return retValue;
	}
	else
	{
		return "1";
	}	
}

function CompareMinMax(srchcrt)
{
	if(srchcrt == null || srchcrt == "price")
	{
		var minP = Number(money2num($('minPrice').value));	
		var maxP = Number(money2num($('maxPrice').value));	
	
		if(minP<0 || maxP<0)
		{
			alert("Please enter valid price range");
			$('minPrice').value = '';
			$('maxPrice').value = '';
			return false;
		}
		if((minP>maxP) && (minP != "" && maxP != ""))
		{
			alert("Please enter valid price range");
			$('minPrice').value = '';
			$('maxPrice').value = '';
			return false;
		}
		if(srchcrt != null)
		{
			return;
		}
	}

	if(srchcrt == null || srchcrt == "beds")
	{
		var minbd = trim($('searchBedsMin').value);
		var maxbd = trim($('searchBedsMax').value);

		if(isNaN(minbd))
		{
			alert("Please enter numeric value for min beds");
			$('searchBedsMin').value = '';
			return false;
		}

		if(isNaN(maxbd))
		{
			alert("Please enter numeric value for max beds");
			$('searchBedsMax').value = '';
			return false;
		}

		if(minbd.include("."))
		{
			var ptLen = minbd.substr(minbd.indexOf(".")+1,minbd.length).length;
			if(ptLen>2)
			{
				alert("Only 2 digits allowed after decimal point for min beds");
				$('searchBedsMin').value = '';
				return false;
			}
		}

		if(maxbd.include("."))
		{
			var ptLen = maxbd.substr(maxbd.indexOf(".")+1,maxbd.length).length;
			if(ptLen>2)
			{
				alert("Only 2 digits allowed after decimal point for max beds");
				$('searchBedsMax').value = '';
				return false;
			}
		}

		minbd = Number(minbd);
		maxbd = Number(maxbd);

		if(minbd<0 || maxbd<0)
		{
			alert("Please enter valid beds range");
			$('searchBedsMin').value = '';
			$('searchBedsMax').value = '';
			return false;
		}
		if((minbd>maxbd) && (minbd != "" && maxbd != ""))
		{
			alert("Please enter valid beds range");
			$('searchBedsMin').value = '';
			$('searchBedsMax').value = '';
			return false;
		}
	}

	if(srchcrt == null || srchcrt == "baths")
	{
		var minbth = trim($('searchBathsMin').value);
		var maxbth = trim($('searchBathsMax').value);

		if(isNaN(minbth))
		{
			alert("Please enter numeric value for min baths");
			$('searchBathsMin').value = '';
			return false;
		}

		if(isNaN(maxbth))
		{
			alert("Please enter numeric value for max baths");
			$('searchBathsMax').value = '';
			return false;
		}

		if(minbth.include("."))
		{
			var ptLen = minbth.substr(minbth.indexOf(".")+1,minbth.length).length;
			if(ptLen>2)
			{
				alert("Only 2 digits allowed after decimal point for min baths");
				$('searchBathsMin').value = '';
				return false;
			}
		}

		if(maxbth.include("."))
		{
			var ptLen = maxbth.substr(maxbth.indexOf(".")+1,maxbth.length).length;
			if(ptLen>2)
			{
				alert("Only 2 digits allowed after decimal point for max baths");
				$('searchBathsMax').value = '';
				return false;
			}
		}

		minbth = Number(minbth);
		maxbth = Number(maxbth);

		if(minbth<0 || maxbth<0)
		{
			alert("Please enter valid baths range");
			$('searchBathsMin').value = '';
			$('searchBathsMax').value = '';
			return false;
		}
		if((minbth>maxbth) && (minbth != "" && maxbth != ""))
		{
			alert("Please enter valid baths range");
			$('searchBathsMin').value = '';
			$('searchBathsMax').value = '';
			return false;
		}
	}

	if(srchcrt == null || srchcrt == "sqft")	
	{
		var sqftMin = Number($("minSize").value);
		var sqftMax = Number($("maxSize").value);
		if(sqftMin>sqftMax && sqftMax != 0)
		{
			alert("Please select valid range for square feet");
			return false;
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "listdate")
	{
		if(trim($("txtLFDate").value) != "" && trim($("txtLTDate").value) != "")
		{
			var valLFDate = $("txtLFDate").value;
			var arrLFDate = valLFDate.split("-");		
			var objLFDate = new Date();
			objLFDate.setYear(arrLFDate[2]);
			objLFDate.setMonth(arrLFDate[0]);
			objLFDate.setDate(arrLFDate[1]);
			var tsLFDate = objLFDate.getTime()
			var valLTDate = $("txtLTDate").value;
			var arrLTDate = valLTDate.split("-");		
			var objLTDate = new Date();
			objLTDate.setYear(arrLTDate[2]);
			objLTDate.setMonth(arrLTDate[0]);
			objLTDate.setDate(arrLTDate[1]);
			var tsLTDate = objLTDate.getTime()
			if(tsLFDate > tsLTDate)
			{
				alert("To date should not be less than From date.");
				$('txtLFDate').value = '';
				$('txtLTDate').value = '';
				return false;
			}
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	return true;
}

function headerContent(srchcrt)
{
	if(srchcrt != null && srchcrt == "mls")
	{
		var ihMLSLabel = "MLS # ";
		var ihMLSValue = "";
		if(trim(getSearchCookie('mlsno')) != "")
		{
			var ihMLSValue = getSearchCookie('mlsno'); 
		}
		if($("divSHMLS") != null)
		{
			if($("divSHMLS").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHMLS").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihMLSLabel;
				}
				var objSpanValue = $("divSHMLS").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihMLSValue) != ""))
				{
					objSpanValue.innerHTML = ihMLSValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "county")
	{
		var ihCountyLabel = "County: ";
		var ihCountyValue = "";
		if((getSearchCookie("county") != null) && (trim(getSearchCookie("county")) != ""))
		{
			ihCountyValue = getSearchCookie("county"); 
		}
		else
		{
			ihCountyValue = 'any';
		}
		if($("divSHCounty") != null)
		{
			if($("divSHCounty").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHCounty").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihCountyLabel;
				}
				var objSpanValue = $("divSHCounty").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihCountyValue) != ""))
				{
					objSpanValue.innerHTML = funWrapText(ihCountyValue,20);
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "neighborhood")
	{
		var ihNeighborhoodLabel = "Neighborhood: ";
		var ihNeighborhoodValue = new StringBuffer();
		if((getSearchCookie("neighborhood") != null) && (trim(getSearchCookie("neighborhood")) != ""))
		{
			var strCKNH = getSearchCookie("neighborhood");
			var arrCKNH = strCKNH.split(',');
			var lenArrCKNH = arrCKNH.length;
			for(var i=0;i<lenArrCKNH;i++)
			{
				ihNeighborhoodValue.append(arrCKNH[i] + ',');
			}
			ihNeighborhoodValue = ihNeighborhoodValue.toString();
			if(ihNeighborhoodValue.charAt(ihNeighborhoodValue.length-1) == ',')
			{
				ihNeighborhoodValue = ihNeighborhoodValue.substr(0,eval(ihNeighborhoodValue.length-1));
			}
		}
		else
		{
			ihNeighborhoodValue =  ihNeighborhoodValue + 'any';
		}
		if($("divSHNeighborHood") != null)
		{
			if($("divSHNeighborHood").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHNeighborHood").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihNeighborhoodLabel;
				}
				var objSpanValue = $("divSHNeighborHood").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihNeighborhoodValue) != ""))
				{
					objSpanValue.innerHTML = funWrapText(ihNeighborhoodValue,15);
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if((srchcrt == null || srchcrt == "price") && $('minPrice') && $('maxPrice'))
	{	
		var ihPriceLabel = "Price: ";
		var ihPriceValue = "";
		var minP = Number(money2num(getSearchCookie("minPrice")));
		var maxP = Number(money2num(getSearchCookie("maxPrice")));	
		if(minP != 0 || maxP != 0)
		{
			if(minP != 0)
			{
				minP = num2money($('minPrice').value,'$','minPrice',false);
				ihPriceValue = ihPriceValue + minP+" to ";
			}
			else
			{
				ihPriceValue = ihPriceValue + "No Min to ";
			}
			if(maxP != 0)
			{
				maxP = num2money($('maxPrice').value,'$','maxPrice',false);
				ihPriceValue = ihPriceValue + maxP;
			}
			else
			{
				ihPriceValue = ihPriceValue + "No Max";
			}
		}
		else
		{
			ihPriceValue = ihPriceValue + "any";
		}
		if($("divSHPrice") != null)
		{
			if($("divSHPrice").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHPrice").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihPriceLabel;
				}
				var objSpanValue = $("divSHPrice").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihPriceValue) != ""))
				{
					objSpanValue.innerHTML = ihPriceValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}
	if(srchcrt == null || srchcrt == "beds")
	{
		var ihBedsLabel = "Beds: ";
		var ihBedsValue = "";
		var searchBeds = getSearchCookie("searchBeds");
		if(trim(searchBeds) == "")
			ihBedsValue = ihBedsValue + "any";
		else
		{
			var bdArr = searchBeds.split("-");

			if(bdArr[0] != "" && bdArr[1] != "")
				ihBedsValue = bdArr[0] + " to " + bdArr[1];
			else if(bdArr[0] != "")
				ihBedsValue = bdArr[0] + " to No Max";
			else
				ihBedsValue = "No Min to " + bdArr[1];
		}
		if($("divSHBeds") != null)
		{
			if($("divSHBeds").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHBeds").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihBedsLabel;
				}
				var objSpanValue = $("divSHBeds").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihBedsValue) != ""))
				{
					objSpanValue.innerHTML = ihBedsValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}		
	if(srchcrt == null || srchcrt == "baths")
	{
		var ihBathsLabel = "Baths: ";
		var ihBathsValue = "";
		var searchBaths = getSearchCookie("searchBaths");
		if(trim(searchBaths) == "")
			ihBathsValue = ihBathsValue + "any";
		else
		{
			var bthArr = searchBaths.split("-");

			if(bthArr[0] != "" && bthArr[1] != "")
				ihBathsValue = bthArr[0] + " to " + bthArr[1];
			else if(bthArr[0] != "")
				ihBathsValue = bthArr[0] + " to No Max";
			else
				ihBathsValue = "No Min to " + bthArr[1];
		}

		if($("divSHBaths") != null)
		{
			if($("divSHBaths").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHBaths").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihBathsLabel;
				}
				var objSpanValue = $("divSHBaths").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihBathsValue) != ""))
				{
					objSpanValue.innerHTML = ihBathsValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sqft")
	{
		var ihSqftLabel = "Sqft: ";
		var ihSqftValue = "";
		var sqftMin = Number(getSearchCookie("minSize"));
		var sqftMax = Number(getSearchCookie("maxSize"));
		if((sqftMax != "0") || (sqftMin > 0 && sqftMax == 0))
		{
			if (sqftMin > 0 || (sqftMax > 0 && sqftMin == 0))
				ihSqftValue = ihSqftValue + sqftMin + ' - ';
			if (sqftMax > 0)
				ihSqftValue = ihSqftValue + sqftMax;
			if (sqftMax == 0)
				ihSqftValue = ihSqftValue + 'No Max';
		}
		else
		{
			ihSqftValue = ihSqftValue +  "any";
		}
		if($("divSHSqft") != null)
		{
			if($("divSHSqft").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHSqft").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihSqftLabel;
				}
				var objSpanValue = $("divSHSqft").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihSqftValue) != ""))
				{
					objSpanValue.innerHTML = ihSqftValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "listdate")
	{
		var ihListDateLabel = "List Date: ";
		var ihListDateValue = "";
		var valLFDate = getSearchCookie("ckLFDate");
		var valLTDate = getSearchCookie("ckLTDate");
		if(trim(valLFDate) != "" || trim(valLTDate) != "")
		{
			if(trim(valLFDate) != "")
			{
				ihListDateValue = ihListDateValue + "From "+valLFDate;
			}
			if(trim(valLFDate) != "" && trim(valLTDate) != "")
			{
				ihListDateValue = ihListDateValue + " To "+valLTDate;
			}
			else if(trim(valLTDate) != "")
			{
				ihListDateValue = ihListDateValue + " : UpTo "+valLTDate;
			}
		}
		else
		{
			ihListDateValue = ihListDateValue + "any";
		}
		if($("divSHListDate") != null)
		{
			if($("divSHListDate").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHListDate").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihListDateLabel;
				}
				var objSpanValue = $("divSHListDate").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihListDateValue) != ""))
				{
					objSpanValue.innerHTML = ihListDateValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "type")
	{
		var ihTypeLabel = "Type: ";
		var ihTypeValue = "";
		var valSearchType = getSearchCookie("searchType");
		if(trim(valSearchType) != "")
		{
			var arrValSearchType = valSearchType.split(':');
			var lenValSearchType = arrValSearchType.length;
			for(var i=0;i<lenValSearchType;i++)
			{
				var keySearchTypeVal = arrValSearchType[i];
				if(trim(keySearchTypeVal) != "")
				{
					ihTypeValue = ihTypeValue + arrValSearchType[keySearchTypeVal]+',';
				}	
			}
			if(ihTypeValue.charAt(ihTypeValue.length-1) == ',')
			{
				ihTypeValue = ihTypeValue.substr(0,eval(ihTypeValue.length-1));
			}
		}
		else
		{
			ihTypeValue = ihTypeValue + "all";
		}
		if($("divSHType") != null)
		{
			if($("divSHType").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHType").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihTypeLabel;
				}
				var objSpanValue = $("divSHType").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihTypeValue) != ""))
				{
					objSpanValue.innerHTML = funWrapText(ihTypeValue,15);
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}	
	if(srchcrt == null || srchcrt == "sortby")
	{
		var ihSortTypeLabel = "Sort By: ";
		var ihSortTypeValue = "";
		var sortType = getSearchCookie("searchSortType");
		if(trim(sortType) == "" || sortType == "ph")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Price High to Low";
		}		
		else if(sortType == "pl")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Price Low to High";
		}	
		else if(sortType == "brh")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Beds High to Low";
		}		
		if(sortType == "brl")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Beds Low to High";
		}	
		else if(sortType == "bah")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Baths High to Low";
		}		
		else if(sortType == "bal")
		{ 
			ihSortTypeValue = ihSortTypeValue + "Baths Low to High";
		}
		if($("divSHSortBy") != null)
		{
			if($("divSHSortBy").getElementsByTagName('a')[0] != null)
			{
				var objSpanLabel = $("divSHSortBy").getElementsByTagName('a')[0].getElementsByTagName('span')[0];
				if(objSpanLabel != null)
				{
					objSpanLabel.innerHTML = ihSortTypeLabel;
				}
				var objSpanValue = $("divSHSortBy").getElementsByTagName('a')[0].getElementsByTagName('span')[1];
				if((objSpanValue != null) && (trim(ihSortTypeValue) != ""))
				{
					objSpanValue.innerHTML = ihSortTypeValue;
				}
			}	
		}
		if(srchcrt != null)
		{
			return;
		}
	}		
}
function funUnchkAllChkBox(objChkBox) 
{
	if(($('chbSHNHAll').checked == true) && (objChkBox.checked == false))
	{
		$('chbSHNHAll').checked = false;
	}
}
function funSetSHNHAll(from)
{
	if(typeof(from)!="undefined")
	{
		divId = "divNHood";
		chkAllId = "chbRSNHAll";
	}
	else
	{
		divId = "divSHDataNeighborHood";
		chkAllId = "chbSHNHAll";
	}
	var arrChkBox = $(divId).getElementsByTagName("input");
	var lenChkBox = arrChkBox.length;
	for(var i=0;i<lenChkBox;i++)
	{
		if(arrChkBox[i].id == chkAllId)
		{
		 	continue;
		}
	    if(($(chkAllId).checked == true) && (arrChkBox[i].type == "checkbox"))
	    {
	    	arrChkBox[i].checked = true;
	    }
	    else if(arrChkBox[i].type == "checkbox")
	    {
    		arrChkBox[i].checked = false;
	    }
	}
}
function funSetSHTypeAll(type)
{
	if(typeof(type)!="undefined")
	{
		divId = "divRSType";
		chkAllId = "RSchbSHTypeAll";
	}
	else
	{
		divId = "divPopUpSHType";
		chkAllId = "chbSHTypeAll";
	}
	if($(divId))
	{
		var	arrChkBox  = $(divId).getElementsByTagName("input");
		var lenChkBox = arrChkBox.length;
		for(var i=0;i<lenChkBox;i++)
		{
			if(arrChkBox[i].id == chkAllId)
			{
				continue;
			}
			if(($(chkAllId).checked == true) && (arrChkBox[i].type == "checkbox"))
			{
				arrChkBox[i].checked = true;
			}
			else if(($(chkAllId).checked == false) && (arrChkBox[i].type == "checkbox"))
			{
				arrChkBox[i].checked = false;
			}
		}
	}
}

function funCloseAdvanceSearch(srchcrt,page)
{	
	if($("divSHCounty")==null)
	{
		return;
	}
	
	Element.removeClassName($("divSHCounty").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHCounty").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHCounty").style.display = "none";

	Element.removeClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHNeighborHood").style.display 	= "none";
	
	if($("divPopUpSHPrice"))
	{
		Element.removeClassName($("divSHPrice").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHPrice").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divPopUpSHPrice").style.display = "none";
	}

	if($("divSHMultiCity") != null)
	{
		Element.removeClassName($("divSHMultiCity").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHMultiCity").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divPopUpSHMultiCity").style.display = "none";
	}
	
	if($("divPopUpSHBeds"))
	{
		Element.removeClassName($("divSHBeds").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHBeds").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divPopUpSHBeds").style.display = "none";
	}
	
	if($("divPopUpSHBaths"))
	{
		Element.removeClassName($("divSHBaths").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHBaths").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divPopUpSHBaths").style.display = "none";
	}
	
	if($("divPopUpSHSqft"))
	{
		Element.removeClassName($("divSHSqft").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHSqft").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divPopUpSHSqft").style.display = "none";
	}
	
	Element.removeClassName($("divSHListDate").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHListDate").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHListDate").style.display = "none";
	
	Element.removeClassName($("divSHType").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHType").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHType").style.display = "none";
	
	Element.removeClassName($("divSHMLS").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHMLS").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHMLS").style.display = "none";
	
	Element.removeClassName($("divSHSortBy").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
	Element.addClassName($("divSHSortBy").getElementsByTagName('a')[0],'linkAdvanceSearch');
	$("divPopUpSHSortBy").style.display = "none";

	if($("divSaveSearch"))
	{
		Element.removeClassName($("divSaveSearch").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSaveSearch").getElementsByTagName('a')[0],'linkAdvanceSearch');
		$("divSaveSearch").style.display = "none";
	}

	if($("divSHPowerSortBy"))
	{
		Element.removeClassName($("divSHPowerSortBy").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
		Element.addClassName($("divSHPowerSortBy").getElementsByTagName('a')[0],'linkAdvanceSearch');
	}
	
	if($("divPopUpSHPower"))
		$("divPopUpSHPower").style.display = "none";
	
	if($("divPopUpSHPropStyle")) $("divPopUpSHPropStyle").style.display = "none";
	if($("divPopUpSHGarage")) $("divPopUpSHGarage").style.display = "none";
	
	$("divPopUpSHMLSInfo").style.visibility = "hidden";
	$("divPopUpSHControls").style.display = "none";
	
	$("divContainerAdvanceSearch").style.display = "none";
	$("divContainerAdvanceSearch").style.left = "-100px";
	$("divContainerAdvanceSearch").style.top = "-100px";
	
	if(srchcrt != null)
	{
		setAllCookieValue(srchcrt);
	}
}
function funSaveAdvanceSearch(srchcrt,page)
{
	if(srchcrt == "multicity")
	{
		var boolAllCityBlank = true;
		for(var i=0;i<20;i++)
		{
			var idTxtObj = 'searchCSZ'+ eval(i+1);
			if(trim($(idTxtObj).value) != "")
			{
				boolAllCityBlank = false;
				break;
			}
		}
		if (boolAllCityBlank == true)
		{
			alert("Please specify either City & State or Zip for atleast one.");
			return false;
		}
		var allCSZ = "";
		for(var i=0;i<20;i++)
		{
			var idTxtObj = 'searchCSZ'+ eval(i+1);
			if(trim($(idTxtObj).value) == "")
			{
				continue;
			}
			else
			{
				allCSZ += trim($(idTxtObj).value.replace(/;/g,'')) + ';';
			}
		}
		$('searchCSZ').value = allCSZ.substr(0, allCSZ.length-1);
		funCloseAdvanceSearch();
		return true;
	}
	if(srchcrt == "mls")
	{
		if(trim($("searchMLS").value) == "")
		{
			alert("Please input MLS number to search.");
			return false;
		}
		searchByMlsNo();
		return true;
	}
	if(srchcrt == "more")
	{
		if(CompareMinMax(null) === false)
		{
			return false;
		}
		setAllToCookie("sqft");
		setAllToCookie("listdate");
		setAllToCookie("county");
		if(bkTheme == 'metrobrokers')
		{
			setAllToCookie("propstyle");
			//setAllToCookie("parkingtype");
			setAllToCookie("garage");
		}
		funCloseAdvanceSearch();
		if(bkTheme == 'metrobrokers'){
			//fromSubmit();
			//alert('more');
			}		
		return true;
	}	
	
	if((srchcrt == 'price') && (CompareMinMax(srchcrt) === false))
	{
		return false;
	}
	if((srchcrt == 'beds') && (CompareMinMax(srchcrt) === false))
	{
		return false;
	}
	if((srchcrt == 'baths') && (CompareMinMax(srchcrt) === false))
	{
		return false;
	}
	if(srchcrt == 'power')
	{		
		var validate = validatePower();
		if(validate === false)
			return false;

		if($("txtArea") && $("txtArea").value != "")
		{
			setSearchCookie("neighborhood","");
			headerContent("neighborhood");
		}
		setAllToCookie("mlssource");
		setAllToCookie("proptype");
		setAllToCookie("propstatus");
		setAllToCookie("sqftp");
		setAllToCookie("listdatep");
		setAllToCookie("listagent");
		setAllToCookie("lotsize");
		setAllToCookie("age");
		setAllToCookie("yearbuilt");
		setAllToCookie("daysonmarket");
		setAllToCookie("garage");
		setAllToCookie("stories");
		setAllToCookie("eleschool");
		setAllToCookie("midschool");
		setAllToCookie("highschool");
		setAllToCookie("saledate");
		setAllToCookie("saleprice");
		setAllToCookie("saleagent");
		setAllToCookie("area");
		setAllToCookie("polygon");
		setAllToCookie("powerradial");
		setAllToCookie("listagtid");
		setAllToCookie("listoff");
		setAllToCookie("saleagtid");
		setAllToCookie("saleoff");
		setAllToCookie("fire");
		setAllToCookie("pool");
		setAllToCookie("roof");
		funCloseAdvanceSearch();
		return true;
	}

	setAllToCookie(srchcrt);
	headerContent(srchcrt);
	funCloseAdvanceSearch();
	if(bkTheme == 'metrobrokers'){
		//alert('others');
		//fromSubmit();		
	}
	return true;
}

function validatePower()
{
	/* Prop Type */
	if(chooseChecked('divPType',true) == '')
	{
		alert("Please select atleast one property type");
		return false;
	}

	/* Prop Status */
	if(chooseChecked('divPStatus',true) == '')
	{
		alert("Please select atleast one property status");
		return false;
	}

	/* Sales Price */
	var minSalesP = Number(money2num($('txtSalePriceFrom').value));	
	var maxSalesP = Number(money2num($('txtSalePriceTo').value));	
	if(minSalesP<0 || maxSalesP<0)
	{
		alert("Please enter valid price range");
		$('txtSalePriceFrom').value = '';
		$('txtSalePriceTo').value = '';
		return false;
	}
	if((minSalesP>maxSalesP) && (minSalesP != "" && maxSalesP != ""))
	{
		alert("Please enter valid price range");
		$('txtSalePriceFrom').value = '';
		$('txtSalePriceTo').value = '';
		return false;
	}
	 
	/* Sqft */
	/*var sqftMin = Number($("minPSize").value);
	var sqftMax = Number($("maxPSize").value);
	if(sqftMin>sqftMax && sqftMax != 0)
	{
		alert("Please enter valid range for square feet");
		$("minPSize").selectedIndex=0;
		$("maxPSize").selectedIndex=0;
		return false;
	}*/

	var sqftMin = Number($F('minPSize'));
	var sqftMax = Number($F('maxPSize'));
	if(isNaN(sqftMin))
	{
		alert("Please enter numerical values only for min sqft.");
		$('minPSize').value = '';
		$('minPSize').focus();
		return false;
	}

	if(isNaN(sqftMax))
	{
		alert("Please enter numerical values only for max sqft.");
		$('maxPSize').value = '';
		$('maxPSize').focus();
		return false;
	}

	if(sqftMin<0 || sqftMax<0)
	{
		alert("Please enter valid square feet range.");
		$('minPSize').value = '';
		$('maxPSize').value = '';
		$('minPSize').focus();
		return false;
	}

	if(sqftMin>sqftMax && (sqftMin != "" && sqftMax != ""))
	{
		alert("Please enter valid square feet range.");
		//$("minPSize").value='';
		//$("maxPSize").value='';
		return false;
	}
	
	/* Lot Sqft */
	/*var sqftLotMin = Number($("minLotSize").value);
	var sqftLotMax = Number($("maxLotSize").value);
	if(sqftLotMin>sqftLotMax && sqftLotMax != 0)
	{
		alert("Please enter valid range for lot size");
		$("minLotSize").selectedIndex=0;
		$("maxLotSize").selectedIndex=0;
		return false;
	}*/
	var sqftLotMin = Number($F('minLotSize'));
	var sqftLotMax = Number($F('maxLotSize'));
	if(isNaN(sqftLotMin))
	{
		alert("Please enter numerical values only for min lot size.");
		$('minLotSize').value = '';
		$('minLotSize').focus();
		return false;
	}

	if(isNaN(sqftLotMax))
	{
		alert("Please enter numerical values only for max lot size.");		
		$('maxLotSize').value = '';
		$('maxLotSize').focus();
		return false;
	}

	if(sqftLotMin<0 || sqftLotMax<0)
	{
		alert("Please enter valid lot size range.");
		$('minLotSize').value = '';
		$('maxLotSize').value = '';
		$('minLotSize').focus();
		return false;
	}

	if(sqftLotMin>sqftLotMax && (sqftLotMin != "" && sqftLotMax != ""))
	{
		alert("Please enter valid lot size range.");
		//$("minLotSize").value='';
		//$("maxLotSize").value='';
		return false;
	}

	/* List Date */
	if($("txtPLFDate").value != "")
	{
		if(!validDate("txtPLFDate","Please select from list date less than current date"))
			return false;
	}

	if($("txtPLTDate").value != "")
	{
		if(!validDate("txtPLTDate","Please select to list date less than current date"))
			return false;
	}

	if(trim($("txtPLFDate").value) != "" && trim($("txtPLTDate").value) != "")
	{
		var valLFDate = $("txtPLFDate").value;
		var arrLFDate = valLFDate.split("-");		
		var objLFDate = new Date();
		objLFDate.setYear(arrLFDate[2]);
		objLFDate.setMonth(arrLFDate[0]);
		objLFDate.setDate(arrLFDate[1]);
		var tsLFDate = objLFDate.getTime()
		var valLTDate = $("txtPLTDate").value;
		var arrLTDate = valLTDate.split("-");		
		var objLTDate = new Date();
		objLTDate.setYear(arrLTDate[2]);
		objLTDate.setMonth(arrLTDate[0]);
		objLTDate.setDate(arrLTDate[1]);
		var tsLTDate = objLTDate.getTime()
		if(tsLFDate > tsLTDate)
		{
			alert("To date should not be less than From date.");
			$('txtPLFDate').value = '';
			$('txtPLTDate').value = '';
			return false;
		}
	}
	
	/* Sale Date */
	if($("txtSFDate").value != "")
	{
		if(!validDate("txtSFDate","Please select from sale date less than current date"))
			return false;
	}

	if($("txtSTDate").value != "")
	{
		if(!validDate("txtSTDate","Please select to sale date less than current date"))
			return false;
	}
	if(trim($("txtSFDate").value) != "" && trim($("txtSTDate").value) != "")
	{
		var valLFDate = $("txtSFDate").value;
		var arrLFDate = valLFDate.split("-");		
		var objLFDate = new Date();
		objLFDate.setYear(arrLFDate[2]);
		objLFDate.setMonth(arrLFDate[0]);
		objLFDate.setDate(arrLFDate[1]);
		var tsLFDate = objLFDate.getTime()
		var valLTDate = $("txtSTDate").value;
		var arrLTDate = valLTDate.split("-");		
		var objLTDate = new Date();
		objLTDate.setYear(arrLTDate[2]);
		objLTDate.setMonth(arrLTDate[0]);
		objLTDate.setDate(arrLTDate[1]);
		var tsLTDate = objLTDate.getTime()
		if(tsLFDate > tsLTDate)
		{
			alert("To date should not be less than From date.");
			$('txtSFDate').value = '';
			$('txtSTDate').value = '';
			return false;
		}
	}
	
	/* Age */
	var minAge = Number($('txtAgeFrom').value);
	var maxAge = Number($('txtAgeTo').value);
	if(isNaN(minAge))
	{
		alert("Please enter numerical values only.");
		$('txtAgeFrom').value = '';
		$('txtAgeTo').value = '';
		return false;
	}
	else if(isNaN(maxAge))
	{
		alert("Please enter numerical values only.");
		$('txtAgeFrom').value = '';
		$('txtAgeTo').value = '';
		return false;
	}
	else if(minAge>maxAge && (minAge != "" && maxAge != ""))
	{
		alert("Please enter valid range for age.");
		//$('txtAgeFrom').value = '';
		//$('txtAgeTo').value = '';
		return false;
	}
	
	/* Year Build */
	var minYr = Number($F('txtYearBuiltFrom'));
	var maxYr = Number($F('txtYearBuiltTo'));
	if(isNaN(minYr))
	{
		alert("Please enter numerical values only.");
		$('txtYearBuiltFrom').value = '';
		$('txtYearBuiltTo').value = '';
		return false;
	}
	else if(isNaN(maxYr))
	{
		alert("Please enter numerical values only.");
		$('txtYearBuiltFrom').value = '';
		$('txtYearBuiltTo').value = '';
		return false;
	}
	else if($F('txtYearBuiltFrom') != '' && $F('txtYearBuiltFrom').length != 4 )
	{
		alert("Please enter 4 digit year value.");
		$('txtYearBuiltFrom').value = '';
		$('txtYearBuiltTo').value = '';
		return false;
	}
	else if($F('txtYearBuiltTo') != '' && $F('txtYearBuiltTo').length != 4)
	{
		alert("Please enter 4 digit year value.");
		$('txtYearBuiltFrom').value = '';
		$('txtYearBuiltTo').value = '';
		return false;
	}
	else if(minYr>maxYr && (minYr != "" && maxYr != ""))
	{
		alert("Please enter valid range for year build.");
		//$('txtYearBuiltFrom').value = '';
		//$('txtYearBuiltTo').value = '';
		return false;
	}
	
	/* Days on Market */
	var minMkt = Number($F('txtDaysMarketFrom'));
	var maxMkt = Number($F('txtDaysMarketTo'));
	if(isNaN(minMkt))
	{
		alert("Please enter numerical values only.");
		$('txtDaysMarketFrom').value = '';
		$('txtDaysMarketTo').value = '';
		return false;
	}
	else if(isNaN(maxMkt))
	{
		alert("Please enter numerical values only.");
		$('txtDaysMarketFrom').value = '';
		$('txtDaysMarketTo').value = '';
		return false;
	}
	else if(minMkt>maxMkt && (minMkt != "" && maxMkt != ""))
	{
		alert("Please enter valid range for days on market.");
		//$('txtDaysMarketFrom').value = '';
		//$('txtDaysMarketTo').value = '';
		return false;
	}
	
	/* Stories */
	var stories = Number($F('txtStories'));
	if(isNaN(stories))
	{
		alert("Please enter numerical values only.");
		$('txtStories').value = '';
		return false;
	}
	
	/* Listing Agt Id*/
	if($("txtListAgtId").value != "")
	{
		var listAgtId = trim($("txtListAgtId").value);
		var tstRegex = /^([a-zA-Z0-9_-]+)$/;
		if(!tstRegex.test(listAgtId))
		{
			alert("Listing Agent Id should not contain special characters.");
		    $('txtListAgtId').value = '';
		    return false;
		}
	}

	/* Selling Agt Id*/
	if($("txtSaleAgtId").value != "")
	{
		var saleAgtId = trim($("txtSaleAgtId").value);
		var tstRegex = /^([a-zA-Z0-9_-]+)$/;
		if(!tstRegex.test(saleAgtId))
		{
			alert("Selling Agent Id should not contain special characters.");		    
		    $('txtSaleAgtId').value = '';
		    return false;
		}
	}
	
	return true;
}

function funGoAdvanceSearch(srchcrt,page)
{
	if(srchcrt == "multicity")
	{
		var boolAllCityBlank = true;
		for(var i=0;i<20;i++)
		{
			var idTxtObj = 'searchCSZ'+ eval(i+1);
			if(trim($(idTxtObj).value) != "")
			{
				boolAllCityBlank = false;
				break;
			}
		}
		if (boolAllCityBlank == true)
		{
			alert("Please specify either City & State or Zip for atleast one.");
			return;
		}
	}	
	var boolSaveAdvanceSearch = funSaveAdvanceSearch(srchcrt,page);
	if(boolSaveAdvanceSearch == true)
	{
		if($('chkmapSearchSelect') != null && $('chkmapSearchSelect').checked == true && typeof(reloadDragZoomAll) != 'undefined') 
		{
			reloadDragZoomAll();
		}
		else
		{
			explore(page);
		}	
	}	
}
function funGetNeighborHood(srchcrt,page)
{
	var cbfnGetNeighborHood = function(reqObj)
	{
		var response = reqObj.responseText;
		if(response.toString() != 'null')
		{
			arrDataNeighborHood = eval(response);
			if(arrDataNeighborHood.length > 0)
			{
				$('divPopUpSHNeighborHood').style.height = "150px";
				var strCKNH = getSearchCookie("neighborhood");
				var arrCKNH = strCKNH.split(',');
				var ihNeighborHood = new StringBuffer();
				var lenArrDataNeighborHood = arrDataNeighborHood.length;
				ihNeighborHood.append('<table cellpadding="0" cellspacing="0" style="width:250px; height:100%;" border="0">');
					ihNeighborHood.append('<tr>'); 
						ihNeighborHood.append('<td style="width:10%;">'); 
							ihNeighborHood.append('<input type="checkbox" value=""  id="chbSHNHAll" name="chbSHNHAll" onclick="javscript:funSetSHNHAll();"/>');
						ihNeighborHood.append('</td>'); 
						ihNeighborHood.append('<td style="width:80%;">'); 
							ihNeighborHood.append('<span class="contentSHPopup lang">all</span>');
						ihNeighborHood.append('</td>'); 
					ihNeighborHood.append('</tr>'); 
				for(var i=0;i<lenArrDataNeighborHood;i++)
				{
					if(typeof(arrDataNeighborHood[i]['neighborhood']) != "undefined" && trim(arrDataNeighborHood[i]['neighborhood'])!="")
					{
						ihNeighborHood.append('<tr>'); 
							ihNeighborHood.append('<td style="width:10%;">'); 
								if((arrCKNH.in_array(arrDataNeighborHood[i]['neighborhood']) !== false) || (trim(strCKNH) == 'all'))
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['neighborhood']+'" onclick="javascript:funUnchkAllChkBox(this);" checked="checked" />');
								}
								else
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['neighborhood']+'" onclick="javascript:funUnchkAllChkBox(this);" />');
								}	
							ihNeighborHood.append('</td>'); 
							ihNeighborHood.append('<td style="width:80%;">'); 
								ihNeighborHood.append('<span class="contentSHPopup lang">'+arrDataNeighborHood[i]['neighborhood']+'</span>');
							ihNeighborHood.append('</td>'); 
						ihNeighborHood.append('</tr>'); 
					}
					else if(typeof(arrDataNeighborHood[i]['area']) != "undefined" && trim(arrDataNeighborHood[i]['area'])!="")
					{
						ihNeighborHood.append('<tr>'); 
							ihNeighborHood.append('<td style="width:10%;">'); 
								if((arrCKNH.in_array(arrDataNeighborHood[i]['area']) !== false) || (trim(strCKNH) == 'all'))
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['area']+'" onclick="javascript:funUnchkAllChkBox(this);" checked="checked" />');
								}
								else
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['area']+'" onclick="javascript:funUnchkAllChkBox(this);" />');
								}	
							ihNeighborHood.append('</td>'); 
							ihNeighborHood.append('<td style="width:80%;">'); 
								ihNeighborHood.append('<span class="contentSHPopup lang">'+arrDataNeighborHood[i]['code']+" - "+arrDataNeighborHood[i]['area']+'</span>');
							ihNeighborHood.append('</td>'); 
						ihNeighborHood.append('</tr>'); 
					}
				}	
				ihNeighborHood.append('</table>');
				$("divSHDataNeighborHood").innerHTML = ihNeighborHood.toString();
				var arrChkBox = $('divSHDataNeighborHood').getElementsByTagName("input");
				var lenArrChkBox = arrChkBox.length;
				var allChked = true;
				for(var i=0;i<lenArrChkBox;i++)
				{
			    	if((arrChkBox[i].id == "chbSHNHAll") || (arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true))
			    	{
			    		continue;
			    	}
					else
					{
						allChked = false;
						break;
					}
				}
				if(allChked == true)
				{
					$("chbSHNHAll").checked = true;
				}
				Element.removeClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkAdvanceSearch');
				Element.addClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
				$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
				$("divPopUpSHMLSInfo").style.visibility = "visible";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
			}
			else
			{
				$('divPopUpSHNeighborHood').style.height = "55px";
				$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
				$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Neighborhood information not available for &nbsp;\"' + getSearchCookie("city") + ', ' + getSearchCookie("state") + '\".</span>';
				$("divPopUpSHMLSInfo").style.visibility = "hidden";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
				headerContent("county");
			}
		}
		else
		{
			$('divPopUpSHNeighborHood').style.height = "50px";
			$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
			$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Neighborhood information for \"' + getSearchCookie("city") + '", ' + getSearchCookie("state") + '\" is coming soon.</span>';
			$("divPopUpSHMLSInfo").style.visibility = "hidden";
			$("divPopUpSHControls").style.display = "inline";
			$("divPopUpSHNeighborHood").style.display = "inline";
			headerContent("county");
		}		
	}
	var url = "../../getCountyNeighborHood.php";
	var qs = "getDataNeighborHood=1&city="+getSearchCookie('city')+"&state="+getSearchCookie("state")+"&zip="+getSearchCookie("zip");

	if($("mlsSource"))
		qs +="&ds="+$F("mlsSource");
	else if(getSearchCookie('mlsSource'))
		qs +="&ds="+escape(getSearchCookie('mlsSource'));

	$("divSHDataNeighborHood").innerHTML = "";
	ajaxRequest(url,qs,cbfnGetNeighborHood);
}
function funGetCounty(srchcrt,page)
{
	var cbfnGetCounty = function(reqObj)
	{
		var response = reqObj.responseText;
		if(response.toString() != 'null')
		{
			arrDataCounty = eval(trim(response));
			if(arrDataCounty.length > 0)
			{
				var strCKCounty = getSearchCookie("county");
				var arrCKCounty = strCKCounty.split(',');
				var ihCounty = new StringBuffer();
				var lenArrDataCounty = arrDataCounty.length;
				ihCounty.append('<table cellpadding="0" cellspacing="0" style="width:320px;*width:100%;height:100%;">');
				for(var i=0;i<lenArrDataCounty;i++)
				{
					var countyName = arrDataCounty[i]['county'];
					ihCounty.append('<tr>'); 
						ihCounty.append('<td style="width:6%;">'); 
							if(arrCKCounty.in_array(countyName) !== false)
							{
								ihCounty.append('<input type="checkbox" value="'+countyName+'" checked="checked" />');
							}
							else
							{
								ihCounty.append('<input type="checkbox" value="'+countyName+'"  />');
							}	
						ihCounty.append('</td>'); 
						ihCounty.append('<td style="width:94%;">'); 
							ihCounty.append('<span class="contentSHPopup lang">'+countyName+'</span>');
						ihCounty.append('</td>'); 
					ihCounty.append('</tr>'); 
				}	
				ihCounty.append('</table>');
				
				$("divSHDataCounty").innerHTML = ihCounty.toString();
				$("divPopUpSHCounty").style.display = "inline";
			}
			else
			{
				$("divSHDataCounty").innerHTML = '<span class="contentSHPopup">County information for \"' + getSearchCookie("city") + ', ' + getSearchCookie("state") + '\" is coming soon.</span>';
				if(bkTheme == 'realestateone' || bkTheme == 'maxbroock' || bkTheme == 'jensenwhite')
				{
					$("divPopUpSHCounty").style.display = "none";
				}
				else
				{
					$("divPopUpSHCounty").style.display = "inline";
				}
			}
		}
		else
		{
			
			$("divSHDataCounty").innerHTML = '<span class="contentSHPopup">County information for \"' + getSearchCookie("city") + ', ' + getSearchCookie("state") + '\" is coming soon.</span>';
			if(bkTheme == 'realestateone' || bkTheme == 'maxbroock' || bkTheme == 'jensenwhite')
			{
			$("divPopUpSHCounty").style.display = "none";
			}
			else
			{
				$("divPopUpSHCounty").style.display = "inline";
			}
		}
	}
	if ($('searchCSZ').value.search(/;/) > -1)
	{
		$("divSHDataCounty").innerHTML = '<span class="contentSHPopup">Please select single city to enable county search.</span>';
		$("divPopUpSHCounty").style.display = "inline";
		return;
	}
	var isContradict = funCheckContradict();
	if((isContradict != null) && (isContradict != 0))
	{
		var url = "../../getCountyNeighborHood.php";
		var qs = "getDataCounty=1&city="+getSearchCookie('city')+"&state="+getSearchCookie("state")+"&zip="+getSearchCookie("zip");
		$("divSHDataCounty").innerHTML = "";
		ajaxRequest(url,qs,cbfnGetCounty);
	}
	else
	{
		return;
	}	
}

/*function funShowMultiCity()
{
if($('divPopUpMultiCity') == null)
	{
		var ihMultiCity = "";
		ihMultiCity += '<table align="center" style="border:3px double #192046;display:block;position:relative;border-collapse: separate;border-spacing: 3px;width:100%;*width:93%;" >';
		ihMultiCity += '<tr>';
		ihMultiCity += '<td valign="middle" >';
		ihMultiCity += '<div id="divDataMultiCity" name="divDataMultiCity" style="width:290px;height:270px;position:relative;float:left;display:inline;vertical-align:middle;overflow:auto" align="left">';
			ihMultiCity += '<table align="center" border="0" width="100%" style="display:block;position:relative;border-collapse: separate;border-spacing: 3px;" >';
				ihMultiCity += '<tr>';
					ihMultiCity += '<td align="left" colspan="2">';
						ihMultiCity += '<span id="multiErr"></span>';
					ihMultiCity += '</td>';													
				ihMultiCity += '</tr>';
				for(var i=1;i<=50;i++)
				{
					ihMultiCity += '<tr>';
						ihMultiCity += '<td align="left">';
							ihMultiCity += '<span class="contentSHPopupNew lang" align="left">City, State</span>';
						ihMultiCity += '</td>';													
						ihMultiCity += '<td align="left">';
							ihMultiCity += '<input type="textbox" id="searchCSZ'+i+'" size="18" name="searchCSZ'+i+'" class="textboxBlue" value=""  readonly  />';
						ihMultiCity += '</td>';													
					ihMultiCity += '</tr>';
				}
			ihMultiCity += '</table>';									
		ihMultiCity += '</div>';
		ihMultiCity += '</td>';													
		ihMultiCity += '</tr>';
		
		ihMultiCity += '<tr>';
					ihMultiCity += '<td align="right" colspan="2" width="100%" class="borderTop">';
						ihMultiCity += '<a href="javascript:gotoSingPropMulti();" class="linkOkCancleSH">Go</a>&nbsp;&nbsp;';
						ihMultiCity += '<a href="javascript:clearMulti();" class="linkOkCancleSH">Clear All</a>&nbsp;&nbsp;';
						ihMultiCity += '<a href="javascript:closePopUpMultiCity();" class="linkOkCancleSH">Close</a>&nbsp;';
					ihMultiCity += '</td>';													
				ihMultiCity += '</tr>';
		ihMultiCity += '</table><input type="hidden" id="lat"><input type="hidden" id="longi">';									
		
		var myDiv = document.createElement('div');
		myDiv.id = "divPopUpMultiCity";
		myDiv.name = "divPopUpMultiCity";
		myDiv.style.display = "none";
		myDiv.style.position = "absolute";
		myDiv.className = "divContainerAdvannceSearchMulti";
		if(isIE)
		{
			myDiv.style.width = "290px";
			myDiv.style.styleFloat = "left";
		}
		else
		{
			myDiv.style.width = "290px";
			myDiv.style.cssFloat = "left";
		}
		myDiv.style.height = "300px";
		//myDiv.style.overflow = "auto";
		myDiv.innerHTML = ihMultiCity;
		document.body.appendChild(myDiv);
	}
	return $('divPopUpMultiCity');
}

function clearMulti()
{
	for(var i=1;i<=50;i++)
	{
		$('searchCSZ'+i).value = '';
	}
	//clearHash
	cityList = new Hash();

}

function closePopUpMultiCity()
{
	$('divPopUpMultiCity').style.display = "none";
}

function gotoSingPropMulti()
{
	var lat = "";
	var lng = "";
	lat = $("lat").value;
	lng = $("longi").value;
	//alert(2 +" "+lat+","+lng);
	var state="";
	var city="";
	for(i=1;i<=50;i++)
	{
		if($("searchCSZ"+i).value!="")
		{
			var arrCityState = (trim($("searchCSZ"+i).value)).split(",");
			city += trim(arrCityState[0]) + "|";
			state += trim(arrCityState[1]) + "|";
		}	
	}
	if(city.length == 0)
	{
		alert("Please select atleast one city");
		return;
	}
	city = city.substring(0,city.length-1);
	state = state.substring(0,state.length-1);
	listAllCity = city;
	var zip="";	var page=""; var action="start";var otherArgs="";

	if(bkTheme=="metrobrokers")
		page="METRO|multicity|mlsCountySearch";
	else
		page=bkTheme.toUpperCase();
		
	getGeoAdd(lat,lng,city,state,zip,page,action,otherArgs)
}*/


function funShowMultiCity()
{
	if($('divPopUpMultiCity') == null)
	{
		var ihMultiCity = new StringBuffer();
		ihMultiCity.append('<table align="center" style="border:3px double #192046;display:block;position:relative;border-collapse: separate;border-spacing: 3px;width:100%;*width:93%;" >');
		ihMultiCity.append('<tr>');
		ihMultiCity.append('<td valign="middle" >');
		ihMultiCity.append('<div id="divDataMultiCity" name="divDataMultiCity" style="width:290px;height:270px;position:relative;float:left;display:inline;vertical-align:middle;overflow:auto" align="left">');
			ihMultiCity.append('<table  id="multiCTFirst" align="center" border="0" width="100%" style="display:block;position:relative;border-collapse: separate;border-spacing: 3px;" >');
				ihMultiCity.append('<tr>');
					ihMultiCity.append('<td align="left" colspan="2">');
						ihMultiCity.append('<span id="multiErr"></span>');
					ihMultiCity.append('</td>');													
				ihMultiCity.append('</tr>');
				ihMultiCity.append('<tr>');
					ihMultiCity.append('<td align="left" colspan="2">');
						ihMultiCity.append('<span class="contentSHPopupNew lang" align="left">City, State</span>');
					ihMultiCity.append('</td>');													
				ihMultiCity.append('</tr>');
			ihMultiCity.append('</table>');									
		ihMultiCity.append('</div>');
		ihMultiCity.append('</td>');													
		ihMultiCity.append('</tr>');
		
		ihMultiCity.append('<tr>');
					ihMultiCity.append('<td align="right" colspan="2" width="100%" class="borderTop">');
						ihMultiCity.append('<a href="javascript:gotoSingPropMulti();" class="linkOkCancleSH">Go</a>&nbsp;&nbsp;');
						ihMultiCity.append('<a href="javascript:clearMulti();" class="linkOkCancleSH">Clear All</a>&nbsp;&nbsp;');
						ihMultiCity.append('<a href="javascript:closePopUpMultiCity();" class="linkOkCancleSH">Close</a>&nbsp;');
					ihMultiCity.append('</td>');													
				ihMultiCity.append('</tr>');
		ihMultiCity.append('</table><input type="hidden" id="lat"><input type="hidden" id="longi">');									
		
		var myDiv = document.createElement('div');
		myDiv.id = "divPopUpMultiCity";
		myDiv.name = "divPopUpMultiCity";
		myDiv.style.display = "none";
		myDiv.style.position = "absolute";
		myDiv.className = "divContainerAdvannceSearchMulti";
		if(isIE)
		{
			myDiv.style.width = "290px";
			myDiv.style.styleFloat = "left";
		}
		else
		{
			myDiv.style.width = "290px";
			myDiv.style.cssFloat = "left";
		}
		myDiv.style.height = "300px";
		myDiv.innerHTML = ihMultiCity.toString();
		document.body.appendChild(myDiv);
	}
	return $('divPopUpMultiCity');
}

function clearMulti()
{
	if(isIE)
	{
		var tbl = document.getElementById('multiCTFirst');
		var lastRow = tbl.rows.length;
		while(lastRow != 2)
		{
			tbl.deleteRow(lastRow-1);
			lastRow--;
		}
	}
	else
	{
		ihMultiCity = "";
		ihMultiCity += '<tr>';
			ihMultiCity += '<td align="left" colspan="2">';
				ihMultiCity += '<span id="multiErr"></span>';
			ihMultiCity += '</td>';													
		ihMultiCity += '</tr>';
		ihMultiCity += '<tr>';
			ihMultiCity += '<td align="left" colspan="2">';
				ihMultiCity += '<span class="contentSHPopupNew lang" align="left">City, State</span>';
			ihMultiCity += '</td>';													
		ihMultiCity += '</tr>';
		if($("multiCTFirst"))
			$("multiCTFirst").innerHTML = ihMultiCity;
	}
	
	cityList = new Hash();
}

function closePopUpMultiCity()
{
	$('divPopUpMultiCity').style.display = "none";
}

function gotoSingPropMulti()
{
	var lat = "";
	var lng = "";
	lat = $("lat").value;
	lng = $("longi").value;
	//alert(2 +" "+lat+","+lng);
	var state="";
	var city="";
	if(bkTheme=="lmsre")
	{
		var typeIncookie = "";
		typeInCookie = getSearchCookie("searchType");
		if(typeInCookie=="'non mls'")
			setSearchCookie("searchType","");
	}
	var cityLst = $('multiCTFirst').getElementsByTagName("input");
	for(i=0;i<=cityLst.length;i++)
	{
		if($(cityLst[i]) && $(cityLst[i]).value!="")
		{
			var arrCityState = (trim($(cityLst[i]).value)).split(",");
			city += trim(arrCityState[0]) + "|";
			state += trim(arrCityState[1]) + "|";
		}	
	}
	if(city.length==0)
	{
		alert("Please select atleast one city");
		return;
	}
	city = city.substring(0,city.length-1);
	state = state.substring(0,state.length-1);
	listAllCity = city;
	var zip="";	var page=""; var action="start";var otherArgs="";

	if(bkTheme=="metrobrokers")
		page="METRO|multicity|mlsCountySearch";
	else
		page=bkTheme.toUpperCase();
		
	getGeoAdd(lat,lng,city,state,zip,page,action,otherArgs)
}

var arrDataCounty = new Array();
var arrDataNeighborHood = new Array();
function funShowAdvanceSearch(srchcrt,page,e)
{	
	funCloseAdvanceSearch();
	if($("divContainerAdvannceSearch"))
		$("divContainerAdvannceSearch").style.display="";
	if($("divPopUpSHPower"))
		$("divPopUpSHPower").style.display="";	

	$("divContainerAdvanceSearch").style.width = "290px";
	switch(srchcrt)
	{
		case "multicity":
			$("divContainerAdvanceSearch").style.width = "250px";
			Element.removeClassName($("divSHMultiCity").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHMultiCity").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHMultiCity").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
			break;
		case "more":
			setAllCookieValue('sqft');
     		setAllCookieValue('listdate');
			$("divContainerAdvanceSearch").style.width = "400px";
			$("divPopUpSHSqft").style.display = "inline";
			$("divPopUpSHListDate").style.display = "inline";
			
			//for property styles
			if($("divPopUpSHPropStyle"))
			{
				var arrChkBox = $('propStyleDv').getElementsByTagName("input");
				var lenArrChkBox = arrChkBox.length;
				var allChked = true;
				var strChkBox = getSearchCookie("propStyle");

				if(strChkBox == "" || strChkBox == null)
				{
					for(var i=0;i<lenArrChkBox;i++)
					{
				    	if(arrChkBox[i].id == "chkStyleAll")
				    	{
				    		continue;
				    	}
		    			if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == false)
		    			{
		    				arrChkBox[i].checked = true;
		    			}
					}
				}
				else
				{
					var arrStrChkBox = strChkBox.split(":");
					for(var i=0;i<lenArrChkBox;i++)
					{
						if (arrChkBox[i].id == "chkStyleAll")
						{
							continue;
						}
						if(arrChkBox[i].type == "checkbox")
						{
							var valChkBox = arrChkBox[i].value;
		    				if(arrStrChkBox.in_array(valChkBox) !== false)
		    				{
		    					arrChkBox[i].checked = true;
		    				}
							else
							{
								allChked = false;
								arrChkBox[i].checked = false;
							}
						}						
					}
				}

				if(allChked == true)
				{
					$("chkStyleAll").checked = true;
				}
				else
				{
					var confAllChked = true;
					for(var i=0;i<lenArrChkBox;i++)
					{
						if (arrChkBox[i].id == "chkStyleAll")
						{
							continue;
						}
						if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
						{
							confAllChked = false;
							break;
						}
					}
					
					if(confAllChked == true)
					{
						for(var i=0;i<lenArrChkBox;i++)
						{
							if(arrChkBox[i].type == "checkbox")
								arrChkBox[i].checked = true;
						}
					}
					else
						$("chkStyleAll").checked = false;
				}
				$("divPopUpSHPropStyle").style.display = "inline";
			}

			//for parking styles
			if($("divPopUpSHGarage"))
			{
				setAllCookieValue("garage");
				/*var arrChkBox = $('parkingStyleDv').getElementsByTagName("input");
				var lenArrChkBox = arrChkBox.length;
				var allChked = true;
				for(var i=0;i<lenArrChkBox;i++)
				{
					if (arrChkBox[i].id == "chkParkingStyleAll")
					{
						continue;
					}
					if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
					{
						continue;
					}
					else
					{
						allChked = false;
						break;
					}
				}
				if(allChked == true)
				{
					$("chkParkingStyleAll").checked = true;
				}
				else
				{
					$("chkParkingStyleAll").checked = false;
				}*/
				$("divPopUpSHGarage").style.display = "inline";
			}

			$("divPopUpSHMLSInfo").style.visibility = "hidden";
			$('searchCSZ').value = $('searchCSZ').value.replace (/^\s+/g, '').replace (/\s+$/g, '').replace (/\s+/g, ' ');
			if(countySearchEnabled == 1)
			{
				if((trim($('searchCSZ').value) == "")||(trim($('searchCSZ').value).toLowerCase () == "required"))
				{
					var ihCounty = "";
					ihCounty = ihCounty + '<a href="javascript:void(0);" onclick="javascript:funGetCounty(\'county\',\''+page+'\');" class="linkOkCancleSH lang">Get County Information</a>'; 
					$("divSHDataCounty").innerHTML = ihCounty;
					$("divPopUpSHCounty").style.display = "inline";
				}
				else
				{
					var isCompare = funCompareSearchCookie();
					if(isCompare === 1)
					{
						var ihCounty = "";
						ihCounty = ihCounty + '<a href="javascript:void(0);" onclick="javascript:funGetCounty(\'county\',\''+page+'\');" class="linkOkCancleSH lang">Get County Information</a>'; 
						$("divSHDataCounty").innerHTML = ihCounty;
						$("divPopUpSHCounty").style.display = "inline";
					}
					else
					{
						if(arrDataCounty.length == 0)
						{
							funGetCounty(srchcrt,page);
						}
						else
						{
							var strCKCounty = getSearchCookie("county");
							var arrCKCounty = strCKCounty.split(',');
							var ihCounty = "";
							var lenArrDataCounty = arrDataCounty.length;
							ihCounty = ihCounty + '<table cellpadding="0" cellspacing="0" style="width:100%;height:100%;">';
							for(var i=0;i<lenArrDataCounty;i++)
							{
								var countyName = arrDataCounty[i]['county'];
								ihCounty = ihCounty + '<tr>'; 
									ihCounty = ihCounty + '<td style="width:20%;">'; 
										if(arrCKCounty.in_array(countyName) !== false)
										{
											ihCounty = ihCounty + '<input type="checkbox" value="'+countyName+'" checked="checked" />';
										}
										else
										{
											ihCounty = ihCounty + '<input type="checkbox" value="'+countyName+'"  />';
										}	
									ihCounty = ihCounty + '</td>'; 
									ihCounty = ihCounty + '<td style="width:80%;">'; 
										ihCounty = ihCounty + '<span class="contentSHPopup lang">'+countyName+'</span>';
									ihCounty = ihCounty + '</td>'; 
								ihCounty = ihCounty + '</tr>'; 
							}	
							ihCounty = ihCounty + '</table>';
							
							$("divSHDataCounty").innerHTML = ihCounty;
							$("divPopUpSHCounty").style.display = "inline";
						}
					}
				}
			}
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "county":
			var isContradict = funCheckContradict();
			if(isContradict == null || isContradict == 0)
			{
				return;
			}
			if(arrDataCounty.length == 0)
			{
				funGetCounty(srchcrt,page);
			}
			else
			{
				var strCKCounty = getSearchCookie("county");
				var arrCKCounty = strCKCounty.split(',');
				var ihCounty = "";
				var lenArrDataCounty = arrDataCounty.length;
				ihCounty = ihCounty + '<table cellpadding="0" cellspacing="0" style="width:100%;height:100%;">';
				for(var i=0;i<lenArrDataCounty;i++)
				{
					var countyName = arrDataCounty[i]['county'];
					ihCounty = ihCounty + '<tr>'; 
						ihCounty = ihCounty + '<td style="width:20%;">'; 
							if(arrCKCounty.in_array(countyName) !== false)
							{
								ihCounty = ihCounty + '<input type="checkbox" value="'+countyName+'" checked="checked" />';
							}
							else
							{
								ihCounty = ihCounty + '<input type="checkbox" value="'+countyName+'"  />';
							}	
						ihCounty = ihCounty + '</td>'; 
						ihCounty = ihCounty + '<td style="width:80%;">'; 
							ihCounty = ihCounty + '<span class="contentSHPopup lang">'+countyName+'</span>';
						ihCounty = ihCounty + '</td>'; 
					ihCounty = ihCounty + '</tr>'; 
				}	
				ihCounty = ihCounty + '</table>';
				
				$("divSHDataCounty").innerHTML = ihCounty;
				Element.removeClassName($("divSHCounty").getElementsByTagName('a')[0],'linkAdvanceSearch');
				Element.addClassName($("divSHCounty").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
				$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHMLSInfo").style.visibility = "visible";
				$("divPopUpSHCounty").style.display = "inline";
			}
			break;
		case "neighborhood":
			if ($('searchCSZ').value.search(/;/) > -1)
			{
				$('divPopUpSHNeighborHood').style.height = "50px";
				$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
				$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Please select single city to enable neighborhood search.</span>';
				$("divPopUpSHMLSInfo").style.visibility = "hidden";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
				headerContent("neighborhood");
				break;
			}
			if($('chkmapSearchSelect') != null && $('chkmapSearchSelect').checked == true) 			
			{
				$('divPopUpSHNeighborHood').style.height = "50px";
				$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
				$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Please disable Map Search to enable neighborhood search.</span>';
				$("divPopUpSHMLSInfo").style.visibility = "hidden";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
				headerContent("neighborhood");
				break;
			}
			if(trim(getSearchCookie("county")) != "" && countySearchEnabled == "1")	
			{
				$('divPopUpSHNeighborHood').style.height = "50px";
				$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
				$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Please deselect county to enable neighborhood search.</span>';
				$("divPopUpSHMLSInfo").style.visibility = "hidden";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
				headerContent("neighborhood");
				break;
			}
			if($("txtArea") && $("txtArea").value != "")
			{
				$('divPopUpSHNeighborHood').style.height = "50px";
				$("divPopUpSHControls").innerHTML = '&nbsp<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';
				$("divSHDataNeighborHood").innerHTML = '<span class="contentSHPopup">Please disable Area Search to enable neighborhood search.</span>';
				$("divPopUpSHMLSInfo").style.visibility = "hidden";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
				headerContent("neighborhood");
				break;
			}
			
			var isContradict = funCheckContradict();
			if(isContradict == null || isContradict == 0)  
			{
				return;
			}
			if(arrDataNeighborHood.length == 0)
			{
				funGetNeighborHood(srchcrt,page);
			}
			else
			{
				$('divPopUpSHNeighborHood').style.height = "150px";
				var strCKNH = getSearchCookie("neighborhood");
				var arrCKNH = strCKNH.split(',');
				var ihNeighborHood = new StringBuffer();
				var lenArrDataNeighborHood= arrDataNeighborHood.length;
				ihNeighborHood.append('<table cellpadding="0" cellspacing="0" style="width:250px; height:100%;" border="0">');
					ihNeighborHood.append('<tr>'); 
						ihNeighborHood.append('<td style="width:30px;">'); 
							ihNeighborHood.append('<input type="checkbox" value=""  id="chbSHNHAll" name="chbSHNHAll" onclick="javscript:funSetSHNHAll();"/>');
						ihNeighborHood.append('</td>'); 
						ihNeighborHood.append('<td style="width:220px;">'); 
							ihNeighborHood.append('<span class="contentSHPopup lang">all</span>');
						ihNeighborHood.append('</td>'); 
					ihNeighborHood.append('</tr>'); 
				for(var i=0;i<lenArrDataNeighborHood;i++)
				{
					ihNeighborHood.append('<tr>'); 
						ihNeighborHood.append('<td style="width:30px;">'); 
							if(typeof(arrDataNeighborHood[i]['neighborhood']) != "undefined")
							{
								if((arrCKNH.in_array(arrDataNeighborHood[i]['neighborhood']) !== false) || (trim(strCKNH) == 'all'))
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['neighborhood']+'" onclick="javascript:funUnchkAllChkBox(this);" checked="checked" />');
								}
								else
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['neighborhood']+'" onclick="javascript:funUnchkAllChkBox(this);" />');
								}	
							}
							else if(typeof(arrDataNeighborHood[i]['area']) != "undefined")
							{
								if((arrCKNH.in_array(arrDataNeighborHood[i]['area']) !== false) || (trim(strCKNH) == 'all'))
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['area']+'" onclick="javascript:funUnchkAllChkBox(this);" checked="checked" />');
								}
								else
								{
									ihNeighborHood.append('<input type="checkbox" value="'+arrDataNeighborHood[i]['area']+'" onclick="javascript:funUnchkAllChkBox(this);" />');
								}
							}
						ihNeighborHood.append('</td>');
						ihNeighborHood.append('<td style="width:220px;">');
							if(typeof(arrDataNeighborHood[i]['neighborhood']) != "undefined")
								ihNeighborHood.append('<span class="contentSHPopup lang">'+arrDataNeighborHood[i]['neighborhood']+'</span>');
							else if(typeof(arrDataNeighborHood[i]['area']) != "undefined")
								ihNeighborHood.append('<span class="contentSHPopup lang">'+arrDataNeighborHood[i]['code']+" - "+arrDataNeighborHood[i]['area']+'</span>');
						ihNeighborHood.append('</td>'); 
					ihNeighborHood.append('</tr>'); 
				}	
				ihNeighborHood.append('</table>');
				$("divSHDataNeighborHood").innerHTML = ihNeighborHood.toString();
				var arrChkBox = $('divSHDataNeighborHood').getElementsByTagName("input");
				var lenArrChkBox = arrChkBox.length;
				var allChked = true;
				for(var i=0;i<lenArrChkBox;i++)
				{
			    	if((arrChkBox[i].id == "chbSHNHAll") || (arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true))
			    	{
			    		continue;
			    	}
					else
					{
						allChked = false;
						break;
					}
				}
				if(allChked == true)
				{
					$("chbSHNHAll").checked = true;
				}
				Element.removeClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkAdvanceSearch');
				Element.addClassName($("divSHNeighborHood").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
				$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
				$("divPopUpSHMLSInfo").style.visibility = "visible";
				$("divPopUpSHControls").style.display = "inline";
				$("divPopUpSHNeighborHood").style.display = "inline";
			}
			break;
		case "price":
			Element.removeClassName($("divSHPrice").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHPrice").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHPrice").style.display = "inline";
			if($("minPrice") && getSearchCookie("minPrice")!='0' && getSearchCookie("minPrice")!='') $("minPrice").value = addCommas(getSearchCookie("minPrice"));
			if($("maxPrice") && getSearchCookie("maxPrice")!='0' && getSearchCookie("maxPrice")!='') $("maxPrice").value = addCommas(getSearchCookie("maxPrice"));
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "beds":
			setAllCookieValue('beds');
			Element.removeClassName($("divSHBeds").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHBeds").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHBeds").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "baths":
			setAllCookieValue('baths');
			Element.removeClassName($("divSHBaths").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHBaths").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHBaths").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "sqft":
			Element.removeClassName($("divSHSqft").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHSqft").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHSqft").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "listdate":
			Element.removeClassName($("divSHListDate").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHListDate").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHListDate").style.display = "inline";
			$("divPopUpSHMLSInfo").style.visibility = "visible";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "type":
			var arrChkBox = $('divPopUpSHType').getElementsByTagName("input");
			var lenArrChkBox = arrChkBox.length;
			var allChked = true;
			for(var i=0;i<lenArrChkBox;i++)
			{
				if (arrChkBox[i].id == "chbSHTypeAll")
				{
					continue;
				}
				if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
				{
					continue;
				}
				else
				{
					allChked = false;
					break;
				}
			}
			if(allChked == true)
			{
				$("chbSHTypeAll").checked = true;
			}
			else
			{
				$("chbSHTypeAll").checked = false;
			}

			Element.removeClassName($("divSHType").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHType").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHType").style.display = "inline";
			$("divPopUpSHMLSInfo").style.visibility = "visible";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "mls":
			Element.removeClassName($("divSHMLS").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHMLS").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			if(trim(getSearchCookie('mlsno')) != "")
			{
				$("searchMLS").value = trim(getSearchCookie('mlsno'));
			}
			else
			{
				$("searchMLS").value = "";
			}
			$("divPopUpSHMLS").style.display = "inline";
			$("divPopUpSHMLSInfo").style.visibility = "visible";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "sortby":
			Element.removeClassName($("divSHSortBy").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSHSortBy").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divPopUpSHSortBy").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;		
		case "power":
			$("divContainerAdvanceSearch").style.width = "456px";
			if($("divSHPowerSortBy"))
			{
				Element.removeClassName($("divSHPowerSortBy").getElementsByTagName('a')[0],'linkAdvanceSearch');
				Element.addClassName($("divSHPowerSortBy").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			}
			$("divPopUpSHPower").style.display = "inline";
			$("divPopUpSHControls").innerHTML = '<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchOK" name="anchorAdvanceSearchOK" onclick="javascript:funSaveAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">save</a>&nbsp;&nbsp;<a href="#" class="linkOkCancleSH lang"  id="anchorAdvanceSearchGo" name="anchorAdvanceSearchGo" onclick="javascript:funGoAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">go</a>&nbsp;&nbsp;<a href="javascript:void(0);" class="linkOkCancleSH lang"  id="anchorAdvanceSearchClose" name="anchorAdvanceSearchClose" onclick="javascript:funCloseAdvanceSearch(\''+srchcrt+'\',\''+page+'\');">close</a>';	
			$("divPopUpSHControls").style.display = "inline";
			break;
		case "saveSearch":
			Element.removeClassName($("divSaveSearch").getElementsByTagName('a')[0],'linkAdvanceSearch');
			Element.addClassName($("divSaveSearch").getElementsByTagName('a')[0],'linkSelAdvanceSearch');
			$("divSaveSearch").style.display = "inline";
			if($("errDivP")) $("errDivP").innerHTML = "";
			if($("txtSrchNm"))
			{
				$("txtSrchNm").value = "";
				$("txtSrchNm").className = 'lang';
			}
			if($("txtClient")) $("txtClient").value = "";
			if($("txtEmails"))
			{
				$("txtEmails").value = "";
				$("txtEmails").className = 'lang';
			}
			break;
		default: 
			return;
	}
	
	var element = Event.element(e);
	var objDiv = element.parentNode;
	var posLeft = getPositionLeft(objDiv);
	if(srchcrt=="power")
		posLeft -=7; 
	var posTop = getPositionTop(objDiv);
	$("divContainerAdvanceSearch").style.left = posLeft + "px";
	$("divContainerAdvanceSearch").style.top = eval(posTop + 15) + "px";
	if(!isIE && srchcrt=="more")	
			$("divContainerAdvanceSearch").style.top = eval(posTop + 9) + "px";
	$("divContainerAdvanceSearch").style.display = "block";
	
}

//====================================================
//LMSRE specific:
//it will check on two pan map..if multicity then give
//alert else allow to go and perform other action
//====================================================
function checkMultiCity()
{
		var cityPipeList = getSearchCookie("city");
		var stateMy = getSearchCookie("state");
		if($("searchCSZ"))
			var csz = $("searchCSZ").value;
		var flag = false;
		if(cityPipeList.indexOf("|") > -1)
		{
			flag=true;
		}
		else
		{
			flag=false;
		}
		return flag;
}
//====================================================
//LMSRE specific:
//called while dragging any bit,and onclik of 
//dashboard tab.
//====================================================
function callMultiCityCheck_Dashboard(fromWhere,bitzName)
{

	var cityPipeList = getSearchCookie("city");
	var csz = $("searchCSZ").value;	
	if(cityPipeList.indexOf("|") > -1  || csz=="required" || csz=="")
	{
		if(fromWhere == 'dashboard')
		{	
			bitzName = "dashboard";
			showPopupDivforMenu(bitzName,'mapit');
		}
		if(fromWhere == 'mapit')
		{
			bitzName = "mapit";
			showPopupDivforMenu(bitzName,'dashboard');
		}
		return false;
	}
	else if(fromWhere == "dashboard")
	{
		var qs = new Querystring();
		var isNoSearch = qs.get('noSearch');
		if(isNoSearch != null && trim(isNoSearch) == 1)
		{
			location.href="../dashboard/dashboardIndex.php?noSearch=1";
		}
		else if (bkTheme == 'reotexashomes') //to load reo bit as default on dashboard of reotexashomes
		{
			var now = new Date();
			now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
			var myObject = new Object();
			myObject.widget1X1="bankowned";
			setCookie("strWidgetCookie",$H(myObject).toJSON(),now);

			location.href="../dashboard/dashboardIndex.php";
		}
		else
		{
			location.href="../dashboard/dashboardIndex.php";
		}
	}
	else if(fromWhere == "mapit")
	{
		callExploreNeighbourhood(); 
	}
}
function callMultiCityCheck_Dashboard_Metro(fromWhere,bitzName)
{
	var cityPipeList = getSearchCookie("city");
	
	if(cityPipeList.indexOf("|") > -1)
	{
		if(fromWhere == 'dashboard')
			bitzName = "dashboard";
		showPopupDivforMenu(bitzName,'mapit');
		return false;
	}
	if(fromWhere == "dashboard")
	{
		location.href="../dashboard/dashboardIndex.php";
	}
}
/**
 * Extra useful functions to the standard javascript prototypes.
 * Added By: Pankit Bhanushali
 */
Array.prototype.intersection = function( value ) {

	var result = new Array();
	
	if( typeof value != "object" ) {
		value = new Array(value);
	}
	
    for( var tc = 0; tc<this.length; tc++) {
		for( var vc = 0; vc < value.length; vc++ ) {
	        if( this[tc] == value[vc] ) {
				result.push_back(value[vc]);
			}
		}
    }
    return result;
}
Array.prototype.push_back = function( value ) {
	if( typeof value == "object" && value.length ) {
		for( var count = 0; count < value.length; count++ ) {
			this[this.length] = value[count];
		}
	} else {
		this[this.length] = value;
	}
}

/** code for brokeragent light box to get all office list **/
function getOffice(type)
{
	var queryString="type=off";
	if(type != null)
		queryString="type=offLoc";
	var url="/app/listing/getOffice.php";
	ajaxRequest(url,queryString,officeCallBack);	
}

//Callback for Assign Lead
function officeCallBack(originalResponse)
{
	var responce = originalResponse.responseText;
	
	
	/*****************sanju, this code can u used if company name depends on office location****************************/
	
	/*
	var respArr = responce.split('<!sep!>');
	if(respArr[0] == 'offLoc')
	{
		$('allOfficeLoc').innerHTML = respArr[1];
		if($('radioOffice').checked)
			$('txtOfficeLoc').disabled= false;
		else
			$('txtOfficeLoc').disabled= true;
	}
	else if(respArr[0] == 'offM')
	{
		$('allOffice').innerHTML = respArr[1];
		if($('radioOffice').checked)
			$('txtOffice').disabled= false;
		else
			$('txtOffice').disabled= true;
	}
	else if(respArr[0] == 'off')
	{
		$('allOffice').innerHTML = respArr[1];
		if($('radioOffice').checked)
			$('txtOffice').disabled= false;
		else
			$('txtOffice').disabled= true;
	}
	* 
	********************************************/
	
	/********************sanju, code that will load both company name and office loc simultanously*************************************/
	
	if (bkTheme == "metrobrokers")
	{
		var respArr = responce.split('<!sep!>');
		$('allOffice').innerHTML = respArr[0];
		$('allOfficeLoc').innerHTML = respArr[1];
		if($('radioOffice').checked)
		{
			$('txtOffice').disabled= false;
			$('txtOfficeLoc').disabled= false;
		}
		else
		{
			$('txtOffice').disabled= true;
			$('txtOfficeLoc').disabled= true;
		}
	}
	else
	{
		$('allOffice').innerHTML = responce;
		if($('radioOffice').checked)
			$('txtOffice').disabled= false;
		else
			$('txtOffice').disabled= true;
	}
	
	/***************************************************************/
}

function offLocChanged()
{
	var offLocId = escape($("txtOfficeLoc").options[$("txtOfficeLoc").selectedIndex].value);
	var queryString="olid="+offLocId;
	var url="/app/listing/getOffice.php";
	ajaxRequest(url,queryString,officeCallBack);	
}

function funExploreMlsAddrMap()
{
	showDetail=1;
	latp = latLong.lat;
	lngp = latLong.lng;

	var city = getSearchCookie("city");
	var zip = getSearchCookie("zip");
	var state = getSearchCookie("state");
	var ad = getSearchCookie("searchAddress");	
	/*var mapLoadedBits = getCookie("strMapitCK");
	
	if (mapLoadedBits != "")
	{
		mapLoadedBits = mapLoadedBits + ",mlsaddrsearch";
	}
	else
	{
		mapLoadedBits = "mlsaddrsearch";
	}*/

	if(mapToShow == "")
	{
		setMapItCookie("mlsaddrsearch","add");
		newUrl = "/app/listing/singlePropertyLanding.php?PHPSESSID=&status=EXP&address=" + ad + "," + city + "," + state + "," + zip + ",,,," + latp + "," + lngp;
	}
	else
	{
		setMapItCookie("mlsNHoodMode","add");
		newUrl = "/app/listing/singlePropertyLanding.php?status=N&code=propView=1:::searchAddress="+ad+":::city="+city+":::state="+state+":::zip="+zip+":::neighborhood=:::county=:::minPrice="+getSearchCookie("minPrice")+":::maxPrice="+getSearchCookie("maxPrice")+":::searchBeds="+getSearchCookie("searchBeds")+":::searchBaths="+getSearchCookie("searchBaths")+":::id=355&mapCenter=("+latp+","+lngp+")&valChkMapSearchSelect=1&fe=&f=1&propLatitude="+latp+"&propLongitude="+lngp+"&mapZoom=13";
	}
	var myQs = new Querystring();
	var frm = myQs.get("frm");
	var aid = myQs.get("aid");
	if(frm != null && trim(frm) == 'agt' && aid != null && trim(aid) != "")
	{
		newUrl = newUrl + "&frm=agt&aid="+aid;

		//agentsite statistics
		var beds = getSearchCookie("searchBeds");
		var baths = getSearchCookie("searchBaths");
		var type = getSearchCookie("searchType");
		var minprice = getSearchCookie("minPrice");
		var maxprice = getSearchCookie("maxPrice");

		var url = "../../classes/emailStats.php";
		var qs = "from=search&aid="+aid+"&city="+city+"&type="+type+"&beds="+beds+"&baths="+baths+"&price="+minprice+"-"+maxprice+"&addr="+ad+"&mlsno=";

		ajaxRequest(url,qs);
		//statistics done
	}
	window.location.href = newUrl;
	return;
}

function gotoSellDshbrd(uid)
{
	if (uid != 1)
	{
		var myObject = new Object();
		myObject.widget1X1="recentsales";
		myObject.widget1X2="marketsnapshot";
		myObject.widget1X3="equity";
		myObject.widget2X1="valuehome";
		myObject.widget2X2="";
		myObject.widget2X3="";
		myObject.widget3X1="";
		myObject.widget3X2="";
		myObject.widget3X3="";

		var now = new Date();
		now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
		setCookie("strWidgetCookie",$H(myObject).toJSON(),now);

		location.href = "http://" + location.hostname + "/app/dashboard/dashboardIndex.php";
	}
	else
	{
		var queryStr="widgetsConf=1,1,25|1,2,46|1,3,57|2,1,58|2,2,|2,3,|3,1,|3,2,|3,3,&setUserPref=1";
		var url ="/app/dashboard/dshbrdProcess.php";
		ajaxRequest(url,queryStr,loadDecDash);
	}
}
function loadDecDash(response)
{
	location.href = "http://" + location.hostname + "/app/dashboard/dashboard.php";
}

function gotoDashBrdFoot(call)
{
	if(call == '1' || call == '0' )
		location.href = "http://" + location.hostname + "/terabitzApi/finance/index.php";
	else if(call == 'openhouse')
	{
		setSearchCookie("listType","openHome");		
		setSearchCookie("ohflag","1");		
		url = 	'/Search/'+getSearchCookie("state")+'/'+getSearchCookie("city");
		location.href = url;
	}
	else
	{
		ClrQckSrchCookies();
		location.href = "http://" + location.hostname + "/app/listing/singlePropertyLandingNew.php";
	}
}

function gotoDashBrdFoot_org(call)
{
	var city = getSearchCookie("city");
	var state= getSearchCookie("state");

	if(trim(city) == '' && city != null)
	{
		var now = new Date();
		now.setTime(now.getTime() + 3650 * 24 * 60 * 60 * 1000);
		city = "San Jose";
		state = "CA";
		latLongStr = "[{'lat':'37.316466','lng':'-121.873881'}]";
		setCookie("latLongCk",latLongStr, now);
		latLong = eval(getCookie("latLongCk"))[0];
		setSearchCookie("city", city);			
		setSearchCookie ("state", state);
	}

	if (call == 'openhouse')
		callMapIt(call);
	else if (call == 1 || call == 0)
		gotoSellDshbrd(call);
	else
		callMapIt();
}

startStack=function() { };  // A stack of functions to run onload/domready

registerOnLoad = function(func) 
{
   var orgOnLoad = startStack;
   startStack = function () {
      orgOnLoad();
      func();
      return;
   }
}

var ranOnload=false; // Flag to determine if we've ran the starting stack already.

if (document.addEventListener) 
{
  // Mozilla actually has a DOM READY event.
   document.addEventListener("DOMContentLoaded", function(){if (!ranOnload) {ranOnload=true; startStack();}}, false);
}
else if (document.all && !window.opera)
{
  // This is the IE style which exploits a property of the (standards defined) defer attribute
  document.write("<scr" + "ipt id='DOMReady' defer=true " + "src=//:><\/scr" + "ipt>");  
  document.getElementById("DOMReady").onreadystatechange=function(){
    if (this.readyState=="complete"&&(!ranOnload)){
      ranOnload=true;
      startStack();
    }
  }
}

var orgOnLoad=window.onload;
window.onload=function() 
{
	if (typeof(orgOnLoad)=='function') 
	{
		orgOnLoad();
	}
	if (!ranOnload) 
	{
		ranOnload=true;
		startStack();
	}
}

var funRplcImgBitzBar = function()
{
	if($('divIconCollect'))
	{
		var dashIcons = $('divIconCollect').getElementsByClassName('dashIconsDrag');
		for(var i=0;i<dashIcons.length;i++)
		{
			var divImgId = dashIcons[i].id;
			var widgetName = divImgId.gsub('divImg_','');
			var imgId =  'img_'+widgetName;
			$(imgId).src = $(imgId).src.gsub('blankImg.gif',eval('widgetsData.'+widgetName+'.img_n'));
		}
	}
	
}
/*
registerOnLoad(funRplcImgBitzBar);

var startup1 = function() {
   alert("I'm the first function!")
}

registerOnLoad(startup1);
registerOnLoad(function () {
   alert("I'm the second function!")
});
*/

function funMakeBitClickable(bitName,page,from)
{
	var ihBitz = new StringBuffer();
		ihBitz.append('<table border="0" style="font-size:0.7em;width:100%;height:100%;border-spacing:0px;">');
			ihBitz.append('<tr>');
				if(page != null && trim(page) == 'dashboard')
				{
					var innerTitleText = "Click to load on dashboard";
				}
				else
				{
					var innerTitleText = "Click to load on map";
				}	
				if(from=="API")
				{
					var innerTitleText = "Click on the bit to load.";
				}
				ihBitz.append('<td align="center" valign="top"  onmouseover="try{showTooltip(\''+innerTitleText.stripTags()+'\',event);}catch(e){}" onmouseout="try{hideTooltip();}catch(e){}">');
					try
					{
						var bitImg = eval('widgetsData.'+bitName+'.img_n');
						var bitTitle = eval('widgetsData.'+bitName+'.title');
					}
					catch(e)
					{
						var bitImg = "";
						var bitTitle = "";
						
					}
				if(page != null && trim(page) == 'dashboard')
					{
						ihBitz.append('<img id="img_'+bitName+'" style="cursor:pointer;" class="crsr" src="../../wt/'+bkTheme+'/images/dashboard/toolbarIcons/'+bitImg+'"  title="" alt="'+bitTitle+'" onclick="javascript:funLoadOnDashboard(\''+bitName+'\');" />');
					}
					else
					{
						ihBitz.append('<img id="img_'+bitName+'" style="cursor:pointer;" class="crsr" src="../../wt/'+bkTheme+'/images/dashboard/toolbarIcons/'+bitImg+'"  title="" alt="'+bitTitle+'" onclick="javascript:funLoadOnMap(\''+bitName+'\');" />');
					}	
				ihBitz.append('</td>');
			ihBitz.append('</tr>');
		ihBitz.append('</table>');
		if($('divImg_'+bitName))
		{
            $('divImg_'+bitName).innerHTML = ihBitz.toString();
            $('img_'+bitName).onmouseover = revealThumbnail;
            $('img_'+bitName).onmouseout = hideThumbnail;
        }
}
function funLoadedOnMap(bitName,page)
{
	//alert('This bit is already loaded on map.'); 
	if(bitName == "wikipedia")
	{
		mapItCtrl.removeIcon_(mapItCtrl.getContainer_(),bitName);
		map.removeOverlay(wikiLayer);
		funMakeBitClickable(bitName);
		
		var currUrl = location.href;
		if(!currUrl.include("singlePropertyLanding.php"))
			unfillLoaded(bitName);
		return;
	}
	if(typeof(unfillLoaded)!="undefined")
	{
		unfillLoaded(bitName);
	}
	closeMapBit (bitName);
	funMakeBitClickable (bitName);
	return;
}
function funLoadedOnDashboard(bitName,page)
{
	//alert('This bit is already loaded on Dashboard.'); 
	funCloseWidget(null,bitName);
	return;
}
function funMakeBitNonClickable(bitName,page)
{
	var ihBitz = new StringBuffer();
		ihBitz.append('<table border="0" style="font-size:0.7em;width:100%;height:100%;border-spacing:0px;">');
			ihBitz.append('<tr>');
				if(page != null && trim(page) == 'dashboard')
				{
					var innerTitleText = "Click on the bit to remove.";
				}
				else
				{
					var innerTitleText = "Click on the bit to remove.";
				}	
				ihBitz.append('<td align="center" valign="top"  class="maskNonClickableBit" onmouseover="try{showTooltip(\''+innerTitleText.stripTags()+'\',event);}catch(e){}" onmouseout="try{hideTooltip();}catch(e){}">');
					var bitImg = eval('widgetsData.'+bitName+'.img_n');
					var bitTitle = eval('widgetsData.'+bitName+'.title');
					if(page != null && trim(page) == 'dashboard')
					{
						ihBitz.append('<img  id="img_'+bitName+'"  class="crsr" src="../../wt/'+bkTheme+'/images/dashboard/toolbarIcons/'+bitImg+'"  title="" alt="'+bitTitle+'" onclick="javascript:funLoadedOnDashboard(\''+bitName+'\');" />');
					}
					else
					{
						ihBitz.append('<img  id="img_'+bitName+'"  class="crsr" src="../../wt/'+bkTheme+'/images/dashboard/toolbarIcons/'+bitImg+'"  title="" alt="'+bitTitle+'" onclick="javascript:funLoadedOnMap(\''+bitName+'\');" />');
					}	
				ihBitz.append('</td>');
			ihBitz.append('</tr>');
		ihBitz.append('</table>');
	$('divImg_'+bitName).innerHTML = ihBitz.toString();
	$('img_'+bitName).onmouseover = hideThumbnail;
	$('img_'+bitName).onmouseout = hideThumbnail;
//	$('divImg_'+bitName).style.display = 'none';
}
function funMakeSummaryHeader(page)
{
	/*var ihSummaryHeader = new StringBuffer();
	if(page != null && trim(page) == 'dashboard')
		ihSummaryHeader = ihSummaryHeader + '<table style="width:180px;height:17px;" cellspacin="0" cellpadding="0" id="tblSummaryHeader">';
	else
		ihSummaryHeader = ihSummaryHeader + '<table style="width:178px;height:17px;" cellspacin="0" cellpadding="0" id="tblSummaryHeader">';
        ihSummaryHeader = ihSummaryHeader + '<tr>';
			ihSummaryHeader = ihSummaryHeader + '<td class="bgLeftSummaryHeader">&nbsp;</td>';
			if(page != null && trim(page) == 'dashboard')
				ihSummaryHeader = ihSummaryHeader + '<td class="bgMiddleSummaryHeader" align="center" valign="middle" id="tdSummaryHeader" style="width:164px;">';
			else
				ihSummaryHeader = ihSummaryHeader + '<td class="bgMiddleSummaryHeader" align="center" valign="middle" id="tdSummaryHeader" style="width:164px;">';
				
					ihSummaryHeader = ihSummaryHeader + '<span class="textSummaryHeader" id="spanSummaryHeader" >';
					if(page != null && trim(page) == 'dashboard')
						ihSummaryHeader = ihSummaryHeader + 'Currently active on dashboard';
					else
						ihSummaryHeader = ihSummaryHeader + 'Currently active on map';
					ihSummaryHeader = ihSummaryHeader + '</span>';
					
			ihSummaryHeader = ihSummaryHeader + '</td>';
			ihSummaryHeader = ihSummaryHeader + '<td class="bgRightSummaryHeader">&nbsp;</td>';
		ihSummaryHeader = ihSummaryHeader + '</tr>';
		
	ihSummaryHeader = ihSummaryHeader + '</table>';
	
	var myDiv = document.createElement('div');
	if(page != null && trim(page) == 'dashboard')
		myDiv.style.width = '180px';
	else
		myDiv.style.width = '170px';
	myDiv.style.position = 'absolute';
	if(page != null && trim(page) == 'dashboard')
	{
		var objSummaryArea = document.getElementById('divSummaryArea');
		var posLeft = getPositionLeft(objSummaryArea);
		var posTop = getPositionTop(objSummaryArea);
		myDiv.style.left = posLeft+'px';
		myDiv.style.top = (posTop-17)+'px';
	}
	else
	{
		var objIconContaner = document.getElementById('myIconContainer');
		var posLeft = getPositionLeft(objIconContaner);
		var posTop = getPositionTop(objIconContaner);
		myDiv.style.left = posLeft+'px';
		myDiv.style.top = (posTop-17)+'px';
	}	
	myDiv.innerHTML = ihSummaryHeader;
	document.body.appendChild(myDiv);*/
}
function funMakeSummaryArea(page)
{
	/*var objBitzBarHeader = document.getElementsByClassName('menuTrTb')[0];
	var posLeft = getPositionLeft(objBitzBarHeader);
	var posTop = getPositionTop(objBitzBarHeader);
	
	var divSummaryArea = document.createElement("div");
	divSummaryArea.id="divSummaryArea";
	divSummaryArea.className = "containerClass";
	
	if(page != null && trim(page) == 'dashboard')
		divSummaryArea.style.width = "178px";
	else
		divSummaryArea.style.width = "168px";
	divSummaryArea.style.cursor = 'default';	
	divSummaryArea.style.height = "50px";
	divSummaryArea.style.position = "absolute";
	divSummaryArea.style.left = eval(posLeft-190)+'px';
	divSummaryArea.style.top = eval(posTop+35)+'px';
	if(page != null && trim(page) == 'dashboard')
	{
		divSummaryArea.innerHTML = '<table cellspacing="0" cellpadding="0" style="cursor:default;width:100%;height:100%;"><tr><td style="width:100%;height:100%;" align="center" valign="middle" class="infoSummaryHeader">Click icons on right to populate dashboard.</td></tr></table>';
	}
	else
	{
		divSummaryArea.innerHTML = '<table cellspacing="0" cellpadding="0" style="cursor:default;width:100%;height:100%;"><tr><td style="width:100%;height:100%;" align="center" valign="middle" class="infoSummaryHeader">Click icons on right to populate map.</td></tr></table>';
	}
	//document.body.appendChild(divSummaryArea);
	funMakeSummaryHeader(page);*/
}
function funShowCrossedImage(objImg)
{
	var imgSrc = objImg.src;
	var newSrc = imgSrc.replace('.gif','Crossed.gif');
	objImg.src = newSrc;
}
function funHideCrossedImage(objImg)
{
	var imgSrc = objImg.src;
	var newSrc = imgSrc.replace('Crossed.gif','.gif');
	objImg.src = newSrc;
}
var cntLoadedBitz = 0;
function funAddBitToSummaryArea(bitName,page)
{
	if(page != null && trim(page) == 'dashboard')
	{
		if(cntLoadedBitz == 0)
		{
			//$('divSummaryArea').innerHTML = '';
		}
		var objDiv = document.createElement('div');
		objDiv.id = 'divSumBit_'+bitName;
		if(isIE)
			objDiv.style.styleFloat = 'left';
		else
			objDiv.style.cssFloat = 'left';
		objDiv.style.position = 'relative';
		objDiv.style.display = 'inline';
		objDiv.style.width = '29px';
		objDiv.style.height = '25px';
		objDiv.innerHTML = '<img src="/wt/'+bkTheme+'/images/common/'+bitName+'.gif" title="Remove '+unescape(widgetsData[bitName]['title']).stripTags()+'" alt="'+unescape(widgetsData[bitName]['title']).stripTags()+'" style="cursor:pointer" onmouseover="javascript:funShowCrossedImage(this);" onmouseout="javascript:funHideCrossedImage(this);" onclick="javascript:funRemoveBit(\''+bitName+'\',\''+page+'\');">';		
		//$('divSummaryArea').appendChild(objDiv);
		cntLoadedBitz = cntLoadedBitz + 1;
	}	
}
function funRemoveBit(bitName,page)
{
	if(page != null && trim(page) == 'dashboard')
	{
		funCloseWidget(null,bitName);
	}
}
function funRemoveImageFromSummaryArea(bitName,page,removeAll)
{
	if(removeAll != null && removeAll == true)
	{
		cntLoadedBitz = 0;
		//$('divSummaryArea').innerHTML = '<table cellspacing="0" cellpadding="0" style="cursor:default;width:100%;height:100%;"><tr><td style="width:100%;height:100%;" align="center" valign="middle" class="infoSummaryHeader">Click icons on right to populate dashboard.</td></tr></table>';
		return;
	}
	if(page != null && trim(page) == 'dashboard')
	{
		//if(($('divSummaryArea') != null) && ($('divSumBit_'+bitName) != null))
		//	$('divSummaryArea').removeChild($('divSumBit_'+bitName));
		cntLoadedBitz = cntLoadedBitz - 1;
		if(cntLoadedBitz == 0)
		{
		//	$('divSummaryArea').innerHTML = '<table cellspacing="0" cellpadding="0" style="cursor:default;width:100%;height:100%;"><tr><td style="width:100%;height:100%;" align="center" valign="middle" class="infoSummaryHeader">Click icons on right to populate dashboard.</td></tr></table>';
		}
	}
}

function openChatPage()
{
	var url = '/help/interoContactUs.php?hCity=' + getSearchCookie("city") + '&hState=' + getSearchCookie("state");
	window.open (url, '', '');
}

function setMapItckBlank(dshbrdUsrId)
{
	if(typeof(dshbrdUsrId) != "undefined" && dshbrdUsrId != "")
		setCookie('strMapitCK','');
}

function addCommas(num)
{
	var nStr = new String(num);
	if(nStr.indexOf(',') > 0)
	{					
		nStr = nStr.replace(/\,/g,'');
	}
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function numFormat(txtPrice)
{
	if($(txtPrice).value != '')
	{
		var price = $(txtPrice).value;
	
		if(price.indexOf(',') > 0)
		{					
			price = price.replace(/\,/g,'');
		}
		$(txtPrice).value = addCommas(price);
	}
}

function keyDown(e,txtprice)
{
	var keycode = e.keyCode;
	if(keycode!=37&& keycode!=38 &&keycode!=39&&keycode!=40)
	{
		numFormat(txtprice);
	}
}

function roundPrice(txtPrice)
{
	if($(txtPrice).value != '')
	{
		var valPrice = $(txtPrice).value;
		
		if(valPrice.indexOf(',') >= 0)
		{			
			valPrice = valPrice.replace(/\,/g,'');
		}
		if (!isNaN(valPrice))
		{
		   //$(txtPrice).value=addCommas(Math.round(valPrice));
		   $(txtPrice).value=addCommas(Math.round(valPrice));
		}
	}
}

function setAllCheckedStyle(from)
{
	if(typeof(from)!="undefined")
	{
		divId = "RSpropStyleDv";
		chkAllId = "RSchkStyleAll";
	}
	else
	{
		divId = "propStyleDv";
		chkAllId = "chkStyleAll";
	}

	if($(divId))
	{
		var arrChkBox = $(divId).getElementsByTagName("input");
		var lenChkBox = arrChkBox.length;

		for(var i=0;i<lenChkBox;i++)
		{	
			if(arrChkBox[i].id == chkAllId)
				continue;
			if(($(chkAllId).checked == true) && (arrChkBox[i].type == "checkbox"))
				arrChkBox[i].checked = true;
			else if(arrChkBox[i].type == "checkbox")
				arrChkBox[i].checked = false;
		}
	}
}

/*function setAllCheckedParkingStyle()
{
	if($("parkingStyleDv"))
	{
		var arrChkBox = $("parkingStyleDv").getElementsByTagName("input");
		var lenChkBox = arrChkBox.length;

		for(var i=0;i<lenChkBox;i++)
		{	
			if(arrChkBox[i].id == "chkParkingStyleAll")
				continue;
			if(($('chkParkingStyleAll').checked == true) && (arrChkBox[i].type == "checkbox"))
				arrChkBox[i].checked = true;
			else if(arrChkBox[i].type == "checkbox")
				arrChkBox[i].checked = false;
		}
	}
}*/

function chkAllOpt(chkAllID,divId)
{
   if($(divId))
	{
   var arrChkBox = $(divId).getElementsByTagName("input");
   lenOptWA = arrChkBox.length;
   lenOpt = arrChkBox.length - 1;
   chkCnt = 0;
   for(i=0;i<lenOptWA;i++)
   {
     if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
     {
       if(arrChkBox[i].id == chkAllID)
        continue;
       else
        chkCnt++; 
     }
   }
   if(chkCnt == lenOpt)
       $(chkAllID).checked = true;
   else
       $(chkAllID).checked = false; 
	}
}

function chkAllUnderDiv(divId,val)
{
	if($(divId)) {
		var arrChkBox = $(divId).getElementsByTagName("input");
		lenOptWA = arrChkBox.length;
		for(i=0;i<lenOptWA;i++)
		{
			if(arrChkBox[i].type == "checkbox" && val)		
				arrChkBox[i].checked = true;
			else
				arrChkBox[i].checked = false;
		}
	}
}

/*************** START ******************** USED FOR NEW POWER SEARCH AND LIST SEARCH CODE **********************/
function ClrQckSrchCookies()
{
	totalRecords = 0;	
	chkAllUnderDiv('divLocalSearch',false);
	removeSearchCookie("multicity");
	if(typeof(clearSearchTemplateParam) == 'function' )
		clearSearchTemplateParam();
	removeSearchCookie("mctSpanHTML");
	if($('showMultiCity')) $('showMultiCity').innerHTML = "";
	funClrQckSrchCookies();
	removeSearchCookie("listType");
	removeSearchCookie("propDesc");
	removeSearchCookie("ckLFDate");
	removeSearchCookie("ckLTDate");
	removeSearchCookie("mlsno");
	removeSearchCookie("nbrSpanHTML");
	//removeSearchCookie("spanHTML");
	removeSearchCookie("lat");
	removeSearchCookie("lng");	
	removeSearchCookie("polygon");
	removeSearchCookie("area");		
	if($('clrSerArea')) $('clrSerArea').style.display='none';
	if($('drawSerArea')) $('drawSerArea').style.display='';	
	lfDate = ''; ltDate = ''; mlsno = '';
	if($("RStxtLFDate"))  $("RStxtLFDate").value = '';
	if($("RStxtLTDate"))  $("RStxtLTDate").value = '';
	if($("RSsearchMLS")) $("RSsearchMLS").value = '';
	if($('frmAdvanceSearch')) $('frmAdvanceSearch').reset();
	if($('rsNHoodCntr')) $('rsNHoodCntr').style.display='none';	
	if($('shoNbhood')) $('shoNbhood').innerHTML= '';
	if($('keySerDiv'))  $('keySerDiv').innerHTML= '';
	//Added by surya for clearing the data from  temp string
	unChkstr  = "";
	chkdDat   = "";
	alwdCnt = 0 ;
	if (typeof(alwdCntMCT) != "undefined") alwdCntMCT = 0;
	if($('RSchbSHTypeAll')) $('RSchbSHTypeAll').checked = true;
	if($('polygonDiv')) $('polygonDiv').style.display='';	
	if($('serByNbrhood')) $('serByNbrhood').style.display='';		
	if($('searchMLS')) $('searchMLS').value = '';
	if($('pStatusList')) $('pStatusList').innerHTML = "";
	if($('pTypeList')) $('pTypeList').innerHTML = "";	
	try 
	{
		funSetSHTypeAll('RS'); 
	} 
	catch (err)
	{ 
	}
	if($('RSsearchMLS')) $('RSsearchMLS').value = '';	
	if(typeof(initPower) != 'undefined' && !initPower) 
	{
		try {
				savePrpType(); 
			}
		catch(err)
		{
		
		}
	}
	if($('bit_select_box')) $('bit_select_box').value = "";
	totalRecords = 0;	
	if(typeof(initPower) != 'undefined' && initPower)
	{
		var noRMsg = 'Select search criteria and Click "Agent View" Or "Consumer View".';
	}
	else
	{
		var noRMsg = 'Select search criteria and Click "Go".';
	}
	var noRecTblMsg = '<table align="center" id="noRecTbl" height="100%" cellspacing="0" cellpadding="0" style="width:450px;display:;"><tbody><tr><td valign="top" style="padding-top: 170px;"><table align="center" style="width: 490px;" valign="middle"><tbody><tr><td valign="top"><table cellspacing="0" cellpadding="0" border="0" align="center" style="width: 450px; height: 60px;" valign="middle"><tbody><tr style="height: 7px;"><td valign="bottom" class="msgTableTopleft"/><td valign="bottom" class="msgTableTopmid"/><td valign="bottom" class="msgTableTopright"/></tr><tr style="height: 44px;"><td class="msgTableCenleft"/><td class="msgTableCenmid"><font color="#666666"><span class="lang">'+noRMsg+'</span></font></td><td class="msgTableCenright"/></tr><tr style="height: 8px;"><td class="msgTableBotleft"/><td class="msgTableBotmid"/><td class="msgTableBotright"/></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>';
	if(!goToMap)
	{
		if($('proListingDiv')) { $('proListingDiv').innerHTML = noRecTblMsg; }
		if($('SortPageTbl')) { $('SortPageTbl').hide(); }
		if($("picdivImg_0") && totalRecords > 0)
		{
			if($('favRoloDiv')) $('favRoloDiv').style.display = '';
		}
		else
		{
			if($('favRoloDiv')) $('favRoloDiv').style.display = 'none';
		}
		if( $('miniMapContainer') ) { $('miniMapContainer').style.display = 'none'; }
		if( $("mapDiv") ) { $("mapDiv").style.display = 'none'; }
		if( $("drawsearchinfobar") ) { $("drawsearchinfobar").style.display = 'none'; }
		if( $("proListingDiv") ) { $("proListingDiv").style.display = ''; }
		if($('impMapShow'))
		{
			$('impMapShow').hide(); 
			$('impMapShow').innerHTML='View On Map'; 
		}
	}
	clearChkBoxInDiv("prpTyp");
    clearChkBoxInDiv("prpStat");
	if($("searchAddress")) $("searchAddress").className = "textboxSH";
	removeSearchCookie("spanStyleHTML");
	removeSearchCookie("propStyle")
	if($('prpStyleText')) $('prpStyleText').innerHTML = "";
	if(typeof(showMultiCityRelated) != "undefined" && typeof(showMultiCityRelated) == "function") 
	{
		showMultiCityRelated();
	}
}

/************************** USED FOR NEW POWER SEARCH AND LIST SEARCH CODE **********************/

/************************************* Lead Management For Ezee Doc Function Starts Here ***************************/

function createHomeValuePopUp()
{		
	
		if($('errLeadPro'))$('errLeadPro').innerHTML = "";
		if($('txtConsEmail')){$('txtConsEmail').className = "";$('txtConsEmail').value="";}
		if($('txtConsAddress'))$('txtConsAddress').className = "";
		if($('txtConsPhone'))$('txtConsPhone').className = "";
		if($('txtConsCity'))$('txtConsCity').className = "";
		if($('txtConsState'))$('txtConsState').className = "";
		if($('txtConsZip'))$('txtConsZip').className = "";

		flg=false;	
			if($("sqft"))
			{
				if($("sqft").value != "")
				{	
					if(($("txtAddress") && $("txtCSZ")) && ($("txtAddress") != null && $("txtCSZ")!= null))
					{
						var adr = escape($("txtAddress").value + "," + $("txtCSZ").value);
						var url = "/agentsite/processAgent.php";
						var qs = "process=validateAddress&address="+adr;
						ajaxRequest(url,qs,function(reqobj){ 
							var varResponse = trim(reqobj.responseText);
								if(varResponse != "")
								{
									flg = true;
									var arr = varResponse.split("|");
									
									if($("txtAddress"))$("txtAddress").value = arr[0];
									if($("txtCSZ"))$("txtCSZ").value = arr[1] + ", " + arr[2] + " " + arr[3];
									city=arr[1];
									state=arr[2];
									zip= arr[3];
								}
								else
								{
									alert("Invalid Address");
								}
						},false);

						if(flg)
						{
							
							top.$('leadFrmHomePopUp').style.display= "block";
							top.$('txtConsAddress').value=$('txtAddress').value;
							top.$('txtConsCity').value=city;
							top.$('txtConsState').value=state;
							top.$('txtConsZip').value=zip;
							top.$('errEmailPro').innerHTML="&nbsp;";		
							top.leadEmailDlg1.show();
							if(top.$('txtConsName'))top.$('txtConsName').focus();	
						}
					}
					else
						{
							
							if(typeof(estimateAddress) != "undefined"  && (typeof(estimateCity)!= "undefined" && typeof(estimateState)!= "undefined" && typeof(estimateZip)!= "undefined" ))
								{

										if($('leadFrmHomePopUp1')) $('leadFrmHomePopUp1').style.display= "block";	
										if($('txtConsName') != null)$('txtConsName').value = "";
										if($('txtConsAddress') != null){$('txtConsAddress').className=""; $('txtConsAddress').value=estimateAddress ; }
										if($('txtConsCity') != null){$('txtConsCity').className="" ; $('txtConsCity').value=estimateCity ;}
										if($('txtConsState') != null){$('txtConsState').className="" ; $('txtConsState').value=estimateState ;}
										if($('txtConsZip') != null){$('txtConsZip').className=""; $('txtConsZip').value=estimateZip ;}
										if(document.saleform.sale)
											document.saleform.sale[0].checked = true ;
										if($("txtConsComments") != null)$("txtConsComments").value = "";
										if($('errEmailPro')) $('errEmailPro').innerHTML="&nbsp;";		
										if(leadEmailDlg1 != "undefined") leadEmailDlg1.show();
										if($('leadFrmHomePopUp1_c')) $('leadFrmHomePopUp1_c').style.zIndex='17';
										if($('leadFrmHomePopUp1_mask')) $('leadFrmHomePopUp1_mask').style.zIndex='16';
										
								}
						}

				}
				
				else
				{
						alert("Please Enter Value in Square Feet.");
						$("sqft").className="textboxRed";
				}
			}	
}
	
/************************* Lead Management For Ezee Doc Function Ends Here *********************/

/*********************** USED FOR NEW POWER SEARCH AND LIST SEARCH CODE **********************/

function goToListSearch()
{
	//url = 	'/app/listing/singlePropertyLandingNew.php?city='+getSearchCookie("city")+'&state='+getSearchCookie("state");
	url = 	'/Search/'+getSearchCookie("state")+'/'+getSearchCookie("city");
	var qs = new Querystring();
	if(qs.get("frm") != null && trim(qs.get("frm")) == 'frch' && qs.get("ouid") != null)
	{
		url += "?frm="+trim(qs.get("frm"))+"&ouid="+trim(qs.get("ouid"));
	}
	if(qs.get("frm") != null && trim(qs.get("frm")) == 'agt' && qs.get("aid") != null)
	{
		url += "?frm="+trim(qs.get("frm"))+"&aid="+trim(qs.get("aid"));
	}
	if(qs.get("ps") != null )
	{
		url += "?ps="+trim(qs.get("ps"));
	}
	location.href=url;
}
function goToTools()
{
	url = 	'/terabitzApi/finance/index.php?city='+getSearchCookie("city")+'&state='+getSearchCookie("state");
	var qs = new Querystring();
	if(qs.get("frm") != null && trim(qs.get("frm")) == 'frch' && qs.get("ouid") != null)
	{
		url += "&frm="+trim(qs.get("frm"))+"&ouid="+trim(qs.get("ouid"));
	}
	if(qs.get("frm") != null && trim(qs.get("frm")) == 'agt' && qs.get("aid") != null)
	{
		url += "&frm="+trim(qs.get("frm"))+"&aid="+trim(qs.get("aid"));
	}
	if(qs.get("ps") != null )
	{
		url += "&ps="+trim(qs.get("ps"));
	}
	location.href=url;
}


function clearChkBoxInDiv(divId)
{
        if($(divId))
		{			
			var arrChkBox = $(divId).getElementsByTagName("input");
			for(i=0;i<arrChkBox.length;i++)
			{
				if(arrChkBox[i].type == "checkbox" && arrChkBox[i].checked == true)
				{
					arrChkBox[i].checked = false;
				}
			}
        }
}

function clearCityStateMLS()
{
	removeSearchCookie("city");	
	removeSearchCookie("state");
	removeSearchCookie("mlsno");
}