
var ns4 = document.layers ? true : false;
var ie4 = document.all ? true : false;
var any_ie = document.all ? true : false;
var dom = document.getElementById ? true : false;
if (dom) { ie4 = false; }

if (ns4) {
  document.captureEvents(Event.MOUSEUP);
  document.onmouseup=netscape_mouse_pos;

  function netscape_mouse_pos(thisEvent)   {
    posX = thisEvent.screenX;
    posY = thisEvent.screenY;
  }
}

function setDate(date, fieldName) {
 	actionForm.elements[fieldName].value = date;
}

var CalendarWindow = null;

function calendar(fieldName) {
  selectDate = actionForm.elements[fieldName].value;
  if(CalendarWindow && !CalendarWindow.closed){
    CalendarWindow.close();
  }
  calendarX = 420;
  calendarY = 520;
  if (ns4) {
    calendarX = posX + 50;
    calendarY = posY - 150;
  }
  if (any_ie) {
    var browserposx = window.screenLeft;
    var browserposy = window.screenTop;
    calendarX = window.
    calendarX = window.event.clientX + 50 + browserposx;
    calendarY = window.event.clientY + browserposy - 150;
  }

  CalendarWindow = window.open( 'PopupCalendar.jsp?SelectDate=' + selectDate + '&FieldName=' + fieldName, 'calendar','menubar=0,toolbar=0,status=0,scrollbars=auto,width=170,height=168,left='+ calendarX +',screenX='+ calendarX +',top=' + calendarY +',screenY='+ calendarY +'');
  CalendarWindow.focus();
}

var OrganisationTreeWindow = null;

// ML 2009-07-30 Freitexteingabe im Orgfeld führt zur Suche der Organisation
// isParentOrgAssignment durchgereicht, wenn Vatorganisation/Organisation des
// Partner zugeordnet wird gelten andere Filter für die AuswahlPartner

function organisationTree(callback) {
	if(callback.fieldName != undefined){
		selectedOrgId = actionForm.elements[callback.fieldName+"SelectedID"].value;
		var inputField = actionForm.document.getElementById(callback.fieldName+"Name"); 
		if(inputField!=null){
			var inputFieldOrgName = actionForm.elements[callback.fieldName+"Name"].value;
		}
	}
	if(callback.selectedID != undefined){
		selectedOrgId = callback.selectedID;
	}
	if(OrganisationTreeWindow && !OrganisationTreeWindow.closed){
		OrganisationTreeWindow.close();
	}

	organisationTreeX = 200;
	organisationTreeY = 200;

	if (ns4) {
		organisationTreeX = posX + 50;
		organisationTreeY = posY - 150;
	}

	if (any_ie) {
		var browserposx = window.screenLeft;
		var browserposy = window.screenTop;
		organisationTreeX = window.event.clientX + 50 + browserposx;
		organisationTreeY = window.event.clientY + browserposy - 150;
	}
	while(selectedOrgId.match("#")){
		selectedOrgId = selectedOrgId.replace("#","-");
	}
	sUrl = 'OrganisationTree.jsp';
	sUrl = sUrl + '?SelectOrgId=' + selectedOrgId;
	sUrl = sUrl + '&FieldName=' + callback.fieldName;
	sUrl = sUrl + '&orgName=' + inputFieldOrgName;
	if(callback.isParentOrganisationAssignment!=undefined){
		sUrl = sUrl + '&isParentOrganisationAssignment='+callback.isParentOrganisationAssignment;	
	}
	OrganisationTreeWindow = window.open( sUrl, 'organisationtree','menubar=no,toolbar=no,location=yes,status=yes,resizable=yes,scrollbars=yes,left='+ organisationTreeX +',screenX='+ organisationTreeX +',top=' + organisationTreeY +',screenY='+ organisationTreeY +'');
	OrganisationTreeWindow['organisationTreeCallback'] = callback;
	OrganisationTreeWindow.focus();
}

	function openWindow(theURL,winName,features) {
	 var popupWindow = window.open(theURL,winName,features);
  	popupWindow.focus();
	}

	function openWindowModal(theURL,winName,features) {
		if (window.showModalDialog) {
	 	  // MyWindow = window.showModalDialog(theURL,"", features);
	        MyWindow = window.open(theURL, winName, features);
	        MyWindow.focus();
	        MyWindow.moveTo(100,100);
	    } else {
	        MyWindow = window.open(theURL, winName, "modal=yes,"+ features);
	        MyWindow.focus();
	        MyWindow.moveTo(100,100);
	    }
	}


	function doOpenSelectionList(selectionListID, fieldName) {
    openURL = 'PopupSelection.jsp?selectionListID=' + selectionListID + '&formName=actionForm&fieldName=' + fieldName;
		popupWindow = openWindowModal(openURL,'ecadia','width=300,height=500,left=200,top=200,scrollbars=yes');
	}


	function setAction(action) {
    top.document.actionForm.action.value = action;
	}

	function doAction(action) {
    setAction(action);
    top.document.actionForm.submit();
	}

	function doActionConfirm(action, message) {
  	if(!confirm(message + '?')) {
    	return;
    }

    doAction(action)
	}

