//**** checks browsertype and os... returns an object
function checkBrowser(){
	this.ver = navigator.appVersion;
	this.dom = document.getElementById ? true:false;
	this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55 = (this.ver.indexOf("MSIE 5.5")>-1 && this.dom)?1:0;
	this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4 = (document.all && !this.dom) ? 1:0;
	this.ie  = (this.ie5 || this.ie4 || this.ie55 || this.ie6);
	this.ns6 = (this.dom && parseInt(this.ver) >= 5 && !this.ie6 && !this.ie5 && !this.ie55 ) ? 1:0;
	this.ns4 = (document.layers) ? 1:0;
	this.ns  = (this.ns4 || this.ns6);
	this.opera  = (this.ver.indexOf("Opera")>-1 || navigator.userAgent.indexOf("Opera")>-1) ? 1:0;
	this.os  = (this.ver.indexOf("Macintosh")>-1)? "mac":"pc";
	this.support = (this.dom);
	if(this.ie) this.browserApdx="ie";
	if(this.ns) this.browserApdx="ns";
	this.browserApdx+='_'+this.os;
        this.swf=false;
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) this.swf=true;
	if(this.ie && this.os=='pc'){
	  result = false;document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.1"))</SCRIPT>\n');
	  if (result) this.swf=true;
	}
	if(this.ie && this.os=='mac' && navigator.plugins["Shockwave-Flash"] && (parseInt(navigator.plugins["Shockwave-Flash"].description)>=5 || parseInt(navigator.plugins["Shockwave-Flash"].filename) >= 5))
	  this.swf=true;
}

function getElementsByAttributeValue(attrName,attrValue,tName,Parent,onlyOne){
	var elem=new Array();
	var d=Parent || self.document.documentElement;
	if(tName && tName!=''){
		var elems=d.getElementsByTagName(tName);
		for(var i=0;i<elems.length;i++){
			var av=getAttributeValue(elems.item(i),attrName);
 			if((attrValue==null && av!=null) || (av!=null && av==attrValue)){
				elem[elem.length]=elems.item(i);
				if(onlyOne) break;
			}
		}
	}
	return elem;
}

function getAttributeValue(node,attrName){
	if((is.ie55 || is.ie5) && !is.opera){  
		if(node.getAttribute(attrName))	return node.getAttribute(attrName);
	}else{
		if(node.getAttributeNode(attrName)) return node.getAttributeNode(attrName).value;
	}
	return null;
}

function switchStyleClass(obj,value){
	if (navigator.appName=="Netscape") 
    		obj.setAttribute("class", value);
	else 
		obj.setAttribute("className", value);
}

function isElementChildOf(cE,pE){
	var tE=cE.parentNode;
	var found=false;
	while(tE && !found){
		if(tE==pE) found=true;
		tE=tE.parentNode;
	}
	return found;
}


AddRefHandler = function(EventName,Handler,pointer,eventObj){
  eventObj[EventName] = function(Ev){
    if(is.ie) Ev=window.event;
    var res=Handler(pointer,Ev);
    return res;
  }
}
//**** Popup - Opener-function

function openWindow(src, name,x, y, width, height,x0,y0,features){
	var yOff=0,xOff=0;
	if(!is) is=new checkBrowser();
	if(!isNaN(x)) xOff=x;if(!isNaN(y)) yOff=y;
	if(x=="ScreenCentered") xOff = Math.ceil((screen.width-width)/2);
	if(y=="ScreenCentered") yOff = Math.ceil((screen.height-height)/2-20);
	if(x=="BrowserLeft"){
		if(is.ie) xOff = self.screenLeft-3; else
		if(is.ns) xOff = self.screenX+self.outerWidth-self.innerWidth-20;
	}
	if(y=="BrowserTop"){
		if(is.ie) yOff = self.screenTop; else
		if(is.ns) yOff = self.screenY+self.outerHeight-self.innerHeight-24;
	}
  xOff+=x0;yOff+=y0;if(xOff<0 )xOff=0;if(yOff<0)yOff=0;
  var stdfeatures = "scrollbars";
  if(features) stdfeatures=features; //else yOff-=20;
  var strfeatures = "left="+xOff+",top="+yOff+",width="+width+",height="+height;
  if (stdfeatures!="") strfeatures+=","+stdfeatures;
  if(popUps[name] && !popUps[name].closed) 		//already opened!
  //		if(popUps[name].location && popUps[name].location.pathname!=src)	//not the same source!
	popUps[name].close();
  self.popUps[name]=window.open(src,name,strfeatures);
  if (! self.popUps[name]) {
  	alert ("Es wurde ein Popup blockiert. Bitte beachten Sie, dass Popups f&uuml;r die Funktion dieser Seite notwendig sind.");
  } else {
  	self.popUps[name].focus();
  }
  return void(0);
}

