Type.registerNamespace('FriendsCategories');
//Helper Methods
function getElementsByClassName(parent, tagName, className)
{
    var classEls = new Array();
    if(parent)
    {	        
        var allEls = parent.getElementsByTagName(tagName);
        for(var i=0;i<allEls.length;i++)
        {
            if(allEls[i].className.indexOf(className) != -1)
            {
                Array.add(classEls, allEls[i]);
            }
        }
    }
    return classEls;
}

// ToolTip Class
FriendsCategories.ToolTip = function(tTipEl, content)
{
	this._tTipEl = tTipEl;
	this._content = content;	
	this._tTipUpHtml = "<div id='divPopup' class='{0}'><div id='{1}' class='{2}'>{3}</div><div id='{4}' class='{5}'>{6}</div></div>";	
	this._userTtipCss;
	this._ptrCss;
	this._tTipTextCss;
	this._isSetUp = false;
	FriendsCategories.ToolTip.initializeBase(this, [tTipEl, content]);
}

FriendsCategories.ToolTip.prototype = 
{
//    <div style="display: none;">
//      <div id="divPopup" class="PopupDiv" >
//            <div id="" class="PopupPointer" />
//            <div id="divPopupText" class="PopupText">
//                ToolTip Message
//            </div>
//      </div>
//    </div>

	initialize : function(showOnFocus, userTtipCss, ptrCss, tTiptextCss)
	{		
		this._userTtipCss = userTtipCss ? userTtipCss : "PopupDiv";
		this._ptrCss = ptrCss ? ptrCss : "PopupPointer";
		this._tTipTextCss = tTiptextCss ? tTiptextCss : "PopupText";
		
		$addHandlers(this._tTipEl, {mouseover:this.show, mouseout:this.hide}, this);		
		if(showOnFocus)		
		{
			$addHandlers(this._tTipEl, {focus:this.show, blur:this.hide}, this);
		}
	},
	
	dispose : function(){
        $clearHandlers(this._tTipEl);
        this._element = null;          
        FriendsCategories.ToolTip.callBaseMethod(this, 'dispose');
   },
	
	setContent : function(content)
	{
		this._content = content;
		// If the tooltip is already built then update ToolTip DOM.
		if(this._element)
		{
			this._element.firstChild.childNodes[1].innerHTML = this._content;
		}
	},
	
	_setUp : function() 
	{		
		this._element = document.createElement('div');		
		this._element.innerHTML = this._buildTTip("up");				

		var toolTipStyle = 	this._element.style;
		toolTipStyle.position = 'absolute';
		toolTipStyle.height = 'auto';
		toolTipStyle.left = '0px';
		toolTipStyle.top = '0px';
		toolTipStyle.zIndex = 50;
		
		//Add the element to DOM		
		document.body.appendChild(this._element);						
		this._isSetUp = true;
	},	
	
	_buildTTip : function(dir)
	{
		if(dir == "up")
		{
			return String.format(this._tTipUpHtml, this._userTtipCss, "divPtr", this._ptrCss, "", "divPopupText", this._tTipTextCss, this._content);
		}
		else
		{
			return String.format(this._tTipUpHtml, this._userTtipCss, "divPopupText", this._tTipTextCss + "Above", this._content, "divPtr", this._ptrCss + "down", "");
		}
	},
	
	// Place the tooltip above of below the element.
	_positionToolTip : function()
	{
		var elementBounds = Sys.UI.DomElement.getBounds(this._tTipEl);
		var windowBounds = this._getWindowSize();
		
		// Showing Tooltip above the Element
		if((elementBounds.y - this._getScrollPos()) + elementBounds.height + this._element.firstChild.clientHeight > windowBounds.height)
		{
			if(this._element.location != 1)
			{				
				this._element.innerHTML = this._buildTTip("down");
			}
		
			this._element.style.top = elementBounds.y - this._element.firstChild.clientHeight + "px";
			this._element.location = 1;
		}
		else
		{
			if(this._element.location != 3)
			{				
				this._element.innerHTML = this._buildTTip("up");
			}
		
			this._element.style.top = elementBounds.y + elementBounds.height + "px";
			this._element.location = 3;
		}

		this._element.style.left = elementBounds.x + "px";
	},
	
	// Returns the size of window.
	_getWindowSize : function() 
	{
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) 
		  {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } 
		  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		  {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } 
		  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		  {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		 return {width:myWidth, height:myHeight};
	},
	
	_getScrollPos : function() 
	{
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0)
		{
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		return ScrollTop;
	},
	
	/// <param name="evt" type="Event" mayBeNull="false"></param>
	show : function(evt)
	{	
		if (!this._isSetUp)
		{
			this._setUp();			
		}
		
		//this._toolTipElement = sourceElement;
		
		if(!this._element || this._tTipEl.dispalyed)
		{
		    return false;
		}
		
		this._tTipEl.dispalyed = true;
		
		//Check for the positioning.
		this._positionToolTip();		
		this._element.style.visibility = 'visible';		
				
		return false;
	},
	
	hide : function(evt)
	{
		if(this._element)
		{
			this._element.style.visibility = 'hidden';
			this._element.style.left = '0px';
			this._element.style.top = '0px';
			this._tTipEl.dispalyed = false;
		}
	}
}
FriendsCategories.ToolTip.registerClass('FriendsCategories.ToolTip');

