// JavaScript Document

function fnOpenNewWindow(oLink) {
	oWin = window.open(oLink.href);
	if( oWin ){
		oWin.focus();
		return false;
	} else {
		return true;
	}
}



/////////// MAIN /////////////////
function sbSetup(){
	sbStyleAbbrForIE();
}

function blurLink(oElement){}

function fnOpenNewWindow(oLink) {
	oWin = window.open(oLink.href);
	if( oWin ){
		oWin.focus();
		return false;
	} else {
		return true;
	}
}


function ffnValidateLogin(oForm, iLangId){
	asMsg  = new Array();
	asText = new Array();
	asText[0] = "Bitte geben Sie \n- Ihren Benutzernamen und \n- Ihr Passwort ein.";
	asText[1] = "Bitte geben Sie \n- Ihren Benutzernamen ein.";
	asText[2] = "Bitte geben Sie \n- Ihr Passwort ein.";
	asMsg[0] = asText;
	
	if( oForm.inputUser.value.length == 0 && oForm.inputPass.value.length == 0 ){
		alert(asMsg[iLangId][0]);
		return false;
	} else if( oForm.inputUser.value.length == 0 && oForm.inputPass.value.length > 0 ){
		alert(asMsg[iLangId][1]);
		return false;
	} else if( oForm.inputUser.value.length > 0 && oForm.inputPass.value.length == 0 ){
		alert(asMsg[iLangId][2]);
		return false;
	}
	return true;
}

function sbStyleAbbrForIE() {
	var sBodyTextOld, sBodyTextNew, sRegEx;
	var fIsIE = (document.all) ? true:false;
	
	if( fIsIE ){
		sBodyTextOld = document.body.innerHTML;
		sRegEx = /<abbr([^>]*)>([^<]*)<\/abbr>/gi;
		sBodyTextNew = sBodyTextOld.replace(sRegEx, '<abbr $1><span class=\"abbr\" $1>$2</span></abbr>');
		document.body.innerHTML = sBodyTextNew;
	}
}



































































function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

/*
	Markiert ein Feld wenn es den Focus hat.
	*/
function markInput(formElement, status) {
	var MARK_ON  = "#F9F3A8";
	var MARK_OFF = "#FFFFFF";
	var MARK_ERR = "#FF6347";
	
	if( status == 1 ){
		formElement.style.backgroundColor = MARK_ON;
	} else if( status == 0 ){
		formElement.style.backgroundColor = MARK_OFF;
	} else if( status == -1 ){
		formElement.style.backgroundColor = MARK_ERR;
	} 
}


/***********************************************************
	Cookie Routines
************************************************************/
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function fnSetCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function sfnGetCookie(name){
   var i=0;  //Suchposition im Cookie
   var suche = name+"=";
   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 unescape(cook);
      }
      i++;
   }
   return null;
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function sbDeleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function vfnFixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0){
	  date.setTime(date.getTime() - skew);
	}
	return date;
}
/***********************************************************
	/Cookie Routines
************************************************************/


g_sLastInputId = "";
g_sLastTabButtonId = "";

function fnFormidable_Setup(){
	var sTabButtonId = "application.button-bar.btn-fragment-1";										// Default.
	if( sfnGetCookie('eoa-app-tab') ){																						// Tab-Nr. aus Cookie.
		sTabButtonId = "application.button-bar.btn-fragment-" + sfnGetCookie('eoa-app-tab');
	}
	//alert(sTabButtonId);
	fnFormidable_SetTabButton(sTabButtonId);
}

function fnFormidable_FocusMissingInput(sInputId, sTabButtonId){
	// Neues Input-Element.
	if( document.getElementById(sInputId) ){
		if( g_sLastInputId > "" ){
			document.getElementById(g_sLastInputId).className = "formidableInpFalseDataBlur";
		}
		
		document.getElementById(sTabButtonId).click();															// Tab per Button auslösen.
		
		document.getElementById(sInputId).className = "formidableInpFalseDataFocus";					// Feld markieren.
		document.getElementById(sInputId).focus();																	// Cursor in Feld setzen.
		
		g_sLastInputId = sInputId;																									// Letzte ID merken.
		
		if( document.getElementById(g_sLastTabButtonId) ){
			document.getElementById(g_sLastTabButtonId).className = "formidableTabButtonDefault";
		}
		fnFormidable_SetTabButton(sTabButtonId);
		g_sLastTabButtonId = sTabButtonId;
	}
}


function fnFormidable_SetTabButton(sTabButtonId){
	if( document.getElementById(sTabButtonId) ){
		if( document.getElementById(g_sLastTabButtonId) ){
			document.getElementById(g_sLastTabButtonId).className = "formidableTabButtonDefault";
		}
		document.getElementById(sTabButtonId).className = "formidableTabButtonActive";
		g_sLastTabButtonId = sTabButtonId;																					// Letzte ID merken.
	}
}


