function openNewWindow(url,width,height,iDefaultPosTop,iDefaultPosLeft,Userparam){
var iPosLeft;
var iPosTop;
if (screen.width){
	iPosLeft=(screen.width/2)-width/2;
	iPosTop=(screen.height/2)-height/2;
}
else{
	iPosLeft=iDefaultPosLeft;
	iPosTop=iDefaultPosTop;
}
param=Userparam+",top="+String(iPosTop)+",left="+String(iPosLeft);
window.open(url, "", "width="+width+",height="+height+","+param);
}

function getFieldValue ( theField, vType){
	//this function will return the field value (or value list) based on the element type
	theValue=""; 
	sep=";"; 
	hits=0;
	vType=vType.toLowerCase();
	//text is the user-entered value as a string
	if(vType=="text" ) return(theField.value); 
	//textarea is the user-entered value as a string array of one element
	if(vType=="textarea" ) return(theField.value);
	//select is an array of selection pointers to an array of strings representing the choices
	if(vType=="select"){
		for ( i=0; i<theField.options.length; i++){
			if(theField.options[i].selected){
				hits++;
				if(theField.options[i].value==""){
					e=theField.options[i].text;
				}else{ 
					e=theField.options[i].value;
				}
				if(hits==1){
					theValue=e;
				}else{
					theValue+= sep+e;
				}
			}
		}
		return(theValue);
	}
	if(vType=="dropdown"){
		if(theField.options[0].selected){
			return("");
		}
		return("True");
	}
	// check Emailaddress
	if(vType=="mail"){
		var mail=theField.value;
		if(mail==""){
			return ("");
		}else{
			var erg =mail.search(/.+@..+\...+/);
			if(erg==-1){
				return ("");
			}
			var erg=mail.search(/\s/);
			if(erg!=-1){
				return ("");
			}
		}
		return (mail);
	}
	//checkboxes & radio buttons
	if(vType=="checkbox"||vType=="radiobutton"){
		if(theField.value==null){
			//if we're here, we are validating a radio button or a nn multi-element checkbox
			for ( i=0; i<theField.length; i++){
				if(theField[i].checked){
					hits++;
					if(hits==1){
						theValue=theField[i].value;
					}else{
						theValue+= sep+theField[i].value;
					}
				} 
			}
		} 
		return(theValue);
	}else{
		return(theField.value);
	}
}

/* Use this function to open a link. Use any htmltag with parameter "value (URL [|"_self"])"  to open the url. */

function openElementLink(objField,sType){
var sFieldValue=getFieldValue(objField,sType);

if (sFieldValue!=""){
	var aValue=sFieldValue.split("|");
	if(aValue[1]=="_self"){
		 location.href=aValue[0];
	}
	else{
		window.open(aValue[0]);
	}
}
}

/*Bottomline*/

function printPage(){
	purl=location.href;
	anchor="";
	p=purl.indexOf("#");
	if(p>0){
		anchor=purl.substring(p)
		purl=purl.substring(0,p)
	}
	if(purl.indexOf("?")!= -1 || purl.indexOf("!") != -1) {
		purl = purl + "&setprintmode"+anchor;
	} else if(purl.indexOf("!")== -1) {
		purl = purl + "?open&setprintmode"+anchor;
	}
	printWindow(purl);
}