FriendsCategories.TimeOutToolTip = function(tTipEl, content)
{
	FriendsCategories.TimeOutToolTip.initializeBase(this, [tTipEl, content]);
}

FriendsCategories.TimeOutToolTip.prototype =
{
	_hideDelay: 500,	
	_timerID: 0,
    
    get_hideDelay : function(){return this._hideDelay;},
	set_hideDelay : function(value){this._hideDelay = value;},
	
	initialize : function(showOnFocus, userTtipCss, ptrCss, tTiptextCss)
	{
		FriendsCategories.TimeOutToolTip.callBaseMethod(this, 'initialize', [showOnFocus, userTtipCss, ptrCss, tTiptextCss]);
		$clearHandlers(this._tTipEl);
		$addHandler(this._tTipEl,"mouseover", Function.createDelegate(this,this._toShow));
		$addHandler(this._tTipEl,"mouseout", Function.createDelegate(this,this._checkToHide));		
	},
	
	dispose : function(){
        $clearHandlers(this._tTipEl);              
        FriendsCategories.TimeOutToolTip.callBaseMethod(this, 'dispose');
   },
	
	_clearTimerID: function(){
		if (this._timerID){
			clearTimeout(this._timerID);
			this._timerID = 0;
		}
	},
	
	_toShow : function(evt)
	{
		if(!this._tTipEl.dispalyed)
		{		
			FriendsCategories.TimeOutToolTip.callBaseMethod(this, 'show', [evt]);
			$addHandler(this._element,"mouseover", Function.createDelegate(this,this._cancelHide));
			$addHandler(this._element,"mouseout", Function.createDelegate(this,this._enableHide));
		}
	},
	
	_cancelHide : function(evt)
	{
		this._mOverTT = true;
	},
	
	_enableHide : function(evt)
	{
		this._mOverTT = false;
	},

	_checkToHide : function(evt)
	{
		this._clearTimerID();
		this._timerID = window.setTimeout(Function.createDelegate(this,this._dHide),this._hideDelay);		
	},
	
	_dHide : function(evt)
	{
		this._clearTimerID();
		if(this._mOverTT)
		{
			this._timerID = window.setTimeout(Function.createDelegate(this,this._dHide),this._hideDelay);
		}
		else
		{
			$clearHandlers(this._element);
			this.hide();
		}
	}
}
FriendsCategories.TimeOutToolTip.registerClass('FriendsCategories.TimeOutToolTip', FriendsCategories.ToolTip);


