/**
 * @author PacMan / Bob
 */

var xmlhttp_ec;
var activeEdit = null;

function ec_AJAX(id){
	if(activeEdit){
		ec_cancel_AJAX(activeEdit);
	}
	activeEdit = id;
	xmlhttp_ec = null;
	if(window.XMLHttpRequest){// code for all new browsers
		xmlhttp_ec = new XMLHttpRequest();
	}else if(window.ActiveXObject){// code for IE5 and IE6
		xmlhttp_ec = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(xmlhttp_ec!=null){		
		url = "js/AJAX/editComment.php?id=" + id;
		xmlhttp_ec.onreadystatechange=state_Change_ec;
		xmlhttp_ec.open("GET",url,true);
		xmlhttp_ec.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change_ec(){
	if (xmlhttp_ec.readyState == 4) {// 4 = "loaded"
		if (xmlhttp_ec.status == 200) {// 200 = "OK"
			document.getElementById('comment_'+activeEdit).innerHTML = xmlhttp_ec.responseText;
		}
		else {
			alert("Problem retrieving XML data:" + xmlhttp_ec.statusText);
		}
	}
}	

var xmlhttp_ec_cancel;

function ec_cancel_AJAX(id){
	editId=id;
	activeEdit = null;
	xmlhttp_ec_cancel = null;
	if(window.XMLHttpRequest){// code for all new browsers
		xmlhttp_ec_cancel = new XMLHttpRequest();
	}else if(window.ActiveXObject){// code for IE5 and IE6
		xmlhttp_ec_cancel = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(xmlhttp_ec_cancel!=null){		
		url = "js/AJAX/editCommentCancel.php?id=" + id;
		xmlhttp_ec_cancel.onreadystatechange=state_Change_ec_cancel;
		xmlhttp_ec_cancel.open("GET",url,true);
		xmlhttp_ec_cancel.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change_ec_cancel(){
	if (xmlhttp_ec_cancel.readyState == 4) {// 4 = "loaded"
		if (xmlhttp_ec_cancel.status == 200) {// 200 = "OK"
			document.getElementById('comment_'+editId).innerHTML = xmlhttp_ec_cancel.responseText;
		}
		else {
			alert("Problem retrieving XML data:" + xmlhttp_ec_cancel.statusText);
		}
	}
}	
