// OnFocus: remove points(thousand);
var hintLenShown = new Array();

/*
	Validate percentage inputfields
*/
function validatePercent(oToValidate){
	sToValidate=oToValidate.value;
	if(sToValidate=="-")return;
	sToValidate=sToValidate.replace(/,/,".");
	sToValidate=trimStr(sToValidate);
	if((!isFinite(sToValidate)) || (parseFloat(sToValidate)>100)){
		alert("ung\u00fcltiger Prozentwert");
		oToValidate.value="";
		oToValidate.focus();
		}
	}
	
/*
	Validate numeric inputfields
*/
function validateNumeric(oToValidate){
	sToValidate=oToValidate.value;
	sToValidate=sToValidate.replace(/,/,".");
	sToValidate=trimStr(sToValidate);
	if((!isFinite(sToValidate))){
		alert("ung\u00fcltiger Wert");
		oToValidate.value="";
		oToValidate.focus();
		}
	}
	
/*
	Validate money inputfields
*/
function validateMoney(oToValidate){
	sToValidate=oToValidate.value;
	sToValidate=sToValidate.replace(/,/,".");
	sToValidate=trimStr(sToValidate);
	if((!isFinite(sToValidate)) || (parseFloat(sToValidate)<0)){
		alert("ung\u00fcltiger W\u00e4hrungswert");
		oToValidate.value="";
		oToValidate.focus();
		}
	}
	
/*
	Validate Integer inputfields
*/
function validateInt(oToValidate){
	var sNew = oToValidate.value
	sNew=sNew.replace(/\./,",");
	if(sNew=="-")return;
	if(sNew != ""){
		if(isNaN(sNew)){
			oToValidate.value = "";
			alert("Nur ganze Zahlen erlaubt!");
			}
	}
}

/*
	Validate Integer inputfields
*/
function validateIntMax(oToValidate, iMaxValue){
	var sNew = oToValidate.value
	sNew=sNew.replace(/\./,",");
	if(sNew != ""){
		if(isNaN(sNew)){
			oToValidate.value = iMaxValue;
		}
		else
		{
			if(parseInt(sNew)>iMaxValue){
				oToValidate.value = iMaxValue;
				alert("ung\u00fcltige Eingabe!");
			}
			else {oToValidate.value=parseInt(sNew);}
		}
	}
}

/*
	Validate Integer inputfields
*/
function validateIntMinMax(oToValidate,iMinValue, iMaxValue, replaceValue){
	var sNew = oToValidate.value
	sNew=sNew.replace(/\./,",");
	if(sNew != "")
	{
		if(isNaN(sNew))
		{
			oToValidate.value = replaceValue;
		}
		else
		{
			if(parseInt(sNew)>iMaxValue || parseInt(sNew)<iMinValue){
				oToValidate.value = replaceValue;
				alert("ung\u00fcltige Eingabe!");
			}
			else {oToValidate.value=parseInt(sNew);}
		}
	}
	else
	{
		oToValidate.value = replaceValue;
	}
}
	
/*
	Formats percentage inputfields
*/
function formatPercent(oToFormat){
	var sF=oToFormat.value;
	sF=sF.replace(/,/,".");
	sF=trimStr(sF);
	if(isNaN(sF) || sF=="" || sF=="-"){
		oToFormat.value = "";
	}else{
		sF=parseFloat(sF).toFixed(2);
		sF=sF.replace(/\./,",");
		oToFormat.value=sF;
	}
}

/*
	Formats Numeric inputfields
*/
function formatNumeric(oToFormat, iNachkomma){
	var sF=oToFormat.value;
	sF=sF.replace(/,/,".");
	sF=trimStr(sF);
	if(isNaN(sF) || sF==""){
		oToFormat.value = "";
	}else{
		sF=parseFloat(sF).toFixed(iNachkomma);
		sF=sF.replace(/\./,",");
		oToFormat.value=sF;
	}
}

/*
	Formats money inputfields
*/
function formatMoney(oToFormat){
	var sF=oToFormat.value;
	sF=sF.replace(/,/,".");
	sF=trimStr(sF);
	if(isNaN(sF) || sF==""){
		oToFormat.value = "";
	}else{
		sF=parseFloat(sF).toFixed(2);
		sF=sF.replace(/\./,",");
		sF=sepThousand(sF);
		oToFormat.value=sF;
	}
}

