/**
 * oft genutzte Objekte in DHTML:
 *  Coord
 *  Canvas
 * oft genutzt Funktionen in DHTML
 *  @return LayerReference getLayerRef(String ID)
 *  @return void setPosition(LayerReference objLayer, Coord coords)  
 *  @return void setVisibility(LayerReference objLayer, boolean visible)
 *  @return Coord getMouseXY(evt)
 *  @return void setVisibility4DivByPrefix(prefix, visible)
 */

// Objekte
function Coord(x, y){
  this.x = (!x)?0:x;
  this.y = (!y)?0:y;
  
  this.toString = objToString;
  this.equals = equalsCoord;
}

function Canvas(x, y, width, height){
  this.width = (!width)?0:width;
  this.height = (!height)?0:height;
  
  this.Coord = Coord;
  this.Coord(x, y);
  
  this.equalsCoord = this.equals;
  this.equals = equalsCanvas;
}

function objToString(){
  var ret = "{";
  for(p in this ){
    if (typeof this[p] == "function" || typeof this[p] == "object") continue;
    if(ret.length > 1)
      ret += ",";
    ret += p + ":" + this[p];
  }
  return ret + "}";
}

function equalsCoord(/*Coord*/ c){
  return (this.x == c.x && this.y == c.y);
}
function equalsCanvas(/*Canvas*/ c){
  return ( this.equalsCoord == c.equalsCoord && this.width == c.width && this.height == c.height);
}

// Funktionen

function getLayerRef (id, document) {
  if (!document)
    document = window.document;
  if (document.layers) {
    for (var l = 0; l < document.layers.length; l++)
      if (document.layers[l].id == id)
        return document.layers[l];
    for (var l = 0; l < document.layers.length; l++) {
      var result = getLayerRef(id, document.layers[l].document);
      if (result)
        return result;
    }
    return null;
  }
  else if (document.all) {
    return document.all[id];
  }
  else if (document.getElementById) {
    return document.getElementById(id);
  }
}

function setPosition(objLayer, coords){

    if (document.layers) {
      objLayer.top = coords.y;
      objLayer.left = coords.x;
    } else if (window.opera) {
      objLayer.style.top = coords.y;
      objLayer.style.left = coords.x;
    } else if (document.all) {
      objLayer.style.top = coords.y;
      objLayer.style.pixelLeft = coords.x;
    } else if (document.getElementById) {
      objLayer.style.top = coords.y + 'px'; 
      objLayer.style.left = coords.x + 'px';
    }
}

function setVisibility(objLayer, visible) {
  if(document.layers){
    objLayer.visibility  = 
        (visible == true) ? 'show' : 'hide';
  } else {
    objLayer.style.visibility = 
        (visible == true) ? 'visible' : 'hidden';
  }

}

function setVisibility4DivByPrefix(prefix, visible, d){
  if (!d)
    d = window.document;

  if(document.layers){
    for (var l = 0; l < d.layers.length; l++){
      if(d.layers[l].id.substr(0, prefix.length ) == prefix)
        setVisibility(d.layers[l], visible);
      setVisibility4DivByPrefix(prefix, 
                                visible, 
                                d.layers[l].document);
    }

  } else if(document.all) {

    var layers = document.all.tags("div"); 
    for(i=0; i < layers.length; i++) { 
      if(layers[i].id.substr(0, prefix.length ) == prefix )
        setVisibility(document.all.tags("div")[i], visible);
    }

  } else if(document.getElementsByTagName) {

    var layers = document.getElementsByTagName("div");
    for(i=0; i < layers.length; i++){
      if(layers[i].id.substr(0, prefix.length ) == prefix)
        setVisibility(layers[i], visible);
    }

  }
}

function getMouseXY(evt) {
  e = evt || window.event;
  if(!e) return null;
  
  if(document.layers) {
    return new Coord(e.pageX, e.pageY);
  }else if(window.opera){
    return new Coord(e.clientX, e.clientY);
  }else if(document.all ) {
    return new Coord(e.clientX + document.body.scrollLeft, e.clientY + document.body.scrollTop);
  }else if(document.getElementById) {
    return new Coord(e.pageX , e.pageY );
  }
}

function setVisibility( /* Layer */ objLayer, 
                        /* boolean */ visible ) {

  if(document.layers){
  	 objLayer.visibility  = 
        (visible == true) ? 'show' : 'hide';
        
  } else {
    objLayer.style.visibility = 
        (visible == true) ? 'visible' : 'hidden';
        
  }
  
}

function ptp (){
setVisibility(getLayerRef('ptp'), true); return false;
}
function allproducts (){
setVisibility(getLayerRef('allproducts'), true); return false;
}
function searchsuggest (){
setVisibility(getLayerRef('searchsuggestcontent'), true); return false;
}
function savecartastemplate (){
setVisibility(getLayerRef('savecartastemplate'), true); return false;
}
function sendcartasemail (){
setVisibility(getLayerRef('sendcartasemail'), true); return false;
}
function alternatives (){
setVisibility(getLayerRef('alternatives'), true); return false;
}
function accessories (){
setVisibility(getLayerRef('accessories'), true); return false;
}

function labelChem (){
setVisibility(getLayerRef('labelChem'), true); return false;
}
function labelBio (){
setVisibility(getLayerRef('labelBio'), true); return false;
}



function altacc (){
setVisibility(getLayerRef('altacc'), true); return false;
}

function umfrage_layer (){
setVisibility(getLayerRef('umfrage_layer'), true); return false;
}

/** 
 * getStreamingObject(); 
 * liefert ein Flash HTML Object zurück 
 */ 

function getStreamingObject(file,width,height,autoplay) {
    return
        '<object type="application/x-shockwave-flash"' +
        ' data="/is-bin/intershop.static/WFS/Merck-International-Site/-/en_US/flash/dcdflvplayer.swf"' +
        ' id="flvplayer" width="' + width + '" height="' + height + '">' +
        '<param name="movie"' +
        ' value="/is-bin/intershop.static/WFS/Merck-International-Site/-/en_US/flash/dcdflvplayer.swf" />' +
        '<param name="allowFullScreen" value="true" />' +
        '<param name="FlashVars" value="width=' + width + '&amp;height=' + height + '&amp;autoplay=' + autoplay +
        '&amp;autoload=1&amp;volume=100&amp;titlesize=12&amp;playercolor=ebeef3&amp;loadingcolor=003399' +
        '&amp;bgcolor=FFFFFF&amp;bgcolor1=93a6c1&amp;bgcolor2=ebeef3&amp;buttoncolor=003399' +
        '&amp;buttonovercolor=cc0033&amp;slidercolor1=003399&amp;slidercolor2=003399&amp;sliderovercolor=cc0033' +
        '&amp;videobgcolor=000000&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showplayer=1&amp;showloading=1' +
        '&amp;showfullscreen=1&amp;showmouse=autohide&amp;loadonstop=1&amp;ondoubleclick=fullscreen&amp;shortcut=1' +
        '&amp;playeralpha=0&amp;flv=' + file +'" />' +
        '</object>';
}
