﻿// Auch für Netsape 7
// 
// Datum: 02.04.2003

var vInputDialog = new Array();
var charPixelX = 10;
var charPixelY = 22.2;
var l_page_x = 100;
var l_page_y = 200;
vv = new Array;
vk = new Array;

function appendVV(tafelZeile,text)
{
	// Tafelzeile decodieren
	var len = 0;
	var i = 0;
	var mysubstr = "";
	var str = new String();

	for (i=0; i< tafelZeile.length; i=i+2)
	{
		mysubstr = tafelZeile.substring(i,i+2);
		str = str.concat(mysubstr);

		if (mysubstr.indexOf("00") >= 0)
		{
			i = i+2;
			len = new Number("0x" + tafelZeile.substring(i,i+2));

			for (k=1; k<len; k++)
				str =str.concat("00");
		}
	}

	str = new String(str);

	var zeile =  new Number("0x" + str.substring(8,16));
	var spalte = new Number("0x" + str.substring(16,24));
	var temp = new Array;
	temp[0] = String(str);
	temp[1] = String(text);
	temp[2] = "";			// ByteString
	temp[3] = "";			// AnzeigeString
	temp[4] = "";			// alter AnzeigeString
	temp[5] = zeile;		// Zeile
	temp[6] = spalte;		// Spalte

	vv[vv.length] = temp;
	vk[vk.length] = temp;
}

function appendKK(xPos,yPos,str)
{
	var temp = new Array;
	temp[0] = parseInt(xPos);
	temp[1] = parseInt(yPos);
	temp[2] = str;

	vk[vk.length] = temp;
}

function test()
{
	var str1 = "";
	var str2 = "";

	for (i=0; i<vv.length; i++)
	{
		str1 = String(vv[i][3]);
		str2 = String(vv[i][4]);

		// Stringlänge ungleich oder indexOf(String) != 0) => Strings sind ungleich
		if ((str1.length != str2.length) || (str1.indexOf(str2) != 0))
		{
			if ((document.layers) && (document.layers.ee))
			{
				doc = document.layers.ee.document.layers["e"+(i+1)].document;
				doc.open();
				doc.writeln("<html><head></head><body><font face ='COURIER'>")
				doc.writeln(str1);
				doc.writeln("</font></body></html>");
				doc.close()
			}
			else if (document.getElementById)
			{
				document.getElementById("e" + (i+1)).innerHTML = str1;
			}
			else if (document.all)
			{
				document.all["e" + (i+1)].innerHTML = str1;
			}
			vv[i][4] = str1;
		}
	}
}

function initApplet()
{
	inputtyp = (window.parent.inputTyp)
	var myApplet = document.applets["BoardApplet"];
	var protocolmodus = "0";

	if (inputtyp.typ == 1)
	{
		protocolmodus = "1";
	}
	
	for (i=0; i<vv.length; i++)
	{
		var str = String(i);

		try
		{
			myApplet.appendVariable(vv[i][0],vv[i][1],str, protocolmodus);
		}
		catch(err)
		{
		}
	}

	myApplet.setRegler(strComputerNr,strReglerZweigNr,strReglerNr);
	myApplet.setUpdateTime(2000);
	myApplet.updateStart(0);
}

function update()
{
	var strvar = null;

	for (i=0; i<vv.length; i++)
	{
		vv[i][2] = document.applets["BoardApplet"].getByteValueAsString(i);
		vv[i][3] = document.applets["BoardApplet"].getFormatetVariable(i);
	}

	window.defaultStatus = document.applets["BoardApplet"].getConnectionStatus();
	test();
	setTimeout("update()",2000);
}

