// isCommTab

jqN(document).ready(function() {
// Default State of the Comments


		setCommentView();


// The changing state of the comments.
	jqN('.user_comm, .post_comm').css('cursor', 'pointer');
	jqN('.user_comm').click(function() {
		setCommentView();
	});
	jqN('.post_comm').click(function() {
		setCommentPost();		
	});
	
	jqN('.shareThisPost').click(function() {
		if (jqN(this).parent().next('.jf_sharebx').css("display") == "none") {
				jqN(this).parent().next('.jf_sharebx').slideDown('fast');
		} else{
			jqN(this).parent().next('.jf_sharebx').slideToggle('fast');
		}
		jqN(this).toggleClass("makeOpc");
	});
	jqN('.linkValueTXT input').click(function() {
		this.select()
	})
	
	jqN("#you_news_recent").click(function(){
		jqN(this).addClass("ugcon");
		jqN("#you_news_popular").removeClass("ugcon");
		jqN(".most_popular_div").hide();
		jqN(".most_recent_div").show();
	});
	
	jqN("#you_news_popular").click(function(){
		jqN(this).addClass("ugcon");
		jqN("#you_news_recent").removeClass("ugcon");
		jqN(".most_recent_div").hide();
		jqN(".most_popular_div").show();		
	});
});

function send2FriendWebEx(obj)
{
    var arr_parts   = obj.id.split('_');
    var elem_num    = arr_parts[1];
    var prefix      = arr_parts[0];
    if (prefix.indexOf('MostPopular') != -1) {
        var appendThis = 'MostPopular';
    } else {
        var appendThis = '';
    }
    var email       = encodeURI(document.getElementById('email'+appendThis+'_'+elem_num).value); // get the senders email
    var friendemail = encodeURI(document.getElementById('friendemail'+appendThis+'_'+elem_num).value); // get the friends email
    var subject     = encodeURI(document.getElementById('subject'+appendThis+'_'+elem_num).value); // get the subject
    var message     = "Your friend knew you'd be dying to check out this latest info from NBC.com...\n";
    message         += document.getElementById('message'+appendThis+'_'+elem_num).value; // get the message
    var message     = escape(message); // get the message
    var url         = escape(document.getElementById('url'+appendThis+'_'+elem_num).value); // get the url
    var mediaName   = encodeURI(document.getElementById('mediaName'+appendThis+'_'+elem_num).value); // get the media name
    var mediaDesc   = encodeURI(document.getElementById('mediaDesc'+appendThis+'_'+elem_num).value); // get the media desc 
    var bool_email       = validateEmailLocal(email);
    var bool_friendemail = validateEmailLocal(friendemail);
    if (!bool_email) {
        // alert('Please enter a valid e-mail address for yourself.');
jqN('.socialNetworkLinks').after('<p class="email_alert">Please enter a valid e-mail address for yourself.</p>')
        document.getElementById('email'+appendThis+'_'+elem_num).focus();
setTimeout('jqN(".email_alert").fadeOut("slow",function() {jqN(this).remove()})', 3000);
        return false;
    }
    if (!bool_friendemail) {
        // alert("Please enter a valid friend's e-mail address.");
		jqN('.socialNetworkLinks').after("<p class=\"email_alert\">Please enter a valid friend's e-mail address.</p>")
		setTimeout('jqN(".email_alert").fadeOut("slow",function() {jqN(this).remove()})', 3000);

        document.getElementById('friendemail'+appendThis+'_'+elem_num).focus();
        return false;
    }

    // the 'mediaName' and 'mediaDesc' form the HTML form have the same values already
    // assigned to the 'message' variable, so go ahead and set 'mediaDesc' and 'mediaName'
    // to empty string as a workaround:
    mediaName = '';
    mediaDesc = '';
    jqN.get("/app/form_mail/send2friend.scet.php?email="+email+"&friendemail="+friendemail+"&subject="+subject+"&message="+message+"&url="+url+"&mediaName="+mediaName+"&mediaDesc="+mediaDesc, function(data) {
            confirmItLocal(elem_num,appendThis);
                  });
}

function confirmItLocal(iteration,appendThis)
{

    //
    document.getElementById('friendemail'+appendThis+'_'+iteration).value = '';
    jqN('.scet_send_confirmation'+appendThis+'_'+iteration).html("<h5>Your email was sent. Enter another email address to send again.</h5>");
setTimeout("jqN('.shareBox h6').remove().fadeOut('slow');", 3000);
}

function validateEmailLocal(value)
{
    var good = /^([\w\d\.\-_]+)@([\w\d\.\-]+)$/i;
    var evil =  /[^a-z0-9\@_\-\.]+/i;
        
    if (good.test(value) && !evil.test(value)) {
        return true;
    } else {
        return false;
    }
}

// jqN('#A-searchform input').hint();

function setCommentView (){
	jqN('.sn_comment_form_div').hide();
	jqN('.sn_comment_div').show();
	jqN('.post_comm').removeClass('isCommTab');
	jqN('.user_comm').addClass('isCommTab');
	jqN('.sn_comment_pager_div').show();
}
function setCommentPost (){
	jqN('.sn_comment_div').hide();
	jqN('.sn_comment_form_div').show();
	jqN('.user_comm').removeClass('isCommTab');
	jqN('.post_comm').addClass('isCommTab');
	jqN('.sn_comment_pager_div').hide();
}
function displayRating(id)
		{
			/*var curRating = nbcu.sn.rating.getRatingByContent(null, 'BLOG_POST-'+id, null, null,'SS_BLOG');

			var avg = curRating['avgRatingValue'];
			
			var rnd = Math.round(avg);
			var per = rnd*20;
			
			jqN("#"+id+" .current-rating").css({"width":per+"%"});
			jqN("#"+id+" .current-rating").html("Currently "+rnd+" out of 5 stars.");*/
			
			var result = nbcu.sn.rating.getRatingByContent(null, 'BLOG_POST-'+id, null, null, 'SS_BLOG');
			/*alert("Avg Rating value: " + result["avgRatingValue"] + " | Rating count: " + result["ratingCount"]);*/
			
			var avg = result['avgRatingValue'];
			
			var rnd = Math.round(avg);
			var per = rnd*20;
			
			jqN("#"+id+" .current-rating").css({"width":per+"%"});
			jqN("#"+id+" .current-rating").html("Currently "+rnd+" out of 5 stars.");
			
		}

  