/*
	will be called onFocus
*/
function removePointsThousand(sIn){
	
	return sIn;
}

function sepThousand(sIn){

	return sIn;
	}


function onKeyDownRemovePoints(oInput){
	sVal=oInput.value;
	if(sVal.charCodeAt(sVal.length-1)==46){
		sVal=sVal.substr(0,sVal.length-1);
		oInput.value=sVal;
	}
}


/*
	removes blanks from string
*/
function trimStr(Str){
		var arg=[];
		var sub;
		for(i=0;i<Str.length;i++){
			sub=Str.substr(i,1);
			if(sub!=" "){arg.push(sub);	}
		}
		newStr=arg.join("")
		return newStr;
}

function validateDate(oToValidate){
	// regExp
	var datum = /\b(0?[1-9]|[12][0-9]|3[01])\.(0?[1-9]|1[0-2])\.(\d\d\d\d|\d\d)\b/
	var sD = oToValidate.value;
	if(datum.test(sD)==false){
			alert("Ung\u00fcltiges Datum!");
			oToValidate.value="";
			oToValidate.focus();
		}
	}

function validateDateAusgaben(oToValidate){
	// regExp
	var datum = /\b(0?[1-9]|[12][0-9]|3[01])\.(0?[1-9]|1[0-2])\.(\d\d\d\d|\d\d)\b/
	var sD = oToValidate.value;
	if(sD!="" && datum.test(sD)==false){
			alert("Ung\u00fcltiges Datum!");
			oToValidate.value="";
			oToValidate.focus();
		}
	}
function validateDateAusgabenRequired(oToValidate){
	// regExp
	var datum = /\b(0?[1-9]|[12][0-9]|3[01])\.(0?[1-9]|1[0-2])\.(\d\d\d\d|\d\d)\b/
	var sD = oToValidate.value;
	if(datum.test(sD)==false){
		if(sD==""){
			alert("Bitte Datum eingeben!")}
		else{
			alert("Ung\u00fcltiges Datum!");}
		oToValidate.value="";
		oToValidate.focus();
	}
}

/*
	replaces '<' and '>'
*/
function stripTags(sToStrip){
	while(sToStrip.indexOf("<")!=(-1) || sToStrip.indexOf(">")!=(-1)){ 
		sToStrip=sToStrip.replace(/</,"&lt;");
		sToStrip=sToStrip.replace(/>/,"&gt;");
	}
	return sToStrip;
}


/*
	Ersetzt jedes Vorkommen von sToRemove in sToClean
	mit sReplace(optional)
	benötigt: rebuildStr(aStr, strToAdd)
*/
function cleanStringFrom(sToClean, sToRemove, sReplace ){
	if(!sToClean || !sToRemove)return "";
	if(!sReplace) sReplace = "";
	if(sToClean.indexOf(sToRemove)!=(-1)){
		var split = sToClean.split(sToRemove);
		sToClean = rebuildStr(split, sReplace)
	}
	return sToClean;
}

function rebuildStr(aStr, strToAdd){
	var sRet = aStr[0];
	for(i=1; i<aStr.length; i++){
		sRet += strToAdd;
		sRet += aStr[i]}
	return sRet;
}

function checkLengthTextarea(oTA,iMaxLen){
	if(iMaxLen>0 && oTA.value.length>iMaxLen){
		oTA.value=oTA.value.substring(0,iMaxLen);
		if(hintLenShown[oTA.id]!=true){
			alert("Eingbe zu lang!\nDie maximale Eingabel\u00e4nge ist auf " +iMaxLen+ " Zeichen beschr\u00e4nkt!");
			hintLenShown[oTA.id]=true;
		}
		oTA.focus();
	}
}

function drucken(){
   if (window.print){
      window.print();
      }
   else{
      window.alert("Leider nicht möglich!")
      }
}

function showHelpWindow(sURL){
	var F1 = window.open("../hilfe/"+sURL,"Hilfe","width=540,height=350,left=0,top=0,scrollbars=yes");
}

