//<script language="JavaScript" type="text/javascript"> // for faking Zend syntax coloring system :-))


/* butt is HTMLElement or undefined => determines highlighting or hidding highlighting*/
/* used in group.php - watch it */
function switchDeletingRow(butt)
{
    if((!butt && !switchDeletingRow.lastRow) || (butt && !butt.parentNode)) return;
    if(butt){
        var tr = butt.parentNode.parentNode;
        switchDeletingRow.lastRow        = tr;
        switchDeletingRow.lastClassName  = tr.className;
        switchDeletingRow.lastMouseOut   = tr.onmouseout;
        switchDeletingRow.lastMouseOver  = tr.onmouseover;
        tr.onmouseout = null;
        tr.onmouseover = null;
        tr.className = 'deleting';
    }else{
        var tr = switchDeletingRow.lastRow;
        tr.className   = switchDeletingRow.lastClassName;
        tr.onmouseout  = switchDeletingRow.lastMouseOut;
        tr.onmouseover = switchDeletingRow.lastMouseOver;
    }
}
switchDeletingRow.lastRow        = null;
switchDeletingRow.lastMouseOut   = null;
switchDeletingRow.lastMouseOver  = null;
switchDeletingRow.lastClassName = '';
/*** ***** **** *** */


/*pouziva se ve spojeni s switchdeletingrow pro mazani v drawtable, viz group.php */
function deleteConfirm(confirm_text)
{
    if ( confirm(confirm_text) )
    {
        return true;
    } else {
        switchDeletingRow();
        return false;
    }
}
/*** *** **  */



function check_all_checkbox(regexp_target_names, caller) {
    var retest = new RegExp(regexp_target_names);
    var obj = find_obj(caller);

    var colection = document.getElementsByTagName('input');
    for (var i=0;i<colection.length;i++) {
        if (retest.test( colection[i].name )  && colection[i].type == "checkbox" &&  colection[i].disabled == false) {
            colection[i].checked = obj.checked;
        }
    }



}

function popup(url, name, width, height) {

    var width_screen = screen.width
    var height_screen = screen.height
    var pos_left = Math.round( (width_screen / 2) - (width / 2) )
    var pos_top = Math.round( (height_screen / 2) - (height / 2) )
    width = width + 2;
    height = height;
    var win = window.open(url,name,"maximizeable = 1, status = 0, toolbar = 0, location = 0, directories = 0, resizable = 1, copyhistory = 0, menuBar = 1, scrollbars = 1, left=" + pos_left + ", top=" + pos_top + ", width=" + width + ", height=" + height);
    //var win = window.open(url, name, "status = 0, resizable = 0, left = " + pos_left + ", top = " + pos_top + ", width = " + width + ", height = " + height);
    win.focus();
}





//fill combo
function fill_combo(obj, string, clear_all){ // string to be parsed, clear-before option (true=clear all)
    if (typeof clear_all == 'undefined') clear_all = false;
    /**
    given string must be like this: Pardubice^1|Chrudim^2|Svitavy^3|�st� nad Orlic�^4|
    and this will be produced : <option value="1">Pardubice</option><option value="2">Chrudim</option> etc.

    ---php example
    $sql = "SELECT nazev,id FROM oblasti WHERE id_kraje = '$id_kraje'";
    $res = $db->query($sql);
    while (true == ($data = $db->fetchrow($res))) echo $data[0].'^'.$data[1].'|';
    **/

    if (clear_all) while (obj.length>0) obj.options[0] = null;

    var rows = string.split(/\|/);
    for (var i=0;i<rows.length;i++) {
        if (rows[i] != '') {
            opts = rows[i].split(/\^/);
            obj.options[obj.options.length] = new Option(opts[0],opts[1]);
        }
    }
}

function combo_fill (name, values) {

    var obj = find_obj(name);
    var objLen = obj.options.length;
    for (var i=objLen-1; i>=0; i--) {
        obj.options[i] = null;
    }
    var mValue = values.split('|');
    for (var i=0; i<mValue.length; i++) {
        var tmp = mValue[i].split('^');
        var objLen = obj.options.length;
        obj.options[objLen] = new Option;
        obj.options[objLen].value = tmp[0];
        obj.options[objLen].text = tmp[1];
    }
    return true;
}
















/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* �2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/*Modified and extended by Radek Zyka */
/* Software licenced under a modified X11 licence,
see documentation or authors website for more details */

