layerHandler = {
  getRefs: function (id) {
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
    if (el) el.css = el.style? el.style: el;
    return el;
  },
  
  writeLayer: function (el, cntnt) {
    if (typeof el.innerHTML!="undefined") {
        el.innerHTML = cntnt;
    } else if (document.layers) {
  			el.document.write(cntnt);
  			el.document.close();
    }
  },
  
  shiftTo: function (el,x,y) {
    var px = (document.layers || window.opera)? 0: "px";
    if (x != null) el.css.left = x + px;
    if (y != null) el.css.top = y + px;
  },

  show: function (el) { el.css.visibility = "visible"; },
  hide: function (el) { el.css.visibility = "hidden"; }
}

var imageHandler = {
  imgs: [], path: "",
  preload: function() {
    for (var i=0; arguments[i]; i++) {
      var img = new Image(); img.src = this.path + arguments[i];
      this.imgs[this.imgs.length] = img;
    }
  }
}

// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// returns amount of horizontal scroll
function getScrollX() {
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		sx = document.body.scrollLeft; 
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}

function popup(url, width, height, name, options) {
	width = width ? width : 550;
	height = height ? height : 600;
	name = name ? name : '_blank';
	win = window.open(url, name, 'width='+width+',height='+height+
		',menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0');

	x = screen.width / 2 - width / 2;
	y = screen.height / 2 - height / 2;
	win.moveTo(x, y);
	return false;
}

function toggle(id) {
  var elem = document.getElementById(id);
  if (elem.style.display == 'none') {
    elem.style.display = 'block';
  } else {
    elem.style.display = 'none';
  }
}


/*
This code is from Dynamic Web Coding 
at http://www.dyn-web.com/
Copyright 2002-3 by Sharon Paine 
See Terms of Use at http://www.dyn-web.com/bus/terms.html
Permission granted to use this code 
as long as this entire notice is included.
*/

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var page_loaded; // set true
function doWriteFlex(id, sHTML, x, y) {
  if (!page_loaded) return;
  var el = layerHandler.getRefs(id);
  if (!el) return;
  layerHandler.hide(el); // just in case ...
  var cntnt = '<div class="info">' + sHTML + '</div>';
  layerHandler.shiftTo(el, x, y);
  layerHandler.writeLayer(el, cntnt);
  layerHandler.show(el);
}

function hideFlex(id) {
  if (!page_loaded) return;
  var el = layerHandler.getRefs(id);
  if (!el) return;
  layerHandler.hide(el);
}

/*
funktion eingefügt von rb 18.06.09
*/
function sprachwechsel() {
  var sprachwechsel_wert = document.sprachwahl.sprache.value;
  var sprachwechsel_index = document.sprachwahl.sprache.selectedIndex;
  var sprachwechsel_wahl = document.sprachwahl.sprache.options[sprachwechsel_index].text;
  window.location.href = sprachwechsel_wert;
}

function refresh_summary(field) {
  if (field && field.name == 'waehrung') {
    $('order-form').submit();
  } else {
    new Ajax.Request(location.href, {
        parameters: Form.serialize('order-form')+'&refresh_summary=1',
        onSuccess: function(req) {
          $('order-summary').replace(req.responseText);
        }
    });
  }
}

function refresh_domain() {
  $('domain-form').hide();
  $('domain-form-loading').show();

  new Ajax.Request(location.href, {
    parameters: Form.serialize('order-form')+'&refresh_domain=1',
    onSuccess: function(req) {
      $('domain-form').replace(req.responseText);
      refresh_summary();
    },
    onComplete: function(req) {
      $('domain-form-loading').hide();
    }
  });
}
