 jQuery(document).ready(function() {
 jQuery(jQuery("#blogCommentStart")).click(function(){
 	//jQuery("#blogCommentsBox").style.visibility = "visible";
 });
jQuery(jQuery("form#submitcomment")).submit(function(){
		jQuery.ajax({
			type: "POST",
			url: document.forms['submitcomment'].action,
			data: jQuery("#submitcomment").serialize(),
			success: function() {
			
				  	jQuery("#comments ul").append("<li>Thank you for your comment.</li>");
					}
			});
		return false;
		});	
	});
function loadComments(pageNum,pageSize) {
	$("#comments").load(escape(postID) + '!comments?_cC=' + pageSize + '&_cP='+pageNum);
	}
	
	
function pollBargraph(){
	$("#poll").load('/poll/'+pollId,{},function(){
		var barGraphs = $("#poll-results .bargraph");
		var pollPercents = $("#poll-form .percent");
		pollPercents.each(function(i){
			if(pollPercents[i].value<3) pollPercents.value = 3;
			var width = pollPercents[i].value*1.79;
			$(barGraphs[i]).css("width", width);
			});	
		
		$("#vote").click(function(){
			if($("#poll-form").serialize() == "") {
				alert("Please check a box to vote.");
				return false;
				}
		$.ajax({
			type: "POST",
			url: document.forms['poll-form'].action,
			data: $("#poll-form").serialize(),
			success: function() { pollBargraph(); }
			});
		return false;
		});
	
	
		$("#showpoll").click(function(){
				$("#pollgraph").show();			
				$("#poll-results").css("position","relative");
				$("#poll-results").css("height","100%");
			});
			
				
		});
	}

/*	
function sendComment(url) {
	c =  document.getElementById("comment-text").value;
	data = {
		userComment: c
    };
	$.get(url,data,function(data){
		loadComments(1,25);
         });
        }  */
        
function sendPrelimComment(obj) {
alert(obj);
	/*c =  document.getElementById("comment-text").value;
	data = {
		userComment: c
	};
	jQuery.get(url,data,function(data){
		if(pageLabel == "blog") { loadBlogComments(this.manager.getAssetId(this.type, this.container),contentType,pageIndex,regionLocator); }
		if(pageLabel == "blogs") { loadBlogComments(obj.contentId,contentType,pageIndex,regionLocator); }
		if(pageLabel == "home") { loadMediaComments(obj.contentId,contentType,pageIndex,regionLocator); }
		if(pageLabel == "media") { loadMediaComments(obj.contentId,contentType,pageIndex,regionLocator); }
         });*/
        } 
function sendComment(url,id,page_label,page,comments,region) {
	c =  document.getElementById("comment-text").value;
	data = {
		userComment: c
    };
	jQuery.get(url,data,function(data){
		if(page_label == "blog") { loadBlogComments(id,page,comments,region); }
		if(page_label == "blogs") { loadBlogComments(id,page,comments,region); }
		if(page_label == "home") { loadMediaComments(id,page,comments,region); }
		if(page_label == "media") { loadMediaComments(id,page,comments,region); }
		return false;
         }); 
        } 

function sendGenericComment() {
	c =  document.getElementById("comment-text").value;
	loadPage = document.getElementById("currentPage").value;
	cm = document.getElementById("commentPosted");
	page =  document.getElementById("pageType").value;
	comments = 3;
	region =  document.getElementById("region").value;
	page_label =  document.getElementById("pageLabel").value;
	id =  document.getElementById("contentId").value;
	url = '/'+region+'/'+page+'/'+id+'!comment';
	data = {
		userComment: c
    };
	jQuery.get(url,data,function(data){	
		if(page_label == "blog") { loadBlogComments(id,loadPage,comments,region); }
		if(page_label == "blogs") { loadBlogComments(id,loadPage,comments,region); }
		if(page_label == "home") { loadMediaComments(id,loadPage,comments,region); }
		if(page_label == "media") { loadMediaComments(id,loadPage,comments,region); }
		cm.style.display = 'block';
		omniLinkCall(this,'comment_execute_link_click');
         });     	
     
} 	
function setViewCounts(id) {
    url = "/"+regionLocator+"/media/"+id+"!viewcount";
    jQuery.get(url);
}
function loadMediaComments(id,page,comments,region) {
    commentsUrl = "/"+regionLocator+"/media/"+id+"/comments?_cC=" + comments + "&_cP="+page;
    //alert('media comments loading...');
    jQuery("#commentsList").load(commentsUrl,{},function(){
    });
}
function loadBlogComments(id,page,comments,region) {
	/* alert('locading comments for '+regionLocator); */
    commentsUrl = "/"+regionLocator+"/blog/"+id+"/comments?_cC=" + comments + "&_cP="+page;
    
    jQuery("#commentsList").load(commentsUrl,{},function(){
        
    });
}
function loadMediaCommentsBox(id,page,comments,region) {
    commentsUrl = "/"+regionLocator+"/media/"+id+"/comments?_cC=" + comments + "&_cP="+page;
    //commentsUrl = "/"+region+"/home-commentpost";    
    jQuery("#commentsList").load(commentsUrl,{},function(){
        
    });
}     
function sendSharedServiceEmail() {
	c =  document.getElementById("toEmail").value;
	em =  document.getElementById("toEmail");
	er =  document.getElementById("missingEmail");
	//es =  document.getElementById("emailSent");
	//if(c=='') { er.style.display = 'inline'; return false; }
	//else { er.style.display = 'none'; }
	//alert('sending shared service email to...' + c);
	//loadPage = document.getElementById("currentPage").value;
	//page =  document.getElementById("pageType").value;
	//comments = 3;
	//region =  document.getElementById("region").value;
	//page_label =  document.getElementById("pageLabel").value;
	//id =  document.getElementById("contentId").value;
		url = '/'+regionLocator+'/media/'+assetId+'!email';
		//alert(pageLabel);
	if(pageLabel=='blog' || pageLabel=='blogs') {
		url = '/'+regionLocator+'/blog/'+customBlogId+'!email';
		} else {
		url = '/'+regionLocator+'/media/'+assetId+'!email';
		}
	data = {
		toEmail: c
    };
    jQuery.get(url,data,function(data){
    	//es.style.display = 'inline';
    	em.value = '';
    });
     
}  
function sendBlogSharedServiceEmail() {
	c =  document.getElementById("toEmail").value;
	em =  document.getElementById("toEmail");
	er =  document.getElementById("missingEmail");
	//es =  document.getElementById("emailSent");
	if(c=='') { er.style.display = 'inline'; return false; }
	else { er.style.display = 'none'; }
	//alert('sending shared service email to...' + c);
	//loadPage = document.getElementById("currentPage").value;
	//page =  document.getElementById("pageType").value;
	//comments = 3;
	//region =  document.getElementById("region").value;
	//page_label =  document.getElementById("pageLabel").value;
	//id =  document.getElementById("contentId").value;
	url = '/'+regionLocator+'/blog/'+assetId+'!email';
	data = {
		toEmail: c
    };
    jQuery.get(url,data,function(data){
    	//es.style.display = 'inline';
    	em.value = '';
    });
     
} 
function rateBlog(url,divid) {
$j('#'+divid).load(url);
}
     
function rateMedia(url,divid) {
//alert(assetId);
$j('#'+divid).load(url);
}
function rateHomeMedia(region,url,divid) {
$j('#'+divid).load('/'+region+'/media/'+assetId+'/'+url);
}