var arrNotify = new Array();
arrNotify[0] = new Array();
arrNotify[1] = new Array();
arrNotify[0][0] = "Sie sind als Demo User eingeloggt und können deshalb diese Funktion nicht ausführen.";
arrNotify[1][0] = "FR: Sie sind als Demo User eingeloggt und können deshalb diese Funktion nicht ausführen.";

//******************************************************************************************
// Prueft ob das Form abgeschickt werden darf
//******************************************************************************************
function BeforeSubmit(sForm, nType, nLanguage) {

    switch (nType) {

        // Demo User 
        case 1: window.alert(arrNotify[nLanguage][0]); break;
        // Normaler User
        default: document.forms[sForm].submit(); break;
    }
}

function changeLanguage(sNewLanguage) {
  if(sNewLanguage == "") return;
  sUrl = top.location.href;

  sOldLanguage = "";

  cLangD = "/d/";
  cLangF = "/f/";
  if(sUrl.indexOf(cLangD) > 0) sOldLanguage = cLangD;
  if(sUrl.indexOf(cLangF) > 0) sOldLanguage = cLangF;

  cDDomain = "www.rezeptformular.ch";
  cFDomain = "www.ordonnance.ch";

  if(sOldLanguage != "")
  {
    sUrl = sUrl.replace(sOldLanguage, sNewLanguage);
    top.location.href = sUrl.replace(sOldLanguage == cLangD ? cDDomain : cFDomain, sOldLanguage == cLangD ? cFDomain : cDDomain);
  }
  else
  {
    sNewDomain = (sNewLanguage == "/d/" ? cDDomain : cFDomain);
    top.location.href = "http://" + sNewDomain + "/login.aspx";
  }
}

function ShowImage(sImage) 
{
    image = new Image();
    image.src = sImage;
    height = image.height + 20;
    width = image.width + 20;

    winRef = window.open("", String(Math.random), 'width=' + width + ',height=' + height + ',scrollbars=no');
    winRef.document.open();
    winRef.document.write("<html><head><title>Novartis Pharma Schweiz AG</title></head><body leftmargin=0 topmargin=0 margindwidth=0 marginheight=0>");
    winRef.document.write("<img src='" + sImage + "' style='margin:10px;'>");
    winRef.document.write("</body></html>");
    winRef.document.close();
    winRef.focus();
}        

function OpenWin(sPage, sWindow, width, height) {
	if (!width) width = 500;
	if (!height) height = 500;  
	if (!sWindow) sWindow = "";
    var winRef = window.open(sPage,sWindow,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
    if(winRef != null)
    {
		winRef.location.href = sPage;
		winRef.focus();
    }
}        
function openWin(sPage, sWindow, width, height) {
	if (!width) width = 500;
	if (!height) height = 500;  
	if (!sWindow) sWindow = "";
    var winRef = window.open(sPage,sWindow,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
    if(winRef != null)
    {
		winRef.location.href = sPage;
		winRef.focus();
    }
}        

function openWinSiegel(sPage) {
  window.open(sPage,"",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=640,height=500');
}

//---------------------------------------------------
// Event-Funktionen
//---------------------------------------------------

function addEvent(elm, evType, fn, useCapture) {
  // cross-browser event handling for IE5+, NS6 and Mozilla
  // By Scott Andrew
  if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent) {
    var r = elm.attachEvent('on' + evType, fn);
    EventCache.add(elm, evType, fn);
    return r;
  } else {
    elm['on' + evType] = fn;
  }
}

/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

/*	Implement array.push for browsers which don't support it natively.
	Please remove this if it's already in other code */
if(Array.prototype.push == null){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){
			this[this.length] = arguments[i];
		};
		return this.length;
	};
};

/*	Event Cache uses an anonymous function to create a hidden scope chain.
	This is to prevent scoping issues. */
var EventCache = function(){
	var listEvents = [];
	
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){
			listEvents.push(arguments);
		},
	
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				
				/* From this point on we need the event names to be prefixed with 'on" */
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				
				item[0][item[1]] = null;
			};
		}
	};
}();


//---------------------------------------------------
// Korrektur-Funktionen für Node-Grösse
//---------------------------------------------------

// Setzt die richtige Höhe eines Elements aufgrund seiner Inhalte
function SetNodeHeight(nodeId)
{
	var node = document.getElementById(nodeId);
	if (node)
	{
		var bottomY = GetNodeAbsBottomY(node, 0);
		node.style.height = (bottomY - GetNodeAbsTopY(node)) + "px";
	}
}

// Liefert die absolute y-Position der Bottom-Seite eines Elements
function GetNodeAbsBottomY(node, y)
{
	for(var i = 0; i < node.childNodes.length; i++)
	{
		var ele = node.childNodes[i];
		if(ele.nodeType != 1) continue

		var yNew = GetNodeAbsTopY(ele) + parseInt(ele.offsetHeight);

		if(y < yNew) y = yNew;
				
		y = GetNodeAbsBottomY(ele, y);
	}
	return y;
}

// Liefert die absolute y-Position der Top-Seite eines Elements
function GetNodeAbsTopY(node)
{
	if(!(node && node.offsetTop)) return;
	var y = node.offsetTop;
	while(node.offsetParent) 
	{
		y += node.offsetParent.offsetTop ? parseInt(node.offsetParent.offsetTop) : 0;
		node = node.offsetParent;
	}
	return y;
}


//-->