// onload = init;

addEvent( window, 'load', init )

function init() {
 dynamizeLinklists();
 displayDate();
 checkPresenceOf('MAPA-1x1');
}

function soutezPopup(url) {
window.open(url,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=425,HEIGHT=500")
}

/*
* myfalidate([formulář=objekt],[class povinných inputů=string])
* předpokládá, že všechny testované inputy mají vlastního parenta (např. <p>)
* testované inputy musí mít jako první class [reqInputClassName]
* v druhém classu můžete být konkrétní typ (number|date|email|string)
* přidané je testování vypnlěnosti "jedné z" (pouze pro jedinou skupinu)
* warning se vypíše do (prvního) tagu ([warningTagName]) v daném kontejneru
*/
function myfalidate(thisForm,reqInputClassName,warningType) {
 var warningTagName = 'strong';
 var fullWarningClass = 'myfalidatewarning';
 // přidáme za všechny testované inputy prázdná warning
 for( var i = 0; i < thisForm.elements.length; i++) {
  if ( thisForm.elements[i].className.length >= reqInputClassName.length ) {
   if ( thisForm.elements[i].className.split(' ')[0] == reqInputClassName ) {
    if ( warningType == 'border') {
     thisForm.elements[i].className = thisForm.elements[i].className.replace(/ warning/g,'');
    } else {
     setWarning(thisForm.elements[i],'');
    }
   }
  }
 }
 // ale result vrátíme na "ano"
 result = true;
 // ale testované věci ne
 var oneOf = 'chybi';

 for( var i = 0; i < thisForm.elements.length; i++) {
  if ( thisForm.elements[i].className.length >= reqInputClassName.length ) {
   if ( thisForm.elements[i].className.split(' ')[0] == reqInputClassName ) {
    curr = thisForm.elements[i];
    currSecondClass = thisForm.elements[i].className.split(' ')[1];
    currValue = thisForm.elements[i].value;

    if ( currSecondClass == 'email' ) {
     if ( curr.value.search(/[^@]+@.+\..+/) == -1 ) {
      setWarning(curr,'Vložte prosím platnou e-mailovou adresu.');
     }
    } else if ( currSecondClass == 'number' ) {
     if ( curr.value.search(/^\d+$/) == -1 ) {
      setWarning(curr,'Vložte prosím číslo.');
     }
    } else if ( currSecondClass == 'looseNumber' ) {
     if ( curr.value.search(/[a-zA-Z]/) > -1 || curr.value.search(/\d/) == -1 ) {
      setWarning(curr,'Vložte prosím číslo.');
     }
    } else if ( currSecondClass == 'date' ) {
     if ( curr.value.search(/^(\d)?\d\.(\d)?\d\.\d\d\d\d$/) == -1 ) {
      setWarning(curr,'Vložte prosím datum ve formátu <code>dd.mm.rrrr<\/code>.');
     }
/* přidáno */
    } else if ( currSecondClass == 'oneOf' ) {
     if ( curr.value.length != 0 ) {
      oneOf = 'nechybi';
     }
/* /přidáno */
    } else {
     if ( curr.value.length == 0 ) {
      setWarning(curr,'Vyplňte prosím.');
     }
    }
   }
  }
 }
/* přidáno */
 if (oneOf == 'chybi') {
  for( var g = 0; g < thisForm.elements.length; g++) {
   if ( thisForm.elements[g].className.split(' ')[1] == 'oneOf' ) {
    setWarning(thisForm.elements[g],'Vyplňte prosím alespoň jeden z těchto.');
   }
  }
 }
/* /přidáno */

 /* přidá text [str] za [obj]ekt do tagu [warningTagName] (viz začátek) */
 function setWarning(obj,str) {
  result = false;
  if ( warningType == 'border') {
   obj.className += ' warning';
  } else {
   if ( obj.parentNode.getElementsByTagName(warningTagName).length == 0 ) {
    var novyObj = document.createElement(warningTagName);
    novyObj.className = fullWarningClass;
    obj.parentNode.appendChild(novyObj);
   } else {
    obj.parentNode.getElementsByTagName(warningTagName)[0].innerHTML = str;
    obj.parentNode.getElementsByTagName(warningTagName)[0].className = fullWarningClass;
    if (str == '') {
     obj.parentNode.getElementsByTagName(warningTagName)[0].className = '';
    }
   }
  }
 }
 return result

}




/*
* hratky s #dynaLinky - schovavani "neaktivnich" divu
*/


function dynamizeLinklists() {
 if ( document.getElementById('dynaLink') ) {
  anchorDivs = getElementsByClassName(document, 'div', 'anchor');
  if ( document.location.hash && document.location.hash.length > 2 )
  { show( document.location.href.split('#')[1] );
  } else { show(anchorDivs[0].id); }
  var dynaLink = document.getElementById('dynaLink');
  var lasos = dynaLink.getElementsByTagName('a');
  for (var g = 0; g < lasos.length; g++) {
   addEvent( lasos[g], 'click', showActive );
  }
 }
}

function hideAll(elArray) {
 for (var g = 0; g < elArray.length; g++) {
  elArray[g].style.display = 'none';
 }
}
function decorActLink(actLinkID) {
 var elArray = document.getElementById('dynaLink').getElementsByTagName('a');
 for (var g = 0; g < elArray.length; g++) {
  if ( elArray[g].href.split('#')[1] != actLinkID ) {
   elArray[g].className = 'normal';
  } else {
   elArray[g].className = 'active';
  }
 }
}

function show(elemID) {
 hideAll(anchorDivs);
 decorActLink(elemID);
 actElem = document.getElementById(elemID);
 actElem.style.display = 'block';
}


function showActive() {
  actID = this.href.split('#')[1];
  show(actID);
  this.className = 'active';
  /* this.style.fontWeight = 'bold'; */
}



/*
* hratky s mapou kontaktu
*/
function sortniMapu(podleceho){
 if ( window.location.href.search(/Mapa.html/) != -1 ) {
  if (podleceho.search(/allBCS/) != -1) { filterTrsByClass('BCS'); }
  if (podleceho.search(/allBDS/) != -1) { filterTrsByClass('BDS'); }
  window.location =  document.forSearch.garagetype.value;
// alert('yoy');
 }
}

function pop(elemToShow) {
 if (this.href.split('#')[1]) {
  elemToShow = this.href.split('#')[1];
 }
 krajeDisplay('none');
 document.getElementById(elemToShow).style.display = 'block';
}

/*
* cssTransProp('mu-he-he') vrátí hlášku 'muHeHe'
*/
function cssTransProp(cssProp) {
 if ( document.all && !window.opera ) {
  while ( cssProp.search(/-./) != -1 ) {
   cssProp = cssProp.replace( /-./ , cssProp.charAt(cssProp.search(/-/)+1).toUpperCase() );
  }
  // obezlička kvůli IEčkovskému nevyzpytatelnému displayi u TR
  if ( cssProp == 'tableRow' ) { cssProp = 'block'; }
 }
 return cssProp;
}

/* STARE filtrovani seznamu autoservisu podle jejich tridy
 *
 * function filterTrsByClass(whichClass) {
 *  krajeDisplay('block');
 *  var trs= document.getElementById('KRAJE').getElementsByTagName('tr');
 *  for( var g = 0; g < trs.length; g++ ) {
 *   trs[g].style.display = cssTransProp('table-row');
 *   var rgx= new RegExp(whichClass);
 *   var curClass= trs[g].className;
 *   var result=rgx.test(curClass);
 *   if ( !result && curClass != 'thead' ) {
 *    trs[g].style.display = cssTransProp('none');
 *   }
 *  }
 * }
 *  
 */


// schova tabulky s nulovym poctem vypsanych servisu
function filterEmptyTables() {
 var tables = document.getElementById('KRAJE').getElementsByTagName('table');
 for( var i = 0; i < tables.length; i++ ) {
   var trs = tables[i].getElementsByTagName('tr');
   if (trs.length == 2) tables[i].style.display = 'none';
 }
}
 
/* NOVE filtrovani seznamu autoservisu podle jejich tridy */
function filterTrsByClass(whichClass) {
 krajeDisplay('block');
 var tables = document.getElementById('KRAJE').getElementsByTagName('table');
 for( var i = 0; i < tables.length; i++ ) {
   var cnt = 0; // pocitadlo odfiltrovanych radku
   var trs = tables[i].getElementsByTagName('tr');
   for( var g = 0; g < trs.length; g++ ) {
     trs[g].style.display = cssTransProp('table-row');
     var rgx= new RegExp(whichClass);
     var curClass= trs[g].className;
     var result=rgx.test(curClass);
     if ( !result && curClass != 'thead' ) {
      trs[g].style.display = cssTransProp('none');
      cnt++;
     }
     else {
      var odkaz = trs[g].getElementsByTagName('a')[0];
      if(odkaz && (odkaz.length != 0)) {
        odkaz.href += '?type=' + window.location.hash.substr(-3);
      }
     }      
   }
   /* pokud odfiltruju vsechny servisy, schovam kraj */
   if (cnt==(trs.length-2)) { tables[i].style.display = 'none'; }
 }
}

function checkPresenceOf(checkedId) {
 if ( document.getElementById(checkedId) ) {
   // dejEventyTagum('area', 'pop', 'click');
   checkHash();
 }
}

function checkHash() {
 if ( window.location.hash ) {
  popFromUrl();
 }
}

function krajeDisplay(jak) {
 var kraje = getElementsByClassName(document, 'div', 'kraj');
 for (var i = 0; i < kraje.length; i++) {
  kraje[i].style.display = jak;
 }
 if ( jak == 'block' ) {
  var trs=document.getElementById('KRAJE').getElementsByTagName('tr');
  for( var g = 0; g < trs.length; g++ ) {
  trs[g].style.display = cssTransProp('table-row');
  }
 }
}

function dejEventyTagum(elmName, funcName, evName) {
 var elms = document.getElementsByTagName(elmName);
 for (var j = 0; j < elms.length; j++) {
  addEvent(elms[j], 'click', pop );
 }
}

function returnClass() {
  if ( document.referrer ) {
    var urlHash = document.referrer.substr(-3);
    var rgxC = new RegExp('all|BCS|BDS|BDC');
    var resultC = rgxC.test(urlHash);
    if (resultC) {
      return urlHash;
    }
  }
}

function popFromUrl() {
 var urlHash = window.location.hash.substr(1);
 var rgx2= new RegExp('all|allBCS|allBDS|allBDC');
 var result2=rgx2.test(urlHash);
 if (result2) {
  if (urlHash == 'all') { krajeDisplay('block'); }
  if (urlHash == 'allBCS') { filterTrsByClass('BCS'); }
  if (urlHash == 'allBDS') { filterTrsByClass('BDS'); }
  if (urlHash == 'allBDC') { filterTrsByClass('BDC'); }
 } else {
  pop(urlHash);
 }
}

/*
* addEvent - Written by John Resig
* http://ejohn.org/projects/flexible-javascript-events/
* addEvent( document.getElementById('foo'), 'click', doSomething );
*/
function addEvent( obj, type, fn ) {
 if ( obj.attachEvent ) {
  obj['e'+type+fn] = fn;
  obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
  obj.attachEvent( 'on'+type, obj[type+fn] );
 } else {
  obj.addEventListener( type, fn, false );
 }
}
function removeEvent( obj, type, fn ) {
 if ( obj.detachEvent ) {
  obj.detachEvent( 'on'+type, obj[type+fn] );
  obj[type+fn] = null;
 } else {
  obj.removeEventListener( type, fn, false );
 }
}

/*
* getElementsByClassName - Written by Jonathan Snook,
* http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
 var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
 var arrReturnElements = new Array();
 var arrRegExpClassNames = new Array();
 if(typeof oClassNames == "object"){
  for(var i=0; i<oClassNames.length; i++){
   arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
  }
 }
 else{
  arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
 }
 var oElement;
 var bMatchesAll;
 for(var j=0; j<arrElements.length; j++){
  oElement = arrElements[j];
  bMatchesAll = true;
  for(var k=0; k<arrRegExpClassNames.length; k++){
   if(!arrRegExpClassNames[k].test(oElement.className)){
    bMatchesAll = false;
    break;
   }
  }
  if(bMatchesAll){
   arrReturnElements.push(oElement);
  }
 }
 return (arrReturnElements)
}


/* ======================================

   Farben fĂĽr die einzelnen MenĂĽs

====================================== */
// function tMenu (menuName, bgColorDefault, bgColorHighlight, bgColorActive, ...)
var menu = new Array ();
menu[0] = new tMenu ('navi', '#153B63', '#1B528C', '#2269B5');
menu[1] = new tMenu ('navigreen', '#00664A', '#008F68', '#00CF88');
menu[2] = new tMenu ('navigreen02', '#00826C', '#12A592', '#23C8B8');
menu[3] = new tMenu ('navicontent', '#1B528C', '#2269B5', '#2269B5');
menu[4] = new tMenu ('navicontentgreen', '#E9F5EE', '#A7DCBC', '#A7DCBC');
menu[5] = new tMenu ('navicontentgreen02', '#DEF3EF', '#83D0B8', '#83D0B8');
menu[6] = new tMenu ('navilist', '#FFFFFF', '#DFE9F4', '#DFE9F4');
menu[7] = new tMenu ('navilistgreen', '#FFFFFF', '#E9F5EE', '#E9F5EE');
menu[8] = new tMenu ('navilistgreen02', '#FFFFFF', '#DEF3EF', '#DEF3EF');
menu[9] = new tMenu ('navirechts', '#DFE9F4', '#B4C6D9', '#B4C6D9');
menu[10] = new tMenu ('navirechtsgreen', '#E9F5EE', '#A7DCBC', '#A7DCBC');
menu[11] = new tMenu ('navirechtsgreen02', '#DEF3EF', '#83D0B8', '#83D0B8');
menu[12] = new tMenu ('additionalnavi', '#B4C6D9', '#A0B7CF', '#8CA8C5');





/* ======================================

   MenĂĽ-Funktionen

====================================== */

// Highlight or un-highlight menu items
function MenuHighlight (MenuItemID, Highlight, menuId) {

  if (debug && !Highlight) window.status = 'MenĂĽpunkt-ID: ' + MenuItemID + ', MenĂĽ-ID: ' + menuId;
  menuId = (menuId == null) ? 0 : menuId;
  if (Highlight == 2) {
    menu[menuId].curItemName = MenuItemID;
  }

  var tdIterator = 0;
  var DocMenuItemTD = '';
  var Color = Highlight ? menu[menuId].bgColorHighlight : menu[menuId].bgColorDefault;
  Color = (Highlight == 2) ? menu[menuId].bgColorActive : Color; // Highlight Page Menu Item

  // Highlight all TDs which build the menu item
 if (document.all) {
   while ( (DocMenuItemTD = eval ('document.all.td' + MenuItemID + 't' + tdIterator) ) && ( (MenuItemID != menu[menuId].curItemName) || (Highlight == 2) ) ) {

     DocMenuItemTD.style.backgroundColor = Color;
    tdIterator++;
  }
 } else if (document.body) {
   DocMenuItemTD = document.getElementsByTagName ('td')['td' + MenuItemID + 't' + tdIterator];
   while ( DocMenuItemTD && ( (MenuItemID != menu[menuId].curItemName) || (Highlight == 2) ) ) {
     DocMenuItemTD.style.backgroundColor = Color;
    tdIterator++;
    DocMenuItemTD = document.getElementsByTagName ('td')['td' + MenuItemID + 't' + tdIterator]
  }
 }

} // function MenuHighlight


function PageStartup () {

 // Select whether position properties need to be set as numbers or e. g. '12px'
 if (document.body) {
  document.getElementsByTagName ('body')[0].style.left = 0;
  px = (String(document.getElementsByTagName ('body')[0].style.left).indexOf ('p') == -1) ? '' : 'px';
 } else {
  px = 0;
 }

  // Highlight current page menu item(s)
  var menuItemId, menuId;
  for (var i=0; i < PageStartup.arguments.length; i=i+2) {
    menuItemId = PageStartup.arguments[i];
    menuId = (PageStartup.arguments[i+1] != null) ? PageStartup.arguments[i+1] : 0;
    MenuHighlight (menuItemId, 2, menuId);
    menu[menuId].pageItemName = menuItemId;
    // open all menu items above menuItemId
    itemNameArray = menuItemId.split('cm');
    var predecItemName = 'dv';
    for (var l = 1; l < itemNameArray.length; l++) {
      predecItemName += 'cm' + itemNameArray[l];
      if (l > 1) clickItem (getItemById (predecItemName), menuId, true);
    }
  }

} // function PageStartup




/* ======================================

   Constants, global variables, type constructors

====================================== */


// "Konstanten" zur Browser-KompatibilitĂ¤t
var px = '';
var visible = (document.layers) ? 'show' : 'visible';
var hidden = (document.layers) ? 'hide' : 'hidden';

function tMenu (menuName, bgColorDefault, bgColorHighlight, bgColorActive, left, top, isPopUp, opensOnMouseOver, opensOnlyOneItem) {

 this.name = menuName;
 this.bgColorDefault = bgColorDefault;
 this.bgColorHighlight = bgColorHighlight;
 this.bgColorActive = bgColorActive;
 this.left = left;
 this.top = top;
 this.isPopUp = isPopUp;
 this.opensOnMouseOver = opensOnMouseOver;
 this.opensOnlyOneItem = opensOnlyOneItem;

 this.curItemName = '';
 this.pageItemName = '';
 this.isCurItemOpen = false;
 this.MouseOutTimeout = 0;
 // this.item = new Array();

} // function tMenu


/* ======================================

   Debug stuff

====================================== */

var debug = false;


function dm (message) {

  if ( debug && (document.forms.debug) ) alert (message); // document.forms.debug.elements.dta.value += message + '\n';

} // function dm



/* ======================================

   Open external product special windows

====================================== */




function open540421 (url) {
// Verwendet bei: Productspecials (GW)
 params = "width=540,height=421,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}

function open720583 (url) {
// Verwendet bei: Productspecials (GW)
 params = "width=720,height=539,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}

function open468500 (url) {
// Verwendet bei: HĂ¤ndlersuche, Newsletter
 params = "width=468,height=500,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}

function open565504 (url) {
// Verwendet bei: BSS HĂ¤ndlersuche
 params = "width=565,height=504,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}


function open550310 (url) {
// Verwendet bei: Messekalender (GW)
 params = "width=550,height=310,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}

function open400550 (url) {
// Verwendet bei: Bildschirmhintergruende
 params = "width=400,height=550,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}

function open344305 (url) {
// Verwendet bei: news008.htm (GW)
 params = "width=344,height=305,resizable=0,status=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0";
 var newwin = window.open(url, "special", params);
 if (newwin) return false;
}






    function displayDate() {

     theDate = new Date();
      var year = theDate.getYear();
      var month = (theDate.getMonth())+1;
      var day = theDate.getDate();
      if (year < 1000) year+=1900;
      if (day  < 10) day="0"+day;
      if (month < 10) month="0"+month;

     var myDate = "day/month/year";

     myDate = myDate.replace(/day/,day);
     myDate = myDate.replace(/month/,month);
     myDate = myDate.replace(/year/,year);
     if(document.getElementById){
      if(document.getElementById("hsDate")){
        document.getElementById("hsDate").innerHTML=myDate;
       }
      }
    }


/* Â¶ */

    function openWebassistant(q){
     // var path="http://www.bosch.cz/content/service/wa/index.asp";
     var path="http://search.ceskyweb.com/search.cgi";
/*
     if (typeof(q) != "string") q = "";
     if(path.indexOf("?") < 0){
      path+="?lang=cs";

     }else{
      if(path.indexOf("lang=") < 0){
       path+="&lang=cs";
      }
     }

     path+="&query="+q;
*/

     window.open(path,"wa","width=584,height=508,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,resizable=no");
    }
    function openContactEmail(e){
     openContact("","","","",e);
    }


function openContact(igb,ioption1,ioption2,ioption3,iemail){
     if (((typeof(iemail)== "undefined")||iemail=="")&&((typeof(email)== "undefined")||email=="")){
      iemail="";
      igb=((typeof(igb)== "undefined") || (igb == ""))?(typeof(gb)=="undefined")?(typeof(business_division)=="undefined")?"":business_division:gb:igb;
      ioption1=((typeof(ioption1)== "undefined") || (ioption1 == ""))?(typeof(option1)=="undefined")?(typeof(sub_division1)=="undefined")?"":sub_division1:option1:ioption1;
      ioption2=((typeof(ioption1)== "undefined") || (ioption2 == ""))?(typeof(option2)=="undefined")?(typeof(sub_division2)=="undefined")?"":sub_division2:option1:ioption1;
      ioption3=((typeof(ioption1)== "undefined") || (ioption3 == ""))?(typeof(option3)=="undefined")?(typeof(sub_division3)=="undefined")?"":sub_division3:option1:ioption1;

     }else{
      igb="";ioption1="";ioption2="";ioption3="";
      if((typeof(iemail)== "undefined")||iemail==""){iemail=email;email="";}
     }


     myurl = "http://servicefunctions.bosch.com/user/contactdealer/index.asp?country=cz&lang=cs&app=contact";
     if ((typeof(myurl) != "undefined") && (myurl != "")) {
      window.open(myurl, "contact", "width=564,height=508,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,resizable=no");
     }
    }



    function openSource(obj){
     var path = obj.href;
     window.open(path, "sitobchodniku", "width=564,height=508,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,resizable=no");
    }

    function openCountryLocator(){
     var path="";
     if(path.indexOf("?") < 0){
      path+="?lang=cs";
     }else{
      if(path.indexOf("lang=") < 0){
       path+="&lang=cs";
      }
     }
     window.open(path,"cl","");
    }
    function openMyBosch(){
     var path="http://www.bosch.cz/content/service/mb/index.asp";
     if(path.indexOf("?") < 0){
      path+="?lang=cs";
     }else{
      if(path.indexOf("lang=") < 0){
       path+="&lang=cs";
      }
     }
     window.open(path,"mybosch","");
    }
    function openImpressum(){
     var path="http://www.bosch.cz/content/language1/html/1062.htm";
     if(path.indexOf("?") < 0){

       path+="?lang=cs";

     }else{
      if(path.indexOf("lang=") < 0){
       path+="&lang=cs";
      }
     }
     window.open(path,"imprint","width=460,height=418,toolbar=no,location=no,directories=no,scrollbars=auto,status=no,menubar=no,resizable=no");
    }


