// FG Forrest, a.s. - AJAX
function obj(id) {
	return document.getElementById(id);
}
function bool(value) {
	return new Boolean(value);
}
function tagValue(obj,name) {
	return obj.getElementsByTagName(name)[0].firstChild.nodeValue;
}
function ajaxRequest(method,url,parseFunc,async) {
	var t = this; //vytvori odkaz na objekt
	method = method.toUpperCase(); //ziska metodu a prevede na velika pismena
	t.parseFunc = parseFunc; //adresuje atribut parseFunc objektu t
	if (!async) { async = true; } //async neni deklarovan tak nastavi na true
	if (window.XMLHttpRequest) { t.ajax = new XMLHttpRequest(); } //pokud existuje tato funkce tak vytvori objekt XMLHttpRequest() a priradi ho do atributu ajax objektu t
	else if (window.ActiveXObject) { t.ajax = new ActiveXObject("Microsoft.XMLHTTP"); } //jinak pokud existuje objekt window.ActiveXObject tak vytvori prislusny objekt
	t.processRequest = processRequest;
	t.parseXML = parseXML;
	t.ajax.onreadystatechange = function() { t.processRequest(t.ajax); }
	t.ajax.open(method,url,async);
	if (method == "POST") {
        t.ajax.setRequestHeader("Connection","close");
		t.ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		t.ajax.setRequestHeader("Method","POST " + url + "HTTP/1.1");
	}
	t.ajax.send(null);
}
/*
readyState Status Codes:
0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete
*/
function processRequest(o) {
	if (o.readyState == 4) {
		if (o.status != 200) {
//			alert (o.status + " " + o.statusText);
			this.parseFunc = "Error";
		}
		this.parseXML();
	}
}
function parseXML() {
	eval("parse"+this.parseFunc+"(this.ajax)");
}
function response(o) {
	var respXML = o.responseXML;
	var respText = o.responseText;
	var resp = respXML;
	if (window.XMLHttpRequest) { resp = (new DOMParser()).parseFromString(respText,"text/xml"); }
	return resp;
}
function doSaveToDB(url)
{
	new ajaxRequest("get",url,"SaveToDB");
}

function parseSaveToDB()
{
	// window.alert("Hotovo!");
}
