Type.registerNamespace('FriendsCategories');

var limitBy12RegEx = new (RegExp)(/[^\s]{12}/mg);

//Helper Methods
function getElementsByClassName(parent, tagName, className) {
    var classEls = new (Array)();
    if( _proxy_jslib_handle(null, 'parent', parent, 0, 0))
    {	        
        var allEls =  _proxy_jslib_handle( _proxy_jslib_handle(null, 'parent', parent, 0, 0), 'getElementsByTagName', '', 1, 0)(tagName);
        for(var i=0;i<allEls.length;i++)
        {
            if( _proxy_jslib_handle(allEls, (i), 0, 0).className.indexOf(className) != -1)
            {
                Array.add(classEls,  _proxy_jslib_handle(allEls, (i), 0, 0));
            }
        }
    }
    return classEls;
}

// AjaxToolTip Class
FriendsCategories.AjaxToolTip = function() {
	this.targetElCss;
	this.targetElTag;
	this.tTipContent;		
	this.tTipCss; 
	this.tTipPtrCss; 
	this.tTipTextCss; 
	this.tTipShowOnFocus;
	this.targets = [];		 
	this._element = null;
	this.fixLocation;	
	FriendsCategories.AjaxToolTip.initializeBase(this);
}

FriendsCategories.AjaxToolTip.prototype = 
{
//    <div style="display: none;">
//      <div id="divPopup" class="PopupDiv" >
//            <div id="" class="PopupPointer" />
//            <div id="divPopupText" class="PopupText">
//                ToolTip Message
//            </div>
//      </div>
//    </div>

	_tTipUpHtml : "<div id='divPopup' class='{0}'><div id='{1}' class='{2}'>{3}</div><div id='{4}' class='{5}'>{6}</div></div>",
	_isSetUp : false,
	get_targets : function() { return this.targets; },	
	initialize : function() {
		if(!this.tTipCss){
			this.tTipCss = "PopupDiv";
		}
		if(!this.tTipPtrCss){
			this.tTipPtrCss = "PopupPointer";
		}
		if(!this.tTipTextCss){
			this.tTipTextCss = "PopupText";
		}
		if(this.targetElCss)
		{
			this.targets = getElementsByClassName( _proxy_jslib_handle(document, 'body', '', 0, 0), this.targetElTag, this.targetElCss);			
		}
		if(this.targets){
			for(var i=0; i<this.targets.length; i++){
				$addHandlers( _proxy_jslib_handle(this.targets, (i), 0, 0), {mouseover:this.show, mouseout:this.hide}, this);		
				if(this.tTipShowOnFocus){
					$addHandlers( _proxy_jslib_handle(this.targets, (i), 0, 0), {focus:this.show, blur:this.hide}, this);
				}
			}
		}
		if(!this.fixLocation){
		    this.fixLocation = 0;
		}		
		FriendsCategories.AjaxToolTip.callBaseMethod(this, 'initialize');
	},
	
	dispose : function() {
		if(this.targets){
			for(var i=0; i<this.targets.length; i++){
				$clearHandlers( _proxy_jslib_handle(this.targets, (i), 0, 0));
			}
		}
        this._element = null;          
        FriendsCategories.AjaxToolTip.callBaseMethod(this, 'dispose');
   },
	
	setContent : function(content) {
		this.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);
		// If the tooltip is already built then update ToolTip DOM.
		if(this._element)
		{
			 _proxy_jslib_assign('',  _proxy_jslib_handle(this._element.firstChild.childNodes, (( _proxy_jslib_handle(this._element, 'location', '', 0, 0) == 3 ? 1:0)), 0, 0), 'innerHTML', '=', ( this.tTipContent));
		}
	},
	
	_setUp : function() {		
		this._element = document.createElement('div');		
		 _proxy_jslib_assign('', this._element, 'innerHTML', '=', ( this._buildTTip("up")));				

		var toolTipStyle = 	this._element.style;
		toolTipStyle.position = 'absolute';
		toolTipStyle.height = 'auto';
		toolTipStyle.left = '0px';
		 _proxy_jslib_assign('', toolTipStyle, 'top', '=', ( '0px'));
		toolTipStyle.zIndex = 50;
		
		//Add the element to DOM		
		 _proxy_jslib_handle(document, 'body', '', 0, 0).appendChild(this._element);						
		this._isSetUp = true;
	},	
	
	_buildTTip : function(dir) {
		if(dir == "up")
		{
			return String.format(this._tTipUpHtml, this.tTipCss, "divPtr", this.tTipPtrCss, "", "divPopupText", this.tTipTextCss, this.tTipContent);
		}
		else
		{
			return String.format(this._tTipUpHtml, this.tTipCss, "divPopupText", this.tTipTextCss + "Above", this.tTipContent, "divPtr", this.tTipPtrCss + "down", "");
		}
	},
	
	// Place the tooltip above of below the element.
	_positionToolTip : function(tipElem) {
		var elementBounds = Sys.UI.DomElement.getBounds(tipElem);
		var windowBounds = this._getWindowSize();
		
		// Showing Tooltip above the Element
		if(this.fixLocation!=3 && (this.fixLocation==1 || (elementBounds.y - this._getScrollPos()) + elementBounds.height + this._element.firstChild.clientHeight > windowBounds.height))
		{
			if( _proxy_jslib_handle(this._element, 'location', '', 0, 0) != 1)
			{				
				 _proxy_jslib_assign('', this._element, 'innerHTML', '=', ( this._buildTTip("down")));
			}
		
			 _proxy_jslib_assign('', this._element.style, 'top', '=', ( elementBounds.y - this._element.firstChild.clientHeight + "px"));
			 _proxy_jslib_assign('', this._element, 'location', '=', ( 1));
		}
		else
		{
			if( _proxy_jslib_handle(this._element, 'location', '', 0, 0) != 3)
			{				
				 _proxy_jslib_assign('', this._element, 'innerHTML', '=', ( this._buildTTip("up")));
			}
		
			 _proxy_jslib_assign('', this._element.style, 'top', '=', ( elementBounds.y + elementBounds.height + "px"));
			 _proxy_jslib_assign('', 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(  _proxy_jslib_handle(document, 'body', '', 0, 0) && (  _proxy_jslib_handle(document, 'body', '', 0, 0).clientWidth ||  _proxy_jslib_handle(document, 'body', '', 0, 0).clientHeight ) ) 
		  {
			//IE 4 compatible
			myWidth =  _proxy_jslib_handle(document, 'body', '', 0, 0).clientWidth;
			myHeight =  _proxy_jslib_handle(document, 'body', '', 0, 0).clientHeight;
		  }
		 return {width:myWidth, height:myHeight};
	},
	
	_getScrollPos : function() {
		var ScrollTop =  _proxy_jslib_handle(document, 'body', '', 0, 0).scrollTop;
		if (ScrollTop == 0)
		{
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = ( _proxy_jslib_handle(document, 'body', '', 0, 0).parentElement) ?  _proxy_jslib_handle(document, 'body', '', 0, 0).parentElement.scrollTop : 0;
		}
		return ScrollTop;
	},
	
	/// <param name="evt" type="Event" mayBeNull="false"></param>
	show : function(evt) {	
		var tipElem = evt.target;
		if (!this._isSetUp)
		{
			this.setContent(this.tTipContent)

 this._setUp();			
		}
				
		if(!this._element || tipElem.dispalyed)
		{
		    return false;
		}
		
		tipElem.dispalyed = true;
		
		//Check for the positioning.
		this._positionToolTip(tipElem);		
		this._element.style.visibility = 'visible';		
				
		return false;
	},
	
	hide : function(evt) {
		var tipElem = evt.target;
		if(this._element)
		{
			this._element.style.visibility = 'hidden';
			this._element.style.left = '0px';
			 _proxy_jslib_assign('', this._element.style, 'top', '=', ( '0px'));
			tipElem.dispalyed = false;
		}
	}
}
FriendsCategories.AjaxToolTip.registerClass('FriendsCategories.AjaxToolTip', Sys.Component);

FriendsCategories.TimeOutAjaxToolTip = function() {
	FriendsCategories.TimeOutAjaxToolTip.initializeBase(this);
}

FriendsCategories.TimeOutAjaxToolTip.prototype =
{
	_hideDelay: 500,	
	_timerID: 0,
	_timeOEvt: null,
    
    get_hideDelay : function() {return this._hideDelay;},
	set_hideDelay : function(value) {this._hideDelay =  _proxy_jslib_handle(null, 'value', value, 0, 0);},
	
	initialize : function() {
		FriendsCategories.TimeOutAjaxToolTip.callBaseMethod(this, 'initialize');
		if(this.targets){
			for(var i=0; i<this.targets.length; i++){
				$clearHandlers( _proxy_jslib_handle(this.targets, (i), 0, 0));
				$addHandler( _proxy_jslib_handle(this.targets, (i), 0, 0),"mouseover", Function.createDelegate(this,this._toShow));
				$addHandler( _proxy_jslib_handle(this.targets, (i), 0, 0),"mouseout", Function.createDelegate(this,this._checkToHide));
			}
		}		
	},
	
	dispose : function() {         
        FriendsCategories.TimeOutAjaxToolTip.callBaseMethod(this, 'dispose');
   },
	
	_clearTimerID: function() {
		if (this._timerID){
			clearTimeout(this._timerID);
			this._timerID = 0;
		}
	},
	
	_toShow : function(evt) {
		if(!evt.target.dispalyed)
		{		
			FriendsCategories.TimeOutAjaxToolTip.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._timeOEvt = evt;
		this._timerID =  _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)(Function.createDelegate(this,this._dHide),this._hideDelay);		
	},
	
	_dHide : function() {
		this._clearTimerID();
		if(this._mOverTT)
		{
			this._timerID =  _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)(Function.createDelegate(this,this._dHide),this._hideDelay);
		}
		else
		{
			$clearHandlers(this._element);
			this.hide(this._timeOEvt);
		}
	}
}
FriendsCategories.TimeOutAjaxToolTip.registerClass('FriendsCategories.TimeOutAjaxToolTip', FriendsCategories.AjaxToolTip);


