// globale Variablen
var ns=false, ie=false;
var windowWidth, windowHeight;
var objRef, styleSwitch, pixSwitch, leftSwitch, topSwitch;
var gen5, elementID, diffX, diffY;
var lastScrollX = 0;
var lastScrollY = 0;
var layerXY = [0, 0, 0, 0];
var mousePos = [0, 0];
var hidethelayer;

var debug = 0;

checkBrowser();

function init() {
        checkBrowser();
        if ( debug == 0 ) { self.onError=null; }
        getDimensions();
}



// Browsererkennung
function checkBrowser() {
        if( (parseInt( navigator.appVersion )) >= 4 ) {
                ( navigator.appName.indexOf("etscape") != -1 ) ? ns = true : ns = false;
                ( navigator.appName.indexOf("xplorer") != -1 ) ? ie = true : ie = false;
                gen5 = document.getElementById ? 1 : 0; // check if it is a 5th generation Browser
        }
}

function getDimensions() {
        if( ns ) {
                windowWidth = innerWidth;
                windowHeight = innerHeight;
        }
        else if( ie ) {
                windowWidth = self.document.body.clientWidth;
                windowHeight = self.document.body.clientHeight;
        }
return windowHeight, windowWidth;
}

// CrossBrowser objRefekte erstellen
function makeObj( elementID ) {
        if ( gen5 ) {
                objRef = 'document.getElementById("' + elementID + '")';
                styleSwitch = ".style";
        }
        if( ns ) {
                // if ( !gen5 ) {objRef = 'document.all["' + elementID + '"]'};
                if ( !gen5 ) {objRef = 'document.layers["' + elementID + '"]'};
                if ( !gen5 ) {styleSwitch = ""};
                leftSwitch = ".left";
                topSwitch = ".top";
                widthSwitch = ".clip.right";
                heightSwitch = ".clip.bottom";
        }
        else if( ie ) {
                if ( !gen5 ) {objRef = 'document.all["' + elementID + '"]'};
                if ( !gen5 ) {styleSwitch = ".style"};
                leftSwitch = ".pixelLeft";
                topSwitch = ".pixelTop";
                widthSwitch = ".width";
                heightSwitch = ".height";
        }

if ( eval( objRef ) ) {

this.obj = eval( objRef );
this.css = eval( objRef + styleSwitch );
this.css.left = eval( objRef + styleSwitch + leftSwitch );
this.css.top = eval( objRef + styleSwitch + topSwitch );
this.css.visibility = eval( objRef + styleSwitch + '.visibility' );
this.css.width = eval( objRef + styleSwitch + widthSwitch );
this.css.height = eval( objRef + styleSwitch + heightSwitch );

var Xleft = parseInt( this.css.left );
var Ytop = parseInt( this.css.top );
var Xright = parseInt( this.css.left ) + parseInt( this.css.width );
var Ybottom = parseInt( this.css.top ) + parseInt( this.css.height );

layerXY = [Xleft, Xright, Ytop, Ybottom];

}
if ( debug == 1 && !eval(objRef) ) {
alert('<div>-Layer mit der ID: "' + elementID + '" nicht gefunden !!')
}
}



function writeInLayer( elementID, txt ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        if ( gen5 || ie ) {
                this.obj.innerHTML = txt;
        }
        if ( !gen5 && ns  ) {
        with( this.document )
                {
                 open();
                 write(txt);
                 close();
                }
        }
}




// Funktionen um die Sichtbarkeit von Layern zu ändern:
// Funktionen um die Sichtbarkeit von Layern zu ändern:
function showLayerContainer( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        this.css.visibility = "visible";
}

function showLayerContact( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        this.css.display = "block";
}
function hideContact( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
		document.forms[0].kontaktWest.selectedIndex = 0;
		document.forms[0].kontaktOst.selectedIndex = 0;
		//document.forms[0].kontaktDE.selectedIndex = 0;
        this.css.display = "none";
}

function showLayer( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        this.css.visibility = "visible";
		hidethelayer=window.setTimeout("hideLayer(elementID)",8000);
}

function hideLayer( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        this.css.visibility = "hidden";
}

// Funktionen um Informationen über den Layer zu erhalten:



function getLayerVisibility( elementID ) {
        if ( this.css && this.obj.id != elementID || !this.css) {
        if ( debug == 1        ) { window.status = 'creating Object: ' + elementID; }
        makeObj( elementID );
        }
        var vis = this.css.visibility;
        switch(vis)
        {
         case "visible":
         return true;
         break;
         case "show":
         return true;
         break;
         case "hidden":
         return false;
         break;
         case "hide":
         return false;
         break;
         default:
         break;
        }
}






function highlight(Bildname, ID) {
 highlightPic = new Image();
 highlightPic.src = "pics/"+Bildname;
 window.document.images[ID].src = highlightPic.src; 
}

function lowlight(Bildname, ID) {
 lowlightPic = new Image();
 lowlightPic.src = "pics/"+Bildname;
 window.document.images[ID].src = lowlightPic.src;
}
 

 
 
 
 function checkEmail(email) {
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
        return filter.test(email);
    }
    function checkForm () {
        var form = document.gewinnspiel;
        if (form.name.value == "") {
            alert("Bitte füllen Sie alle Pflichtfelder aus.");
            return false;
        }
		if (form.vorname.value == "") {
            alert("Bitte füllen Sie alle Pflichtfelder aus.");
            return false;
        }
		if (form.adresse.value == "") {
            alert("Bitte füllen Sie alle Pflichtfelder aus.");
            return false;
        }
		if (form.plz.value == "") {
            alert("Bitte füllen Sie alle Pflichtfelder aus.");
            return false;
        }
		if (form.ort.value == "") {
            alert("Bitte füllen Sie alle Pflichtfelder aus.");
            return false;
        }	        
        if ( (form.email.value=="") || !checkEmail(form.email.value)) {
            alert("Bitte geben Sie eine gültige E-Mail Adresse ein.");
            return false;
        }
		if (!form.CHECKBOX.checked) {
            alert("Bitte lesen Sie die Datenschutzbelehrung und erteilen Sie die Einwilligung.");
            return false;
        }
        return true;
}
function leeresFeld() {
document.gewinnspiel.loesung.value='';
}


