/**
	Copyright - Tibor Bedő
	All rights reserved.

	E-mail: tib@i-design.hu
	Web: www.i-design.hu
*/

var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
var isOPERA = (navigator.appName == "Opera");

var req;
var dobj;
var p;

var loading = null;
loading = document.createElement("div");
loading.style.position = "absolute";
loading.style.width = "200px";
loading.style.height = "20px";
loading.style.backgroundColor = "#ffffff";
loading.style.borderColor = "#000000";
loading.style.color = "#000000";
loading.style.borderStyle = "solid";
loading.style.borderWidth = "1px";
loading.style.overflow = "auto";
loading.style.filter = "alpha(opacity=90)";
loading.style.mozOpacity = 0.90;
loading.style.opacity = 0.90;
loading.innerHTML = "Betöltés folyamatban...";

function loadXMLDoc(url,showLoading,loadingobj) 
{

	if (showLoading) {
		if (typeof(window['getMousePosition'])!='undefined') {
			loading.style.left = (id_mouse_position_X-20)+"px";
			loading.style.top = (id_mouse_position_Y+20)+"px";
		} else {
			loading.style.left = '0px';
			loading.style.top = '0px';
		}
		document.body.appendChild(loading);
	}

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange(req);
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange(req);
            req.open("GET", url, true);
            req.send();
        }
    }

	return req;
	
}

function id_parse(r) {
	if (r.getElementsByTagName('object')[0])
		obj = r.getElementsByTagName('object')[0].firstChild.data;
	else obj = false;


	if (r.getElementsByTagName('params')[0])
		params = r.getElementsByTagName('params')[0].childNodes;
	else params = new Array();
	
	p = {};
	var i;
	var attribs = null;
	var key = null;
	var element = null;

	for (i=0;i<params.length;i++) {
		if (typeof(params[i].tagName)!="undefined" && params[i].firstChild) {
			element = params[i].firstChild;
			if (params[i].getAttribute('id')) key = params[i].getAttribute('id');
			else key = params[i].tagName;
			p[key] = {};
			if (params[i].childNodes.length>1) {
				for (j=0;j<params[i].childNodes.length;j++) {
					if (typeof(params[i].childNodes[j].tagName)!="undefined" && params[i].childNodes[j].firstChild) {
						element = params[i].childNodes[j].firstChild;
						p[key][params[i].childNodes[j].tagName] = element.data;
					}
				}
			} else p[key] = element.data;
		}
	}
	if (obj) eval("dobj = new "+obj+"(p);");
}

function processReqChange(req2) 
{
	return function () {
		var req = req2;
		if (req) {
			// only if req shows "complete"
			if (req.readyState == 4) {
				// only if "OK"
				try
				{
					if (req.status && (req.status == 200) ) {
						try
						{
							document.body.removeChild(loading);
						}
						catch (err)
						{
						}
						if (req.responseXML) {

							// ...processing statements go here...
							var r = req.responseXML.documentElement;

							id_parse(r);
						}

						
						
					} else {
						try
						{
							document.body.removeChild(loading);
						}
						catch (err)
						{
						}

						//alert("There was a problem retrieving the XML data:\n" + req.statusText);
					}
				}
				catch (err) {}
				
			}
		} else {
			try
			{
				document.body.removeChild(loading);
			}
			catch (err)
			{
			}
		}
	}
}

   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
            //http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = processReqChange(http_request);
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	  return http_request;
   }

loaded=true;