
// --------------------------------------------------
// Allgemeine Shop-Funktionen
// --------------------------------------------------


function wopen(link,wi,he) {

  var width = wi ;
  var height = he ;
  var l = (screen.availWidth-width)/2 ;
  var t = (screen.availHeight-height)/2 ;

    wincom = window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);

    if ( wincom ) {

      wincom.focus() ;
    }
}

function wopen2(link,wi,he) {

  var width = wi ;
  var height = he ;
  var l = (screen.availWidth-width)/2 ;
  var t = (screen.availHeight-height)/2 ;

    wincom2 = window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);

    if ( wincom2 ) {

      wincom2.focus() ;
    }
}

function tabbgcolor(tabid,col) {

  tabid.style.backgroundColor = col;
}

function fielddel(f) {
  if (f.value == f.defaultValue) {

    f.value = "" ;
  }
}


function fieldset(f) {

  if (f.value == "") {

    f.value = f.defaultValue ;
  }
}


function fieldemp(f) {

  if (f.sbeg.value == f.sbeg.defaultValue) {

    f.sbeg.value = "" ;
  }
}



// --------------------------------------------------
// DIV-Popupup-Funktionen
// --------------------------------------------------


var PopupDiv = {

  popupid: null ,

  show: function( divid , tiframe ,  url ) {

    var arrayPageSize = PopupDivGetPageSize();
    $('PopupDivBG').style.height = arrayPageSize[1] + 'px' ;
    Effect.Appear('PopupDivBG',{duration:0.3,to:0.6}) ;

    PopupDiv.popupid = divid ;
    var popup = $(PopupDiv.popupid) ;

    popup.scrollTop = 0 ;
    PopupDivCenter(popup) ;
    Element.hide(PopupDiv.popupid) ;
    Effect.Appear(PopupDiv.popupid,{duration:0.1}) ;

    if ( url ) {
      if ( tiframe ) {
        $(tiframe).src = shopimgpath + 'trenner.gif' ;
        $(tiframe).src = url ;
      } else {
        new Ajax.Updater(PopupDiv.popupid,url,{encoding:'iso-8859-1'}) ;
      }
    }

    window.onresize = PopupDivResize ;
    window.onscroll = PopupDivResize ;
  } ,

  close: function() {

    Effect.Fade(PopupDiv.popupid,{duration:0.1}) ;
    Effect.Fade('PopupDivBG',{duration:0.1}) ;
  }
}


function PopupDivCenter(popupid) {

  popupid.style.visibility = 'hidden' ;
  popupid.style.display    = 'block' ;

  var divh = PopupDivGetPageScroll() - popupid.getHeight() / 2 ;
  var divw = 0 - popupid.getWidth() / 2 ;

  popupid.style.display    = 'none';
  popupid.style.visibility = '';
  popupid.style.marginTop  = divh + 'px' ;
  popupid.style.marginLeft = divw + 'px' ;
}


function PopupDivResize() {

  var arrayPageSize = PopupDivGetPageSize();
  PopupDivResizeCenter($(PopupDiv.popupid));
  $('PopupDivBG').style.height = arrayPageSize[1] + 'px' ;
}


function PopupDivResizeCenter(popupid) {

  var divh = PopupDivGetPageScroll() - popupid.getHeight() / 2 ;
  var divw = 0 - popupid.getWidth() / 2 ;

  popupid.style.marginTop  = divh + 'px' ;
  popupid.style.marginLeft = divw + 'px'  ;
}


