//JavaScript - All rights reserved - Copyright by mediaLINK 
//General script-Library for BayerEdWebsite - v1.12a/02.02.2007



//-----fnc rollover section
if (document.images){
	var imageov = new Array();
	var imageof = new Array();
	
	for (var z=1; z<=4; z++){
		imageov['fnc'+z] = new Image();
		imageov['fnc'+z].src = "/"+lang + "/mGraphfnc/fnc"+z+"ov.gif";
		imageof['fnc'+z] = new Image();
		imageof['fnc'+z].src = "/"+lang + "/mGraphfnc/fnc"+z+"of.gif";
	}
}

function imgov(i){
	if (document.images){
		document.images[i].src=imageov[i].src;
	}
}

function imgof(i){
	if (document.images){
		document.images[i].src = imageof[i].src;
	}
}




//-----form functions
function formSend(p){
	//selftest
	if (p == "selftest"){
		var s = 0;
		var v;
		for (var i=0; i<=4; i++){
			v = document.forms[0].elements[i].checked;
			if (v == true){
				s++;
			}
		}
		
		if (s >= 0){
			if (cookieOK == true){
				SetCookie("edSelftest_v1_00","Selfest done",(new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000)),"/");
			}
			if ((s == 0) | (s == 1) | (s == 2)){
				self.location.href = "/"+lang +"/mPages/HI/HI_StVh.shtml?Answer2";
			}
			if ((s == 3) | (s == 4)){
				self.location.href = "/"+lang +"/mPages/HI/HI_StVh.shtml?Answer4";
			}
			if (s == 5){
				self.location.href = "/"+lang +"/mPages/HI/HI_StVh.shtml?Answer5";
			}
		}else{
			alert(msgSelftestNoAnswers);
		}
	}


	if (p == "registerspecs"){
		if ((document.formula.lastname.value == '') || 
			(document.formula.firstname.value == '') || 
			(document.formula.specialization.value == '') || 
			(document.formula.address.value == '') || 
			(document.formula.ziplocation.value == '') || 
			(document.formula.email.value == '')){
			alert(msgFormRequired);
		}else{
			document.formula.submit();
		}
	}
}



var rs = 0;
function getRisikoScore(){
	if (document.formula.alter.value == ""){
		document.formula.alter.value = "0";
	}
	rs = parseInt(document.formula.alter.value,10);
	for(z=1; z<=12; z++){
		if (document.formula.elements[z].checked == true){
			rs = rs + parseInt(""+document.formula.elements[z].value,10)
		}
	}
	document.formula.risikoScore.value = "" + rs;
}


function getRisikoTable(){
	self.location.href = "HI_RtAg.shtml?" + rs;
}


function writeRisikoScore(){
	sls=self.location.search.substring(1,self.location.search.length);
		if (sls.indexOf('risikoscore') > -1){
			sls = sls.substring(sls.indexOf(risikoscore)+12,sls.length);
		}
}


function risikoScoreReset(){
	document.formula.reset();
	rs = 0;
}



//-----cookie-functions
//Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt
//Adapted by mediaLINK Switzerland - Version 1.0 / 22.09.2001
//-----------------------------------------------------------------------------------
var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

function GetCookie(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 getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

function DeleteCookie(name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

function SetCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}

var cookieOK = false;
function cookieCheck(){
	SetCookie("cookieChecker","CheckingForCookieFunction",0,"/");	//when setting expTime: attn. GTM-problem NS4.05WIN
	if (GetCookie("cookieChecker") != null){						//no Time set: is a session cookie
		cookieOK = true;
	}
}

cookieCheck();

function saveLanguage(l){
	SetCookie("selectedLanguage",l,(new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000)),"/");
}



//-----various functions

//checking filename
var filename;
//following if-query to prevent ev. location-attaches on netscape (to adjust, if location-attaches can contain slashes)
if (self.location.href.indexOf("?") > -1){
	filename = self.location.href.substring(self.location.href.lastIndexOf("/")+1,self.location.href.lastIndexOf("?"));
}else{
	filename = self.location.href.substring(self.location.href.lastIndexOf("/")+1,self.location.href.length);
}
rubric = filename.substring(0,2);

//reading self-location
var sls = self.location.search.substring(1,self.location.search.length);


