//##COMMENTI############################################
//######################################################
function c_save(o) {
	fields = "";
	var t = document.getElementById("commento");
	var v = t.value.replace(/&/g,"|AND|");
	v = v.replace(/'/g,"\\'");
	
	fields = "o="+o+"&t="+v;
	if (t.value != "") {
		var url = "../commenti_save.php";
		save_c(url);
	}
}
function c_reg(f,ids) {
	ids = ids.split("_");
	fields = "f="+f;
	for (i = 0; i < ids.length; i++) {
		var n = document.getElementById(ids[i]);
		var v = n.value.replace(/&/g,"|AND|");
		v = v.replace(/'/g,"\\'");
		fields += "&"+ids[i]+"="+v;
	}
	//alert(fields)
	var url = "../commenti_reg.php";
	save_reg(url);
}
function logout_c(msg) {
	var agree = confirm(msg);
	if (agree) {
		url = location.href+"&l=out";
		location = url;
	} else {
		//
	}
}


//################################################
function save_c(url) {
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange_scomment;
		req.open("POST",url,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		req.send(fields);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange_scomment;
			req.open("POST",url,true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			req.send(fields);
		}
	}
}
function processReqChange_scomment() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			scomment();
		} else {
			//alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}
function scomment() {
	var response = req.responseText;
	//alert(response)
	//////////////////////////////////////////////
	// Parse the XML ////////////////////////////
	if (window.XMLHttpRequest) {
		if (version == "IE7") {
			var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
			xmlDocument.async = false;
			var loaded = xmlDocument.loadXML(response);
			if (loaded) {
				//alert(xmlDocument.documentElement.nodeName);
			} else {
				//alert(xmlDocument.parseError.reason + xmlDocument.parseError.srcText);
				// shows error with end tag </gods> not matching start tag <god>
			}
		} else {
			var domParser = new DOMParser();
			var xmlDocument = domParser.parseFromString(response, 'application/xml');
			var parseError = checkForParseError(xmlDocument);
			if (parseError.errorCode == 0) {
				//alert(xmlDocument.documentElement.nodeName);
			} else {
				//alert(parseError.reason + '\r\n' + parseError.srcText);
				// shows detailed error message
			}
		}
	//////////
	} else if (window.ActiveXObject) {
		var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
		xmlDocument.async = false;
		var loaded = xmlDocument.loadXML(response);
		if (loaded) {
			//alert(xmlDocument.documentElement.nodeName);
		} else {
			//alert(xmlDocument.parseError.reason + xmlDocument.parseError.srcText);
			// shows error with end tag </gods> not matching start tag <god>
		}
	}
	//////////////////////////////////////////////
	//////////////////////////////////////////////
	var item = xmlDocument.getElementsByTagName("item")[0];
	var content = getElementTextNS("content", "", item, 0);
	
	location = location.href;
	
}
//################################################
function save_reg(url) {
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange_rcomment;
		req.open("POST",url,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		req.send(fields);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange_rcomment;
			req.open("POST",url,true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			req.send(fields);
		}
	}
}
function processReqChange_rcomment() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			rcomment();
		}
	}
}
function rcomment() {
	var response = req.responseText;
	//alert(response)
	//////////////////////////////////////////////
	// Parse the XML ////////////////////////////
	if (window.XMLHttpRequest) {
		if (version == "IE7") {
			var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
			xmlDocument.async = false;
			var loaded = xmlDocument.loadXML(response);
		} else {
			var domParser = new DOMParser();
			var xmlDocument = domParser.parseFromString(response, 'application/xml');
			var parseError = checkForParseError(xmlDocument);
		}
	//////////
	} else if (window.ActiveXObject) {
		var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
		xmlDocument.async = false;
		var loaded = xmlDocument.loadXML(response);
	}
	//////////////////////////////////////////////
	var item = xmlDocument.getElementsByTagName("item")[0];
	var content = getElementTextNS("content", "", item, 0);

	contentA = content.split("#");
	
	if (contentA.length > 1) {
		content1 = contentA[0];
		content = contentA[1];
		if (content1 == "duser") {
			var e = "e_"+content;
			var ff1 = document.getElementById(e);
			ff1.innerHTML = "";
			
			var p = "p_"+content;
			var ff1 = document.getElementById(p);
			ff1.innerHTML = "";
		}
	} else {
		if (content != "logged") {
			var ff1 = document.getElementById("msg_comment");
			var con = content.split("=");
			if (con[0] == "mok") {
				ff1.className = "msgok";
			} else {
				ff1.className = "msg";
			}
			ff1.innerHTML = con[1];
		} else {
			loc = location.href.split("&l=");
			loc = loc[0]
			location = loc;
		}
	}
}
//################################################
function deleteContent(code) {
	var agree = confirm("Sei sicuro di voler cancellare?\nAre you sure you wish to continue?");
	if (agree) {
		loc = location.href.replace(/&/g,"|AND|");
		url = "../deleteContent.php?loc=" + loc + "&code=" + code;
		location.href = url;
	}
}

function c_del(f,code) {
	var agree = confirm("Sei sicuro di voler cancellare?\nAre you sure you wish to continue?");
	if (agree) {
		fields = "f="+f+"&code="+code;
		var url = "../commenti_reg.php";
		//alert(fields);
		save_reg(url);
	}
}

