  
function addEventListener(elem, type, handler)
{
	if(elem.attachEvent)
	    elem.attachEvent("on"+type, handler);	
 
}

function doMOver(event)
{
	target.style.visibility = "visible";
	CancelEvent(event);
}

function doMOut(event)
{
	target.style.visibility = "hidden";
	CancelEvent(event);
}

function doMMove(event)
{
	var curX = event.clientX + document.body.scrollLeft;
	var curY = event.clientY + document.body.scrollTop;

	target.style.left = curX - 12;
	target.style.top = curY - 12;
	CancelEvent(event);
}

//Commented out code to attach listener to map + mouse events
//var target = document.getElementById("maptarget");
//var mapImage = document.getElementById("imgEsriMap");
//if(navigator.appName=="Microsoft Internet Explorer")
//{
//	addEventListener (mapImage, "mousemove", doMMove);
//	addEventListener (mapImage, "mouseover", doMOver);
//	addEventListener (mapImage, "mouseout", doMOut);
//}

function CancelEvent(e)
{
	if (!e) var e = window.event;
	e.returnValue = false;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	if (e.preventDefault) e.preventDefault();
}


<!--
function ShowInterMapDemo() 
{
	window.open("/includex/Flash/InterMapDemo.html","InterMapDemo","location=no,menubar=no,resizable=no,scrollbars=no,status=yes,toolbar=no,height=360,width=450");
}

function ShowVideo() 
{
	//window.open("/includex/Flash/MHP_SWF/cbbain_menu.html","CBBainVideo","location=no,menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no,height=360,width=560");
}

//Show/Hide Start (Shoaib)
//These functions are used to Show/Hide panels on the Default page.
function showHideLayerTop(layerID)
{
	if (layerID == 'mls') {
		document.getElementById('SearchByMLS_ContentWrapper').style.display = "block";
		document.getElementById('imgMLS').src = "../App_Themes/Default/Images/HomePage/search_by_mls_tab_on.gif";
		document.getElementById('MyHomePlannerBlock_ContentWrapper').style.display = "none";
		document.getElementById('imgMyHomePlanner').src = "../App_Themes/Default/Images/HomePage/my_hm_plner_tab_off.gif";
	}  
    else {
        
		document.getElementById('MyHomePlannerBlock_ContentWrapper').style.display = "block";
		document.getElementById('imgMyHomePlanner').src = "../App_Themes/Default/Images/HomePage/my_hm_plner_tab_on.gif";
		document.getElementById('SearchByMLS_ContentWrapper').style.display = "none";
		document.getElementById('imgMLS').src = "../App_Themes/Default/Images/HomePage/search_by_mls_tab_off.gif";
	}	
}

function showHideLayerBottom(layerID)
{
	if (layerID == 'agent') {
		document.getElementById('FindOfficeOrAgent_ContentWrapper').style.display = "block";		
		document.getElementById('imgOfficeAgent').src = "../App_Themes/Default/Images/HomePage/find_agent_tab_on.gif";
		document.getElementById('VideoBlock_ContentWrapper').style.display = "none";
		document.getElementById('imgCompareSolds').src = "../App_Themes/Default/Images/HomePage/video_tab_off.gif";
//		document.getElementById('imgCompareSolds').src = "./includeX/image/compare_solds_tab_off.gif";
	}  
    else {
		document.getElementById('FindOfficeOrAgent_ContentWrapper').style.display = "none";
		document.getElementById('imgOfficeAgent').src = "../App_Themes/Default/Images/HomePage/find_agent_tab_off.gif";
		document.getElementById('VideoBlock_ContentWrapper').style.display = "block";
		document.getElementById('imgCompareSolds').src = "../App_Themes/Default/Images/HomePage/video_tab.gif";
//		document.getElementById('imgCompareSolds').src = "./includeX/image/compare_solds_tab_on.gif";
	}	
}
//Show/Hide End (Shoaib)


var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
//debugger;
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";

// -->												
														
														

