/*********************************************************************/
/* SystemVariablen                                                     */
/*********************************************************************/
var _FLib_MouseX = 0;
var _FLib_MouseY = 0;
var _FLib_MouseClickX = 0;
var _FLib_MouseClickY = 0;
var _FLib_is_ie = false;
var _FLib_is_ns = false;
var _FLib_is_op = false;
var _FLib_GlobalCookies = new Array();
var _FLib_registred_onmousedown = new Array();
var _FLib_registred_onmouseup = new Array();
var _FLib_registred_onmousemove = new Array();
var _FLib_GetArray = new Array();

function _FLib_bodyOnMouseMove(Event){
    if(!Event) Event = window.event;
    _FLib_MouseX = Event.clientX;
    _FLib_MouseY = Event.clientY;
    if(!_FLib_registred_onmousemove.length) return true;
    for(attr in _FLib_registred_onmousemove){
        _FLib_registred_onmousemove[attr].OnMouseMove(Event);
    }
}

function FLib__bodyOnMouseDown(Event){
    if(!Event) Event = window.event;
    if(!_FLib_registred_onmousedown.length) return true;
    for(attr in _FLib_registred_onmousedown){
        _FLib_registred_onmousedown[attr].OnMouseDown(Event);
    }
}

function FLib__bodyOnMouseUp(Event){
    if(!Event) Event = window.event;
    if(!_FLib_registred_onmouseup.length) return true;
    for(attr in _FLib_registred_onmouseup){
        _FLib_registred_onmouseup[attr].OnMouseUp(Event);
    }
}

function FLib__bodyOnMouseClick(Event){
    if(!Event) Event = window.event;
    _FLib_MouseClickX = Event.clientX+ViewX();
    _FLib_MouseClickY = Event.clientY+ViewY();
}
/*********************************************************************/
/* Darstellung                                                         */
/*********************************************************************/
function IsOpera(){return _FLib_is_op;}
function IsNetscape(){return _FLib_is_ns;}
function IsIE(){return _FLib_is_ie;}

function MouseX(){return _FLib_MouseX+ViewX();}
function MouseY(){return _FLib_MouseY+ViewY();}
function MouseClickX(){return _FLib_MouseClickX;}
function MouseClickY(){return _FLib_MouseClickY;}

function ViewX(){
    if(IsNetscape()) return window.pageXOffset;
    return document.documentElement.scrollLeft;
}

function ViewY(){
    if(IsNetscape()) return window.pageYOffset;
    return document.documentElement.scrollTop;
}

function ViewWidth(){
    if(IsOpera()) return document.body.clientWidth;
    return document.documentElement.clientWidth;
}

function ViewHeight(){
    if(IsOpera()) return document.body.clientHeight;
    return document.documentElement.clientHeight;
}

function PageWidth(){
    if(IsOpera()) return document.documentElement.clientWidth;
    return document.body.clientWidth;
}

function PageHeight(){
    if(IsOpera()) return document.documentElement.clientHeight;
    return document.body.clientHeight;
}
/*********************************************************************/
/* Mathe                                                              */
/*********************************************************************/
function Random(min,max){
    var rnd = Math.random();
    if(arguments.length==1){
        max = min;
        min = 0;
    }
    return min+((rnd*max)%(max-min));
}

function Sign(value){
    if(value==0) return 0;
    if(value>0) return 1; else return -1;
}
/*********************************************************************/
/* Cookies                                                              */
/*********************************************************************/
function GetCookie(name_){
    vals = (document.cookie+"").split(";");
    for(var i=0;i<vals.length;i++){
        vars = vals[i].split("=");
        if(vars[0].replace(" ","")==name_){
            return vars[1];
        }
    }
    return "";
}

function ClearCookies(){
    for(var i=0;i<_FLib_GlobalCookies.length;i++){
        val = _FLib_GlobalCookies.shift();
        SetCookie(val,"",0);
    }
}

function SetCookie(name_,value_,life){
    if(life)
    {
        time = new Date();
        time.setTime(time.getTime()+(1000*life));
        life_ = "expires="+time.toGMTString()+";";
    }
    else
    {
        life_ = "";
    }
    if(life>0) {_FLib_GlobalCookies[_FLib_GlobalCookies.length] = name_;}
    document.cookie = name_+"="+value_+";"+life_;
}
/*********************************************************************/
/* Elemente                                                          */
/*********************************************************************/
function ElementX(element){
    if(!element) return false;
    if(element.offsetLeft) return element.offsetLeft;
    return element.scrollLeft;
}

function ElementY(element){
    if(!element) return false;
    if(element.offsetTop) return element.offsetTop;
    return element.scrollTop;
}

function ElementHeight(obj,complete){
    if(!obj) return 0;
    var xtra = 0;
    if((arguments.length==2 && complete==true) || arguments.length==1){
		xtra = StyleHeight(obj);
    }
    if(IsIE()) return obj.offsetHeight+xtra;
    return obj.clientHeight+xtra;
}

function ElementWidth(obj,complete){
    if(!obj) return 0;
    var xtra = 0;
    if((arguments.length==2 && complete==true) || arguments.length==1){
        xtra = StyleWidth(obj);
    }
    if(IsIE()) return obj.offsetWidth+xtra;
    return obj.clientWidth+xtra;
}

