
//================================================================
/** Ermittelt die Value eines Radio-Feldes */

function getRadioWert(rObj)
{
    if(rObj.length != undefined)
    {
    	for (var i=0; i<rObj.length; i++) 
    		if (rObj[i].checked) 
    			return rObj[i].value;
    	}
    else if(rObj.checked)
    	return rObj.value;
    
    return "";
}

/** oeffnet ein Popup-Fesnter */

function popup(strUrl, strName, nWidth, nHeight, strFeature)
{    
    // Korrekturfaktor Fensterraender
    dX = 5;
    dY = 30;

    if (-1 == nWidth)
       nWidth = screen.availWidth;

    if (-1 == nHeight)
       nHeight = screen.availHeight;

    if ("" != strFeature)
       strFeature += ", ";
	
    strFeature += "width=" + nWidth + ",height=" + nHeight;	
    var wnd = window.open(strUrl, strName, strFeature);
    
    wnd.moveTo( ((screen.availWidth - nWidth) / 2) - dX, ((screen.availHeight - nHeight) / 2) - dY );
    //if (arguments.length == 6)
    //   wnd.scrollbars.visible = arguments[5];


    wnd.focus();
}

/** Prueft ob das Datum korrekt ist, FormatMode ist optional */

function isDate(sDatum,FormatMode)
{
   if (FormatMode!=0) {FormatMode=1}
   if (sDatum.indexOf(".")==-1) {return false};
   var ArrayDate = sDatum.split(".");
   if ((ArrayDate.length!=3) || (isNaN(ArrayDate[0])) || (ArrayDate[0]=="") || (isNaN(ArrayDate[1])) || (ArrayDate[1]=="") || (isNaN(ArrayDate[2])) || (ArrayDate[2]=="")) {return false};
   var daysInMonth = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
   if ((parseInt(ArrayDate[1 - FormatMode],10)<1) || (parseInt(ArrayDate[1 - FormatMode],10)>daysInMonth[parseInt(ArrayDate[0 + FormatMode],10)])) {return false};
   if ((parseInt(ArrayDate[0 + FormatMode],10)==2) && (parseInt(ArrayDate[1 - FormatMode],10)>GetDaysInFebruary(parseInt(ArrayDate[2],10)))) {return false};
   if ((parseInt(ArrayDate[0 + FormatMode],10)<1) || (parseInt(ArrayDate[0 + FormatMode],10)>12)) {return false};
   //Jahreszahl muss > 1900 sein:
   if (parseInt(ArrayDate[2], 10) < 1900) {return false};
   return true;
}
/** Prueft ob die Uhrzeit korrekt ist, FormatMode ist optional */

function isTime(sZeit)
{   
   //Format HH:mm
   if (sZeit.indexOf(":")==-1) {return false};
   var ArrayDate = sZeit.split(":");
   if ((ArrayDate.length!=2) || (isNaN(ArrayDate[0])) || (ArrayDate[0]=="") || (isNaN(ArrayDate[1])) || (ArrayDate[1]=="")) {return false};   
   if ((parseInt(ArrayDate[0], 10)<0) || (parseInt(ArrayDate[0],10)>23)) {return false};
   if ((parseInt(ArrayDate[1], 10)<0) || (parseInt(ArrayDate[1],10)>59)) {return false};  
   return true;
}

// onBlur: prüfen, ob String eine gültige Uhrzeit ist [hH:MM]
function checkTime(input)
{	
	var posi=-1;
	strTime = input.value;
 	if (strTime=="") {return true;}

 	if (strTime.indexOf(".") == -1) { // kein Punkt eingegeben!!!
	 	// Position der Punkte herausfinden
	 	posi = strTime.indexOf(":")

	 	if ((posi==1) || (posi==2)) {
	 		// Teilstrings in Zahlen konvertieren
 			nHH = strTime.slice(0, posi) - 0;
 		nMM = strTime.slice(posi + 1, strTime.length) - 0;

 		if ((posi+1)==strTime.length) { // Doppelpunkt ohne was dahinter -> umformen
 			input.value=strTime+"00"
 			return true;
 		}

 		if ((nHH < 24) && (nMM < 60)) {return true;}
 	}
 	if (posi==-1 && input.value < 24) { // Zahl ohne Doppelpunkt -> umformen
 		input.value=strTime+":00"
 		return true;
	 }
 }
 alert('Falsches Uhrzeitformat! (Beispiel: "9:30")');
 input.value="";
 input.focus();
 return false;
}
//================================================================
/** Liefert die Anzahl der Tage im Februar */
function GetDaysInFebruary(year) {return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 )}

//================================================================
/** Selektiert aus einer Radiogroup den angegebenen Value */
function selectRadioByValue(radio, value)
{
   i = 0;
   while(i < radio.length)
   {
     if(radio[i].value == value)
      {
         radio[i].checked = true;
         return true;
      }
      i++;
   }
   return false;
}

