﻿


/******************************************************************/
/********** Toolbox functions *************************************/
/******************************************************************/
function toolbox(tbid,tcid1,tcid2) {
    
    dialogid = "tb_" + tbid;
    buttonid = "tb_but_" + tbid;
    itemid      = "tb_item_" + tbid;
    
    closeddialogid1 = "tb_" + tcid1;
    closedbuttonid1 = "tb_but_" + tcid1;
    closeditemid1   = "tb_item_" + tcid1;
    closeddialogid2 = "tb_" + tcid2;
    closedbuttonid2 = "tb_but_" + tcid2;
    closeditemid2   = "tb_item_" + tcid2;
    
    dialogclassname = document.getElementById(dialogid).className;
    dialogclass = new String(dialogclassname);
    if (tcid1 != "") {
        closeddialogclassname1 = document.getElementById(closeddialogid1).className;
        closeddialogclass1 = new String(closeddialogclassname1);
        }
    if (tcid2 != "") {
        closeddialogclassname2 = document.getElementById(closeddialogid2).className;
        closeddialogclass2 = new String(closeddialogclassname2);
        }
    
    buttonclassname = document.getElementById(buttonid).className;
    buttonclass = new String(buttonclassname);
    if (tcid1 != "") {
        closedbuttonclassname1 = document.getElementById(closedbuttonid1).className;
        closedbuttonclass1 = new String(closedbuttonclassname1);
        }
    if (tcid2 != "") {
        closedbuttonclassname2 = document.getElementById(closedbuttonid2).className;
        closedbuttonclass2 = new String(closedbuttonclassname2);
        }
    
    itemclassname = document.getElementById(itemid).className;
    itemclass = new String(itemclassname);
    if (tcid1 != "") {
        closeditemclassname1 = document.getElementById(closeditemid1).className;
        closeditemclass1 = new String(closeditemclassname1);
        }
    if (tcid2 != "") {
        closeditemclassname2 = document.getElementById(closeditemid2).className;
        closeditemclass2 = new String(closeditemclassname2);
        }
    
    
    if (buttonclassname == 'toolbox') {
        document.getElementById(buttonid).className = buttonclass.replace("toolbox","toolbox_hi");
        document.getElementById(dialogid).className = dialogclass.replace("toolbox_dialog","toolbox_dialog_hi");
        document.getElementById(itemid).className = itemclass.replace("toolbox_item","toolbox_item_hi");
        if (tcid1 != "") {
            document.getElementById(closedbuttonid1).className = closedbuttonclass1.replace("toolbox_hi","toolbox");
            document.getElementById(closeddialogid1).className = closeddialogclass1.replace("toolbox_dialog_hi","toolbox_dialog");
            document.getElementById(closeditemid1).className = closeditemclass1.replace("toolbox_item_hi","toolbox_item");
            }
        if (tcid2 != "") {
            document.getElementById(closedbuttonid2).className = closedbuttonclass2.replace("toolbox_hi","toolbox");
            document.getElementById(closeddialogid2).className = closeddialogclass2.replace("toolbox_dialog_hi","toolbox_dialog");
            document.getElementById(closeditemid2).className = closeditemclass2.replace("toolbox_item_hi","toolbox_item");
            }
    } else {
        document.getElementById(buttonid).className = buttonclass.replace("toolbox_hi","toolbox");
        document.getElementById(dialogid).className = dialogclass.replace("toolbox_dialog_hi","toolbox_dialog");
        document.getElementById(itemid).className = itemclass.replace("toolbox_item_hi","toolbox_item");
    }

    Cookie.set('toolbox', tbid);
}
/******************************************************************/
/********** Folder category functions *****************************/
/******************************************************************/
function category(catid) {
        
    catdialogid = "cat_" + catid;
    catbuttonid = "cat_but_" + catid;
   
    catdialogclassname = document.getElementById(catdialogid).className;
    catdialogclass = new String(catdialogclassname);
    catbuttonclassname = document.getElementById(catbuttonid).className;
    catbuttonclass = new String(catbuttonclassname);
    
    if (catbuttonclassname == 'category_item') {
        document.getElementById(catbuttonid).className = catbuttonclass.replace("category_item","category_item_hi");
        document.getElementById(catdialogid).className = catdialogclass.replace("category_dialog","category_dialog_hi");
    } else {
        document.getElementById(catbuttonid).className = catbuttonclass.replace("category_item_hi","category_item");
        document.getElementById(catdialogid).className = catdialogclass.replace("category_dialog_hi","category_dialog");
    }
    
}
/******************************************************************/
/********** FAQ category functions ********************************/
/******************************************************************/
function faq(faqnr) {
    faq_link = "faq_link_" + faqnr;
    faqid = "faq_" + faqnr;
    faqclassname = document.getElementById(faqid).className;
    faqclass = new String(faqclassname);
    
    var divtags = document.getElementsByTagName('div');
    for(var x = 0; x < divtags.length; x++) {
        var thisdiv = divtags[x];
        var classAttribute = String(thisdiv.className);    
        if(classAttribute == "folder_item_faq" || classAttribute == "folder_item_faq_active") {
            thisdiv.className = "folder_item_faq";
        }
        if(classAttribute == "folder_item_text_faq" || classAttribute == "folder_item_text_faq_hi") {
            thisdiv.className = "folder_item_text_faq";
        }
    }
    
    if (faqclass == 'folder_item_text_faq') {
        document.getElementById(faq_link).className =  "folder_item_faq_active";
        document.getElementById(faqid).className = "folder_item_text_faq_hi";
    }
    if (faqclass == 'folder_item_text_faq_hi') {
        document.getElementById(faq_link).className =  "folder_item_faq";
        document.getElementById(faqid).className = "folder_item_text_faq";
    }
}

