/* Rev:$Revision: 137864 $ */

/*
 * Metadata - jQuery plugin for parsing metadata from elements
 *
 * Copyright (c) 2006 John Resig, Yehuda Katz, Jörn Zaefferer, Paul McLanahan
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.MetaData.js 2 2008-09-10 21:43:59Z diego.alto $
 *
 */

/**
 * Sets the type of metadata to use. Metadata is encoded in JSON, and each property
 * in the JSON will become a property of the element itself.
 *
 * There are three supported types of metadata storage:
 *
 *   attr:  Inside an attribute. The name parameter indicates *which* attribute.
 *          
 *   class: Inside the class attribute, wrapped in curly braces: { }
 *   
 *   elem:  Inside a child element (e.g. a script tag). The
 *          name parameter indicates *which* element.
 *          
 * The metadata for an element is loaded the first time the element is accessed via jQuery.
 *
 * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
 * matched by expr, then redefine the metadata type and run another $(expr) for other elements.
 * 
 * @name $.metadata.setType
 *
 * @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
 * @before $.metadata.setType("class")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from the class attribute
 * 
 * @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
 * @before $.metadata.setType("attr", "data")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from a "data" attribute
 * 
 * @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
 * @before $.metadata.setType("elem", "script")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from a nested script element
 * 
 * @param String type The encoding type
 * @param String name The name of the attribute to be used to get metadata (optional)
 * @cat Plugins/Metadata
 * @descr Sets the type of encoding to be used when loading metadata for the first time
 * @type undefined
 * @see metadata()
 */

(function($) {

$.extend({
	metadata : {
		defaults : {
			type: 'class',
			name: 'metadata',
			cre: /({.*})/,
			single: 'metadata'
		},
		setType: function( type, name ){
			this.defaults.type = type;
			this.defaults.name = name;
		},
		get: function( elem, opts ){
			var settings = $.extend({},this.defaults,opts);
			// check for empty string in single property
			if ( !settings.single.length ) settings.single = 'metadata';
			
			var data = $.data(elem, settings.single);
			// returned cached data if it already exists
			if ( data ) return data;
			
			data = "{}";
			
			if ( settings.type == "class" ) {
				var m = settings.cre.exec( elem.className );
				if ( m )
					data = m[1];
			} else if ( settings.type == "elem" ) {
				if( !elem.getElementsByTagName ) return;
				var e = elem.getElementsByTagName(settings.name);
				if ( e.length )
					data = $.trim(e[0].innerHTML);
			} else if ( elem.getAttribute != undefined ) {
				var attr = elem.getAttribute( settings.name );
				if ( attr )
					data = attr;
			}
			
			if ( data.indexOf( '{' ) <0 )
			data = "{" + data + "}";
			
			data = eval("(" + data + ")");
			
			$.data( elem, settings.single, data );
			return data;
		}
	}
});

/**
 * Returns the metadata object for the first member of the jQuery object.
 *
 * @name metadata
 * @descr Returns element's metadata object
 * @param Object opts An object contianing settings to override the defaults
 * @type jQuery
 * @cat Plugins/Metadata
 */
$.fn.metadata = function( opts ){
	return $.metadata.get( this[0], opts );
};

})(jQuery);
/*
 ### jQuery Star Rating Plugin v2.5 - 2008-09-10 ###
 * http://www.fyneworks.com/ - diego@fyneworks.com
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 ###
 Project: http://plugins.jquery.com/project/MultipleFriendlyStarRating
 Website: http://www.fyneworks.com/jquery/star-rating/
*//*
	Based on http://www.phpletter.com/Demo/Jquery-Star-Rating-Plugin/
 Original comments:
	This is hacked version of star rating created by <a href="http://php.scripts.psu.edu/rja171/widgets/rating.php">Ritesh Agrawal</a>
	It thansform a set of radio type input elements to star rating type and remain the radio element name and value,
	so could be integrated with your form. It acts as a normal radio button.
	modified by : Logan Cai (cailongqun[at]yahoo.com.cn)
*/

