onload = function ()
{
	var links = document.getElementsByTagName('A');
	var count = links.length;
	
	for(var i = 0; i < count; i++) {
		links[i].onfocus = new Function('this.blur()');
	}
	
	new Draggable('iframewindow',{handle:'iframewindowtitle',starteffect:null,endeffect:null});
}
function changeStyle(id, newClass){
		document.getElementById(id).className = newClass;
}
function toggleLogIn()
{
	Effect.toggle('login', 'slide');
}

function toggleNewsletter()
{
	Effect.toggle('newsletter', 'slide');
}

function popup(url, width, height, name) {
	var p = window.open(url, '', "left="+(screen.availWidth-width)/2+",top="+(screen.availHeight-height)/2+",width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=yes,resizable=no");
	if (p) {
		p.outerWidth = width;
		p.outerHeight = height;
		p.focus();
	}
}

var warenkorb = false;

function toggleWarenkorb()
{
	Effect.toggle('warenkorb_vorschau', 'slide', { duration: 0.3, transition: Effect.Transitions.linear, fps: 100 });
	if(warenkorb) {
		warenkorb = false;
		$('warenkorb_oeffnen').src = '/img/teaser/warenkorb.gif';
	}
	else {
		warenkorb = true;
		$('warenkorb_oeffnen').src = '/img/teaser/warenkorb2.gif';
	}
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}




var posX, posY;
document.onmousemove = function(e) {
   try {
   	if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posX = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
		posY = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
	}
  } catch (er) {}
}

function ShowElement(id){
  document.getElementById(id).style.display = "block";
}

function PosToMouseElement(id) {
  	x 		= (posX) ? posX : 0;
	y 		= (posY) ? posY : 0;
	width 	= $(id).getWidth();
	sWidth  = document.body.clientWidth;
	if(x + width > sWidth) {
		x = x - width;
	}
    PosElement(id, x, y);
}





function HideElement(id){
   document.getElementById(id).style.display = "none";
}

function WriteToElement(id,inhalt){
  document.getElementById(id).firstChild.nodeValue=inhalt;
}

function PosElement(id, x, y) {
	if(id && x) {
		document.getElementById(id).style.left = x + 'px';;
	}
	if(id && y) {
		document.getElementById(id).style.top = y + 'px';;
	}
}

/**
* Ajax functions, requires Prototype
*/
function reportError(e) {}
function Helpbox(module, key, options)
{ 
  var url = '/micro/help_' + module + '/' + key; 
  var params = null;
  
  PosToMouseElement('helpbox');
  new Ajax.Updater( {success: 'helpbox'}, url, { method: 'get', parameters: params });
  /*new Draggable('helpbox', {} );*/
  
  $('helpbox').setStyle({
  	width:	(options.width) ? options.width : 300 + 'px'
  });
  
  
  ShowElement('helpbox');
}


function PosToMouseElement2(id) {
	width 	= $(id).getWidth();
	sWidth  = document.body.clientWidth;
	
	Position.prepare();
	
	x = (sWidth-width)/2;
	y = Position.deltaY + 100;
	
  	PosElement(id, x, y);
}


function showIFrame(url)
{
	PosToMouseElement2('iframewindow')
 
 
	 
  
	//var left = (document.body.clientWidth - parseInt($('iframewindow').getStyle('width'))) / 2;
	//var top = oSource.offsetTop;
	
	//pp: iframe nicht in der mitte anzeigen
	//var left = (document.body.clientWidth - parseInt($('iframewindow').getStyle('width'))) / 2 +100;
	
	$('iframe').src = url;
	
	$('overlay_background').setStyle({
		display: 'block'
	});
	
	$('iframewindow').setStyle({
		//left: left + 'px',
		//top: top +'px',
		display: 'block'
	});
}

function hideIFrame()
{
	
	
	
	if(hideIFrame.arguments[0] != true) {
		$('overlay_background').setStyle({
			display: 'none'
		});
	}
	
	$('iframe').setStyle({
		display: 'none'
	});
	
	$('iframewindow').setStyle({
		display: 'none'
	});
	
	$('iframemessage').setStyle({
		display: 'block'
	});
	
	
	//pp: seite neuladen wenn vertrag oder pr&auml;mie gew&auml;hlt beim schlie&szlig;ne
	var QuellText = $('iframe').src;
	var Pos1 = QuellText.indexOf('praemie_waehlen', 0);
	var Pos2 = QuellText.indexOf('vertrag_waehlen', 0);
	var Pos3 = QuellText.indexOf('praemie_zum_vertrag', 0);
	var Pos4 = QuellText.indexOf('vertrag_tauschen', 0);
	var Pos5 = QuellText.indexOf('vertrag_tauschen', 0);
	var Pos6 = QuellText.indexOf('vertragsliste', 0);
	var Pos7 = QuellText.indexOf('praemie_tauschen', 0);
	var Pos8 = QuellText.indexOf('praemienliste', 0);
	
	if(Pos1 > 0 ||Pos2 > 0||Pos3 > 0||Pos4 > 0||Pos5 > 0||Pos6 > 0||Pos7 > 0||Pos8 > 0)
	{
		window.location.reload();
	}
	
}

function onloadIFrame()
{
	if(document.getElementById('iframe')) {
		$('iframe').setStyle({
			display: 'block'
		});
		
		$('iframemessage').setStyle({
			display: 'none'
		});
		
	}
}

function setTitleIFrame(text)
{
	document.getElementById('iframetitle').innerHTML = text;
	
}

function jump(url)
{
	document.location.href = url + document.location.search;
}

function anmelden(){
	document.getElementById('iframe').style.height='170px';
	showIFrame('/home/newsletter?micro=true&action=anmelden&email='+document.getElementById('news_email').value );
	
}
function anmelden_neu(){
	location.href='/service/newsletter?email='+document.getElementById('news_email').value;
	
}
function abmelden(){
	document.getElementById('iframe').style.height='170px';
	showIFrame('/home/newsletter?micro=true&action=abmelden&email='+document.getElementById('news_email').value );
	
}

function plz(){
	document.getElementById('iframe').style.height='100px';
	showIFrame('/vertragswelten/plz?micro=true');
	
}