var js_tools_orig_object = new Object();
var jst = js_tools_orig_object;


jst._init = {
    
    apply_anchor: function(section_name) {
        if (typeof js_tools_orig_object[section_name].anchor=="function") {
            js_tools_orig_object[section_name] = js_tools_orig_object.method.object(js_tools_orig_object[section_name].anchor,js_tools_orig_object[section_name]);
        }
    },
    
    apply_anchors: function() {
        for (var ind in js_tools_orig_object) {
            this.apply_anchor(ind);
        }
    }
    
};


jst.data = {
    
    dump: function(data,maxdepth,filter,filter_maxdepth,depth) {
        var temp=[],str="",pre="",tab="       ";
        maxdepth = (typeof maxdepth=="number")?maxdepth:3;
        depth = depth?depth:1;
        if (typeof filter=="string") {
            filter = new RegExp("^"+js_tools_orig_object.text.regex_escape(filter).replace(/\\\*/g,".*").replace(/\\\?/g,".")+"$");
        }
        for (var i=0; i<depth; i++) {
            pre += tab;
        }
        switch (typeof data) {
            case "boolean":
                str += data?"true":"false";
            break;
            case "number":
                str += data;
            break;
            case "string":
                str += "'"+data.replace(/'/g,"\\'").replace(/\\/g,"\\\\")+"'";
            break;
            case "object":
                var element_dump,multiline;
                if (data===null) {
                    str += "null";
                } else if (jst.array.check(data)) {
                    str += "/*array*/ [";
                    temp = [];
                    for (var i=0; i<data.length; i++) {
                        element_dump = this.dump(data[i],maxdepth,filter,filter_maxdepth,depth+1);
                        multiline = (element_dump.indexOf("\n")!=-1);
                        temp[temp.length] = "\n"+(multiline?"\n":"")+pre+tab+"/* "+i+" => */ "+element_dump;
                    }
                    str += temp.join(",")+"\n"+pre+"]";
                } else if (maxdepth>=depth || maxdepth==0) {
                    str += "/*object*/ {";
                    temp = [];
                    for (var index in data) {
                        if (filter && (!filter_maxdepth || depth<=filter_maxdepth) && ((typeof(filter)=="function")? (!filter(index)) : (!filter.test(index)) ) ) {
                            continue;
                        }
                        try {
                            element_dump = this.dump(data[index],maxdepth,filter,filter_maxdepth,depth+1);
                            multiline = (element_dump.indexOf("\n")!=-1);
                            temp[temp.length] = "\n"+(multiline?"\n":"")+pre+tab+"'"+index+"': "+element_dump;
                        } catch (e) {
                            temp[temp.length] = "\n"+pre+tab+"'"+index+"': null /* error! */";
                        }
                    }
                    str += temp.join(",")+"\n"+pre+"}";
                } else {
                    str += "/*object*/ 'rec!'";
                }
            break;
            case "function":
                str += "/*function*/\n\n'";
                str += data.toString();
                str += "\n";
            break;
            default:
                str += "null";
        }
        return str;
    },
    
    search: function(obj,value,parents) {
        if (typeof obj!="object") {
            return false;
        }
        parents = parents?parents:[];
        var sub_parents;
        var sub_result;
        for (var ind in obj) {
            sub_parents = parents.concat([ind]);
            if (obj[ind]==value) {
                return sub_parents;
            } else if (sub_result=this.search(obj[ind],value,sub_parents)) {
                return sub_result;
            }
        }
        return false;
    },
    
    search_index: function(obj,index,parents) {
        if (typeof obj!="object") {
            return false;
        }
        parents = parents?parents:[];
        var sub_parents;
        var sub_result;
        for (var ind in obj) {
            sub_parents = parents.concat([ind]);
            if (ind==index) {
                return sub_parents;
            } else if (sub_result=this.search_index(obj[ind],index,sub_parents)) {
                return sub_result;
            }
        }
        return false;
    },
    
    get_sub: function(obj,sub_indexes) {
        var element = obj;
        for (var i=0; i<sub_indexes.length; i++) {
            if (typeof element!="object") {
                break;
            }
            element = element[sub_indexes[i]];
        }
        return element;
    },
    
    flush: function(data,count,type) {
        var data_text = this.dump(data);
        var sep = "\n";
        if (type=="c" || type=="char" || type=="chars") {
            sep = false;
        }
        var splitted = sep?jst.text.cut(data_text,sep,count):jst.text.cut(data_text,count);
        jst.array.each(
            splitted,
            function(item,index,refs){
                if (!confirm(item)) {
                    refs.breaker[0]=true;
                }
            }
        );
    },
    
    merge: function() {
    	var result = (typeof arguments[0]=="object")?arguments[0]:{};
    	for (var i=1; i<arguments.length; i++) {
    		if (typeof arguments[i]=="object" && !jst.array.check(arguments[i]) && !this.is_empty(arguments[i])) {
    			for (var j in arguments[i]) {
    				if (arguments[i][j]!==null) {
    					result[j] = arguments[i][j];
    				}
    			}
    		} else {
    			for (var j in result) {
    				if (result[j]===null) {
    					result[j] = arguments[i];
    				}
    			}
    		}
    	}
    	return result;
    },
    
    is_empty: function (variable) {
    	if (variable==null) {
    		return true;
    	}
    	if (typeof variable!="object") {
    		return !variable;
    	}
    	if (js_tools_orig_object.array.check(variable)) {
    		return (variable.length==0);
    	}
    	for (var ind in variable) {
    		return false;
    	}
    	return true;
    }
    
};


jst.text = {
    
    htmlstrlen: function (str) {
        return str.replace(/&(\w+|#\d+);/g,"_").length;
    },
    
    htmlsubstr: function(str,start_pos,length) { // !!!
        if (typeof length=="undefined") {
            length = str.length-start_pos;
        }
        var result;
        var search_str = str;
        var results = [];
        for (var index,true_pos=0,next; (index=search_str.indexOf("&"))!=(-1); ) {
            true_pos += index;
            search_str = search_str.substr(index);
            next = search_str.replace(/^&(\w+|#\d+);/,"");
            if (search_str==next) {
                search_str = search_str.substr(1);
            } else {
                if (true_pos>=start_pos&&true_pos<start_pos+length) {
                    results[results.length] = [true_pos-start_pos,search_str.substr(0,search_str.length-next.length)];
                }
                search_str = next;
            }
            true_pos++;
        }
        result = str.replace(/&(\w+|#\d+);/g,"_").substr(start_pos,length);
        for (var i=results.length-1; i>=0; i--) {
            result = result.substr(0,results[i][0])+results[i][1]+result.substr(results[i][0]+1);
        }
        return result;
    },
    
    htmlspecialchars: function (str) {
        return str.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
    },
    
    trim: function(str,type) {
        switch (type) {
            case "l":
            case "left":
                return str.replace(/^\s+/g,"");
            break;
            case "r":
            case "right":
                return str.replace(/\s+$/g,"");
            break;
            case "both":
            default:
                return str.replace(/^\s+|\s+$/g,"");
        }
    },
    
    cut: function(str,delim,count) {
        var delim_str = "";
        if (!delim) {
            delim = false;
            count = 1;
        } else if (typeof delim=="number") {
            count = delim;
            delim = false;
        } else if (typeof delim=="string") {
            delim_str = delim;
            delim = new RegExp(js_tools_orig_object.text.regex_escape(delim));
        } else {
            delim_str = "\n";
        }
        if (!count) {
            count = 1;
        }
        var elements = [];
        if (delim) {
            var pieces = str.split(delim);
            var pc = Math.floor(pieces.length/count);
            for (var i=0; i<pc; i++) {
                elements[elements.length] = pieces.slice(i*count,(i+1)*count).join(delim_str);
            }
            if (pieces.length>pc*count) {
                elements[elements.length] = pieces.slice(pc*count).join(delim_str);
            }
        } else {
            var pc = Math.floor(str.length/count);
            for (var i=0; i<pc; i++) {
                elements[elements.length] = str.substring(i*count,(i+1)*count);
            }
            if (str.length>pc*count) {
                elements[elements.length] = str.substring(pc*count);
            }
        }
        return elements;
    },
    
    split: function(str,delim,show_empty,show_matches) {
        if (!show_empty && !show_matches) {
            return str.split(delim);
        }
        if (typeof delim=="string") {
            delim = new RegExp(this.regex_escape(delim),"g");
        }
        var matches = str.match(delim);
        var pieces = [];
        var start_pos = 0;
        var search_text = str;
        for (var i=0,pos; i<matches.length; i++) {
            pos = search_text.indexOf(matches[i]);
            pieces[pieces.length] = search_text.substr(0,pos);
            if (show_matches) {
                pieces[pieces.length] = matches[i];
            }
            search_text = search_text.substr(pos+matches[i].length);
        }
        pieces[pieces.length] = search_text;
        if (!show_empty) {
            for (var i=pieces.length-1; i>=0; i--) {
                if (pieces[i]=="") {
                    pieces.splice(i,1);
                }
            }
        }
        return pieces;
    },
    
    regex_escape: function(str) {
        return str.replace(/([\/\\\.\*\?\-\+\[\]\{\}\(\)])/g,"\\$1");
    }
    
};


jst.array = {
    
    check: function(variable) {
		return (typeof variable==='object' && typeof variable.length==='number' && typeof variable.splice==='function');
	},
		
	each: function(arr,func,start,end,keep_empty) {
        start = (typeof start=="number")?start:0;
        end = (typeof end=="number")?end:arr.length;
        var result = [];
        var breaker = [false];
        var refs = {breaker:[false],data:{}};
        for (var i=start,res; i<end; i++) {
            refs.breaker[0] = false;
            res = func(arr[i],i,refs);
            if (refs.breaker[0]) {
                break;
            }
            if (!keep_empty || res!==null) {
                result[result.length] = res;
            }
        }
        return result;
    }
    
};


jst.method = {
    
    _start_regex: /^\s*function\s*([a-zA-Z_\$][a-zA-Z_0-9\$]*\s*)?\(((\s*[a-zA-Z_\$][a-zA-Z_0-9\$]*\s*,)*\s*[a-zA-Z_\$][a-zA-Z_0-9\$]*\s*)?\)\s*\{\s*/,
    _end_regex: /\s*\}\s*$/,
    
    code: function(func) {
        var code = func.toString();
        code = code.replace(this._start_regex,"").replace(this._end_regex,"")
        return code;
    },
    
    params: function(func) {
        var code = func.toString();
        var param_list = code.substring(code.indexOf("(")+1,code.indexOf(")")).replace(/ /g,"");
        if (param_list=="") {
            return [];
        }
        return param_list.split(",");
    },
    
    create: function(code,params) {
        params = params?params:[];
        var param_list = params.join('","');
        if (params.length>0) {
            param_list = '"'+param_list+'",';
        }
        var res;
        eval('res = new Function('+param_list+'"'+code.replace(/"/g,'\\"').replace(/\r?\n/g," ")+'");');
        return res;
    },
    
    copy: function(func) {
        var code = this.code(func);
        var params = this.params(func);
        return this.create(code,params);
    },
    
    object: function(func,obj) {
        var res_obj = this.copy(func);
        if (typeof obj=="object") {
            for (var ind in obj) {
                res_obj[ind] = obj[ind];
            }
        }
        return res_obj;
    }
    
};


jst.select = { // prefName típusú neveket átírni! (használatukat ellenőrizni!)
    
    set: function(obj, value) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        for (var i=0; i<obj.options.length; i++) {
            if (obj[i].value==value) {
                obj[i].selected = true;
                return true;
            }
        }
        return false;
    },
    
    set_multi: function(obj, value) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        for (var i=0; i<obj.options.length; i++) {
            obj[i].selected = (obj[i].value==value);
        }
        return false;
    },
    
    add: function(obj, value, label, selected) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        selected = (typeof selected=="undefined")?false:selected;
        new_opt = new Option(label,value);
        new_opt.selected = selected;
        try {
            obj.add(new_opt);
        } catch (e) {
            obj.add(new_opt,null);
        }
    },
    
    load: function(obj, values, labels, keep) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        var temp;
        keep = keep && obj.selectedIndex;
        if (keep) {
            temp = obj.options[obj.selectedIndex].value;
        }
        obj.options.length = 0;
        var new_opt,value,label;
        for (var i=0; i<values.length; i++) {
            value = values[i];
            label = (typeof labels=="string")?
                labels
                : ((labels&&labels.length&&labels[i])?labels[i]:value);
            this.add(obj,value,label);
        }
        if (keep) {
            this.set(obj,temp);
        }
    },
    
    load_optgroup: function(obj, values, labels) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        var childs = obj.childNodes;
        for (var i=0; i<childs.length; i++) {
            obj.removeChild(childs[i]);
        }
        for (var i=0; i<values.length; i++) {
            value = values[i];
            label = (typeof labels=="string")?
                labels
                : ((labels&&labels.length&&labels[i])?labels[i]:value);
            var new_option = new Option();
            new_option.value = value;
            obj.appendChild(new_option);
            new_option.appendChild(document.createTextNode(label));
        }
    },
    
    option_move: function(from,to,select) {
        var sel_from = (typeof from=="string")?document.getElementById(from):from;
        var sel_to = (typeof to=="string")?document.getElementById(to):to;
        var opt_insert;
        for (var i=sel_from.options.length-1; i>=0; i--) {
            if (sel_from.options[i].selected) {
                opt_insert = document.createElement("option");
                sel_to.options.add(opt_insert);
                opt_insert.text = sel_from.options[i].text;
                opt_insert.value = sel_from.options[i].value;
                opt_insert.selected = select?true:false;
                sel_from.remove(i);
            }
        }
    },
    
    remove_selected: function(obj) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        for (var i=obj.options.length-1; i>=0; i--) {
            if (obj.options[i].selected) {
                obj.remove(i);
            }
        }
    },

    get_values: function(obj, all) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        var results = [];
        for (var i=0; i<obj.options.length; i++) {
            if (all || obj.options[i].selected) {
                results[results.length] = obj.options[i].value;
            }
        }
        return results;
    },

    get_label: function(obj,join) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        join = join?join:",";
        var label;
        if (obj.size) {
            var labels = [];
            for (var i=0; i<obj.options.length; i++) {
                if (obj.options[i].selected) {
                    labels[labels.length] = obj.options[i].text;
                }
            }
            label = labels.join(join);
        } else if (obj.selectedIndex>-1) {
            label = obj.options[obj.selectedIndex].text;
        } else {
            label = "";
        }
        return label;
    },

    get_label_by_value: function(obj,value) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        for (var i=0; i<obj.options.length; i++) {
            if (obj.options[i].value==value) {
                return obj.options[i].text;
            }
        }
    },

    blur: function(obj) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        if (obj.size) {
            for (var i=0; i<obj.options.length; i++) {
                obj.options[i].selected = false;
            }
        } else {
            obj.selectedIndex = 0;
        }
    },

    empty: function(obj) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        for (var i=obj.options.length-1; i>=0; i--) {
            obj.remove(i);
        }
    },

    set_abc: function(obj) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        var temp_id,temp_label,temp_select,end;
        var last_end = obj.options.length-1;
        for (var i=0; i<obj.options.length-1; i++) {
            end = 0;
            for (var j=0; j<Math.min(last_end,obj.options.length-i-1); j++) {
                if (obj.options[j].text.toLowerCase()>obj.options[j+1].text.toLowerCase()) {
                    end = j;
                    temp_id = obj.options[j].value;
                    temp_label = obj.options[j].text;
                    temp_select = obj.options[j].selected;
                    obj.options[j].value = obj.options[j+1].value;
                    obj.options[j].text = obj.options[j+1].text;
                    obj.options[j].selected = obj.options[j+1].selected;
                    obj.options[j+1].value = temp_id;
                    obj.options[j+1].text = temp_label;
                    obj.options[j+1].selected = temp_select;
                }
            }
            last_end = end;
        }
    }
    
};


