﻿hoverImages = {
    srcDelimiter : "#",
    preloadimages : new Array(),
    preload : function(imgsrc) {
        var img = new Image();
        img.src = imgsrc;
        return this.preloadimages.push(img);
    },
    init : function() {
        regExpTest = new RegExp(this.srcDelimiter);
        regExpFind = new RegExp("(.*)" + this.srcDelimiter + "(.*)");    
        for (i = 0; i < document.images.length; i++) {
            img = document.images[i];
            if(regExpTest.test(img.getAttribute('src'))) {
                 img.setAttribute('src_reg', regExpFind.exec(img.getAttribute('src'))[1]);
                 img.setAttribute('src_ovr', regExpFind.exec(img.getAttribute('src'))[2]);
                 img.onmouseover = function(){ this.setAttribute('src', this.getAttribute('src_ovr')); };    
                 img.onmouseout = function(){ this.setAttribute('src', this.getAttribute('src_reg')); };
                 img.onmouseout();
                 this.preload(img.getAttribute('src_ovr'));
            }
        }
    }
};
cssHelper = {
    setChildNodeClassNames : function(p) {
        if (p.keepLastClass) lastNode = p.rootNode.childNodes[ p.rootNode.childNodes.length - ((typeof p.rootNode.lastChild.className == 'undefined')?2:1) ];
        var childNode = p.rootNode.firstChild;
        var i = 0;
        while (childNode != null) {
            if (typeof childNode.className != 'undefined') {
                
                childNode.className = p.classeNames[i];
                if (++i >= p.classeNames.length) i = 0;
                
            }
            childNode = childNode.nextSibling;
            if (p.keepLastClass && childNode == lastNode) break;
        }
    },
    addChildNodeClassNames : function(p) {
        var childNode = p.rootNode.firstChild;
        var i = 0;
        while (childNode != null) {
            if (typeof childNode.className != 'undefined') {
                
                $(childNode).addClassName(p.classeNames[i]);
                if (++i >= p.classeNames.length) i = 0;
                
            }
            childNode = childNode.nextSibling;
        }
    },
    setClassOfChildElement : function(p) {
        //{rootnode:DOMnode,index:0,className:'active'}
        var n = $A(p.rootnode.childNodes);
        var j = p.index;
        for (var i=0; i<n.length; i++) 
            if (((n[i].nodeType!=3)?--j:j)==-1) n[i].className = p.className;
    },
    setHeightOfChildElements : function(p) {
        childElements = p.rootNode.getElementsByTagName(p.childTagName);
        if(childElements.length > 0){
            for(var i=0; i<= childElements.length-1; i++){                
                childElements[i].style.height = (p.rootNode.clientHeight-p.offset) + 'px';                                    
            }
        } else {p.rootNode.style.height = '17px';}
    }
}
domHelper = {
    sortSelectOptions : function(p) {
        //{select:selectField,start:0}
        var a = new Array();
        while (p.select.options[p.start]!= null) { a.push([p.select.options[p.start].text, p.select.options[p.start].value]); p.select.options[p.start] = null; }
        a.sort(function(a, b) { return(a[0]>b[0])?1:-1; });
        $A(a).each(function(n) { p.select.options[p.select.length] = new Option(n[0], n[1], false) } )
    }
}
documentViewHelper = {
    init : function() { 
        hoverImages.init();
    }
}
popupHelper = {
    openImagePopup : function(p){ //{width:,height:,alt:,url:}
        newWindow = window.open("","","height="+(p.height+20)+",width="+(p.width+20)+",left="+((screen.width/2)-((p.width+20)/2))+",top="+((screen.height/2)-((p.height+20)/2))+",status=0");
        newWindow.document.open();
        newWindow.document.write('<'+'html'+'><'+'head'+'><'+'title'+'>'+((typeof(p.alt)=="undefined")?'':p.alt)+'</'+'title'+'></'+'head'+'><'+'body style="margin:0px;padding:10px;cursor:pointer;height:'+p.height+40+';" onclick="window.close()"><img src="'+p.url+'" alt="'+((typeof(p.alt)=="undefined")?'':p.alt)+'" align="center"></'+'body'+'></'+'html'+'>');
        newWindow.document.close();
        newWindow.focus();
        return void(0);
    },
    open360DegPopup : function(p){ //{features:,width:,height:,name:,url:}
        if(p.width > screen.width || p.height > screen.height) {
            x = y = 0; 
            p.width = screen.width-10; 
            p.height = screen.height-60;
        } else {
            x=(screen.width/2)-(p.width/2)
            y=(screen.height/2)-(p.height/2)
        }
        window.open(p.url, p.name,"width="+ p.width +",height="+ p.height +",toolbar=no,menubar=no,left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y +","+ p.features);
        return void(0);
    }
}
ajaxHelper = {
    insertPageSnippets : function(p) {
        for (var i=0; i<p.snippets.length; i++){
            var pageURL = p.snippetPrefix+p.snippets[i]+p.snippetSuffix;
        
            new Ajax.Request(pageURL, 
                            {evalScripts:true, asynchronous:false, method:'get',
                                 onComplete: function(transport) {
                                     if (200 == transport.status){
                                        new Insertion.Bottom(p.container,transport.responseText);
                                        //p.container.innerHTML = p.container.innerHTML + transport.responseText;
                                        //new Ajax.Updater(p.container, pageURL, {evalScripts:true, asynchronous:false, insertion: Insertion.Bottom });   
                                    }  
                                }    
                            }
            );
        }     
    }
}
function winopen(theURL, wname, width, height, features){
    if(width > screen.width || height > screen.height) {
        positionx = 0;
        positiony = 0;
        width = screen.width-10;
        height = screen.height-60;
    } else {
        positionx=(screen.width/2)-(width/2)
        positiony=(screen.height/2)-(height/2)
    }
    window.open(theURL, wname,"width="+ width +",height="+ height +",toolbar=no,menubar=no,left=" + positionx + ",top=" + positiony + ",screenX=" + positionx + ",screenY=" + positiony +","+ features);
}
function getActualYear() {
    var jetzt = new Date();
    document.write(jetzt.getFullYear());
}
function getActualDate() {
    var actualDate = new Date();
    document.write(actualDate.getDay()+"."+actualDate.getMonth()+"."+actualDate.getFullYear());
}

function dropselection(name, formname){
    for(i=0;i<document.forms[formname].elements[name].length;++i){
        if(document.forms[formname].elements[name].options[i].selected == true && document.forms[formname].elements[name].options[i].value)
        {
            window.location = document.forms[formname].elements[name].options[i].value;
        }
    }
}
