var ajax_handler_file = "main/ajax_handler.php";




function targetBlank(url) {
blankWin = window.open(url,'_blank');
}


function stickyimage_popup(url, width, height) {
   si_window=window.open('', "_blank", "toolbar=no, location=no, menubar=no, resizable=no, status=no, width=" + width + ", height=" + height);
   si_window.document.open();
   si_window.document.writeln('<html><head><title>zona tomada</title>');
   si_window.document.writeln('<style type="text/css" media="screen">');
   si_window.document.writeln('<!--');
   si_window.document.writeln('  body { margin: 0px; padding: 0px; }');
   si_window.document.writeln('-->');
   si_window.document.writeln('</style>');
   si_window.document.writeln('</head><body">');
   si_window.document.writeln('<img src="' + url + '">');
   si_window.document.writeln('</body></html>');
   si_window.document.close();
}


function show_comment_formattags() {
/* WARNING: Advertencia: No se aconseja el uso de getBoxObjectFor(). Trate de usar element.getBoundingClientRect() en lo posible.
Archivo Fuente: http://127.0.0.1/zt09/*/
document.getElementById("comment_formattags").style.display="block";
}


function hidden_comment_preview() {
/* WARNING: Advertencia: No se aconseja el uso de getBoxObjectFor(). Trate de usar element.getBoundingClientRect() en lo posible.
Archivo Fuente: http://127.0.0.1/zt09/*/
document.getElementById("comment_preview").style.display="none";
}







var xmlHttp = createXmlHttpRequestObject();


function createXmlHttpRequestObject() {
var xmlHttp;
try {
	xmlHttp = new XMLHttpRequest();
} catch(e) {
	var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
	"MSXML2.XMLHTTP.5.0",
	"MSXML2.XMLHTTP.4.0",
	"MSXML2.XMLHTTP.3.0",
	"MSXML2.XMLHTTP",
	"Microsoft.XMLHTTP");
	for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
		try	{
			xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
		} catch (e) {}
	}
}
if (!xmlHttp)
	alert("Error creating the XMLHttpRequest object.");
else
	return xmlHttp;
}



function ajax_comment(id_post, command) {
if (xmlHttp) {
	try {
		//display("&#151; ZT server working... &#151;")
		if (command == "previewComment") {
			var commentTxt = document.getElementById("comment_txt").value;
			var commentName = document.getElementById("comment_name").value;
			var commentMail = document.getElementById("comment_mail").value;
			var commentUrl = document.getElementById("comment_url").value;
			commentTxt = commentTxt.replace('\r\n', '[erdosign]', 'g');
			commentTxt = commentTxt.replace('\n', '[erdosign]', 'g');
		} else if (command == "insertComment") {
			var commentTxt = document.getElementById("final_comment_txt").value;
			var commentName = document.getElementById("final_comment_name").value;
			var commentMail = document.getElementById("final_comment_mail").value;
			var commentUrl = document.getElementById("final_comment_url").value;
			document.getElementById("new_comment").style.display="none";
		}
		var params = "command=" + command + "&idPost=" + id_post + "&commentTxt=" + commentTxt + "&commentName=" + commentName + "&commentMail=" + commentMail + "&commentUrl=" + commentUrl;
		/*alert(ajax_handler + "?" + params);
		xmlHttp.open("GET", ajax_handler + "?" + params, true);
		xmlHttp.onreadystatechange = handleRequestStateChange;
		xmlHttp.send(null);*/

		xmlHttp.open("POST", ajax_handler_file, true);
		xmlHttp.onreadystatechange = comment_handleRequestStateChange;
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
		xmlHttp.send(params);

	} catch(e) {
		displayError(e.toString());
	}
}
}


function comment_handleRequestStateChange() {
if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
		try	{
			serverResponse("ajax_result");
		} catch(e) {
			displayError(e.toString(), "ajax_result");
		}
	} else {
		displayError(xmlHttp.statusText, "ajax_result");
	}
}
}


function ajax_pointer(value) {
if (xmlHttp) {
	try {
		var params = "command=pointer&value=" + value;
		//alert(ajax_handler_file + "?" + params);
		xmlHttp.open("GET", ajax_handler_file + "?" + params, true);
		xmlHttp.onreadystatechange = pointer_handleRequestStateChange;
		xmlHttp.send(null);
	} catch(e) {
		displayError(e.toString());
	}
}
}


function pointer_handleRequestStateChange() {
if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
		try	{
			serverResponse("pointer");
		} catch(e) {
			displayError(e.toString(), "pointer");
		}
	} else {
		displayError(xmlHttp.statusText, "pointer");
	}
}
}


function ajax_linker(value) {
if (xmlHttp) {
	try {
		var params = "command=linker&value=" + value;
		xmlHttp.open("GET", ajax_handler_file + "?" + params, true);
		xmlHttp.onreadystatechange = linker_handleRequestStateChange;
		xmlHttp.send(null);
	} catch(e) {
		displayError(e.toString());
	}
}
}


function linker_handleRequestStateChange() {
if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
		try	{
			serverResponse("linker");
		} catch(e) {
			displayError(e.toString(), "linker");
		}
	} else {
		displayError(xmlHttp.statusText, "linker");
	}
}
}


function display($message, destiny_id) {
myDiv = document.getElementById(destiny_id);
myDiv.innerHTML = $message;
}



function displayError($message, destiny_id) {
display("Error retrieving data: " + $message, destiny_id);
}



function serverResponse(destiny_id) {
var response = xmlHttp.responseText;
if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0 || response.length == 0)
	throw(response.length == 0 ? "Server error." : response);
display(response, destiny_id);
}
