function load_comments(editorial_cartoon_num,site_url)
{
	xmlHttp=GetXmlHttpObject();
	
	if(xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
			
	var from = "ajax"; 
	
	var url = site_url+"/modules/editorial_cartoons/assets/php/cartoon_comments_content.php"; 
	url	= url+"?from="+ from ;
	url	= url+"&editorial_cartoon_num="+ editorial_cartoon_num ;
	url	= url+"&sid="+Math.random();
	//prompt("",url);
  
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var result = xmlHttp.responseText;
			document.getElementById('div_read_cartoon_comments_display').innerHTML = result;   
			return;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function leave_comment_cartoon(site_url,editorial_cartoon_num,account_system_num)
{
	xmlHttp=GetXmlHttpObject();
	
	if(xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}  
		
	var editorial_cartoon_comment_message	= document.getElementById('editorial_cartoon_comment_message').value; 
	var editorial_cartoon_comment_message 	= url_safe_entities(editorial_cartoon_comment_message);
	
	var editorial_cartoon_comment_subject	= document.getElementById('editorial_cartoon_comment_subject').value; 
	var editorial_cartoon_comment_subject 	= url_safe_entities(editorial_cartoon_comment_subject);

	var message  = '';
 
	if(account_system_num == "") 
	{
		message += '- You must be logged in.\n\n';
	}
	else
	{
		if(editorial_cartoon_comment_subject == "") 	 
		{
			message += '- A comment Subject is required.\n\n';
		} 	
		if(editorial_cartoon_comment_message == "") 	 
		{
			message += '- A comment is required.\n\n';
		} 	
	}
	if(message) 
	{
		alert('The following error(s) occurred:\n\n' + message);
		return false;
	}
	
	document.getElementById("div_leave_cartoon_comment_content").style.display 	= 'none';
	document.getElementById("div_leave_cartoon_comment_loading").style.display 	= 'block';		
	
	var url = site_url+"/modules/editorial_cartoons/assets/php/leave_cartoon_comment.php"; 
	url	= url+"?editorial_cartoon_num="+ editorial_cartoon_num;
	url	= url+"&account_system_num="+ account_system_num;
	url	= url+"&editorial_cartoon_comment_message="+ editorial_cartoon_comment_message;
	url	= url+"&editorial_cartoon_comment_subject="+ editorial_cartoon_comment_subject;			
	url	= url+"&sid="+Math.random();
	//prompt("",url);

  
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var result = xmlHttp.responseText;
			if (result == "success")
			{
				document.getElementById("div_leave_cartoon_comment").style.display 				= 'none';
				document.getElementById("div_leave_cartoon_comment_loading").style.display 		= 'none';				
				document.getElementById("div_leave_cartoon_comment_content").style.display 		= 'block';
				document.getElementById("editorial_cartoon_comment_message").value 				= '';						
				document.getElementById("editorial_cartoon_comment_subject").value 				= '';														
				load_comments(editorial_cartoon_num,site_url);
			}
			return;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function report_comment(site_url,account_system_num,editorial_cartoon_comment_num)
{
	xmlHttp=GetXmlHttpObject();
	
	if(xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}  
	 
	var message  = '';
 
	if(account_system_num == "") 
	{
		message += '- You must be logged in.\n\n';
	}
	if(message) 
	{
		alert('The following error(s) occurred:\n\n' + message);
		return false;
	}
	 
	var url = site_url+"/modules/editorial_cartoons/assets/php/report_cartoon_comment.php"; 
	url	= url+"?account_system_num="+ account_system_num;
	url	= url+"&editorial_cartoon_comment_num="+ editorial_cartoon_comment_num;	 		
	url	= url+"&sid="+Math.random();
	//prompt("",url);
  
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var result = xmlHttp.responseText;
			if (result == "success")
			{
				alert("Comment Successfully Reported to the Site Admin.");				 
			}
			else if (result == "duplicate")
			{
				alert("You have already reported this comment");
			}
			return;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function report_ec_comment(site_url,account_system_num,editorial_cartoon_comment_num)
{
	xmlHttp=GetXmlHttpObject();
	
	if(xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}  
	 
	var message  = '';
 
	if(account_system_num == "") 
	{
		message += '- You must be logged in.\n\n';
	}
	if(message) 
	{
		alert('The following error(s) occurred:\n\n' + message);
		return false;
	}
	 
	var url = site_url+"/modules/editorial_cartoons/assets/php/report_cartoon_comment.php"; 
	url	= url+"?account_system_num="+ account_system_num;
	url	= url+"&editorial_cartoon_comment_num="+ editorial_cartoon_comment_num;	 		
	url	= url+"&sid="+Math.random();
	//prompt("",url);
  
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{ 
			var result = xmlHttp.responseText;
			if (result == "success")
			{
				alert("Comment Successfully Reported to the Site Admin.");				 
			}
			else if (result == "duplicate")
			{
				alert("You have already reported this comment");
			}
			return;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function url_safe_entities(variable)
{
	var variable 	= variable.replace(new RegExp('%', 'gi'), 		'%25');		
	var variable 	= variable.replace(new RegExp('#', 'gi'),	 	'%23');
	var variable 	= variable.replace(new RegExp('&', 'gi'),	 	'%24');
	var variable 	= variable.replace(new RegExp(';', 'gi'), 		'%3B');
	var variable 	= variable.replace(new RegExp(':', 'gi'), 		'%3A');
	var variable 	= variable.replace(new RegExp('=', 'gi'), 		'%3D');
	var variable 	= variable.replace(new RegExp('~', 'gi'), 		'%7E');
	var variable 	= variable.replace(new RegExp('<\\?', 'gi'), 	'< ?');
	var variable 	= variable.replace(new RegExp('\\?>', 'gi'), 	'? >');
	var variable 	= variable.replace(new RegExp('<', 'gi'), 		'%3C');
	var variable 	= variable.replace(new RegExp('>', 'gi'), 		'%3E');	
	var variable 	= variable.replace(new RegExp('\\+', 'gi'), 	'%2B');	
	var variable 	= variable.replace(new RegExp('\\?', 'gi'), 	'%3F');
	var variable 	= variable.replace(new RegExp('\\$', 'gi'),	 	'%26');
	
	return variable;
	
	/*
	var replace_string = variable;
	replace_string.replace(/&/gi, "&amp;");
	replace_string.replace(/"/gi, "&quot;");
	replace_string.replace(/ /gi, "&nbsp;");
	replace_string.replace(/#/gi, "&#35;");
	replace_string.replace(/!/gi, "&#33;");
	replace_string.replace(/!/gi, "&#33;"); 
	replace_string.replace(/"/gi, "&#34;");  	 
	replace_string.replace(/#/gi, "&#35;"); 	 
	replace_string.replace(/$/gi, "&#36;");  
	replace_string.replace(/%/gi, "&#37;"); 	 
	replace_string.replace(/&/gi, "&#38;"); 	 
	replace_string.replace(/'/gi, "&#39;"); 	 
	replace_string.replace(/(/gi, "&#40;");  
	replace_string.replace(/)/gi, "&#41;");  
	replace_string.replace(/+/gi, "&#43;"); 
	replace_string.replace(/,/gi, "&#44;"); 
	replace_string.replace(/-/gi, "&#45;"); 
	replace_string.replace(/./gi, "&#46;"); 
	replace_string.replace(/:/gi, "&#58;"); 	
	replace_string.replace(/;/gi, "&#59;"); 
	replace_string.replace(/=/gi, "&#61;"); 
	replace_string.replace(/?/gi, "&#63;"); 
	replace_string.replace(/@/gi, "&#64;"); 		
	replace_string.replace(/[/gi, "&#91;"); 
	replace_string.replace(/]/gi, "&#93;"); 
	replace_string.replace(/^/gi, "&#94;"); 
	replace_string.replace(/_/gi, "&#95;"); 
	replace_string.replace(/`/gi, "&#96;"); 
	replace_string.replace(/{/gi, "&#123;"); 
	replace_string.replace(/|/gi, "&#124;"); 	
	replace_string.replace(/}/gi, "&#125;"); 
	replace_string.replace(/~/gi, "&#126;"); 	
	*/
	//replace_string.replace(/*/gi, "&#42;"); 
}