// View Friends Class
// ------------------

FriendsCategories.ViewFriends = function() {
	this._catDD;
	this._cId;
	this._cName;
	this._cPriv;
	this._cDesc;
	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, cDesc, cPriv, isReqOwner, rndFrndHref) {
	if(!_viewFriendso)
	{
		//_viewFriendso=$create(FriendsCategories.ViewFriends);
		_viewFriendso= new (FriendsCategories.ViewFriends)();
		_viewFriendso._rndFrndHref = rndFrndHref;
		_viewFriendso.initialize(cId, cName, cDesc, cPriv, isReqOwner)

 }
	return _viewFriendso;
}
FriendsCategories.ViewFriends.prototype =
{
	initialize : function(cId, cName, cDesc, cPriv, isReqOwner) {
		FriendsCategories.ViewFriends.initializeBase(this);
		
		this._cId = cId;
		this._cName = cName;
		this._cDesc = cDesc;
		this._cPriv = cPriv;
		this._isReqOwner = isReqOwner;
		
		// Gets the dropdown
		var ddContainer = $get("myfriends_display");
		if(ddContainer)
		{
			this._catDD =  _proxy_jslib_handle(ddContainer, 'getElementsByTagName', '', 1, 0)("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._cDesc, this._cPriv);
				editCato.addEditCatClicked(Function.createDelegate(this,this.editCatCB));
			}
			
			// wrap text in owner and visitor views
			var catLabel = getElementsByClassName(this._ownViewo, "a", "categoryNameLabel")[0];
			
			 _proxy_jslib_assign('', catLabel, 'innerHTML', '=', ( manageFriends._encodeAmpersands(this._cName.call(TextFilterWBR))));
						
			var catDesc = getElementsByClassName(this._ownViewo, "p", "categoryDescLabel")[0];
			if(catDesc)
			{
				 _proxy_jslib_assign('', catDesc, 'innerHTML', '=', ( manageFriends._encodeAmpersands(this._cDesc)));
			}
			MySpace.Util.applyWBRToElement(catDesc, {frequency: 12});			
			
		}
	},
	
	setViewHideTips : function() {	
		var hTipsImgs = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'hiddenTTip','targetElTag':'img', 'tTipContent':MySpaceRes.FriendCategories.HiddenFriendTooltip,'tTipShowOnFocus':0});
	},
	
	setOwnerViewTips : function() {
		var content = new (Sys.StringBuilder)("");        
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("<div id='' class='toolTipDefText'>");
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipHelpText);
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("</div>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.JustMeCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>")

  _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipJustMe);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");

		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");

		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		
		var hTipsImgs = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'categoryHelpImg','targetElTag':'img', 'tTipCss':'BluePopupDiv','tTipPtrCss':'BluePopupPointer','tTipTextCss':'BluePopupText','tTipShowOnFocus':0});
		hTipsImgs.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);		
	},
	
	setVisitorViewTips : function() {
		var content = new (Sys.StringBuilder)("");  
		      
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>") 

  _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		
		var hTipsImgs = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'categoryHelpImg','targetElTag':'img', 'tTipCss':'BluePopupDiv','tTipPtrCss':'BluePopupPointer','tTipTextCss':'BluePopupText','tTipShowOnFocus':0});
		hTipsImgs.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);
	},
	
	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 = $create(FriendsCategories.TimeOutAjaxToolTip, {'targets':[rndImg], 'tTipShowOnFocus':0});
			toTip.tTipContent = rndTipContent;
		}
	},
	
	setExViewTips : function() {
		var exTipImg = $get("_exViewHideTip");
		if(exTipImg)
		{
			this._exViewTTo = $create(FriendsCategories.AjaxToolTip,{'targets':[exTipImg], 'targetElTag':'img', 'tTipShowOnFocus':0});			
			
			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)
		{			
			 _proxy_jslib_assign('',  _proxy_jslib_handle(this._catDD.options, (this._catDD.selectedIndex), 0, 0), 'innerHTML', '=', ( e.cName));
			// Update the dropdown
			var catName =  _proxy_jslib_handle(this._catDD.options, (this._catDD.selectedIndex), 0, 0).text;
			if (catName.length > this.MAX_DD_NAME_LEN)
			{
				catName = catName.substring(0, this.MAX_DD_NAME_LEN) + "...";
			}
			 _proxy_jslib_assign('',  _proxy_jslib_handle(this._catDD.options, (this._catDD.selectedIndex), 0, 0), 'innerHTML', '=', ( catName));
			
			// Update the ownerView title
			catName = e.cName;
			var catLabel = getElementsByClassName(this._ownViewo, "a", "categoryNameLabel")[0];
			 _proxy_jslib_assign('', catLabel, 'innerHTML', '=', ( manageFriends._encodeAmpersands(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( _proxy_jslib_handle(document, 'body', '', 0, 0), "a", "catName");
			for(var i=0;i<aBarNames.length;i++)
			{
				 _proxy_jslib_assign('',  _proxy_jslib_handle(aBarNames, (i), 0, 0), 'innerHTML', '=', ( catName));
			}
		}
		
		if(e.cDesc != 'undefined' && e.cDesc != null)
		{		
			var catDesc = getElementsByClassName(this._ownViewo, "p", "categoryDescLabel")[0]
			 _proxy_jslib_assign('', catDesc, 'innerHTML', '=', ( manageFriends._encodeAmpersands(e.cDesc)));
			MySpace.Util.applyWBRToElement(catDesc, {frequency: 12});
		}
		
		// update the privacy setting.
		if(e.cPriv)
		{
			 _proxy_jslib_assign('', getElementsByClassName(this._ownViewo, "span", "categoryDefBold")[0], 'innerHTML', '=', ( e.cPriv));
		}		
	},
	
	setCategoryPrivacyStatus : function (catId, ownerId, elem, hideTxt, showTxt) {
		var switchToPublic = elem.getAttribute("IsPublic") == "false";
		
		var oSmile = getElementsByClassName($get("myfriends"), "img", "hiddenCatImage")[0];
		
		MySpace.Web.Modules.Friends.Services.FriendsService.UpdateMembershipStatus(catId, switchToPublic);
		if (switchToPublic) {
			 _proxy_jslib_assign('', elem, 'innerHTML', '=', ( hideTxt));
			 _proxy_jslib_handle(elem, 'setAttribute', '', 1, 0)("IsPublic", "true");
			_viewFriendso._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.HideToolTip);
			oSmile.style.visibility = "hidden";
			
		} else {
		    _proxy_jslib_assign('', elem, 'innerHTML', '=', ( showTxt));
		    _proxy_jslib_handle(elem, 'setAttribute', '', 1, 0)("IsPublic", "false");
		   _viewFriendso._exViewTTo.setContent(MySpaceRes.ViewAllFriendsPage.UnHideToolTip);
		   oSmile.style.visibility = "visible";
		}
    
	},
	
	_encodeAmpersands : function(str) {
		str =  _proxy_jslib_handle(str, 'replace', '', 1, 0)(/&$/g, "&amp;");
		str =  _proxy_jslib_handle(str, 'replace', '', 1, 0)(/\s&$/g, " &amp;");
		str =  _proxy_jslib_handle(str, 'replace', '', 1, 0)(/\s&\s/g, " &amp; "); 
		
		return str;
	}
}



// Setup Edit Category Links for the View Categories page
FriendsCategories.ViewCats = function() {
	this._isReqOwner;
	this._catIds;
	this._catNames;
	this._catDescs;
	this._catPrivs;

}
FriendsCategories.ViewCats.registerClass('FriendsCategories.ViewCats');

FriendsCategories.ViewCats.prototype = {
    initialize : function(isReqOwner, categoryIds, categorNames, categoryDescriptions, categoryPrivs, isCatIamIn) {
		FriendsCategories.ViewCats.initializeBase(this);
		this._isReqOwner = isReqOwner;
		this._catIds = categoryIds;
		this._catNames = categorNames;
		this._catPrivs = categoryPrivs;
		this._catDescs = categoryDescriptions;
		
		var cats = getElementsByClassName($get("myfriends"), "div", "categoryListView");
			
		for(var i=0;i<cats.length;i++)
		{
			var ownerLinks = getElementsByClassName( _proxy_jslib_handle(cats, (i), 0, 0), "a", "categoryDefA");
			
			if (ownerLinks.length > 0)
			{
				var editCato = new (FriendsCategories.EditCat)();
				editCato.init(ownerLinks[0],  _proxy_jslib_handle(this._catIds, (i), 0, 0), _proxy_jslib_handle(this._catNames, (i), 0, 0), _proxy_jslib_handle(this._catDescs, (i), 0, 0), _proxy_jslib_handle(this._catPrivs, (i), 0, 0));
				editCato.addEditCatClicked(Function.createDelegate( _proxy_jslib_handle(cats, (i), 0, 0),this.editCatCB));
			}
		}
		// initialize the tool tips for viewable by
		if (this._isReqOwner && (! isCatIamIn))
		{
			this.setOwnerViewTips();
		}
		else
		{
			this.setVisitorViewTips();
		}
		
		// set the tool tips for hidden friends 
		this.setHiddenViewTips();
		this.setCatWBR();				
		
		this.setHideLinksTips();
    },
    
    setCatWBR : function() {
		var catNames = getElementsByClassName($get("myfriends"), "a", "categoryNameLabel");
		for(var i=0;i<catNames.length;i++)
		{
			MySpace.Util.applyWBRToElement( _proxy_jslib_handle(catNames, (i), 0, 0), {frequency: 12});
		}
		
		var catDescs = getElementsByClassName($get("myfriends"), "p", "categoryDescLabel");
		for(var i=0;i<catDescs.length;i++)
		{			 
			MySpace.Util.applyWBRToElement( _proxy_jslib_handle(catDescs, (i), 0, 0), {frequency: 12});
		}
    },
    
    editCatCB : function(sender, e) {		
		if(e.cName)
		{
			var cNameLabel = getElementsByClassName(this, "a", "categoryNameLabel")[0];
			 _proxy_jslib_assign('', cNameLabel, 'innerHTML', '=', ( manageFriends._encodeAmpersands(e.cName.call(TextFilterWBR))));
		}
		if(e.cPriv)
		{
			var cPrivLabel = getElementsByClassName(this, "span", "categoryDefBold")[0];			
			 _proxy_jslib_assign('', cPrivLabel, 'innerHTML', '=', ( e.cPriv));
		}
		if(e.cDesc != 'undefined' && e.cDesc != null)
		{
			var cDescLabel = getElementsByClassName(this, "p", "categoryDescLabel")[0];			
			 _proxy_jslib_assign('', cDescLabel, 'innerHTML', '=', ( manageFriends._encodeAmpersands(e.cDesc)));
			MySpace.Util.applyWBRToElement(cDescLabel, {frequency: 12});
		}		
    },
    	
	setOwnerViewTips : function() {
		var content = new (Sys.StringBuilder)("");        
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("<div id='' class='toolTipDefText'>");
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipHelpText);
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("</div>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.JustMeCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>")

  _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipJustMe);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");

		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");

		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		
		var tellCatTip = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'categoryHelpImg','targetElTag':'img','tTipCss':'BluePopupDiv','tTipPtrCss':'BluePopupPointer','tTipTextCss':'BluePopupText','tTipShowOnFocus':0});
		tellCatTip.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);		
	},
	
	setVisitorViewTips : function() {
		var content = new (Sys.StringBuilder)("");        
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.MembersOnlyCategorySecurityLabel);
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipMembersOnly);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>"); 
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");
		
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefLabel'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.EveryoneCategorySecurityLabel);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(":&nbsp;</span>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("<span id='' class='toolTipDefText'>");
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.PrivacyTooltipEveryone);
		 _proxy_jslib_handle(null, 'content', content, 0, 0).append("</span>") 

  _proxy_jslib_handle(null, 'content', content, 0, 0).append("<br />");

		var hTipsImgs = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'categoryHelpImg','targetElTag':'img','tTipCss':'BluePopupDiv','tTipPtrCss':'BluePopupPointer','tTipTextCss':'BluePopupText','tTipShowOnFocus':0});
		hTipsImgs.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);
	},
	
	setHiddenViewTips : function() {
		var content = new (Sys.StringBuilder)("");        
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("<div id='' class=''>");
         _proxy_jslib_handle(null, 'content', content, 0, 0).append(MySpaceRes.ViewAllFriendsPage.ToolTipHiddenFriends);
         _proxy_jslib_handle(null, 'content', content, 0, 0).append("</div>");
		
		var hTips = $create(FriendsCategories.AjaxToolTip,{'targetElCss':'hiddenFriendsImg','targetElTag':'img','tTipCss':'BluePopupDiv2','tTipPtrCss':'BluePopupPointer2','tTipTextCss':'BluePopupText2','tTipShowOnFocus':0});
		hTips.tTipContent =  _proxy_jslib_handle(null, 'content', content, 0, 0);
	},
	
	setHideLinksTips : function() {
		var hTipsImgs = getElementsByClassName($get("myfriends"), "img", "hidelinktooltip"); 
		
		if (hTipsImgs != null && hTipsImgs.length > 0)
		{			
			this._hideLinkCatTip = $create(FriendsCategories.AjaxToolTip,{'tTipCss':'BluePopupDiv2','tTipPtrCss':'BluePopupPointer2','tTipTextCss':'BluePopupText2','tTipShowOnFocus':0});
	
			for(var i=0;i<hTipsImgs.length; i++)
			{
				$addHandlers( _proxy_jslib_handle(hTipsImgs, (i), 0, 0), {mouseover:this.ShowHideLinkTip, mouseout:this.HideHideLinkTip}, this);			
			}
		}		
	},
	
	ShowHideLinkTip : function(evt) {
		if(this._hideLinkCatTip)
		{
			//Check Attribute
			var isPublic = (evt.target.getAttribute("IsPublic") == "true");
			
			if(isPublic)
			{
				this._hideLinkCatTip.setContent(MySpaceRes.ViewAllFriendsPage.HideToolTip);
			}
			else
			{
				this._hideLinkCatTip.setContent(MySpaceRes.ViewAllFriendsPage.UnHideToolTip);
			}
			
			this._hideLinkCatTip.show(evt);
		}
	},
	
	HideHideLinkTip : function(evt) {
		this._hideLinkCatTip.hide(evt);
	}
	
}

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 +=  _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];
    }
}

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= _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;
    }
}



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 ==  _proxy_jslib_handle(sender, 'value', '', 0, 0))
    {
         _proxy_jslib_assign('', sender, 'value', '=', ( ""));
        sender.className = "inp";
    }
}