function printWindow(adr){
	 var param='width=640,height=500,scrollbars=yes,resizable=yes,locationbar=no,menubar=yes,screenX=50,screenY=50';
	 var title="PrintWindow";
	 adr=adr.replace(/#/,"%23");		 
	 window.open(adr,title,param);
}

function addToFavorites(pagename){
	if(window.external){
		window.external.AddFavorite(location.href,pagename)
	}else{
		// this is not an Internet Explorer
		alert("Your browser does not support automated adding to favourites, probably you are not using Internet Explorer. However, please use your browsers menu command for bookmarking instead. Thank you!");
	}
	return false;
}

function switchCSS(element,classname){
	if(is.ie){
	 	obj=document.all[element];
	 	if(obj){
			obj.className=classname;
		}
	}
	if(is.moz||is.opera||is.opera6||is.ns6||is.ns7){
		obj=document.getElementById(element);
	 	if(obj){
			obj.className=classname;
		}
	}
}

function loginSubmit() {
		 if (document.layers) {
		 		 formobj = document.layers['LoginLayerAnonymous'].document._DominoForm;
		 } else {
		 		 formobj = document._DominoForm;
		 }
document.cookie="sessionCookie=troet";
		 (GetCookie("sessionCookie"))?formobj.submit():alert ("Please enable sessionbased cookies in your browser \npreferences and reload the page!");
}

/* 2 functions
function GetCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }
  // a cookie with the requested name does not exist
  return null;
}

*/
function enter(){
	var hotkey=13;
	if (document.layers)
	document.captureEvents(Event.KEYDOWN)
	if (document.layers){		 		 		 
		if(e.which==hotkey)loginSubmit();
	}else if (document.all){
		 if(event.keyCode==hotkey)loginSubmit();
	}
}

var UNdefValue="Name";
var UNtmpStyle=null;
function UNonFocus(o){
	if(o){
		if(o.value){
			if(o.value==UNdefValue){
				o.value=''
			}
		}
		if(o.style.getAttribute){
			UNtmpStyle=o.style.getAttribute("bordercolor","false");
			o.style.setAttribute("bordercolor","#d00021","false");
		}
	}
}

function UNonBlur(o){
	if(o){
		if(o.value==''){
			o.value=UNdefValue;
		}
		if(o.style.setAttribute){
			o.style.setAttribute("bordercolor",UNtmpStyle,"false");
		}
	}
}

var PWtmpStyle=null;
function PWonFocus(o){
	if(o){
		if(o.style.getAttribute){
			PWtmpStyle=o.style.getAttribute("bordercolor","false");
			o.style.setAttribute("bordercolor","#d00021","false");
		}
		o.select();
	}
}

function PWonBlur(o){
	if(o){
		if(o.style.setAttribute){
			o.style.setAttribute("bordercolor",PWtmpStyle,"false");
		}
	}
}

function setCookie(name,value,expires,path,domain,secure){
	var curCookie=name+"="+escape(value)+
	((expires)?"; expires="+expires.toGMTString():"")+
	((path)?"; path="+path:"")+
	((domain)?"; domain="+domain:"")+
	((secure)?"; secure":"");
	document.cookie=curCookie;
}

function getCookie(name){
	var dc=document.cookie;
	var prefix=name+"=";
	var begin=dc.indexOf("; "+prefix);
	if(begin==-1){
		begin=dc.indexOf(prefix);
		if(begin!=0) return null;
	} 
	else begin+=2;
	var end=document.cookie.indexOf(";", begin);
	if(end==-1) end=dc.length;
	return unescape(dc.substring(begin+prefix.length, end));
}

function fixDate(date) {
        var base = new Date(0)
        var skew = base.getTime()
        if (skew > 0)
                date.setTime(date.getTime() - skew)
}
function startLogin() {
  formobj = document.formlogin;
  if(formobj.NickName.value == "")
  {
     alert("Please enter your Nickname");
     return false;
  }		
  var now = new Date();
  fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
  setCookie("SametimeNickname",formobj.NickName.value, now,'/');
}

function newWindow(url,width,height,addparam) {
		 w = (width=="")?800:width;
		 h = (height=="")?600:height; 
		 param = (addparam=="")?"scrollbars=auto,resizable=yes":addparam;
		 window.open(url,  "", "width="+w+",height="+h+","+param);
}

function NewWindowOPM(z)
{
 window.open(z,  "", "width=400,height=200,scrollbars=no,resizable=no");
}

function NewWindow(z)
{
 window.open(z,  "", "width=400,height=400,scrollbars=auto,resizable=yes");

}

function NewWindow2(z)
{
 window.open(z,  "", "width=500,height=700,scrollbars=yes,resizable=yes");

}

function NewWindow3(z)
{
 window.open(z,  "", "width=640,height=400,scrollbars=yes,resizable=yes");

}

function NewWindow4(z)
{
 window.open(z,  "", "width=400,height=600,scrollbars=no,resizable=yes");

}

function prozwin_ohneToolbar(ieXPos, ieYPos, ieWidth, ieHeight, nProzent, sFileName){
  sName="Dummy"
  if (is.ns) {
//- FUNKTIONIERT FÜR NS:
    winWidth = (nProzent*window.innerWidth)/ 100; 
    winHeight = (nProzent*window.innerHeight)/ 100;
    test=window.open(sFileName, sName, "width="+winWidth+",height="+winHeight+",locationbar=yes,menubar=yes,status=yes,dependent=yes,hotkeys=yes");
// relative Position:
    test.screenX=screenX+parent.innerWidth/2-winWidth/2;
    test.screenY=screenY+parent.innerHeight/2+winHeight/4-winHeight/2;
    test.focus();
   }
  else if (is.ie) {
    if (ieWidth==0) {
      winWidth=(nProzent/100)*screen.availWidth
    }
    else {
      winWidth=ieWidth
    }
    if (ieHeight==0) {
      winHeight=(nProzent/100)*screen.availHeight
    }
    else {
      winHeight=ieHeight
    }
    test=window.open(sFileName, sName, "width="+winWidth+",height="+winHeight+",locationbar=yes,menubar=yes,status=yes");
//    window.moveTo(ieXPos,ieYPos);
//    test.focus();
   }
}

function BrowserCheck() {
	if (window.defaultStatus) { window.defaultStatus = "";}
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.useragent = navigator.userAgent
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns3 = (this.b=="ns" && this.v>=3)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && (navigator.userAgent.indexOf('Netscape6')>0))
	this.ns7 = (this.b=="ns" && ((navigator.userAgent.indexOf('Netscape7')>0)||(navigator.userAgent.indexOf('Netscape/7')>0)))
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.ie6 = (this.version.indexOf('MSIE 6')>0) // not tested yet
	this.moz = ((navigator.appName == "Netscape") && (navigator.appVersion.substring(0,1) >= "5"))
	this.opera = ((navigator.appName == "Opera") || (navigator.userAgent.indexOf("Opera")>0))
	this.opera6 = (	(this.opera) && ( (navigator.appVersion.substring(0,1) >= "6") || (navigator.userAgent.indexOf("Opera 6")>0) ) )
	this.DOMsupport = (this.moz || this.opera)
	this.min = (this.ns||this.ie)
	// overriding the Opera "feature" of pretending to be another browser
	if (this.opera) {
/*		if ( this.ie || this.ns || this.ns3 || this.moz ) {
			msg = "even if you pretend to be another browser, we know that you are using Opera.";
			window.defaultStatus = msg;
		} */
		this.ns = false;
		this.ns4 = false;
		this.ns5 = false;
		this.ie = false;
		this.ie4 = false;
		this.ie5 = false;
		this.moz = false;
	}
}

