﻿/** --------------------------------------------------------------------------- +
* Project:    D&Uuml;RR DENTAL AG
* Author:     Dirk Schroeer, Edoras GmbH & Co KG, www.edoras.de
* Module:     ddj_js.js
* Created:    2004-07-15
* ---------------------------------------------------------------------------- +
* Purpose:  All js for this page
* History:  2004-07-30 DS add Niederlassungen and vertretungen
*           2004-08-11 DS add Functions for multiple Teaser
*           2004-08-16 DS add ansprechpartner-list  
*           2005-01-20 DS add setOfficeArray() to change format for Niederlassungen
*           2005-02-17 DS sort regions and start filling on pos 1    
*           2005-07-11 DS insert browser-check to resolve problem in Niederlassungen   
* --------------------------------------------------------------------------- */
/* Init browser-check */
var bw=new lib_bwcheck()
 
/** 
*  control all functions on pageLoad
*/
function PageInit(s_pageURL)
{
    //activate main navigation, doesn't work in Reddot mode
    var i_navID = getPageID(s_pageURL);
    if(i_navID != 0)
    {
        changeImage(i_navID);
    }
}
// Background-Image for Header
function SetHeader(img)
{
    document.getElementById("header_img").style.backgroundImage = "url("+img+")";
}
function openLink(link)
{
    win = window.open("http://"+link, "DuerrLink", "width=800,height=600,left=50,top=50,scrollbars=yes,menubar=yes,resizable=yes");
    win.focus();
}
/****************** Image Navigation ****************************/
function effektberechnen(){
    if (document.all){
        //  display multiple changes
       document.getElementById("photolauf").filters.revealTrans.Transition=5
       // Math.floor(Math.random()*23)
       document.getElementById("photolauf").filters.revealTrans.stop()
       document.getElementById("photolauf").filters.revealTrans.apply() 
    }
}
function effektzeigen(){
    if (document.all)
    {
        document.getElementById("photolauf").filters.revealTrans.play()
    }
}
function wievielebilder(){
    window.status="Image "+(which+1)+" of "+photos.length
}
function zurueck(){
    if (which>0){
    which--
    effektberechnen()
    document.getElementById("photolauf").src=photos[which]
    document.getElementById("txt_img").innerHTML = photos_text[which]
    effektzeigen()
    wievielebilder()
    }
}
function weiter(){
    if (which<photos.length-1){
        which++
        effektberechnen()
        document.getElementById("photolauf").src = photos[which]
        document.getElementById("txt_img").innerHTML = photos_text[which]
        effektzeigen()
        wievielebilder()
    }    
}
function transport(){
    window.location=photoslink[which]
}
function zoom(){
    
    var img = photos_link[which]; 
    var winImg = window.open(img,  "DuerrImages", "width=450,height=340,left=50,top=50,resizable=yes,scrollbars=auto,");
    winImg.focus();
}
function resizeWin()
{
    var img = document.getElementById("ProductImg");    
    window.resizeTo((img.width+10),(img.height+30));
}
/*
function prealoadImages()
{
    var preloadedimages=new Array()
    for (i=0;ibr> preloadedimages[i]=new Image()
        preloadedimages[i].src=photos[i]
    } 
}
*/
// display navigation icons, if more then 1 image 
function getImgNavigation()
{     
    if(photos[which] != undefined)
    {
        document.getElementById("photolauf").src = photos[which]    
        document.getElementById("txt_img").innerHTML = photos_text[which]
    }    
    
    if(photos.length > 1)   
    {
        document.getElementById("img_back").style.visibility = "visible";        
        document.getElementById("img_next").style.visibility = "visible";     
    }
}
/************************************** Niederlassungen & Aussendienst *****************************************/
// 20050119 DS create office from officelist
// get officelist [REGION1:COUNTRY1,COUNTRY2#REGION2:COUNTRY1,COUNTRY2]         
// an formate it to standard office
function setOfficeArray()
{
 var counter = 0;
 
 for(var a=0;a<officelist.length; a++)
 {
   counter = officelist[a][1];
  if(officelist[a][0].indexOf("#") == -1)
  {
         var a_region = new Array();  
          a_region = officelist[a][0].split(":");   
   var entry = new Array(a_region[0], a_region[1], counter);      
     office.push (entry); 
  } else 
  {
         var a_office = new Array();
         a_office = officelist[a][0].split("#");  
  
   for(var c=0;c < a_office.length; c++)
   {
      var a_region = new Array();
      a_region = a_office[c].split(":");      
      var entry = new Array(a_region[0], a_region[1], counter);         
     office.push (entry);   
   }  
  }
 }
 return office;
}

