// browser type

function getBrowserType() {
   // returns browserType:
   // N3 = Nescape Navigator >3
   // M4 = Mircosoft IExplorer >4
   // NN = browser unknown

   var browserVer=parseInt(navigator.appVersion);
   var browserType=navigator.appName;
   var browser = "NN";

   if (browserType == "Netscape" && browserVer >= 3) browser = "N3";
   if ((browserType.indexOf("Microsoft") != -1) && browserVer >= 4 ) browser = "M4";
   return browser;

}


function isMacIe() {
   // returns browserType:
   // N3 = Nescape Navigator >3
   // M4 = Mircosoft IExplorer >4
   // NN = browser unknown


   var is = false;

   if (navigator.userAgent.indexOf("Mac") != -1) {
      if (navigator.appName.indexOf("Microsoft") != -1) {

         is = true;
      }
   }
   return is;
}


// nav functions ////////////////////////////////////////////////////////

function selectboxNavigation(selectboxId, page)   {

    var selectbox = document.getElementById(selectboxId);
    var id = selectbox.options[selectbox.selectedIndex].value; 
    
    if (id != 0) {
      window.location = "index.php?p=" + page + "&" + selectbox.name + "=" +  id;
    }

}




// popup functions ////////////////////////////////////////////////////////

function popupDisplay3D(location, width, height) {

   return popupSizedCentered(location, width, height);

}


function popupSizedCentered(location, width, height) {


   LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-height)/2 : 0;

   if(window.screenLeft) {

      LeftPosition  = LeftPosition + window.screenLeft

   }

   ref = window.open(location, 'stefanmaycom', "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width="+width+",height="+height+",top="+TopPosition+",left="+LeftPosition);

   ref.focus();
   return ref;

}




function changePopup(location, width, height) {

   LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-height)/2 : 0;


   window.width = width;
   window.height = height;
   window.location = location;

   /*
   ref.focus();
   return ref;
   */

}



// layer functions ////////////////////////////////////////////////////////

// init visibility
var vista = new Array();


function toggleDisplay(id) {

   vista[id] = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
   document.getElementById(id).style.display = vista[id];

}

function toggleInversDisplay(id) {
   vista[id] = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
   document.getElementById(id).style.display = vista[id];

}


function toggleVisibility(id) {

   vista[id] = (document.getElementById(id).style.visibility == 'hidden') ? 'visible' : 'hidden';
   document.getElementById(id).style.visibility = vista[id];



}

function toggleInversVisibility(id) {
   if(document.getElementById(id)) {
      vista[id] = (document.getElementById(id).style.visibility == 'visible' || document.getElementById(id).style.visibility == 'inherit' ) ?  'hidden' : 'visible';
      document.getElementById(id).style.visibility = vista[id];
   }

}



var markedElems = Array();

function markOrder(id, event) {
   name = "row"+id
   arrElems = document.getElementsByName(name);

   bgcolors = Array();
   bgcolors['over']    = '#1F1F1F';
   bgcolors['out']     = '#0F0F0F';
   bgcolors['click']   = '#1F1F1F';

   colors = Array();
   colors['over']    = '#CCCCCC';
   colors['out']     = '#8A8A8A';
   colors['click']   = '#CCCCCC';




   if(event == 'click') {

      //alert(id);
      if(markedElems[id] == true) {
         //alert("unmark");
         markedElems[id] = false;
      } else {
         //alert("mark");
         markedElems[id] = true;
      }
   } else {

      highlightButton('ordericon'+id, event);

   }


   for(i=0; i<arrElems.length; i++) {
      elem = arrElems[i];

      if(markedElems[id] == true) {
         elem.style.backgroundColor = bgcolors['click'];
         elem.style.color = colors[event];

      } else {

         elem.style.backgroundColor = bgcolors[event];
         elem.style.color = colors[event];

      }

   }



}





function loadOpenerPage(page, id) {

   window.opener.location = "index.php?p=" + page + "&id=" + id;

}

function loadOpenerPageUri(uri) {

   window.opener.location = uri;
   window.close();

}


function loadPageUri(uri) {

   window.location = uri;

}


function reloadOpenerPage() {

   window.opener.location = window.opener.location;

}



// cartbar //////////////////////////////////////////////////////////////

function cartbar() {
   toggleDisplay("cartLayer");

   if(vista["cartLayer"] == 'block') {
      document.getElementById('cartButton').src = 'images/listdetail_open_hi.gif';
      document.getElementById('orderButton1').style.visibility = 'hidden';
      vista["cartLayer"] = 'block';
   } else {
      document.getElementById('cartButton').src = 'images/listdetail_closed_hi.gif';
      document.getElementById('orderButton1').style.visibility = 'visible';
      vista["cartLayer"] = 'none';
   }

   setCookie('smCartLayer', vista["cartLayer"]);

}