// Setting up tooltips for view categories page
function setViewCatTips()
{
	var pHelps = getElementsByClassName($get("myfriends"), "span", "categoryPrivHelp"); 
	var pHelpTipHtml = "<div id='privTtTitle' class='categoryPrivTitle'>" + MySpaceRes.ViewAllFriendsPage.PrivacyTooltipHelpText + "</div><br/><span class='categoryPrivLabel'>" + MySpaceRes.ViewAllFriendsPage.JustMeCategorySecurityLabel +"</span>: <span class='categoryPrivText'>" + MySpaceRes.ViewAllFriendsPage.PrivacyTooltipJustMe +"</span><br /><br /><span class='categoryPrivLabel'>"+MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel+"</span>: <span class='categoryPrivText'>"+MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly+"</span><br /><br /><span class='categoryPrivLabel'>"+MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel+"</span>: <span class='categoryPrivText'>"+ MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone+"</span>"
	for(var i=0;i<pHelps.length; i++)
	{
		var tellCatTip = new FriendsCategories.ToolTip(pHelps[i], pHelpTipHtml);	
		tellCatTip.initialize();
	}	
}

function setViewHideTips()
{
	var hTipsImgs = getElementsByClassName($get("myfriends_grid"), "img", "hiddenTTip"); 	
	for(var i=0;i<hTipsImgs.length; i++)
	{
		var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], MySpaceRes.FriendCategories.HiddenFriendTooltip);
		tellCatTip.initialize();
	}
}

// View Friends Class
// ------------------

FriendsCategories.ViewFriends = function()
{
	this._catDD;
	this._cId;
	this._cName;
	this._cPriv;
	this._isReqOwner;
	this._rndFrndHref;
	this._ownViewo;
	this._exViewTTo;
	this.MAX_DD_NAME_LEN = 30;
	this.MAX_AB_NAME_LEN = 17;
}
FriendsCategories.ViewFriends.registerClass('FriendsCategories.ViewFriends');
var _viewFriendso;