////////////// fill Region List
function fillRegionList(office)
{
    setOfficeArray();
    var regionlist = document.getElementById("region");
    var a_double = new Array();
    var a_region = new Array(); 
    var entry = ""; 
    var i_cnt = 0;
   
    for(var i=0;i<office.length; i++)
    {
       entry = office[i][0];       
        // only unique entries
        if(!a_double[entry])         
        {    
            a_region[i_cnt++] = entry;
            // set value in compare list
            a_double[entry] = true;
        } 
    }
   fillDropDownList(a_region, regionlist, 0);
}
///// change umlauts for sorting in IE
function replaceUmlauts(string)
{
    if(!bw.ie)
    {
        return string;
    } else {
        string = encodeURI(string);
        string = string.replace(/%C3%84/, "Ae");
        string = string.replace(/%C3%96/, "Oe");
        return string; 
    }
}
///// Rechange Umlauts
function resetUmlauts(string)
{
    if(!bw.ie)
    {
        return string;
    } else {
        string = decodeURI(string);
        string = string.replace(/Ae/, "Ä");
        string = string.replace(/Oe/, "Ö");
        return string; 
    }
}
////////////// to use in other functions
var a_countries = new Array();
// fill Countries depend on region
function fillCountryList()
{
    hidePartners();
    emptyCountryList();
    regionlist  = document.getElementById("region");
    var countrylist = document.getElementById("country");
    var country_div = document.getElementById("countries");
    var a_double = new Array();
    var a_selectedCountrys = new Array();
    var entry = ""; 

    if(regionlist.value == "-") 
    {
       country_div.style.visibility = "hidden";
       return;
    }
    var x =0;
    for(var i=0;i<office.length; i++)
    {    
        // multiple countries accociated
        if(office[i][1].indexOf(",") != -1)
        {
            var a_country = new Array();
            a_country = office[i][1].split(",");
            for(var z = 0; z < a_country.length; z++)
            {     
                var s_country = alltrim(a_country[z]);
                a_countries[x] = new Array(office[i][0], s_country, office[i][2]);
                x++;
            }     
        }    
        else 
        {        
            // collect countries and associated person-id's
            a_countries[x] = new Array(office[i][0], office[i][1], office[i][2]);
            x++;    
        }
       }
    var i_list = 0;
    for(var i=0; i < a_countries.length; i++)
    {
        // only unique entries
        if((!a_double[a_countries[i][1]])             
            && (a_countries[i][0] == regionlist.value ))         
        {
            if(!bw.ie) 
            {        
                a_selectedCountrys[i_list++] = a_countries[i][1];
            } else {
                a_selectedCountrys[i_list++] = replaceUmlauts(a_countries[i][1]);
            }  
        }
        a_double[a_countries[i][1]] = true;
   }
   fillDropDownList(a_selectedCountrys, countrylist, 1);
   country_div.style.visibility = "visible"; 
}
/* fill DropDownList
 * @param entries Array
 * @param dll DropDownList
 * uml bool for sorting by umlauts 
 */
