﻿/* GLOBALE DATEN */
var arPictures = null;
var targetobject = null;

var Pause = false;
var curPause = 0;
var PauseZeit = 380;

var Divgroesse = 100;
var verhaeltnis = 1.4;	
/* EFFECTS WELCOME */
function LoadGallery( StartPictureName, picID, sizeX, v, num )
{ 
    countPics = num;
    arPictures = new Array(countPics);

    targetobject = document.getElementById(picID);
    targetobject.visible = true;
    
	Divgroesse = sizeX;
	actDivgroesse = 0;
	verhaeltnis = v;
    curPause = 0;
    
    
	var sParams = StartPictureName;
    var sUrl = document.URL;
    var index = sUrl.indexOf("?");

    if( index != -1 && sParams == ""){ sParams = sUrl.substring(index+5, sUrl.length);}
    targetobject.src = sParams;

    for( i = 0; i < countPics; i++)
    {
        var name = sParams.substring(0, sParams.length - 4);
        var end = sParams.substring(sParams.length - 4, sParams.length);
        var url = name + i + end; 
        var id = picID + i;
        var Img = document.getElementById(id);
        Img.src = url;
        arPictures[i] = Img;
    }
    
    var loadDiv = document.getElementById("loadingHolder");
    var loadImg = document.getElementById("loading");
    if(loadImg) loadDiv.removeChild(loadImg);

    resize();
    SwitchPicturesInGallery();
}

var nr = 0;
function SwitchPicturesInGallery()
{
    if( nr < countPics)
    {
        if(arPictures[nr].src == ""){ nr++; SwitchPicturesInGallery();}
        targetobject.src = arPictures[nr].src;
        nr++;

        setimgopacity(opValue);
        fadeIn();         //läßt das Bild erscheinen 
    }
    
    else
    {
   	    nr = 0;
   	    curPause = 0;
	    SwitchPicturesInGallery();
    }
}

var opValue = 0;
function fadeIn()
{

    if( opValue <= 0.9){
        setimgopacity(opValue, targetobject);
        opValue += 0.1;
        window.setTimeout("fadeIn()", 10);
    }
    
    else{
        curPause = 0;
        setPause();
        
    }
}

function fadeOutGallery()
{
    if( arPictures.length > 1 ){
        if( opValue > 0){
            setimgopacity(opValue, targetobject);
            opValue -= 0.1;
            window.setTimeout("fadeOutGallery()", 10);
        }
        else {
            SwitchPicturesInGallery();
        }
    }
}

function fadeOut()
{
    if( opValue > 0){
        setimgopacity(opValue, targetobject);
        opValue -= 0.05;
        window.setTimeout("fadeOut()", 10);
    }

}

function resize()
{
    if( actDivgroesse < Divgroesse){
                  
        targetobject.style.width = actDivgroesse + "px";
        targetobject.style.height = actDivgroesse/verhaeltnis + "px";
        actDivgroesse += 5;
        
        window.setTimeout("resize()", 10);
    }
    else actDivgroesse = 0;
}

function setimgopacity(value, object)
{ 
    if(object == null) return;
    var ievalue=value*100;
    //Sets the opacity of "language_selector" div per the passed in value setting (0 to 1 and in between)

    object.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ ievalue + ");"; //IE7 opacity

    if (object.filters && object.filters[0]){ //IE syntax
        if (typeof object.filters[0].opacity=="number") //IE6
            object.filters[0].opacity=value*100;
        else //IE 5.5
            object.style.filter="alpha(opacity="+value*100+")";}
    else if (typeof object.style.MozOpacity!="undefined") //Old Mozilla syntax
        object.style.MozOpacity=value;
    else if (typeof object.style.KHTMLOpacity!="undefined") //Safari syntax
        object.style.KHTMLOpacity= value;
    else if (typeof object.style.opacity!="undefined") //Standard opacity syntax
        object.style.opacity=value;
    else{ //Non of the above, stop opacity animation
        value=100;}
}


//---------------------------------
// Pause - blockiert changePictures
//---------------------------------
function setPause()
{  
    if( curPause <= PauseZeit){
        Pause = true;                	    
        curPause += 1;
        window.setTimeout("setPause()", 10);
    }
    
    else{
        curPause = 0;
        Pause = false;
        window.setTimeout("fadeOutGallery()", 10);
    }
}