/*# AVOID COLLISIONS #*/
;if(window.jQuery) (function($){
/*# AVOID COLLISIONS #*/
	
	// default settings
	$.rating = {
		cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
		cancelValue: '',           // value to submit when user click the 'cancel' link
		split: 0,                  // split the star into how many parts?
		
		// Width of star image in case the plugin can't work it out. This can happen if
		// the jQuery.dimensions plugin is not available OR the image is hidden at installation
		starWidth: 16,
		
		//NB.: These don't need to be defined (can be undefined/null) so let's save some code!
		//half:     false,         // just a shortcut to settings.split = 2
		//required: false,         // disables the 'cancel' button so user can only select one of the specified values
		//readOnly: false,         // disable rating plugin interaction/ values cannot be changed
		//focus:    function(){},  // executed when stars are focused
		//blur:     function(){},  // executed when stars are focused
		//callback: function(){},  // executed when a star is clicked
		
		// required properties:
		groups: {},// allows multiple star ratings on one page
		event: {// plugin event handlers
			fill: function(n, el, settings, state){ // fill to the current mouse position.
				//if(window.console) console.log(['fill', $(el), $(el).prevAll('.star_group_'+n), arguments]);
				this.drain(n);
				$(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover'));
				// focus handler, as requested by focusdigital.co.uk
				var lnk = $(el).children('a'); val = lnk.text();
				if(settings.focus) settings.focus.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			},
			drain: function(n, el, settings) { // drain all the stars.
				//if(window.console) console.log(['drain', $(el), $(el).prevAll('.star_group_'+n), arguments]);
				$.rating.groups[n].valueElem.siblings('.star_group_'+n).removeClass('star_on').removeClass('star_hover');
			},
			reset: function(n, el, settings){ // Reset the stars to the default index.
				if(!$($.rating.groups[n].current).is('.cancel'))
					$($.rating.groups[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on');
				// blur handler, as requested by focusdigital.co.uk
				var lnk = $(el).children('a'); val = lnk.text();
				if(settings.blur) settings.blur.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			},
			click: function(n, el, settings){ // Selected a star or cancelled
				$.rating.groups[n].current = el;
				var lnk = $(el).children('a'); val = lnk.text();
				// Set value
				$.rating.groups[n].valueElem.val(val);
				// Update display
				$.rating.event.drain(n, el, settings);
				$.rating.event.reset(n, el, settings);
				// click callback, as requested here: http://plugins.jquery.com/node/1655
				if(settings.callback) settings.callback.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			}      
		}// plugin events
	};
	
	$.fn.rating = function(instanceSettings){
		if(this.length==0) return this; // quick fail
		
		instanceSettings = $.extend(
			{}/* new object */,
			$.rating/* global settings */,
			instanceSettings || {} /* just-in-time settings */
		);
		
		// loop through each matched element
		this.each(function(i){
			
			var settings = $.extend(
				{}/* new object */,
				instanceSettings || {} /* current call settings */,
				($.metadata? $(this).metadata(): ($.meta?$(this).data():null)) || {} /* metadata settings */
			);
			
			////if(window.console) console.log([this.name, settings.half, settings.split], '#');
			
			// Generate internal control ID
			// - ignore square brackets in element names
			var n = (this.name || 'unnamed-rating').replace(/\[|\]/, "_");
   
			// Grouping
			if(!$.rating.groups[n]) $.rating.groups[n] = {count: 0};
			i = $.rating.groups[n].count; $.rating.groups[n].count++;
			
			// Accept readOnly setting from 'disabled' property
			$.rating.groups[n].readOnly = $.rating.groups[n].readOnly || settings.readOnly || $(this).attr('disabled');
			
			// Things to do with the first element...
			if(i == 0){
				// Create value element (disabled if readOnly)
				$.rating.groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '/>');
				// Insert value element into form
				$(this).before($.rating.groups[n].valueElem);
				
				if($.rating.groups[n].readOnly || settings.required){
					// DO NOT display 'cancel' button
				}
				else{
					// Display 'cancel' button
					/*
					$(this).before(
						$('<div class="cancel"><a title="' + settings.cancel + '">' + settings.cancelValue + '</a></div>')
						.mouseover(function(){ $.rating.event.drain(n, this, settings); $(this).addClass('star_on'); })
						.mouseout(function(){ $.rating.event.reset(n, this, settings); $(this).removeClass('star_on'); })
						.click(function(){ $.rating.event.click(n, this, settings); })
					);
					*/
				}
			}; // if (i == 0) (first element)
			
			// insert rating option right after preview element
			eStar = $('<div class="star"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
			$(this).after(eStar);
			
			// Half-stars?
			if(settings.half) settings.split = 2;
			
			// Prepare division settings
			if(typeof settings.split=='number' && settings.split>0){
				var stw = ($.fn.width ? $(eStar).width() : 0) || settings.starWidth;
				var spi = (i % settings.split), spw = Math.floor(stw/settings.split);
				$(eStar)
				// restrict star's width and hide overflow (already in CSS)
				.width(spw)
				// move the star left by using a negative margin
				// this is work-around to IE's stupid box model (position:relative doesn't work)
				.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' })
			};
			
			// Remember group name so controls within the same container don't get mixed up
			$(eStar).addClass('star_group_'+n);
			
			// readOnly?
			if($.rating.groups[n].readOnly)//{ //save a byte!
				// Mark star as readOnly so user can customize display
				$(eStar).addClass('star_readonly');
			//}  //save a byte!
			else//{ //save a byte!
				$(eStar)
				// Enable hover css effects
				.addClass('star_live')
				// Attach mouse events
				.mouseover(function(){ $.rating.event.drain(n, this, settings); $.rating.event.fill(n, this, settings, 'hover'); })
				.mouseout(function(){ $.rating.event.drain(n, this, settings); $.rating.event.reset(n, this, settings); })
				.click(function(){ $.rating.event.click(n, this, settings); });
			//}; //save a byte!
			
			////if(window.console) console.log(['###', n, this.checked, $.rating.groups[n].initial]);
			if(this.checked) $.rating.groups[n].current = eStar;
			
			//remove this checkbox
			$(this).remove();
			
			// reset display if last element
			if(i + 1 == this.length) $.rating.event.reset(n, this, settings);
		
		}); // each element
			
		// initialize groups...
		for(n in $.rating.groups)//{ not needed, save a byte!
			(function(c, v, n){ if(!c) return;
				$.rating.event.fill(n, c, instanceSettings || {}, 'on');
				$(v).val($(c).children('a').text());
			})
			($.rating.groups[n].current, $.rating.groups[n].valueElem, n);
		//}; not needed, save a byte!
		
		return this; // don't break the chain...
	};
	
	
	
	/*
		### Default implementation ###
		The plugin will attach itself to file inputs
		with the class 'multi' when the page loads
	*/
	$(function(){ $('input[@type=radio].star').rating(); });
	
	
	
/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/

/*merged*/






//End of dynaboards.api.js





//var webSvc="http://localhost:8080/";
var webSvc="/";
var ajaxPage="/news/ajaxPage.jsp";
var webSvcComment=webSvc+"api/articleComment";
var webSvcReport=webSvc+"api/report";
var webSvcReportPhoto=webSvc+"api/reportPhoto";
var webSvcRating=webSvc+"api/rating";
var webSvcView = webSvc + "api/viewCount";
var loadurl = "http://o.aolcdn.com/art/ch_sports/cmntyloading.gif";
var total_comments_shown = 25;
var _sns_isLoggedIn = 0;

var txtDefault = "Type your comment here";
var isProfileOn = 0;//was 1 changed by brendan

$(document).ready(function(){
    //if(_sns_isLoggedIn == 1 && getCookie("RSP_DAEMON")==null)
    //	window.location = "http://my.screenname.aol.com/_cqr/login/login.psp?sitedomain=fanhouse.com&errorIfUnauth=1&siteState=" + encodeURIComponent("OrigUrl="+encodeURIComponent(window.location));
    
    // this sets up every star rating link to have an onclick handler
    $('.star_live > a').click(brd.ratinghandler);
    
    if (typeof(tid) != "undefined" && typeof(bid) != "undefined" && typeof(bpid) != "undefined") 
        brd.updateView(tid, bid, bpid);
        
    //brd.replaceImg();   
    
    //$('.cmntBoxtxtarea textarea').focus(brd.snsPopup());
    $('.cmntBoxtxtarea textarea').click(function(){brd.snsPopup();});	

	$(".sortBy").hover(function(){
    $(".sortBy").click(function(){  $(".selectboxdd").show();});
    },function(){
      $(".selectboxdd").hide();
    });  

});


function GCPRegister() {
         var newUrl = "https://new.aol.com/productsweb/?promocode=827686";
         setTimeout(function() {window.location = newUrl;}, 0);
}

var brd = {
    element: "",
    id: "",
    sort: "",
    loadComments: function(t_id, b_id, bp_id, c_id, pc_id){
        chCmnt = $("#ch_" + c_id);
        chCmntAjax = $("#id_" + c_id + " .brdajax_response");
        if (chCmntAjax.length > 1) 
            chCmntAjax = $($(chCmntAjax)[0]);
        chCmntAjax.html("");
        this.element = chCmnt;
        
        if (typeof(chCmnt) != "undefined" && chCmnt.length > 0) {
            if (jQuery.trim(chCmnt.html()) == "") {
                chCmnt.css({
                    display: "none"
                });
                chCmnt.html("<img src=\"" + loadurl + "\"/>");
                this.toggleChild(c_id, "#ch_");
		    $.ajax({
           		type: "POST",
           		url:ajaxPage,
           		data: {
           			"tId": t_id,
                    	"pId": c_id,
                    	"bId": b_id,
                    	"bpId": bp_id,
                    	"page": "comments"
           		},
            	success: function(xml){
				brd.element.css({
                        	display: "none"
                    	});
                    	brd.element.html(xml);
                    	$('input[@type=radio].star').rating();
                    	$('.star_live > a').click(brd.ratinghandler);
                    	brd.element.fadeIn(1500).css({
                        	display: "block"
                    	});
            	}
        	    });
			
            }
            else {
                this.toggleChild(c_id, "#ch_");
            }
            
        }
        
    },
    
    ajaxCall: function(url, t_id, p_id){
        $.get(url, {
            tid: t_id,
            pid: p_id,
            page: 'comments'
        }, function(xml){
            brd.element.css({
                display: "none"
            });
            brd.element.html(xml);
            brd.element.fadeIn(1500).css({
                display: "block"
            });
        });
    },
    
    loadCmntBox: function(t_id, b_id, bp_id, c_id, c_name, c_l, ttle){
		if ($("#rply_" + c_id + " .cmntBoxNewPos")) { $("#rply_" + c_id + " .cmntBoxNewPos").remove();}
		$("#rply_" + c_id + " .cmntBoxPos").css({display: "block"});
        chCmnt = $("#id_" + c_id + " .brdinline_reply");
        if (chCmnt.length > 1) 
            this.element = $($(chCmnt)[0]);
        else 
            this.element = chCmnt;
        if (jQuery.trim(this.element.html()) == "") {
            this.element.html("<img src=\"" + loadurl + "\"/>");

		$.ajax({
           		type: "POST",
           		url:ajaxPage,
           		data: {
           			"tId": t_id,
                		"bId": b_id,
                		"bpId": bp_id,
                		"cId": c_id,
                		"cName": c_name,
                		"cL": c_l,
                		"tName": ttle,
                		"page": "textblock"
           		},
            	success: function(xml){
                		brd.element.css({
                   		display: "none"
                		});
                		brd.element.html(xml);
                		brd.element.fadeIn(1500).css({
                    		display: "block"
                		});
                		$('.cmntBoxtxtarea textarea').click(function(){brd.snsPopup();});
            	}
        	});	
            
        }
    },
    
    cmntDisplayUdt: function(action, pid){
        chCmnt = $("#ch_" + pid + "");
        icon = $("#pr_" + pid + " .brdhidePostAction");
        replycount = $("#pr_" + pid + " .brdreplyCount");
        this.element = chCmnt;
        
        if (action == "collapse") {
            this.hideChldrn(chCmnt, replycount, icon);
        }
        else {
            this.showChldrn(cchCmnt, replycount, icon);
        }
        
    },
    
    toggleChild: function(id, pre){
        icon = $("#id_" + id + " .brdhidePostAction");
        replycount = $("#id_" + id + " .brdreplyCount");
        
        cmChldEl = $(pre + id);
        this.element = cmChldEl;
        if (cmChldEl.length > 0) {
            if (cmChldEl.css("display") == "block") {
                this.hideChldrn(cmChldEl, replycount, icon);
            }
            else {
                this.showChldrn(cmChldEl, replycount, icon);
            }
        }
    },
    
    hideChldrn: function(cmChldEl, replycount, icon){
        if (typeof(cmChldEl) != "undefined") 
            cmChldEl.css({
                display: "none"
            });
        if (typeof(replycount) != "undefined") 
            replycount.css({
                display: "inline"
            });
        if (typeof(icon) != "undefined") {
            icon.removeClass('brdexpanded');
            icon.addClass('brdcollapsed');
        }
    },
    
    showChldrn: function(cmChldEl, replycount, icon){
        if (typeof(cmChldEl) != "undefined") 
            cmChldEl.fadeIn(1500).css({
                display: "block"
            });
        if (typeof(replycount) != "undefined") 
            replycount.css({
                display: "none"
            });
        if (typeof(icon) != "undefined") {
            icon.removeClass('brdcollapsed');
            icon.addClass('brdexpanded');
        }
    },
    
    newCap: function(eId, lnge, tid, tttl, bid, bpid, id, cid, sort){
        capEl = $(".cap_" + eId);
        this.element = capEl;
	  $.ajax({
           type: "POST",
           url:ajaxPage,
           data: {
           "page": "captcha"
           },
            success: function(xml){
			brd.element.html(xml);
			$(".cap_" + eId +" "+".capForm input:text").keypress(function (e) {
				if(e.keyCode == 13){
					brd.postCmnt(eId, lnge, tid, tttl, bid, bpid, id, cid, sort);
				}
			});
			
            }
        });
    },
    
    postCmnt: function(pnt, lnge, tid, tttl, bid, bpid, id, cid, sort){
    if (_sns_isLoggedIn == 1) {
        this.sort = sort;
        cEl = $("#rply_" + id);

        if (cEl.length > 0) {
            cmntSbj = $("#rply_" + id + " input[name='commentSubject']").val();
            capguess = $("#rply_" + id + " input[name='captchaguess']").val();
            capref = $("#rply_" + id + " input[name='captchareference']").val();
            //cmnt = tinyMCE.get("id_comment_text_" + id).getContent();
            //cmnt = $("#id_comment_text_"+ id +"IFrame").contents().find("body").html();
            cmnt = $("#id_comment_text_"+ id ).val();
	        cmnt = html2bbcode(cmnt);
            cmnt = cmnt.replace(/\&nbsp\;/g,"");
            if (cmnt != "" && cmnt != txtDefault) {
                this.id = id;
                //cmnt = tinyMCE.get("id_comment_text_" + id).getContent();
                this.element = $("#id_" + id + " .brdajax_response");
                if (typeof(cmntSbj) == "undefined") 
                    cmntSbj = "";
                if (typeof(capguess) == "undefined") 
                    capguess = "";
                if (typeof(capref) == "undefined") 
                    capref = "";
                $.ajax({
                    type: "POST",
                    url: webSvcComment,
			  contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    data: {
                        parent: pnt,
                        lineage: lnge,
                        topicId: tid,
                        topicTitle: tttl,
                        boardId: bid,
                        boardParentId: bpid,
                        captchaguess: capguess,
                        captchareference: capref,
                        commentSubject: cmntSbj,
                        comment: cmnt,
                        channelId: cid,
                        topicPermaLink: turl
                    },
                    success: function(msg){
                        brd.formatCmnt(msg);
                        brd.replaceImg();
                        brd.cnclCmnt("");
                        CmntPostCallBack();
                    },
                    error: function(msg){
                        elmt = $("#rply_" + brd.id + " .cmntBoxError");
                        if (msg.responseText.indexOf("Incorrect captcha.") > 0) {
                            //alert( "error: " + );
                            elmt.html("Code validation failed. Please try again.");
                        }
                        else if (msg.responseText.indexOf("user is blocked") >= 0) {
                            elmt.html("You have been blocked from posting comments.");
                        }
                        else {
                            alert( "error: " + msg.responseText ); 
                            elmt.html("Error. Please try again.");
                        }
                        elmt.fadeIn(1500).css({
                            display: "block"
                        });
                        //setTimeout('elmt.fadeOut(1500);', 5000);
                        //setTimeout('elmt.html("")', 7500);
                    }
                });
                
            } else {
            	elmt = $("#rply_" + id + " .cmntBoxError");
            	elmt.html("Please type in a comment.");
            	elmt.fadeIn(1500).css({display: "block"});
            }
            
        	}
        }
        else {
            elmt = $("#rply_" + id + " .cmntPostBox")
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            toggleLayer('anchorImg', 'loginLayer', elmt.offset().left, elmt.offset().top, lu);
            //brd.loginPop(event);
        }
    },
    
    postCmnt2: function(pnt, lnge, tid, tttl, bid, bpid, id, cid, sort){
        if (_sns_isLoggedIn == 1) {
	        this.sort = sort;
	        cEl = $("#rply_" + id);
	        if (cEl.length > 0) {
	            cmnt = $("#id_comment_text_"+ id ).val();
	            //cmnt = $("#id_comment_text_"+ id +"IFrame").contents().find("body").html();
	            cmnt = html2bbcode(cmnt);
	            //cmnt = tinyMCE.get("id_comment_text_" + id).getContent();
            	cmnt = cmnt.replace(/\&nbsp\;/g,"");
            	if (cmnt != "" && cmnt != txtDefault) {
					$("#rply_" + id + " .cmntBoxCap").after("<div class=\"cmntBoxNewPos\">"+$("#rply_" + id + " .cmntBoxPos").html()+"</div>");
					$("#rply_" + id + " .cmntBoxPos").css({display: "none"});
            		$("#rply_" + id + " .cmntBoxtxtarea").fadeOut();
	            	$("#rply_" + id + " .cmntBoxError").fadeOut();
	            	$("#rply_" + id + " .cmntPost2Box").fadeOut();
	            	$("#rply_" + id + " .cmntResetBox").fadeOut();
	            	
		            $("#rply_" + id + " .cmntBoxCap").fadeIn(1500).css({display: "block"});
		            $("#rply_" + id + " .cmntPostBox").fadeIn(1500).css({display: "block"});

	            } else {
	            	elmt = $("#rply_" + id + " .cmntBoxError");
	            	elmt.html("Please type in a comment.");
	            	elmt.fadeIn(1500).css({display: "block"});
	            }
	        }
        } else {
            elmt = $("#rply_" + id + " .cmntPost2Box")
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            toggleLayer('anchorImg', 'loginLayer', elmt.offset().left, elmt.offset().top, lu);
            //brd.loginPop(event);
        }
    },
    
    cnclCmnt: function(id){
        if (id != null && id != "") {
            chCmnt = $("#id_" + id + " .brdinline_reply").fadeOut(1500);
            chCmnt.html("");
        }
        else {
            //tinyMCE.get("id_comment_text_" + id).setContent("Type your comment here");
            //$("#id_comment_text_"+ id +"IFrame").contents().find("body").html(txtDefault);
            $("#id_comment_text_"+ id ).val(txtDefault);
            $("#rply_" + id + " input[name='captchaguess']").val("");
            $("#rply_" + id + " .cmntBoxtxtarea").fadeIn(1500).css({display: "block"});
	        $("#rply_" + id + " .cmntPost2Box").fadeIn(1500).css({display: "block"});
	        $("#rply_" + id + " .cmntResetBox").fadeIn(1500).css({display: "block"});
	        
	        $("#rply_" + id + " .cmntBoxError").fadeOut();
		    $("#rply_" + id + " .cmntBoxCap").fadeOut();
			if ($("#rply_" + id + " .cmntBoxNewPos")) { $("#rply_" + id + " .cmntBoxNewPos").remove();}
			$("#rply_" + id + " .cmntBoxPos").css({display: "block"});
		    if($("#rply_" + id + " .cmntPost2Box").length == 1)
		    	$("#rply_" + id + " .cmntPostBox").fadeOut();
        }
    },
    
    resetCmnt: function(id){
		$("#id_comment_text_"+ id ).val(txtDefault);
		//$("#id_comment_text_"+ id +"IFrame").contents().find("body").html(txtDefault);
		$("#rply_" + id + " input[name='captchaguess']").val("");
    },
    
    formatCmnt: function(data){
        if (typeof(data) == "string") 
            jdata = eval('(' + data + ')');
        else 
            jdata = data;
        if (this.id == "") {
            elmt = $("#brdFirst");
            if (elmt.length > 0) {
                old = elmt.html();
                elmt.html(this.buildHTML(jdata, false) + old);
                $('input[@type=radio].star').rating();
            	$('.star_live > a').click(brd.ratinghandler);
                elmt.fadeIn(1500).css({
                    display: "block"
                });
            }
            else {
                elmt = $("#brdLast");
                if (elmt.length > 0) {
                    old = elmt.html();
                    elmt.html(old + this.buildHTML(jdata, false));
                    $('input[@type=radio].star').rating();
            		$('.star_live > a').click(brd.ratinghandler);
                    elmt.fadeIn(1500).css({
                        display: "block"
                    });
                }
            }
            brd.refreshBox(jdata["topicId"], jdata["boardId"], jdata["boardParentId"],jdata["topicTitle"]);
        }
        else {
            elmt = $("#id_" + this.id + " .brdinline_reply");
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            elmt.css({
                display: "none"
            });
            elmt.html("<div class=\"cmntThanks\">Your Post has been made.</div>");
            if (this.element.length > 1) 
                this.element = $($(this.element)[this.element.length - 1]);
            this.element.html(this.buildHTML(jdata, true));
            $('input[@type=radio].star').rating();
            $('.star_live > a').click(brd.ratinghandler);
            elmt.fadeIn(1500).css({
                display: "block"
            });
            this.id = "";
            setTimeout('elmt.fadeOut(1500);', 5000);
            setTimeout('elmt.html("")', 6500);
        }
    },


    report: function(id, event, cid, assetType){
        if (_sns_isLoggedIn == 1) {
            elmt = $("#id_" + id + " .brdreport")
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            elmt.html("<span class=\"cmntyRprtd\"></span>");
            //elmt.removeClass("brdreport");
            //Make the Ajax call                 
            $.post(webSvcReport, {
                id: id,
                type: assetType,
                channelId: cid
            }, function(){
                //alert('Your data has been saved.');
            });
            
            var cookieName = "rpts";
            var cookie = getCookie(cookieName);
            if (cookie != null) {
                cookie = cookie + "&" + id;
            }
            else {
                cookie = id;
            }
            setCookie(cookieName, cookie, 7);
        }
        else {
            elmt = $("#id_" + id + " .brdreport")
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            toggleLayer('anchorImg', 'loginLayer', elmt.offset().left, elmt.offset().top, lu);
            //brd.loginPop(event);
        }
    },
    reportProfile: function(cid){
		var id=$("#profileId").val();
        //if (_sns_isLoggedIn == 1) {
            //Make the Ajax call                 
            $.post(webSvcReport, {
                id: id,
                type: 'profile',
                channelId: cid
            }, function(){
				$("#reportAnchor").html("reported")[0].removeAttribute("href");
                //alert('Your data has been saved.');
            });
            
            var cookieName = "rpts";
            var cookie = getCookie(cookieName);
            if (cookie != null) {
                cookie = cookie + "&" + id;
            }
            else {
                cookie = id;
            }
            setCookie(cookieName, cookie, 7);
       /* }
        else {
            elmt = $("#id_" + id + " .brdreport")
            if (elmt.length > 1) 
                elmt = $($(elmt)[0]);
            toggleLayer('anchorImg', 'loginLayer', this.offsetLeft, elmt.position().top, lu);
        }*/
    },
    
    ratinghandler: function(){
        // postRating:function(this,tId,Id,bId, bPId, cnt, avg,cId){
        if (_sns_isLoggedIn == 1) {
            var rating = $(this).attr('title');
            var strVal = $(this).parents('div').parents('div').attr('class').split("_");
            var id = strVal[0];
            var topicId = strVal[3];
            var count = strVal[1];
            var avgRating = strVal[2];
            var cid = strVal[4];
            // set cookie
            var cookieName = "rted";
            
            var cookie = getCookie(cookieName);
            if (cookie != null) {
                cookie = cookie + "&" + id;
            }
            else {
                cookie = id;
            }
            setCookie(cookieName, cookie, 7);
            
            //$('#cmt_stars_' +id).load(webSvcReport, {rating: rating, id:id, avgRating:avgRating,count:count, topicId:topicId});
            brd.id = id;
            $.ajax({
                type: "POST",
                url: webSvcRating,
                data: {
                    rating: rating,
                    id: id,
                    avgRating: avgRating,
                    count: count,
                    topicId: topicId,
                    channelId: cid,
                    topicTitle: tttl,
                    boardId: bid,
                    boardParentId: bpid,
                    topicPermaLink: turl
                },
                success: function(msg){
                    brd.rateCallBack(msg);
                },
                error: function(msg){
                
                }
            });
        }
        else {
            toggleLayer('anchorImg', 'loginLayer', this.offsetLeft, this.offsetTop+10, lu);
        }
    },
    
    rateCallBack: function(data){
        elmt = $('#id_' + this.id + ' .brdrating');
        if (elmt.length > 1) 
            elmt = $($(elmt)[0]);
        elmt.html(data);
        this.id = "";
    },
    
    ratePop: function(show, id){
        elmt = $('#id_' + id + ' .brdratingPop');
        if (elmt.length > 1)
            elmt = $($(elmt)[0]);
        if (show == 1) {
            elmt.css({
                display: "block"
            });
        }
        else {
            elmt.css({
                display: "none"
            });
        }
    },
    
    updateView: function(tid, bid, bpid){
        $.ajax({
            type: "POST",
            url: webSvcView,
            data: {
                tId: tid,
                bId: bid,
                bpId: bpid
            },
            success: function(msg){
                //brd.rateCallBack(msg);
                //alert("success");
            },
            error: function(msg){
            
            }
        });
    },
    
    loginPop: function(e)
	{
          e = e || window.event;
           var cursor = {x:0, y:0};
           if (e.pageX || e.pageY) {
                 cursor.x = e.pageX;
                 cursor.y = e.pageY;
           } 
          else {
              var de = document.documentElement;
              var b = document.body;
              cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
              cursor.y = e.clientY +  (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
           }
		toggleLayer('anchorImg','loginLayer',cursor.x,cursor.y,lu);	
	},
	
	dropDown : function(){
	
	},
	
	sortSelect : function(sort){
		if(location.toString().indexOf("sort=") > 0)
			location = location.toString().replace(/sort=\d/,"sort="+sort).replace(/.pg=\d/,"").replace(/\#.*/g,"")+"#cmtyComment";
		else if(location.toString().indexOf("?") > 0)
			location = location.href.replace(/\#.*/g,"") + "&sort=" + sort +"#cmtyComment";
		else location = location.href.replace(/\#.*/g,"") + "?sort=" + sort +"#cmtyComment";
	},
    
    refreshBox : function(t_id, b_id, bp_id, ttle){
        chCmnt = $(".cmntMain");
        if (chCmnt.length > 1) 
            this.element = $($(chCmnt)[0]);
        else 
            this.element = chCmnt;
        if (this.element.length == 1) {
		$.ajax({
           		type: "POST",
           		url:ajaxPage,
           		data: {
           			"tId": t_id,
                		"bId": b_id,
                		"bpId": bp_id,
                		"cId": "",
                		"cName": "",
                		"cL": "",
                		"tName": ttle,
                		"page": "textblock"
           		},
            	success: function(xml){
					
                		brd.element.css({
                    		display: "none"
                		});
                		brd.element.html(xml);
                		brd.element.fadeIn(1500).css({
                   		 display: "block"
                		});
            	}
        	});
            
        }
    },
    
    toggleTopic : function(id) {
    	elmt = $("#id_" + id + " .cmtyPost .brdtext");
    	
    	if(elmt.css("display") == "block"){
    		elmt.fadeOut();
    		$("#id_" + id + " .cmtyPost .brdhidePostAction").removeClass('brdShow');
    		$("#id_" + id + " .cmtyPost .brdhidePostAction").addClass('brdcollapsed');
    		$("#id_" + id + " .cmtyPost .brdhide").html("SHOW POST");
    	} else {
    		elmt.fadeIn(1500).css({display: "block"});
    		$("#id_" + id + " .cmtyPost .brdhidePostAction").removeClass('brdcollapsed');
    		$("#id_" + id + " .cmtyPost .brdhidePostAction").addClass('brdShow');
    		$("#id_" + id + " .cmtyPost .brdhide").html("HIDE POST");
    	}
    }, 
    
    replaceImg : function () {
        for (var i=0; i<document.images.length; i++){
	    img = new Image();
	    img.src = document.images[i].src;
	    if (img.height == 0)
	      document.images[i].src = 'http://o.aolcdn.com/art/ch_sports/img_noimgv1.gif';
	  	}
    },
    buildHTML : function(jdata, flg){
        htmlappend = "<div id=\"id_" + jdata["id"] + "\" class=\"brdcontent ";
        if (flg) 
            htmlappend += "brdlevel1 ";
        htmlappend += jdata["lineage"] + "\">";
        htmlappend += "<div class=\"brdimg\">";
		if(isProfileOn == 1)
			htmlappend += "<a href=\"/profiles/" + jdata["hashedUserId"] + "\"><img src=\"" + jdata["avatar"] + "\"/></a>";
		htmlappend += "</div>";
		htmlappend += "<div class=\"brdDisName\">";
		if(isProfileOn == 1)
			htmlappend += "<a href=\"/profiles/" +  jdata["hashedUserId"] + "\">" + jdata["displayName"] + "</a>";
		else 
			htmlappend += jdata["displayName"];
		htmlappend += "<div class=\"brdtime\">" + jdata["timeStamp"] + "</div>";
		htmlappend += "</div>";
        htmlappend += "<div class=\"brdtext\">" + jdata["body"] + "</div>";
        htmlappend += "<div class=\"brdaction\">";
        htmlappend += "<span class=\"brdreport\">";
        htmlappend += "<a href=\"javascript:\" onmousedown=\"javascript:brd.report('" + jdata["id"] + "');\" class=\"cmntyReport\" id=\"" + jdata["id"] + "\">&nbsp;</a>";
        htmlappend += "</span>";
		htmlappend += "<span onclick=\"javascript:brd.loadCmntBox('" + jdata["topicId"] + "','" + jdata["boardId"] + "','" + jdata["boardParentId"] + "','" + jdata["id"] + "','" + jdata["displayName"] + "','" + jdata["lineage"] + "','" + jdata["topicTitle"] + "');\" class=\"brdreply\"><a href=\"javascript:;\">Reply</a></span>";
        htmlappend += "<span class=\"brdrating\"><span onmouseover=\"brd.ratePop(1,'" + jdata["id"] + "');\" onmouseout=\"brd.ratePop(0,'" + jdata["id"] + "');\" class=\"brdratinglbl\">Rate This Comment</span>";
        htmlappend += "<div class=\"" + jdata["id"] + "_0_0.0_" + jdata["topicId"] + "_" + jdata["channelId"] + "\">";
        htmlappend += "<span class=\"brdstars\">";
        for (x = 1; x <= 10; x++) 
            htmlappend += "<input class=\"star {split:2}\" type=\"radio\" name=\"" + jdata["id"] + "\" value=\"" + (x / 2) + "\" />";
        htmlappend += "</span></div><span class=\"brdratingPop\">(0 RATINGS)</span></span>";
        htmlappend += "</div><div class=\"brdinline_reply\"/>";
        htmlappend += "<div id=\"ch_" + jdata["id"] + "\" class=\"brdreplies\"/>";
        htmlappend += "<div class=\"brdajax_response\"/>";
        htmlappend += "</div>";
        return htmlappend;
    },
    snsPopup : function() { 
			if(_sns_isLoggedIn == 1) { 
	   			if ($(this).val() == "Type your comment here")
					$(this).val("");
			} else {
			       //elmt = $(this);
			       elmt = $('.cmntBoxtxtarea textarea');
			       //if(elmt.length > 1) elmt=$($(elmt)[0]);
			          toggleLayer('anchorImg', 'loginLayer', elmt.offset().left, elmt.offset().top, lu);
			          //brd.loginPop(event);
			      } 
				//ed.windowManager.alert('User clicked the editor.');
    	//$(this).css('display','inline').fadeOut(1000);})
    }
    
};



$(function(){
    comment_toggle_handler = function(){
        comment = $($(this).parents('.comment')[0]);
        is_collapsed = comment.hasClass('collapsed')
        
        toggle_img = $(comment.find('.toggle img')[0]);
        replies = $(comment.find('.replies')[0]);
        if (is_collapsed) {
            replies.show();
            comment.removeClass('collapsed')
            toggle_img.attr('src', "http://o.aolcdn.com/propeller/images/thread-open.gif");
        }
        else {
            replies.hide();
            comment.addClass('collapsed');
            toggle_img.attr('src', "http://o.aolcdn.com/propeller/images/thread-closed.gif");
        }
        return false;
    };
    
    form_show_handler = function(){
        main = $($(this).parents('.addTopicMain')[0]);
        frm = $(main.find('.showHideFrm')[0]);
        is_hidden = frm.hasClass('hide');
        is_show = frm.hasClass('show');
        
        if (is_hidden) {
            frm.show();
            frm.removeClass('hide');
            frm.addClass('show');
        }
        if (is_show) {
            frm.hide();
            frm.removeClass('show');
            frm.addClass('hide');
        }
        return false;
    }
    
    /*$('.rating .rank').click(comment_rating_handler);
     $(".actions .reply").click(comment_reply_handler);*/
    $(".expand, .toggle").click(comment_toggle_handler);
    $(".addTopic").click(form_show_handler);
    
}); // end doc ready
//$(function(){$('input[@type=radio].brdstar').rating({ 
//	  callback: function(value, link){ 
//	    alert(value); 
//	} 
//	}); });





html2bbcode = function(s) {
	//s = tinymce.trim(s);

	function rep(re, str) {
		s = s.replace(re, str);
	};

	// example: <strong> to [b]
	rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
	rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
	rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
	rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
	rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
	rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
	//Start of Sophak's Hack
	rep(/<span style=\"font-family:(.*?);\">(.*?)<\/span>/gi,"[family=$1]$2[/family]");
	rep(/<span style=\"font-style: italic;\">(.*?)<\/span>/gi,"[i]$1[/i]");
	rep(/<span style=\"font-weight: bold;\">(.*?)<\/span>/gi,"[b]$1[/b]");
	rep(/<span style=\"text-decoration: underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
	rep(/<span style=\"(.*?)\">(.*?)<\/span>/gi,"[style=$1]$2[/style]");
	rep(/<big(.*?)>/gi,"[big]");
	rep(/<\/big>/gi,"[/big]");
	rep(/<small(.*?)>/gi,"[small]");
	rep(/<\/small>/gi,"[/small]");
	for(x=0;x<3;x++){
		rep(/<span class="Apple-style-span" style="font-weight: bold;">((?!<span).*?)<\/span>/gi,"[b]$1[/b]");
		rep(/<span class="Apple-style-span" style="text-decoration: underline;">((?!<span).*?)<\/span>/gi,"[u]$1[/u]");
		rep(/<span class="Apple-style-span" style="font-style: italic;">((?!<span).*?)<\/span>/gi,"[i]$1[/i]");
	}
	//End of Sophak's Hack
	rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
	rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
	rep(/<font>(.*?)<\/font>/gi,"$1");
	rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
	rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
	rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
	rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
	rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
	rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
	rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
	rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
	rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
	rep(/<\/(strong|b)>/gi,"[/b]");
	rep(/<(strong|b)>/gi,"[b]");
	rep(/<\/(em|i)>/gi,"[/i]");
	rep(/<(em|i)>/gi,"[i]");
	rep(/<\/u>/gi,"[/u]");
	rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
	rep(/<u>/gi,"[u]");
	rep(/<blockquote[^>]*>/gi,"[quote]");
	rep(/<\/blockquote>/gi,"[/quote]");
	rep(/<br \/>/gi,"\n");
	rep(/<br\/>/gi,"\n");
	rep(/<br>/gi,"\n");
	rep(/<p>/gi,"");
	rep(/<\/p>/gi,"\n");
	rep(/&nbsp;/gi," ");
	rep(/&quot;/gi,"\"");
	rep(/&lt;/gi,"<");
	rep(/&gt;/gi,">");
	rep(/&amp;/gi,"&");

	return s; 
		}

CmntPostCallBack = function(){
	// Please override this function for actions after a 	Success Comment Post.
	elmtCmt= $("#articleCmntHdr");
  	var str=elmtCmt.html();  
    	var splitStr=str.split(" ");
    	cmtCnt=parseInt(splitStr[2])+1;
    	elmtCmt.html("COMMENTS ( "+cmtCnt+" )");
       
       if(endpost==1){
                     
       window.location.hash="cmtyComment";
       }
}

/* Rev: $Revision: 137864 $ */
    
    var authLev = "1";
    var _sns_bg_color_ = "CFD9E3";
    var _sns_x_offset_ = 300;
    var _sns_y_offset_ = 0;
    var _sns_showSignInOutLinks_ = 0;
    var _sns_showByDef_ = 0;
    var _sns_set_var_ = 0;
    var _sns_var_ = "";
    var siteState = encodeURIComponent("OrigUrl="+encodeURIComponent(window.location));
    var loginCallBack = function(a){ _sns_isLoggedIn = a;}

