// enable distance dropdown
function enableDistanceDropDown(target) {
    if (target)
    {    
        var dropDown =  _proxy_jslib_handle(target, 'getElementsByTagName', '', 1, 0)('select')[0];
        if (dropDown && dropDown.disabled)
        {        
            dropDown.removeAttribute('disabled');
        }
    }
}

// key press handler
function keyPressHandler(e, buttonId) {
    var keyCode;
    
    if(!e)
    {
        e = window.event;
    }
    
    if(window.event) // IE
    {
        keyCode = event.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keyCode = e.which;
    }

    if (keyCode == 13 )
    {					
        // cancel the default submit
        e.returnValue=false;
        e.cancel = true;
    
        // Click appropriate button
        $get(buttonId).click();
        
        return false;
    }
	
    return true;
}

// Search Button Click
function searchButtonClick() {
   doSubmit(new (Array)('siteSearch'));
}

// Tab Click
function tabClick(tab) {
    var addPrevious = false;
    if ( _proxy_jslib_handle($get('qry', $get('siteSearch')), 'value', '', 0, 0).trim().length > 0)
    {
        var tabType = $get('type', $get('siteSearch'));
        if ( _proxy_jslib_handle(tabType, 'value', '', 0, 0) != tab)
        {
            addPrevious = true;
             _proxy_jslib_assign('', tabType, 'value', '=', ( tab));
        }
    }
    else
    {
        return;
    }
    
    if (addPrevious == true)
        doSubmit(new (Array)('siteSearch', 'previous'));
    else
        doSubmit(new (Array)('siteSearch'));
}

// Location dropdown Click
function locationClick(latitude, longitude, regionId, countryId, countryCode, location) {
	if(latitude.length != 0)
	     _proxy_jslib_assign('', $get('latitude'), 'value', '=', ( latitude));
	if(longitude.length != 0)
	     _proxy_jslib_assign('', $get('longitude'), 'value', '=', ( longitude));	
	if(regionId.length != 0)
	     _proxy_jslib_assign('', $get('region'), 'value', '=', ( regionId));	
	if(countryId != 0)
	     _proxy_jslib_assign('', $get('country'), 'value', '=', ( countryId));			
	if(countryCode.length != 0)
	     _proxy_jslib_assign('', $get('countryCode'), 'value', '=', ( countryCode));		
	
	 _proxy_jslib_assign('',  _proxy_jslib_handle($get('regionForm'), 'getElementsByTagName', '', 1, 0)('input')[0], 'value', '=', (  _proxy_jslib_handle(null, 'location', location, 0, 0)));
	
	doSubmit(new (Array)('siteSearch', 'filter', 'locationForm'));
}

// Update Button Click
function updateButtonClick() {
	doSubmit(new (Array)('siteSearch', 'filter'));
}


// Click Similar pages link in Web tab
function similarPagesClick(query) {
     _proxy_jslib_assign('', $get('qry', $get('siteSearch')), 'value', '=', ( query));
    doSubmit(new (Array)('siteSearch'));
}

// Set Pager
function changePage(page, searchid) {
	 var urlHelper = new (SiteSearch.UrlHelper)( _proxy_jslib_handle(document.aspnetForm, 'action', '', 0, 0));
	 urlHelper.SetQueryValue("searchid", encodeURIComponent(searchid));	 
	 urlHelper.SetQueryValue("pg", encodeURIComponent(page));
	 urlHelper.RemoveQueryPair("prev");	
	 var queryS = urlHelper.ToUrl();
	  _proxy_jslib_assign('',  _proxy_jslib_handle(self, 'location', '', 0, 0), 'href', '=', ( queryS));		
}

// Update Search Text box with keyword value 
function UpdateQTextBox(keyword) {    
    if(keyword != null && keyword.length > 0)
	     _proxy_jslib_assign('', $get('qry', $get('siteSearch')), 'value', '=', ( keyword));
    updateButtonClick();
}

