function getCookie(Name,Default){
    var search = Name + "="
    if (document.cookie.length > 0){
        offset = document.cookie.indexOf(search)
        if (offset != -1){
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1)
                end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
    }
    return Default;
}

function resetScrollPos(){
    document.cookie = "st2=0";
    document.cookie = "st3=0";
}

function rememberScrollPos(){
    var kw2scroll = document.getElementById("kw2scroll");
    var kw3scroll = document.getElementById("kw3scroll");
    if(kw2scroll!=null)
        document.cookie = "st2="+kw2scroll.scrollTop;
    else
        document.cookie = "st2=0";
    if(kw3scroll!=null)
        document.cookie = "st3="+kw3scroll.scrollTop;
    else
        document.cookie = "st3=0";
}

function setScrollPos(){
    var kw2scroll = document.getElementById("kw2scroll");
    var kw3scroll = document.getElementById("kw3scroll");
    if(kw2scroll!=null)
        kw2scroll.scrollTop = getCookie("st2",0);
    if(kw3scroll!=null)
        kw3scroll.scrollTop = getCookie("st3",0);
}

function bookmark(url,text){
 if (window.sidebar) /* firefox */
 {
  window.sidebar.addPanel(text,url, "");
 }
 else if(window.opera && window.print)
 {
  var elem = document.createElement('a');
  elem.setAttribute('href',url);
  elem.setAttribute('title',text);
  elem.setAttribute('rel','sidebar');
  elem.click();
 }
 else if(document.all) /* ie */
 {
  window.external.AddFavorite(url,text);
 }
} 
// automatische selektion in einem select element
function selectOption(element, value){
    var opt = element.options;
    for(i=0;i<opt.length;i++){
        if(opt[i].value==value){
            element.selectedIndex = i;
            return true;
        }
    }
    return false;
}

function selectOptionText(element, text){
    var opt = element.options;
    for(i=0;i<opt.length;i++){
        if(opt[i].text==text){
            element.selectedIndex = i;
            return true;
        }
    }
    return false;
}

function selectRadio(form, fieldName, selectedValue){
    var field = form[fieldName];
    for(i=0;i<field.length;i++){
        if(field[i].value==selectedValue){
            field[i].checked=true;
            return;
        }
    }
}

function setVisible(divId,state){
    div = document.getElementById(divId);
    div.style.visibility = state?'visible':'hidden';
}

// division show hide ------------------------------------
var openDiv=null;
function showDiv(divId){
    if(openDiv!=null && openDiv!=divId)
        hideDiv(openDiv);
    div = document.getElementById(divId);
    div.style.visibility = 'visible';
    openDiv = divId;
}
function hideDiv(divId){
    div = document.getElementById(divId);
    div.style.visibility = 'hidden';
}

// confirm link
function confirmAction(href,prompt){
    if(confirm(prompt))
        window.location.href=href;
}

// buchungSuchen
function leeren(element){
    switch(element.type){
        case 'text'       :element.value = '';
                            break;
        case 'select-one' :element.options.selectedIndex=0;
                            break;
    }
}


// movie window
function video(videoname,imagename){
	video.iframe = document.createElement("iframe");
	video.iframe.src = "videos/_video.jsp?video="+videoname+"&image="+imagename;
	video.iframe.style.position = "absolute";
	video.iframe.style.left   = "300px"; 
	video.iframe.style.top    = "300px"; 
	video.iframe.style.width  = "400px"; 
	video.iframe.style.height = "340px"; 
	video.iframe.style.overflow = "hidden"; 
	video.iframe.style.zIndex = 10;
	document.body.appendChild(video.iframe);
}
function schliesseMovie(){
	document.body.removeChild(video.iframe);
}

var expander = {
    toggle : function (id,height){
        var div = document.getElementById(id);
        if(div.className.indexOf("geoeffnet")!=-1){
            div.className = div.className.replace("geoeffnet", "geschlossen")
        }else{
            div.className = div.className.replace("geschlossen", "geoeffnet")
            if(height){
                var divInfobox = document.getElementById(id+'_infobox');
                divInfobox.style.height = height + 'px';
                divInfobox.style.overflow = 'auto';
            }
        }
    }
};

/* Funktionen für Basisanzeige gestalten (kundendaten1.jsp) */
function basisanzeigeSpeichern(){
	document.basisanzeige.submit();
}
function vorschauKunde(idkunde){
    window.open('suchen.anz?idkunde='+idkunde,'_blank','width=820,scrollbars=yes,resizable=yes');
}

function vorschauKombination(idkombination){
    window.open('suchen.anz?idkombination='+idkombination,'_blank','width=820,scrollbars=yes,resizable=yes');
}

/* Preisauswahl im Operator Modus */
function preis(id){
    location.href="operatorPreisauswahl.do?idpreis="+id;
}
/* Vertriebskanalauswahl im Operator Modus */
function vertriebskanal(id){
    location.href="operatorVertriebskanal.do?idvertriebskanal="+id;
}

/** setzt den focus eines feldes innerhalb eines formulares */
function formularFocus(formularname,feldname){
    var form = document.getElementById(formularname);
    if(form){
        var feld = form.elements[feldname];
        if(feld){
            feld.focus();
        }
    }
}

/**
 *   .popup { position: absolute; background-color: white; top: 100px; left: 100px; visibility: hidden; padding: 20px; border: 5px outset red; z-index: 999;}
 *
 *   <div id="popup" class="popup">
 *       <p id="popup_msg"></p><br>
 *       <p align="center"><input id="popupOk" type=button value=OK onclick="closePopup()"></p>
 *   </div>
 *
 *   popup(document.getElementById('gaga'), 'das geht so aber nicht');
 */
function popup(msg){
    divover(true);
    var popup     = document.getElementById('popup');
    var popup_msg = document.getElementById('popup_msg');
    popup_msg.innerHTML = msg;
    showDiv('popup');
    zentrieren(popup);
    document.getElementById("popupOk").focus();
}
function closePopup(){
    hideDiv('popup');
    divover(false);
}

function zentrieren(element) /* element muss position: fixed haben */
{
    var dimElement = getDimension(element);
    var screen = getScreenSize();
    element.style.top  = "" + Math.round((screen[1] - dimElement.height)/2) + "px";
    element.style.left = "" + Math.round((screen[0] - dimElement.width)/2 ) + "px";
}

function getScreenSize() {
    var width = 0, height = 0;

    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        width = window.innerWidth;
        height = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    return [ width, height ];
}

function getScrollXY() {
    var x = 10, y = 20;

    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
    return [ x, y ];
}

function getDimension(element)
{
    var x = y = 0;
    var node = element;
    if(node.nodeName != 'IFRAME'){
      while (node) {
          x += node.offsetLeft;
          y += node.offsetTop;
          node = node.offsetParent;
      }
    }
    var dimension=new Object();
    dimension.x=x;
    dimension.y=y;
    dimension.width  = element.offsetWidth;
    dimension.height = element.offsetHeight;
    return dimension;
}

