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';
}

// node display  ------------------------------------
function disp(id,state){
    var node = document.getElementById(id);
    if(node){
        node.style.display=state;
    }
}

function check(element, value){
    if(element.value == value)
        element.checked = true;
}
// division display or none ------------------------------------
function display(element,state){
    node = document.getElementById(element);
    if(node){
        node.style.display = state ? "" : "none";
    }
}

// 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;
}
// confirm submission of form
function confirmSubmit(prompt){
    return confirm(prompt);
}

// buchungSuchen
function leeren(element){
    switch(element.type){
        case 'text'       :element.value = '';
                            break;
        case 'select-one' :element.options.selectedIndex=0;
                            break;
    }
}


function openIFrame(src, x, y, width, height){
	var iframe = document.createElement("iframe");
	iframe.src = src;
	iframe.style.position = "absolute";
	iframe.style.left     = x      + "px";
	iframe.style.top      = y      + "px";
	iframe.style.width    = width  + "px";
	iframe.style.height   = height + "px";
	iframe.style.overflow = "hidden";
	iframe.style.zIndex   = 10;
    return iframe;
}

/* erzeugt einen IFRame fuer den QRCode, src: URL fuer IFrame, id: Node-ID, gibt Stelle an, wo IFrame positioniert werden soll */
function openQRCode(src, id_iframe){
    var iframe = document.getElementById(id_iframe);
    iframe.src = src;
    iframe.style.display = 'block';
}
// movie window
function video(videoname,imagename){
    video.iframe = openIFrame("videos/_video.jsp?video="+videoname+"&image="+imagename, 300, 300, 400, 340)
	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;
    }
    var point=new Object();
    point.x = x;
    point.y = y;
    return point;
}

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;
}

function smoothScroll(id) {
    var stopScroll = getDimension(document.getElementById(id));
    var scroll = getScrollXY();

    var timer = 1;
    var speed = 20;
    var step = 10;
    var doScroll = true;
    while(doScroll){
        var distanceX = stopScroll.x - scroll.x;
        var distanceY = stopScroll.y - scroll.y;

        scroll.x = Math.abs(distanceX) < step ? stopScroll.x : (distanceX > 0 ? scroll.x + step : scroll.x - step);
        scroll.y = Math.abs(distanceY) < step ? stopScroll.y : (distanceY > 0 ? scroll.y + step : scroll.y - step);

        doScroll = (scroll.x != stopScroll.x) || (scroll.y != stopScroll.y);
        setTimeout("window.scrollTo("+scroll.x+", "+scroll.y+")", timer * speed);
        timer++;
    }
}

function go(param)
{
    var url = "ht"+"tp:/"+"/";
    for(i=0; i<go.arguments.length; i++){
        url += go.arguments[i];
    }
    window.location.href = url;
}

// popup IFRAME
var popupFrame = function(name, msg)
{
	var iframe = document.createElement('iframe');
	iframe.setAttribute("id", name);
	iframe.className = name;
	document.body.appendChild(iframe);

    if(!popupFrame.iframe)
        popupFrame.iframe = {};

    popupFrame.iframe[name] = iframe;

	var fkt = "popupFrame.delayWrite('"+name+"','"+msg+"')";
	window.setTimeout(fkt, 100);

	popupFrame.delayWrite = function(name,msg)
	{
		if (iframe.contentDocument)						// For Firefox
		{
			iframeDoc = iframe.contentDocument;
		}
		else if (iframe.contentWindow)					// For IE5.5 and IE6
		{
			iframeDoc = iframe.contentWindow.document;
		}
		else if (iframe.document)						// For IE5
		{
			iframeDoc = iframe.document;
		}
		else											// z.B.Opera 8.5
		{
			iframeDoc = document.getElementById(name).document;
		}

		var html = '<html><body>'
				 + '<div align="right"><a href="javascript:parent.popupFrame.close(\''+name+'\');">schliessen</a></div>'
				 + msg
				 + '</body></html>'
				 ;

		iframeDoc.open();
		iframeDoc.write(html);
		iframeDoc.close();
	}

    popupFrame.close = function(name)
    {
        document.body.removeChild(popupFrame.iframe[name]);
    }
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}