jst.radio = {
    
    anchor: function(obj,value) {
        if (typeof value=="undefined") {
            return js_tools_orig_object.radio.get(obj);
        }
        return js_tools_orig_object.radio.set(obj,value);
    },

    set: function(obj,value) {
        obj = (typeof obj=="string")?document.getElementsByName(obj):obj;
        if (typeof obj.length=="undefined") {
            obj.checked = (obj.value==value);
            return true;
        }
        for (var i=0; i<obj.length; i++) {
            if (obj[i].value==value) {
                obj[i].checked = true;
                return true;
            }
        }
        return false;
    },
    
    get: function(obj) {
        obj = (typeof obj=="string")?document.getElementsByName(obj):obj;
        if (typeof obj.length=="undefined") {
            return obj.checked?obj.value:"";
        }
        for (var i=0; i<obj.length; i++) {
            if (obj[i].checked) {
                return obj[i].value;
            }
        }
        return "";
    },
    
    blur: function(obj) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        if (typeof obj.length=="undefined") {
            obj.checked = false;
            return true;
        }
        for (var i=0; i<obj.length; i++) {
            if (obj[i].checked) {
                obj[i].checked = false;
                break;
            }
        }
        return false;
    },
    
    attr: function(obj,name,value) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        if (typeof obj.length=="undefined") {
            obj[name] = value;
            return true;
        }
        for (var i=0; i<obj.length; i++) {
            obj[i][name] = value;
        }
    }

};

