var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1 && navigator.appVersion.indexOf("MSIE 6")<10;

var tm;
var stop_scroll=true;
function start_scroll(_id,direction){
	if(stop_scroll) return;
	_root=document.getElementById(_id).getElementsByTagName("span")[0];
	max_shift=_root.parentNode.offsetWidth-_root.offsetWidth+2;
	if(_root.offset==0 && direction==1) return;
	if(_root.offset<max_shift && direction==0) return;
	//alert(_root.offsetWidth+" "+_root.parentNode.offsetWidth);
	_root.offset+=(direction?10:-10);
	_root.style.marginLeft=_root.offset+"px";
	if(_root.offset<max_shift || _root.offset==0){
		stop_scroll=false;
		return;
	}
	delay=(document.all && !window.opera ? 40 : 25);
	tm = setTimeout("start_scroll('"+_id+"',"+direction+")",delay);
	 
}

if(IE6)
	window.onscroll=function (){
		document.getElementById("footer").style.top=Number(document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("footer").clientHeight)+"px";
	}


//addEvent(window, "load", function(){_("contents").style.minHeight=document.body.offsetHeight-225+"px"}) 
	
	
var ie=(document.all && !window.opera?1:0);

function init_bookmark(_id,count){
       sum=0;
       sum2=0;
       bcount=count;
       _root=document.getElementById(_id);

//alert(_id+' = '+_root.offsetWidth);
       if ( _root == null ) return;

       _root.setAttribute("cur_field","d_0");
       _root.cur_field=0;
       objs=_root.getElementsByTagName("a");

       objs[0].className="act";
       for(i=0; i<objs.length;i++) {
               //document.getElementById(_root.id+"_fld_"+i).style.display="none";
               objs[i].id=_root.id+"_a_"+i;
               objs[i].name=i;
               objs[i].href=i+1;
               objs[i].onclick=function() {
                       _root=this.parentNode.parentNode;
                       document.getElementById(_root.id+"_a_"+_root.cur_field).className="";
                       this.className="act";
                       document.getElementById(_root.id+"_fld_"+_root.cur_field).style.display="none";
                       if(!ie) document.getElementById(_root.id+"_fld_"+this.name).className="field complete";
                       document.getElementById(_root.id+"_fld_"+this.name).style.display="block";
                       _root.cur_field=this.name;
                       return false;
               }
			
               sum+=objs[i].offsetWidth+1;
               if(count && count==i+1)
                       if(sum<100) count++;
                       else sum2=sum;
       }
       if(!ie) document.getElementById(_root.id+"_fld_"+_root.cur_field).className="field complete";
       document.getElementById(_root.id+"_fld_"+_root.cur_field).style.display="block";

       _img1=document.getElementById(_root.id+"_img1");
       _img2=document.getElementById(_root.id+"_img2");
       if(sum2<sum && bcount<objs.length){
               _fst=_root.getElementsByTagName("span")[0];
               _fst.setAttribute("offset",0);
               _fst.offset=0;


               _img1.className=_img2.className="arr";
               _img1.name=_img2.name=_root.id;
               _img1.onmouseover=function(){stop_scroll=false; start_scroll(this.name,1)}
               _img1.onmouseout=function(){stop_scroll=true;}
               _img2.onmouseover=function(){stop_scroll=false; start_scroll(this.name,0)}
               _img2.onmouseout=function(){stop_scroll=true; }
               _img2.style.marginLeft=Number(sum2+4)+"px";
               }
       else _img1.style.display=_img2.style.display="none";

       objs[0].parentNode.style.width=sum+"px";
       if(sum2){
               objs[0].parentNode.parentNode.style.width=sum2+"px";
               for(i=0; i<objs.length;i++)
                       document.getElementById(_root.id+"_fld_"+objs[i].name).style.width=sum2-11+"px";
       }
//       alert(sum);
}


function set_width(_cblock,fix){
	_cblock=document.getElementById(_cblock);
	var blockquote=_cblock.parentNode.parentNode.parentNode;
	var title=blockquote.getElementsByTagName("span")[0];
	_cblock.className="cc fl";
	var w=_cblock.offsetWidth>title.offsetWidth?_cblock.offsetWidth:title.offsetWidth;
	blockquote.style.width=Number(w+36)+"px";
	_cblock.className="cc";
}

function close_dialog(_sender_name) {
	_obj=document.getElementById(_sender_name);
	_obj.parentNode.parentNode.parentNode.style.visibility="hidden"; 
	
	
}
/*
function show_dialog(_obj){
	_dialog=document.getElementById(_obj).parentNode.parentNode.parentNode;
	_dialog.style.left=Number(coord.x+5)+"px";
	_dialog.style.top=Number(coord.y+5)+"px";
	_dialog.style.visibility="visible";
}
*/
function show_dialog(_id,pos){
	_dialog=_(_id).parentNode.parentNode.parentNode;
	
	set_width(_id);
	
	if(pos!="center") pos_dialog_by_cursor(_id);
	else pos_dialog_by_center(_id);
	
	
	_dialog.style.visibility="visible";
	return false;
}

function pos_dialog_by_cursor(_obj){
	_dialog=_(_obj).parentNode.parentNode.parentNode;
	_max_left=document.body.offsetWidth-_dialog.offsetWidth-20;
	_left=Number(coord.x+5);
	_top=Number(coord.y+5);
	
	if((document.documentElement.clientHeight<coord.y-document.documentElement.scrollTop+_dialog.offsetHeight) && (coord.y-30 >= _dialog.offsetHeight)) 
		_top-=_dialog.offsetHeight+60;
	_dialog.style.left=(_max_left>_left?_left:_max_left)+"px";
	_dialog.style.top=_top+"px";
}

function pos_dialog_by_center(_obj){
	_obj=_(_obj).parentNode.parentNode.parentNode;
	_scrTop=document.documentElement.scrollTop;
	if(ie) document.body.style.overflow="hidden";
	_t=Math.round((document.body.offsetHeight/2)-_obj.offsetHeight+110+_scrTop);
	_l=Math.round((document.body.offsetWidth/2-_obj.offsetWidth+40));
	_obj.style.top=_t+"px";
	_obj.style.left=_l+"px";
	if(ie){
		document.body.style.overflow="visible";
		window.scrollTo(0, _scrTop);
	}
}


function init_dialogs(){
	objs=document.getElementById("dialog").getElementsByTagName("blockquote");
	for(i=0; i<objs.length;i++) {
		set_width(objs[i].getElementsByTagName("div")[5].id);
		init_move_obj(objs[i]);
		}

	objs=document.getElementById("dialog").getElementsByTagName("a");
	for(i=0; i<objs.length;i++) 
		if(objs[i].parentNode.parentNode.parentNode.className=="top"){
			objs[i].href="close";
			objs[i].onclick=function() { 
				this.parentNode.parentNode.parentNode.parentNode.style.visibility="hidden";
                if (document.getElementById('testh'))
                {
                    //change_div_visibility();
                    hide_subpage_form();
                }
//				ifrm = _("gToday:contrast:agenda.js");
//				alert(ifrm);
//				alert(typeof(gfPop));
//				if (typeof(gfPop) == "object") {delete(gfPop);}
//				alert('type = '+typeof(gfPop)+'  name = '+gfPop.name);
//				alert(gfPop.name);
//				alert(self.gfPop);
//				alert(gfPop.fStartPop);
				return false;
			}
		}
}



var cur;
function hblock_exec(block,op){
	if(cur && cur.id!=""){
		cur.style.display="none";
		document.getElementById("but_"+cur.id).className="";
		}
	document.getElementById(block).style.display=(op?"block":"none");
	document.getElementById("but_"+block).className=(op?"act":"");
	cur=document.getElementById(block);
	return false;
}



function copy2Clipboard(text_block){
	if (document.body.createTextRange) {
        var BodyRange = document.body.createTextRange(); 
        BodyRange.moveToElementText(text_block); 
        BodyRange.execCommand('Copy');  
      } else {
         alert(_MENU_COPY_LINK_DO_NOT_WORK_);
      }
      return false;
}


/*--only for CMS */

function add_shadow(name, path){
if(path==null) path="";
	document.write("<style> ."+name+" {");
	if(document.all && !window.opera) {
		if (/MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32") {
		document.write("filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='imgs/"+path+name+".png', sizingMethod='crop');");
    	}
    } 
	else if (document.getElementById) {
    document.write("background:url('imgs/"+path+name+".png') no-repeat;");
	}
	document.write("}</style>");
}


//*/