// retrieve an Element's absolute position:
function getElemAbsPos(element){
	var l=0; var t=0;
	var ref = element;
	while(ref){
		t+=ref.offsetTop;
		l+=ref.offsetLeft;
//		dbWrite("OFFSETCALCULATION",ref.tagName,ref.name,"L:",ref.offsetLeft,"T:",ref.offsetTop,"SUM:",l,t);
		ref = ref.offsetParent;
	}
  	return [l,t];
}

function RequestParam(name){
 var Pl = self.location.search;
 var pars;
 var valu=null;
 name=UC(name);
 if(Pl.length>1){
   Pl=Pl.slice(1,Pl.length);
   pars=Pl.split("&");
   for(i=0; i<pars.length;i++){
     hs=new String(pars[i]);
	pe=hs.indexOf("=");
     if(pe>0){
       if(hs.slice(0,pe).toUpperCase()==name)
       	   valu=hs.slice(pe+1,hs.length);
     }else{
       if(hs.toUpperCase()==name) valu=new String();
     }
   }
 }
 return valu;
}
//**** Execute arrays of Strings (each string must be executable JS!)
function execObj(objs){
  for (var i = 0; i < objs.length; i++){
  	dbWrite('evaluation',objs[i]);
    if (typeof objs[i]=="string") eval(objs[i]);
  }  
}
function writeObj(objs){
  for (var i = 0; i < objs.length; i++)
   document.write(objs[i]);
}

function UC(str){return str.toUpperCase();}

//handling cookies:
function localBuffer(name,value){
  this.name=name;
  this.value=value || null;
}
localBuffer.prototype.load=function(){
 var cok=document.cookie;
 var larr1=cok.split(";");
 var v=null;
 for(var i=0;i<larr1.length && !v;i++){
  var eqPos=(larr1[i]).toString().indexOf('=');
  if(eqPos>0){
    var n=larr1[i].substring(0,eqPos);
    if(n==''+this.name) v=larr1[i].substring(eqPos+1,larr1[i].length);
  }
 }
 this.value=v;
 return v;
}
localBuffer.prototype.save= function(v){
 if(v) this.value=v;
 document.cookie=this.name+'='+this.value+";";
}


// MOUSEOVERHELP:
function switchMOHelp(Trigger, vis){
  var LyrHL=document.getElementById("LyrMOHelp");
  if(LyrHL){
  	if(vis){
   		var hint=getAttributeValue(Trigger,"hint");
   		if(hint && hint!=""){
			var xy=getElemAbsPos(Trigger);
			var ECnt=document.getElementById("LyrMOHelpContent");
			ECnt.innerHTML=hint;
			LyrHL.style.left=(xy[0]+1)+"px";
			LyrHL.style.top=(xy[1]+20)+"px";
			LyrHL.style.visibility="visible";
		}

  	}else
  			LyrHL.style.left="-2000px";
  }
}


//ALL THE POPUP-WINDOW STUFF FOLLOWS HERE:
if(window.name=='') window.name='winMain';

// standard window open routine
function openWinMain(URL,FORM,closePopUp){
  if(!popUps['winMain'] || popUps['winMain'].closed)
  	openWindow('','winMain','ScreenCentered','ScreenCentered',780,520,0,0,'location,menubar,personalbar,scrollbars,status,toolbar,resizable,');
  else popUps['winMain'].focus();
  if(FORM){
  	if(URL!='') FORM.action=URL;
  	FORM.target='winMain';
  }else popUps['winMain'].location.href=URL;
  if(closePopUp) self.close();
  return void(0);
}