var theForm = document.forms['Form1'];
if (!theForm) {
    theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
														
														
								
								
								
								
								
<!--
function KeyPressedMLSName(e)
{
	var key;
	if(window.event)
	{
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which)
	{
		// netscape
		key = e.which; 				
	}
	else
	{
		// no event, so pass through
		return true;
	}
	
	if(key == 13)
	{
		//is enter key
		CancelEvent(e);
		//document.getElementById("ptMLS_imgmls").click(); Commented out: Shoaib 030508
		return false;
//		return validateForMLSSearch();
	}
	return true;
}

function validateForMLSSearch(e)
{		
//	var txtM1 = document.getElementById("ptMLS_txtM1");     Commented out: Shoaib 030508
//	var txtM2 = document.getElementById("ptMLS_txtM2");
//	var error = "";
//	if(txtM1.value=="" && txtM2.value=="" )
//		error += "Please supply an MLS#.\r\n";
//	if(validateNotlessfour(txtM1.value)&& txtM1.value!="" )
//	{
//		error += "One or more numbers supplied is not in the proper format. Please type in a valid MLS#.\r\n";
//		txtM1.focus();
//	}
//	if(validateNotlessfour(txtM2.value)&& txtM2.value!="" )
//	{
//		error += "One or more numbers supplied is not in the proper format. Please type in a valid MLS#.\r\n";
//		txtM2.focus();
//	}


//	if(error != "")
//	{
//		alert(error);
//		CancelEvent(e);
//	}
//	return true;
}

function CancelEvent(e)
{
	if (!e) var e = window.event;
	e.returnValue = false;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	if (e.preventDefault) e.preventDefault();
}
	//-->
	
/************* Utilities Functions *****************************/

/* This function is mostly used by Popups positioning ****/

var CounterEllipsis = 0;
function CentralizeAxis(objWidth, objHeight, doResize, doMove) {
    var DefaultLeft = screen.width / 4;
    var DefaultTop = screen.height / 4;

    var PosAxis = { "ScreenLeft": DefaultLeft, "ScreenTop": DefaultTop };

    if (objWidth != null)
        PosAxis.ScreenLeft = ((screen.width - objWidth) / 2);

    if (objHeight != null) {

        PosAxis.ScreenTop = (((screen.height - objHeight) / 2));
        if (PosAxis.ScreenTop > DefaultTop) 
            PosAxis.ScreenTop = DefaultTop;
    }

    if (doResize)
        window.resizeTo(objWidth, objHeight);
    
    if (doMove)
        window.moveTo(PosAxis.ScreenLeft, PosAxis.ScreenTop);
        
    return PosAxis;
}


//Ellipses if overflows
function OverflowEllipsis(cid) {

    var container = $("#" + cid);

    var ct = container.text();
    var cw = container.width();
    var sw = container.attr("scrollWidth");

    if (sw > cw) {
        CounterEllipsis++;
        ct = container.text().substring(0, (ct.length - 2));
        container.text(ct);
        sw = container.attr("scrollWidth");

        //For Recursive/ReAccurance
        OverflowEllipsis(cid);
    }
    else {
        if (CounterEllipsis > 0) {
            container.text(ct.substring(0, ct.length - 2) + "...");
            CounterEllipsis = 0;
        }
    }
}	

/********** Script Required for Home page ******* 01-06-2010 - AR */

   //Global Variables
   var SelectedButton;
   var FindHome;
   var QuickSearchType = { City: 1, Zip: 2, Address: 3, MLSID: 4 };
   var AutoCompleteObj;

   //Search Object
   function FindMyHome(id) {

       //PROPERTIES
       var IsSearchInputEdit = false;
       var SearchType = 0;
       var self = this;
       var btnResultOnListId;
       var btnResultOnMapId;
       var btnSearchResultsId;
       var NeedResetTextBox;

       //METHODS
       this.InitializeEvents = function(btnResultOnList,btnResultOnMap,btnSearchResults ) {

           btnResultOnListId = btnResultOnList;
           btnResultOnMapId = btnResultOnMapId;
           btnSearchResultsId = btnSearchResults;
           
           //For Address Seacrch (selection)
           var divSearchTypeContainer = $('#divSearchTypeOptions');

           $('.jqSubmitButton').each(function() {
               $(this).click(self.ValidateSearch);
           });

           //Default Focus COntrol
           //$(".rbSearchByNeighbourhood :radio").focus();
           $(".rbSearchByNeighbourhood :radio", divSearchTypeContainer).click(function() { FindHome.CustomizeSearchContentsForNaighborhood() });
           $(".rbSearchByZipCode :radio", divSearchTypeContainer).click(function() { FindHome.CustomizeSearchContentsForZipCode() });
           $(".rbSearchByAddress :radio", divSearchTypeContainer).click(function() { FindHome.CustomizeSearchContentsForAddress() });
           $(".rbSearchByMLS :radio", divSearchTypeContainer).click(function() { FindHome.CustomizeSearchContentsForMLS() });
               
          //For Combo Boxes
//           $(".jQCombo").each(function() {
//               var $this = $(this);
//              // var emptyText = $this.attr('EmptyText');
//               var deactive = $this.attr('disabled')
//               $this.sexyCombo({ emptyText: emptyText, autoFill: true, skin: "custom", triggerSelected: true });
//               if (deactive)
//                   $.sexyCombo.deactivate($this);
//           });
            //FindHome.DeActivateCombo();
            
            
            //For Autocomplate Initialize
            AutoCompleteObj = LoadAndInitAutoComplete();
            
            //check if reset needed for textboxes-- need to support browser back button
            NeedResetTextBox = FindHome.NeedResetText();
            switch(FindHome.GetSearchType())
            {
                case QuickSearchType.City:
                    FindHome.CustomizeSearchContentsForNaighborhood();
                    $(".rbSearchByNeighbourhood :radio").focus();
                break;
                case QuickSearchType.Zip:
                    FindHome.CustomizeSearchContentsForZipCode();
                    $(".rbSearchByZipCode :radio").focus();
                break;
                case QuickSearchType.Address:
                    FindHome.CustomizeSearchContentsForAddress();
                    $(".rbSearchByAddress :radio").focus();
                break;
                case QuickSearchType.MLSID:
                    FindHome.CustomizeSearchContentsForMLS();
                    $(".rbSearchByMLS :radio").focus();
                break;
                default:
                    FindHome.CustomizeSearchContentsForNaighborhood();
                    $(".rbSearchByNeighbourhood :radio").focus();
                    
            }


            
            // Set Default serach to neighborhood            

       }
       
       this.NeedResetText = function() 
       {
           var $search = $('#divSearchWaterMark');
           var $searchInputNormal = $('.jqSearchInput');
           //TODO
           var $searchInput = $search.find('.jqAutoComplete');
           
           return $searchInput.val() == '' && $searchInputNormal.val() == '';

       }
       
       this.GetSearchType = function(){
        
        if($(".rbSearchByNeighbourhood :radio").is(":checked"))
        {
            this.SearchType = QuickSearchType.City;
        }
        else if($(".rbSearchByZipCode :radio").is(":checked"))
        {
            this.SearchType = QuickSearchType.Zip;
        }
        else if($(".rbSearchByAddress :radio").is(":checked"))
        {
            this.SearchType = QuickSearchType.Address;
        }
        else if($(".rbSearchByMLS :radio").is(":checked"))
        {
            this.SearchType = QuickSearchType.MLSID;
        }
        else
        {
            this.SearchType = QuickSearchType.City;
        }
        
        return this.SearchType;
       
       }

       this.CustomizeSearchContentsDefault = function() {
           
           //For Search Buttons
           $("#divShowResults").show();
           $("#divSearchResults").hide();

           //For price contents
           $("#imgPriceRange").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/PriceRange.png" });
//           $(".jqPriceFrom").removeAttr("disabled");
//           $(".jqPriceTo").removeAttr("disabled");

           //For SquareFootage contents
           $("#imgSQFT").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/SquareFootage.png" });
//           $(".jqSQFT").removeAttr("disabled");

           //For Bedrooms contents
           $("#imgBedrooms").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/Beds.png" });
//           $(".jqBedrooms").removeAttr("disabled");
            
            //Combo's State
            this.ActivateCombo();

//           var $search = $('#divSearchWaterMark');
//           var $searchInputNormal = $('.jqSearchInput');
//           var $searchInput = $search.find('input');
//           var $searchLabel = $search.find('label');

//           //reset textboxe values
//           $searchInput.val('');
//           $searchInputNormal.val('');
//           $searchLabel.show();
           //this.SearchType = 0;
           
           
       }
       
       
       this.CustomizeSearchContentsDisable = function() {

           //For Search Buttons
           $("#divShowResults").hide();
           $("#divSearchResults").show();

           //For price contents
           $("#imgPriceRange").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/PriceRangeDisable.png" });
//           $(".jqPriceFrom").attr({ disabled: "disabled" });
//           $(".jqPriceTo").attr({ disabled: "disabled" });

           //For SquareFootage contents
           $("#imgSQFT").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/SquareFootageDisable.png" });
//           $(".jqSQFT").attr({ disabled: "disabled" });

           //For Bedrooms contents
           $("#imgBedrooms").attr({ src: "../App_Themes/Default/Images/NewDesign/HomePage/BedsDisable.png" });
//           $(".jqBedrooms").attr({ disabled: "disabled" });

            //For StylishCombo
           this.ResetControl();
           this.DeActivateCombo();
           
           //Switch Search Control
           $("#divAutoCompleteSearchTextBox").hide();
           $("#divNornalSearchTextBox").show();
       }
       


       this.CustomizeSearchContentsForNaighborhood = function() {
           //Set Default
           this.CustomizeSearchContentsDefault();
           //For Search Input text w.r.t options selected
           this.SetDefaultSearchTxt("Enter a City/Neighborhood here");
          
           
           //Enable control
           $("#"+btnResultOnListId).removeAttr("disabled");
           $("#"+btnResultOnMapId).removeAttr("disabled");
           //Switch Search Control
           $("#divAutoCompleteSearchTextBox").show();
           $("#divNornalSearchTextBox").hide();

           //set autosuggest to CityName
           AutoCompleteObj.SetExtraParam('1');
           this.InitializeWaterMarkTextBoxSearch();

           this.SearchType = QuickSearchType.City;
           //$(".rbSearchByNeighbourhood :radio").attr('checked',true);
       }

       this.CustomizeSearchContentsForZipCode = function() {
           //Set Default
           this.CustomizeSearchContentsDefault();
           //For Search Input text w.r.t options selected
           this.SetDefaultSearchTxt("Enter a Zip Code here");
           
         
           //Enable control
           $("#"+btnResultOnListId).removeAttr("disabled");
           $("#"+btnResultOnMapId).removeAttr("disabled");

           //Switch Search Control
           $("#divAutoCompleteSearchTextBox").show();
           $("#divNornalSearchTextBox").hide();
           //set autosuggest to zip
           AutoCompleteObj.SetExtraParam('2');
           this.InitializeWaterMarkTextBoxSearch();
           this.SearchType = QuickSearchType.Zip;
           $(".rbSearchByZipCode :radio").attr('checked',true);
       }

       this.CustomizeSearchContentsForAddress = function() {
           this.CustomizeSearchContentsDisable();
           //Enable control
           $("#"+btnSearchResultsId).removeAttr("disabled");

           //For Search Input text w.r.t options selected
           //TODO
           if(NeedResetTextBox){
            this.SetDefaultSearchTxt("Enter address here (Street Address, Zip Code)");
           }
                                     


           this.InitializeWaterMarkTextBoxSearch();
           this.SearchType = QuickSearchType.Address;
           $(".rbSearchByAddress :radio").attr('checked',true);
           
       }

       this.CustomizeSearchContentsForMLS = function() {
           //Set Default
           this.CustomizeSearchContentsDisable();


           //For Search Input text w.r.t options selected
           //ToDo
           if(NeedResetTextBox){
                this.SetDefaultSearchTxt("Enter MLS number(s) here, separated by commas");
           }

           this.InitializeWaterMarkTextBoxSearch();

           //Enable control
           $("#"+btnSearchResultsId).removeAttr("disabled");

                      
           this.SearchType = QuickSearchType.MLSID;
           $(".rbSearchByMLS :radio").attr('checked',true);
           
       }

       
        //For StylishCombo
        this.ActivateCombo = function(){
            
            //For Disbaled Image
            $("#StylishComboMain").attr("class","jqStylishComboMain newListSelected jqStylishCombo");
            $(".jqStylishComboMain").each(function(){
                $(this).attr("class","jqStylishComboMain newListSelected jqStylishCombo");
            });
            
            if($(".jqStylishCombo").length > 0){
                $(".jqStylishCombo").attr("disabled",false);
            }
        }
        
        this.DeActivateCombo = function(){
      
            //For Disbaled Image
            $("#StylishComboMain").attr("class","jqStylishComboMain newListSelectedDisabled jqStylishCombo");
            $(".jqStylishComboMain").each(function(){
                $(this).attr("class","jqStylishComboMain newListSelectedDisabled jqStylishCombo");
            });
                        
            
            $(".jqStylishCombo").each(function(index){
                $(this).attr("disabled",true);
                });  
                  
        }
            
       
       

       this.SwitchImageToDefault = function(obj, imgUrl) {
           obj.src = imgUrl;
       }

       this.SwitchImageToLive = function(obj, imgUrl) {
           obj.src = imgUrl;
       }
       //For Default Seach Value
       this.SetDefaultSearchTxt = function(strSearchTxt) {
           $("#lblSearchWaterMark").text(strSearchTxt);
       }

//       this.RestFilterControls = function() {
//           $(".jQCombo").each(function() {
//               $.sexyCombo.changeOptions($(this));
//           });
//       }

       this.InitializeWaterMarkTextBoxSearch = function() {
    
           var $search = $('#divSearchWaterMark');
           var $searchInputNormal = $('.jqSearchInput');
           var $searchInput = $search.find('input');
           var $searchLabel = $search.find('label');

          if(NeedResetTextBox)
          {
                //reset textboxe values
                $searchInput.val('');
                $searchInputNormal.val('');
                $searchLabel.show();
           }
           else
           {
                NeedResetTextBox = true;
           }
           //this.RestFilterControls();

           //if input textbox contains value then hide label from it
           if ($searchInput.val()) {
               $searchLabel.hide();
           }

           $searchInput
           .focus(function() {
               $searchLabel.hide();
           })

           .blur(function() {
               if (this.value == '') {
                   $searchLabel.show();
               }
           });

           $searchLabel.click(function() {
                   $searchInput.trigger('focus');
               });
           }

           this.ResetControl = function() {
                 
                 //For Stylish Combo
                 //cRef.resetSS();
                 cRef.getSetSSValue("0");
                 cRef.getSetSSValue("0");
           }

       this.ValidateSearch = function(sender, e) {
           
           SelectedButton = sender.target.alt;

           var $normalTextBox = $('.jqSearchInput');
           switch (self.SearchType) {
               case QuickSearchType.City:
                   return AutoCompleteObj.ValidateAutoComplete(QuickSearchType.City);
                   break;
               case QuickSearchType.Zip:
                   return AutoCompleteObj.ValidateAutoComplete(QuickSearchType.Zip);
                   break;
               case QuickSearchType.Address:
                   if (($.trim($normalTextBox.val()) != ""))
                       return true;
                   else {
                       $normalTextBox.focus();
                       alert("Please specify Address to search.");
                       return false;
                   }

                   break;
               case QuickSearchType.MLSID:
                   if (($.trim($normalTextBox.val()) != ""))
                       return true;
                   else {
                       $normalTextBox.focus();
                       alert("Please specify MLSID to search.");
                       return false;
                   }
                   break;
               default:
                   alert('No Search Type Selected.');
                   return false;
                   break;
           }
       }
   }
/********** Home Page Script Ends *************/


    /*Trim the object value and reset the trimmed value*/
    function TrimAndReSetVal(obj) {
        var tVal = $.trim($(obj).val());
        $(obj).val(tVal);
    }