function login()
{
	var inputtyp = (window.parent.inputTyp)

	if (inputtyp.typ == 1)
	{
		alert("Protokollmodus aktiv!\nFür Login bitte die Protokolleingabe beenden.");
		return;
	}
  
	var screenX,screenY,strPara,wWidth,wHeight;

	if ( Touch == "false" )
	{
		wWidth = 320;
		wHeight = 165;
	}
	else
	{
		wWidth = 575;
		wHeight = 360;
	}
	
	pX = (screen.availWidth - wWidth) / 2;
	pY = (screen.availHeight - wHeight) / 2;

	if ((window.dlg) && (!window.dlg.closed))
		window.dlg.close();

	strUrl = "/COSMOWEB&TYP=REGLER&COMPUTERNR=" + encodeURI(strComputerNr);
	strUrl += "&REGLERSTRANG=" + encodeURI(strReglerZweigNr) + "&REGLERNR=" + encodeURI(strReglerNr);
	strUrl += "&MSG=GET_LOGIN_DLG&TIMESTAMP=" + encodeURI(new Date().getTime());
	strUrl += "&TOUCH=" + encodeURI(Touch) + "&";

	strPara = "width=" + wWidth + ",height=" + wHeight +",";
	strPara += "screenX=" + pX + ",screenY=" + pY + ",";
	strPara += "left=" + pX + ",top=" + pY + ",";
	strPara += "locationbar=false,menubar=false,resizable=false,dependent=yes";
	dlg = window.open(strUrl,"Passwort",strPara);
}

function getTree(str)
{
	if (str.indexOf(".htm") >= 0)
		window.parent.location.replace(str);
}

function stoerLoeschen()
{
	str  = "Sollen die Störmeldungen wirklich gelöschet werden ?\n";
	str += "\nKlicken Sie auf OK, um die Störmeldungen zu löschen!\n";
	str += "Klicken Sie auf Abbrechen, um den Vorgang abzubrechen!";

	if (confirm(str) == true)
	{
		for (i=0; i <loeschArray.length;i++)
		{
			strUrl = "/COSMOWEB&TYP=REGLER&COMPUTERNR=" + encodeURI(loeschArray[i].substring(0,4));
			strUrl += "&REGLERSTRANG=" + encodeURI(loeschArray[i].substring(4));
			strUrl += "&MSG=DELETE_STOERMELDUNGEN&";
			strData = "&PASSWORT=XXXX&STTYP=LOKAL&";

			document.applets["BoardApplet"].sendCosmosURL(strUrl,strData);
		}
		window.parent.openLastTafel();
	}
}

function getCookie(name)
{
	var i=0;
	var suche=name+"=";

	if (document.cookie == null)
		return null;

	while(i < document.cookie.length)
	{
		if (document.cookie.substring(i,i+suche.length)==suche)
		{
			var ende=document.cookie.indexOf(";",i+suche.length);
			ende=(ende>-1) ? ende: document.cookie.length;
			var cook=document.cookie.substring(i+suche.length,ende);
			return cook;
		}
		i=i+1;
	}
	return null;
}

/** Diese Funktion setzt einen Cookie (ehk)*/
function setCookie(name,value)
{
	var shorty = new String();
	var ablauf = new Date();
	var infuenfTagen = ablauf.getTime() + (99999 * 24 * 60 * 60 * 1000);
	ablauf.setTime(infuenfTagen);
	shorty = name+"="+value+"; expires=" + ablauf.toGMTString();

	// und alles wieder merken
	document.cookie = shorty;
}

function getCookie(name)
{
	var i=0;
	var suche=name+"=";

	if (document.cookie == null)
		return null;
  
	while(i < document.cookie.length)
	{
		if (document.cookie.substring(i,i+suche.length)==suche)
		{
			var ende=document.cookie.indexOf(";",i+suche.length);
			ende=(ende>-1) ? ende: document.cookie.length;
			var cook=document.cookie.substring(i+suche.length,ende);
			return cook;
		}
		i=i+1;
	}
	return null;
}