// Submit new search request
function doSubmit(divIds) {
    if ( _proxy_jslib_handle($get('qry', $get('siteSearch')), 'value', '', 0, 0).trim().length == 0 && $get('browseMode') == null)
    {
        return;
    }

    if (Sys.Browser.agent == Sys.Browser.InternetExplorer && (navigator.userAgent.toLowerCase().indexOf('aol') == -1))
    {
        window.external.AutoCompleteSaveForm(document.aspnetForm);
    }
        
    var urlHelper = new (SiteSearch.UrlHelper)( _proxy_jslib_handle(document.aspnetForm, 'action', '', 0, 0));  
    urlHelper.query = "";
    
    var elements = getElementsByTagNameMultiple(['input', 'textarea', 'select'], divIds);
    for (var i = 0; i < elements.length; i++)
    {
        if( _proxy_jslib_handle(elements, (i), 0, 0) &&  _proxy_jslib_handle(elements, (i), 0, 0).attributes != null)
        {
            if( _proxy_jslib_handle(elements, (i), 0, 0).getAttribute("type") != null && ( _proxy_jslib_handle(elements, (i), 0, 0).getAttribute("type") == "radio" ||  _proxy_jslib_handle(elements, (i), 0, 0).getAttribute("type") == "checkbox"))
            {
               if( _proxy_jslib_handle(elements, (i), 0, 0).checked)
               {
                   var element =  _proxy_jslib_handle(elements, (i), 0, 0);
                   do
                   {
                        if(element.getAttribute("queryID") != null)
                        {
                            urlHelper.SetQueryValue(element.getAttribute("queryID"), encodeURIComponent( _proxy_jslib_handle( _proxy_jslib_handle(elements, (i), 0, 0), 'value', '', 0, 0)));
                            break;
                        }   
                   }
                   while((element = element.parentNode) && element != null);
               }
            }
            else 
            {    		
	            if( _proxy_jslib_handle(elements, (i), 0, 0).getAttribute("queryID") != null &&  _proxy_jslib_handle( _proxy_jslib_handle(elements, (i), 0, 0), 'value', '', 0, 0) != null &&  _proxy_jslib_handle( _proxy_jslib_handle(elements, (i), 0, 0), 'value', '', 0, 0).trim().length > 0)
                    urlHelper.SetQueryValue( _proxy_jslib_handle(elements, (i), 0, 0).getAttribute("queryID"), encodeURIComponent( _proxy_jslib_handle( _proxy_jslib_handle(elements, (i), 0, 0), 'value', '', 0, 0)));
            }
        }
    }
    
	var queryS = urlHelper.ToUrl();
	 _proxy_jslib_assign('',  _proxy_jslib_handle(self, 'location', '', 0, 0), 'href', '=', ( queryS));		
}


function getElementsByTagNameMultiple(tag_names, divIds) {
  var out = new (Array)();
  for( var i = 0; i <  divIds.length; i++ ) 
  {
    var div = $get( _proxy_jslib_handle(divIds, (i), 0, 0));
    for( var j = 0; j <  tag_names.length; j++ ) 
    {
        var elementsFound =  _proxy_jslib_handle(div, 'getElementsByTagName', '', 1, 0)( _proxy_jslib_handle(tag_names, (j), 0, 0));
        for (var k = 0; k < elementsFound.length; k++)
        {
            out.push(elementsFound.item(k));
        }
    }
  }
  return out;
}

function UseNoPicImage(img) {
     _proxy_jslib_assign('', img, 'src', '=', ( noPicUrl));
}

// Wrap Text
function wrap(elementId) {
    if($get(elementId))
         _proxy_jslib_assign('', $get(elementId), 'innerHTML', '=', (  _proxy_jslib_handle($get(elementId), 'innerHTML', '', 0, 0).call(TextFilterWBR)));
}

//Alert pop-up
function showAlertPopUp(message) {
    var p = MySpace.UI.Popup.create(message, MySpaceRes.Common.Attention);
	p.add_button(MySpaceRes.Common.Ok, true).isCancel=true;
	p.show();      
}   

function openLocationForm(event) {
    if(!SiteSearch.locationForm) 
    {
        SiteSearch.locationForm = new (SiteSearch.LocationForm)();
    }
    
     _proxy_jslib_handle(SiteSearch.locationForm, 'open', '', 1, 0)(event);
}

String.prototype.trim = function() { return  _proxy_jslib_handle(this, 'replace', '', 1, 0)(/^\s+|\s+$/g, ""); };