function fillDropDownList(entries, ddl, uml)
{ 
    // include empty entry
  var addmeEmpty = new Option("", "-");
  ddl.options.add(addmeEmpty); 

  if(!bw.ie) 
  {  
    // string comparison do not work in IE!
    entries.sort(stringComparison);
  } else {
    entries.sort();
  }
 for(var i=0;i<entries.length; i++)
 {
    if(!bw.ie)
    {
      var entry = entries[i];
      var entry1 = entries[i];
    } else {
      var entry = resetUmlauts(entries[i]);
      var entry1 = resetUmlauts(entries[i]);

    }
  if(entry.length <= 1) { continue; }  
  var addme = new Option(entry, entry);
  ddl.options.add(addme); 
  }     
}
// delete all entries in country list
function emptyCountryList()
{
    var countrylist = document.getElementById("country");
    countrylist.length = 0;
}
// hide all partner cards
function hidePartners()
{
    for(var i=0;i<office.length; i++)
    {
  if(document.getElementById("partner_"+i))
  {
         document.getElementById("partner_"+i).style.display = "none";    
  }
    }
}
function hideError()
{    
    document.getElementById("error_txt").style.display = "none";    
}
///// display Partners for niederlassungen & vertretungen
function displayPartner()
{    
    hidePartners();
    var region =  document.getElementById("region").value;
var country = document.getElementById("country").value;
    if(country == "-") return
    var i_counter = 0;
    for(var i=0;i<a_countries.length; i++)
    {
        if(a_countries[i][1] == country)
        {
            // list the cards, multiple possible
            displayPartners(a_countries[i][2], i_counter);
            i_counter++;    
        }
    }    
    // nothing found
    if(i_counter == 0)
    {
        displayError();
    }    
}
// display partners for Aussendienst in Deutschland
function getAussendienst()
{
    hidePartners();
    hideError();
    var plz1 = document.getElementById("plz1").value;
    var plz2 = document.getElementById("plz2").value;
    var plz3 = document.getElementById("plz3").value;
    var a_partners = new Array();
    var a_double = new Array();
    
    // create new array from plz-list
    var a_plz = new Array();
    var x =0;
    for(var i=0;i<office.length; i++)
    {    
        // multiple plz associated
        if(office[i][0].indexOf(";") != -1)
        {
            var a_plz_temp = new Array();
            a_plz_temp = office[i][0].split(";");
             for(var z = 0; z < a_plz_temp.length; z++)
            {     
                var s_plz = alltrim(a_plz_temp[z]);
                a_plz[x] = new Array(s_plz, i);
        
                x++;
            }     
        }    
        else 
        {        
            // collect countries and associated person-id's
             a_plz[x] = new Array(a_plz_temp[z], i);
            x++;    
        }
       }
    //a_plz.sort();
    if(plz1 == "")
    {
        return;
    } else  {
        if(plz2 != "")
        {
            if(plz3 !== "")
            {
                // PLZ 1 + 2 + 3
                var i_cnt = 0;
                for(var i=0;i<a_plz.length; i++)
                {
                    var s_plz =  a_plz[i][0]; 
                    if((plz1 == s_plz.charAt(0))
                        && (plz2 == s_plz.charAt(1)) 
                        && (plz3 == s_plz.charAt(2))) 
                    {
                        // only unique entries
                        if(!a_double[a_plz[i][1]])         
                        {                        
                            a_partners[i_cnt] = a_plz[i][1];
                            i_cnt++;
                            a_double[a_plz[i][1]] = true;
                        }
                    } 
                }
            } else {
                // only PLZ 1 + 2
                var i_cnt = 0;
                for(var i=0;i<a_plz.length; i++)
                {
                    var s_plz =  a_plz[i][0]; 
                    if((plz1 == s_plz.charAt(0))
                        && (plz2 == s_plz.charAt(1))) 
                    {
                        // only unique entries
                        if(!a_double[a_plz[i][1]])         
                        {    
                            a_partners[i_cnt] = a_plz[i][1];
                            a_double[a_plz[i][1]] = true;
                            i_cnt++;
                        }
                    } 
                }
            }
        } else {
            // only PLZ 1
            var i_cnt = 0;
            for(var i=0;i<a_plz.length; i++)
            {
                var s_plz =  a_plz[i][0]; 
                if(plz1 == s_plz.charAt(0))
                {
                    // only unique entries
                    if(!a_double[a_plz[i][1]])         
                    {    
                        a_partners[i_cnt] = a_plz[i][1];
                        a_double[a_plz[i][1]] = true;
                        i_cnt++;
                    }
                } 
            }
        }
    }
    
    // display partners
    var i_counter = 0;
    for(var i=0;i<a_partners.length; i++)
    {
        displayPartners(a_partners[i], i_counter);
        i_counter++;    
    }
    // nothing found
    if(i_counter == 0)
    {
        displayError();
    }        
}    
// display partners
function displayPartners(i_partner, i_counter)
{
    // list the cards, multiple possible
    var item = document.getElementById("partner_"+i_partner);
    var distance = (175 * i_counter) + 280;
    item.style.top = distance+"px";
    item.style.display = "block";
}
// display default message
function displayError()
{
    var item = document.getElementById("error_txt");
    var distance = 280;
    item.style.top = distance+"px";
    item.style.display = "block";
}
/********************* MULTIPLE TEASER *************************************/
// display and highlight selected card, hide the others
function displayCard(i_card)
{    
    // arrow-image on topline
    var o_img_arr = document.getElementById("img_arr");    
    var i_distance = 94 * (i_card - 1);
    if(i_card == 3) i_distance += 1;        // don't ask me...
    o_img_arr.style.marginLeft = i_distance+"px";  
    
    for(var i=1; i<=3; i++)
    {
        var o_card = document.getElementById("card_"+i);    
        var o_head = document.getElementById("head_"+i);    
        if(i == i_card)
        {    
            o_card.style.zIndex = "10";
            o_card.style.visibility = "visible";
            o_head.style.backgroundColor = "#FFFFFF";
        } else {
            o_card.style.visibility = "hidden";
            o_head.style.backgroundColor = "#66CCFF";
        }
    }    
}
/********************************  TOOLBAR  *********************************/
function addToFavorites(urlAddress, pageName)
 {
  if (window.external)
  {
   //alert("urlAddress:"+urlAddress+" | pageName:"+pageName);
   window.external.AddFavorite(urlAddress,pageName)
  }
  else
  { 
   alert("Error: Your browser doesn't support this function.");
  }
 }