function CheckAZ09Only( str ) {
	re = /^[a-zA-Z0-9\-_]+$/;
	if (! str.match(re) ) {
		return false;
	}
	return true;
}

function CheckMail(str) {
	
	re = /^[a-zA-Z0-9\-_\.]+@[a-zA-Z0-9\-_\.]+\.[a-zA-Z0-9]+?$/ ;
	if (! str.match(re) ) {
		return false;
	}
	return true;


}


function CheckValues( form, name ) {
	for ( i =0; i < form.elements.length; i++ ) {
		var str = form.elements[i].name;
		if ( str.indexOf(name+'[') == 0) {
			if ( form.elements[i].value == "" ) {
				return false;
			} else {
				return true;
			}
		}
	}
	return true;
}



function CollectValues( form, name ) {
	count = 0;
	for ( i =0; i < form.elements.length; i++ ) {
		var str = form.elements[i].name;
		if ( str.indexOf(name+'[') == 0 )
			count++;
	}
	
	
	arr = new Array(count);
	for ( i =0; i < form.elements.length; i++ ) {
		var str = form.elements[i].name;
		if ( str.indexOf(name+'[') == 0 ) {
			ind = str.substring( str.indexOf('[')+1,str.indexOf(']') );
			//alert( str + ' ' + str.indexOf( '[' ) + ' ' +  str.indexOf(']') + ' ' + ind );
			arr[ind] = form.elements[i];
		}
	}
	return arr;
}


function GetRadioValue ( form, name ) {
	for ( i =0; i < form.elements.length; i++ ) {
		var str = form.elements[i].name;
		if ( str ==  name ) {
			if ( form.elements[i].checked == true ) {
				return form.elements[i].value;
			}
		}
	}
	return null;
}

/*
function UserSubmitForm() {
	
	form = document.getElementById('userform');

	for ( i =0; i < form.elements.length; i++ ) {
		var str = form.elements[i].name;
		if ( str.indexOf('!') == 0 ) {
			if (form.elements[i].value == ""  ) {
				alert(_PAGE_FORM_REQUEIRED_NOT_ENTERED_);
				return false;
			}
		}
	}

	return formchecker(form);

}


function formchecker(theForm) {
	var allvalid = true;
	var alertstr = "";
	var num_of_elements = theForm.length;
	var radios = "";
	var checkboxes = "";

	for (var i=0; i<num_of_elements; i++) {
		var theElement = theForm.elements[i];
		var element_type = theElement.type;
		var element_name = theElement.name;
		var element_value = theElement.value;
		var element_required = (element_name.indexOf ("!") == 0) ? true : false;

// Muss dieses element geprueft werden?
		if (element_required) {

// Textfelder pruefen...
			if (element_type == "text") {
				if (element_value.length == 0) {
					alertstr += "Das Feld '" + element_name.replace(/ _obligatorisch/, '').replace(/_obligatorisch/, '') + "' erfordert eine Eingabe.\n\n";
					allvalid = false;
				}
			}

// Mehrzeilige Textfelder pruefen...
			if (element_type == "textarea") {
				if (element_value.length == 0) {
					alertstr += "Das Feld '" + element_name.replace(/ _obligatorisch/, '').replace(/_obligatorisch/, '') + "' erfordert eine Eingabe.\n\n";
					allvalid = false;
				}
			}

// Dropdown-Menues pruefen...
			if (element_type.indexOf("select") > -1) {
				var index = theElement.selectedIndex;
				if (index <= 0) {
					alertstr += "Das Dropdownmen? '" + element_name.replace(/ _obligatorisch/, '').replace(/_obligatorisch/, '') + "' erfordert eine Auswahl.\n\n";
					allvalid = false;
				}
			}

// Radio-buttons pruefen...
			if (element_type == "radio" ) {
				if (theElement.checked == true) {
					radios += element_name;
				}
			}

// Checkboxen pruefen...
			if (element_type == "checkbox") {
				if (theElement.checked == true) {
					checkboxes += element_name;
				}
			}

// Buttons pruefen...
			if (element_type == "button") {
				// Buttons nicht pruefen - onClick event verwenden, um Functionen aufzurufen.
			}

// Ende des zu pruefenden Bereichs?
		}

 	// .... Ende der Schleife durch die einzelnen Form-Elemente ....
	}

// Schleife durch Radio-Buttons und Checkboxen fuer die Pruefung
	for (var i=0; i<num_of_elements; i++) {
		var theElement = theForm.elements[i];
		var element_type = theElement.type;
		var element_name = theElement.name;
		var element_required = (element_name.indexOf ("_obligatorisch") > 0) ? true : false;
		if (element_type == "radio" && element_required && radios.indexOf (element_name) == -1) {
			alertstr += "Die Radio-Buttons '" + element_name.replace(/ _obligatorisch/, '').replace(/_obligatorisch/, '') + "' erfordern eine Auswahl.\n\n";
			radios += element_name;
			allvalid = false;
		}
		if (element_type == "checkbox" && element_required && checkboxes.indexOf (element_name) == -1) {
			alertstr += "Die Checkbox '" + element_name.replace(/ _obligatorisch/, '').replace(/_obligatorisch/, '') + "'  erfordert eine Auswahl.\n\n";
			checkboxes += element_name;
			allvalid = false;
		}
	}


// Alle Elemente wurden geprueft - jetzt wird ermittelt, ob das Formular korrekt ausgefuellt wurde oder nicht...
	if (allvalid) {
		return true; 
	} else {
		alert (alertstr);
		return false;
	}
}

*/


function UserSubmitForm() {

	form = document.getElementById('userform');

       for ( i =0; i < form.elements.length; i++ ) {
               var str = form.elements[i].name;
//               alert(i+') '+form.elements[i].name+' = '+form.elements[i].value);
//               alert(form.elements[i].name+' = '+form.elements[i].value);
               if ( str.indexOf('!') == 0 ) {
                       if(form.elements[i].type=="checkbox"){
                               if(!form.elements[i].checked){
                                       alert(_PAGE_FORM_REQUEIRED_NOT_ENTERED_);
                                       return false;
                               }
                       }
                       else if(form.elements[i].type=="radio"){
                               ok=0;
                               el=form.elements[i].name;
                               for ( j =0; j < form.elements[el].length; j++ ) {
                                       if(form.elements[el][j].checked){
                                               ok=1;
                                               break;
                                       }
                               }
                               if(!ok){
                                       alert(_PAGE_FORM_REQUEIRED_NOT_ENTERED_);
                                       return false;
                               }
                       }
                       else if (form.elements[i].value == ""  ) {
                               alert(_PAGE_FORM_REQUEIRED_NOT_ENTERED_);
                               return false;
                       }
               }
       }
return true;

}


function RegisterLang(id) {

	_lang=(navigator.language?navigator.language:navigator.userLanguage);

	JsHttpRequest.query(
        '/module.php',
        { 
			module: id,
			lang: _lang
		}, 
        function(responseJS, responseText) {
			//alert (responseText);
        },
        true
	);
	//alert(_lang);
	
}





function _(_id){
	if(document.getElementById && document.getElementById(_id)) return document.getElementById(_id);
	else return null;
}


function addEvent(parent, ev, func){
	if (parent.attachEvent) parent.attachEvent('on'+ev, func);
	else parent.addEventListener(ev, func, true);
}


function init_wysiwyg_icons(root){
	root=(root && root.tagName)?root:document;
	objs=root.getElementsByTagName("*");
	for(i=0;i<objs.length;i++){
		if(objs[i].getAttribute("wi"))
		{	//alert(objs[i].getAttribute("wi"));
			var t;
			(objs[i].insertBefore(t=document.createElement("i"), objs[i].firstChild)).className="wi wi_"+objs[i].getAttribute("wi");
			t.innerHTML="&nbsp;";
		}
		if(objs[i].ondblclick)
			objs[i].onmouseup=function(e){
				but=(window.event?event.button:e.button);
				if((window.event && but!=1) || (!window.event && but==2)){
					this.ondblclick()
				}
			}
	}
			
	initPNG(document);
}