function sack(file) {
    this.xmlhttp = null;

    this.resetData = function() {
        this.method = "POST";
        this.queryStringSeparator = "?";
        this.argumentSeparator = "&";
        this.URLString = "";
        this.encodeURIString = true;
        this.encodingCharset = 'utf-8'; //windows-1250
        this.execute = false;
        this.requestFile = file;
        this.vars = new Object();
        this.responseStatus = new Array(2);
        this.running = false;
        this.async = true;
    };

    this.resetFunctions = function() {
        this.onLoading = function() { };
        this.onLoaded = function() { };
        this.onInteractive = function() { };
        this.onCompletion = function() { };
        this.onError = function() { };
        this.onFail = function() { };
    };

    this.reset = function() {
        this.resetFunctions();
        this.resetData();
    };

    this.createAJAX = function() {
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e1) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                this.xmlhttp = null;
            }
        }

        if (! this.xmlhttp) {
            if (typeof XMLHttpRequest != "undefined") {
                this.xmlhttp = new XMLHttpRequest();
            } else {
                this.failed = true;
            }
        }
    };

    this.delVar = function(RegExpName)
    {
        var retest= new RegExp(RegExpName);
        for(var key in this.vars) if(retest.test(key) ) delete this.vars[key];

    };


    this.setVar = function(name, value){
        this.vars[name] = Array(value, false);
    };

    this.encVar = function(name, value, returnvars) {
        if (true == returnvars) {
            return Array(encodeURIComponent(name), encodeURIComponent(value));
        } else {
            this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
            return true;
        }
    }

    this.processURLString = function(string, encode) {
        encoded = encodeURIComponent(this.argumentSeparator);
        regexp = new RegExp(this.argumentSeparator + "|" + encoded);
        varArray = string.split(regexp);
        for (i = 0; i < varArray.length; i++){
            urlVars = varArray[i].split("=");
            if (true == encode){
                this.encVar(urlVars[0], urlVars[1]);
            } else {
                this.setVar(urlVars[0], urlVars[1]);
            }
        }
    }

    this.createURLString = function(urlstring) {
        if (this.encodeURIString && this.URLString.length) {
            this.processURLString(this.URLString, true);
        }

        if (urlstring) {
            if (this.URLString.length) {
                this.URLString += this.argumentSeparator + urlstring;
            } else {
                this.URLString = urlstring;
            }
        }

        // prevents caching of URLString
        this.setVar("rndval", new Date().getTime());

        var urlstringtemp = new Array();
        for (key in this.vars) {
            if (false == this.vars[key][1] && true == this.encodeURIString) {
                var encoded = this.encVar(key, this.vars[key][0], true);
                delete this.vars[key];
                this.vars[encoded[0]] = Array(encoded[1], true);
                key = encoded[0];
            }

            urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
        }
        if (urlstring){
            this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
        } else {
            this.URLString += urlstringtemp.join(this.argumentSeparator);
        }
    }

    this.runResponse = function() {
        eval(this.response);
    }

    this.runAJAX = function(urlstring) {
        if (this.running) return;
        this.running = true;
        if (this.failed) {
            this.onFail();
        } else {
            this.createURLString(urlstring);
            if (this.xmlhttp) {
                var self = this;
                if (this.method == "GET") {
                    var totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
                    this.xmlhttp.open(this.method, totalurlstring, this.async);
                } else {
                    this.xmlhttp.open(this.method, this.requestFile, this.async);
                    try {
                        this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + this.encodingCharset)
                    } catch (e) { }
                }

                this.xmlhttp.onreadystatechange = function() {
                    switch (self.xmlhttp.readyState) {
                        case 1:
                        self.onLoading();
                        break;
                        case 2:
                        self.onLoaded();
                        break;
                        case 3:
                        self.onInteractive();
                        break;
                        case 4:
                        self.response = self.xmlhttp.responseText;
                        self.responseXML = self.xmlhttp.responseXML;
                        self.responseStatus[0] = self.xmlhttp.status;
                        self.responseStatus[1] = self.xmlhttp.statusText;

                        if (self.execute) {
                            self.runResponse();
                        }

                        if (self.responseStatus[0] == "200") {
                            self.onCompletion();
                        } else {
                            self.onError();
                        }

                        self.URLString = "";
                        self.running = false;
                        break;
                    }
                };

                this.xmlhttp.send(this.URLString);
            }
        }
    };

    this.reset();
    this.createAJAX();
    this.running = false;

}






/**
*
*  Crossbrowser Drag Handler
*  http://www.webtoolkit.info/
*
**/

var DragHandler = {


    // private property.
    _oElem : null,


    // public method. Attach drag handler to an element.
    attach : function(oElem) {
        oElem.onmousedown = DragHandler._dragBegin;

        // callbacks
        oElem.dragBegin = new Function();
        oElem.drag = new Function();
        oElem.dragEnd = new Function();

        return oElem;
    },


    // private method. Begin drag process.
    _dragBegin : function(e) {
        var oElem = DragHandler._oElem = this;

        if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
        if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }

        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);

        e = e ? e : window.event;
        oElem.mouseX = e.clientX;
        oElem.mouseY = e.clientY;

        oElem.dragBegin(oElem, x, y);

        document.onmousemove = DragHandler._drag;
        document.onmouseup = DragHandler._dragEnd;
        return false;
    },


    // private method. Drag (move) element.
    _drag : function(e) {
        var oElem = DragHandler._oElem;

        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);

        e = e ? e : window.event;
        oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
        oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';

        oElem.mouseX = e.clientX;
        oElem.mouseY = e.clientY;

        oElem.drag(oElem, x, y);

        return false;
    },


    // private method. Stop drag process.
    _dragEnd : function() {
        var oElem = DragHandler._oElem;

        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);

        oElem.dragEnd(oElem, x, y);

        document.onmousemove = null;
        document.onmouseup = null;
        DragHandler._oElem = null;
    }

}


String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}



/*
	var dragable1 = DragHandler.attach(document.getElementById('dragable1'));
	var dragable2 = DragHandler.attach(document.getElementById('dragable2'));
	var dragable3 = DragHandler.attach(document.getElementById('dragable3'));

	dragable1.dragBegin = begin;
	dragable1.drag = drag;
	dragable1.dragEnd = end;

	dragable2.dragBegin = begin;
	dragable2.drag = drag;
	dragable2.dragEnd = end;

	dragable3.dragBegin = begin;
	dragable3.drag = drag;
	dragable3.dragEnd = end;

*/