jst.screen = {
    
    anchor: function() {
        return js_tools_orig_object.screen.screen();
    },
    
    pos: function (obj,outer,noscroll) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        outer = outer?((typeof outer=="string")?document.getElementById(outer):outer):document.body;
        var result = new Object();
        result.top = obj.offsetTop-(noscroll?0:obj.scrollTop);
        result.left =  obj.offsetLeft-(noscroll?0:obj.scrollLeft);
        var parent = obj.offsetParent;
        while (parent&&parent!=outer) {
            result.top += parent.offsetTop-(noscroll?0:parent.scrollTop);
            result.left += parent.offsetLeft-(noscroll?0:parent.scrollLeft);
            result.top += (parent.style.borderTopWidth?parent.style.borderTopWidth:(parent.style.borderWidth?parent.style.borderWidth:"0")).replace(/[^0-9]*$/,"")*1;
            result.left += (parent.style.borderLeftWidth?parent.style.borderLeftWidth:(parent.style.borderWidth?parent.style.borderWidth:"0")).replace(/[^0-9]*$/,"")*1;
            parent = parent.offsetParent;
        }
        if (document.all) {
            result.top += 2;
            result.left += 2;
        }
        return result;
    },
    
    stick: function(obj,obj_to,type,offset,outer) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        obj_to = (typeof obj_to=="string")?document.getElementById(obj_to):obj_to;
        outer = outer?((typeof outer=="string")?document.getElementById(outer):outer):document.body;
        js_tools_orig_object.dom.move(obj,outer);
        type = type?type:"tl";
        offset = offset?offset:[0,0];
        offsets = this.pos(obj_to,outer);
        switch (type) {
            case "tr":
                offsets.left = offsets.left+obj_to.offsetWidth-obj.offsetWidth;
            break;
            case "bl":
                offsets.top = offsets.top+obj_to.offsetHeight-obj.offsetHeight;
            break;
            case "br":
                offsets.top = offsets.top+obj_to.offsetHeight-obj.offsetHeight;
                offsets.left = offsets.left+obj_to.offsetWidth-obj.offsetWidth;
            break;
        }
        offsets.top += offset[0];
        offsets.left += offset[1];
        obj.style.position = "absolute";
        obj.style.top = offsets.top+"px";
        obj.style.left = offsets.left+"px";
    },
    
    client: function(win) {
        win = win?win:window;
        var result = { width: 0, height: 0 };
        if (typeof win.innerWidth=='number') {
            result.width = win.innerWidth;
            result.height = win.innerHeight;
        } else if (win.document.documentElement && (win.document.documentElement.clientWidth||win.document.documentElement.clientHeight)) {
            result.width = win.document.documentElement.clientWidth;
            result.height = win.document.documentElement.clientHeight;
        } else if (win.document.body && (win.document.body.clientWidth||win.document.body.clientHeight)) {
            result.width = win.document.body.clientWidth;
            result.height = win.document.body.clientHeight;
        }
        return result;
    },
    
    scrollable: function(win) {
        win = win?win:window;
        var result = {
            v: Math.max(0,win.document.body.scrollHeight-this.client(win).height),
            h: Math.max(0,win.document.body.scrollWidth-this.client(win).width)
        }
        return result;
    },
    
    screen: function() {
        return {width:window.screen.width,height:window.screen.height};
    }
    
};


