

        function keepalive(){
	        var keepAliveFrame = document.createElement("iframe");
	        keepAliveFrame.src = clientScriptPathInfo.ApplicationPath + "/keepalive.ashx";
	        keepAliveFrame.style.display = "none";
	        document.body.appendChild(keepAliveFrame);
        }






function titleAndStar(totalPosts, score, isMod, isAdmin, customTitle, customPic, imgID, titleID) {
        //alert(titleID + ' called!');
	    var title;
	    var star;
	    var separator = String.fromCharCode(1);
    	
	    if (score==null||score=="") score=0;
    	
	    if (isMod){
		    title = userLevelNameMod;
		    star = modStar;
	    }
	    if(isAdmin){
		    title = userLevelNameAdmin;
		    star = adminStar;
	    }
	    if (title==null){
		    for (var i=1; i<strTitle.length ; i++){
			    var userL = strTitle[i].split(separator);
			    var evaluation = eval(totalPosts+"<="+userL[0]+userL[1]+score+"<="+userL[2]);
			    if (evaluation){
				    title = userL[3];
				    star = userL[4]+starPicSuffix;
				    break;
			    }
		    }
		    if (title==null){
			    title = strTitle[strTitle.length-1].split(separator)[3];
			    star =  strTitle[strTitle.length-1].split(separator)[4]+starPicSuffix;
		    }

	    }
	    if (customTitle!="") (title = customTitle);
	    if (customPic!="") (star = customPic);

        theImage = $get(imgID);
        theTitle = $get(titleID);
        
        if (theTitle) theTitle.innerHTML = title; 
        if (theImage) theImage.src = clientScriptPathInfo.ApplicationPath + "/image/" + star;

	//document.write (title + "<br /><img src=\"" + clientScriptPathInfo.ApplicationPath + "/image/" + star + "\" /><br />");
}








/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
/* Modified 20070316 to stop highlighting inside nosearchhi nodes */

var ASPPG_searchQuery = 'high';

