//Method for submitting  a comment
function submitPost(buttonIndicator)
{
	if(isUsrLoggedIn=="notlogged")
	{
	alert("You have to login before you submit a comment");
	return;
	}
	var form=document.getElementById("rating");
	var comment="";
	//var commentObject="";
	if(buttonIndicator=="topButton")
	{
		comment=document.getElementById("comments").value;
		//commentObject=document.getElementById("comments");
	}
	if(buttonIndicator=="bottomButton")
	{
		comment=document.getElementById("commentsBelow").value;
	//	commentObject=document.getElementById("commentsBelow");
	}
	if(trim(comment).length==0)
	{
		alert("Please enter some comment before clicking on submit");
		//commentObject.focus();
		return;
	}
	//alert("The number "+comment.indexOf("\n"));	
	//alert("The number "+comment.indexOf("\r"));
	comment=comment.replace(/\r\n/g,"\n");
	comment=comment.replace(/\r/g,"\n");
	comment=comment.replace(/\n/g, "<br />");	
	//comment=replaceEnters(comment);	
	document.getElementById("thisComment").value=comment;
	form.action=rurl+"showVideo/postComment/";
	form.submit();
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function replaceEnters(comment){
	var totalComment="";
	var dupComment=""+comment;
	var prevCount=-1;
	var count=0;
	for(var i=0;i<comment.length;i++){
		var temp = "";
		if(comment.charAt(i)=="\n"){			
			var temp = dupComment.substring(0,i-prevCount-1);
			alert("The values are "+prevCount+" - "+(i-1)+" - "+temp);
			dupComment=dupComment.substring(i-prevCount,dupComment.length);
			prevCount=i;
			count++;
		}
		if(count>0){
			totalComment+=temp+"<br />";
			count=0;
		}		
	}
	if(totalComment.length<=0)
		totalComment=comment;
	return totalComment;
}
//Method for email Popup when button on left navigation bar is clicked
function popup(popupName,videoId,identifier)
{
  popupName=popupName.replace(/\s/g,"_");
  // alert("url is:"+rurl);
   var url=rurl+"showVideo/emailpopup/"+videoId+"/"+identifier+"/";
   window.open(url,popupName,"menubar=no,width=490,height=410,toolbar=no,resizable=no,location=no,status=no");  
}
//Method for email Popup when email link beneath video is clicked
function popupForLink(popupName,videoId,identifier)
{
	  popupName=popupName.replace(/\s/g,"_");
	if(isUsrLoggedIn=="notlogged")
	{
	alert("You have to login before you can send an invitation");
	return;
	}
	var url=rurl+"showVideo/emailPopupForLink/"+videoId+"/";
	window.open(url,popupName,"menubar=no,width=490,height=410,toolbar=no,resizable=no,location=no,status=no");
}
//Method for supporting or opposing a video comment
function reportAbuseForComment(commentId,buttonIndicator)
{
	if(isUsrLoggedIn=="notlogged")
	{
	alert("You have to login before you can support or oppose a comment");
	return;
	}
	var form=document.getElementById("rating");
    form.action=
	rurl+"showVideo/reportAbuse/"+commentId+"/"+buttonIndicator+"/";
    form.submit();
}
//Method for supporting or opposing a video comment
function reportSpamForComment(commentId)
{
	if(isUsrLoggedIn=="notlogged")
	{
	alert("You have to login before you can report a comment as Spam");
	return;
	}
	var form=document.getElementById("rating");
    form.action=
	rurl+"showVideo/reportSpam/"+commentId+"/";
    form.submit();
}
//Method for rating a video
function submitRating(rating)
{
	if(isUsrLoggedIn=="notlogged")
		{
		alert("You have to login before you can rate a video");
		return;
		}
	if(isUploadedByUser=="yes")
		{
         alert("Now, now! You can't rate a video you uploaded! ");	
		 return;
		}
	var form=document.getElementById("rating");
	form.action=rurl+"showVideo/updateRating/"+rating+"/";
	form.submit();
}
function share(popupName,videoId,videoTitle)
{
	  popupName=popupName.replace(/\s/g,"_");
	var url=rurl+"showVideo/socialBookmarking/"+videoId+"/"+videoTitle+"/";
	window.open(url,popupName,"menubar=no,width=430,height=360,toolbar=no");
}