jst.display = {

    opacity: function(obj,opacity) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        if (document.all) {
            obj.style.filter = "alpha(opacity="+(opacity*100)+")";
        } else if (typeof obj.style.opacity!="undefined") {
            obj.style.opacity = opacity;
        } else if (typeof obj.style.MozOpacity!="undefined") {
            obj.style.MozOpacity = opacity;
        }
    },
    
    cover: function(id,opacity,color,z_index,win) {
        win = win?win:window;
        win.document.body.style.overflow = "hidden";
        var cover_div = document.createElement("div");
        if (id) {
            cover_div.id = id;
        }
        cover_div.innerHTML = "&nbsp;";
        cover_div.style.position = "absolute";
        this.cover_align(cover_div,win);
        this.opacity(cover_div,opacity?opacity:0.5);
        cover_div.style.backgroundColor = color?color:"#999999";
        cover_div.style.zIndex = z_index?z_index:1000;
        win.document.body.appendChild(cover_div);
        return cover_div;
    },
    
    cover_align: function(cover_div,win) {
        win = win?win:window;
        var dims = js_tools_orig_object.screen.client(win);
        cover_div.style.top = win.document.body.scrollTop+"px";
        cover_div.style.left = win.document.body.scrollLeft+"px";
        cover_div.style.width = dims.width+"px";
        cover_div.style.height = dims.height+"px";
    },
    
    // le kellene kezelni, hogy most csak saját styleSheet meglétekor kezeli a styleSheetekeket!
    // pl:
    //  div_with_empty_style = document.createElement("div");
    //  div_with_empty_style.innerHTML = "<style>.asdfghjkasghfkahgfk { } </style>"; // style hack
    //  div_with_empty_style.style.display = "none";
    //  document.body.appendChild(div_with_empty_style);
    // kipróbálni!
    get_css: function(name,attr) {
        var styles = document.styleSheets;
        if (!styles || !styles.length) {
            return; // !!! meg lehetne próbálni létrehozni...
        }
        for (var i=0,rules; i<styles.length; i++) {
            rules = styles[i].cssRules?styles[i].cssRules:styles[i].rules;
            for (var j=0; j<rules.length; j++) {
                if (rules[j].selectorText.toLowerCase()==name.toLowerCase()) {
                    return (typeof attr=="undefined")?rules[j].style:rules[j].style[attr];
                }
            }
        }
        return null;
    },
    
    set_css: function(name,attr,value) { // !!! fogadjon style(-szerű) objektumot is
        var styles = document.styleSheets;
        if (!styles || !styles.length) {
            return; // !!! meg lehetne próbálni létrehozni...
        }
        for (var i=0,rules; i<styles.length; i++) {
            rules = styles[i].cssRules?styles[i].cssRules:styles[i].rules;
            for (var j=0; j<rules.length; j++) {
                if (!attr) {
                    if (styles[i].removeRule) {
                        styles[i].removeRule(j);
                    } else {
                        styles[i].deleteRule(j);
                    }
                    return;
                }
                if (rules[j].selectorText.toLowerCase()==name.toLowerCase()) {
                    if (value===null) {
                        rules[j].style.removeAttribute(attr);
                    } else {
                        rules[j].style[attr] = value;
                    }
                    return;
                }
            }
        }
        if (value==null) {
            return;
        }
        var st = document.styleSheets[0];
        if (st.insertRule) {
            var rules = st.cssRules?st.cssRules:st.rules;
            st.insertRule(name+" { "+attr+": "+value+"; }", rules.length);
        } else {
            st.addRule(name,attr+": "+value);
        }
    },
    
    del_css: function(name,attr) {
        this.set_css(name,attr,null);
    }

};