function blurBox(sender) {	
    if (  _proxy_jslib_handle(sender, 'value', '', 0, 0) == "")
    {
         _proxy_jslib_assign('', sender, 'value', '=', ( sender.defaultValue));
        sender.className = "inp grey";
    }
}

function ResetSearchText(sender) {
	if (sender.className == "inp grey")
	{
		 _proxy_jslib_assign('', sender, 'value', '=', ( ""));
		sender.className = "inp";
	}
}

function BlurSearchText(sender) {
	if (  _proxy_jslib_handle(sender, 'value', '', 0, 0) == "")
	{ 
		 _proxy_jslib_assign('', sender, 'value', '=', ( MySpaceRes.ViewAllFriendsPage.SearchWithin));
		sender.className = "inp grey";
	}
}

function ValidateSearchText(sendToUrl) {	
	if ( searchTextBox.className == "inp grey" ||
		 _proxy_jslib_handle(searchTextBox, 'value', '', 0, 0).length == 0 )
	{
		return false;
	}
	
	 _proxy_jslib_assign('',  _proxy_jslib_handle(self, 'location', '', 0, 0), 'href', '=', ( sendToUrl));	
	return false;
}

function CheckSearchTextBox() {
	if(searchTextBox == null)
		return;
		
	if( _proxy_jslib_handle(searchTextBox, 'value', '', 0, 0) == MySpaceRes.ViewAllFriendsPage.SearchWithin)
	{
		searchTextBox.className = "inp grey";
	}
	else
	{
		searchTextBox.className = "inp";
	}
}