function cartbarInit() {

   vista["cartLayer"] = getCookie('smCartLayer');

   
   
   document.getElementById('cartLayer').style.display = vista["cartLayer"];

   if(vista["cartLayer"] == 'block') {
      document.getElementById('cartButton').src = 'images/listdetail_open_norm.gif';
      document.getElementById('orderButton1').style.visibility = 'hidden';
      vista["cartLayer"] = 'block';
   } else {
      document.getElementById('cartButton').src = 'images/listdetail_closed_norm.gif';
      vista["cartLayer"] = 'none';
   }


}



// order /////////////////////////////////////////////////////

function recaluclateCart() {

   //document.getElementById('acceptGtc').style.display = 'none';
   document.getElementById('cartAction').value = 'calculate';
   //document.getElementById('orderformButton').src = './images/en/button_calculate.gif';
   document.getElementById('cartForm').submit();

}






// form functions ///////////////////////////////////////////////

function selectRadio(elemId, index) {

   document.getElementsByName(elemId)[index].checked = true;


}

function selectCheckbox(elemId) {

   elem = document.getElementById(elemId);
   if(elem.checked == true) {
      elem.checked = false;
   }else {
      elem.checked = true;

   }

}




function highlightButton(id, event) {

   src = document.getElementById(id).src;

   basename = src.substring(0,src.lastIndexOf('_'));

   //basename = src.substring(src.lastIndexOf('/'));

   if(event == 'over') {
      document.getElementById(id).src = basename + '_hi.gif';
      //alert(document.getElementById(id).src);
   }

   if(event == 'out') {
      document.getElementById(id).src = basename + '_norm.gif';
   }

}


function highlightButtonName(name, event) {

   elems = document.getElementsByName(name);

   for(i=0; i < elems.length; i++) {
      elem = elems[i];
      src = elem.src;

      basename = src.substring(0,src.lastIndexOf('_'));

      //basename = src.substring(src.lastIndexOf('/'));

      if(event == 'over') {
         elem.src = basename + '_hi.gif';
         //alert(document.getElementById(id).src);
      }

      if(event == 'out') {
         elem.src = basename + '_norm.gif';
      }

   }

}

function highlightLink(id, event) {

   elem = document.getElementById(id);

   if(event == 'over') {
      elem.style.textDecoration = 'underline';
   }

   if(event == 'out') {
      elem.style.textDecoration = '';
   }

}

var oldColor = '';
function highlightLinkColor(id, event) {

   elem = document.getElementById(id);

   if(event == 'over') {
      oldColor = elem.style.color;
      elem.style.color = '#222222';
      elem.style.textDecoration = 'underline';
   }

   if(event == 'out') {
      elem.style.color = oldColor;
      elem.style.textDecoration = '';
   }

}

function highlightNewsLink(id, event) {

   elem = document.getElementById(id);

   if(event == 'over') {
      oldColor = elem.style.color;
      elem.style.color = '#009BA2';
      elem.style.textDecoration = 'underline';
   }

   if(event == 'out') {
      elem.style.color = oldColor;
      elem.style.textDecoration = '';
   }

}




function highlightImage(id, event) {

   src = document.getElementById(id).src;

   basename = src.substring(0,src.lastIndexOf('_'));

   //basename = src.substring(src.lastIndexOf('/'));

   if(event == 'over') {
      document.getElementById(id).src = basename + '_hi.jpg';
     //alert(document.getElementById(id).src);
   }

   if(event == 'out') {
      document.getElementById(id).src = basename + '_norm.jpg';
   }

}


// selectnav ///////////////////////////////////////////////


function selectnav(pagenum) {

   if(selectnavCurrent >0 ) {
      document.getElementById('selectnav'+selectnavCurrent).style.visibility = 'hidden';

   }

   selectnavCurrent = pagenum;
   document.getElementById('selectnav'+pagenum).style.visibility = 'visible';

}

// referenz teaser

function nextTeaser() {

   if(curteaser >= refteaserImg.length - 1) {
      curteaser = 1;
   } else {
      curteaser++;
   }
   
   showTeaser();
   
}

function prevTeaser() {
   if(curteaser > 1) {
      curteaser--;
   } else {
      curteaser = refteaserImg.length -1;
   }
   showTeaser();
}


function showTeaser() {
   document.getElementById('referenzteaser').src = refteaserImg[curteaser];
   document.getElementById('refteaserLink').href = 'index.php?p=referenzen&id=' + curteaser;
   document.getElementById('refteaserLink').firstChild.nodeValue =  refteaserLabel[curteaser];
}
