/* JavaScript Library */

var ns4 = (document.layers)?1:0;
var dom = (document.getElementById && !document.all);
var ie4 = (document.all)?1:0;
var opr = navigator.userAgent.indexOf("Opera");
var moz = navigator.appName=="Netscape" && navigator.appCodeName=="Mozilla" && !document.all;
var mac = navigator.userAgent.indexOf("Mac")!= -1;

window.status = "Brenntag"; // writes Javascript default message in browser status bar

// calculate the height of a layer
function getDivsHeight() {
	var iDivsHeight = 0;
	for(var i=0; i < arguments.length; i++) {
		if (document.getElementById(arguments[i]))
			iDivsHeight += document.getElementById(arguments[i]).offsetHeight;
	}
	return iDivsHeight;
}

//find the position of a layer in page
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// set the height of the back main layer in order to move the footer
function setDivContentMinHeight() {
	var oDivcontent, oStopperDiv, iWinInnerHeight, tmpHeight, newHeight, stopperTop;
	var mozCorrection = moz ? -1 : 0;
	oDivcontent = document.getElementById(arguments[0]); //assumes first passed object as name for the content area layer
	oStopperDiv = document.getElementById(arguments[1]); // retrieve stopper div object

	if (self.innerHeight) {
		// all except Explorer
		iWinInnerHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		iWinInnerHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		// other Explorers
		iWinInnerHeight = document.body.clientHeight;
	}

	if (arguments.length == 4) {
		tmpHeight = getDivsHeight(arguments[2], arguments[3]);
	} else if (arguments.length == 3) {
		tmpHeight = getDivsHeight(arguments[2]);
	} // calculate the height of the page elements except the content area; using the getDivsHeight function

	if (oStopperDiv) {
		stopperTop = findPosY(oStopperDiv) - getDivsHeight(arguments[2])
		if (iWinInnerHeight > (tmpHeight + stopperTop + oStopperDiv.offsetHeight) || (document.getElementById('popup') && document.getElementById('frame'))) {
			//if there is more space on the page than the header and footer height, than the main layer is set to a new height
			newHeight = iWinInnerHeight - tmpHeight + mozCorrection;
			oDivcontent.style.height =  newHeight + "px";
			if (document.getElementById("popup")) {
				if (document.getElementById('popup').offsetHeight > iWinInnerHeight) {
					oDivcontent.style.height = newHeight - (document.getElementById('popup').offsetHeight - iWinInnerHeight) + "px";
				}
				if (document.getElementById('frame')) {
					document.body.style.overflow='hidden';
				}
			} else if (document.getElementById('page')) {
				if (document.getElementById('page').offsetHeight > iWinInnerHeight) {
					oDivcontent.style.height = newHeight - (document.getElementById("page").offsetHeight - iWinInnerHeight) + "px";
				}
			} 
		} else {
			// Festlegen der Höhe wegen Druckproblem entfernt.
			// oDivcontent.style.height = stopperTop + oStopperDiv.offsetHeight + 50 + mozCorrection + "px";
		}
	}
}

// Wrapper function to apply the changes to the footer / main layers if DOM browser detected
// loadEvent triggers a bugfix for MSIE 5.0 and footer bar placement, "true" is for function calls in onLoad events,
// "false" is default and for onResize events

function init(loadEvent) {
	if (!ns4) {
		setDivContentMinHeight('main', 'stopper', 'header', 'footer');
		footero=document.getElementById('footer');
		if (footero)
			footero.style.visibility='visible';
	}
	if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
		window.resizeBy(1,1);
		window.resizeBy(-1,-1);
	}
}

//switch to country
function gotoCountry()
{
  box = document.selectCountry.country;
  destination = box.options[box.selectedIndex].value;
  if (destination != "") window.location.href = destination;
  else alert('Out of order!');
}

//switch to together
function gotoTogether()
{
  box = window.document.brenntagTogether.togehterArchive;
  destination = box.options[box.selectedIndex].value;
  if (destination != "") window.location.href = destination;
  else alert('Out of order!');
}

//check for email-formular
function check()
{
  var status=true;
  var email=document.form1.email.value;
  kk=email.indexOf("@");
  if (kk <= 0 || email.indexOf(".", kk) < 0)
  {
    alert("Ihre E-Mail ist nicht korrekt!");
    return false;
  }
}

// open new window to selected country url
function openCountryWindow()
{
  var index, inhalt;
  index = window.document.brenntagWorld.brenntagWorldCountry.selectedIndex;
  inhalt = window.document.brenntagWorld.brenntagWorldCountry.options[index].value;
  if (inhalt == "sales_regions/index.html")
    window.location.href = "sales_regions/index.html"
  else if (inhalt != "")
    window.open(inhalt,"_blank");
}

// popup window opener service function for standard content pages
function showPopUp(zielFrame, parameter) {
  var newWindow = window.open("about:blank", zielFrame, parameter);
  newWindow.focus();    
}

//change opener location (for sitemap)
function start(url) 
{
  opener.top.location = url;
}

function checkQuicksearchInput() {
  if (document.quicksearch.q.value == "Schnellsuche" || document.quicksearch.q.value == "Quicksearch" || document.quicksearch.q.value == "Búsqueda rápida" || document.quicksearch.q.value == "Recherche rapide" || document.quicksearch.q.value == "Hurtig søgning" || document.quicksearch.q.value == "Pesquisa rápida" || document.quicksearch.q.value == "Snelzoek" || document.quicksearch.q.value == "Ricerca veloce" ) {
      document.quicksearch.q.value = "";
    }
  return true;
}