function openSub(node, display_type) {
	next = node.nextSibling;
	
	 display_type =  display_type ?  display_type : 'block';
	
	if (next.nodeType != document.ELEMENT_NODE) next = next.nextSibling;
	
	if (next.style.display != display_type)
		next.style.display = display_type;
	else
		next.style.display = 'none';
}

function HideShow(id) {
	obj=document.getElementById(id);;
	if (obj.className=="show") obj.className="hide";
	else obj.className="show";
}
function showObj(id, style){
	obj = document.getElementById(id);
	if (obj) {
        obj.style.visibility = "visible";
        obj.style.display = style ? style : "block";
    } else alert('`'+id+'` is not defined');
}
		
function hideObj(id){
	obj = document.getElementById(id);
	if (obj) {
        obj.style.visibility = "hidden";
        obj.style.display = "none";
    } else if (id.style) {
		id.style.visibility = "hidden";
        id.style.display = "none";
	}
}

function clearObj(id){
	obj = document.getElementById(id);
	if (obj) obj.innerHTML = "";
}

function moveObj(obj, to_obj) {
	if (obj && to_obj) {
		to_obj.appendChild(obj);
	}
}

function changeValue(id, value) {
	var inp = document.getElementById(id);
	if (inp) inp.value=value;
		else alert("`"+inp+"` is not defined in changeValue()");
}
function getValue(id) {
	var inp = document.getElementById(id);
	if (inp && inp.value) return inp.value;
	else alert('`' + id + '` not defined in getValue()');
	
	return false;
}

function disableButton(id) {
    var but = getReference(id);
    if (but)
		but.disabled = true;
	else if (typeof(id) != 'undefined' && typeof(id.disabled) != 'undefined')
		id.disabled = true;
}
function enableButton(id) {
    var but = getReference(id);
    if (but)
		but.disabled=false;
	else if (typeof(id.disabled) != 'undefined')
		id.disabled = false;
}

function getReference(id) {
	var inp = document.getElementById(id);
	return inp;
}
	function $(id) {
		var inp = document.getElementById(id);
		return inp;
	}
function realEscape(str) {
	//Òîâà åñêåèïâà ' è \, à íå êàòî íà æàáàñêðèïò òúïèÿ escape
	if (!str) return false;
	
	str = str.split('\\').join('\\\\');
	str = str.split("'").join("\\'");
	
	return str;
}
function changeAttribute(id, attribute, value){
    var inp = document.getElementById(id);
	
	value = realEscape(value); //Òîâà åñêåèïâà ' è \, à íå êàòî íà æàáàñêðèïò òúïèÿ escape
	eval("inp."+attribute+"='"+value+"'");
}
function changeCssClass(id, css_class){
	var obj = document.getElementById(id);
	if (obj) obj.className = css_class;
}
function getCssClass(id){
	var obj = document.getElementById(id);
    return obj.className;
}

function GoTo(url) {
	location.href=url;
}
function goto_time(url, time) {
	setTimeout("location.href='"+url+"';",3000);
}
function urlCleanup(url, arr) {
    var new_url = new String;
	var new_url = '';
    url_org = url.split('?');
	
    if (url_org[1]) {
		url = url_org[1].split('#');
        url = url[0].split('&');
    	if (arr && (arr.length > 0)) {
			for(var u=0; u<url.length; u++) {
				if (typeof(url[u]) != 'undefined' && url[u] != '') {
					val = url[u].split('=');
					da_eba_javascript = false;
					for(var i=0; i<arr.length; i++) {
						da_eba_javascript = (val[0] == arr[i]) && (val[1] != '');
						if (da_eba_javascript === true) break;
                    }
					if (da_eba_javascript !== true) {
						new_url = new_url + '&' + val[0] + '=' + val[1];
						i=arr.length;
					}
                }
            }
        }
    }
	
	new_url = url_org[0] +  (new_url != '' ? '?' + new_url.substring(1) : '?'); //
    return new_url;
}

String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

String.prototype.theEscape = function () {
    return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\s/g,'%20');
}
String.prototype.addSlashes = function () {
	return this.replace(/\\/g,"\\"+"\\").replace(/'/g,"\\"+"'").replace(/"/g,'\\'+'"');
}

if (!document.ELEMENT_NODE) {
	document.ELEMENT_NODE = 1;
	document.ATTRIBUTE_NODE = 2;
	document.TEXT_NODE = 3;
	document.CDATA_SECTION_NODE = 4;
	document.ENTITY_REFERENCE_NODE = 5;
	document.ENTITY_NODE = 6;
	document.PROCESSING_INSTRUCTION_NODE = 7;
	document.COMMENT_NODE = 8;
	document.DOCUMENT_NODE = 9;
	document.DOCUMENT_TYPE_NODE = 10;
	document.DOCUMENT_FRAGMENT_NODE = 11;
	document.NOTATION_NODE = 12;
}
document.javascripts = new Array();
document._importNode = function(node, allChildren) {
	switch (node.nodeType) {
		case document.ELEMENT_NODE:
			var newNode = document.createElement(node.nodeName);
			var isJS = false;
			/* does the node have any attributes to add? */
			if (node.attributes && node.attributes.length > 0)
				for (var i = 0; i < node.attributes.length;) {
					if (node.attributes[i].nodeName == 'type' && node.getAttribute(node.attributes[i].nodeName) == 'text/javascript') {
						isJS = true;
						break;
						i++;
					} else newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
				}
			/* are we going after children too, and does the node have any? */
			if (allChildren && node.childNodes && node.childNodes.length > 0)
				for (var i = 0; i < node.childNodes.length;) {
					var new_child = document._importNode(node.childNodes[i], allChildren);
					if (isJS) eval(new_child.nodeValue);
					 else if (newNode) newNode.appendChild(new_child);
					i++;
				}
			return newNode;
		break;
		
		case document.TEXT_NODE:
		case document.CDATA_SECTION_NODE:
		case document.COMMENT_NODE:
			return document.createTextNode(node.nodeValue);
		
		break;
	}
};
function disableBtn(btn_id, classCss) {
	var btn = getReference(btn_id);
	
	if (btn) {
		btn.className = classCss;
		btn.onclick = function () {return false;};
	} 
}
function undisableBtn(btn_id, classCss) {
	var btn = getReference(btn_id);
	
	if (btn) {
		btn.className = classCss;
		btn.onclick = null;
	} 
}
function checkAjax() {
    url = location.href;
	if (zXmlHttp.isSupported()) { // имаме ajax поддръжка
        xmlRequest('_sender.php?show=ajax', "window.location.href='"+url+"'");
    }
}