/* END EFFECTS */
function show(stringText){
    var bg = document.getElementById("over");
    bg.style.visibility = "visible";
    bg.style.width = document.body.offsetWidth + "px";
    bg.style.height = document.body.offsetHeight + "px";

    setimgopacity(0.6, bg);
   
    
    //now display content
    var x = (document.all && event) ? window.event.clientX + document.body.scrollLeft : 100;
    var y = (document.all && event) ? window.event.clientY - document.body.scrollTop : 100;
    var ele = null;

    if(stringText != "") {
        //now display content
        ele = document.getElementById("globalContent");
        ele.style.visibility = "visible";
        ele.innerHTML = stringText;
        ele.style.left = document.body.offsetWidth / 2 - 200;
        ele.style.top = y+30; }
    else {
        ele = document.getElementById("Reservierung");
        ele.style.visibility = "visible";
        ele.style.zIndex = 2500; 
        ele.style.left = document.body.offsetWidth / 2 - 300;
        ele.style.top = 100; 
    }
}

function display(id)
{
    var oLayer = document.getElementById(id);

    if(ns4 && oLayer.style.visibility == "hidden" ) { oLayer.style.display="inline";oLayer.style.visibility="visible";}
    else if(ns4) { oLayer.style.visibility="hidden";oLayer.style.display="none"; }
   
    if ((ns6 || ie4) && oLayer.style.display == "none") { oLayer.style.display="inline";oLayer.style.visibility="visible";}
    else if (ns6 || ie4) { oLayer.style.visibility="hidden";oLayer.style.display="none"; }
}

function hide(){
    targetobject = document.getElementById("over");
    fadeOut();
    targetobject.style.visibility = "hidden";
    var resObj = document.getElementById("Reservierung");
    if(resObj != null) resObj.style.visibility = "hidden";

}

function hideDiv(id){

    var ele = document.getElementById(id);
    if(!ele) return;
    ele.style.visibility = "hidden";
    ele.style.display = "none";

    //document.body.removeChild(ele);
}

//- CALENDAR EFFECTS -------------------------------------------------------------------
function showCalendarText(sText, ID, GuestID)
{
    var oText = document.getElementById("divText");
    oText.style.display = "block";
    oText.style.visibility = "visible";
    oText.className = "divCalendar";

    var MenuWidth = "350px";
    MenuWidth = parseInt(MenuWidth);
    
    var MenuHeight = "80px";
    MenuHeight = parseInt(MenuHeight);

    oText.style.posLeft = event.clientX + 10;
	oText.style.posTop = event.clientY;
	setimgopacity(0.7, oText);
    oText.innerHTML = "<div align='center'><table width='100%' height='90%'>"
                      + "<tr><td align='left'>" + sText 
                      + "</td><td align='right' valign='top'>"
                      + "<a id='C1' onclick='hideCalendarText()' onmouseover='onMouseOver(this.id)' onmouseout='onMouseOut(this.id)'>close&nbsp;"
                      + "<img src='../Pictures/Icons/cancelicon.gif' align='middle' height='16px' border=0></a>"
                      + "</td></tr>"
                      //+ "<tr><td></td><td align='right' valign='bottom'>"
                      //+ "<a id='C2' target='_blank' href='updateGuest.aspx?roomID=" + roomNumber + "&id=" + GuestID + "' class='LinkWhite' onmouseover='onMouseOver(this.id)' onmouseout='onMouseOut(this.id)'>Bearbeiten&nbsp;"
                      //+ "<img src='../Pictures/Icons/401.ico' align='middle' height='16px' border=0></a></td></tr>"
                      + "</table></div>";
}

function hideCalendarText( id )
{
    var oText = document.getElementById(id);
    oText.style.display = "none";
    oText.style.visibility = "hidden";
}

function showTabs( id, len ){
    
    for(var i=1; i<len+1; i++)
        parent.document.getElementById(i).style.display = 'none';	
    
    oDiv = parent.document.getElementById(id);
    oDiv.style.display = 'inline';    
}

function showOnScreen(stringText, Event, targetElement, width, height)
{   
    var ele = null;
    if(targetElement == "" || targetElement == null) { 
        ele = document.createElement("div"); 
        ele.id = "overlay2"; 
        if(parseInt(width)) ele.style.width = width + "px"; else width = 300;
        if(parseInt(height)) ele.style.height = height + "px"; else height = 200;
    }
    
    else{
        ele = document.getElementById(targetElement);
    }

    if(targetobject == null) targetobject = document.createElement("div"); 

    hideDiv(ele.id);
 
    if(parseInt(width)) targetobject.innerHTML = stringText + "<br /><a style='left:" + (width-40) + "px' class='closeLink' href='#' onclick='hideDiv(\"" + ele.id + "\")'>Fenster schliessen</a>";
    ele.appendChild(targetobject); 
    ele.setAttribute("class" , "overlay"); 
    document.body.appendChild(ele);
    
    var point = getMousePos( ele ); 
    setElementToPos( ele, point);
 
    ele.style.visibility = "visible";
    ele.style.display = "block";
    
    targetobject = ele;
    opValue = 0; 
}

