var bilder = new Array(
     "/_techcenter_images/marker/pfeilright-sm.gif"
   , "/_techcenter_images/marker/pfeilright-over-sm.gif"
   ,  "/_techcenter_images/marker/pfeiltop-sm.gif"
   , "/_techcenter_images/marker/pfeiltop-over-sm.gif"
   , "/_techcenter_images/marker/pfeildown-sm.gif"
   , "/_techcenter_images/marker/pfeildown-over-sm.gif"
);
var images = new Array(6);
for(var i = 0; i < 6; i++) {
   images[i] = new Image();
   images[i].src = bilder[i];
}

var bilderTD = new Array(
     "/_techcenter_images/marker/pfeiltop-sm.gif"
   , "/_techcenter_images/marker/pfeiltop-over-sm.gif"
   , "/_techcenter_images/marker/pfeildown-sm.gif"
   , "/_techcenter_images/marker/pfeildown-over-sm.gif"
);
var imagesTD = new Array(4);
for(var j = 0; j < 4; j++) {
   imagesTD[j] = new Image();
   imagesTD[j].src = bilderTD[j];
}

//fuer popupImage
var popImg = new Array(
      "/_techcenter_images/icon_graphic.gif"
    , "/_techcenter_images/icon_graphic_hi.gif"
    , "/_techcenter_images/icon_table.gif"
    , "/_techcenter_images/icon_table_hi.gif"
    , "/_techcenter_images/icon_image.gif"
    , "/_techcenter_images/icon_image_hi.gif"
);
var popImages = new Array(6);
for(var i = 0; i < 6; i++) {
   popImages[i] = new Image();
   popImages[i].src = popImg[i];
}
//popupImage-Highlight
function highPopup(imgName, imgAction) {
   document[imgName].src=popImages[imgAction].src;
}

//fuer neues techcenter:
function chLinkImg(bildname, bld) {
   document[bildname].src=images[bld].src;
}

//aus altem übernommen (bitte nach oben, wenn genutzt
function changeImage(bereich, index, bld) {
   var bild = "bild"+index;
   if (bereich==1) { bild ="mainbild"+index;}
   document[bild].src=images[bld].src;
}

function changeImageTop(bereich, index, bld) {
   var bild = "bild"+index;
   if (bereich==1) { bild ="mainbild"+index;}
   document[bild].src=imagesTD[bld].src;
}

function schliessen() {
  window.close();
}

function hilfe (text) {
 alert (text);
}


function goExt(URL) {
  xsize = 750; //hier die Breite des neuen Fensters
  ysize = 450; //hier die Hoehe des neuen Fensters

  if (browser=="NS"){
            second = window.open(URL, "Zweitfenster");
            second.resizeTo(xsize,ysize);
  }
  else {
            window.open(URL, "Zweitfenster");
  }
}

// fuer BC-Navigation
function openNewWindow(URL, windowName, option) {
   var optionStr;
   if (option==1) { optionStr = "scrollbars=yes,status=yes,resizable=yes,menubar=yes,location=no,toolbar=no"; }
   if (option==2) { optionStr = "scrollbars=yes,status=yes,resizable=yes,menubar=yes,location=yes,toolbar=yes"; }
   var windowWidth = getWindowWidth()-20;
   var windowHeight = getWindowHeight()-20;
   optionStr = optionStr + ",width=" +windowWidth+ ",height=" +windowHeight;
   window.open(URL, windowName, optionStr);
 }