/*************************** ANSPRECHPARTNER SEITEN-LISTEN ******************/
// fill Person List
function fillPersonList()
{
    var o_personlist = document.getElementById("personlist");
    var i_cnt = 1; 
    
    for(var i=0; i < a_personList.length; i++)
    {
           var addme = new Option(a_personList[i][0], a_personList[i][1]);            // fill list
        o_personlist.options[i_cnt] = addme;
        if(a_personList[i][0] == s_hdl_page)
        {
            o_personlist.options.selectedIndex = i+1;        // select current entry in list
        }    
        i_cnt++;
    }
}
// jump to selectet page
function gotoPage()
{
    var o_personlist = document.getElementById("personlist");
    if(o_personlist.options[o_personlist.options.selectedIndex].value == "-") return
    document.location.href = o_personlist.options[o_personlist.options.selectedIndex].value;
}
/*********************** GENERAL FUNCTION *****************************/
// trim all whitespaces
function alltrim(wert)
{
    s=s=/(^\s+|\s+$)/g
    wert=wert.replace(s,"")
    return wert
}
/** --------------------------------------------------------------------------- +
* Project:  JS
* Author:  Dirk Schroeer, Edoras GmbH & Co KG, www.edoras.de
* Module:  functions.js
* Created:  2004-08-24
* ---------------------------------------------------------------------------- +
* Purpose:  often used JS-Functions for RedDot
* History: 
* --------------------------------------------------------------------------- */
/* ACTIVATE MENUS
*  activate multiple menu-struktures by CSS 
*/
function displayNav()
{
 
 if(navID )
 {
    /* MAINNAV */
/*    
    if(document.getElementById("nav_main_"+navID))
    {
        document.getElementById("nav_main_"+navID).className = "Nav1_act"; 
    }
*/    /* ICON NAV */
    if(document.getElementById("nav_main_"+navID))
    {
       img = document.getElementById("nav_main_"+navID);
       s_SrcNew = getImgAkt(img.src);
       // set new Img   
       if(s_SrcNew)
       {
           img.src = s_SrcNew;        
       }   
       if(document.getElementById("Nav2_Text_"+navID))
       { 
           span = document.getElementById("Nav2_Text_"+navID);
           span.innerHTML = img.alt; 
           span.style.visibility = "visible"; 
 
       }
    }
  }
/*
  // 2. Nav-Ebene  
  if(pageID > 0)
  {
   //alert("pageID = "+pageID);    
    // SUBNAV-TEXT
    if(document.getElementById("Nav1_1#"+pageID))
    {
        document.getElementById("Nav1_1#"+pageID).className = "Nav1_1_act"; 
    }
    if(document.getElementById("Nav1_2#"+pageID))
    {
        document.getElementById("Nav1_2#"+pageID).className = "Nav1_2_act"; 
    }
    
  }
  // 3. Nav-Ebene
  if(pageID > 0)
  {
   //alert("pageID = "+pageID);    
    // SUBNAV-TEXT
    if(document.getElementById("Nav1_1_1#"+pageID))
    {
        document.getElementById("Nav1_1_1#"+pageID).className = "Nav1_1_1_act"; 
    }
    
  }
  // DISPLAY BACK-BUTTON IN NAVIGATE IN TARGET-CONTAINER  
  if(pageTC == 1)
  {
    if(document.getElementById("BackButton"))
    {    
        document.getElementById("BackButton").className = "DisplayBackButton"; 
    }
    if(document.getElementById("img_BackButton"))
    {    
        document.getElementById("img_BackButton").width= 126; 
        document.getElementById("img_BackButton").height = 18; 
    }
  }  
*/
}
/* ROLL-OVER BY IMAGE
*  changing imgage to image_akt if not active
*  this roll over returns to original image
*  @param s_ID image-ID 
*/
function getRollover(s_ID)
{
    if(document.getElementById(s_ID))
    {    
        img = document.getElementById(s_ID);
        s_Src = img.src;
        // no rollover if active 
        if(s_Src.indexOf("_act") == -1)
        {
            s_SrcNew = getImgAkt(s_Src);
            img.src = s_SrcNew;
        }
        // reset Image
        img.onmouseout = new Function('img.src=s_Src');    
    }
}
/* ROLL-OVER BY CSS-CLASS 
*  changing CSS-class and return on mouseout
*  @param: element ID
*/
function getRolloverByClass(s_ID)
{
    if(document.getElementById(s_ID))
    {    
        element = document.getElementById(s_ID);
        s_Class = element.className;
        // no rollover if active 
        if(s_Class.indexOf("_act") == -1)
        {
            s_ClassNew = s_Class+"_act";
            element.className = s_ClassNew;
        }
        // reset Class
        element.onmouseout = new Function('element.className=s_Class');    
    }
}
/**
* DEACTIVATE ALL AND ACTIVATE CURRENT BUTTON 
* @param: current button ID
*/
function actProject(s_ID)
{    
    // deactivate all buttons
    var i = 1;
    while (i < 15) 
    {    
        s_AllID = "Nav_Projects#"+i;
        if(!document.getElementById(s_AllID))
        {
            break;
        }
        document.getElementById(s_AllID).className = "Nav_Projects";
        i++;
    }
    // activate current Button 
    document.getElementById(s_ID).className = "Nav_Projects_act";
}
/**
*  ACTIVATE IMAGE
*  changing imgage to image_act if not active
*  @param s_ID : String image-ID 
*/
function changeImage(s_ID)
{
    if(document.getElementById(s_ID))
    {    
        img = document.getElementById(s_ID);
        s_Src = img.src;
        s_SrcNew = getImgAkt(s_Src);
        img.src = s_SrcNew;
    }
}
/* DISPLAY SELECTED CONTENT SPAN, HIDE THE OTHER 
*  @param: span-ID
*/
function dspContent(s_Cnt)
{
    // hide all spans
    i = 1;
    do {
        i_old = i;
        if(document.getElementById('cnt_'+i))
        {    
            document.getElementById('cnt_'+i).style.visibility = "hidden"; 
            i = i+1;
        }
    } while(i>i_old);
    // display selected
    if(document.getElementById(s_Cnt))
    {    
        document.getElementById(s_Cnt).style.visibility = "visible"; 
    }
}
/* EXTRACT IMG-NAME FROM SRC AND ADD '_act' 
*  used in Roll-over functions
*  @param: image-src
*/
function getImgAkt(s_Src)
{
  a_Src = s_Src.split("/");
  i_LastEntry = a_Src.length-1 ;       // count entries
  s_Temp = a_Src[i_LastEntry] ;        
  s_Img = s_Temp.slice(0, (s_Temp.length-4));    // Name of Img
  s_ImgType = s_Temp.slice(s_Temp.length-4);     // type of Img e.g. '.gif'   
  i_ImgLength = s_Img.length;                    // length of img to delete from src   
  s_SrcRest = s_Src.slice(0, (s_Src.length - s_Temp.length));       // get src without img   
  s_SrcNew = s_SrcRest+s_Img+"_act"+s_ImgType;      
 
  return s_SrcNew;  
}
/** EXTRACT PAGE-ID FROM TARGET-CONTAINER URL
*  @param: URL  e.g."www.page.de/10_342.html"
*/
function getPageID(s_Url)
{ 
 /* check, if RedDot-Mode */
 if (s_Url.indexOf("ioRD.asp") == 1)
 {
   return 0;   
 } else {
  a_ID = s_Url.split("_");  
  s_Temp = a_ID[a_ID.length-1] ;
  s_ID = s_Temp.slice(0, (s_Temp.length-4));
 }
 if(s_ID)
 {   
    return s_ID; 
 }
}
/** POPUPS 
*  @param: URL
*/
function popupWin(file)
{
    win = window.open(file,"NAME","width=621,height=600,left=50,top=50,resizable=yes,scrollbars=yes");   
    win.focus(); 
}
function popupLink(file)
{
    winLink = window.open(file,"NAME","width=800,height=600,left=50,top=50,resizable=yes,scrollbars=yes");   
    winLink.focus(); 
}
/** 
 * Display Text in span, div or other element
 * @param id String
 * @parma text String
 */
 function displayTextInDiv(s_ID, s_Text)
 {
  var div = document.getElementById(s_ID);
 div.innerHTML = s_Text;
 }