//init png in IE6
function initPNG(root){
	//return false;
	if(!IE6) return false;
	var all=root.getElementsByTagName("*");
	var src;
	for(var i in all){
		if(all[i].currentStyle && all[i].currentStyle["backgroundAttachment"]!="fixed"){
			var src=all[i].tagName.toLowerCase()=="img" ? all[i].src : all[i].currentStyle["backgroundImage"];
			if( !(/\.png/i).test(src)) continue;
			if(all[i].tagName.toLowerCase()=="img"){
				all[i].style.width=all[i].offsetWidth;
				all[i].style.height=all[i].offsetHeight;
				all[i].src=IMGS_PATH+"dot.gif"; 
			}
			else src=src.replace(/url\(\"(.*)\"\)$/i,"$1");
			
			var sizing=all[i].currentStyle["backgroundRepeat"]=="no-repeat"?"crop":"scale";
			all[i].style["filter"]="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod="+sizing+")";
			all[i].style["backgroundImage"]="none";
			all[i].style["backgroundPosition"]="-1000px -1000px";
		}
	}
}



function init_script(root){
	if(typeof root=="string") root=document.getElementById(root);
	objs=root.getElementsByTagName("script");
	
	for(i=0;i<objs.length;i++){
		var func=(new Function(objs[i]?objs[i].innerHTML:""));
		func.apply(objs[i]); //normal script execution
	}
}

var COOKIE={
    set:function(name, value, expire) {
        if(expire){
            var d=new Date();
            d.setTime(d.getTime()+expire*1000);
            expire="; expires="+d.toUTCString();
        }
        else expire="";
        document.cookie=name+"="+escape(value)+expire+"; path=/";
    },
    get:function(name) {
        if(document.cookie.length==0) return false;
        var offset=document.cookie.indexOf(name+"=");
        if(offset!=-1) { 
            offset+=name.length+1;
            var end=document.cookie.indexOf(";", offset);
            if (end==-1) end=document.cookie.length;
            return unescape(document.cookie.substring(offset, end)) 
        }
        return false;
    }
};/* AJAX JavaScript kernel */

function JsHttpRequest() { this._construct() }
(function() { // to create local-scope variables
    var COUNT       = 0;
    var PENDING     = {};
    var CACHE       = {};

    // Called by server script on data load. Static.
    JsHttpRequest.dataReady = function(id, text, js) {
        var undef;
        var th = PENDING[id];
        delete PENDING[id];
       if (th) {
            delete th._xmlReq;
            if (th.caching && th.hash) CACHE[th.hash] = [text, js];
            th._dataReady(text, js);
        } else if (th !== false) {
            throw "JsHttpRequest.dataReady(): unknown pending id: " + id;
        }
    }

    // Simple interface for most popular use-case.
    JsHttpRequest.query = function(url, content, onready, nocache) {
        var req = new JsHttpRequest();
        req.caching = !nocache;
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                onready(req.responseJS, req.responseText);
            }
        }
        req.open(null, url, true);
        req.send(content);
    },
    
    JsHttpRequest.prototype = {
        // Standard properties.
        onreadystatechange: null,
        readyState:         0,
        responseText:       null,
        responseXML:        null,
        status:             200,
        statusText:         "OK",
        // JavaScript response array/hash
        responseJS:         null,

        // Additional properties.
        session_name:       "PHPSESSID",  // set to SID cookie or GET parameter name
        caching:            false,        // need to use caching?
        loader:             null,         // loader to use ('form', 'script', 'xml'; null - autodetect)

        // Internals.
        _span:              null,
        _id:                null,
        _xmlReq:            null,
        _openArg:           null,
        _reqHeaders:        null,
        _maxUrlLen:         2000,

        dummy: function() {}, // empty constant function for ActiveX leak minimization

        abort: function() {
            if (this._xmlReq) {
                this._xmlReq.abort();
                this._xmlReq = null;
            }
            this._cleanupScript();
            this._changeReadyState(4, true); // 4 in IE & FF on abort() call; Opera does not change to 4.
        },

        open: function(method, url, asyncFlag, username, password) {
            // Append SID to original URL.
            var sid = this._getSid();
            if (sid) url += (url.indexOf('?')>=0? '&' : '?') + this.session_name + "=" + this.escape(sid);
            this._openArg = {
                method:     (method||'').toUpperCase(),
                url:        url,
                asyncFlag:  asyncFlag,
                username:   username != null? username : '',
                password:   password != null? password : ''
            };
            this._id = null;
            this._xmlReq = null;
            this._reqHeaders = [];
            this._changeReadyState(1, true); // compatibility with XMLHttpRequest
            return true;
        },
        
        send: function(content) {
            this._changeReadyState(1, true); // compatibility with XMLHttpRequest

            var id = (new Date().getTime()) + "" + COUNT++;
            var url = this._openArg.url; 

            // Prepare to build QUERY_STRING from query hash.
            var queryText = [];
            var queryElem = [];
            if (!this._hash2query(content, null, queryText, queryElem)) return;

            var loader = (this.loader||'').toLowerCase();
            var method = this._openArg.method;
            var xmlReq = null;
            if (queryElem.length && !loader) {
                // Always use form loader if we have at least one form element.
                loader = 'form';
            } else {
                // Try to obtain XML request object.
                xmlReq = this._obtainXmlReq(id, url)
            }

            // Full URL if parameters are passed via GET.
            var fullGetUrl = url + (url.indexOf('?')>=0? '&' : '?') + queryText.join('&');

            // Solve hashcode BEFORE appending ID and check if cache is already present.
            this.hash = null;
            if (this.caching && !queryElem.length) {
                this.hash = fullGetUrl;
                if (CACHE[this.hash]) {
                    var c = CACHE[this.hash];
                    this._dataReady(c[0], c[1]);
                    return false;
                }
            }

            // Detect loader and method. (Yes, lots of code and conditions!)
            var canSetHeaders = xmlReq && (window.ActiveXObject || xmlReq.setRequestHeader); 
            if (!loader) {
                // Auto-detect loader.
                if (xmlReq) {
                    // Can use XMLHttpRequest.
                    loader = 'xml';
                    switch (method) {
                        case "POST":
                            if (!canSetHeaders) {
                                // Use POST method. Pass query in request body.
                                // Opera 8.01 does not support setRequestHeader, so no POST method.
                                loader = 'form';
                            }
                            break;
                        case "GET":
                            // Length of the query is checked later.
                            break;
                        default:
                            // Method is not set: auto-detect method.
                            if (canSetHeaders) {
                                method = 'POST';
                            } else {
                                if (fullGetUrl.length > this._maxUrlLen) {
                                    method = 'POST';
                                    loader = 'form';
                                } else {
                                    method = 'GET';
                                }
                            }
                    }
                } else {
                    // Cannot use XMLHttpRequest.
                    loader = 'script';
                    switch (method) {
                        case "POST":
                            loader = 'form';
                            break;
                        case "GET":
                            // Length of the query is checked later.
                            break;
                        default:
                            if (fullGetUrl.length > this._maxUrlLen) {
                                method = 'POST';
                                loader = 'form';
                            } else {
                                method = 'GET';
                            }
                    }
                }
            } else if (!method) {
                // Loader is pre-defined, but method is not set.
                switch (loader) {
                    case 'form':
                        method = 'POST';
                        break;
                    case 'script':
                        method = 'GET';
                        break;
                    default:
                        if (canSetHeaders) {
                            method = 'POST';
                        } else {
                            method = 'GET';
                        }
                }
            }

            // Correct GET URL.
            var requestBody = null;
            if (method == 'GET') {
                url = fullGetUrl;
                if (url.length > this._maxUrlLen) return this._error('Cannot use so long query (URL is ' + url.length + ' byte(s) length) with GET request.');
            } else if (method == 'POST') {
                requestBody = queryText.join('&');
            } else {
                return this._error('Unknown method: ' + method + '. Only GET and POST are supported.');
            }

            // Append loading ID to URL: a=aaa&b=bbb&<id>
            url = url + (url.indexOf('?')>=0? '&' : '?') + 'JsHttpRequest=' + id + '-' + loader;

            // Save loading script.
            PENDING[id] = this;

            // Send the request.
            switch (loader) {
                case 'xml':
                    // Use XMLHttpRequest.
                    if (!xmlReq) return this._error('Cannot use XMLHttpRequest or ActiveX loader: not supported');
                    if (method == "POST" && !canSetHeaders) return this._error('Cannot use XMLHttpRequest loader or ActiveX loader, POST method: headers setting is not supported');
                    if (queryElem.length) return this._error('Cannot use XMLHttpRequest loader: direct form elements using and uploading are not implemented');
                    this._xmlReq = xmlReq;
                    var a = this._openArg;
                    this._xmlReq.open(method, url, a.asyncFlag, a.username, a.password);
                    if (canSetHeaders) {
                        // Pass pending headers.
                        for (var i=0; i<this._reqHeaders.length; i++)
                            this._xmlReq.setRequestHeader(this._reqHeaders[i][0], this._reqHeaders[i][1]);
                        // Set non-default Content-type. We cannot use 
                        // "application/x-www-form-urlencoded" here, because 
                        // in PHP variable HTTP_RAW_POST_DATA is accessible only when 
                        // enctype is not default (e.g., "application/octet-stream" 
                        // is a good start). We parse POST data manually in backend 
                        // library code.
                        this._xmlReq.setRequestHeader('Content-Type', 'application/octet-stream');
                    }
                    // Send the request.
                    return this._xmlReq.send(requestBody);

                case 'script':
                    // Create <script> element and run it.
                    if (method != 'GET') return this._error('Cannot use SCRIPT loader: it supports only GET method');
                    if (queryElem.length) return this._error('Cannot use SCRIPT loader: direct form elements using and uploading are not implemented');
                    this._obtainScript(id, url);
                    return true;

                case 'form':
                    // Create & submit FORM.
                    if (!this._obtainForm(id, url, method, queryText, queryElem)) return null;
                    return true;

                default:
                    return this._error('Unknown loader: ' + loader);
            }
        },

        getAllResponseHeaders: function() {
            if (this._xmlReq) return this._xmlReq.getAllResponseHeaders();
            return '';
        },
            
        getResponseHeader: function(label) {
            if (this._xmlReq) return this._xmlReq.getResponseHeader(label);
            return '';
        },

        setRequestHeader: function(label, value) {
            // Collect headers.
            this._reqHeaders[this._reqHeaders.length] = [label, value];
        },


        //
        // Internal functions.
        //

        // Constructor.
        _construct: function() {},

        // Do all work when data is ready.
        _dataReady: function(text, js) { with (this) {
            if (text !== null || js !== null) {
                status = 4;
                responseText = responseXML = text;
                responseJS = js;
            } else {
                status = 500;
                responseText = responseXML = responseJS = null;
            }
            _changeReadyState(2);
            _changeReadyState(3);
            _changeReadyState(4);
            _cleanupScript();
        }},

        // Called on error.
        _error: function(msg) {
            throw (window.Error? new Error(msg) : msg);
        },

        // Create new XMLHttpRequest object.
        _obtainXmlReq: function(id, url) {
            // If url.domain specified and differ from current, cannot use XMLHttpRequest!
            // XMLHttpRequest (and MS ActiveX'es) cannot work with different domains.
            var p = url.match(new RegExp('^[a-z]+://(.*)', 'i'));
            if (p) {
                var curHost = document.location.host.toLowerCase();
                if (p[1].substring(0, curHost.length).toLowerCase() == curHost) {
                    url = p[1].substring(curHost.length, p[1].length);
                } else {
                    return null;
                }
            }
            
            // Try to use built-in loaders.
            var req = null;
            if (window.XMLHttpRequest) {
                try { req = new XMLHttpRequest() } catch(e) {}
            } else if (window.ActiveXObject) {
                try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
                if (!req) try { req = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
            }
            if (req) {
                var th = this;
                req.onreadystatechange = function() { 
                    if (req.readyState == 4) {
                        // Avoid memory leak by removing closure.
                        req.onreadystatechange = th.dummy;
                        th.status = null;
                        try { 
                            // In case of abort() call, req.status is unavailable and generates exception.
                            // But req.readyState equals to 4 in this case. Stupid behaviour. :-(
                            th.status = req.status;
                            th.responseText = req.responseText;
                        } catch (e) {}
                        if (!th.status) return;
                        var funcRequestBody = null;
                        try {
                            // Prepare generator function & catch syntax errors on this stage.
                            eval('funcRequestBody = function() {\n' + th.responseText + '\n}');
                        } catch (e) {
                            return th._error("JavaScript code generated by backend is invalid!\n" + th.responseText)
                        }
                        // Call associated dataReady() outside try-catch block 
                        // to pass excaptions in onreadystatechange in usual manner.
                        funcRequestBody();
                    }
                };
                this._id = id;
            }
            return req;
        },

        // Create new script element and start loading.
        _obtainScript: function(id, href) { with (document) {
            // Oh shit! Damned stupid fucked Opera 7.23 does not allow to create SCRIPT 
            // element over createElement (in HEAD or BODY section or in nested SPAN - 
            // no matter): it is created deadly, and does not respons on href assignment.
            // So - always create SPAN.
            var span = createElement('SPAN');
            span.style.display = 'none';
            body.insertBefore(span, body.lastChild);
            span.innerHTML = 'Text for stupid IE.<s'+'cript></' + 'script>';
            setTimeout(function() {
                var s = span.getElementsByTagName('script')[0];
                s.language = 'JavaScript';
                if (s.setAttribute) s.setAttribute('src', href); else s.src = href;
            }, 10);
            this._id = id;
            this._span = span;
        }},

        // Create & submit form.
        _obtainForm: function(id, url, method, queryText, queryElem) {
            // In case of GET method - split real query string.
            if (method == 'GET') {
                queryText = url.split('?', 2)[1].split('&');
                url = url.split('?', 2)[0];
            }

            // Create invisible IFRAME with temporary form (form is used on empty queryElem).
            var div = document.createElement('DIV');
            div.id = 'jshr_d_' + id;
            div.style.position = 'absolute';
            div.style.visibility = 'hidden';
            div.innerHTML = 
                '<form enctype="multipart/form-data"></form>' + // stupid IE, MUST use innerHTML assignment :-(
                '<iframe src="javascript:\'\'" name="jshr_i_' + id + '" style="width:0px; height:0px; overflow:hidden; border:none"></iframe>';
            var form = div.getElementsByTagName('FORM')[0];
            var iframe = div.getElementsByTagName('IFRAME')[0];

            // Check if all form elements belong to same form.
            if (queryElem.length) {
                // If we have at least one form element, we use its form as POST container.
                form = queryElem[0][1].form;
                var foundFile = false;
                for (var i = 0; i < queryElem.length; i++) {
                    var e = queryElem[i][1];
                    if (!e.form) {
                        return this._error('Element "' + e.name + '" do not belongs to any form!');
                    }
                    if (e.form != form) {
                        return this._error('Element "' + e.name + '" belongs to different form. All elements must belong to the same form!');
                    }
                    foundFile = foundFile || (e.tagName.toLowerCase() == 'input' && (e.type||'').toLowerCase() == 'file');
                }
                var et = "multipart/form-data";
                if (form.enctype != et && foundFile) {
                    return this._error('Attribute "enctype" of elements\' form must be "' + et + '" (for IE), "' + form.enctype + '" given.');
                }
            }

            // Temporary disable ALL form elements in 'form' (including custom!).
            for (var i = 0; i < form.elements.length; i++) {
                var e = form.elements[i];
                if (e.name != null) {
                    e.jshrSaveName = e.name;
                    e.name = '';
                }
            }

            // Insert hidden fields to the form.
            var tmpE = [];
            for (var i=0; i<queryText.length; i++) {
                var pair = queryText[i].split('=', 2);
                var e = document.createElement('INPUT');
                e.type = 'hidden';
                e.name = unescape(pair[0]);
                e.value = pair[1] != null? unescape(pair[1]) : '';
                form.appendChild(e);
                tmpE[tmpE.length] = e;
            }

            // Enable custom form elements back & change their names.
            for (var i = 0; i < queryElem.length; i++) queryElem[i][1].name = queryElem[i][0];

            // Insert generated form inside the document.
            // Be careful: don't forget to close FORM container in document body!
            document.body.insertBefore(div, document.body.lastChild);
            this._span = div;

            // Temporary modify form attributes, submit form, restore attributes back.
            var sv = {};
            sv.enctype  = form.enctype;  form.enctype = "multipart/form-data";
            sv.action   = form.action;   form.action = url;
            sv.method   = form.method;   form.method = method;
            sv.target   = form.target;   form.target = iframe.name;
            sv.onsubmit = form.onsubmit; form.onsubmit = null;
            form.submit();
            for (var i in sv) form[i] = sv[i];
            
            // Remove generated temporary hidden elements from form.
            for (var i = 0; i < tmpE.length; i++) tmpE[i].parentNode.removeChild(tmpE[i]);

            // Enable all disabled elements back.
            for (var i = 0; i < form.elements.length; i++) {
                var e = form.elements[i];
                if (e.jshrSaveName != null) {
                    e.name = e.jshrSaveName;
                    e.jshrSaveName = null;
                }
            }
        },

        // Remove last used script element (clean memory).
        _cleanupScript: function() {
            var span = this._span;
            if (span) {
                this._span = null;
                setTimeout(function() {
                    // without setTimeout - crash in IE 5.0!
                    span.parentNode.removeChild(span);
                }, 50);
            }
            if (this._id) {
                // Mark this loading as aborted.
                PENDING[this._id] = false;
            }
            return false;
        },

        // Convert hash to QUERY_STRING.
        // If next value is scalar or hash, push it to queryText.
        // If next value is form element, push [name, element] to queryElem.
        _hash2query: function(content, prefix, queryText, queryElem) {
            if (prefix == null) prefix = "";
            if (content instanceof Object) {
                for (var k in content) {
                    var v = content[k];
                    if (v instanceof Function) continue;
                    var curPrefix = prefix? prefix+'['+this.escape(k)+']' : this.escape(k);
                    if (this._isFormElement(v)) {
                        var tn = v.tagName.toLowerCase();
                        if (tn == 'form') {
                            // This is FORM itself. Add all its elements.
                            for (var i=0; i<v.elements.length; i++) {
                                var e = v.elements[i];
                                if (e.name) queryElem[queryElem.length] = [e.name, e];
                            }
                        } else if (tn == 'input' || tn == 'textarea' || tn == 'select') {
                            // This is a single form elemenent.
                            queryElem[queryElem.length] = [curPrefix, v];
                        } else {
                            return this._error('Invalid FORM element detected: name=' + (e.name||'') + ', tag=' + e.tagName);
                        }
                    } else if (v instanceof Object) {
                        this._hash2query(v, curPrefix, queryText, queryElem);
                    } else {
                        // We MUST skip NULL values, because there is no method
                        // to pass NULL's via GET or POST request in PHP.
                        if (v === null) continue;
                        queryText[queryText.length] = curPrefix + "=" + this.escape('' + v);
                    }
                }
            } else {
                queryText = [content];
            }
            return true;
        },

        // Return true if e is any form element of FORM itself.
        _isFormElement: function(e) {
            // Fast & dirty method.
            return e && e.ownerDocument && e.parentNode && e.parentNode.appendChild && e.tagName;
        },

        // Return value of SID based on QUERY_STRING or cookie
        // (PHP compatible sessions).
        _getSid: function() {
            var m = document.location.search.match(new RegExp('[&?]'+this.session_name+'=([^&?]*)'));
            var sid = null;
            if (m) {
                sid = m[1];
            } else {
                var m = document.cookie.match(new RegExp('(;|^)\\s*'+this.session_name+'=([^;]*)'));
                if (m) sid = m[2];
            }
            return sid;
        },

        // Change current readyState and call trigger method.
        _changeReadyState: function(s, reset) { with (this) {
            if (reset) {
                status = statusText = responseJS = null;
                responseText = '';
            }
            readyState = s;
            if (onreadystatechange) onreadystatechange();
        }},

        // Stupid JS escape() does not quote '+'.
        escape: function(s) {
            return escape(s).replace(new RegExp('\\+','g'), '%2B');
        }
    }
})();
//document.oncontextmenu=function(){return false;}

var cur;
var coord;
document.onmousedown=function(e){
	//*
	//but=(window.event?event.button:e.button);
	coord=Coord(e);
	/*
	if((window.event && but!=1) || (!window.event && but==2)){
		preventEvent(e);
		sender=(window.event?event.srcElement:e.target);
		sender.onmouseup=sender.ondblclick;//function(e){eval(sender.ondblclick(e))};
		cur=sender;
		return false;
	} 
	//*/
};

document

document.onmouseup=function(){if(cur)cur.onmouseup=null;}


var gwidth;
var gheight;
var drag_obj;
var g_zindex=150;
var onmousemove_bak;

function Coord(e){
	if(window.event){
		this.x=window.event.clientX;
		this.y=window.event.clientY;
	}
	else{
		this.x=e.pageX;
		this.y=e.pageY;
	}
	return this;
}



function preventEvent(e){
	if(window.event){
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	}
	else if (e.preventDefault) e.preventDefault();
}





function init_move_obj(obj){
	obj.getElementsByTagName("div")[0].onmousedown=function(e){startdrag(this.parentNode,e)}
	obj.getElementsByTagName("div")[0].style.cursor="move";
	//obj.style.position="absolute";
	//obj.style.marginLeft=0;
	//obj.style.marginTop=0;
	obj.style.left=obj.offsetLeft+"px";
	obj.style.top=obj.offsetTop+"px";
}


function startdrag(obj,e){
	preventEvent(e);
	//obj.style.zIndex=g_zindex++;
	gwidth=Coord(e).x-obj.offsetLeft;
	gheight=Coord(e).y-obj.offsetTop;
	drag_obj=obj;
	document.onmouseup=function(e){ enddrag(e)}
	onmousemove_bak=document.onmousemove;
	document.onmousemove=function(e){ move(e)}
}


function move(e){
	if(drag_obj){ 
		preventEvent(e);
		drag_obj.style.left=Coord(e).x-gwidth+"px";
		drag_obj.style.top=Coord(e).y-gheight+"px";
	}
}


function enddrag(obj,e){
	if(drag_obj){
		drag_obj=null;
		document.onmouseup=null;
		document.onmousemove=onmousemove_bak;
	}
}
var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1 && navigator.appVersion.indexOf("MSIE 6")<10;

function init_panels(){
	if(IE6 && document.getElementById("panel_left"))
		window.onscroll=function (){
			obj1=document.getElementById("panel_left");
			obj2=document.getElementById("panel_right");
			status=document.documentElement.scrollTop;
			obj1.style.top=obj2.style.top=document.documentElement.scrollTop+"px";
		}
}

/*
function showAdminPanel() {
	_obj = document.getElementById('admin_panel').parentNode.parentNode.parentNode;
	_obj.style.top=Number(50)+"px";
	_obj.style.left=Number(100)+"px";
	_obj.style.visibility = "visible";
}
*/

function showAdminPanel() {
     ie=(document.all && !window.opera?1:0);
     _obj = document.getElementById('admin_panel').parentNode.parentNode.parentNode;
	 set_width('admin_panel')
     document.body.style.height="100%";
	_scrTop=document.documentElement.scrollTop;
	if(ie) document.body.style.overflow="hidden";
	_t=Math.round((document.body.offsetHeight-_obj.offsetHeight)/2);
	_l=Math.round((document.body.offsetWidth-_obj.offsetWidth)/2);
	_obj.style.top=Number((_t<5?5:_t)+_scrTop)+"px";
	_obj.style.left=_l+"px";
	document.body.style.height="auto";
	if(ie){
		document.body.style.overflow="visible";
		window.scrollTo(0, _scrTop)
	}
     _obj.style.visibility = "visible";
}

/*

function showAdminPanel() {
       ie=(document.all && !window.opera?1:0);
       _obj = document.getElementById('admin_panel').parentNode.parentNode.parentNode;
       document.body.style.height="100%";
       if(ie)document.body.style.overflow="hidden";
       document.body.style.height="auto";
       if(ie)document.body.style.overflow="visible";
       _obj.style.top=Math.round((document.body.offsetHeight-_obj.offsetHeight)/2)+"px";
       _obj.style.left=Math.round((document.body.offsetWidth-_obj.offsetWidth)/2)+"px";
       _obj.style.visibility = "visible";
}

*/


function fillAdminPanel( text ) {
	document.getElementById('admin_panel').innerHTML = text;
}


function ProceedResponce ( responseJS, responseText ) {

	if ( responseJS.failed == true  ) {
		alert( responseJS.message );
	} else {
		fillAdminPanel(  responseText );
		set_width('admin_panel');
		showAdminPanel();
 		if ( responseJS.change_title == true ) {
			d = document.getElementById('admin_panel_title');
			if ( d != null )  {
				d.innerHTML = responseJS.dialog_title; 
			}		
 		}

	}

}

function LoadByID( _task, _id ) {
	JsHttpRequest.query(
        '/module.php',
		{
			module: 11,
			task: _task,
			id: _id
		}, 
		ProceedResponce,
        true 
    );
	return false;
}



function DoDelete(_task, _id) {
	
	if ( ! confirm( _ADMIN_CONFIRM_DELETE_ ) )
		return false;

	JsHttpRequest.query(
        '/module.php',
		{
			module: 11,
			task: _task,
			id: _id
		}, 
		ProceedResponce,
        true 
    );
	return false;
}



function Load(_task) {
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: 11,
			task: _task
		}, 
		ProceedResponce,
        true 
    );
	return false;
}




