var C21AgentRESTServiceUrl = "/DesktopModules/C21Agents/AgentService.aspx";
var C21SearchRESTServiceUrl = "/DesktopModules/C21PropertySearch/SearchService.aspx";


// Document Ready Actions
jQuery(function($)
{
	

 if($("a") != null)
	{
		$("a").filter(function(index) {
		        var URL=this.href;        
		        if((URL.substring(0,15)=='http://maps.goo'))
		            return true;
		        else
		            return false;
		     }).click( function(){
				//alert(escape(this.href));
		        window.open(this.href,null,"height=600,width=780,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes");return false;
		       });
	}






	jQuery(".important").hide();
	// hide the dnn "Visiblity" radio button areas in the Member Profile page
	jQuery("span[id*=__vis]").hide();
});

function C21ClearSearchForm()
{
    // clear all drop-downs
    jQuery('.FormRow select').each(function(i){
       this.selectedIndex = 0;
     });
    // clear all textboxes
    jQuery('.FormRow input[type=text]').each(function(i){
       this.value = '';
     });
    // clear all checkboxes
    jQuery('.FormRow input[type=checkbox]').each(function(i){
       this.checked = false;
     });     
}

function C21DelayClosePopup()
{
    jQuery(function()
    {
        window.top.setTimeout("TB_remove()",2000); // 2 second delay before closing thickbox
    });        
}

function C21GetHomepageNewlyListed(userId)
{
    jQuery.post(C21SearchRESTServiceUrl,
        { a: "NewlyListed", u: userId },
        function(data){           
            var response = ParseRESTRespone(data);
            if(response[0] == "true")
            {                                
			    if(jQuery('#slideshow').length > 0)
			    {
                    jQuery('#slideshow').html(response[1]);
    				//jQuery('#slideshow img .Photo2').photoborder2();
    				
				    jQuery('#slideshow').slideshow({timeout: 4000});
			    }          
            }
        }
    );    
}

function C21SetFormMasterSendTo()
{
    // populate the Form Master 'hSendTo' field
    $formMasterTable = jQuery('.FormMaster');
    if($formMasterTable.length > 0)
    {
	    var qs = jqs.parse(); // parse querystring params
	    var s = String(qs['sendTo']);
	    if(s != "undefined")
	    {
	        jQuery('.hSendTo').val(s.rot13());
	    }
	}
}

function C21SetFormMasterFieldFromParam(elmCssClass,qryParamName,isUrlEncoded)
{
    $formMasterTable = jQuery('.FormMaster');
    if($formMasterTable.length > 0)
    {
	    var qs = jqs.parse(); // parse querystring params
	    var s = String(qs[qryParamName]);	    
	    if(s != "undefined")
	    {	    
	        jQuery('.' + elmCssClass).val(s.unescape());
	    }
	} 
}
function C21SetFormMasterFieldFromParam(elmCssClass,qryParamName)
{
    $formMasterTable = jQuery('.FormMaster');
    if($formMasterTable.length > 0)
    {
	    var qs = jqs.parse(); // parse querystring params
	    var s = String(qs[qryParamName]);
	    if(s != "undefined")
	    {
	        jQuery('.' + elmCssClass).val(s);
	    }
	}    
}


// Parse a REST webservice response and return just the stuff between the <body> tags
function ParseRESTRespone(data)
{
    // grab stuff between the <body> tags
    var startTag = "<body>";
    var endTag = "</body>";
    var start = data.indexOf(startTag);
    var end = data.lastIndexOf(endTag);
    if(start > -1 && end > start)
    {
        var text = data.substr( start + startTag.length, end - (start + startTag.length) )
        return Trim(text).split("|");
    }
    else
    {
        return data;
    }
}


/*------------------------------------------------
	String Functions
-------------------------------------------------*/	
String.prototype.rot13 = function(){ //v1.0
	return this.replace(/[a-zA-Z]/g, function(c){
		return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
	});
};

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}
// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function Trim( value ) {
	return LTrim(RTrim(value));	
}