//================================================================
/** gibt den selektierten value einer Radiogroup zur?ck */
function getselectedValuebyRadio(radio)
{
   i = 0;
   while(i < radio.length)
  {
      if(radio[i].checked == true)
      {
         return radio[i].value;
      }
      
      i++;
   }
   return "";
}


//================================================================
/** Selektiert aus einer ComboBox den angegebenen Value */
function selectCboByValue(cbo, value)
{
   i = 0;
   while(i < cbo.options.length)
   {
      if(cbo.options[i].value == value)
      {
         cbo.options[i].selected = true;
         return true;
      }
      i++;
   }
   return false;
}
//================================================================
/** Selektiert aus einer ComboBox den angegebenen Value */
function selectCboByText(cbo, txt)
{
   i = 0;
   while(i < cbo.options.length)
   {
      if(cbo.options[i].text == txt)
      {
         cbo.options[i].selected = true;
         return true;
      }
      i++;
   }
   return false;
}

//================================================================
function checkSonderzeichen( strSonderzeichen, strCheck)
{
  //pr??ft, ob in String strCheck eines der Sonderzeichen aus strSonderzeichen vorkommt:
  var b = true;
  var i = 0;
  while(i<strCheck.length) {
     var c = strCheck.charAt(i);
     if(strSonderzeichen.indexOf(c) != -1) {
       b = false;
     }
     i++;
  }
  return b;
}
//================================================================
function isEMail(str) // by [SD]
{  
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
 }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(str));
 }
 else
 {
  res = (str.search('@') >= 1 &&
         str.lastIndexOf('.') > str.search('@') &&
         str.lastIndexOf('.') >= str.length-5)
 }
 return(res);
}
//================================================================
function isTelefonNr(str) // by [SD]
{
 
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
 }
 if(a == true)
 {
  reg = new RegExp('^[0-9]+\\s?[-/]?\\s?[0-9]+$');
  res = (reg.test(str));
 }
 else
 {   
   res = true;
 }
 return(res);
}
//================================================================
function isNumeric(str) // by [SD]
{
  var str2 = str.replace(/^\s*|\s*$/g,"");
  if(str2.length == 0) return false;
  str = str.replace(",",".");
  return (Number(str)==str);
}
//================================================================
function isTooShort(str,minimum) // by [SD]
{
  return (str.length<minimum);
}
//================================================================
function NumandCharOnly(e)
{
	if(!e) e=window.event;
  
  	var iKeyCode;
    if (!document.all) {
        iKeyCode = e.which;
    } else {
        iKeyCode = e.keyCode;
    }
  	// nur Steuerzeichen und Zahlen zulassen
  	if ( iKeyCode == 8                                     // BackSpace
      ||   iKeyCode == 9                                     // TAB
      ||   iKeyCode == 13                                    // ENTER
      ||   iKeyCode == 37                                    // Left
      ||   iKeyCode == 39                                    // Right
      ||   iKeyCode == 46                                    // Entf
      ||   iKeyCode == 109                                    // Num -
      ||   iKeyCode == 189                                   // -
      || ( iKeyCode > 47 && iKeyCode < 58 )      // 0..9 Tastatur
      || ( iKeyCode > 64 && iKeyCode < 91 )      // Buchstaben
      || ( iKeyCode > 95 && iKeyCode < 106 ) )   // 0..9 NumBlock
  	{
     	// auch die nicht zulassen, wenn mit shift, alt, ctrl
     	if ( !iKeyCode.shiftKey && !iKeyCode.altKey && !iKeyCode.ctrlKey ) 
     	{
        	return true;
       	}
    }
  	return false;   // eingabe ignorieren
}
//================================================================
function NumOnly(a_oEvent)
{
//geht nur in IE fuer alles siehe unten (auch FireFox)

    var iKeyCode;
    if (!document.all) {
        iKeyCode = a_oEvent.which;
        //Extra Prüfung weil Tab nur im KeyCode mitkommt
        if(iKeyCode == 0)
        	iKeyCode = a_oEvent.keyCode;
    } else {
        iKeyCode = a_oEvent.keyCode;
    }

    if ( iKeyCode == 8                                     // BackSpace
    ||   iKeyCode == 9                                     // TAB
    ||   iKeyCode == 13                                    // ENTER
    //||   iKeyCode == 37                                    // Left
    //||   iKeyCode == 39                                    // Right
    //||   iKeyCode == 46                                    // Entf
    || ( iKeyCode > 47 && iKeyCode < 58 )      // 0..9 Tastatur
    //|| ( iKeyCode > 95 && iKeyCode < 106 )    // 0..9 NumBlock
    )
    {
       // auch die nicht zulassen, wenn mit shift, alt, ctrl
       if ( !iKeyCode.shiftKey && !iKeyCode.altKey && !iKeyCode.ctrlKey ) {
         return true;
       }
    }
    else  return false;
}
//================================================================
function CurrencyOnly(a_oEvent)
{
//geht nur in IE fuer alles siehe unten (auch FireFox)

    var iKeyCode;
    if (!document.all) {
        iKeyCode = a_oEvent.which;
    } else {
        iKeyCode = a_oEvent.keyCode;
    }
	//alert(iKeyCode);
    if ( iKeyCode == 8                                     // BackSpace
    ||   iKeyCode == 9                                     // TAB
    ||   iKeyCode == 13                                    // ENTER
    //||   iKeyCode == 37                                    // Left
    //||   iKeyCode == 39                                    // Right
    || 	 iKeyCode == 44										//,
    ||   iKeyCode == 46                                    	//.
    || ( iKeyCode > 47 && iKeyCode < 58 )      // 0..9 Tastatur
    //|| ( iKeyCode > 95 && iKeyCode < 106 )    // 0..9 NumBlock
    
    )
    {
       // auch die nicht zulassen, wenn mit shift, alt, ctrl
       if ( !iKeyCode.shiftKey && !iKeyCode.altKey && !iKeyCode.ctrlKey ) {
         return true;
       }
    }
    else  return false;
}
//================================================================
function NoEnter(a_oEvent)
{
    var iKeyCode;
    if (!document.all) {
        iKeyCode = a_oEvent.which;
        //Extra Prüfung weil Tab nur im KeyCode mitkommt
        if(iKeyCode == 0)
        	iKeyCode = a_oEvent.keyCode;
    } else {
        iKeyCode = a_oEvent.keyCode;
    }

    if ( iKeyCode == 9                                     // TAB
    ||   iKeyCode == 13                                    // ENTER    
    )
    {
       // auch die nicht zulassen, wenn mit shift, alt, ctrl       
         return false;
    }
    else  return true;
}
//================================================================
function Trim(TRIM_VALUE)
{
  //alert("begin trim");
  if(TRIM_VALUE.length < 1) {
    //alert("value zu kurz");
    return"";
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE==""){
    return "";
  }
  else{
    return TRIM_VALUE;
  }
}
//================================================================
function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0){
    return"";
  }
  var iTemp = v_length -1;

  while(iTemp > -1){
    if(VALUE.charAt(iTemp) == w_space){}
    else{
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  } //End While

  return strTemp;

} //End Function
//================================================================
function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1){
    return"";
  }
  var v_length = VALUE.length;
  var strTemp = "";

  var iTemp = 0;

  while(iTemp < v_length){
    if(VALUE.charAt(iTemp) == w_space){}
    else{
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } //End While

  return strTemp;
} //End Function
//******************************************************************************
function TelefonOnly(a_oEvent)
{
  var iKeyCode;
  if (!document.all)
  {
      iKeyCode = a_oEvent.which;
      //Extra Prüfung weil Tab nur im KeyCode mitkommt
      if(iKeyCode == 0)
        	iKeyCode = a_oEvent.keyCode;
  }
  else iKeyCode = a_oEvent.keyCode;
  //alert(window.event.keyCode);
  // nur Steuerzeichen und Zahlen zulassen
  if ( iKeyCode == 8                                     // BackSpace
      ||   iKeyCode == 9                                     // TAB
      //||   iKeyCode == 45                                    // -
      ||   iKeyCode == 47                                    // /
      ||   iKeyCode == 40                                    // (
      ||   iKeyCode == 41                                    // )
      //||   iKeyCode == 43                                    // +
      ||   iKeyCode == 13                                    // ENTER
      ||   iKeyCode == 37                                    // Left
      ||   iKeyCode == 39                                    // Right
      ||   iKeyCode == 46                                    // Entf
      || ( iKeyCode > 47 && iKeyCode < 58 )      // 0..9 Tastatur
      //|| ( iKeyCode > 95 && iKeyCode < 106 )    // 0..9 NumBlock
      )
  {
     // auch die nicht zulassen, wenn mit shift, alt, ctrl
     if ( !a_oEvent.shiftKey && !a_oEvent.altKey && !a_oEvent.ctrlKey || iKeyCode == 47
          || iKeyCode == 40 || iKeyCode == 41)
          return true;
  }

  return false;   // eingabe ignorieren
}
//******************************************************************************
function maxLength(obj, maxLength, a_oEvent)
{	
	// Allow user to type character if at least one character is selected
	var iKeyCode;	
    if (!document.all) {
        iKeyCode = a_oEvent.which;
    } else {
        iKeyCode = a_oEvent.keyCode;
    }
    if ( iKeyCode != 8 && iKeyCode != 46 )
    {
		if(obj.value.length > maxLength-1)
			return false;	
	}
	return true;	
}

//******************************************************************************