/******************************************************************/
/********** Browsing in product lists and search results **********/
/******************************************************************/
function loadpages() {
    var divs = document.getElementsByTagName('div');
    var pages = 1;
        
    for (var i=0; i<divs.length; i++)
    {
        var div = divs[i];
        var idAttribute = String(div.getAttribute('id'));
            
        if (idAttribute.toLowerCase().indexOf('page_') == 0) 
        {
            pageArray[pages] = idAttribute;
            pages++;
            if (idAttribute != "page_1") {
                hideID(idAttribute);
            }
        }
    }
    document.getElementById("top_total_pages").innerHTML = pages - 1;
    document.getElementById("bottom_total_pages").innerHTML = pages - 1;
}
function showPage(page_nr) {
    document.getElementById("top_act_page").innerHTML = page_nr;
    document.getElementById("bottom_act_page").innerHTML = page_nr;
    activePage = page_nr * 1;
    
    /* left_bound = activePage - 2;
    if (activePage > pageArray.length - 3)
        left_bound -= activePage - (pageArray.length - 3);
    if (left_bound < 1)
        left_bound = 1;
        
    right_bound = activePage + 2;
    if (activePage < 3)
        right_bound += 3 - activePage;
    if (right_bound > pageArray.length)
        right_bound = pageArray.length; */
        
    
    for (var i=1; i<pageArray.length; i++)
    {
        var top_nr = document.getElementById("top_nr_" + i);
        var bottom_nr = document.getElementById("bottom_nr_" + i);
        if (i == page_nr) 
        {
            showID(pageArray[i]);
            top_nr.className = 'browser strong';
            bottom_nr.className = 'browser strong';
        } else {
            hideID(pageArray[i]);
            top_nr.className = 'browser';
            bottom_nr.className = 'browser';
            
            /* if (i >= left_bound && i <= right_bound) {
                showIDInline(top_nr.id);
                showIDInline(bottom_nr.id);
            } else {
                hideID(top_nr.id);
                hideID(bottom_nr.id);
            } */
        }
    }
    
    if (page_nr == 1) {
        hideID_visibility("top_prev");
        hideID_visibility("bottom_prev");
    } else {
        showID_visibility("top_prev");
        showID_visibility("bottom_prev");
    }
    
    if (page_nr == (pageArray.length - 1)) {
        hideID_visibility("top_next");
        hideID_visibility("bottom_next");
    } else {
        showID_visibility("top_next");
        showID_visibility("bottom_next");
    }
}
function hideID(id_name) {
    document.getElementById(id_name).style.display = 'none';
}
function hideID_visibility(id_name) {
    document.getElementById(id_name).style.visibility = 'hidden';
}
function showID(id_name) {
    document.getElementById(id_name).style.display = 'block';
}
function showID_visibility(id_name) {
    document.getElementById(id_name).style.visibility = 'visible';
}
function showNextPage() {
    showPage(activePage + 1);
}
function showPrevPage() {
    showPage(activePage - 1);
}
/******************************************************************/
/********** iFrame resizing in pic_text_thumbnails ****************/
/******************************************************************/
function adjustIFrame(val) {
    iframeHeight = val + "px";
    iframeId     = "media_iframe";
    document.getElementById(iframeId).style.height = iframeHeight;
}
/******************************************************************/
/********** Global gallery popup link *****************************/
/******************************************************************/
function popup_zoom(name,aid,width,height) {
    var linkname;
    var linkadr;
    var linkid;
    
    linkname = new String(name);
    linkid = new String(aid);
    linkadr = document.getElementById(linkid).rel;
    pwidth = width + 20;
    pheight = height + 69;
    
    win=window.open(linkadr,linkname,"resizable=yes,status=no,scrollbars=no,toolbar=no,menubar=no,width="+pwidth+",height="+pheight);
    win.focus();
    return false;
}
function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
           var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      } 
      // alert('Query Variable ' + variable + ' not found');
}
/******************************************************************/
/********** Global popup call *************************************/
/******************************************************************/
function picture_window(link_adr,name,scroll,width,height){
      fen=window.open("" + link_adr,name,"resizable=yes,status=no,scrollbars="+scroll+",toolbar=no,menubar=no,width="+width+",height="+height);
      fen.focus();
}
/******************************************************************/
/********** A08 scale_drawing *************************************/
/******************************************************************/
function loadscaledrawing() {
    var p_h1                     = opener.document.getElementById("h1").innerHTML;
    var p_h2                     = opener.document.getElementById("h2").innerHTML;
    var p_scaledrawing_numbers   = opener.document.getElementById("scaledrawing_numbers").innerHTML;
    var p_scaledrawing_image     = opener.document.getElementById("scaledrawing_image").innerHTML;
    i_scaledrawing_image = new Image();
    i_scaledrawing_image.src = p_scaledrawing_image;
    i_scaledrawing_image.onload = function () {
        document.getElementById("scaledrawing_height").style.height = i_scaledrawing_image.height + "px";
    };
    document.getElementById("h1").innerHTML                     = p_h1;
    document.getElementById("h2").innerHTML                     = p_h2;
    document.getElementById("scaledrawing_image").src           = p_scaledrawing_image;
    document.getElementById("scaledrawing_image").alt           = p_h1 + " " +  p_h2;
    document.getElementById("scaledrawing_image").title         = p_h1 + " " +  p_h2;
    document.getElementById("scaledrawing_numbers").innerHTML   = p_scaledrawing_numbers;
    
    /* Resize imageframe (necessary for ie - bug)*/
    //document.getElementById("scaledrawing_height").style.height = i_scaledrawing_image.height;
}