function load_edit_header_image(_destination,_sender,_module_id,_page_id) {
	JsHttpRequest.query(
        '/module.php',
		{
			module: _module_id,
			task: 'open_popup_menu',
			id: _destination,
			sender: _sender.name,
			page_id: _page_id
		},
		function(responseJS, responseText) {
			document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			init_bookmark("bkm_edit_dialog",3);
			set_width(responseJS.id);
        },
        true
    );
	return false;
}

function doLoad_edit_header_image(_form,_sender,_module_id,_page_id) {
//	if ( _form.file.value == "" && _form.fileURL.value == "" ) {
//			//alert( _PICTUREVOTE_ENTER_FILE_ );
//			return true;
//	}
	JsHttpRequest.query(
        '/module.php',
        {
			destination: 'edit_headerimage_dialog',
			module: _module_id,
			task: 'save_header_image',
			page_id: _page_id,
			file: _form.file,
			sender: _form.block_id,
			fileURL: _form.fileURL
		},
	    function(responseJS, responseText) {

			if ( responseJS.failed == true  ) {
       			alert( responseJS.message );
    			close_dialog(responseJS.sender);
        	} else {
				if(responseText != "")
					alert(responseText);
				close_dialog(responseJS.destination);
				window.location.reload();
			}
    },
        true
    );
	return false;
}
function load_edit_header_image_left(_destination,_sender,_module_id,_page_id) {
	JsHttpRequest.query(
        '/module.php',
		{
			module: _module_id,
			task: 'open_popup_menu',
			id: _destination,
			sender: _sender.name,
			page_id: _page_id
		},
		function(responseJS, responseText) {
			document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			init_bookmark("bkm_edit_dialog",3);
			set_width(responseJS.id);
        },
        true
    );
	return false;
}