function verpackungInfo(URL) {
  var ergDur = URL.search(/(Durethan.+)(B)/);
  var ergNov = URL.search(/Novodur.+/);
  var ergBak = URL.search(/BAK/);
  var ergTri = URL.search(/Triax/);
  var ergFol = URL.search(/Makrofol.+/);
  var s;

  if (ergDur != -1)
  {
  s = "http://194.45.69.14/html/auswahl.cfm?sprache=german&Region=Europa&produkt=Durethan+B";
  window.open(s,"NeuesFenster");
  }
  else {
    if (ergNov != -1)
    {
     s = "http://194.45.69.14/html/auswahl.cfm?sprache=german&Region=Europa&produkt=Novodur";
     window.open(s,"NeuesFenster");
    }
    else {
    if ((ergBak != -1) || (ergTri != -1) || (ergFol != -1))
    {
     alert("Für dieses Produkt liegen z.Zt. keine Verpackungsinformationen vor.");
    }
     else
     {
      s = "http://194.45.69.14/html/auswahl.cfm?sprache=german&Region=Europa&produkt="+URL;
      window.open(s,"NeuesFenster");
     } }
  }
}

function openRegionSelection(url) {
    fenster = window.open(url,'region_window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=210,height=280');
    fenster.focus();
}

function openLanguageSelection(url) {
    fenster = window.open(url,'language_window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=480,height=200');
    fenster.focus();
}

function openLanguageSelectionLup(url) {
    fenster = window.open(url,'language_window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=570,height=200');
    fenster.focus();
}

function openTerms(url) {
    fenster = window.open(url,'Terms_of_use','toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=790,height=550');
    fenster.focus();
}

function goSearch(product,property) {
    alert(product + " - " + property);
    return false;
}

function changeRegion(ind) {
    top.location.href = ind;
}

function searchSimilarCases2(region,lang) {
  var uri=window.location.pathname;
  var nothingChecked = true;

  for (i=0; i < document.simCases2.selSimilar.length; i++)
    if(document.simCases2.selSimilar[i].checked == true){
      nothingChecked=false;
      break;
    }
  if (nothingChecked)
    for (i=0; i < document.simCases2.selSimilar.length; i++)
      document.simCases2.selSimilar[i].checked = true;

  ind = uri.lastIndexOf("/")-5;
  uri2= uri.substring(20);
  uri2= uri2.substring(0,uri2.indexOf("/"));
  uri = uri.substring(ind);
  document.forms.simCases2.action='/' + region + '/' + lang + '/applications/' + uri2 + '/similar.jsp';
  document.forms.simCases2.uri.value=uri;
  document.forms.simCases2.submit();
}

function MM2_showHideLayers() { //v2.0
  var i, visStr, args, theObj;
  args = MM2_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
        visStr   = args[i+2];
        if (navigator.appName == 'Netscape' && document.layers != null) {
          theObj = eval(args[i]);
          if (theObj) theObj.visibility = visStr;
        } else if (document.all != null) { //IE
          if (visStr == 'show') visStr = 'visible'; //convert vals
          if (visStr == 'hide') visStr = 'hidden';
          theObj = eval(args[i+1]);
          if (theObj) theObj.style.visibility = visStr;
        }
  }
}


function doFolienInfo(type) {
    url = "folieninfo.jsp?type=" + type;
    folWin = window.open(url,'folien_info','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=500,height=320');
    folWin.focus();
}

function openMail(lang) {
  uri = "/AG/" + lang + "/contact/enquiry/index.jsp";
  top.opener.location.href=uri;
  top.opener.focus();
}

function checkSearch() {
  if(doucment.fullFAQ.searchStr.value=="") {
    alert("Please insert a search string.");
    return false;
  }
  return true;
}

 function openDocument(docId, jnlp) {
  // first check whether java is enabled at all");
  if (!navigator.javaEnabled()) {
     alert('Java is not enabled.');
   }
  // now check whether our applet it up and running
   try {
     document.opencms.getAppletInfo();
   } catch (e) {
      alert('Could not communicate with the applet. Perhaps you do do not have the SUN VM installed?'+e);
   }
   // finally call the method to open the document                
    document.opencms.openDocument(docId,jnlp);
  }

