function emailing(emailurl)
{
	$.ajax({
	url : emailurl,
	success : function (data) {
	$("#contentArea").html(data+'<input type="button" value=" x " id="no">');
	/*$.blockUI.defaults.css.border = '1px solid black'; 
	 $.blockUI.defaults.css.width="410px";
	 $.blockUI.defaults.css.top="20px";
	 $.blockUI.defaults.css.cursor='default';
	$.blockUI({ message:  '<span style="padding-left:380px;"><input type="button" value=" x " id="no"></span>'+data });*/
	$('#no').click(function() {$("#contentArea").hide('slow');}); 
	}
	});	
}
function cheerToon(val,author)
{
var user="";
var imgPath="";
var action_data="toonId="+val;
if (userName=="")
{
	$.blockUI({css: { backgroundColor: '#d88f8f', border:'1px solid #000' }, message: "<span class='bigred'><br><br>Please Login to cheer!<br><br></span>"});
	setTimeout($.unblockUI, 1000);
}
else if(author==userName)
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>You can't cheer your ToonDoo!<br><br></span>"});
	setTimeout($.unblockUI, 1000);
}
else
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000'}, message: "<span class='bigblue'><br><br>Processing...<br><img src='../images/processing.gif'><br><br></span>"});
	$.ajax({ 
		type: "POST",
		url: 'addCheers.toon', 
		cache: false, 
		data: action_data,
		success: function()
		{
			var cheers=parseInt($("#cheercount").text())+1;	
			setTimeout("$('#cheercount').text("+cheers+");",3000);
		},
		complete: function() { 			
			// unblock when remote call returns 			
			$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000'}, message: "<span class='bigblue'><br><br>Thanks for cheering this one up!<br> Time to feel good!<br><br><br></span>"});	
			setTimeout($.unblockUI, 1000); 
		}
	 }); 	
} 

}
function favToon(val,author)
{
var action_data="toonId="+val;
var div="favorites";
/*$('#message').show('slow');
$("#message").html("<b>Processing...</b><br><img src='images/processing.gif'>");	
if(userName=="guest")
{
	$('#message').show('slow');
	$("#message").html("<b>Please login to add it to your favorites!</b>");	
	setTimeout("$('#message').hide('slow');",3000);
}
else if(author==userName)
{
	$('#message').show('slow');
	$("#message").html("<b>You can't add your toon to your favorites</b>");	
	setTimeout("$('#message').hide('slow');",3000);

}
else
{
	$.ajax
	(
		{
			type: "POST",
			url: "/addFavorites.toon",
			data: action_data,
			success: function(msg)
			{		
				var favs=parseInt($("#favcount").text())+1;	
				setTimeout("$('#favcount').text("+favs+");",3000);
				$('#message').show('slow');
				$("#message").html("<b>We have added this ToonDoo to your favourites!</b>");	
				setTimeout("$('#message').hide('slow');",3000);
			}
			
		}
	);
}
*/
if (userName=="")
{
	$.blockUI({css: { backgroundColor: '#d88f8f', border:'1px solid #000' }, message: "<span class='bigred'><br><br>Please login to add it to your favorites!<br><br></span>"});
	setTimeout($.unblockUI, 2000);
}
else if(author==userName)
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>You can't add your toon to your favorites!<br><br></span>"});
	setTimeout($.unblockUI, 2000);
}
else
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>Processing...<br><img src='../images/processing.gif'><br><br></span>"});
	$.ajax({ 
	type: "POST",
	url: 'addFavorites.toon', 
	cache: false, 
	data: action_data,
	success: function()
	{
		var favs=parseInt($("#favcount").text())+1;	
		setTimeout("$('#favcount').text("+favs+");",3000);
	},
	complete: function() { 
		// unblock when remote call returns 
		$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>We have added this ToonDoo to your favourites!<br><br><br></span>"});	
		setTimeout($.unblockUI, 2000); 
	}
 });
}
 
}
function flagInapp(val,imgPath,author)
{
var user="";
var action_data="toonId="+val+"&user="+user+"&imgPath="+imgPath;
if (userName=="")
{
	$.blockUI({css: { backgroundColor: '#d88f8f', border:'1px solid #000' }, message: "<span class='bigred'><br><br>Please login to flag it as mature!<br><br></span>"});
	setTimeout($.unblockUI, 2000);
}
else if(author==userName)
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>You can't flag your ToonDoo as mature!<br><br></span>"});
	setTimeout($.unblockUI, 2000);
}
else
{
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>Processing...<br><img src='../images/processing.gif'><br><br></span>"});
	$.ajax({ 
		type: "POST",
		url: 'flagInapp.toon', 
		cache: false, 
		data: action_data,
		complete: function() { 
			// unblock when remote call returns 
			$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>Thanks! The editors at ToonDoo have been alerted about this!<br><br><br></span>"});	
			setTimeout($.unblockUI, 2000); 
		}
	 });
}
}