function doLoad_edit_header_image_left(_form,_sender,_module_id,_page_id) {
//	if ( _form.file.value == "" && _form.fileURL.value == "" ) {
//			//alert( _PICTUREVOTE_ENTER_FILE_ );
//			return true;
//	}
	JsHttpRequest.query(
        '/module.php',
        {
			destination: 'edit_headerimageleft_dialog',
			module: _module_id,
			task: 'save_header_image',
			page_id: _page_id,
			file: _form.file,
			sender: _form.block_id,
			fileURL: _form.fileURL
		},
	    function(responseJS, responseText) {

			if ( responseJS.failed == true  ) {
       			alert( responseJS.message );
    			close_dialog(responseJS.sender);
        	} else {
				if(responseText != "")
					alert(responseText);
				close_dialog(responseJS.destination);
				window.location.reload();
			}
    },
        true
    );
	return false;
}
function load_add_page_dialog(_destination,_sender,_pos,_module,_task,_page,_parent,_menudivid) {//alert('load_add_page_dialog');
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: _module,
			task: _task,
			id: _destination, 
			page: _page,
			parent: _parent,
			menudivid:_menudivid,
			sender: _sender.name
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
            //init_bookmark("bkm_1","fld_1",1);
			show_dialog(responseJS.id);
			init_bookmark("bkm_add_page",3);
			set_width(responseJS.id);
			
        },
        true 
    );
	return false;
}