jst.scroll = {
    
    _win: window,
    _timer: null,
    _moving: false,
    _callback: null,
    
    set_win: function(win) {
        this._win = win;
    },
    
    down: function(timeout,height,callback) {
        this.stop();
        this._moving = true;
        this._move(timeout,height*1);
        this._callback = callback;
    },
    
    up: function(timeout,height,callback) {
        this.stop();
        this._moving = true;
        this._move(timeout,0-height);
        this._callback = callback;
    },
    
    _move: function(timeout,diff) {
        var new_pos = this._win.document.body.scrollTop+diff;
        if (new_pos<0) {
            this._win.document.body.scrollTop = 0;
            this.stop();
            return;
        }
        var maxpos = Math.max(0,document.body.scrollHeight-document.body.clientHeight);
        if (new_pos>maxpos) {
            this._win.document.body.scrollTop = maxpos;
            if (this._callback) {
                this._callback(new_pos,"end");
            }
            this.stop();
            return;
        }
        this._win.document.body.scrollTop = new_pos;
        if (this._callback) {
            this._callback(new_pos,"move");
        }
        this._timer = setTimeout("jst.scroll._move("+timeout+","+diff+")",timeout);
    },
    
    stop: function() {
        try {
            clearTimeout(this._timer);
        } catch (e) {}
        this._moving = false;
    }

};