/**
 * Scripte für HTMLSessionTimeOutCtrl
 * 
 * @author GT, 081207
 */
	var sessionDurationInSeconds = 0;
	var startOfRequest = new Date().getTime();
	var sessionDurationText = "";
	var sessionDurationAlertText = "Session expired!";
	
	function ShowSessionDuration() {
		var sDuration = "-";
		
		var nowTime = new Date().getTime();
		var lastingSeconds = sessionDurationInSeconds - ((nowTime - startOfRequest) / 1000);
		var seconds = Math.round(lastingSeconds);
		var restSeconds = seconds % 60;
		var minutes = Math.abs(Math.round((seconds - 30) / 60));
		var showSeconds = "" + ((restSeconds > 9) ? restSeconds : "0" + restSeconds);
		var showMinutes = "" + ((minutes > 9) ? minutes : "0" + minutes);
		
		sDuration = showMinutes + ":" + showSeconds;
		
		var htmlTag = document.getElementById("SessionDuration");
		if(htmlTag != null) {
			htmlTag.innerHTML = sessionDurationText + sDuration;
		}
		
		if(lastingSeconds <= 0) {
			alert(sessionDurationAlertText);
		} else {
			window.setTimeout("ShowSessionDuration()", 1000);
		}
	}

/**
 * HTMLTable-Unterstützung
 */

function checkAll(elmnt) {    
	var o = document.forms['actionForm'].elements;
	if (o){
	var i = 0;
	for (i=0; i<o.length; i++){
	if (elmnt != ''){
	if ((o[i].type == 'checkbox')&&(o[i].name.indexOf(elmnt+"") != -1)){
	o[i].checked = !o[i].checked;
	}
	}
	else {
	if (o[i].type == 'checkbox'){
	o[i].checked = !o[i].checked;
	}
	}
	}
	}
	}
	
function resetAll(elmnt) {    
	var o = document.forms['actionForm'].elements;
	if (o){
		var i = 0;
	for (i=0; i<o.length; i++){
	if (elmnt != ''){
	if ((o[i].type == 'checkbox')&&(o[i].name.indexOf(elmnt+"") != -1)){
	o[i].checked = false;
	}
	}
	else {
	if (o[i].type == 'checkbox'){
	o[i].checked = false;
	}
	}
	}
	}
	}
	
	function selectRow(checkBoxItem, selectState) {
	dom = (document.getElementById && document.documentElement && document.createElement && document.getElementsByTagName) ? 1 : 0;
	mozi=0; 
	if (this.dom) { this.mozi =(typeof(document.documentElement.style.MozBinding)=='string') ? 1 : 0; }
	if (dom||mozi) {
	checkBoxItemParent = checkBoxItem;
	while(checkBoxItemParent.tagName != 'TR' && checkBoxItemParent.parentNode) { checkBoxItemParent = checkBoxItemParent.parentNode; }
	if (checkBoxItemParent.className) {
	if (checkBoxItemParent.className!='') {
	row = (checkBoxItemParent.className.indexOf('1') != -1) ? 'tableRow2' :' tableRow1';
	sel = (selectState) ? 'Selected' : '';
	checkBoxItemParent.className = row + sel;
	}
	}
	}
	}
	
	function onSubmitAction(sel) {
	var selectedValue = sel.options[sel.selectedIndex].value;
	var selectedText = sel.options[sel.selectedIndex].text;
	var tmpMsg = "Soll die Aktion %s ausgeführt werden?"; // Achtung, das muss
															// noch übersetzt
															// werden
	var msg = tmpMsg.replace(/%s/, selectedText);
	if(confirm(msg)) {
	this.document.getElementsByName(selectedValue)[0].value = 1;
	this.document.actionForm.submit();
	}
	}

	