/**
 * Dient als Comparator für die Methode Array.sort und
 * definiert, wie Characters verglichen werden sollen.
 * Ignoriert Groß- Kleinschreibung und sortiert Umlaute
 * zu den entsprtechenden Selbstlauten.
 * (ä == a, ß == s, usw.)
 * @param a erstes Argument
 * @param b zweites Argument
 * @return  0, wenn beide Argumente gleich sind
 *   -1, wenn a größer als b ist
 *    1, sonst
 */
function stringComparison(a, b) {
  try{
 a = a.toLowerCase();
 a = a.replace(/ä/g,"a");
 a = a.replace(/ö/g,"o");
 a = a.replace(/ü/g,"u");
 a = a.replace(/ß/g,"s");
 b = b.toLowerCase();
 b = b.replace(/ä/g,"a");
 b = b.replace(/ö/g,"o");
 b = b.replace(/ü/g,"u");
 b = b.replace(/ß/g,"s");
 return(a==b)?0:(a>b)?1:-1;
  } catch (e){
 //   alert("fehler: "+a+"- "+b);
   return false;
  }
}
/* ---------------------------------------------------------------------------
 *  File:   clsBrowser.js
 *  Projekt:  CLASS
 *  Author:  Dirk Schröer 
 *         http://www.edoras.de
 *  Date:   2002-06-27
 * ----------------------------------------------------------------------------
 *  Description:   Check the Browser. With bw.X all attributes can be used 
 *      Example: VAR = bw.ie?10:bw.ns?20:bw.opera5?30:40;
 *      set an VAR for IE on 10, NS on 20, Opera5 on 30 
 *      and as default value on 40   
 *  Last Mofification  
 *  
 * ----------------------------------------------------------------------------
*/
function lib_bwcheck(){ 
 this.ver=navigator.appVersion
 this.agent=navigator.userAgent
 this.dom=document.getElementById?1:0
 this.opera5=this.agent.indexOf("Opera 5")>-1
 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
 this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
 this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
 this.ie=this.ie4||this.ie5||this.ie6
 this.mac=this.agent.indexOf("Mac")>-1
 this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 this.ns4=(document.layers && !this.dom)?1:0;
 this.ns=this.ns4||this.ns6
 this.bw=(this.ie || this.ie6 || this.ie5 || this.ie4 || this.ns || this.ns4 || this.ns6 || this.opera5)
 return this
}