jst.php = {
    
    htmlspecialchars: function (str) {
        return  js_tools_orig_object.text.htmlspecialchars(str);
    },
    
    base64_decode: function (data) {
        var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, h1, h2, h3, h4, bits, ac = 0;
        if (!data) {
            return false;
        }
        data = data.toString();
        var i = 0;
        var tmp_arr = [];
        do {
            h1 = b64.indexOf(data.charAt(i++));
            h2 = b64.indexOf(data.charAt(i++));
            h3 = b64.indexOf(data.charAt(i++));
            h4 = b64.indexOf(data.charAt(i++));

            bits = h1<<18 | h2<<12 | h3<<6 | h4;

            o1 = bits>>16 & 0xff;
            o2 = bits>>8 & 0xff;
            o3 = bits & 0xff;

            if (h3 == 64) {
                tmp_arr[ac++] = String.fromCharCode(o1);
            } else if (h4 == 64) {
                tmp_arr[ac++] = String.fromCharCode(o1, o2);
            } else {
                tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
            }
        } while (i < data.length);
        return tmp_arr.join('');
    },
    
    base64_encode: function(data) {
        var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];
        
        if (!data) {
            return data;
        }
        
        do {
            o1 = data.charCodeAt(i++);
            o2 = data.charCodeAt(i++);
            o3 = data.charCodeAt(i++);
            
            bits = o1<<16 | o2<<8 | o3;
            
            h1 = bits>>18 & 0x3f;
            h2 = bits>>12 & 0x3f;
            h3 = bits>>6 & 0x3f;
            h4 = bits & 0x3f;
            
            tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
        } while (i < data.length);
        
        enc = tmp_arr.join('');
        
        switch (data.length % 3) {
            case 1:
                enc = enc.slice(0, -2) + '==';
            break;
            case 2:
                enc = enc.slice(0, -1) + '=';
            break;
        }
        
        return enc;
    },
    
    array_search: function (element,array,strict) {
        for (var i=0; i<array.length; i++) {
            if (strict?(array[i]===element):(array[i]==element)) {
                return i;
            }
        }
        return false;
    },
    
    in_array: function (element,array,strict) {
        return (this.array_search(element,array,strict)!==false);
    }

};


jst.http = {

    get_vars: function(win) {
        var search_text = window.location.search;
        if (typeof win=="string") {
            var ind = win.indexOf("?");
            search_text = (ind==-1)?"":win.substr(ind);
        } else if (win && win.location) {
            search_text = win.location.search;
        }
        var result = new Object();
        if (search_text.length) {
            var searches = search_text.replace(/^\?/,"").split("&");
            for (var i=0,key_value; i<searches.length; i++) {
                key_value = searches[i].split("=");
                result[key_value[0]] = key_value[1];
            }
        }
        return result;
    },
    
    get: function(name,win) {
        var vars = this.get_vars(win);
        return vars[name];
    }
    
};