// setting the webservice path
// This method also sets the handler that will be invoked before making reqests
// Sets handler to unload the eventhandlers
function setServicePath(wsPath) {
	MySpace.Web.Modules.Friends.Services.FriendsService.set_path(wsPath);
	Sys.Net.WebRequestManager.add_invokingRequest(onReqInvoke);
	Sys.Application.add_unload(onCatPgUnload);

}

// Sends the hash code in request header
function onReqInvoke(sender, args) {
     _proxy_jslib_assign('', args.get_webRequest().get_headers(), ('hashChecker'), '=', (  _proxy_jslib_handle($get("hashChecker"), 'value', '', 0, 0)));
}

// removes the WebRequestManager request handler.
function onCatPgUnload(sender, args) {
    Sys.Net.WebRequestManager.remove_invokingRequest(onReqInvoke);
}


function ExitSuggestionPopup() {
	  var popup =  _proxy_jslib_handle(null, 'parent', parent, 0, 0).window.get_iframepopup();
	  if(null !== popup && "undefined" !== typeof(popup)) popup.hide();
	  		
}

// Clientside object for alphabar can be generalized if needed at more places.
FriendsCategories.AlphaBar = function() {
    var alphaBaro = this;
    this.alphaLinks = new (Array)();
    this.pagerLinks = new (Array)();    
    this._container = null;
    this._events = null;
    
    this.AlphabarUnload = function() {
        alphaBaro.ClearAlpha();
        alphaBaro.ClearPager();
        alphaBaro = null;
    }
    
    this.ClearAlpha = function() {
        for(var i=0;i<alphaBaro.alphaLinks.length;i++)
        {
            $removeHandler( _proxy_jslib_handle(alphaBaro.alphaLinks, (i), 0, 0), 'click', alphaBaro.AlphaLinkClicked);
        }        
        alphaBaro.alphaLinks = null;
    }
    
    this.ClearPager = function() {
		if(alphaBaro.pagerLinks)
		{
			for(var i=0;i<alphaBaro.pagerLinks.length;i++)
			{            
				$removeHandler( _proxy_jslib_handle(alphaBaro.pagerLinks, (i), 0, 0), 'click', alphaBaro.PagerLinkClicked);
			}
        }
        alphaBaro.pagerLinks = null;
    }
        
    // Handler for alpha link clicked event
    this.AlphaLinkClicked = function(evt) {        
        alphaBaro._RaiseEvent('alphaLinkClicked', evt.target);
        evt.preventDefault();        
    }
    
    // Handler for alpha link clicked event
    this.PagerLinkClicked = function(evt) {
        var linkClass = evt.target.className.toLowerCase();
        if(!(linkClass.indexOf("highlight") > -1 || linkClass.indexOf("disabled") > -1))
        {
            alphaBaro._RaiseEvent('pagerLinkClicked',  _proxy_jslib_handle(evt.target, 'href', '', 0, 0));
        }
        evt.preventDefault();        
    }
}