FriendsCategories.ViewFriends.getObj = function(cId, cName, cPriv, isReqOwner, rndFrndHref)
{
	if(!_viewFriendso)
	{
		//_viewFriendso=$create(FriendsCategories.ViewFriends);
		_viewFriendso= new FriendsCategories.ViewFriends();
		_viewFriendso._rndFrndHref = rndFrndHref;
		_viewFriendso.initialize(cId, cName, cPriv, isReqOwner)
	}
	return _viewFriendso;
}
FriendsCategories.ViewFriends.prototype =
{
	initialize : function(cId, cName, cPriv, isReqOwner)
	{
		FriendsCategories.ViewFriends.initializeBase(this);
		
		this._cId = cId;
		this._cName = cName;
		this._cPriv = cPriv;
		this._isReqOwner = isReqOwner;
		
		// Gets the dropdown
		var ddContainer = $get("myfriends_display");
		if(ddContainer)
		{
			this._catDD = ddContainer.getElementsByTagName("select")[0];
		}
		this.setEditCat();
		this.setViewHideTips();
		this.setExViewTips();
		this.setRndHlpTip();
		
		// initialize the tool tips for viewable by
		if (this._isReqOwner)
		{
			this.setOwnerViewTips();
		}
		else
		{
			this.setVisitorViewTips();
		}		
	},
	
	// hook up to the Edit category popover.
	setEditCat : function()
	{
		this._ownViewo = getElementsByClassName($get("myfriends"), "div", "categoryListView")[0];
		// called only when proper category shown
		if(this._ownViewo)
		{
			var ownerLinks = getElementsByClassName(this._ownViewo, "a", "categoryDefA");
			if (ownerLinks.length > 0)
			{
				var editCato = new FriendsCategories.EditCat();
				editCato.init(ownerLinks[0], this._cId, this._cName, this._cPriv);
				editCato.addEditCatClicked(Function.createDelegate(this,this.editCatCB));
			}
			
			// wrap text in owner and visitor views
			var catLabel = getElementsByClassName(this._ownViewo, "a", "categoryNameLabel")[0];
			catLabel.innerHTML = this._cName.call(TextFilterWBR);
		}
	},
	
	setViewHideTips : function()
	{
		var hTipsImgs = getElementsByClassName($get("myfriends_grid"), "img", "hiddenTTip"); 	
		for(var i=0;i<hTipsImgs.length; i++)
		{
			var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], MySpaceRes.FriendCategories.HiddenFriendTooltip);
			tellCatTip.initialize();
		}
	},
	
	setOwnerViewTips : function()
	{
		var content = new Sys.StringBuilder("");        
        content.append("<div id='' class='toolTipDefText'>");
        content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipHelpText);
        content.append("</div>"); 
		content.append("<br />");
		content.append("<span id='' class='toolTipDefLabel'>"); 
		content.append(MySpaceRes.ViewAllFriendsPage.JustMeCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>")
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipJustMe);
		content.append("</span>");
		content.append("<br />");
		content.append("<br />");

		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		content.append("</span>"); 
		content.append("<br />");
		content.append("<br />");

		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		content.append("</span>");
		content.append("<br />");
		
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "categoryHelpImg"); 	
		for(var i=0;i<hTipsImgs.length; i++)
		{
			var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], content);
			tellCatTip.initialize(true, "BluePopupDiv", "BluePopupPointer", "BluePopupText"); 
		}
		
	},
	
	setVisitorViewTips : function()
	{
		var content = new Sys.StringBuilder("");        
        content.append("<span id='' class='toolTipDefLabel'>");
        content.append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
        content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		content.append("</span>"); 
		content.append("<br />");
		content.append("<br />");
		
		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		content.append(":</span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		content.append("</span>") 
		content.append("<br />");
		
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "categoryHelpImg"); 	
		
		for(var i=0;i<hTipsImgs.length; i++)
		{
			var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], content);
			tellCatTip.initialize(true, "BluePopupDiv", "BluePopupPointer", "BluePopupText"); 
		}
	},
	
	setRndHlpTip : function()
	{
		var rndImg = $get("_rndHlpTipImg");
		if(rndImg)
		{
			var rndTipContent = new Sys.StringBuilder(MySpaceRes.ViewAllFriendsPage.FriendsRandomziedTooltip1); 
			rndTipContent.append("<br /><br />");
			rndTipContent.append(String.format(MySpaceRes.ViewAllFriendsPage.FriendsRandomziedTooltip2, "<a href="+ this._rndFrndHref +">", "</a>" ));
			
			var toTip = new FriendsCategories.TimeOutToolTip(rndImg, rndTipContent);
			toTip.initialize();
		}
	},
	
	setExViewTips : function()
	{
		var exTipImg = $get("_exViewHideTip");
		if(exTipImg)
		{
			this._exViewTTo = new FriendsCategories.ToolTip(exTipImg);	
			this._exViewTTo.initialize();
			
			if($get("hideMeButton").firstChild.getAttribute("IsPublic") == "false")
			{
				this._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.UnHideToolTip);
			}
			else
			{
				this._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.HideToolTip);
			}
		}		
	},
	
	editCatCB : function(sender, e)
	{		
		// Update the dropdown
		if(e.cName)
		{			
			// Update the dropdown
			var catName = e.cName;
			if (e.cName.length > this.MAX_DD_NAME_LEN)
			{
				catName = e.cName.substring(0, this.MAX_DD_NAME_LEN) + "...";
			}
			this._catDD.options[this._catDD.selectedIndex].innerHTML = catName;
			
			// Update the ownerView title
			catName = e.cName;
			var catLabel = getElementsByClassName(this._ownViewo, "a", "categoryNameLabel")[0];
			catLabel.innerHTML = catName.call(TextFilterWBR);
			
			// Update the Alphabar
			catName = e.cName;
			if (e.cName.length > this.MAX_AB_NAME_LEN)
			{
				catName = e.cName.substring(0, this.MAX_AB_NAME_LEN) + "...";
			}
			var aBarNames = getElementsByClassName(document.body, "a", "catName");
			for(var i=0;i<aBarNames.length;i++)
			{
				aBarNames[i].innerHTML = catName;
			}
		}
		
		// update the privacy setting.
		if(e.cPriv)
		{
			getElementsByClassName(this._ownViewo, "span", "categoryDefBold")[0].innerHTML = e.cPriv;
		}		
	},
	
	setCategoryPrivacyStatus : function (catId, ownerId, elem, hideTxt, showTxt) {
		var switchToPublic = elem.getAttribute("IsPublic") == "false";
		MySpace.Web.Friends.Services.FriendsService.UpdateMembershipStatus(catId, switchToPublic);
		if (switchToPublic) {
			elem.innerHTML = hideTxt;
			elem.setAttribute("IsPublic", "true");
			_viewFriendso._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.HideToolTip);
		} else {
		   elem.innerHTML = showTxt;
		   elem.setAttribute("IsPublic", "false");
		   _viewFriendso._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.UnHideToolTip);
    }
}
}