jst.dom = {
    
    anchor: function(selector_text) {
        return js_tools_orig_object.dom.list(selector_text);
    },
    
    list: function(selector_text) { // !!!
        
    },
    
    move: function(obj,obj_to) {
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        obj_to = (typeof obj_to=="string")?document.getElementById(obj_to):obj_to;
        obj_to.appendChild(this.remove(obj));
    },
    
    remove: function(obj) {
    	try {
    		obj.parentNode.removeChild(obj);
    	} catch (e) { }
    	return obj;
    },
    
    empty: function(obj) { // !!!
        obj = (typeof obj=="string")?document.getElementById(obj):obj;
        obj.innerHTML = "";
    }
    
}


jst.cookie = {

    get: function(name) {
        var result = null;
        if (document.cookie && document.cookie.length>0) {
            var cookies = document.cookie.split(';');
            for (var i=0,cookie; i<cookies.length; i++) {
                cookie = js_tools_orig_object.text.trim(cookies[i]);
                if (cookie.substring(0,name.length+1)==(name+'=')) {
                    return decodeURIComponent(cookie.substring(name.length+1));
                }
            }
        }
        return null;
    },
    
    set: function(name,value,options) {
        options = options || {};
        if (value===null) {
            value = '';
            options.expires = -1;
        }
        var date = false;
        if (typeof options.expires=='number') {
            date = new Date();
            date.setTime(date.getTime()+(options.expires*24*3600*1000));
        } else if (options.expires && options.expires.toUTCString) {
            date = options.expires;
        }
        document.cookie = name+"="+encodeURIComponent(value)
            +(date?'; expires='+date.toUTCString():'')
            +(options.path?'; path='+(options.path):'')
            +(options.domain?'; domain='+(options.domain):'')
            +(options.secure?'; secure':'');
    },
    
    del: function(name) {
        this.set(name,null);
    }

}


jst.ajax = { // !!! TODO
	
	default_params: {
		method: "get",
		url: "",
		datas: {},
		callback: function(){},
		context: null,
		type: "text", // !!! json check, xml
		onerror: function(){}, // !!! minden lehetseges hibahoz!
		timeout: 0, // !!! timer ha nem ready(4): abort() + onerror(...,"timeout")
		async: true,
		wait: false,
		username: null, // !!! open(...
		password: null, // !!! open(...
		cache: false // !!! timestamp az url-be!
		// !!! callback a tobbi ready state-hez is?
	},
	
    get: function(url,callback,type,params) {
		params = params?params:{};
		params.method = "get";
		params.url = url;
		params.callback = callback;
		params.type = type;
        return this.complex(params);
    },
    
    post: function(url,datas,callback,type,params) {
		params = params?params:{};
		params.method = "post";
		params.url = url;
		params.datas = datas;
		params.callback = callback;
		params.type = type;
        return this.complex(params);
    },
    
	complex: function(params) {
    	var send_params = js_tools_orig_object.data.merge(this.default_params,params);
    	var req = new js_tools_orig_object.ajax._request_abstract(send_params);
    	return req;
    },
    
    _request_abstract: function (params) {
    	this.params = params;
        var datas_strs = [];
        if (this.params.datas) {
	        for (var ind in this.params.datas) {
	        	datas_strs[datas_strs.length] = ind+"="+encodeURI(this.params.datas[ind]);
	        }
        }
        this.data_string = datas_strs.join("&");
        this.state = null;
        this.request = new Object();
        if (window.XMLHttpRequest) {
             this.request = new XMLHttpRequest();
        } else if (typeof ActiveXObject!=undefined) {
            try {
            	this.request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                	this.request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) { }
            }
        }
        this.request.abstract = this;
        this.state = this.request.readyState;
        this.result = "";
        this.request.open(this.params.method,this.params.url,this.params.async);
        this.state = this.request.readyState;
        this.onsuccess = function(resp) {
            switch (this.params.type) {
	            case "json":
	                if (this.request.responseText) {
	                    try {
	                    	eval("resp="+this.request.responseText+";");
	                    } catch (e) { }
	                }
	            break;
	            case "text":
	            default:
	            	resp = this.request.responseText;
            }
        	this.result = resp;
            if (typeof this.params.callback=="function") {
            	if (this.params.context) {
            		this.params.callback.call(this.params.context,resp);
            	} else {
            		this.params.callback(resp);
            	}
            } else if (typeof this.params.callback=="string") {
            	var obj = this.params.context?this.params.context:window;
            	var tokens = this.params.callback.split(".");
            	var funcname = tokens[tokens.length-1];
            	for (var i=0; i<tokens.length-1; i++) {
            		try {
            			obj = obj[tokens[i]];
            		} catch (e) {
            			return;
            		}
            	}
            	try {
            		obj[funcname](resp);
            	} catch (e) { }
            }
            
        }
        this.request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        this.request.setRequestHeader("Content-length",this.data_string.length);
        this.request.setRequestHeader("Connection","close");
        this.request.onreadystatechange = function() {
            this.abstract.state = this.readyState;
            switch (this.readyState) {
                case 4:
                    this.abstract.onsuccess(this.responseText);
                break;
            }
        };
        this.started = false;
        this.start = function() {
        	if (!this.started) {
        		this.request.send((this.params.method=="post")?this.data_string:null);
        	}
        	this.started = true;
        }
        if (!this.params.wait) {
        	this.start();
        }
        if (!this.params.async) {
        	this.onsuccess(this.request.responseText);
        }
    },
    
    create_iframe: function(name) {
        if (window.ActiveXObject) {
            var frame = document.createElement('<iframe id="'+id+'" name="'+id+'" />');
            frame.src = 'javascript:false';
        } else {
            var frame = document.createElement('iframe');
            frame.id = name;
            frame.name = name;
        }
        return frame;
    }
    
}