function openMinicase(url) {
    win=window.open(url, 'Minicase', 'width=640,height=550,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    win.focus();
}

function openWin(URL,titel,opt) {
    win=window.open(URL,titel,opt);
    win.focus();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image(); d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array(); for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openDiagram(filename) {
    var queryString = window.location.search;
    if (queryString.indexOf("pid=")==-1) { return; }
    var pid = queryString.substring(queryString.indexOf("pid=")+4, queryString.length);
    if (pid.indexOf("&")!=-1) { pid = pid.substring(0, pid.indexOf("&")); }
    var url = "../PR"+pid+"/"+filename + "?main=true";
    win=window.open(url, 'Diagramm', 'width=650,height=500,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    win.focus();
}

// --------------------------------------------------------------------------

var isStupidBrowserV = isStupidBrowser();

function changeArrow(ref, highlight) {
  if (highlight==0) {
    changeImageSrc(ref, 'arrow', '/_techcenter_images/marker/pfeilright-sm.gif');
  } else {
    changeImageSrc(ref, 'arrow', '/_techcenter_images/marker/pfeilright-over-sm.gif');
  }
}


function changeImageSrc(ref, imageName, newSrc) {
  if (isStupidBrowserV) { return; }
  if (!ref.hasChildNodes()) { return; }
  var children = ref.childNodes;
  for (var i=0; i<children.length; i++) {
    // for every child element of "ref"
    if ((children[i].nodeType==1) && (children[i].nodeName == "IMG")) {
       // the child-element is a IMG-Tag
       if (children[i].getAttribute("name") == imageName) { children[i].setAttribute("src", newSrc); }
    }
  }
}

function isStupidBrowser() {
  var agent = navigator.userAgent.toLowerCase();
  var version;
  //Internet Explorer
  if (agent.indexOf('msie')!=-1) {
     version = agent.substr(agent.indexOf("msie ") + 5, 3);
     if (version>=4) { return false; }
  }
  // Netscape
  if (agent.indexOf('mozilla')!=-1) {
      version = parseFloat(navigator.appVersion);
      if (version>=5) { return false; }
  }
  return true;
}

// -------------------------------------------------------------------------------
// neue Funktionen fuer Techcenter

function popupWindow(uri) {
    win=window.open(uri, 'TechCenter', 'width=650,height=500,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    win.focus();
}

function selectBU() {
    if(document.forms['form_crossbu'].elements['select_crossbu'].options[document.forms['form_crossbu'].elements['select_crossbu'].options.selectedIndex].value != 0 &&
       document.forms['form_crossbu'].elements['select_crossbu'].options[document.forms['form_crossbu'].elements['select_crossbu'].options.selectedIndex].value != 1 &&
       document.forms['form_crossbu'].elements['select_crossbu'].options[document.forms['form_crossbu'].elements['select_crossbu'].options.selectedIndex].value != 2)
       {
         top.location.href=document.forms['form_crossbu'].elements['select_crossbu'].options[document.forms['form_crossbu'].elements['select_crossbu'].options.selectedIndex].value;
       }
}
function selectProduct() {
    var form = document.forms['form_crossproduct'];
    var selectedIndex = form.elements['select_crossproduct'].options.selectedIndex;
    var value = form.elements['select_crossproduct'].options[selectedIndex].value;
    if(value != "") {
      top.location.href = value;
    }
}
function selectRegion() {
       top.location.href=document.forms['form_crossregion'].elements['select_crossregion'].options[document.forms['form_crossregion'].elements['select_crossregion'].options.selectedIndex].value;
}
function selectLinks() {
     if(document.forms['form_crosslink'].elements['select_crosslink'].options[document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex].value != "0")
     {
       if(document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex==1 ||document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex==2
          ||document.forms['form_crosslink'].elements['select_crosslink'].options[document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex].value == 'http://us.lanxess.com/'
          ||document.forms['form_crosslink'].elements['select_crosslink'].options[document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex].value == 'http://www.bayermaterialsciencenafta.com/'
          )
       {
         window.open(document.forms['form_crosslink'].elements['select_crosslink'].options[document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex].value, '_blank');
       }
       else
       {
         top.location.href=document.forms['form_crosslink'].elements['select_crosslink'].options[document.forms['form_crosslink'].elements['select_crosslink'].options.selectedIndex].value;
       }
     }
}

