function htmlspecialchars(ch) {
   ch = ch.replace(/&/g,"|*|*|amp;")
   ch = ch.replace(/\"/g,"|*|*|quot;")
   ch = ch.replace(/\'/g,"|*|*|#039;")
   ch = ch.replace(/</g,"|*|*|lt;")
   ch = ch.replace(/>/g,"|*|*|gt;")
   return ch
}
	function view_comments_ajax(order,article_id){
	get = '?article_id='+article_id+'&order='+order;
	post = '';
	path = 'php_functions/ajax_article_cometary_prosses.php';
	element = 'comments';
	ajax(path,get,post,element);
}
	function post_comments_ajax(timezone,article_id){
	var post_time = new Date();
	var server_timezone = timezone/100;
	var local_timezone = (post_time.getTimezoneOffset() / 60);
	var time_ajustment = (local_timezone + server_timezone) *60*60;
	var timestamp_java = post_time.getTime() / 1000;
	var timestamp = timestamp_java - time_ajustment;
	get = '?article_id='+article_id+'&time='+timestamp;
	post = 'comment='+document.getElementById('comment').value;
	post = htmlspecialchars(post);
	path = 'php_functions/ajax_article_cometary_prosses.php';
	element = 'comments';
	ajax(path,get,post,element);
	document.getElementById('comment').value = "";
}
	function agree_disagree_ajax(id,agree_or_disagree){
	if(agree_or_disagree == 'agree'){
	var agree_content = document.getElementById('agree_'+id).innerHTML;
	if(!agree_content.match(/disabled/)){
	var get = '?comment_id='+id+'&agree=1&disagree=0';
	document.getElementById('agree_'+id).innerHTML = eval(agree_content +' + 1') + '<!--disabled-->';
	document.getElementById('disagree_'+id).innerHTML = document.getElementById('disagree_'+id).innerHTML + '<!--disabled-->';
	document.getElementById('feedback_'+id).innerHTML = 'YOU AGREE';
	}}
	
	if(agree_or_disagree == 'disagree'){
	var disagree_content = document.getElementById('disagree_'+id).innerHTML;
	if(!disagree_content.match(/disabled/)){
	var get = '?comment_id='+id+'&agree=0&disagree=1';
	document.getElementById('disagree_'+id).innerHTML = eval(disagree_content +' + 1') + '<!--disabled-->';
	document.getElementById('agree_'+id).innerHTML = document.getElementById('agree_'+id).innerHTML + '<!--disabled-->';
	document.getElementById('feedback_'+id).innerHTML = 'YOU DISAGREE';
	}}
	post = '';
	path = 'php_functions/agree_disagree_ajax.php';
	element = "";
	ajax(path,get,post,element);
	}
	
	function report_abuse_ajax(comment_id){
	get = '?comment_id='+comment_id;
	post = '';
	path = 'php_functions/report_abuse_ajax.php';
	element = 'test';
	ajax(path,get,post,element);
	document.getElementById('abuse_flag_'+comment_id).innerHTML = 'This comment was reported for abuse<br />';
}
	function pagination_commentaires_ajax(page_number,article_id){
	get = '?page='+page_number+'&article_id='+article_id;
	post = '';
	path = 'php_functions/ajax_article_cometary_prosses.php';
	element = 'comments';
	ajax(path,get,post,element);
}

function favorites_ajax(howmanystars, article_id, chapter_id){
counter = 0;
stars = "";
if(howmanystars > 0){
stars = '<span class="fakelink" onClick="favorites_ajax(\'0\');">Remove from favorites</span>&nbsp;&nbsp;';
while(counter < howmanystars){
counter++;
stars = stars + '<img style="cursor:pointer" onclick="favorites_ajax(\''+counter+'\',\''+article_id+'\',\''+chapter_id+'\');" src="images/favorite_on.jpg" width="20" height="20" alt="star" />';
}
}else{
stars = '<span class="fakelink" onClick="favorites_ajax(\'1\',\''+article_id+'\',\''+chapter_id+'\');">Add to favorites</span>&nbsp;&nbsp;';
}
while(counter < 5){
counter++;
stars = stars + '<img style="cursor:pointer" onclick="favorites_ajax(\''+counter+'\',\''+article_id+'\',\''+chapter_id+'\');" src="images/favorite_off.jpg" width="20" height="20" alt="star" />';
}

document.getElementById('favorites').innerHTML = stars;
	get = "?howmanystars="+howmanystars+"&article_id="+article_id+"&chapter_id="+chapter_id;
	post = "";
	path = 'php_functions/add_to_favorites_ajax.php';
	element = '';
	ajax(path,get,post,element);
}


	function ajax_follow_article(opperation, article_id){
	get = '?article_id='+article_id+'&opperation='+opperation;
	post = '';
	path = 'php_functions/ajax_follow_article.php';
	element = '';
	ajax(path,get,post,element);
	if(opperation == 'follow'){
		spancontent = '<span id="suscribe"><span class="fakelink" onclick="ajax_follow_article(\'no_follow\',\''+article_id+'\');">Stop following this article in weekly newsletter</span> <img style="cursor:pointer;" onclick="ajax_follow_article(\'no_follow\',\''+article_id+'\');" src="images/email_activated.jpg" width="28" height="33" alt="unsuscribe" /></span>';
	}
	if(opperation == 'no_follow'){
		spancontent = '<span id="suscribe"><span class="fakelink" onclick="ajax_follow_article(\'follow\',\''+article_id+'\');">Follow this article in weekly newsletter</span> <img style="cursor:pointer;" onclick="ajax_follow_article(\'follow\',\''+article_id+'\');" src="images/email_deactivated.jpg" width="28" height="33" alt=" suscribe" /></span>';
	}
	document.getElementById('suscribe').innerHTML = spancontent;
}