jst.application = { // FIXME: fejlesztes alatt
	
	ready_callbacks: [],
	ready_timer: null,
	ready_inited: false,
	ready_success: false,
	
	ready: function(callback) {
		if (typeof callback=="function") {
			this.ready_callbacks.push(callback);
		} else if (jst.array.check(callback)) {
			this.ready_callbacks = this.ready_callbacks.concat(callback);
		}
		if (!this.ready_inited) {
			this.ready_init();
		}
	},
    
    ready_init: function() {
    	this.ready_inited = true;
    	if (document.addEventListener) {
    		document.addEventListener("DOMContentLoaded",function(){
    			js_tools_orig_object.application._ready_run();
    		},false);
    	} else if (document.all && !window.opera) {
		    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
		    document.getElementById("contentloadtag").onreadystatechange = function() {
		        if (this.readyState=="complete") {
		        	js_tools_orig_object.application._ready_run();
		        }
		    }
		} else if (/Safari/i.test(navigator.userAgent)) {
			this.ready_timer = setInterval(function(){
				if (/loaded|complete/.test(document.readyState)) {
					var handler = js_tools_orig_object.application;
					clearInterval(handler.ready_timer);
					handler._ready_run();
				}
			},20)
		}
		window.onload = function() { // FIXME: kell ez?
			setTimeout(function(){
				var handler = js_tools_orig_object.application;
				if (!handler.ready_success) {
					handler._ready_run();
				}
			},0);
		}
    },
    
    _ready_run: function() {
    	this.ready_success = true;
    	for (var i=0; i<this.ready_callbacks.length; i++) {
			if (typeof this.ready_callbacks[i]=="function") {
				this.ready_callbacks[i]();
			}
    	}
    },
    
	stop: function(res,disable) { // FIXME: IE-re is meg kell irni
	    if (res) {
	        alert(res);
	    }
	    window.addEventListener('error', function (e) {e.preventDefault();e.stopPropagation();}, false);
	    if (disable) {
		    var handlers = [
		        'copy', 'cut', 'paste',
		        'beforeunload', 'blur', 'change', 'click', 'contextmenu', 'dblclick', 'focus', 'keydown', 'keypress', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'resize', 'scroll',
		        'DOMNodeInserted', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument', 'DOMNodeInsertedIntoDocument', 'DOMAttrModified', 'DOMCharacterDataModified', 'DOMElementNameChanged', 'DOMAttributeNameChanged', 'DOMActivate', 'DOMFocusIn', 'DOMFocusOut', 'online', 'offline', 'textInput',        'abort', 'close', 'dragdrop', 'load', 'paint', 'reset', 'select', 'submit', 'unload'
		    ];
		    for (var i=0; i<handlers.length; i++) {
		        window.addEventListener(handlers[i], function (e) {e.stopPropagation();}, true);
		    }
	    }
	    if (window.stop) {
	        window.stop();
	    }
	    throw '';
    },
	
    sleep: function(ms) { // !!! FIXME under constructing
          /*if (window.showModalDialog) {
              var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + ms + ');';
              window.showModalDialog('javascript:document.writeln ("<script>' + sDialogScript + '<' + '/script>")','','dialogHeight:20;dialogWidth:20;dialogLeft:0;dialogTop:0;dialogHide:yes;');
          } else {*/
            var d = new Date();
            var d_start = d.getTime();
            while (d.getTime()<(d_start+ms)) {
                d = new Date();
            }
          //}
    }
    
}

jst._init.apply_anchors();