function highlightWord(node,word) {
    if (word.trim().length == 0) return;
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			// check if we're inside a "nosearchhi" zone
			checkn = pn;
			while (checkn.nodeType != 9 && 
			checkn.nodeName.toLowerCase() != 'body') { 
			// 9 = top of doc
				if (checkn.className.match(/\bnosearchhi\b/)) { return; }
				checkn = checkn.parentNode;
			}
			if (pn.className != ASPPG_searchQuery) {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = ASPPG_searchQuery;
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

addLoadListener(
    function () {
        var qs = createRequestObject();
        var highlitewords = (qs[ASPPG_searchQuery]) ? qs[ASPPG_searchQuery].trim() : '';
        if (typeof highlitewords != 'undefined' && highlitewords != '') {
            var wordList = highlitewords.replace(/\s/gi, ',').split(',');
            var nodes = $(".msg");

            for (i = 0; i < wordList.length; i++) {
                for (j = 0; j < nodes.length; j++) {
                    highlightWord(nodes[j], wordList[i]);
                }
            }
        }
    }
);






var userLevelNameMod = "Moderator";
var userLevelNameAdmin = "Administrator";
var starPicSuffix = "star.gif";
var modStar = "5star.gif";
var adminStar = "5starA.gif";
var strTitle = new Array() ;
 strTitle [1] = "9||-5000Just Starting Out1";
 strTitle [2] = "99||-5000New Member2";
 strTitle [3] = "249||-5000Trainee3";
 strTitle [4] = "499||-5000Lifter4";
 strTitle [5] = "749||-5000Power Lifter5";
 strTitle [6] = "999||-5000Hardcore Lifter6";
 strTitle [7] = "1499||-5000Master Lifter7";
 strTitle [8] = "2499||-5000Champion8";
 strTitle [9] = "3999||-5000Grand Champion9";
 strTitle [10] = "10000||-5000Master Champion10";







    var tmSelectString;
    //var selectedFromMsg = false;
    
    function tmSelect(){
        
        //selectedFromMsg = true;
        
        if (window.getSelection)
        {
            tmSelectString = window.getSelection().toString();
        }   
        else if (window.document.selection)
        {
            var rng = window.document.selection.createRange();
            tmSelectString = rng.text;
        }
        else {
            tmSelectString = "";
        }
    }

    function attachSelectionToMsg() {
        $("body").bind("mouseup", tmSelect);
    }

    $(attachSelectionToMsg);
    
    function changeTmSort(value){
        if (isNaN(value)) return;        
        createCookie(dbName + "tmRemember", value);
        self.location.replace(clientScriptPathInfo.RawUrl);
    }
    
    var cannotShowTip = false;
    
	function toolTipWin(url){
	    if(cannotShowTip) return;
	    cannotShowTip = true;
	    var tipwin = popRadWin('showpic.aspx?img=' + url, 300, 300);
	    tipwin.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close);
	    setTimeout("cannotShowTip = false;",1000);
	}

    function reloadParent(radWindow){
        //alert("reloadParent");
        
        var arg = radWindow.argument;
        
        //alert(arg);
        
        if(typeof(arg) == 'string'){
            if (arg ==''){
                return;
            }
            else if (arg == 'true' || (arg == 'del' && !inTreeMode)) {
                refreshButton.click();
            }
            else if (arg == 'del' && inTreeMode) {
                tree.loadPrevious();                
            }
            else if (arg == 'reload'){
                self.location.replace(clientScriptPathInfo.RawUrl);
            }
            else if (!isNaN(arg)){
                self.location.replace(clientScriptPathInfo.ApplicationPath + "/tt.aspx?forumID=" + arg);
            }
            
        }
        
    }

    function switchMsgDivOnOff(msgID){
        $get('msg' + msgID).style.display = $get('msg' + msgID).style.display == 'none' ? '' : 'none';
        $get(msgID).style.height = '';
    }

	function SetMessageID(id){
	    currSelectedMsgID = id;
	}
	
	function SetRatingID(){
	    $get(msgRatingHiddenField).value = currSelectedMsgID.toString();

	}
	
	function RemoveRatingID(){
	    $get(msgRatingHiddenField).value = '';
	}
	
	function SubmitRating(){
	    refreshButton.click();
	    hideAllMenus();
	}
	
	function treeUpdate(msgID){
	    $get(msgTreeHiddenField).value = msgID;
	    refreshButton.click();
	}

	var JQMenuLink;
	
	function SetThreadRead(self, lastVisit) {

	    JQMenuLink = self;
	    
	    $(self).css('cursor', 'wait');
	    setTimeout("hideOptionalMenu('markread')", 200);
	    
	    JQCallWebService("tm.aspx/ReadTrackThread", String.format("{{'ThreadID':'{0}','lastVisit':'{1}'}}", currentThreadID, lastVisit),
	        function() {
	            setTimeout("$(JQMenuLink).css('cursor', 'default'); $(OptionalMenu.get_childListElement()).show()", 400);	                
	        }
	    );

	    }

	function SetThreadSubscription(self, action) {

	        JQMenuLink = self;

	        $(self).css('cursor', 'wait');
	        setTimeout("hideOptionalMenu('subscription')", 200);
	        
	        JQCallWebService("tm.aspx/SubscribeToThread", String.format("{{'threadID':{0},'action':{1}}}", currentThreadID, action),
            function(rtn) {
                setTimeout(String.format("updateSubscriptionMenuItem({0});", action), 400);
            }

        );
	}

	function hideOptionalMenu(itemToHide) {
    
        OptionalMenu.close();

        $(OptionalMenu.get_childListElement()).hide();
        
        OptionalMenu.findItemByValue(itemToHide).blur();
    }


    function updateSubscriptionMenuItem(action) {

        $(JQMenuLink).css('cursor', 'default');

        $(OptionalMenu.get_childListElement()).show();

        var imgBaseLocation = clientScriptPathInfo.ApplicationPath + '/' + pageThemeImageURL;
        
        var subscriptionItem = OptionalMenu.findItemByValue('subscription');

        subscriptionItem.set_text((action == -1) ? SubscribeMenuText : UnSubscribeMenuText);

        subscriptionItem.set_imageUrl(imgBaseLocation +
            ((action == -1) ? 'menuSubscribe.gif' : 'menuUnSubscribe.gif'));

        if (action > -2 && action < 4) {
            //alert(action);
            for (var i = 0; i < 4; i++) {
                var subItem = OptionalMenu.findItemByValue('Sub' + i.toString());

                if (action == i) {
                    subItem.set_imageUrl(imgBaseLocation + 'menuSubscription.gif');
                } else {
                    subItem.set_imageUrl(imgBaseLocation + 'blank.gif');
                }

            }

        }

        $(subscriptionItem.get_linkElement()).unbind('click').attr('onclick', '')
            .click(function() {
                if (action == -1) return false; SetThreadSubscription(this, -1);

            });
            
    }


	var tdSizeFired = false;
	var tdsToResize = [];
	
	function changeTdSize(){
	    try { 
	        if (tdSizeFired) return ; 
	        tdSizeFired = true;
	        
	        for (var i in tdsToResize){
	            $get(tdsToResize[i]).style.height = '';
	            $get(tdsToResize[i]).style.height = ($get("td" + tdsToResize[i]).clientHeight - 50).toString() + 'px';	            
	        }
	        setTimeout("tdSizeFired = false;", 1000);
	    }
	    catch(err){
	        //alert(err.description);
	    }
	    
	}
	
	var multiQuoteIDs = [];
	
	function AddMultiQuote(msgID){
	    if (isNaN(msgID)) return ;
	    for (var i =0; i<multiQuoteIDs.length; i++){
	        if(multiQuoteIDs[i] == msgID) {return;}
        }	
	
	    if (multiQuoteIDs.length<3) {
	        multiQuoteIDs[multiQuoteIDs.length] = msgID;
	        $get("multiquoteImg" + msgID).src = pageThemeImageURL + 'menuUnMultiQuote.gif';
        } else {
            alert(tooManyQuotes);
        }
        
        
	}
	
	function RemoveMultiQuote(msgID){
	    if (isNaN(msgID)) return ;
	    var indexToDelete = -1;
	    
	    for (var i =0; i<multiQuoteIDs.length; i++){
	        if(multiQuoteIDs[i] == msgID) {indexToDelete = i; break;}
        }
        
        if (indexToDelete!=-1) multiQuoteIDs.splice(indexToDelete,1);
        $get("multiquoteImg" + msgID).src = pageThemeImageURL + 'blank.gif';        
	}
	
    function openPreview(){
        var rwd = popRadWin('preview.aspx');
        rwd.argument = RadEditor1ClientObject.GetHtml();
        return false; 
    }
    
    function replySimulatedClick(msgID, canReply){

        if (!canReply) {
            currentMemberInfo.popupPosting = false;
        }

        var gotoURL = clientScriptPathInfo.ApplicationPath + '/' + String.format('post.aspx?mq={0}&messageID=', multiQuoteIDs.join()) + msgID;

        if (currentMemberInfo.popupPosting) {
            popRadWin(gotoURL + '&pop=true');
        } else {
            self.location.href = gotoURL;
        }
        return false;
    }

    function showMsgNum(msgID) {
        popTip("<div style='margin:20px 10px;'>URL: <br /><input type='text' onfocus='this.select()' size='45' value='" +
	                 clientScriptPathInfo.ForumDir + "fb.ashx?m=" + msgID + "' /></div>", 
	                 450, 250, false, true, 5000, true, messageIDToolTipClientID);
    }

    function showIP(ip) {
        popTip("<div style='margin:20px 10px;'>IP: <br /><input type='text' onfocus='this.select()' size='45' value='" +
	                 ip + "' /></div>", 450, 250, false, true, 5000, true, messageIDToolTipClientID);

    }

    var rewardMsgID;
    
    function findRewardMsg(msg) {

        if (typeof rewardMsgID != 'undefined') {

            var elePosition = $($get(rewardMsgID)).offset();
            scrollTo(0, elePosition.top);
            
            return;
            
        }

        JQCallWebService("tm.aspx/FindRewardMsg", String.format("{{'msgID':'{0}'}}", msg),
            function(rtn) {
                var returnedMsgID = rtn.d;

                if (returnedMsgID == 0) return;

                if ($get(returnedMsgID)) {

                    var elePosition = $($get(returnedMsgID)).offset();
                    scrollTo(0, elePosition.top);

                    rewardMsgID = returnedMsgID;

                } else {
                    self.location.href = 'fb.ashx?m=' + returnedMsgID;
                }
            },
            JQOnCallError
        )
    
    };

        




    var menuFired = false;

	function OnMenuItemClick(s, e){
	    
	    menuFired = true;
	    
	    setTimeout("menuFired = false;",1000);
	    
	    var item = e.get_item();
	    var baseURL = clientScriptPathInfo.ApplicationPath + '/';
	    var attributes = item.get_attributes();
        var itemArg = attributes.getAttribute('arg');
	    
	    switch (attributes.getAttribute('command')){
    
	        case 'friend':
	            return true;
	            break;	        
	        case 'ignore':
	            return true;
	            break;
	        case 'unignore':
                return true;
	            break;
	        case 'helpful' :
                return true;
                break;
            case 'unhelpful':
                return true;
                break;	            
	        case 'reward' :
                return true;
	            break;
	        case 'mark' :
                return true;
	            break;	            	            
	        case 'pm':
	            var gotoURL = baseURL + 'pmsend.aspx?toMemId=' + itemArg ;
	            if (currentMemberInfo.popupPosting) {
	                popRadWin(gotoURL + '&pop=true');
	            } else {
	                self.location.href = gotoURL;
	            }
	            
	            break;	 
	        case 'reply':
	            var gotoURL = baseURL + String.format('post.aspx?mq={0}&messageID=', multiQuoteIDs.join()) + itemArg ;
	            if (currentMemberInfo.popupPosting) {
	                popRadWin(gotoURL + '&pop=true');
	            } else {
	                self.location.href = gotoURL;
	            }
	            
	            break;	
	        case 'quote':
	            var gotoURL = baseURL + String.format('post.aspx?quote=true&mq={0}&messageID=', multiQuoteIDs.join()) + itemArg ;
	            if (currentMemberInfo.popupPosting) {
	                popRadWin(gotoURL + '&pop=true');
	            } else {
	                self.location.href = gotoURL;
	            }
	            
	            break;	
	        case 'edit':
	            var gotoURL = baseURL + 'post.aspx?edit=true&messageID=' + itemArg ;
	            if (currentMemberInfo.popupPosting) {
	                popRadWin(gotoURL + '&pop=true');
	            } else {
	                self.location.href = gotoURL;
	            }
	            
	            break;		            
	        case 'manage':
	            var gotoURL = baseURL + 'management.aspx?messageID=' + itemArg ;
	            popRadWin(gotoURL, 550, 450);

	            break;

	        case 'ban':
	            var gotoURL = baseURL + 'tempban.aspx?messageID=' + itemArg;
	            popRadWin(gotoURL, 600, 450);

	            break;	            
	            
	        case 'flag':
	        	var gotoURL = baseURL + String.format('flagreport.aspx?messageID={0}&mode=flag',itemArg) ;
	            popRadWin(gotoURL, 600,275);
	            break;
	        case 'report':
	        	var gotoURL = baseURL + 'flagreport.aspx?messageID=' + itemArg ;
	            popRadWin(gotoURL, 600,575);  
	            break; 
	             
	        case 'fwd':
	        	var gotoURL = baseURL + 'forward.aspx?messageID=' + itemArg ;
	            popRadWin(gotoURL, 600,275);  
	            break; 
	            
	        case 'multiquote':
	            AddMultiQuote(itemArg);  
	            break; 	
            
            case 'ip' : 
	            popTip("<div style='margin:20px 10px;'>IP: <br /><input type='text' onfocus='this.select()' size='45' value='" +
	                 itemArg +"' /></div>", 450, 250, false, true, 5000, true, messageIDToolTipClientID);
	            break;   
	            	            
	        case 'msglink' : 
	            popTip("<div style='margin:20px 10px;'>URL: <br /><input type='text' onfocus='this.select()' size='45' value='" +
	                 clientScriptPathInfo.ForumDir + "fb.ashx?m=" + itemArg +"' /></div>", 450, 250, false, true, 5000, true, messageIDToolTipClientID);
	            break;           	                      	            	                       	    
	    }
	    
	    e.set_cancel(true);
	    return false;
	}
	

	function ShowMenu(e, id, isSelf, login, isFriend, isIgnored, viewerIsGuest, memberPMable) {
	    if (menuFired || typeof menu == 'undefined' || !menu) return;
	    
        hideAllMenus(190);
        
        with (menu) {
            var frienditem = findItemByValue("friend");
            var pmitem = findItemByValue("pm");
            var blockitem = findItemByValue("block");
        }

        var menuImgURL = clientScriptPathInfo.ApplicationPath + '/' + pageThemeImageURL;
        
        var oneItemVisible = false;
        
        with (frienditem) {
            set_imageUrl(menuImgURL + 'menuAdd.gif');
            set_text(String.format(FriendMemText, ''));
            
            menu.trackChanges();
            get_attributes().setAttribute('command', 'friend'); get_attributes().setAttribute('arg', id);
            if (isFriend || isIgnored || isSelf || viewerIsGuest) hide(); else {show(); oneItemVisible = true;}
            menu.commitChanges();
        }
        
        with (blockitem){
            var blockItemText = isIgnored ? UnBlockMemText : BlockMemText;
            var blockItemCommand = isIgnored ? 'unignore' : 'ignore';
            set_imageUrl(menuImgURL + (isIgnored ? 'menuUnblock.gif' : 'menuBlock.gif'));
            set_text(String.format(blockItemText, ''));
            
            menu.trackChanges();
            get_attributes().setAttribute('command', blockItemCommand); get_attributes().setAttribute('arg', id);
            if (isSelf || viewerIsGuest) hide(); else {show(); oneItemVisible = true;}
            menu.commitChanges();             
        }

        with (pmitem){
             set_imageUrl(menuImgURL + 'menuPM.gif');
             
             set_text(String.format(PmMemText, login)); 
             set_text(String.format(PmMemText, '')); 
             get_attributes().setAttribute('command', 'pm'); get_attributes().setAttribute('arg', id);
             
             if (isSelf || viewerIsGuest || !memberPMable) hide(); else {show(); oneItemVisible = true;}
        }
        
        if (oneItemVisible) menuShow(e, menu);
        
    }	
	
    function showOptionMenu(e, id, canReply, isMod, isLocked, isSelf, canDelete, canDeleteThread, isDeleted, canStillEditDelete, isPostWaitingModeration, viewerIsGuest, theTarget){
	    if (menuFired || typeof menu == 'undefined' || !menu) return;
	    
	    hideAllMenus(110);
	    SetMessageID(id);

	    var oneItemVisible = false;

        with (menu) {
            var quoteitem = findItemByValue("quote");
            var multiquoteitem = findItemByValue("multiquote");
        }
        
        var menuImgURL = clientScriptPathInfo.ApplicationPath + '/' + pageThemeImageURL;
        
        with (quoteitem){
            set_text(QuoteMessageText); get_attributes().setAttribute('command', 'quote'); get_attributes().setAttribute('arg', id);
            set_imageUrl(menuImgURL + 'menuQuote.gif');
            if (canReply && (!isLocked || isMod) && !isDeleted && !isPostWaitingModeration) { show(); oneItemVisible = true; } else { hide(); }           
        } 
        
        with (multiquoteitem) {
	        set_text(MultiquoteText); get_attributes().setAttribute('command', 'multiquote'); get_attributes().setAttribute('arg', id);
	        set_imageUrl(menuImgURL + 'menuMultiQuote.gif');
	        if (!isDeleted && !viewerIsGuest && canReply) { show(); oneItemVisible = true; } else { hide(); }         
	    }

	    if (oneItemVisible) menuShow(e, menu, theTarget);
	    
	}	

	function showMoreOptionMenu(e, id, isMod, isThreadStarter, isSelf, isDeleted, isCashReward, isAnswered, CanFlagPost, 
	        isThread, isHelpfulPost, isRewardedPost, CanRatePost, canReply, viewerIsGuest, canDelete, canDeleteThread,
	        canStillEditDelete, msgnum, ip, isPostWaitingModeration, isBanAllowed, theTarget) {
	    if (menuFired || typeof menu == 'undefined' || !menu) return;
	    
	    hideAllMenus(180);
	    
	    SetMessageID(id);
	    
	    with(menu){
            
            var edititem = findItemByValue("edit");
            var manageitem = findItemByValue("manage");	
            var fwditem = findItemByValue("fwd");

            var helpfulitem = findItemByValue("helpful");
            var unhelpfulitem = findItemByValue("unhelpful");
            var rewarditem = findItemByValue("reward");
            var rateitem = findItemByValue("rate");
            var flagitem = findItemByValue("flag");
            var reportitem = findItemByValue("report");	    
	        var banitem = findItemByValue("ban");	
	        
	        var ipitem = findItemByValue("ip");	        
	        var msglinkitem = findItemByValue("msglnk");	
	    }

	    var menuImgURL = clientScriptPathInfo.ApplicationPath + '/' + pageThemeImageURL;
	    
        with (edititem){
            set_text(EditMessageText); get_attributes().setAttribute('command', 'edit'); get_attributes().setAttribute('arg', id);
            set_imageUrl(menuImgURL + 'menuEdit.gif');
	        if (isMod || (isSelf && canStillEditDelete) && !viewerIsGuest){show();} else {hide();} 
        }
        
        with (manageitem){
            set_text(ManageMessageText); get_attributes().setAttribute('command', 'manage'); get_attributes().setAttribute('arg', id);
            set_imageUrl(menuImgURL + 'menuManage.gif');
            if (isMod || (isSelf && canStillEditDelete && (canDelete && id!=currentThreadID || canDeleteThread && id==currentThreadID)) && !viewerIsGuest){show();} else {hide();} 
        }
        
        with (fwditem){
            set_text(ForwardMessageText); get_attributes().setAttribute('command', 'fwd'); get_attributes().setAttribute('arg', id);
            set_imageUrl(menuImgURL + 'menuForward.gif');
            if (isDeleted || viewerIsGuest || isPostWaitingModeration) hide(); else show();
        }	    
	    
	    with (helpfulitem) {
	        set_text(PostHelpfulText); 
	        set_imageUrl(menuImgURL + 'menuHelpful.gif');
	        
	        menu.trackChanges();
	        get_attributes().setAttribute('command', 'helpful'); get_attributes().setAttribute('arg', id);
	        if ((isMod || isThreadStarter) && !isPostWaitingModeration && !isDeleted && !isThread && !isHelpfulPost && !isRewardedPost && !viewerIsGuest){show();} else {hide();} 
	        menu.commitChanges();
	    }

	    with (unhelpfulitem) {
	        set_text(PostUnHelpfulText);
	        set_imageUrl(menuImgURL + 'menuHelpful.gif');

	        menu.trackChanges();
	        get_attributes().setAttribute('command', 'unhelpful'); get_attributes().setAttribute('arg', id);
	        if ((isMod || isThreadStarter) && !isPostWaitingModeration && !isDeleted && !isThread && isHelpfulPost && !isRewardedPost && !viewerIsGuest) { show(); } else { hide(); }
	        menu.commitChanges();
	    }	    
	    
	    with (rewarditem) {
	        set_text(PostGetRewardText); 
	        set_imageUrl(menuImgURL + 'menuAward.gif');
	        
	        menu.trackChanges();
	        get_attributes().setAttribute('command', 'reward'); get_attributes().setAttribute('arg', id);
	        if ((isMod || isThreadStarter) && !isPostWaitingModeration && !isDeleted && isCashReward && !isAnswered && !isThread && !isHelpfulPost && !isRewardedPost && !viewerIsGuest) { show(); } else { hide(); } 
	        menu.commitChanges();
	    }
	    
	    with (rateitem) {
	        set_text(RatingText); get_attributes().setAttribute('command', 'rate'); get_attributes().setAttribute('arg', id);
	        set_imageUrl(menuImgURL + 'menuRate.gif');
	        if (!isSelf && !isPostWaitingModeration && !isDeleted && CanRatePost && !viewerIsGuest) { show(); } else { hide(); } 
	    }	    	    
	    
	    with (flagitem) {
	        set_text(PostInappropriateText); get_attributes().setAttribute('command', 'flag'); get_attributes().setAttribute('arg', id);
	        set_imageUrl(menuImgURL + 'menuFlag.gif');
	        if (!isMod && CanFlagPost && !isPostWaitingModeration && !isDeleted && !isSelf && !viewerIsGuest) { show(); } else { hide(); } 
	    }
	    
	    with (reportitem) {
	        set_text(ReportAbuseText); get_attributes().setAttribute('command', 'report'); get_attributes().setAttribute('arg', id);
	        set_imageUrl(menuImgURL + 'menuReport.gif');
	        if (!isMod && !isPostWaitingModeration && !isDeleted && !isSelf && !viewerIsGuest) { show(); } else { hide(); }
	    }

	    with (banitem) {
	        set_text(TempBanText); get_attributes().setAttribute('command', 'ban'); get_attributes().setAttribute('arg', id);
	        set_imageUrl(menuImgURL + 'menuBan.gif');
	        if (isBanAllowed && !isDeleted && !isSelf) { show(); } else { hide(); }
	    }	    
	    
	    with (ipitem) {
	        set_text('IP: ' + ip); get_attributes().setAttribute('command', 'ip'); get_attributes().setAttribute('arg', ip);
	        //set_imageUrl(menuImgURL + 'menuFlag.gif');
	        if (isMod) {show();} else {hide();} 
	    }
	    
	    with (msglinkitem) {
	        set_text(menuMsgLinkText + ': #' + msgnum); get_attributes().setAttribute('command', 'msglink'); get_attributes().setAttribute('arg', id);
	        //set_imageUrl(menuImgURL + 'menuMultiQuote.gif');
	        if (!isPostWaitingModeration && !isDeleted) { show(); } else { hide(); }         
	    }

	    menuShow(e, menu, theTarget);
	    
	}

	function hideAllMenus(widthForImg){
	
	    if (typeof menu == 'undefined' || !menu) return;
        
        setNono(menu, widthForImg);
        
        for (var i = 0; i < menu.get_items().get_count(); i++)
        {
           var theItem = menu.get_items().getItem(i);
           if (theItem.get_value() != 'nono') theItem.hide();
        }

        menu.hide(); 

	}




// JScript File

    var RTEDialogLocation = clientScriptPathInfo.ApplicationPath + '/editor/';

    var RadEditor1ClientObject = null;
    var restorePoint = null;

    function OnEditorClientLoad(editor) {

        if (editor.GetHtml() == "&nbsp;" || escape(editor.GetHtml()) == '%A0') {
            editor.Document.body.innerHTML = (navigator.oscpu && document.getElementsByClassName) ? '<br/>' : '';
        }    
        
        document.writeln('<input type="hidden" id="ASPPG_baseRefURL" name="ASPPG_baseRefURL" value="' + clientScriptPathInfo.ForumDir + '">');
                
        var filter = editor.FiltersManager.GetFilterByName("FixUlBoldItalic");
        if (filter) filter.Enabled = false;

        RadEditor1ClientObject = editor;

               
        RadEditorCommandList["Insert an Image"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                editor.ShowDialog(
                    RTEDialogLocation + "image.aspx"
                    , null//argument
                    , 470
                    , 120
                    , InsertCustomImage
                    , null
                    , "Insert Image");
                    return false;
            };

        RadEditorCommandList["Insert a Link"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var link = editor.GetSelection().GetParentElement();                    
                var arg = link; //link.tagName == "A" ? link : null;
                                
                editor.ShowDialog(
                    RTEDialogLocation + "hyperlink.aspx"
                    , arg
                    , 470
                    , 150
                    , InsertCustomLink
                    , null
                    , "Insert Link");
                    return false;
            };


        RadEditorCommandList["Quote Original"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var quoteField = $get(quoteFieldClientID);
                if (quoteField.value != '') EditorPasteHtml(quoteField.value);
                quoteField.value = '';
                
            }; 
                
        RadEditorCommandList["Wrap [code] tag"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                EditorPasteHtml("[code]" + editor.GetSelectionHtml() + "[/code]");
                
            };  
                
        RadEditorCommandList["Wrap [quote] tag"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                EditorPasteHtml("[quote]" + editor.GetSelectionHtml() + "[/quote]");
                
            };
            
        RadEditorCommandList["Show PGDCodes"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var link = editor.GetSelection().GetParentElement();                    
                var arg = link; //link.tagName == "A" ? link : null;
                                
                editor.ShowDialog(
                    RTEDialogLocation + "custompgdcode.aspx"
                    , arg
                    , 470
                    , 450
                    , InsertCustomPGDCode
                    , null
                    , "Custom PGDCodes");
                    return false;
                };

        RadEditorCommandList["Show Smilies"] =
            function(commandName, editor, oTool) {
                restorePoint = editor.CreateRestorePoint();

                editor.ShowDialog(
                    RTEDialogLocation + "customsmiley.aspx"
                    , arg
                    , 470
                    , 450
                    , InsertSmiley
                    , null
                    , "Smilies");
                return false;
            };

    }
    
    function OnEditorClientInit(editor)
    {
        if (!window.opera) return; 
 
        editor.old_AttachEventHandler = editor.AttachEventHandler;    
        editor.AttachEventHandler = function(eventName, eventFn)
        {     
             if (eventName.indexOf("click") < 0)
             {
                this.old_AttachEventHandler(eventName, eventFn);     
             }                    
        }
    }
    

    function InsertQuotePrevious(){
        //if (restorePoint != null) restorePoint.Select();
        var quoteField = $get(quoteFieldClientID);
        if (quoteField.value != '') EditorPasteHtml(quoteField.value);
        quoteField.value = '';
    }

    function InsertMultiQuote() {
        //if (restorePoint != null) restorePoint.Select();
        var quoteField = $get(multiquoteFieldClientID);
        if (quoteField.value != '') EditorPasteHtml(quoteField.value);
        quoteField.value = '';
    }    
    
    function InsertCustomImage(returnValue)
    {
        //if (restorePoint != null) restorePoint.Select();
        if (typeof(returnValue)=="string" && returnValue!='')
        {
            EditorPasteHtml(returnValue);
        } 
    }

    function InsertCustomLink(returnValue) {

        //restorePoint = RadEditor1ClientObject.CreateRestorePoint();
        //if (restorePoint != null) restorePoint.Select();
        
        if (returnValue)
        {
            var selectionHTML = RadEditor1ClientObject.GetSelectionHtml();
            
            if (returnValue.text==""){
                if (selectionHTML=="") {
                    EditorPasteHtml("<a href=\"" + returnValue.url + "\">" + returnValue.url + "</a>");
                } else {
                    EditorPasteHtml("<a href=\"" + returnValue.url + "\">" + selectionHTML + "</a>");
                }
            
            } else {
                EditorPasteHtml("<a href=\"" + returnValue.url + "\">" + returnValue.text + "</a>");
            }
            
            
        }
    } 
    
    function InsertCustomPGDCode(returnValue) {

        //if (restorePoint != null) restorePoint.Select();
        
        if (returnValue)
        {
            var selectionHTML = RadEditor1ClientObject.GetSelectionHtml();
            EditorPasteHtml(returnValue.insertFront + selectionHTML + returnValue.insertBack);
        }
    }      
            
    function InsertSmiley(returnValue)
    {
        //if (restorePoint != null) restorePoint.Select();
        if (returnValue != "" && returnValue!= null)
        {
            EditorPasteHtml(returnValue);
        }
        return false;

    }

    function EditorPasteHtml(html) {
        var isSafari = /Safari/.test(navigator.userAgent);
        
        if (isSafari) {
            RadEditor1ClientObject.Document.execCommand('Cut', false, null);
        }

        RadEditor1ClientObject.PasteHtml(html);

    }




function ASPPGFormatMsgBody(msgID, enableImg, enableLink){
var msgArea = $get('msg' + msgID);
sbody = msgArea.innerHTML;
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(\/?(?:[bius]|[ou]l|hr|strike|pre|sub|sup))\]/gi,"<$1>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(?:align=)?(right|center|left)\]/gi,"<div align=\"$1\">");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[\/(?:right|center|left|align)\]/gi,"</div>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(\/)?\*\]/gi,"<$1li>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(\/?h[1-6]{1})\]/gi,"<$1>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(\/?h[1-6]{1} align\="\w+?")\]/gi,"<$1>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[quote(?:=([^\]]+))?\]/gi,"<blockquote class=\"quote\"><i>$1</i><br>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[\/quote\]/gi,"</blockquote>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(\/)?blockquote\]/gi,"<$1blockquote>");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(size|color)\=((?:&quot;|")\s?)?([\+\-\#\w]+?)\2\]/gi,"<font $1=\"$3\">");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[font\=((?:&quot;|")\s?)?([\w\s\,\-]+?)\1\]/gi,"<font face=\"$2\">");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[\/(?:font|size|color)\]/gi,"</font>");
if (!((false && !enableImg) || (true && !enableLink))) sbody = sbody.replace(/\[(url|link)\=(\&quot\;)?((?:ftp|https?)\:\/\/.+?)\2\](.+?)\[\/\1\]/gi,"<a href=\"$3\" target=\"_blank\" rel=\"nofollow\">$4</a>");
if (!((false && !enableImg) || (true && !enableLink))) sbody = sbody.replace(/\[(url|link)\=?\]((?:ftp|https?)\:\/\/.+?)\[\/\1\]/gi,"<a href=\"$2\" target=\"_blank\" rel=\"nofollow\">$2</a>");
if (!((false && !enableImg) || (true && !enableLink))) sbody = sbody.replace(/\[email\=(\&quot\;)?([\w\.]+\@[\w\-\.]+\.[a-zA-Z]{2,4})\1\](.+?)\[\/email\]/gi,"<a href=\"mailto:$2\">$3</a>");
if (!((true && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/\[(im(?:g|age))\]((?:https?\:\/\/)(?:[^\?])+?\.(?:jpg|gif|jpeg|bmp|png))\[\/\1\]/gi,"<img src=\"$2\">");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/ <br> \[(im(?:g|age))\](?:local\:\/\/(?:upfiles\/)?)([\-\w\.\/]+?)\[\/\1\]/gi,"");
if (!((false && !enableImg) || (false && !enableLink))) sbody = sbody.replace(/video\=http\:\/\/[a-z]{2,3}\.youtube\.com\/(?:watch\?v\=|v\/)([^\s]+)/gi,"<object width=\"425\" height=\"355\"><param name=\"movie\" value=\"http://www.youtube.com/v/$1&rel=1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/$1&rel=1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"355\"></embed></object>");
msgArea.innerHTML = sbody;
}


function ASPPGRestoreCodePGDCode(msgID, toReplace, replaceWith){
var msgArea = $get('msg' + msgID);
sbody = msgArea.innerHTML;
sbody = sbody.replace(toReplace, replaceWith.replace(/\$\'/gi, '$<span>\'</span>').replace(/\[code lang\=([a-z]{1,5})\]/gi, '<pre class="prettyprint lang-$1">').replace(/\[code\]/gi, '<pre class="prettyprint">').replace(/\[\/code\]/gi, '</pre>').replace(/\s?<br>\s?/gi, '\r\n'));
msgArea.innerHTML = sbody;
}


function ASPPGRestoreHTMLPGDCode(msgID, toReplace, replaceWith){
var msgArea = $get('msg' + msgID);
sbody = msgArea.innerHTML;
sbody = sbody.replace(toReplace, replaceWith.replace(/\$\'/gi, '$<span>\'</span>').replace(/\[(\/)?html\]/gi, '').replace(/\s?<br>\s?/gi, '\r\n').replace(/&lt;/gi, '<').replace(/&gt;/gi, '>').replace(/&quot;/gi, '"').replace(/&amp;/gi, '&'));
msgArea.innerHTML = sbody;
}