function setTopBanner(sImg,sUrl){
	if(sImg!=""){
	sMain = location.href;
	parent.frames["topFrame"].setBanner(sUrl,sImg,sMain);
	}
}

function setTopMessage(sMessage){
	parent.frames['topFrame'].setLable(sMessage);
}

function BannerChange()
{
	setTopBanner(BannerImg[BannerIndex],BannerURL[BannerIndex]);
	BannerIndex++;
	if(BannerIndex==BannerImg.length) {BannerIndex=0;}
	clearTimeout(BannerChanger);
	BannerChanger = setTimeout("BannerChange()",BannerTime);
}

function InitBannerChange()
{
	setTopBanner("images/blank.gif","");

// ZUNÄCHST KEINE BANNER IN 2008
//	BannerChanger = setTimeout("BannerChange()",BannerTime);
//	// do not alway use the same first
//	BannerIndex = Math.round(Math.random()*(BannerImg.length-1));
//	BannerChange();
}
////var BannerIndex = 0;
//var BannerTime = 5000;
//var BannerImg = new Array("top/banner-2.gif","top/bhb-4.gif","top/BANNER-bit.jpg");
//var BannerURL = new Array("http://seminare..de","http://www..de/bhb/","http://www.bitworks.net");


function oeffneFenster(url, name ,params)
{
	Fenster = null;
	Fenster = window.open(url,name,params);
	Fenster.focus();
	return Fenster;
}

// Nur für Fachgruppenfenster
function SetOpenerUrl(url)
{
	top.opener.location.href=url;
}

/*
Call on keyup
*/
function FormatDateGerman(DateField)
{
   DateValue = DateField.value;
   if (DateValue.length == 2 || DateValue.length == 4) 
   {
		DateField.value = DateValue + ".";
   }

}

/*
validates Date Input field
(Format dd.mm.yyyy or dd/mm/yyyy)

field = Input field (the text box)
seperator = date seperator (. or /)
sInvalidFormatMessage 
sErrMessage = error message
bRequired = is value required? (true/false)
*/
function check_date(field, seperator, sInvalidFormatMessage, sErrMessage, bRequired){
var checkstr = "0123456789./";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
var seperators = "./";	//allowed seperators
var mySeperator;		// used seperator

//var seperator = ".";
   err = 0;
   DateValue = DateField.value;
   /* Empty field is OK */
   if (!bRequired && DateValue.length == 0) return;
   /* Delete all chars except 0..9 and seperator*/
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }

   }
   /* Just one seperator is allowed */
   var seperatorCount = 0;
   for (i = 0; i < seperators.length; i++) {
	  if (DateValue.indexOf(seperators.substr(i,1)) >= 0) {
	     seperatorCount++;
	     mySeperator = seperators.substr(i,1);
	  }
   }
   alert(seperatorCount + ", used: " + mySeperator);
   if(seperatorCount != 1)
   {
      alert(sInvalidFormatMessage);
      DateField.value = "";
      DateField.select();
	  DateField.focus();
	  return;
   }
   
   if(!seperator){
      seperator = mySeperator;}

   
   // DateTemp is clean string now
   DateValue = DateTemp;
   var dateparts = DateValue.split(mySeperator);
   if(dateparts.length != 3 || (dateparts[2].length!=2 && dateparts[2].length!=4) || dateparts[0].length>2 || dateparts[1].length>2 || dateparts[0].length<1 || dateparts[1].length<1)
   {
      alert(sInvalidFormatMessage);
      DateField.value = "";
      DateField.select();
	  DateField.focus();
	  return;
	}
	
	day = parseInt(dateparts[0]);
	month = parseInt(dateparts[1]);
	if(dateparts[2].length==2) dateparts[2]= "20" + dateparts[2];
	year = parseInt(dateparts[2]);

   /* year is wrong if year = 0000 */
   alert("Y " + year);
   if (year == 0 || year>2100) {
      err = 20;
   }
   /* Validation of month*/
   //month = parseInt(DateValue.substr(2,2));
   alert("M " + month);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   alert("D " + day);
   if ("D " + day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
      //alert("set null");
   }
   //alert("Err: " + err);
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      //alert("Date is incorrect!");
      alert(sErrMessage);
      DateField.value = "";
      DateField.select();
	  DateField.focus();
   }
}
//  End -->