function redooToon(val,author)
{
	var user="";
	if(userName=="guest")
	{
		$('#message').show('slow');
		$("#message").html("<b>Please login to Redoo this ToonDoo!</b>");	
		setTimeout("$('#message').hide('slow');",3000);
	}
	else if(userName==author)
	{
		$('#message').show('slow');
		$("#message").html("<b>You can't ReDoo your own ToonDoo!</b>");	
		setTimeout("$('#message').hide('slow');",3000);
	}
	else
	{
		$('#message').hide('slow');
	}
}
function addComment(form)
{

  var toonId = form.toonId.value;
  var toonAuthor = form.toonAuthor.value;
  var toonStatus = form.toonStatus.value;
  var commentText = form.commentsText.value;
  res='';
  if(commentText.length <1){
	commentText = 'Default - Comment';
	}
	else
	{
		commentText = commentText.split("\n");		
		for(var i = 0; i < commentText.length; i++)
		{
			res += commentText[i]+'\\n';
		}
		commentText = res;
	}
	document.getElementById("comment").disabled=true;							
	document.getElementById("comment").value="Sending...";
	$.post("addComment.toon",{'toonId':toonId,'commentText':commentText,'toonAuthor':toonAuthor, 'toonStatus':toonStatus},function(msg)
	{
		
		document.getElementById("comment").disabled=false;		
		document.getElementById("comment").value="Submit";
		form.commentsText.value="";
		document.getElementById("showyourcomment").innerHTML += msg;
		
	});		
}
/** add book comment **/
function addBookComment(form)
{
  var toonId = form.bookId.value;
  var commentText = form.commentsText.value;  
  var bookAuthor = form.bookAuthor.value;
  res='';
  if(commentText.length <1){
	commentText = 'Default - Comment';
	}
	else
	{
		commentText = commentText.split("\n");		
		for(var i = 0; i < commentText.length; i++)
		{
			res += commentText[i]+'\\n';
		}
		commentText = res;
	}
	document.getElementById("comment").disabled=true;							
	document.getElementById("comment").value="Sending...";
	$.post("addBookComment.toon",{'bookId':toonId,'commentText':commentText, 'bookAuthor':bookAuthor},function(msg)
	{
		document.getElementById("comment").disabled=false;		
		document.getElementById("comment").value="Submit";
		form.commentsText.value="";
		document.getElementById("showyourcomment").innerHTML += msg;
	});		
}
/** ends here **/

function deleteComment()
{
	var delCom = document.getElementById('delcommentid').value;	
	$.blockUI({css: { backgroundColor: '#fff', border:'1px solid #000' }, message: "<span class='bigblue'><br><br>Are you sure you want to delete this comment?<br><br><input type='button' name='areyes' id='areyes' value=' Yes ' onClick='$.unblockUI();delComment();'> &nbsp; <input type='button' name='no' id='no' value=' No ' onClick=$.unblockUI();><br><br></span>"});
}	
	
function loadVcfcr(toonId,toonAuthor,dirString)
{
	var userLength=toonAuthor.length;
	var lcaseuname = toonAuthor.toLowerCase();
	var imgPath="";
	if(userLength > 2)
	{
		imgPath = "public/"+lcaseuname.substring(0,1)+"/"+lcaseuname.substring(1,2)+"/"+lcaseuname.substring(2,3)+"/"+toonAuthor+"/toons/cool-cartoon-"+toonId+".png";
	}
	
	
	var dirPath = "http://www.toondoo.com/webincludes/"+dirString+"/toondata-"+toonId+".inc";

	var imagePath = 
	/*$.post(dirPath,{'toonId':toonId},function(msg)
	{
		var result=msg;
		result=result.replace(/&vcfcr=/,"");
		vcfcrArray=result.split(",") ;
		document.getElementById('viewcount').innerHTML=vcfcrArray[1];
		document.getElementById('cheercount').innerHTML=vcfcrArray[2];
		document.getElementById('favcount').innerHTML=vcfcrArray[3];
		document.getElementById('commentscount').innerHTML=vcfcrArray[4];
		//document.getElementById('redoocount').innerHTML=vcfcrArray[5];
		jQuery("#bgcheering").click(function() {cheerToon(toonId,toonAuthor);});
		jQuery("#favorites").click(function() {favToon(toonId,toonAuthor);});
		jQuery("#flagToon").click(function() {flagInapp(toonId,imagePath,toonAuthor);});
		jQuery("#print").click(function() {fullScreenMode('printToon.jsp?toonlink='+imgPath,2); return false;});			
	});
	*/
	
	$.ajax({
	url: dirPath,
	data: { 'toonId':toonId},
	type: "POST",
	//beforeSend: function(){disableSubmitButton();},
	//complete: function(){enableSubmitButton();},
	error: function(xhr, statusText, errorThrown){
			// Work out what the error was and display the appropriate message
			//alert("xhr "+xhr.status);
			//if(xhr.status == 400)
			//{
				//alert("inside");
				document.getElementById('viewcount').innerHTML=0;
				document.getElementById('cheercount').innerHTML=0;
				document.getElementById('favcount').innerHTML=0;
				document.getElementById('commentscount').innerHTML=0;
			//}
		},
	    success: function(msg){
			//displayUserCreatedMessage();
			//refreshUserList();
		var result=msg;
		result=result.replace(/&vcfcr=/,"");
		vcfcrArray=result.split("±") ;
		document.getElementById('viewcount').innerHTML=vcfcrArray[1];
		document.getElementById('cheercount').innerHTML=vcfcrArray[2];
		document.getElementById('favcount').innerHTML=vcfcrArray[3];
		document.getElementById('commentscount').innerHTML=vcfcrArray[4];
		//document.getElementById('redoocount').innerHTML=vcfcrArray[5];		
		},
		complete: function() {
			//alert("inside complete");
			jQuery("#bgcheering").click(function() {cheerToon(toonId,toonAuthor);});
			jQuery("#favorites").click(function() {favToon(toonId,toonAuthor);});
			jQuery("#flagToon").click(function() {flagInapp(toonId,imagePath,toonAuthor);});
			jQuery("#print").click(function() {fullScreenMode('printToon.jsp?toonlink='+imgPath,2); return false;});	
		}
	});
}
function vcfcr() {}