SiteSearch = function() {}

//
// client-side sub-implementation of the server-side UrlHelper class
//
SiteSearch.UrlHelper = function() { }
SiteSearch.UrlHelper = function(url) {
    this.fullUrl = url;
    this.basePath = this.fullUrl;
    this.query = "";
    
    if (this.fullUrl.indexOf('?') > -1) {
        qSplit = this.fullUrl.split('?');
        for(var i = 1; i < qSplit.length; i++) {
            this.query +=  _proxy_jslib_handle(qSplit, (i), 0, 0);
        }
        
        if (this.query.indexOf('#') > -1) {
            this.query = this.query.substring(0, this.query.indexOf('#'));
        }
        
        this.basePath = qSplit[0];
    }
}

SiteSearch.UrlHelper.prototype = {
    GetQueryPair : function(key) {
        var keyIdx = this.query.indexOf('&'+key + '=') ;
        
        if(keyIdx==-1)
		{ 
		    if(this.query.indexOf(key + '=') == 0)
                keyIdx = 0;
        }
        
        if (keyIdx > -1) {
            var nextIdx = this.query.indexOf('&', keyIdx + 1);
            
            if (nextIdx == -1)
                nextIdx = this.query.length;
            
            return this.query.substring(keyIdx, nextIdx);
        }
        
        return null;
    },
    
    GetQueryValue : function(key) {
        var pair = this.GetQueryPair(key);
        
        if (pair != null && pair.indexOf('=') > -1)
            return pair.split('=')[1];
        else
            return null;
    },
    
    SetQueryValue : function(key, value, encodeValue) {
        if (encodeValue)
             value= _proxy_jslib_assign_rval('', 'value', '=', ( escape( _proxy_jslib_handle(null, 'value', value, 0, 0))), value);
            
        if (this.query.length > 0) {
            var pair = this.GetQueryPair(key);
            
            if (pair != null) {
                this.query =  _proxy_jslib_handle(this.query, 'replace', '', 1, 0)(pair, "&" + key + "=" +  _proxy_jslib_handle(null, 'value', value, 0, 0));
            } else {
                this.query += "&" + key + "=" +  _proxy_jslib_handle(null, 'value', value, 0, 0);
            }
        } else {
            this.query = key + "=" +  _proxy_jslib_handle(null, 'value', value, 0, 0);
        }
    },
    
    RemoveQueryPair : function(key) {
        var pair = this.GetQueryPair(key);
        if (pair != null) {
            this.query =  _proxy_jslib_handle(this.query, 'replace', '', 1, 0)(pair, "");
        }
    },
    
    ToUrl : function() {
        return this.basePath + "?" + this.query;
    }
}

//
// LocationForm class
//
SiteSearch.LocationForm = function() { 
    this.visible = false;
    this.locdiv = null;
    this.spans = null;
}

SiteSearch.LocationForm.prototype.setStyle = function(style, left, top) {
	style.display = this.visible ? "none": "block";
	style.left = left + "px";
	 _proxy_jslib_assign('', style, 'top', '=', (  _proxy_jslib_handle(null, 'top', top, 0, 0) + "px"));
}
    
 _proxy_jslib_assign('', SiteSearch.LocationForm.prototype, 'open', '=', ( function(event) {
	var top = 17, marginTop;
	var left=0, span, i=0;
	
	var locationForm = $get("locationForm");
	
	var div = locationForm;
	do  top= _proxy_jslib_assign_rval('', 'top', '+=', ( div.offsetTop), top);
        while(div = div.offsetParent)
	marginTop =  _proxy_jslib_handle(null, 'top', top, 0, 0);
	
	this.spans = this.spans ||  _proxy_jslib_handle(locationForm, 'getElementsByTagName', '', 1, 0)("span");
	(event || window.event).cancelBubble= !i;
	if(!this.locdiv)
	{
		this.locdiv=document.createElement("DIV");
		locationForm.appendChild(this.locdiv).id="locationDiv";			
		document.onclick = function(event) {  _proxy_jslib_handle(SiteSearch.locationForm, 'close', '', 1, 0)(event); }			
	}
	
	while(span =  _proxy_jslib_handle(this.spans, (i++), 0, 0))
	{	    
		if(left)
		{   
		    this.setStyle(span.style, left+1,  _proxy_jslib_handle(null, 'top', top, 0, 0));
		     top= _proxy_jslib_assign_rval('', 'top', '+=', ( span.offsetHeight), top);    
        }
	    		
		if(span.className == "location2")
		{
			do left += span.offsetLeft;
			while(span = span.offsetParent)
		}
	}
	
	this.locdiv.style.height=  _proxy_jslib_handle(null, 'top', top, 0, 0) - marginTop + "px";
	this.setStyle(this.locdiv.style, left, marginTop - 1);
	this.visible = !this.visible;		
}))

 

 _proxy_jslib_assign('', SiteSearch.LocationForm.prototype, 'close', '=', ( function(event) {
	SiteSearch.locationForm.visible &&  _proxy_jslib_handle(SiteSearch.locationForm, 'open', '', 1, 0)(event);
}))