function StyleWidth(obj){
	var xtra = 0;
	if(parseInt(obj.style.borderRight)) xtra += parseInt(obj.style.borderRight);
    if(parseInt(obj.style.borderLeft)) xtra += parseInt(obj.style.borderLeft);
    if(parseInt(obj.style.marginRight)) xtra += parseInt(obj.style.marginRight);
    if(parseInt(obj.style.marginLeft)) xtra += parseInt(obj.style.marginLeft);
    return xtra;
}

function StyleHeight(obj){
	var xtra = 0;
	if(parseInt(obj.style.borderBottom)) xtra += parseInt(obj.style.borderBottom);
    if(parseInt(obj.style.borderTop)) xtra += parseInt(obj.style.borderTop);
    if(parseInt(obj.style.marginBottom)) xtra += parseInt(obj.style.marginBottom);
    if(parseInt(obj.style.marginTop)) xtra += parseInt(obj.style.marginTop);
    return xtra;
}


function ElementContentHeight(obj){
    if(!obj) return 0;
    var xtra = 0;
	if(!IsNetscape()) xtra = StyleHeight(obj);
    return obj.scrollHeight+xtra;
}

function ElementContentWidth(obj){
    if(!obj) return 0;
    return obj.clientWidth+xtra;
}

function GetElementWidth(obj,complete){return ElementWidth(obj,complete);}
function GetElementHeight(obj,complete){return ElementHeight(obj,complete);}
function GetElementById(id){return document.getElementById(id);}
function GetElementsByName(name){return document.getElementsByName(name);}

function GetFirstChild(obj,nodename){
    if(arguments.length==1) return obj.firstChild;
    for(var i=0;i<obj.childNodes.length;i++){
        if(obj.childNodes[i].nodeName.toUpperCase()==nodename) return obj.childNodes[i];
    }
    return null;
}

function AddElementEventFunction(obj,objfuncname,func){
    if(!obj) return false;
    var tmp_func = obj[objfuncname];
    /*if(obj.getAttribute!=undefined){
        var code = obj.getAttribute(objfuncname);
        if(code!=null){
            if(IsIE()){
                obj[objfuncname] = function(Event){
                    obj.AttachedFunction = func;
                    obj[objfuncname+"_Function"] = code;
                    eval("obj[objfuncname] = function(Event){obj[\""+objfuncname+"_Function\"](Event);this.AttachedFunction(Event);}");
                }
            }else{
                obj.AttachedFunction = func;
                eval("obj[objfuncname] = function(Event){"+code+";this.AttachedFunction(Event);}");
            }
            return true;
        }
    }*/
    if(typeof(obj[objfuncname])!='function'){
        obj[objfuncname] = func;
    }else{
        obj[objfuncname] = function(Event){
            tmp_func(Event);
            func(Event);
        }
    }
    return true;
}

function Toggle(element){
    if(!element) return;
    if(element.style.display){element.style.display = "";}else{element.style.display = "none";}
}
/*********************************************************************/
/* Register                                                          */
/*********************************************************************/
function RegisterOnMouseUp(obj){
    if(obj==false) return false;
    if(!obj.OnMouseUp) return false;
    _FLib_registred_onmouseup[_FLib_registred_onmouseup.length] = obj;
}

function RegisterOnMouseDown(obj){
    if(obj==false) return false;
    if(!obj.OnMouseDown) return false;
    _FLib_registred_onmousedown[_FLib_registred_onmousedown.length] = obj;
}

function RegisterOnMouseMove(obj){
    if(obj==false) return false;
    if(!obj.OnMouseMove) return false;
    _FLib_registred_onmousemove[_FLib_registred_onmousemove.length] = obj;
}
/*********************************************************************/
/* Sonstiges                                                          */
/*********************************************************************/
function LocationGetValue(name){return _FLib_GetArray[name];}
function LocationGetArray(){return _FLib_GetArray;}

function Import(url){
    var script = document.createElement("SCRIPT");
    script.setAttribute("type","text/javascript");
    script.setAttribute("src",url);
    document.getElementsByTagName("head")[0].appendChild(script);
}
/*********************************************************************/
/* System (Private)                                                  */
/*********************************************************************/
function FLib__InitData(Event){
    if(!Event) Event = window.event;
    AddElementEventFunction(document.body,"onclick",FLib__bodyOnMouseClick);
    if(navigator.appName.search("Microsoft")!=-1){
        _FLib_is_ie = true;
    }else if(navigator.appName.search("Opera")!=-1){
        _FLib_is_op = true;
    }else if(navigator.appName.search("Netscape")!=-1){
        _FLib_is_ns = true;
    }
    if(IsIE()){
        AddElementEventFunction(document.body,"onmousemove",_FLib_bodyOnMouseMove);
        AddElementEventFunction(document.body,"onmouseup",FLib__bodyOnMouseUp);
        AddElementEventFunction(document.body,"onmousedown",FLib__bodyOnMouseDown);
    }else{
        AddElementEventFunction(window,"onmousemove",_FLib_bodyOnMouseMove);
        AddElementEventFunction(window,"onmouseup",FLib__bodyOnMouseUp);
        AddElementEventFunction(window,"onmousedown",FLib__bodyOnMouseDown);
    }
    _FLib_bodyOnMouseMove(Event);
    var data = document.location.search.substr(1);
    data = data.split("&");
    for(var i=0;i<data.length;i++){
        var pos = data[i].search("=");
        if(pos==-1){
            _FLib_GetArray[data[i]] = null;
        }else{
            _FLib_GetArray[data[i].substr(0,pos)] = decodeURI(data[i].substr(pos+1));
        }
    }
}

AddElementEventFunction(window,"onload",FLib__InitData);