// Setup Edit Category Links for the View Categories page
FriendsCategories.ViewCats = function() 
{
	this._isReqOwner;
	this._catIds;
	this._catNames;
	this._catPrivs;

}
FriendsCategories.ViewCats.registerClass('FriendsCategories.ViewCats');

FriendsCategories.ViewCats.prototype = {
    initialize : function(isReqOwner, categoryIds, categorNames, categoryPrivs) {
		FriendsCategories.ViewCats.initializeBase(this);
		this._isReqOwner = isReqOwner;
		this._catIds = categoryIds;
		this._catNames = categorNames;
		this._catPrivs = categoryPrivs;
		
		var cats = getElementsByClassName($get("myfriends"), "div", "categoryListView");
			
		for(var i=0;i<cats.length;i++)
		{
			var ownerLinks = getElementsByClassName(cats[i], "a", "categoryDefA");
			
			if (ownerLinks.length > 0)
			{
				var editCato = new FriendsCategories.EditCat();
				editCato.init(ownerLinks[0], this._catIds[i],this._catNames[i], this._catPrivs[i]);
				editCato.addEditCatClicked(Function.createDelegate(cats[i],this.editCatCB));
			}
		}
		// initialize the tool tips for viewable by
		if (this._isReqOwner)
		{
			this.setOwnerViewTips();
		}
		else
		{
			this.setVisitorViewTips();
		}
		
		// set the tool tips for hidden friends 
		this.setHiddenViewTips();
		this.setCatWBR();				
    },
    
    setCatWBR : function()
    {
		var catNames = getElementsByClassName($get("myfriends"), "a", "categoryNameLabel");
		for(var i=0;i<catNames.length;i++)
		{
			catNames[i].innerHTML = catNames[i].innerHTML.call(TextFilterWBR);			
		}
    },
    
    editCatCB : function(sender, e)
    {
		if(e.cName)
		{
			var cNameLabel = getElementsByClassName(this, "a", "categoryNameLabel")[0];
			cNameLabel.innerHTML = e.cName.call(TextFilterWBR);
		}
		if(e.cPriv)
		{
			var cPrivLabel = getElementsByClassName(this, "span", "categoryDefBold")[0];			
			cPrivLabel.innerHTML = e.cPriv;
		}
    },
    	
	setOwnerViewTips : function()
	{
		var content = new Sys.StringBuilder("");        
        content.append("<div id='' class='toolTipDefText'>");
        content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipHelpText);
        content.append("</div>"); 
		content.append("<br />");
		content.append("<span id='' class='toolTipDefLabel'>"); 
		content.append(MySpaceRes.ViewAllFriendsPage.JustMeCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>")
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipJustMe);
		content.append("</span>");
		content.append("<br />");
		content.append("<br />");

		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		content.append("</span>"); 
		content.append("<br />");
		content.append("<br />");

		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		content.append("</span>");
		content.append("<br />");
		
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "categoryHelpImg"); 	
		for(var i=0;i<hTipsImgs.length; i++)
		{
			var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], content);
			tellCatTip.initialize(true, "BluePopupDiv", "BluePopupPointer", "BluePopupText"); 
		}
		
	},
	
	setVisitorViewTips : function()
	{
		var content = new Sys.StringBuilder("");        
        content.append("<span id='' class='toolTipDefLabel'>");
        content.append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
        content.append(": </span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		content.append("</span>"); 
		content.append("<br />");
		content.append("<br />");
		
		content.append("<span id='' class='toolTipDefLabel'>");
		content.append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		content.append(":</span>");
		content.append("<span id='' class='toolTipDefText'>");
		content.append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		content.append("</span>") 
		content.append("<br />");
		
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "categoryHelpImg"); 	
		
		for(var i=0;i<hTipsImgs.length; i++)
		{
			var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], content);
			tellCatTip.initialize(true, "BluePopupDiv", "BluePopupPointer", "BluePopupText"); 
		}
	},
	
	setHiddenViewTips : function()
	{
		var content = new Sys.StringBuilder("");        
        content.append("<div id='' class=''>");
        content.append(MySpaceRes.ViewAllFriendsPage.ToolTipHiddenFriends);
        content.append("</div>");
		
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "hiddenFriendsImg"); 	
		
		if (hTipsImgs != null && hTipsImgs.length > 0)
		{
			for(var i=0;i<hTipsImgs.length; i++)
			{
				var tellCatTip = new FriendsCategories.ToolTip(hTipsImgs[i], content);
				tellCatTip.initialize(true, "BluePopupDiv2", "BluePopupPointer2", "BluePopupText2"); 
			}
		}
	}
}