function doLoad_add_page_dialog(_destination,_form,_module,_task,_page,_parent) {
//	alert(_destination);
	if ( _form.txt.value == "" ) {
		alert(_MENU_ENTER_NAME_);
		return false;
	}

	if (  CheckAZ09Only( _form.txt.value ) == false ) {
		alert(_MENU_ENTER_VALID_NAME_);
		return false;
	}

	if (  null == GetRadioValue(_form,'contentelement') ) {
		alert('select page type');
		return false;
	}
	
	/*
	if ( _form.title.value == "" ) {
		alert( _MENU_ENTER_TITLE_ );
		return false;
	}
	*/
	if ( CheckValues( _form, "title" ) == false ) {
		alert(_MENU_ENTER_TITLE_);
		return false;
	}
	
	
	titles = CollectValues( _form, "title" ); 
	
    JsHttpRequest.query(
        '/module.php',
        { 
			id: _destination, 
			sender: _form.block_id, 
			module: _module,
			task: _task,
			page: _page,
			parent: _parent,
        	title: titles,
			element: GetRadioValue(_form,'contentelement'),
        	txt: _form.txt 
		}, 
        function(responseJS, responseText) { //alert(responseJS.id);
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
            	close_dialog(responseJS.sender);
        	} else {
        		if (responseJS.id == 'nav') {responseText = _BUTTOM_ + responseText; }
				document.getElementById(responseJS.id).innerHTML = responseText;
				init_wysiwyg_icons(document.getElementById(_destination));
//				if (_destination == 'top_nav') { document.getElementById('menu').innerHTML = responseText; }
            	close_dialog(responseJS.sender);
        	}
        },
        true
    );
    hide_subpage_form();
	return false;
}


function load_edit_page_dialog(_destination,_sender,_pos,_module,_task,_page,_menuid,_show_add_parent,_menudivid) {//alert(_menudivid);
    
//	alert('_destination = '+_destination);
//	alert('_sender = '+_sender);
//	alert('_pos = '+_pos);
//	alert('_module = '+_module);
//	alert('_task = '+_task);
//	alert('_page = '+_page);
//	alert('_menuid = '+_menuid);
//	alert('_show_add_parent = '+_show_add_parent);
//	alert('_menudivid = '+_menudivid);
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: _module,
			task: _task,
			id: _destination, 
			page: _page,
			menuid: _menuid,
			show_add_parent: _show_add_parent,
			menudivid:_menudivid,
			sender: _sender.name
		}, 
		function(responseJS, responseText) {// alert(responseText);
			document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			init_bookmark("bkm_edit_page",3);
			init_bookmark("bkm_editadd_page",3);
			set_width(responseJS.id);
//			alert(responseJS.id)
        },
        true 
    );
	return false;
}




function load_edit_page_dialog_reload(_destination,_sender,_pos,_module,_task,_page,_menuid,_show_add_parent,_menudivid) {//alert(_menudivid);
	
//	alert('_destination = '+_destination);
//	alert('_sender = '+_sender);
//	alert('_pos = '+_pos);
//	alert('_module = '+_module);
//	alert('_task = '+_task);
//	alert('_page = '+_page);
//	alert('_menuid = '+_menuid);
//	alert('_show_add_parent = '+_show_add_parent);
//	alert('_menudivid = '+_menudivid);
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: _module,
			task: _task,
			id: _destination, 
			page: _page,
			menuid: _menuid,
			show_add_parent: _show_add_parent,
			menudivid:_menudivid,
			sender: _sender.name
		}, 
		function(responseJS, responseText) { //alert(responseText);
			document.getElementById(responseJS.id).innerHTML = responseText;
//			show_dialog(responseJS.id);
			init_bookmark("bkm_edit_page",3);
			init_bookmark("bkm_editadd_page",3);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}



function doLoad_edit_page_dialog(_destination,_form,_module,_task,_page,_menuid) { 

	if ( _form.menuname.value == "" ) {
		alert( _MENU_EDIT_ENTER_NAME_ );
		return false;
	}
/*	
	if ( _form.menutitle.value == "" ) {
		alert( _MENU_EDIT_ENTER_TITLE_ );
		return false;
	}
*/
	
	if (  CheckAZ09Only( _form.menuname.value ) == false ) {
		alert(_MENU_ENTER_VALID_NAME_);
		return false;
	}
	
	if ( CheckValues( _form, "menutitle" ) == false ) {
		alert(_MENU_EDIT_ENTER_TITLE_);
		return false;
	}
	
	titles = CollectValues( _form, "menutitle" ); 

	
	JsHttpRequest.query(
        '/module.php',
        { 
			id: _destination, 
			sender: _form.block_id, 
			module: _module,
			task: _task,
			startdate: _form.dc1,
			enddate: _form.tdc1,
			page: _page,
			menuid: _menuid,
        	menuname: _form.menuname, 
        	menutitle: titles 
		}, 
        function(responseJS, responseText) { //alert(responseJS.id); alert(responseText);
        	//alert(document.getElementById(responseJS));
           	if ( responseJS.failed == true  ) {
	    		alert( responseJS.message );
	        	close_dialog(responseJS.sender);
	    	} else {
	    		
	    		if (responseJS.id == 'nav') {responseText = _BUTTOM_ + responseText; }
				if( responseJS.id != 'top_nav')document.getElementById(responseJS.id).innerHTML = responseText;
				init_wysiwyg_icons(document.getElementById(_destination));
//	            close_dialog(responseJS.sender);
				load_edit_page_dialog_reload('edit_page_dialog',  _form.block_id,   'b', _module, 'show_edit_page_dialog',_page,_menuid,    1,     _destination);
	    	}
	    },
        true
    );
	return false;
}