function PopupDivGetPageSize(){

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {	// all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}


function PopupDivGetPageScroll(){

  var yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  return yScroll ;
}

//--------------------------------------------------
//Titelzeilen der Rubrikenansicht fixen
//--------------------------------------------------
function FixRubViewContainer() {
  $('.RubViewContainer').each(function() {
    //Maximale Höhe innerhalb dieses Containers ermitteln
    var maxheight = 0;
    $(this).find('.title a').each(function() {
      var height = $(this).height();
      if(height > maxheight) { maxheight = height; }
    });

    //Größte ermittelte Höhe auf alle Kindelemente dieses Containers anwenden
    $(this).find('.title').each(function() {
      $(this).height(maxheight);
    });
  });
}

//--------------------------------------------------
//Layout bei zu großer Tabelle vergrößern
//--------------------------------------------------
function FixDetailTableWidth() {
  var maxWidth = 560;
  if($.browser.msie && parseFloat($.browser.version) < 7) { var IE6 = true; }

  // Detailseite

  var width = $('#DetailTable').width();
  if (width > maxWidth) {
    var missingWidth = width - maxWidth;
    $('.SiteContainer').width($('.SiteContainer').width() + missingWidth);
    $('.Head').width($('.Head').width() + missingWidth);
    $('.HeadNavLinks li.last').width($('.HeadNavLinks li.last').width() + missingWidth);
    if(!IE6) { $('.ContentCenter').width($('.ContentCenter').width() + missingWidth); }
    if(IE6) { $('.Breadcrum').width($('.Breadcrum').width() + missingWidth); }
    if(IE6) { $('.HeadlineBG').width($('.HeadlineBG').width() + missingWidth); }
    if(IE6) { $('.BackgroundGrauDunkel').width($('.BackgroundGrauDunkel').width() + missingWidth); }
    $('.FooterCopyright').width($('.FooterCopyright').width() + missingWidth);
  }

  // Debug
//	var SiteContainer = $(".SiteContainer").width();
//	var Head = $(".Head").width();
//	var HeadNavigation = $(".HeadNavigation").width();
//	var ContentCenter = $("#ContentCenter").width();
//	var Breadcrum = $(".Breadcrum").width();
//	var DetailText = $(".DetailText").width();
//	var Aval = $(".aval").width();
//	var DetailTable = $("#DetailTable").width();
//	var CrossTable = $("#DetailCross").width();

//	$("#Debug").show();
//	$("#Debug").append("maxWidth: " + maxWidth + "<br/>");
//	$("#Debug").append("missingWidth: " + missingWidth + "<br/>");
//	$("#Debug").append("IE6: " + IE6 + "<br/>");
//	$("#Debug").append("SiteContainer: " + SiteContainer + "<br/>");
//	$("#Debug").append("Head: " + Head + "<br/>");
//	$("#Debug").append("HeadNavigation: " + HeadNavigation + "<br/>");
//	$("#Debug").append("ContentCenter: " + ContentCenter + "<br/>");
//	$("#Debug").append("Breadcrum: " + Breadcrum + "<br/>");
//	$("#Debug").append("DetailText: " + DetailText + "<br/>");
//	$("#Debug").append("Aval: " + Aval + "<br/>");
//	$("#Debug").append("DetailTable: " + DetailTable + "<br/>");
//	$("#Debug").append("CrossTable: " + CrossTable + "<br/>");
//	$("#Debug").append("width > maxWidth: " + (width > maxWidth));
}

function FixScartTableWidth() {
  var maxWidth = 560;
  if($.browser.msie && parseFloat($.browser.version) < 7) { var IE6 = true; }

  // Warenkorb
  var scartWidth = $("#ScartTable").width();
  if (scartWidth > maxWidth) {
    var missingScartWidth = scartWidth - maxWidth;
    $('.SiteContainer').width($('.SiteContainer').width() + missingScartWidth);
    $('.Head').width($('.Head').width() + missingScartWidth);
    $('.HeadNavLinks li.last').width($('.HeadNavLinks li.last').width() + missingScartWidth);
    if(!IE6) { $('.ContentCenter').width($('.ContentCenter').width() + missingScartWidth); }
    if(IE6) { $('.Breadcrum').width($('.Breadcrum').width() + missingScartWidth); }
    $('.FooterCopyright').width($('.FooterCopyright').width() + missingScartWidth);
    /*
    $('.SiteContainer').width($('.SiteContainer').width() + missingScartWidth);
    $('.Head').width($('.Head').width() + missingScartWidth);
    if(IE6) { $('.HeadNavigation').width($('.HeadNavigation').width() + missingScartWidth - 2); }
    else { $('.HeadNavigation').width($('.HeadNavigation').width() + missingScartWidth); }
    if(!IE6) { $('#ContentCenter').width($('#ContentCenter').width() + missingScartWidth); }
    if(IE6) { $('.InfoHead').width($('.InfoHead').width() + missingScartWidth); }
    if(IE6) { $('.InfoText').width($('.InfoText').width() + missingScartWidth); }
    */
  }

  // Kostenstellen
  var ccWidth = $("#CCTable").width();
  if (ccWidth > maxWidth) {
	var missingCCWidth = ccWidth - maxWidth;
	$('.SiteContainer').width($('.SiteContainer').width() + missingCCWidth);
    $('.Head').width($('.Head').width() + missingCCWidth);
    $('.HeadNavLinks li.last').width($('.HeadNavLinks li.last').width() + missingCCWidth);
    if(!IE6) { $('.ContentCenter').width($('.ContentCenter').width() + missingCCWidth); }
    if(IE6) { $('.Breadcrum').width($('.Breadcrum').width() + missingCCWidth); }
    $('#ScartTable').width($('#ScartTable').width() + missingCCWidth);
    $('.FooterCopyright').width($('.FooterCopyright').width() + missingCCWidth);
    /*
    $('.SiteContainer').width($('.SiteContainer').width() + missingCCWidth);
    $('.Head').width($('.Head').width() + missingCCWidth);
    if(IE6) { $('.HeadNavigation').width($('.HeadNavigation').width() + missingCCWidth - 2); }
    else { $('.HeadNavigation').width($('.HeadNavigation').width() + missingCCWidth); }
    if(!IE6) { $('#ContentCenter').width($('#ContentCenter').width() + missingCCWidth); }
    if(IE6) { $('.InfoHead').width($('.InfoHead').width() + missingCCWidth); }
    if(IE6) { $('.InfoText').width($('.InfoText').width() + missingCCWidth); }
    $('#FooterCopyright').width($('#FooterCopyright').width() + missingCCWidth);
    */
  }
}

//--------------------------------------------------
//Zoomansicht
//--------------------------------------------------
function zoomBox() {
  //Iframe in Overlay-Box einfügen
  $("#DetailBox").append('<iframe src="" scrolling="no" frameborder="0"></iframe>');

  $("a[rel=#DetailBox]").click(function() {
    //URL holen
    var url = $(this).attr("href");
    url = url.replace("Javascript: wopen('", "").replace("',680,750)", "");
    $("#DetailBox iframe").attr("src", url);
  }).overlay({
    top: 'center',
    mask: {
      color: '#d8d8d8',
      opacity: 0.5
    }
  });
}

//--------------------------------------------------
//Hinweisbox
//--------------------------------------------------
function hinweisBox(textmsg){
  var textmsg = textmsg;
  if (textmsg) {
    $("#HinweisBox p").text(textmsg);
    $("#HinweisBox").overlay({
      top: 'center',
      mask: {
        color: '#d8d8d8',
        opacity: 0.5
      },
      load: true
    });
  }
}




// --------------------------------------------------
// END
// --------------------------------------------------

