//JavaScript - Library
//All rights reserved - Copyright by medialink 2001-2007 - v6.04a/12.06.2007


//-----default-settings
var filename = "";
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);
}

var rubric = filename.substring(0,2);
var sls = self.location.search.substring(1,self.location.search.length);




//----- rollover-section ---------------------------------------------------------------------------

if (document.images){
	var imageov = new Array();
	var imageof = new Array();
	
	//fnc-images
	for (var z=1; z<=4; z++){
		imageov['fnc'+z] = new Image();
		imageov['fnc'+z].src = "/nw_any/graphlay/fnc"+z+"ov.gif";
		imageof['fnc'+z] = new Image();
		imageof['fnc'+z].src = "/nw_any/graphlay/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;
	}
}




//----- init-section ---------------------------------------------------------------------------
//defining the rubric (also for weblication-edit-filenames
if ((rubric != "AQ") && (rubric != "WA") && (rubric != "BE") && (rubric != "AN") && (rubric != "PR") && (rubric != "KO")){
	rubric= "AQ"; //default if not specified
}


//setting the header images (not for WA_.php)
function doinit(){
	if ((document.images) && (filename != "WA_.php")){
		document.images['headimage'].src = "/nw_any/graphlay/headImage_" + rubric + ".jpg";
	}
}




//-----cookie-functions
//Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt
//Adapted by medialink Switzerland - Version 1.01a / 30.05.2006
//-----------------------------------------------------------------------------------
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();





//----- form-section ---------------------------------------------------------------------------
var requestArray = new Array();
var requestContent = "";


function setRequestIndex(r){
	if (cookieOK == true){
		var requested = r;
		
		//reading cookie
		requestContent = GetCookie("selectedrequests");
		if (requestContent != null){
			requestArray = requestContent.split("&");
		}else{
			requestArray = new Array();
		}

		//checking if already requested
		if (requestArray.length != null){
			for (var i=0; i < requestArray.length; i++){
				if (requestArray[i].indexOf(requested) > -1){
					requested = "";
					break;
				}
			}
		}
		
		//new request saved in cookie
		if (requested != ""){
			requestArray[requestArray.length] = requested;				//adding request
			SetCookie("selectedrequests",requestArray.join('&'),0,"/");	//expTime=0 creates session cookie
		}
		
		//option to call th request form		
		if (confirm(msgForwardingToRequestForm)){
			wait = setTimeout("JavaScript:self.location.href='/nw_'+lang+'/pages/KO/KO_Ar.php'",50)
		}
		
		
	}else{
		alert(msgCookiesRequired);
	}
}



function initRequests(){
	requestContent = GetCookie("selectedrequests");
	
	if (requestContent != null){
		requestArray = requestContent.split("&");
		for (var i=0; i<requestArray.length; i++){
			eval("document.formula.request" + requestArray[i] + ".checked = true")
		}
	}
}



function setRecipient(n,e){
	document.formula.namerecipient.value = n.value;
	document.formula.emailrecipient.value = e;
}




//new formmaling
//hiddenfield-section 0 > confirm-mail to user
//hiddenfield-section 1 > CC-Mail to website-holder
//hiddenfield-section 2 > Mail to recipient

function setSenderName(n){
	//user filling-in his name
	document.formula.elements[3].value = document.formula.firstname.value + " " + n;	//mail_recipient_name[0]
	document.formula.elements[6].value = document.formula.firstname.value + " " + n;	//mail_sender_name[1]
	document.formula.elements[11].value = document.formula.firstname.value + " " + n;	//mail_sender_name[2]	
}


function setSenderAddress(a){
	//user filling-in his email-address
	document.formula.elements[4].value = a;		//mail_recipient_addr[0]
	document.formula.elements[7].value = a;		//mail_sender_addr[1]
	document.formula.elements[12].value = a;	//mail_sender_addr[2]
}

function setRecipientNameAndAddress(n,a){
	//user selects a recipient (laboratory)
	document.formula.elements[13].value = n;	//mail_recipient_name[2]
	document.formula.elements[14].value = a;	//mail_recipient_addr[2]
}



function formSend(p){
	if (p == "userrequest"){
		if ((document.formula.lastname.value == "") || (document.formula.firstname.value == "") || (document.formula.ziplocation.value == "") || (document.formula.emailuser.value == "")){
			alert(msgFormRequired);
		}else{
			//collecting the request topics
			for (var i=1; i<=document.formula.numberofrequests.value; i++){
				eval("b = document.formula.request" + i + ".checked");
				eval("v = document.formula.request" + i + ".value");
				if (b == true){
					document.formula.requests.value = document.formula.requests.value + "- " + v + "\n";
				}
			}
			document.formula.submit();
		}
	}
}



function formReset(p){
	document.formula.reset();
	if (p == "userrequest"){
		DeleteCookie("selectedrequests","/");
	}
}





//-----fnc-handling---------------------------------------------------------------------------

//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){
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	}else{
		alert(msgBookmarkingFailed);
	}
}




//--- end of file