function loadStartPage(absolutePath)
{
	var strZoom = getCookie("ZOOM");

	if (strZoom == null)
	{
		strZoom = "ZOOM_100";
	}
	var strUrl = "/COSMOWEB&TYP=REGLER&MSG=GET_HTML_BOARD&COMPUTERNR=" + encodeURI(strComputerNr);
	strUrl += "&REGLERSTRANG=" + encodeURI(strReglerZweigNr) + "&REGLERNR=" + encodeURI(strReglerNr);
	strUrl += "&TAFEL=V_GRAFIKAPPLET&EBENE=" + encodeURI(strEbene) + "&RNEBENE=" + encodeURI(strRNEbene);
	strUrl += "&ABSPATH=" + encodeURI(absolutePath) + "&GOONLINE=" + encodeURI(strGoOnline);
	strUrl += "&TOUCH=" + encodeURI(Touch) + "&ZOOM=" + encodeURI(strZoom) + "&";

	alert(strUrl);
	location.href=strUrl;
	alert('fertig');
}

function isTouchOn()
{
	if (getCookie("Touch") == "true")
		return true;
	else
		return false;
}

function inputDialog(i)
{
	var myApplet;
	var index = i;
	var inputtyp = (window.parent.inputTyp)

	if ((inputtyp.typ == 1) && (inputtyp.rN == reglerNummer))
	{
		inputProtokoll(index);
		return;
	}
  
	vInputDialog[0] = new String(vv[index][0]);
	vInputDialog[1] = new String(vv[index][1]);
	vInputDialog[2] = new String(vv[index][2]);
	vInputDialog[3] = window.parent.Ebene;
	vInputDialog[4] = isTouchOn();
	vInputDialog[5] = Userverwaltung;

	
	
	if(navigator.appVersion.indexOf("MSIE") != -1)
	{
		if (isTouchOn())
			showModalDialog('/DialogTextField.html',vInputDialog,'dialogWidth:587px;dialogHeight:400px;center:1;scroll:no');
		else 
			showModalDialog('/DialogTextField.html',vInputDialog,'dialogWidth:450px;dialogHeight:210px;center:1;scroll:no');
	}
	else
	{
		if ((window.inputDlgWnd) && (!window.inputDlgWnd.closed))
		{
			window.inputDlgWnd.close();
		}

		var l = screen.width / 2 - 225;
		var t = screen.height / 2 - 87;

		str = "width=450,height=210,locationbar=false,menubar=false,resizable=false,";
		str += "left=" + l + ",top=" + t + ",screenX=" + l + ",screenY=" + t;

		inputDlgWnd = window.open("/DialogTextField.html","EingabeDialog",str);
	}
	
}

function getInputDialogVariable()
{
	return vInputDialog;
}

function inputProtokoll(i)
{
	str = "Protokollmodus noch aktiv!\n";
	str += "Bitte beenden Sie diesen auf der Service-Seite";

	if (window.parent.inputTyp.fenster.closed)
	{
		alert(str);
		return;
	}

	str = "Sie haben folgenden Datenpunkt ausgewählt: ";
	str +=  document.applets["BoardApplet"].getVariString(i);
	str += "\nGeben Sie hierfür einen Namen ein!";
	eingabe = prompt(str,"");

	if (eingabe == null)
		return;

	str = window.parent.inputTyp.fenster.addAdress(vv[i][0],eingabe,window.parent.lastTafel.absolutePath);

	if (str.indexOf("OK",0) != 0)
		alert(str);
}

function getPassPara()
{
	var temp = new Array;
	temp[0] = String(strComputerNr);
	temp[1] = String(strReglerZweigNr);
	temp[2] = String(strReglerNr);
	temp[3] = String(strKanalNr);
	temp[4] = String(window.parent.Ebene);
	return temp;
}

function initDlgApplet(v)
{
	if ((window.inputDlgWnd) && (!window.inputDlg.closed))
		inputDlgWnd.initApplet(vv[index]);
	else
		setTimeout("initDlgApplet(v)",500);
}

function start()
{
	initApplet();
	setTimeout("update()",2000);
}

function toFront()
{
	document.applets["PasswortDlg"].focus();
	setTimeout("toFront()",500);
}