/******************************************************************/
/********** A01 search_result *************************************/
/******************************************************************/
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}


function highlightArtNr (searchterm) {
    $$("div").each(function(el){
        if (el.getProperty('name') == 'searchres_numbers') {
            strHit = el.innerHTML;
            searchterm = searchterm.replace(/[*]/g, '');
            var strregex = '/(' + trimAll(searchterm) + ')/gi';
            var str = strHit.replace(eval(strregex),'<span class="searchres_hi">$1</span>'); 
            el.setHTML(str);
        }
    });
}
function highlightRegExp( objRegExp, str ) {
    var orig = str, replacement = orig;
    
    var result = objRegExp.exec( orig );
    if( null != result ) {
        replacement = '';
        while( null != result ) {
            replacement += result[1]+'<span class="searchres_hi">'+result[2]+'</span>';
            
            orig = orig.substr( objRegExp.lastIndex );
            objRegExp.lastIndex = 0;
            
            result = objRegExp.exec( orig );
        }
        replacement += orig;
    }
    return replacement;
}
function highlightInnerHtml( objRegExp, objElement ) {
    var orig = objElement.innerHTML, replacement = highlightRegExp( objRegExp, orig );
    if( orig != replacement )
        objElement.setHTML( replacement );
}
function get_words(str) {
    var no_quotes = '';
    var arrPhrases = new Array();
    var last_pos = 0;
    var beg_quo;
    while( last_pos < str.length && ( beg_quo = str.indexOf( '"', last_pos ) ) >= 0 ) {
        no_quotes += ' ' + str.substr( last_pos, beg_quo - last_pos );
        var end_quo = str.indexOf( '"', beg_quo+1 );
        if( -1 == end_quo )
            last_pos = beg_quo + 1;
        else {
            last_pos = end_quo + 1;
            if( beg_quo+1 != end_quo )
                arrPhrases.push( mask_regexp( str.substr( beg_quo+1, end_quo-beg_quo-1 ) ) );
        }
    }
    if( last_pos < str.length )
        no_quotes += ' ' + str.substr( last_pos );
    no_quotes = mask_regexp( no_quotes );
    no_quotes = trimAll( no_quotes ).replace( /\s{2,}/gi, ' ' );
    if( no_quotes.length > 0 )
        arrPhrases = arrPhrases.concat( no_quotes.split( /\s+/ ) );
    return arrPhrases;
}
function mask_regexp(str) {
  //var plain_query = searchterm.replace(/[^\w^\s]/gi, '');
    str = str.replace( /[\*\+\-\"\']/gi, '' );
    return str.replace( /([\^\$\(\)\[\]\.\?\*\+\"\'\\])/gi, '\\$1' );
}
function highlightFulltext (searchterm) {
    searchterm = trimAll(searchterm);
    arr_words = get_words( searchterm );
     
    if( arr_words && arr_words.length > 0 ) {
        // sort words by LENGTH - the longest are earlier in order to highlite the longste word instead of subparts of the one
        arr_words.sort( function( x, y ) {
            return x.length < y.length ? 1 : ( x.length > y.length ? -1 : 0 );
        } );
        var re_words = arr_words.join( '|' );
//        var objRegExp = new RegExp( '^((?:[^<]*<[^>]*>)*?[^<]*?)(' + re_words + ')', 'gi' );
        var objRegExp = new RegExp( 
          '^(' + 
             '(?:[^<]*<[^>]*>)*?' + 
             '[^<&]*?' + // ---------------------------------------------- 
             '(?:' + 
                 '(?:&[^<;]+;)+' + 
                 '[^<&]*?' + 
             ')*?' + 
             '[^<&]*?' + 
          ')' + 
          '(' + re_words + ')', 'gi' );

        $$("div").each(function(el){
            if( el.hasClass('searchres_item_list') || el.hasClass('searchres_item_list_document') || el.getProperty('name') == 'searchres_numbers' )
                highlightInnerHtml( objRegExp, el );
        });
         
        $$("strong").each(function(el){
            if( el.hasClass('searchitem') )
                highlightInnerHtml( objRegExp, el );
        });
    }
}
/******************************************************************/
/********** A09 bathroom_gallery **********************************/
/******************************************************************/
function load_bathroomgallery() {


    var imageArray   = new Array;
    var imageNum     = 0;
    var anchors      = opener.document.getElementsByTagName('a');
    // Load all anchor elements from opening page in array
    for (var i=0; i<anchors.length; i++)
    {
        var anchor = anchors[i];
        var relAttribute = String(anchor.getAttribute('rel'));
        
        // Load thumbnails from title
        if (relAttribute == 'bathroom_gallery') {
            
            
            // string.match() reads all images from anchors with attribute rel="bathroomgallery[xx]" 
            if (anchor.getAttribute('title') && (relAttribute.toLowerCase().match('bathroom_gallery')))
            {
                thumbnailImage = new Image();
                thumbnailImage.src = anchor.getAttribute('title');
                thumbnailImage.title = anchor.innerHTML;
                    
                    document.getElementById('gallerythumbnails').innerHTML = document.getElementById('gallerythumbnails').innerHTML + '<div class="popup_imagegallery_item"><a onclick="changeGalleryImage(\'' + thumbnailImage.title + '\')" href="#"><img src="' + thumbnailImage.src + '" alt="Enlarge image" title="Enlarge image" \/><div class="reduce-3"></div></div><\/a><\/div>';
                
                /* Get first gallery image */
                if (imageNum == 0) {
                
                    firstImage = new Image();
                    firstImage.src = anchor.innerHTML;
                    
                    document.getElementById("galleryimage").src = firstImage.src;
                    
                }
                
                imageNum++;
                
            }
        }
    }
   
}
function changeGalleryImage(img) {
    var gImg = img;
    document.getElementById("galleryimage").src = gImg;
}



/******************************************************************/
/********** Visibility of JS-only Template-Elements ***************/
/******************************************************************/
document.write('<style type="text/css" media="screen">');
document.write('.folder_item_faq { padding: 2px 0 0 9px; }');
document.write('.category_item { background-image: url(/systemimages/SG/arrow-category-vr.gif); }');
document.write('.category_item,.category_item_hi { cursor: pointer; }');
document.write('.folder_item_faq { font-weight: normal; }');
document.write('.folder_item_faq { background-image: url(/systemimages/SG/nav-arrow-black-vr.gif); }');
document.write('.folder_item_faq, .folder_item_faq_active .black { cursor: pointer; }');
document.write('.folder_item_text_faq { display: none; }');
document.write('.category_dialog { display: none; }');
document.write('.cat_item_button { visibility: visible; }');
document.write('.toolbar_content_frame_product { background-color: #ebebeb; } ');
document.write('.toolbar_content_frame_product { height: 22px; } ');
document.write('.toolbar_content_frame_product { margin-top: 3px; } ');
document.write('.box_download_note_frame { display: block; } ');
document.write('.space15 { padding-bottom: 15px; } ');
document.write('<\/style>');