function toggleQuickFilters(searchBy, quickFilterCheckBoxes) {
    if(searchBy == null || quickFilterCheckBoxes == null)
    {
        return;
    }

    var searchByValue =  _proxy_jslib_handle( _proxy_jslib_handle($get(searchBy), 'getElementsByTagName', '', 1, 0)('select')[0], 'value', '', 0, 0);
    var divQuickFilters = $get(quickFilterCheckBoxes).parentNode;
    var inputCheckBoxes =  _proxy_jslib_handle($get(quickFilterCheckBoxes), 'getElementsByTagName', '', 1, 0)('input');

    if(searchByValue == '1')
    {
        for(var i = 0; i < inputCheckBoxes.length; i++)
        {
             _proxy_jslib_handle(inputCheckBoxes, (i), 0, 0).checked = true;
             _proxy_jslib_handle(inputCheckBoxes, (i), 0, 0).disabled = false;
        }

        divQuickFilters.style.display = "block";
    }
    else
    {
        for(var j = 0; j < inputCheckBoxes.length; j++)
        {
             _proxy_jslib_handle(inputCheckBoxes, (j), 0, 0).checked = false;
             _proxy_jslib_handle(inputCheckBoxes, (j), 0, 0).disabled = false;
        }

        divQuickFilters.style.display = "none";
    }
}

function quickFilterCheckBoxClick(quickFilterCheckBoxes) {
    var inputCheckBoxes =  _proxy_jslib_handle($get(quickFilterCheckBoxes), 'getElementsByTagName', '', 1, 0)('input');     
    
    var countChecked = 0;
    for(var i = 0; i < inputCheckBoxes.length; i++)
    {
        if( _proxy_jslib_handle(inputCheckBoxes, (i), 0, 0).checked)
        {
            countChecked++;    
        }
    }
    
    if(countChecked == 1)
    {
        for(var j = 0; j < inputCheckBoxes.length; j++)
        {
            if( _proxy_jslib_handle(inputCheckBoxes, (j), 0, 0).checked)
            {
                 _proxy_jslib_handle(inputCheckBoxes, (j), 0, 0).disabled = true;
                return;
            }
        }
    }
    else if(countChecked == 2)
    {
        for(var k = 0; k < inputCheckBoxes.length; k++)
        {
            if( _proxy_jslib_handle(inputCheckBoxes, (k), 0, 0).disabled)
            {
                 _proxy_jslib_handle(inputCheckBoxes, (k), 0, 0).disabled = false;
                return;
            }
        }
    }
}

function enforceSearchByAndQuickFilters(searchByAndQuickFiltersId) {
    if(Sys.Browser.agent == Sys.Browser.Safari)
    {
        var searchByValue =  _proxy_jslib_handle( _proxy_jslib_handle($get('searchBy'), 'getElementsByTagName', '', 1, 0)('select')[0], 'value', '', 0, 0);
        var divQuickFilters = $get('quickFilterCheckBoxes').parentNode;

        if(searchByValue == 1)
        {
            quickFilterCheckBoxClick('quickFilterCheckBoxes');    
            divQuickFilters.style.display = "block";        
        }
        else
        {
            divQuickFilters.style.display = "none";
        }    
    }
}


 ;
_proxy_jslib_flush_write_buffers() ;