function hide_subpage_form() {
	
	document.getElementById('testh').style.visibility = 'hidden';
	return false;
}

//****************************************************************************
function change_div_visibility()
{
	
//				if (document.getElementById('testh').style.height != 'auto')
	if (document.getElementById('testh').style.visibility != 'visible')
	{
		document.getElementById('imgtesth').src = 'imgs/ico_minus.gif';
//					document.getElementById('testh').style.height = 'auto';		
//					document.getElementById('testh').style.display = 'block';		
		document.getElementById('testh').style.position = 'relative';		
		document.getElementById('testh').style.visibility = 'visible';		
	}
	else

	{

		document.getElementById('imgtesth').src = 'imgs/ico_plus.gif';
//					document.getElementById('testh').style.height = '0';
//					document.getElementById('testh').style.display = 'none';
		document.getElementById('testh').style.position = 'absolute';	
		document.getElementById('testh').style.visibility = 'hidden';			
	}
    return false;
}
					
				
			
//***************************************************************************
	

function doLoad_delete_page (_destination,_form,_module,_task,_page,_menuid) {
	
	if ( confirm( _MENU_CONFIRM_DELETE_ ) ) {

		JsHttpRequest.query(
	        '/module.php',
	        { 
				id: _destination, 
				sender: _form.block_id, 
				module: _module,
				task: _task,
				page: _page,
				menuid: _menuid,
	        	menuname: _form.menuname, 
	        	menutitle: _form.menutitle 
			}, 
	        function(responseJS, responseText) {
	          	if ( responseJS.failed == true  ) {
	        		alert( responseJS.message );
	            	close_dialog(responseJS.sender);
	        	} else {
		        	if ( responseJS.redirect != false ) {
			        		location.href = '/';
			       	} else {
			       			if (responseJS.id == 'nav') {responseText = _BUTTOM_ + responseText; }
			            	document.getElementById(responseJS.id).innerHTML = responseText;
							init_wysiwyg_icons(document.getElementById(_destination));
			            	close_dialog(responseJS.sender);
			    	}
				}
	        },
	        true
	    );
	    
	}
	return false;
}

function init_dialogs_menu( str ) {
	objs=document.getElementById( str ).getElementsByTagName("a");
	for(i=0; i<objs.length;i++) objs[i].onclick=function() { 
		this.parentNode.style.visibility="hidden"; return false
	}
}

var gform;
function save_time(obj, n) {
	gform=document.editpageform;
	self.gfPop=obj.parentNode.parentNode.getElementsByTagName("iframe")[0].contentWindow;
	if(self.gfPop) gfPop.fStartPop(document.editpageform.elements[n+1],document.editpageform.elements[n+2]);
}




function TimeChanged() {
	obj = document.getElementById( "date_from_text" );
	objFrom = document.getElementById( "Start_Date" );
	obj.innerHTML = objFrom.value;
	alert(objFrom.value);
}

function testfunv(DivID){
	_(DivID).style.display = 'block';
	return false;
}

function load_edit_nothelle_jobs_dialog(_sender) {
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: 17,
			task: "edit",
			id: "edit_nothellejobs",
			sender: _sender.name
			
		}, 
		function(responseJS, responseText) {
            document.getElementById("edit_nothellejobs").innerHTML = responseText;
			init_script('edit_nothellejobs');
            //init_bookmark("bkm_1","fld_1",1);
            show_dialog("edit_nothellejobs");
			init_bookmark("bkm_nothelle_jobs",3);
			set_width(responseJS.id);
			
        },
        true 
    );
	return false;
}


function DoSaveNothelleJob() {
	
	_form = document.getElementById('formnothelle');
	values = CollectValues( _form, "FCKeditorForm" ); 
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: 17,
			task: "save",
        	nothelletext: values,
			id: "edit_nothellejobs",
			sender: ""
		}, 
		function(responseJS, responseText) {
            document.getElementById("nothelle_jobs").innerHTML = responseText;
        },
        true 
    );
	return false;
	
}



// Downloads section


function load_edit_nothelle_downloads_dialog(_sender) {
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: 17,
			task: "edit_downloads",
			id: "edit_nothelledownloads",
			sender: _sender.name
		}, 
		function(responseJS, responseText) {
            document.getElementById("edit_nothelledownloads").innerHTML = responseText;
            //init_bookmark("bkm_1","fld_1",1);
			show_dialog("edit_nothelledownloads");
			init_bookmark("bkm_nothelle_downloads",3);
			set_width(responseJS.id);
			
        },
        true 
    );
	return false;
}


function DoSaveNothelleDownload() {
	
	_form = document.getElementById('formnothelle');
	values = CollectValues( _form, "FCKeditorForm" ); 
	
	JsHttpRequest.query(
        '/module.php',
		{
			module: 17,
			task: "save_downloads",
        	nothelletext: values,
			id: "edit_nothelledownloads",
			sender: ""
		}, 
		function(responseJS, responseText) {
            document.getElementById("nothelle_downloads").innerHTML = responseText;
        },
        true 
    );
	return false;
	
}

function load_add_downloads_dialog(_destination,_sender,_contentelement_id,_page) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _contentelement_id,
//			task: _task,
			destination: _destination, 
			page_id: _page,
			sender: _sender.name
		}, 
		function(responseJS, responseText) {
			document.getElementById(responseJS.destination).innerHTML = responseText;
			show_dialog(responseJS.destination);
			init_bookmark("bkm_add_dialog",3);
			set_width(responseJS.destination);
			
        },
        true 
    );
	return false;
}

function doLoad_add_downloads_dialog(_form) {

	if ( _form.title.value == "" ) {
		alert( _DOWNLOAD_ENTER_TITLE_ );
		return;
	}

	if ( _form.file.value == "" ) {
		alert( _DOWNLOAD_ENTER_FILE_ );
		return;
	}

_form.submit();

/*    JsHttpRequest.query(
        'content.php',
        { 
			destination: _destination, 
			sender: _form.destination, 
        	contentelement_id: _contentelement_id,
        	task: _task,
        	page_id: _page_id,
        	title: _form.title.value,
        	description: _form.description.value

		}, 
        function(responseJS, responseText) {
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
            	close_dialog(responseJS.sender);
        	} else {
            	document.getElementById(responseJS.destination).innerHTML = responseText;
            	close_dialog(responseJS.sender);
        	}
        },
        true
    );
*/
}

function load_edit_download_menu(_destination,_sender,_contentelement_id,_page,_download_id) {
	
		JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _contentelement_id,
			task: 'open_popup_menu',
			destination: _destination, 
			page_id: _page,
			sender: _sender.name,
			download_id: _download_id
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.destination).innerHTML = responseText;
			show_dialog(responseJS.destination);
			init_bookmark("bkm_edit_dialog",3);
			set_width(responseJS.destination);
        },
        true 
    );
	return false;
}

function doLoad_edit_download_menu(_destination,_form,_task,_contentelement_id,_page_id) {

/*	if ( _form.title.value == "" ) {
		alert( _DOWNLOAD_ENTER_TITLE_ );
		return;
	}
	*/	titles = CollectValues( _form, "title" ); 
		descriptions = CollectValues( _form, "description" ); 

    JsHttpRequest.query(
        'content.php',
        { 
			destination: _destination, 
			sender: _form.destination, 
        	contentelement_id: _contentelement_id,
        	task: _task,
        	page_id: _page_id,
        	title: titles,
        	description: descriptions,
			download_id: _form.download_id.value
		}, 
        function(responseJS, responseText) {
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
            	close_dialog(responseJS.sender);
        	} else {
            	document.getElementById(responseJS.destination).innerHTML = responseText;
                init_wysiwyg_icons(document.getElementById(responseJS.destination));
                //close_dialog(responseJS.sender);
        	}
        },
        true
    );
    return false;
}

function doLoad_delete_download(_destination,_form,_task,_contentelement_id,_page_id) {
	
	if ( confirm( _DOWNLOAD_CONFIRM_DELETE_ ) ) {

		JsHttpRequest.query(
	        'content.php',
	        { 
				destination: _destination, 
				sender: _form.destination, 
				contentelement_id: _contentelement_id,
				task: _task,
				page_id: _page_id,
				download_id: _form.download_id.value
			}, 
	        function(responseJS, responseText) {
	          	if ( responseJS.failed == true  ) {
	        		alert( responseJS.message );
	            	close_dialog(responseJS.sender);
	        	} else {
	            	document.getElementById(responseJS.destination).innerHTML = responseText;
                    init_wysiwyg_icons(document.getElementById(responseJS.destination));
	            	close_dialog(responseJS.sender);
		    	}
	        },
	        true
	    );
	    
	}
	return false;
}
function load_select_gallery_dialog(_destination,_sender,_contentelement_id,_page,_gallery) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _contentelement_id,
//			task: _task,
			id: _destination, 
			page_id: _page,
			gallery: _gallery,
			sender: _sender.name
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}

