<!--
var ie = false;
if(document.uniqueID) ie = true;
var locks = [];
//var url = document.URL.substring(0,document.URL.search(/[a-zA-Z0-9_-]*\.php/));

/// Create an XMLHttpRequest object to make an AJAX request.
function AJAXgetHttpRequest()
{
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	return http_request;
}


/// Send an AJAX request to the server.
/// Parameters:
///  data: contains parameters what sent to the server (data.params)
/// Return value: true = ok, false = sending failed
function AJAXsendRequest(data)
{
	var http_request = AJAXgetHttpRequest('POST');
	if (!http_request) {
		alert('error: no http request');
		return false;
	}

	// swith on loading anim
	loadingAnim(true);

	// send request
	http_request.open('POST', document.forms[0].action, true);
	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');	
	http_request.onreadystatechange = function() { AJAXgetAnswer(http_request, data); };

	var post = '';
	for(var param in data.params)
		post += param+'='+data.params[param]+'&';
	http_request.send(post);

	return true;
}

/// Incoming AJAX answer. Callback.
/// Parameters:
///  http_request: AJAX answer object
///  data: array to store incoming xml and text
function AJAXgetAnswer(http_request, data)
{
	if(http_request.readyState != 4) return;

	// swith off loading anim
	loadingAnim(false);	

	if (http_request.status != 200) {
		alert('error: status '+http_request.status);
		return false;
	}
	if(data.debug) alert(http_request.responseText);

	data.xml = http_request.responseXML;
	data.text = http_request.responseText;

	data.callback.call(null,data);
}

/// Search for a child tag (not recursive!).
/// Parameters:
///   obj: object, DOM object
///   name: string, tag name (without <>)
/// Return value: object, DOM object (or NULL).
function AJAXgetTag(obj, name)
{
	if(!obj || !obj.childNodes || !obj.childNodes.length)
		return null; // check for valid DOM object and for childrens

	obj = obj.firstChild;
	while(obj) {
		if(obj.nodeName == name) return obj;
		obj = obj.nextSibling;
	}
	
	return null;
}

/// Search for the next tag (sibling) with the same name on the same level.
/// Parameters:
///   obj: object, DOM object
/// Return value: object, DOM object (or NULL).
function AJAXgetNextTag(obj)
{
	if(!obj || !obj.nextSibling)
		return null; // check for valid DOM object and sibling
	
	var name = obj.nodeName;
	while(obj = obj.nextSibling) {
		if(obj.nodeType == 1 && obj.nodeName == name)
			return obj;
	}
			
	return null;
}

/// Return a tag text content, eg <sample>THIS WILL BE THE RESULT</sample>.
/// Warning! Just the first text will be the result.
/// Parameters:
///  obj: object, XML tag (DOM object)
/// Return value: string, value of the tag
function AJAXgetTagValue(obj)
{
	if(!obj || !obj.childNodes || !obj.childNodes[0] || !obj.childNodes[0].data) return "";
	return obj.childNodes[0].data;
}

/// Return a tag's attribute, eg <sample id="THIS WILL BE THE RESULT'></sample>.
/// Parameters:
///  obj: object, XML tag (DOM object)
///  attr: string, required attribute name
/// Return value: string, value of the attribute
function AJAXgetAttributeValue(obj, attr)
{
	if(!obj || !obj.attributes) return "";

	// search for the attribute
	var i = -1;
	while(obj.attributes[++i])
		if(obj.attributes[i].name == attr) return obj.attributes[i].value;
}

/// Put attributes of the given node into an asssociative array.
/// Parameters:
///  obj: object, XML tag (DOM object)
/// Return value: associative arrays with the attributes
function AJAXgetAttributesAsHash(obj)
{
	if(!obj || !obj.attributes) return "";
	
	var hash = {};
	var i = -1;
	while(obj.attributes[++i]) hash[obj.attributes[i].name] = obj.attributes[i].value;
	
	return hash;
}

/// You can lock your function (what calls AJAX) to run only once at the same time.
/// Parameters:
///  name: string, lock name
///  status: boolean, true (lock) or false (release)
/// Return value: boolean, true if you changed the lock status or false if not
function AJAXlock(name, status)
{
	if(locks[name] == status) return false;
	
	locks[name] = status;
	return true;
}

/// Show message from server (<obj message='...'>) if it exists.
/// Parameters:
///  obj: object, XML tag (DOM object)
function AJAXshowMessage(obj)
{
	// show message
	if(AJAXgetAttributeValue(obj,'message').length) ShowMessage(AJAXgetAttributeValue(obj,'message'));
}


var active_process = [];
/// Start/stop loading animation.
/// Parameters:
///  status: boolean, true = anim active
function loadingAnim(status)                                                     
{                                  
	// handle multithread js
	if(status) active_process.push(true);
	else active_process.pop();

	var obj = document.getElementById("loading_ajax");
	if(obj) {
		if(active_process.length && obj.className != 'loading_ajax_active')
			obj.className = "loading_ajax_active";
		else if(obj.className != 'inactive')
			obj.className = "loading_ajax_inactive";
	}
}

/// Put <input values into an array (data.params).
/// Parameters:
///  form: object, <form what holds <input
//   inputsName: array, requested <input field's name
///  params: array, result, usually data.params
function InputsToParams(form, inputsName, params)
{
	if(!form || !inputsName.length || !params) return false;
	
	for(var i in inputsName) {
		var name = inputsName[i];
		
		// search arrays ([])
		if(name.charAt(name.length-1) == '[') {
			for(var i2 = 0; i2 < form.elements.length; i2++) {
				var input = form.elements[i2];
				if(input.name.substr(0, name.length) == name && input.name.charAt(input.name.length-1) == ']') {
					if (input.type == 'checkbox') params[input.name] = input.checked ? 1 : 0;
					else params[input.name] = input.value;
				}
			}
		}
		
		// single input
		else {
			var input = form[name];
			if(input) {
				if (input.type == 'checkbox') params[input.name] = input.checked ? 1 : 0;
				else params[input.name] = input.value;
			}
		}
	}
	
	return true;
}

//-->