//universal div-handling
function setdiv(divname,displaytype){
	if ((document.getElementById) && (!ie4)){
		eval("document.getElementById('" + divname + "').style.display = '" + displaytype + "'");
	}
	if (document.layers){
		eval("document." + divname + ".display = '" + displaytype + "'");
	}
	if (ie4){
		eval("document.all." + divname + ".style.display = '" + displaytype + "'");
	}
}



//changing add-content
//divPrimary   = Selftest as addContent
//divSecondary = any addContent per rubric

function setAddContent(){
	if (cookieOK == true){
		if ((GetCookie("edSelftest_v1_00") != null) & (filename != "HI_StHe.shtml")){
		//selftest made
			setdiv("divSecondary","block");
		}else{
		//selftest pending
			setdiv("divPrimary","block");
		}
	}else{
		//no cookies available
		if ((filename == "HO_Wn.shtml") | (filename == "IN_Ae.shtml") | (filename == "WA_Et.shtml") | (filename == "HI_StHe.shtml") | (filename == "ER_Mn.shtml")){
			//if first page of rubric
			setdiv("divPrimary","block");
		}else{
			setdiv("divSecondary","block");
		}
	}
}



//setting of correct answer-text in HI_StVh.shtml
function setTestAnswer(){
	if ((sls == "Answer2") | (sls == "Answer4") |  (sls == "Answer5")){
		if (sls == "Answer2"){
			setdiv("divTestAnswer2","block");
		}
		if (sls == "Answer4"){
			setdiv("divTestAnswer4","block");
		}
		if (sls == "Answer5"){
			setdiv("divTestAnswer5","block");
		}
	}else{
		setdiv("divTestAnswer0","block");
	}
}



//checking profmeds for accesshandling in "IN"
function setprofmed(){
	SetCookie("profmed","profmed",0,"/")
	self.location.href = "/"+lang+"/mPages/IN/IN_La.shtml";
}

function getHomepage(){
	self.location.href = "/"+lang+"/mPages/HO/HO_Wn.shtml";
}


if ((rubric == "IN") && (filename != "IN_As.shtml") && (filename != "IN_AsBg.shtml")){
	if (cookieOK != true){
		alert(msgNoCookies);
		self.location.href="/"+lang+"/mPages/IN_As/IN_As.shtml"; //redirected to accesspage
	}else{
		SetCookie("profmed","profmed",0,"/");
	}
}


if (filename == "IN_As.shtml"){
	if (cookieOK != true){
		alert(msgNoCookies);
	}else{
		if (GetCookie("profmed") != null){
			//self.location.href="/"+lang+"/mPages/IN/IN_La.shtml"; //forwarded to the first page of this rubric
		}

		//for auto-select language on redirecting from www.levitra.ch
		if (GetCookie("selectedLanguage") != null){
			if  (GetCookie("selectedLanguage") != lang){
				self.location.href = "/"+GetCookie("selectedLanguage")+"/mPages/IN_As/IN_As.shtml";
			}
		}
		
	}

}







//print functions
function printdsp(){
	if ((self.print) || (ieX && WIN)){
		if (self.print){			//NS4W/NS4.5M/NS6W/IE5W/Mozilla 1.21
			if (self.focus){
				self.focus();	//for E5W
			}
			self.print();
		}else{
			printo();				//IEXWin
		}
	}else{
		if ((ieX) && (MAC)){		//IE4/5Mac
			alert(msgPrintingFailedE5M);
		}else{
			alert(msgPrintingFailed);
		}
	}
}

function printo() {
	var OLECMDID_PRINT = 6;
	var OLECMDEXECOPT_DONTPROMPTUSER = 2;
	var OLECMDEXECOPT_PROMPTUSER = 1;
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	oldHandler = window.onerror;
	window.onerror = deal;
	WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
	WebBrowser1.outerHTML = "";
	window.onerror = oldHandler;
}

function deal(){
	WebBrowser1.outerHTML = "";
	window.onerror = oldHandler;
	return true;
}


//bookmark-functions
function setBookmark(){
	var bookmarkurl = self.location.href;
	var bookmarktitle = document.title;
	if (window.external && noMAC){
	//if(document.all){
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	}else{
		alert(msgBookmarkingFailed);
	}
}


//defocus-function
function defocus(t){
	if (t.blur){t.blur()}
}


//---end of script