function doLoad_select_gallery_dialog(_destination,_form,_task,_contentelement_id,_page_id) {
    JsHttpRequest.query(
        'content.php',
        { 
			id: _destination, 
			sender: _form.block_id, 
        	contentelement_id: _contentelement_id,
        	task: _task,
        	page_id: _page_id,
        	gallery: _form.gallery.value
		}, 
        function(responseJS, responseText) {
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
            	close_dialog(responseJS.sender);
        	} else {
            	document.getElementById(responseJS.id).innerHTML = responseText;
            	close_dialog(responseJS.sender);
        	}
        },
        true
    );
}

function load_gallery_img(element_id, _sender, _img_path,_width){ 
    document.getElementById(element_id).innerHTML = "<img src='"+_img_path+"'>";
	//show_dialog(document.getElementById(element_id).parentNode,_sender,'b');
	show_dialog(element_id,'center');
//	set_width(element_id);
	set_width_manual(element_id,_width);
	return false;
}/*

function showUploadForm() {
        ie=(document.all && !window.opera?1:0);
        _obj = document.getElementById('pv_upload_dialog').parentNode.parentNode.parentNode;
        document.body.style.height="100%";
        if(ie)document.body.style.overflow="hidden";
        document.body.style.height="auto";
        if(ie)document.body.style.overflow="visible";
 
	_obj.style.top=Math.round((document.body.offsetHeight-_obj.offsetHeight)/2+650)+"px";
 
	_obj.style.left=Math.round((document.body.offsetWidth-_obj.offsetWidth)/2)+"px";
        _obj.style.visibility = "visible";
}

*/


function showUploadForm() {
     ie=(document.all && !window.opera?1:0);
     _obj = document.getElementById('pv_upload_dialog').parentNode.parentNode.parentNode;
     document.body.style.height="100%";
	_scrTop=document.documentElement.scrollTop;
	if(ie) document.body.style.overflow="hidden";
	_t=Math.round((document.body.offsetHeight-_obj.offsetHeight)/2);
	_l=Math.round((document.body.offsetWidth-_obj.offsetWidth)/2);
	_obj.style.top=Number((_t<5?5:_t)+_scrTop)+"px";
	_obj.style.left=_l+"px";
	document.body.style.height="auto";
	if(ie){
		document.body.style.overflow="visible";
		window.scrollTo(0, _scrTop)
	}
     _obj.style.visibility = "visible";
}

function ProceedPicResponce ( responseJS, responseText ) {
	//show_dialog(responseJS.id);
	set_width(responseJS.id);
	set_width(responseJS.id);
	showUploadForm();
	set_width(responseJS.id);
}

function Load_upload_picture_dialog(_destination, _module_id) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: '',
			id: _destination
		}, 
		function(responseJS, responseText) {
			document.getElementById(responseJS.id).innerHTML = responseText;
        	ProceedPicResponce( responseJS, responseText )
			set_width(responseJS.id);
			tooltip.init ();
        },
        true 
    );
	return false;
}


function doLoad_upload_picture_dialog(_destination, _form, _module_id) {

	if ( _form.title.value == "" ) {
		alert( _PICTUREVOTE_ENTER_TITLE_ );
		return;
	}
	if ( _form.description.value == "" ) {
		alert( _PICTUREVOTE_ENTER_DESCRIPTION_ );
		return;
	}

	if ( CheckMail( _form.email.value ) == false ) {
		alert(_ADMIN_MAIL_NOT_CORRECT_);
	    return false;
	} 

	if ( _form.file.value == "" ) {
		alert( _PICTUREVOTE_ENTER_FILE_ );
		return;
	}

	if ( ! _form.terms[0].checked ) {
		alert( _PICTUREVOTE_TERMS_NO_ );
		return;
	}

	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'upload',
			id: _destination,
			sender: _form.block_id,
			
			title: _form.title,
			description: _form.description,
			salutation: _form.salutation,
			username: _form.surname,
			lastname: _form.lastname,
			street: _form.street,
			zip: _form.zip,
			email: _form.email,
			telephone: _form.telephone,
			keywords: _form.keywords,
			newsletter: _form.newsletter[0].checked,
			comments: _form.comments[0].checked,
			file: _form.file
		}, 
		function(responseJS, responseText) {//alert('responseText = '+responseText);alert( 'responseJS.message = '+responseJS.message );
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
    			close_dialog(responseJS.sender);
        	} else {
//            	document.getElementById(responseJS.id).innerHTML = responseText;
//            	alert(document.getElementById(responseJS.id).value);
				if(responseText != "")
					alert(responseText);
				close_dialog(_destination);
        	}
        },
        true 
    );
	return false;
}



function Load_statistic_dialog(_destination, _module_id, _picture_id) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'view_statistic',
			id: _destination,
			picture_id: _picture_id
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}


function doLoad_statistic_dialog(_destination, _form, _module_id, _picture_id) {

	if ( _form.email.value == "" ) {
		alert( _PICTUREVOTE_ENTER_MAIL_ );
		return;
	}

	if ( CheckMail( _form.email.value ) == false ) {
		alert(_ADMIN_MAIL_NOT_CORRECT_);
	    return false;
	} 

	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'send_statistic',
			id: _destination,
			sender: _form.block_id,
			
			email: _form.email,
			picture_id: _picture_id
		}, 
		function(responseJS, responseText) {
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
    			close_dialog(_destination);
        	} else {
            	//document.getElementById(responseJS.id).innerHTML = responseText;
				if(responseText != "")
//				alert(responseText);
				alert("Under construction");
				//window.location = "index.php";
				close_dialog(_destination);
        	}
        },
        true 
    );
	return false;
}



function Load_comment_dialog(_destination, _module_id, _picture_id) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'comment_dialog',
			id: _destination,
			picture_id: _picture_id
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}



function doLoad_comment_dialog(_destination, _form, _module_id, _picture_id) {

	if ( _form.comment.value == "" ) {
		alert( _PICTUREVOTE_ENTER_COMMENT_ );
		return;
	}

	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'send_comment',
			id: _destination,
			sender: _form.block_id,
			
			comment: _form.comment.value,
			email: _form.email.value,
			picture_id: _picture_id
		}, 
		function(responseJS, responseText) {
        	if ( responseJS.failed == true  ) {
        		alert( responseJS.message );
    			close_dialog(_destination);
        	} else {
            	//document.getElementById(responseJS.id).innerHTML = responseText;
				if(responseText != "")
					alert(responseText);
				close_dialog(_destination);
        	}
        },
        true 
    );
	return false;
}



function Load_archive_list(_destination, _module_id){
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _module_id,
			task: 'archive',
			id: _destination
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}


function makeVote(vote){
	document.scale_form.scale.value=vote;
	document.scale_form.submit();
}
/*
* saves contenr editor
*/
function save_content_editor(_static_id, _form, _page, _contentelement_id){

	values = CollectValues( _form, "FCKeditor" ); 

	JsHttpRequest.query(
	        'content.php',
	        { 
	        	contentelement_id: _contentelement_id, //obligatory
	        	id: _static_id, 
	        	task: 'save',
				page: _page,
				text: values
 			}, 
	        function(responseJS, responseText) {
	            alert(responseText);
				elem = document.getElementById(timeoutid);
				elem.innerHTML="&nbsp;";
				start_count_idle();
	        },
	        false
	    );
	return false;
}


var timeoutid = 'time_out_message';

function start_count_idle() {
	setTimeout("printtimemessage()",1000 * 60 * 5); 
}

function printtimemessage(){
	if ( timeoutid != '' ) {
		elem = document.getElementById(timeoutid);
		elem.innerHTML=_CONTENT_EDITING_5_MINUTES_;
	}
}

function load_static_versions_dialog(_destination,_sender,_contentelement_id,_page) {
	JsHttpRequest.query(
        'content.php',
		{
			contentelement_id: _contentelement_id,
			task: 'restore_dialog',
			id: _destination, 
			page_id: _page,
			sender: _sender.name
		}, 
		function(responseJS, responseText) {
            document.getElementById(responseJS.id).innerHTML = responseText;
			show_dialog(responseJS.id);
			set_width(responseJS.id);
        },
        true 
    );
	return false;
}