function hookDivToPos( id, Pos, w, h )
{
    var oLayer = parent.document.getElementById(id);
    if(oLayer == null) return;

    var posX = 0; 
    var posY = 0;
    var width  = parseInt(w); 
    var height = parseInt(h); 
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {//Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {//IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {//IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    posY = posY + ((window.pageYOffset)?window.pageYOffset:(document.documentElement && document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop);

    switch(Pos){
        case "MD":{ posX= document.body.offsetWidth/2+width/2; posY= myHeight/2-height/2; 
            posX = posX - ((window.pageXOffset)?window.pageXOffset:(document.documentElement && document.documentElement.scrollLeft)?document.documentElement.scrollLeft:document.body.scrollLeft);
            break;}
        case "UL":{ posX= 0; posY= 0; break;}
        case "UR":{ posX= event.clientX; posY= event.clientY; break;}
        case "DL":{ posX= 0; posY= document.body.offsetHeight+height-100; break;}        
        case "DR":{ posX= document.body.offsetWidth; posY= document.body.offsetHeight+height-100; 
            posX = posX - ((window.pageXOffset)?window.pageXOffset:(document.documentElement && document.documentElement.scrollLeft)?document.documentElement.scrollLeft:document.body.scrollLeft);
            break;}
    }
    
    if(ns4) { oLayer.style.posLeft = (posX-width) + "px"; oLayer.style.posTop = (posY) + "px";}
    if (ns6 || ie4) { oLayer.style.left = (posX-width) + "px"; oLayer.style.top = (posY) + "px";}
}

function clearTextBox( TBID )
{
    var objTB = parent.document.getElementById("ctl00_" + TBID);
    if(objTB == null) objTB = parent.document.getElementById("ctl00_MidleHolder_" + TBID);
    if(objTB == null) objTB = parent.document.getElementById(TBID);
    if(objTB == null) return;
    if("Suchbegriff") objTB.value = ""; 
}

function move( id )
{   
    var dragDropDiv = parent.document.getElementById(id);
    if(!dragDropDiv) { return;}
    
    var point = getMousePos( dragDropDiv );  
    setElementToPos( dragDropDiv, point);
}

// sets an element object to the right x, y coordinates
function setElementToPos( ele, point )
{
    var posX = point[0];
    var posY = point[1];

    posX = posX + "px";
    posY = posY + "px";

    
    if(ns4) { 
        ele.style.posLeft  = posX; 
        ele.style.posTop   = posY;
    }
    if (ns6 || ie4) { 
        ele.style.left     = posX; 
        ele.style.top      = posY;
    }
}

// gets x, y coordinates from the current mouse
function getMousePos(ele)
{
    var widthOfElement = 460;
    var heigthOfElement = 250;
    if(parseInt( ele.style.width)) { widthOfElement = parseInt( ele.style.width); heigthOfElement = parseInt( ele.style.height);}
    
    var point = new Array();
    var x = 0;
    var y = 0;
    if(window.event!= null){
        if (event.pageX == null)// IE case
        {
           x = (document.all) ? window.event.clientX + document.body.scrollLeft : 200;
           y = (document.all) ? document.documentElement.scrollTop + window.event.clientY : screen.height/2-100;
        }
        else{ // all other browsers    
            x = window.event.clientX;
            y = window.pageYOffset + window.event.clientY;
        }  
    }
    
    else{
        x = 10;
        y = 10;
    }
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {//Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {//IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {//IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if(x >= (myWidth - widthOfElement)) x = x - widthOfElement - 10;
    if(y >= (myHeight - heigthOfElement)) {if(y > heigthOfElement) y = y - heigthOfElement - 20;}
    
    point.push(x + 5);
    point.push(y + 5);
    return point
}

var o = null;
function myAlert(stringText, targetElement,width,height)
{    
    var ele = document.getElementById(targetElement);
    ele.setAttribute("class" , "overlay"); 
    if(parseInt(width)) ele.style.width = width + "px"; else width = 300;
    if(parseInt(height)) ele.style.height = height + "px"; else height = 200;
    
    if(o == null) o = document.createElement("div");
 
    o.innerHTML = "<div class='top'><p>Warnung</p></div><br /><br /><p><img src='../Pictures/Icons/400.ico' alt='Fehlermeldung' />" + stringText + "</p><br /><a class='alert' href='#' onclick='hideDiv2(\"" + ele.id + "\")'>Fenster schliessen</a>";
    ele.appendChild(o);   
    
            
    hookDivToPos(targetElement, "MD",width,height); 
    
    ele.style.visibility = "visible";
    ele.style.display = "block";
    
    targetobject = ele;
    opValue = 0;
}

function hideDiv2(id){

    var ele = document.getElementById(id);
    if(!ele) return;
    ele.style.visibility = "hidden";
    ele.style.display = "none";

    for(var i = 0; i<ele.children.length; i++){}
    ele.removeChild(ele.lastChild);
}