// popup for entertainment:
function openWinEntertain(URL){
  if(!popUps['winEntertainment'] || popUps['winEntertainment'].closed)
	openWindow(URL,'winEntertainment','ScreenCentered','ScreenCentered',781,573,0,0,'scrollbars,resizable');
  else{
   	popUps['winEntertainment'].location.href=URL;
   	popUps['winEntertainment'].focus();
  }
  return void(0);
}

// standard window MyHN routines
function openWinMyHN(URL,FORM,closePopUp){
  if(!popUps['winMyHN'] || popUps['winMyHN'].closed)
  	openWindow('','winMyHN','ScreenCentered','ScreenCentered',700,520,0,0,'scrollbars,resizable');
  else popUps['winMyHN'].focus();
  if(FORM){
  	if(URL!='') FORM.action=URL;
  	FORM.target='winMyHN';
  }else popUps['winMyHN'].location.href=URL;
  if(closePopUp) self.close();
  return void(0);  
}

// popup for customer selection:
function openWinCustomerSelect(URL){
  if(!popUps['winCustomerSelect'] || popUps['winCustomerSelect'].closed)
	openWindow(URL,'winCustomerSelect','ScreenCentered','ScreenCentered',400,200,0,0,'');
  else{
   	popUps['winCustomerSelect'].location.href=URL;
   	popUps['winCustomerSelect'].focus();
  }
  return void(0);
}


// popup general, for medium sized popups
function openWinMedium(URL,name){
  if(!name) name='win'+popUps[length];
  if(!popUps[name] || popUps['name'].closed)
	openWindow(URL,'name','ScreenCentered','ScreenCentered',580,400,0,0,'scrollbars,resizable');
  else{
   	popUps[name].location.href=URL;
   	popUps[name].focus();
  }
  return void(0);
}

// popup general, for prepage popups
function openWinPrepage(URL,name){
  if(!name) name='win'+popUps[length];
  if(!popUps[name] || popUps['name'].closed)
	openWindow(URL,'name','10','10',365,321,0,0,'scrollbars=No,resizable=No');
  else{
   	popUps[name].location.href=URL;
   	popUps[name].focus();
  }
  return void(0);
}

// popup general, for Sonderaktionen popups
function openWinGewinnspiel(URL,name){
  if(!name) name='win'+popUps[length];
  if(!popUps[name] || popUps['name'].closed)
	openWindow(URL,'name','ScreenCentered','ScreenCentered',702,485,0,0,'scrollbars=No,resizable=No');
  else{
   	popUps[name].location.href=URL;
   	popUps[name].focus();
  }
  return void(0);
}



// Cookie Popup etc..

/* function openHomeTVPopup(){

var wWidth=409;
	var wHeight=395;
	var posX=(screen.width-wWidth)/2;
	var posY=(screen.height-wHeight)/2;
	if (window.location.search == "")
		var popW=openPopUpWindowCheckCookie("/kundencenter/cms/de/kundencenter/newsletter/home_tv_promo/alice_home_tv_popup.html",'NL_PopUp','left='+posX+',top='+posY+',height='+wHeight+',width='+wWidth+',dependent=true,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
} */

function openPopUpWindowCheckCookie(url,windowName,options) {
	if (readCookie('HNHomeTVPopUp') == null) {
		var exp = new Date();
		// Set cookie-expiration to one week (7 days a 24hrs a 60 minutes a 60 seconds a 1000 milliseconds)
		exp.setTime(exp.getTime() + (7 * 24 * 60 * 60 * 1000));
		//exp.setTime(exp.getTime() + (5 * 1000));
		setCookie('HNHomeTVPopUp', 1, exp);
		openPopUpWindow(url,windowName,options);
	} else {
	}
}

function readCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return importCookie (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) {
			break;
		}
	}
	return null;
}
       
function setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}
       
function removeCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = readCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
       
function importCookie(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function openPopUpWindow(url,windowName,options) {
	var popUpWindow=window.open(url,windowName,options);
	if(!popUpWindow){
		return false;
	}
	else
		popUpWindow.focus();
	return true;
}	  

var is = new checkBrowser();