function prozwin(ieXPos, ieYPos, ieWidth, ieHeight, nProzent, sFileName){
  sName="Dummy"
      if (ieWidth==0) {
      winWidth=(nProzent/100)*screen.availWidth
    }
    else {
      winWidth=ieWidth
    }
    if (ieHeight==0) {
      winHeight=(nProzent/100)*screen.availHeight
    }
    else {
      winHeight=ieHeight
    }

    test=window.open(sFileName, sName, "width="+winWidth+",height="+winHeight+",toolbar=yes,location=no,locationbar=no,menubar=yes,status=yes,scrollbars=yes,personalbar=no,resizable=yes,dependent=yes,hotkeys=yes");
}


/************* LEGACY JAVASCRIPT ****************/
var w = screen.availWidth;
var h = screen.availHeight; 
var popW = 150;
var popH = 600;
var leftPos = (w+(w/1.9))/2;
var topPos = h/10;

function ostern_de(){ ostern('de'); } 
function ostern_en(){ ostern('en'); } 

function ECARD_de(){ ECARD('de'); } 
function ECARD_en(){ ECARD('en'); } 
function MEMORY_de(){ MEMORY('de'); } 
function MEMORY_en(){ MEMORY('en'); } 



function ECARD(lang) 
{ 
var wleft =200;
var wtop = 170;
if (lang == 'de')
	{
		seite = 'http://ecard.bayermaterialscience.de/check6.html';
	}else{
		seite = 'http://ecard.bayermaterialscience.de/check_e_6.html';
	}
wshelp = window.open (seite, 'ecard','width=638,height=473,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=no,left=' + wleft +',top='+ wtop+'screenY=' + wtop + ',screenX=' +wleft);
wshelp.focus();
}

function ostern(lang) 
{ 
var wleft =200;
var wtop = 170;
if (lang == 'de')
	{
		seite = 'http://www.game.bayermaterialscience.de/osterspiel/eastergame_2005_de.html';
	}else{
		seite = 'http://www.game.bayermaterialscience.com/egg-hunting/eastergame_2005_e.html';
	}
wshelp = window.open (seite, 'eastern','width=688,height=535,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=no,left=' + wleft +',top='+ wtop+'screenY=' + wtop + ',screenX=' +wleft);
wshelp.focus();
}


function MEMORY(lang) 
{ 

var wleft = 200;
var wtop = 170;
	if (lang == 'de')
	{
		seite = 'http://ecard.bayermaterialscience.de/memory/game_get2_de.html';
	}else{
		seite = 'http://ecard.bayermaterialscience.de/memory/game_get2_e.html';
	}

wshelp = window.open (seite, 'memory','width=691,height=544,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=no,left=' + wleft +',top='+ wtop+'screenY=' + wtop + ',screenX=' +wleft);
wshelp.focus();
}
function openpopup(page,param1,param2)
{
	var wleft = 150;
	var wtop = 100;
	wshelp = window.open (page, 'Popup','width=' + param1 + ',height=' + param2 + ',location=yes,menubar=yes,status=yes,toolbar=yes,resizable=yes,scrollbars=auto,left=' + wleft +',top='+ wtop+'screenY=' + wtop + ',screenX=' +wleft);
	wshelp.focus();
}

function weltreise(lang) 
{ 
var wleft =200;
var wtop = 170;
if (lang == 'de')
	{
		seite = 'b_weltreise_de';
        }else if (lang == '1'){

		seite = 'http://www.weltreise.bayermaterialscience.de/game_2005_de.html';
	}else if (lang == '2'){

		seite = 'http://www.worldtour.bayermaterialscience.com/game_2005_e.html';

	}else{
		seite = 'b_weltreise_en';
	}
wshelp = window.open (seite, 'eastern','width=690,height=544,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=no,left=' + wleft +',top='+ wtop+'screenY=' + wtop + ',screenX=' +wleft);
wshelp.focus();
}