var viewCatso = new FriendsCategories.ViewCats();



//-----------------------
// client-side sub-implementation of the server-side UrlHelper class
//
FriendsCategories.UrlHelper = function() { }
FriendsCategories.UrlHelper.registerClass('FriendsCategories.UrlHelper');
FriendsCategories.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 += qSplit[i];
        }
        
        if (this.query.indexOf('#') > -1) {
            this.query = this.query.substring(0, this.query.indexOf('#'));
        }
        
        this.basePath = qSplit[0];
    }
}

FriendsCategories.UrlHelper.prototype = {
    GetQueryPair : function(key) {
        var keyIdx = this.query.indexOf(key + '=') - 1;
        
        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 = escape(value);
            
        if (this.query.length > 0) {
            var pair = this.GetQueryPair(key);
            
            if (pair != null) {
                this.query = this.query.replace(pair, "&" + key + "=" + value);
            } else {
                this.query += "&" + key + "=" + value;
            }
        } else {
            this.query = key + "=" + value;
        }
    },
    
    RemoveQueryPair : function(key) {
        var pair = this.GetQueryPair(key);
        if (pair != null) {
            this.query = this.query.replace(pair, "");
        }
    },
    
    ToUrl : function() {
        return this.basePath + "?" + this.query;
    }
}



function submitFormOnEnter(buttonId,evt)
{				
	var e = evt?evt:window.event;	
	
	if (!e) return true;
		
	if ((e.which == 13) || (e.keyCode == 13)) 
	{		
		var submitBtn = $get(buttonId);
		submitBtn.click();				
		return false;
	}
	
	return true;
}

function resetBox(sender)
{
    if (sender.defaultValue == sender.value)
    {
        sender.value = "";
        sender.className = "inp";
    }
}

function blurBox(sender)
{	
    if ( sender.value == "")
    {
        sender.value = sender.defaultValue;
        sender.className = "inp grey";
    }
}

function ResetSearchText(sender)
{
	if (sender.className == "inp grey")
	{
		sender.value = "";
		sender.className = "inp";
	}
}

function BlurSearchText(sender)
{
	if ( sender.value == "")
	{ 
		sender.value = MySpaceRes.ViewAllFriendsPage.SearchWithin;
		sender.className = "inp grey";
	}
}

function ValidateSearchText(sendToUrl)
{	
	if ( searchTextBox.className == "inp grey" ||
		searchTextBox.value.length == 0 )
	{
		return false;
	}
	
	window.location.href = sendToUrl;	
	return false;
}

function CheckSearchTextBox()
{
	if(searchTextBox == null)
		return;
		
	if(searchTextBox.value == MySpaceRes.ViewAllFriendsPage.SearchWithin)
	{
		searchTextBox.className = "inp grey";
	}
	else
	{
		searchTextBox.className = "inp";
	}
}

// setting the webservice path
// move this call to page load using ASP AJAX
function setServicePath(wsPath)
{
	MySpace.Web.Friends.Services.FriendsService.set_path(wsPath);
}