FriendsCategories.AlphaBar.prototype = 
{  
    Initialize: function(container) {
		this._container = container;
        this.SetUpAlphaLinks(container);
        Sys.Application.add_unload(this.AlphabarUnload);
    },            
    
    SetUpAlphaLinks : function(container) {
        var rightPanelLinks =  _proxy_jslib_handle(container, 'getElementsByTagName', '', 1, 0)("A");
        for(var i=0;i<rightPanelLinks.length;i++)
        {
            // Storing Alpha links
            if( _proxy_jslib_handle(rightPanelLinks, (i), 0, 0).className.toLowerCase().indexOf("alphabarlink") > -1)
            {
                $addHandler( _proxy_jslib_handle(rightPanelLinks, (i), 0, 0), 'click', this.AlphaLinkClicked);
                Array.add(this.alphaLinks,  _proxy_jslib_handle(rightPanelLinks, (i), 0, 0));                
            }
            // Storing paging links
            else if( _proxy_jslib_handle(rightPanelLinks, (i), 0, 0).className.toLowerCase().indexOf("paginglink") > -1 ||( _proxy_jslib_handle(rightPanelLinks, (i), 0, 0).className == "highlight" &&  _proxy_jslib_handle(rightPanelLinks, (i), 0, 0).parentNode.className == "nav_left"))
            {
                $addHandler( _proxy_jslib_handle(rightPanelLinks, (i), 0, 0), 'click', this.PagerLinkClicked);
                Array.add(this.pagerLinks,  _proxy_jslib_handle(rightPanelLinks, (i), 0, 0));
            }            
        }
    },
    
    // truncates the cat name if its more then Max chars.
    AdjustAlphaTitle : function(aTitle) {
        var maxLen = 17;
		if(aTitle && aTitle.length > maxLen)
		{
			aTitle = aTitle.substring(0, maxLen) + "...";
		}
		return aTitle;
    },
    
    UpdateAlpha : function(newAlpha) {
		newAlpha = this.AdjustAlphaTitle(newAlpha);
        for(var i=0;i<this.alphaLinks.length;i++)
        {
            var currLink =  _proxy_jslib_handle(this.alphaLinks, (i), 0, 0);
            if( _proxy_jslib_handle(currLink, 'innerHTML', '', 0, 0) == newAlpha)
            {
                Sys.UI.DomElement.addCssClass(currLink, "highlight");
            }
            else 
            {
                Sys.UI.DomElement.removeCssClass(currLink, "highlight");
            }
        }        
    },
    
    UpdateAlphaTitle : function(cName) {		
		cName = this.AdjustAlphaTitle(cName);
		for(var i=0;i<this.alphaLinks.length;i++)
        {
            if( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).className.indexOf("catName") > -1)
            {
                 _proxy_jslib_assign('',  _proxy_jslib_handle(this.alphaLinks, (i), 0, 0), 'innerHTML', '=', ( cName));
            }
        }
    },
    
    UpdatePager : function(currPageNum, newPageNum, prevPageNum, nextPageNum) {
        for(var i=0;i<this.pagerLinks.length;i++)
        {
            var currLink =  _proxy_jslib_handle(this.pagerLinks, (i), 0, 0);
            if( _proxy_jslib_handle(currLink, 'innerHTML', '', 0, 0) == currPageNum)
            {
                currLink.className = "pagingLink";
                 _proxy_jslib_assign('', currLink, 'href', '=', ( "GotoPage("+currPageNum+")"));
            }
            else if( _proxy_jslib_handle(currLink, 'innerHTML', '', 0, 0) == newPageNum)
            {
                currLink.className = "highlight";
                currLink.removeAttribute("href");
            }
            else if(Sys.UI.DomElement.containsCssClass(currLink, "prevPagingLink"))
            {
                if(prevPageNum > 0)
                {
                     _proxy_jslib_assign('', currLink, 'href', '=', ( "GotoPage("+prevPageNum+")" ))

 Sys.UI.DomElement.removeCssClass(currLink, "disabledPaging");
                }
                else
                {
                    currLink.removeAttribute("href");
                    Sys.UI.DomElement.addCssClass(currLink, "disabledPaging");                    
                }
            }
            else if(Sys.UI.DomElement.containsCssClass(currLink, "nextPagingLink"))
            {
                if(nextPageNum > 0)
                {
                     _proxy_jslib_assign('', currLink, 'href', '=', ( "GotoPage("+nextPageNum+")"))

 Sys.UI.DomElement.removeCssClass(currLink, "disabledPaging");
                }
                else
                {
                    currLink.removeAttribute("href");
                    Sys.UI.DomElement.addCssClass(currLink, "disabledPaging");
                }
            }
        }
    },
    
    HidePager : function(pagers) {
		for(var i=0;i<pagers.length;i++)
		{
			 _proxy_jslib_handle(pagers, (i), 0, 0).style.visibility = "hidden";
		}
    },
    
    ShowPager : function(pagers) {
		for(var i=0;i<pagers.length;i++)
		{
			 _proxy_jslib_handle(pagers, (i), 0, 0).style.visibility = "visible";
		}
    },
    
    ResetPager : function(pagerContainer) {
		pagerContainer.style.visibility = "visible";
		// check for showing divider between alpha bar and pager bar
		if(this.alphaLinks && this.alphaLinks.length > 0)
		{
			Sys.UI.DomElement.addCssClass(pagerContainer.childNodes[0], "alphaLine");
		}
        var pageLinks =  _proxy_jslib_handle(pagerContainer, 'getElementsByTagName', '', 1, 0)("A");
        if(this.pagerLinks == null)
        {
            this.pagerLinks = new (Array)();
        }
        //attach handlers to new link
        for(var i=0;i<pageLinks.length;i++)
        {
            $addHandler( _proxy_jslib_handle(pageLinks, (i), 0, 0), 'click', this.PagerLinkClicked);
            Array.add(this.pagerLinks,  _proxy_jslib_handle(pageLinks, (i), 0, 0));            
        }                
    },
    
    AddAlphaLinkClicked : function(handler) {
        this.GetEvents().addHandler('alphaLinkClicked', handler);
    },       
    
    AddPagerLinkClicked : function(handler) {
        this.GetEvents().addHandler('pagerLinkClicked', handler);
    },
    
     DisableHandlers : function(grayLink) {
		for(var i=0;i<this.alphaLinks.length;i++)
        {
			$removeHandler( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0),'click', this.AlphaLinkClicked);
			$addHandler( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0),'click', this.DisabledLinkClick);
			if(grayLink) { _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).style.color = "gray";}
			if( _proxy_jslib_handle( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0), 'href', '', 0, 0))
			{
				 _proxy_jslib_handle( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0), 'setAttribute', '', 1, 0)('hrefback',  _proxy_jslib_handle( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0), 'href', '', 0, 0)); 
				 _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).removeAttribute('href'); 
			}
        }
        
        if(this.pagerLinks)
        {
			for(var i=0;i<this.pagerLinks.length;i++)
			{
				$removeHandler( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0),'click', this.PagerLinkClicked);
				$addHandler( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0),'click', this.DisabledLinkClick);
				if(grayLink) { _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).style.color = "gray";}
				if( _proxy_jslib_handle( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0), 'href', '', 0, 0))
				{
					 _proxy_jslib_handle( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0), 'setAttribute', '', 1, 0)('hrefback',  _proxy_jslib_handle( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0), 'href', '', 0, 0)); 
					 _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).removeAttribute('href'); 				
				}
			}
        }
    },
    
    EnableHandlers : function() {
		for(var i=0;i<this.alphaLinks.length;i++)
        {			
			$removeHandler( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0),'click', this.DisabledLinkClick);
			$addHandler( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0),'click', this.AlphaLinkClicked);
			 _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).style.color = "";
			if( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).getAttribute("hrefback"))
			{
				 _proxy_jslib_handle( _proxy_jslib_handle(this.alphaLinks, (i), 0, 0), 'setAttribute', '', 1, 0)('href',  _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).getAttribute("hrefback")); 
				 _proxy_jslib_handle(this.alphaLinks, (i), 0, 0).removeAttribute('hrefback'); 				
			}
        }
        
        if(this.pagerLinks)
        {
			for(var i=0;i<this.pagerLinks.length;i++)
			{			
				$removeHandler( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0),'click', this.DisabledLinkClick);
				$addHandler( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0),'click', this.PagerLinkClicked);
				 _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).style.color = "";	
				if( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).getAttribute("hrefback"))
				{
					 _proxy_jslib_handle( _proxy_jslib_handle(this.pagerLinks, (i), 0, 0), 'setAttribute', '', 1, 0)('href',  _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).getAttribute("hrefback")); 
					 _proxy_jslib_handle(this.pagerLinks, (i), 0, 0).removeAttribute('hrefback'); 			
				}
			}
        }		
    },
    
    DisabledLinkClick : function() {
		return false;
    },

    
    GetEvents : function() {
        if(!this._events){
            this._events = new (Sys.EventHandlerList)();
        }
        return this._events;
    },
            
    _RaiseEvent : function(eventName, eventArgs) {
        var handler = this.GetEvents().getHandler(eventName);
        if(handler){
            if(!eventArgs){
                eventArgs = Sys.EventArgs.Empty;
            }
            handler(this, eventArgs);
        }
    }
} ;
_proxy_jslib_flush_write_buffers() ;