/*****************************************************
  Initialize function
  Browser Detection
  Language: German locale
*****************************************************/
  NS4      = (document.layers) ? true:false;
  IE4      = (document.all) ? true:false;
  W3C      = (document.documentElement && !document.all) ? true:false;
  MAXINT   = Math.pow(2,31);
  MAXFLOAT = Math.pow(2,63);

/*****************************************************
  Initialize function
  Event capturing for Netscape
*****************************************************/
  if (NS4) {
    document.captureEvents(Event.KEYPRESS);
    document.onkeypress = processKey;
  }
  if (W3C) {
    document.addEventListener("keypress",processKey,true);
  }

  //------------------------------------------------
  function SwitchMLControl(p_oSelect,p_strField,p_lLCID) {
  //------------------------------------------------
    for(i=0;i < p_oSelect.options.length;i++) {
      document.getElementById('ML' + p_strField + '_' + p_oSelect.options[i].value).style.display = 'none';
    }
    document.getElementById('ML' + p_strField + '_' + p_lLCID).style.display = 'block';
  }

  //------------------------------------------------
  function swapimg(oImg, sSearchFor, sReplace, sCursorStyle) {
  //------------------------------------------------
    var strSrc = oImg.src.toLowerCase();
    var a=sSearchFor.toLowerCase();
    var b=sReplace.toLowerCase();
    var sC=sCursorStyle.toLowerCase();
    if (sC!='pointer' && sC!='hand')
      sC='pointer';
    if (IE4 )
      if (sC=='pointer')
        sC='hand';
    strSrc = strSrc.replace(a,b);
    oImg.src=strSrc;
    oImg.style.cursor = sC;
  }

/*****************************************************
  Function um Fenstergröße zu optimieren
*****************************************************/
  //--------------------------------------------------
  function optimize_WindowSize() {
  //--------------------------------------------------
    if (!IE4)
      return
    var OuterWidth,OuterHeight;
    var sWidth,sHeight;
    var s,w,h,bSpace,rSpace;
    var x=0,y=0,rs;
    var win = self.window;
    var doc = self.document;
    if (optimize_WindowSize.arguments.length>0 && parent.frames.length>0) {
        var Idx = parseInt(arguments[0], 10);
        win = parent.frames[Idx].window;
        doc = parent.frames[Idx].document;
    }
    sWidth=screen.availWidth;
    sHeight=screen.availHeight;
    s=sWidth,w=100,h=100;
    // antesten breite und Höhe
    win.scrollBy(1,0)
    x=doc.body.scrollLeft;
    win.scrollBy(0,1)
    y=doc.body.scrollTop;
    if (x>0 || y>0) {
      win.scrollTo(0,0)
      self.resizeTo(w,h);
      OuterWidth  = w-doc.body.offsetWidth;
      OuterHeight = h-doc.body.offsetHeight;
      win.scrollBy(s,0);
      x=doc.body.scrollLeft;
      rs = parseInt(OuterWidth, 10) + parseInt(doc.body.offsetWidth, 10);
      // Breite anpassen
      if ((rs+x) < sWidth) {
        win.resizeBy(x,0);
      } else {
        win.resizeBy(sWidth-rs,0);
      }
      win.scrollTo(0,0)
      win.scrollBy(0,s);
      y=doc.body.scrollTop;
      rs = parseInt(OuterHeight, 10) + parseInt(doc.body.offsetHeight, 10);
      // Höhe anpassen
      if ((rs+y) < sHeight) {
        self.resizeBy(0,y);
      } else {
        self.resizeBy(0,sHeight-rs);
      }
      win.scrollTo(0,0)
      self.moveTo(0,0)
    }
  }

/*****************************************************
  Function zum anzeigen des DatePickers
*****************************************************/
function GetDatepickerWindow(p_strFieldname,p_strType,p_strPath) {
  var l_lngPopupX;
  var l_lngPopupY;
  if(p_strPath == null )
  {
    p_strPath = "../../../";
  }

  l_lngPopupX = Math.round(screen.width/3);
  l_lngPopupY = Math.round(screen.height/3);
  if (IE4)
    {
    l_lngPopupX = (window.event.screenX+10);
    l_lngPopupY = (window.event.screenY+10);
    }
  var l_objTargetField = eval("window.document.forms[0]." + p_strFieldname);
  var l_strUrl = p_strPath + "_UpInclude/script/UpCalendars/UpCalendarPicker.asp?rq_strFieldname=" + p_strFieldname;
  //var l_strUrl = "../../../_UpInclude/script/UpCalendars/UpCalendarPicker.asp?rq_strFieldname=" + p_strFieldname;
  if (!p_strType)
    {p_strType = "";}
  l_strUrl += "&rq_strType="+p_strType+"&rq_binit=1";
  if (l_objTargetField && l_objTargetField.value!="")
    {
    if (p_strType == "datetime" && l_objTargetField.value.indexOf(' ')>-1)
      {
      l_strDate = l_objTargetField.value.substr(0,l_objTargetField.value.indexOf(' '))
      l_strTime = l_objTargetField.value.substr(l_objTargetField.value.indexOf(' ') + 1)
      }
    else
      {
      l_strDate = l_objTargetField.value;
      l_strTime = "";
      }
    l_strUrl += "&rq_strDate=" + l_strDate;
    l_strUrl += "&rq_strTime=" + l_strTime;
    }
  if (parent && parent.UpAppNav) {
    if (p_strType == "datetime")
      {parent.UpAppNav.wndPrint = window.open(l_strUrl,'wndPrint','width=180, height=192, resizable=NO, help=NO, status=NO, scroll=NO, scrollbars=NO, toolbar=NO, left=' + l_lngPopupX + ', top='+ l_lngPopupY);}
    else
      {parent.UpAppNav.wndPrint = window.open(l_strUrl,'wndPrint','width=180, height=165, resizable=NO, help=NO, status=NO, scroll=NO, scrollbars=NO, toolbar=NO, left=' + l_lngPopupX + ', top='+ l_lngPopupY);}
  }
}

//****************************************
// Initialize function: Detect if we are in an popup or not
// Generating a new Parameter
//****************************************
if(parent.window.name == "UpPopup")
  l_strIsPopup = "&rq_bIsPopup=1";
else
  l_strIsPopup = "";

//****************************************
// Function to decide to Popup or not
//****************************************
  function ButtonAction(p_strLink,p_bNewWindow)
  {
    if(p_bNewWindow && window.name != "UpPopup")
    {
      loadPopup(p_strLink);
    }
    else
    {
      window.document.__UpForm.action= p_strLink;
      if ( typeof g_arrFK != "undefined" ) {
        if ( SubmitHandlerCrossRref() ) {
          document.forms[0].submit();
        }
      } else {
        if ( ValidateFields(window.document.__UpForm) ) {
          document.forms[0].submit();
        }
      }
    }
    return;
  }

//****************************************
// Load popup
//****************************************
function loadPopup(p_strLink)
{

  if(!top.wndPopUp)
  {
    top.wndPopUp = open("../../UpAppGlobal/popupframeset.asp?rq_strUrl=" + HexEncodeString(p_strLink),"UpPopup","resizable=yes,width=380,height=250,screenX=300,screenY=200");
  }
  else
  {
    if (top.wndPopUp.closed)
    {
      top.wndPopUp = open("../../UpAppGlobal/popupframeset.asp?rq_strUrl=" + HexEncodeString(p_strLink),"UpPopup","resizable=yes,width=380,height=250,screenX=300,screenY=200");
      top.wndPopUp.focus();
    }
    else
    {
        top.wndPopUp = open("../../UpAppGlobal/popupframeset.asp?rq_strUrl=" + HexEncodeString(p_strLink),"UpPopup","resizable=yes,width=380,height=250,screenX=300,screenY=200");
      top.wndPopUp.focus();
    }
  }
  if(window.name != "UpPopup")
    ResetTimeout();
  return;
}

function closePopup()
{
  if(!top.wndPopUp)
    return;
  else
  {
    if (top.wndPopUp.closed)
      return;
    else
      top.wndPopUp.close();
    
  }
  return;
}



function PopUpResizeByContent()
/************************************************
DESCRIPTION: ändert die Größe des Popups entsprechend des Inhaltes
*************************************************/
{
  if(parent.window.name != "UpPopup" && window.name != "winConfig")
    return;
  
  var doc = this.document;
  
  if (this.parent)
    var WinToResize = this.parent;
  else
    var WinToResize = this;
    
  var sWidth, sHeight;
  var x = 0, y = 0, w = 0, h = 0, diffWidth = 0, diffHeight = 0, rs;
  sWidth = screen.availWidth;
  sHeight = screen.availHeight;
  w = 100;
  h = 100;
  // antesten Breite und Höhe
  this.scrollBy(1,0)
  x = doc.body.scrollLeft;
  this.scrollBy(0,1)
  y = doc.body.scrollTop;
  // wenn in einer der beiden Richtungen Scrollbalken vorhanden sein sollten -> anpassen
  if (x > 0 || y > 0)
  {
    this.scrollTo(0,0);
    this.resizeTo(w,h);
    // damit haben wir die tatsächliche Grösse des Fensters und können davon jetzt die innere Breite/Höhe subtrahieren
    diffHeight = h - this.document.body.offsetHeight;
    diffWidth = w - this.document.body.offsetWidth;    
    // Breite anpassen
    this.scrollBy(sWidth, 0);
    x  = this.document.body.scrollLeft;
    rs = parseInt(diffWidth) + parseInt(doc.body.offsetWidth);
    if ((rs + x) < sWidth)
    {
      WinToResize.resizeBy(x, 0);
    }
    else
    {
      WinToResize.resizeBy(sWidth-rs, 0);
      
    }
    // Höhe anpassen
    this.scrollTo(0, 0);
    this.scrollBy(0, sHeight);
    y = this.document.body.scrollTop;
    rs = parseInt(diffHeight) + parseInt(doc.body.offsetHeight);
    
    
    if ((rs + y) < sHeight)
    {
      if (W3C)
        WinToResize.resizeBy(0, y + 100);
      else
        WinToResize.resizeBy(0, y);
      
    }
    else
    {
      WinToResize.resizeBy(0, sHeight-rs);
      
    }
    this.scrollTo(0, 0);
    //this.resetPosition();
  }
}

/**************************************************************************
 * put datas in two boxes add left add right ,clear list and set init values 
 ****************************************************************************/
icoleft = new Image();
icoleft.src = "../../../images/assets/icoLeft.gif";
icoleftover = new Image();
icoleftover.src = "../../../images/assets/icoLeftOver.gif";
icoleftclick = new Image();
icoleftclick.src = "../../../images/assets/icoLeftClick.gif";

icoright = new Image();
icoright.src = "../../../images/assets/icoRight.gif";
icorightover = new Image();
icorightover.src = "../../../images/assets/icoRightOver.gif";
icorightclick = new Image();
icorightclick.src = "../../../images/assets/icoRightClick.gif";

function changeImage(Image,ImageSrc)
{
   window.document.images[Image].src = ImageSrc.src;
}

function AddRight(p_strLeft, p_strRight,p_strName)
{
  l_oLeft  = eval( "document.forms[0]" + "." + p_strLeft);
  l_oRight = eval("document.forms[0]" + "." + p_strRight);
  
  l_lFirstSelected = l_oLeft.selectedIndex ;
  if(l_lFirstSelected == -1)
  {
    alert(l_strSelectEntry);
  }
  while(l_oLeft.selectedIndex != -1)
  {
  l_lSelected = l_oLeft.selectedIndex ;
  if(l_lSelected == -1)
    return;
  
  l_optNew = new Option(l_oLeft.options[l_lSelected].text);
  l_oRight.options[l_oRight.length] = l_optNew;
  l_oLeft.options[l_lSelected] = null;
  }
  l_oLeft.selectedIndex = l_lFirstSelected;
  SetValue(l_oRight,p_strName);
  return;
}

function AddLeft(p_strLeft, p_strRight,p_strName)
{
  l_oLeft  = eval( "document.forms[0]" + "." + p_strLeft);
  l_oRight = eval("document.forms[0]" + "." + p_strRight);
  
  l_lFirstSelected = l_oRight.selectedIndex ;
  if(l_lFirstSelected == -1)
  {
    alert(l_strSelectEntry);
  }
  while(l_oRight.selectedIndex != -1)
  {
    l_lSelected = l_oRight.selectedIndex ;
    if(l_lSelected == -1)
      return;
  
    l_optNew = new Option(l_oRight.options[l_lSelected].text);
    l_oLeft.options[l_oLeft.length] = l_optNew;
    l_oRight.options[l_lSelected] = null;
  }
  l_oRight.selectedIndex = l_lFirstSelected;
  SetValue(l_oRight,p_strName);
  return;
}

function ClearList(p_strLeft, p_strRight)
{
  l_oLeft  = eval( "document.forms[0]" + "." + p_strLeft);
  l_oRight = eval("document.forms[0]" + "." + p_strRight);
  l_oLeft.options[0] = null;
  l_oRight.options[0] = null;
  return;
}

function SetValue(p_oRight,p_strName)
{
  l_strOut = '';
  for(i=0;i < p_oRight.options.length;i++)
  {
    if(i==0)
    {
      l_strOut = p_oRight.options[i].text;
    }
    else
    {
      l_strOut += '|'
      l_strOut += p_oRight.options[i].text;
    }
  }
  l_oHidden  = eval( "document.forms[0]" + "." + p_strName);
  l_oHidden.value = l_strOut;
  return true;
}



/*****************************************************
  Function zum Hinzufügen von Einträgen in Listboxen
*****************************************************/
function LoadForeignWindow(p_strPath,p_strForeignField,p_strField,p_strTable,p_strFilter)
{
  if (top.name=="wndInsert")
  {
    alert(l_strFuncNotAvailable);
    return;
  } 
    l_bIsPicker = false;
    l_lPicker   = 0;
    //Check:Picker ?
    if (typeof g_arrFK != 'undefined')
    {
        for (i = 0; i < g_arrFK.length; i++)
    {  
      if(typeof g_arrFK[i] != 'undefined')
      {
        if( g_arrFK[i] == p_strForeignField)
          l_bIsPicker = true;
      }   
    }
    }
    
    if(l_bIsPicker)
        l_lPicker = 1;
    p_strPath = HexEncodeString(p_strPath);
    l_strPath = "../../../_UpInclude/Script/UpInserterFrameset.asp?rq_IsPicker=" + l_lPicker + "&rq_strTarget=" + p_strPath + "&rq_ForeignField=" + p_strForeignField + "&rq_strField=" + p_strField + "&rq_strTable=" + p_strTable + "&rq_strFilter=" + p_strFilter;

  if(!top.wndInsert)
  {
    top.wndInsert = open(l_strPath,"wndInsert","menubar=no,toolbar=no,dependent=yes,resizable=yes,scrollbars=yes,width=600,height=400,left=300,screenX=300,top=200,screenY=200");
  }
  else
  {
    if (top.wndInsert.closed)
    {
      top.wndInsert = open(l_strPath,"wndInsert","menubar=no,toolbar=no,dependent=yes,resizable=yes,scrollbars=yes,width=600,height=400,left=300,screenX=300,top=200,screenY=200");
    }
    else
    {
        top.wndInsert = open(l_strPath,"wndInsert","menubar=no,toolbar=no,dependent=yes,resizable=yes,scrollbars=yes,width=600,height=400,left=300,screenX=300,top=200,screenY=200");
      top.wndInsert.focus();
      
    }
  }
    return;
}

/*****************************************************
  Function zum setzen der Hintergrundfarbe in OnBlur
*****************************************************/
function SetFocusColor(p_obField,p_bFocus) {
  ele_type = p_obField.type;
  if (p_bFocus)
    {
    if (ele_type != "radio" && ele_type != "checkbox" && ele_type != "select-one")
      {
      p_obField.style.backgroundColor = l_strCOLORONFOCUS;
      }
    }
  else
    {
    if (ele_type != "radio" && ele_type != "checkbox" && ele_type != "select-one")
      {
      p_obField.style.backgroundColor = l_strCOLORONBLUR;
      }
    }
  }

/*****************************************************
  Helper: für Control.js -> MakeFloat -> Umwandlung von String in Float unter Berücksichtigung von 
  Dezimaltrennzeichen und TausenderTrennung
  falls eingegebener Wert NaN ist, gibt "0" zurück
*****************************************************/
function MakeFloat(p_strIn,p_strUPtype)
{
  var l_fOut = 0;
    l_fOut = toFloat(p_strIn,p_strUPtype);
    if (isNaN(l_fOut))
    {
      return parseFloat(0);
    } 
    else
    {
      return parseFloat(l_fOut);
    }
}

/*****************************************************
  Umwandlung von String in Float unter Berücksichtigung von
  Dezimaltrennzeichen und TausenderTrennung
  gibt Float oder "NaN" zurück
*****************************************************/
function toFloat(p_strIn,p_strUPtype)
{
    var l_strIn = p_strIn;
    if (p_strUPtype == "UPCurrency")
  {
      var l_strGroupSymbol = g_strMonetaryDecimalGroupingSymbol;
    var l_strDecSymbol = g_strMonetaryDecimalSymbol;
  }
  else
  {
      var l_strGroupSymbol = g_strDecimalGroupingSymbol;
    var l_strDecSymbol = g_strDecimalSymbol;
  }
  // Tausender Trennzeichen rauswerfen
  l_strIn = replaceSubstring(l_strIn,l_strGroupSymbol,"");
  // Dezimalzeichen ist immer "."
  l_strIn = replaceSubstring(l_strIn,l_strDecSymbol,".");
  if(l_strIn=="" || l_strIn=="-")
  {
    l_strIn = 0;
  }
  // in Float
    l_fOut    = parseFloat(l_strIn);
    if(l_fOut > MAXFLOAT)
  {
    l_fOut = "isNaN";
  }
  return l_fOut;
}

/*****************************************************
  Helper: für Control.js -> MakeInteger -> Umwandlung von String in Integer unter Berücksichtigung von 
  TausenderTrennung
  falls eingegebener Wert NaN ist, gibt "0" zurück
*****************************************************/
function MakeInteger(p_strIn)
{
  var l_lOut = 0;
    l_lOut = toInteger(p_strIn);
    if (isNaN(l_lOut))
    {
      return parseInt(0,10);
    } 
    else
    {
      return parseInt(l_lOut,10);
    }
}

/*****************************************************
  Umwandlung von String in Float unter Berücksichtigung von
  Dezimaltrennzeichen und TausenderTrennung
  gibt Float oder "NaN" zurück
*****************************************************/
function toInteger(p_strIn) {
    var l_strIn = p_strIn;
    var l_lOut = 0;
  var l_strGroupSymbol = g_strDecimalGroupingSymbol;
  // Tausender Trennzeichen rauswerfen
  l_strIn = replaceSubstring(l_strIn,l_strGroupSymbol,"");
  if(l_strIn=="" || l_strIn=="-")
  {
    l_strIn = 0;
  }
  // in Integer
    l_lOut    = parseInt(l_strIn,10);
  return l_lOut;
}

function FillLeading(strIn) {
  var strInput = new String(strIn);
  if(strInput.length > 1)
    return strInput;
  else
    return '0' + strInput;
}

function GetCurrDate(obj)
{
  obj.value =  GetCurrDateLCID();
}

function GetCurrTime() {
  var dateTime = new Date();
  var strTime = new String(FillLeading(dateTime.getHours()) + ":" + FillLeading(dateTime.getMinutes()));
  if( l_LCID == 1031)
    strTime = new String(FillLeading(dateTime.getHours()) + ":" + FillLeading(dateTime.getMinutes()));
  if( l_LCID == 2057)
    strTime = new String(FillLeading(dateTime.getHours()) + ":" + FillLeading(dateTime.getMinutes()));
  if( l_LCID == 1033)
  {
    l_lHours = dateTime.getHours();
    
    if(l_lHours > 12)
    {
      l_lHours = l_lHours - 12;
      strHoursInd = "pm"; 
    } 
    else
    {
      strHoursInd = "am"; 
    }
    strTime = new String(FillLeading(l_lHours) + ":" + FillLeading(dateTime.getMinutes()) + " " + strHoursInd);
  }
  return strTime; 
}

function GetCurrDateLCID() {
  var currDate = new Date();
  if(l_LCID == 1031)
    var strDate = new String(FillLeading(currDate.getDate()) + "." + FillLeading(currDate.getMonth() +1) + "." + FillLeading(currDate.getFullYear()));
  if(l_LCID == 2057)
    var strDate = new String(FillLeading(currDate.getDate()) + "/" + FillLeading(currDate.getMonth() +1) + "/" + FillLeading(currDate.getFullYear()));
  if(l_LCID == 1033)
    var strDate = new String(FillLeading(currDate.getMonth() +1) + "/" + FillLeading(currDate.getDate()) + "/" +  FillLeading(currDate.getFullYear()));
  return strDate; 
}
function GetCurrDateTime(obj) {
  obj.value =  GetCurrDateLCID() + ' ' + GetCurrTime();
}

/*****************************************************
  Date specific variables
*****************************************************/
  var daysInMonth = makeArray(12);
  daysInMonth[1] = 31;
  daysInMonth[2] = 29;
  daysInMonth[3] = 31;
  daysInMonth[4] = 30;
  daysInMonth[5] = 31;
  daysInMonth[6] = 30;
  daysInMonth[7] = 31;
  daysInMonth[8] = 31;
  daysInMonth[9] = 30;
  daysInMonth[10] = 31;
  daysInMonth[11] = 30;
  daysInMonth[12] = 31;
  var whitespace = " \t\n\r";


function charInString(c, s) {
  for (i = 0; i < s.length; i++)
  {
    if (s.charAt(i) == c)
      return true;
  }
  return false
}

/*****************************************************
  Number of Days in February
*****************************************************/
function daysInFebruary(year) {
  return ( ((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}


/****************************************
 validate legal Number Characters,
 return false, if not a legal number
 return "0", if empty String
****************************************/
function validateLegalNumberChars(p_strValue,p_strDecSymbol,p_strGroupSymbol,p_bShowGroupingSymbol) {
      var l_strValue = p_strValue.toString();
    if(l_strValue=="")
    {
      return "0";
    }
    var l_strDecSymbol = p_strDecSymbol;
    var l_strGroupSymbol = p_strGroupSymbol;
    //falls kein GroupingSymbol Schalter(soll das Control ein Tausendertrenner haben?) reingegeben wird, wird auf "false" setzen
    if(!p_bShowGroupingSymbol)
    {
      l_bShowGroupingSymbol = false;
    }
    else
    {
      l_bShowGroupingSymbol = p_bShowGroupingSymbol;    
    }
    // "-" rauswerfen, ausser an erster Stelle
    var regExpMinusSign = new RegExp("-","g");
    l_strRightValue = l_strValue.substring(1,l_strValue.length).replace(regExpMinusSign,"");
    l_strValue = l_strValue.substr(0,1) + l_strRightValue;
    // sind im String nur legale Zeichen?
      for (var i = 0; i < l_strValue.length; i++)
      {   
      var isLegalChar = false;
          var c = l_strValue.charAt(i);
          if (isDigit(c) || (l_strDecSymbol!="" && c==l_strDecSymbol) || (l_bShowGroupingSymbol==true && c==l_strGroupSymbol))
          {
        isLegalChar = true;
          }
          // erstes Zeichen darf "-" oder "+" sein
          else if((c=="-" ||c=="+") && i==0)
          {
        isLegalChar = true;
          }
          if(!isLegalChar)
          {
        return false;
          }
      }
    return l_strValue;
}

/************************************************
prüft und ergänzt die Tausendertrennzeichen
PARAMETERS:  p_strValue = zu korrigierender Wert
             p_strGroupSymbol = länderabh. Tausender Trennzeichen
             p_bShowGroupingSymbol = Schalter, ob dies Control TausenderTrenner anzeigen soll
RETURNS:     l_strValue = evtl. angepasster Wert ODER false (falls scheitert)
*************************************************/
function correctGroupingSymbol(p_strValue,p_strGroupSymbol,p_bShowGroupingSymbol) {
   var l_strValue = p_strValue.toString();
   // falls kein TausenderTrenner erwünscht -> mit Ausgangswert zurück
   if (!p_bShowGroupingSymbol || p_bShowGroupingSymbol=='')
   {
      return l_strValue;
   }
   var checkEnd = 0;
   var checkStart = l_strValue.length-1;
   var l_strGroupSymbol = p_strGroupSymbol;

   // löscht alle Tausendertrenner, falls vorhanden
   l_strValue = replaceSubstring(l_strValue,l_strGroupSymbol,"");

   // Funktion parst von rechts nach links durch Vorkommastellen, um Tausender Trenner zu setzen

   // Ende des Parsens finden;"+" oder "-" vorhanden?
   if (l_strValue.substr(0,1)=='+' || l_strValue.substr(0,1)=='-')
   {
      checkEnd = 1;
   }
   else
   {
      checkEnd = 0;
   }
  // Eingaben wie "-,1" in "-0,1" wandeln; für NS4 nötig
   if(checkStart<checkEnd)
   {
    l_strValue = l_strValue.substring(0,checkEnd) + "0";  
   }
   // Variable j zählt je bis 3=Stelle für Tausendertrenner hoch
   var j = 0;
   // von rechts (checkStart) nach links (checkEnd) durchgehen
   // Tausender Zeichen setzen
   for(i=checkStart;i>=checkEnd;i--)
   {
  if(j==3)
  //falls Stelle des Tausendertrenners
  {
    // Tausendertrenner fehlt?
    if(l_strValue.charAt(i) != l_strGroupSymbol)
    {
      l_strValue = l_strValue.substring(0,i+1) + l_strGroupSymbol + l_strValue.substring(i+1,l_strValue.length);
      i++;
    }
    // Stelle des Tausendertrenners zurücksetzen
    j = 0;
  }
  else
  {
    j++;
  }
   }
   return l_strValue;
}

/************************************************
 replaceSubstring(p_strString,p_strSubstringFrom,p_strSubstringTo)
 ersetzt alle Vorkommen von p_strSubstringFrom in p_strString durch p_strSubstringTo;
************************************************/
function replaceSubstring(p_strString,p_strSubstringFrom,p_strSubstringTo) {
  var l_strStingOut = "";
  if(!p_strString || p_strString=="")
  {
    return "";
  }
  else
  {
    var l_strString = p_strString.toString(); 
  }
  if(!p_strSubstringFrom || p_strSubstringFrom=="")
  {
    return l_strString;
  }
  else
  {
    var l_strSubstringFrom = p_strSubstringFrom.toString(); 
  }
  if(!p_strSubstringTo)
  {
     l_strSubstringTo = "";
  }
  else
  {
    var l_strSubstringTo = p_strSubstringTo.toString(); 
  }

  var l_lStartPos  = 0;
  var l_lEndPos  = l_strString.indexOf(l_strSubstringFrom, 0);
  while (l_lEndPos != -1)
  {
    for (var i = l_lStartPos;i < l_lEndPos;i++)
    {
      l_strStingOut += l_strString.charAt(i);
    } 
    l_strStingOut += l_strSubstringTo;
    l_lStartPos = l_lEndPos + l_strSubstringFrom.length;
    l_lEndPos = l_strString.indexOf(l_strSubstringFrom, l_lStartPos);
  }
  for (i = l_lStartPos; i < l_strString.length; i++)
  {
    l_strStingOut += l_strString.charAt(i);
  } 
  return l_strStingOut;
}

/************************************************
  Helper function
************************************************/
function isIntegerInRange(s, a, b) {
  if ( ! isInteger(s) ) return false;
  var num = parseInt (s);
  return ( ( num >= a ) && ( num <= b ) );
}

/************************************************
  Check for being a integer
************************************************/
function isInteger(s) {
  // TODO
  var i;
  for ( i = 1; i < s.length; i++ ) {
    var c = s.charAt(i);
    if ( ! isDigit(c)) return false;
  }
  return true;
}

/************************************************
 Date Helper function
************************************************/
function isMonth(s) {
  return isIntegerInRange (s, 1, 12);
}

/************************************************
  makeArray
************************************************/
function makeArray(n) {
  var arr = new Array(n + 1);
  for (var i = 1; i <= n; i++)
    arr[i] = 0
  return arr
}

//****************************************************
//  Trim whitespaces
//****************************************************
function lTrim(s) {
  return s.replace(/^ +/g, "");
}
function rTrim(s) {
  return s.replace(/ +$/g, "");
}
function Trim(s) {
  return s.replace(/^ +| +$/g, "");
}
function trim(s) {
  return s.replace(/^ +| +$/g, "");
}

//****************************************************
// General
//****************************************************

function canInput(str, cKey, iMaxCount) {
  var l_lPrecision = 0;
  for (i = 0; i < str.length; i++)
  {
    if (str.charAt(i) == cKey)
      l_lPrecision++;
  }
  return (l_lPrecision < iMaxCount) ? true:false;
}
function isDigit(c) {
  return ( ( c >= "0" ) && ( c <= "9" ) )
}

//****************************************************
// Float Control - inserting trailing zeros
//****************************************************
function getLastZeros(iCount) {
  str = new String();
  var iCounter = iCount;
  for(i=0;i< iCounter;i++)
  {
    str = str + '0';
  }
  return str;
}

var g_achHex = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
function HexEncodeString(p_str)
{
  var l_str = new String();
  for (i = 0; i < p_str.length; i++)
  {
    var l_n = p_str.charCodeAt(i);
    l_str += g_achHex[(l_n >> 4) & 0x0F] + g_achHex[l_n & 0x0F];
  }
  return l_str + "00";
}

//****************************************************
// function Integer2Screen(p_lInput, p_bFormat)
// Wandelt Float in Formatierten HTML Output:Currency
//****************************************************
function Integer2Screen(p_lInput,p_bFormat) {
  var l_strNewValue = toLocalIntegerString(p_lInput,p_bFormat,g_strDecimalGroupingSymbol);
  if(!l_strNewValue)
  {
    return "0";
  }
  else
  {
    return l_strNewValue;
  }
}

//****************************************************
// toLocalIntegerString(p_lInput, p_bFormat, p_strGroupSymbol)
// Wandelt Integer in Formatierten HTML Output
//****************************************************
function toLocalIntegerString(p_lInput, p_bFormat, p_strGroupSymbol) {
  if(isNaN(parseInt(p_lInput,10)))
  {
    return false;
  }
  var l_bShowGroupingSymbol = p_bFormat;
  var l_strGroupSymbol = p_strGroupSymbol;
  var l_strNewValue = "";
  // in String wandeln
  var l_strValue = p_lInput.toString();
  l_strNewValue = correctGroupingSymbol(l_strValue,l_strGroupSymbol,l_bShowGroupingSymbol); 
  if(!l_strNewValue)
  {
    return false;
  }
  return l_strNewValue;
}

//****************************************************
// function FloatToScreenCurrency(p_fInput, p_bFormat)
// Wandelt Float in Formatierten HTML Output:Currency
//****************************************************
function Float2ScreenCurrency(p_fInput,p_lPrecision, p_bFormat) {
  var l_strOut = "";
  var l_strNewValue = toLocalFloatString(p_fInput,p_lPrecision,p_bFormat,g_strMonetaryDecimalSymbol,g_strMonetaryDecimalGroupingSymbol);
  if(!l_strNewValue)
  {
    l_strOut = "0";
    if(l_lPrecision && l_lPrecision > 0)
    {
      l_strOut = l_strOut + g_strMonetaryDecimalSymbol + correctDecs("",p_lPrecision);
    } 
    return l_strOut;
  }
  else
  {
    return l_strNewValue;
  } 
}

//****************************************************
// FloatToScreenFloat(p_fInput,p_lPrecision)
// Wandelt Float in Formatierten HTML Output:Float
//****************************************************
function Float2ScreenFloat(p_fInput,p_lPrecision, p_bFormat) {
  var l_strOut = "";
  var l_lPrecision = p_lPrecision;
  var l_strNewValue = toLocalFloatString(p_fInput,p_lPrecision,p_bFormat,g_strDecimalSymbol,g_strDecimalGroupingSymbol);
  if(!l_strNewValue)
  {
    l_strOut = "0";
    if(l_lPrecision && l_lPrecision > 0)
    {
      l_strOut  = l_strOut + g_strDecimalSymbol + correctDecs("",p_lPrecision);
    } 
    return l_strOut;
  }
  else
  {
    return l_strNewValue;
  }
}

//****************************************************
// toLocalFloatString(p_fInput,p_lPrecision, p_bFormat, p_strDecSymbol, p_strGroupSymbol)
// Wandelt Float in Formatierten HTML Output
//****************************************************
function toLocalFloatString(p_fInput,p_lPrecision, p_bFormat, p_strDecSymbol, p_strGroupSymbol) {
  if(isNaN(parseFloat(p_fInput)))
  {
    return false;
  }
  var l_bShowGroupingSymbol = p_bFormat;
  var l_lPrecision = p_lPrecision;
  var l_strDecSymbol = p_strDecSymbol;
  var l_strGroupSymbol = p_strGroupSymbol;
  var isCorrect = true; 
  var l_strPreDec = "";
  var l_strPostDec = "";
  var l_strNewValue = "";
  
  // in String wandeln
  var l_strValue = p_fInput.toString();
  // in Bestandteile vor und nach Komma splitten
  if(l_strValue.indexOf(".")>-1)
  {
    l_strPreDec  = l_strValue.substr(0, l_strValue.indexOf('.'));
    l_strPostDec = l_strValue.substring(l_strValue.indexOf('.') + 1,l_strValue.length);
  }
  else
  {
    l_strPreDec  = l_strValue;
    l_strPostDec  = "";   
  } 
  l_strPreDec = correctGroupingSymbol(l_strPreDec,l_strGroupSymbol,l_bShowGroupingSymbol);  
  l_strPostDec = correctDecs(l_strPostDec,l_lPrecision);
  if(!l_strPreDec || !l_strPostDec)
  {
    isCorrect = false;
  }
  // String zusammenbauen
  if(isCorrect)
  {
    l_strNewValue = l_strPreDec;
    if(l_lPrecision && l_lPrecision > 0)
    {
      l_strNewValue = l_strNewValue + l_strDecSymbol + l_strPostDec;
    } 
    return l_strNewValue;
  }
  else
  {
    return false;
  }
}

//****************************************************
// Anpassung Nachkommastellen für Float und Currency Controls
//****************************************************
function correctDecs(p_strValue,p_lPrecision) {
  var l_strValue = p_strValue;
  var l_lPrecision = p_lPrecision;

   // Leerstring
   if(!l_strValue || l_strValue.length == 0 )
   {
    return getLastZeros(l_lPrecision);
   }

   if(l_strValue.length > l_lPrecision)
   {
    return l_strValue.substr(0,l_lPrecision);
   }
   else
   {
    return l_strValue + this.getLastZeros(l_lPrecision - l_strValue.length);
   }
}

//****************************************************
//  if Blur Validation of Numeric Controls result false
//****************************************************
function handleBlurValidationError(oControl,value) {
  alert(l_strValBlurAlert + ":\n" + value);
  return false;
}

//****************************************************
//  Validation of Float Controls 
//  invoked by 'onBlur()'
//****************************************************
function ValidateFloat(oFloat,p_lPrecision,p_bShowGroupingSymbol) {
  var l_lPrecision = p_lPrecision;
  var l_bShowGroupingSymbol = p_bShowGroupingSymbol;
  var isCorrect = true;
  var l_strOldValue = oFloat.value;
  var l_strNewValue = "";
  var l_fNewValue = 0;
  l_fNewValue = toFloat(l_strOldValue,"UPFloat");
  if(isNaN(l_fNewValue))
  {
    isCorrect = false;
  }
  if(isCorrect)
  {
    l_strNewValue = toLocalFloatString(l_fNewValue,l_lPrecision,l_bShowGroupingSymbol,g_strDecimalSymbol,g_strDecimalGroupingSymbol);
  }
  if(!l_strNewValue)
  {
    isCorrect = false;
  }
  if(isCorrect)
  {
    oFloat.value = l_strNewValue;
    return true;
  }
  else
  {
    return handleBlurValidationError(oFloat,l_strOldValue);
  }
}

//****************************************************
// Validation of Integer Control
// invoked by 'onBlur()'
//****************************************************

function ValidateInteger(oInt,p_bShowGroupingSymbol) {
  var l_bShowGroupingSymbol = p_bShowGroupingSymbol;
  var isCorrect = true;
  var l_strOldValue = oInt.value;
  var l_strNewValue = "";
  var l_lNewValue = 0;

  l_lNewValue = toInteger(l_strOldValue);
  if(isNaN(l_lNewValue))
  {
    isCorrect = false;
  }
  if(isCorrect)
  {
    l_strNewValue = toLocalIntegerString(l_lNewValue,l_bShowGroupingSymbol,g_strDecimalGroupingSymbol);
  }
  if(!l_strNewValue)
  {
    isCorrect = false;
  }
  if(isCorrect)
  {
    oInt.value = l_strNewValue;
    return true;  
  }
  else
  {
    return handleBlurValidationError(oInt,l_strOldValue);
  } 
}


//****************************************************
// Validation of Currency Controls 
// invoked by 'onBlur()'
//****************************************************

// mit fester Anzahl Nachkommastellen=2
function ValidateCurrency(oCurrency,p_bShowGroupingSymbol) {
  ValidateCurrencyDo(oCurrency,2,p_bShowGroupingSymbol);
}

// mit variabler Anzahl Nachkommastellen
function ValidateCurrency(oCurrency,l_lPrecision,  p_bShowGroupingSymbol) {
  ValidateCurrencyDo(oCurrency,l_lPrecision,p_bShowGroupingSymbol);
}

function ValidateCurrencyDo(oCurrency,p_lPrecision,p_bShowGroupingSymbol) {
  var l_lPrecision = p_lPrecision;
  var l_bShowGroupingSymbol = p_bShowGroupingSymbol;
  var isCorrect = true;
  var l_strOldValue = oCurrency.value;
  var l_strNewValue = "";
  var l_fNewValue = 0;
  
  l_fNewValue = toFloat(l_strOldValue,"UPCurrency");
  if(isNaN(l_fNewValue))
  {
    isCorrect = false;   
  }
  if(isCorrect)
  {
    l_strNewValue = toLocalFloatString(l_fNewValue,l_lPrecision,l_bShowGroupingSymbol,g_strMonetaryDecimalSymbol,g_strMonetaryDecimalGroupingSymbol);  
  }
  if(!l_strNewValue)
  {
    isCorrect = false;   
  }
  if(isCorrect)
  {
    oCurrency.value = l_strNewValue;
    return true;  
  }
  else
  {
    return handleBlurValidationError(oCurrency,l_strOldValue);
  }
}

function IsINTInRange(strC) {
  l_lIntValue = parseInt(strC);
  if(isNaN(l_lIntValue))
    return false;
  l_lIntValue = Math.abs(l_lIntValue);
  
  if(l_lIntValue > MAXINT)
    return false;
  
  return true;
}

function IsFLOATInRange(strC,p_strUPtype) {
  strC = toFloat(strC,p_strUPtype);
  l_fFloatValue = parseFloat(strC);
  if(isNaN(l_fFloatValue))
    return false;
  l_fFloatValue = Math.abs(l_fFloatValue);
  if(l_fFloatValue > MAXFLOAT)
    return false;
  return true;
}

//****************************************************
// CheckDate(p_strDate) - Überprüfung ob Datum gültig ist
//****************************************************
function CheckDate(p_strDate) {
  l_bBuildDate = false;
  var l_iDay,l_iMonth,l_iYear,l_strSeperator;
  var l_dtCurrDate = new Date();
  var l_strInput   = new String(p_strDate);
  var l_strSeperator = new String();
  l_re = /^(\d{1,2})?(\.|\/)?(\d{1,2})?(\.|\/)?(\d{1,4})? *$/i;
  var l_result     = l_strInput.match(l_re);
  if (!l_result)
  {
    return GetCurrDateLCID();
  }
  // german + uk date format

  if(l_LCID == 1031 || l_LCID == 2057)
  {
    if (l_result[1])
    { 
      l_iDay   = parseInt(trim(l_result[1]),10);
    }
    if (l_result[3])
    { 
      l_iMonth = parseInt(trim(l_result[3]),10);
    } 
    if (l_result[5])
    { 
      l_iYear  = parseInt(trim(l_result[5]),10);
    }
    if (l_result[2])
    { 
      l_strSeperator = l_result[2];
    } 

    if(l_strSeperator == "" && l_LCID == 1031)
    {
      l_strSeperator  = '.';
      l_bBuildDate = true;
    }
    if((l_strSeperator== "" || l_strSeperator == '.') && l_LCID == 2057)
    {
      l_strSeperator  = '/';
      l_bBuildDate = true;
    }
  }
  // us Date Format
  if(l_LCID == 1033)
  {
    if (l_result[3])
    { 
      l_iDay   = parseInt(trim(l_result[3]),10);
    } 
    if (l_result[1])
    { 
      l_iMonth = parseInt(trim(l_result[1]),10);
    } 
    if (l_result[5])
    { 
      l_iYear  = parseInt(trim(l_result[5]),10);
    }
    if (l_result[2])
    { 
      l_strSeperator = l_result[2];
    } 

    if(l_strSeperator== "" || l_strSeperator == '.')
    {
      l_strSeperator  = '/';
      l_bBuildDate = true;
    }
  }
    if(isNaN(l_iMonth) || !isMonth(l_iMonth))
      l_iMonth = l_dtCurrDate.getMonth() + 1;
        
    if (isNaN(l_iDay) || l_iDay > daysInMonth[l_iMonth] || l_iDay < 1) 
      l_iDay = l_dtCurrDate.getDate();
    if (isNaN(l_iYear) || l_iYear > 9999)
      l_iYear = l_dtCurrDate.getFullYear();
    
    if (l_iYear < 100 && l_iYear > 30 )
      l_iYear = 1900 + l_iYear;
         
    if(l_iYear <= 30)
      l_iYear = 2000 + l_iYear;
    
    //check february
    if ( (l_iMonth == 2 ) && ( l_iDay > daysInFebruary(l_iYear) ) )
      l_iDay = daysInFebruary(l_iYear);

    if(l_LCID != 1033)
      return FillLeading(l_iDay) + l_strSeperator + FillLeading(l_iMonth) + l_strSeperator + l_iYear;
    else
      return  FillLeading(l_iMonth) + l_strSeperator + FillLeading(l_iDay) + l_strSeperator + l_iYear;

  return FillLeading(l_iDay) + l_strSeperator + FillLeading(l_iMonth) + l_strSeperator + l_iYear;
}


//****************************************************
// CheckTime(p_strTime) - Überprüfung ob Zeit gültig ist
//****************************************************
function CheckTime(p_strTime) {
  l_bBuildDate = false;
  var l_dtCurrDate = new Date();
  var l_strInput = new String(p_strTime);
  l_re = /^(\d{1,2})?(:)?(\d{1,2})?(:)?(\d{1,2})? *((A|P)M)?$/i;
  var l_result     = l_strInput.match(l_re);
  if (!l_result)
    return GetCurrTime();
  if (l_result[1])
  {
    l_iHour = parseInt(trim(l_result[1]),10);
  }
  else
  {
    l_iHour = l_dtCurrDate.getHours();
  }

  if (l_result[3])
  {
    l_iMinutes = parseInt(trim(l_result[3]),10);
  }
  else
  {
    l_iMinutes = "00";
  }
  l_strDayTimeInd = ""
  if (l_result[6])
  {
    l_strDayTimeInd = l_result[6];
  }
  if (l_strDayTimeInd != null)
  {
    l_strDayTimeInd = l_strDayTimeInd.toUpperCase();
  }

  l_lDayTimeAdd = 0;
  // german + uk date format
  if(l_LCID == 1031 || l_LCID == 2057)
  {
    if(isNaN(l_iHour) || !isIntegerInRange(l_iHour,0,23))
    {
      l_bBuildDate = true;
      l_iHour = l_dtCurrDate.getHours();
    }
    if(isNaN(l_iMinutes) || !isIntegerInRange(l_iMinutes,0,59))
    {
      l_bBuildDate = true;
      //l_iMinutes = l_dtCurrDate.getMinutes();
      l_iMinutes = "00";
    }
    return trim(FillLeading(l_iHour) + ":" + FillLeading(l_iMinutes));
  }
  // us date format
  if(l_LCID == 1033)
  {
    //Hour is OK , no timeindicator available...
    if(!isNaN(l_iHour) && l_strDayTimeInd.length < 1)
    {
      l_bBuildDate = true;
      if(l_iHour >= 12)
      {
        l_strDayTimeInd = "PM";
      }
      else
      {
        l_strDayTimeInd = "AM";
      } 
    }
    
    //hour is ok, time indicator is pm
    if(!isNaN(l_iHour) && (l_strDayTimeInd == "pm" || l_strDayTimeInd == "PM"))
    {
      l_lDayTimeAdd = 12;
    }
    
    //hour is not ok
    if(isNaN(l_iHour))
      l_iHour = l_dtCurrDate.getHours();
    
    
    //hour is not in range
    if(!isIntegerInRange(l_iHour,1,12))
    {
      l_bBuildDate = true;
      l_strDayTimeInd = "am";
      
      if(l_iHour > 12 )
      {
        if(l_iHour > 24 )
        { 
          l_iHour = l_dtCurrDate.getHours();
          if(l_iHour > 12)
          {
            l_iHour-= 12;
          }
        }
        else
        {
          l_iHour-= 12;
        }
          
        l_strDayTimeInd = "pm";
      }
      else
      {
        l_iHour= 12;
        l_strDayTimeInd = "am";
      }
    }
    
    if(isNaN(l_iMinutes) ||!isIntegerInRange(l_iMinutes,0,59))
    {
      l_bBuildDate = true;
      //l_iMinutes = l_dtCurrDate.getMinutes();
      l_iMinutes = "00";
    }
    if(l_bBuildDate)
      return trim(FillLeading(l_iHour) + ":" + FillLeading(l_iMinutes) + " " + l_strDayTimeInd);
    else 
      return trim(FillLeading(l_iHour) + ":" + FillLeading(l_iMinutes) + " " + l_strDayTimeInd);
  }
}

function ValidateDateTime(obDateTime) {
  var l_strInput = new String(obDateTime.value);
  if(l_strInput.length==0)
    return;
  l_reDate = /^((\d{1,2})(\.|\/)(\d{1,2})(\.|\/)(\d{1,4}) ?){1}((\d{1,2})?(:)?(\d{1,2})?(:)?(\d{1,2})? *((A|P)M)?)?$/i;
  l_reTime = /^ {0,2}((\d{1,2})?(\.|\/)?(\d{1,2})?(\.|\/)?(\d{1,4}) +)?((\d{1,2})?(:)?(\d{1,2})?(:)?(\d{1,2})? *((A|P)M)?)?$/i;
  var l_resultDate   = l_strInput.match(l_reDate);
  var l_resultTime   = l_strInput.match(l_reTime);
  if(l_resultDate) {
    l_strDate = l_resultDate[1];
    obDateTime.value = trim(CheckDate(l_strDate));
  } else {
    obDateTime.value = GetCurrDateLCID();
  }
  if(l_resultTime && l_resultTime[7]) {
    l_strTime = l_resultTime[7];
    obDateTime.value+= ' ' + trim(CheckTime(l_strTime));
  } else {
    obDateTime.value+= ' ' + GetCurrTime();
  }
}

//****************************************************
// invoked by 'onBlur()'
//****************************************************
function ValidateDate(obDate) {
  strC = obDate.value;
  if(strC.length==0)
    return;
  obDate.value = CheckDate(strC);
}

//****************************************************
// invoked by 'onBlur()'
//****************************************************
function ValidateTime(obTime) {
  strC = obTime.value;
  if(strC.length==0)
    return;
  obTime.value = CheckTime(strC);
}

//****************************************************
// Input Handler for Integer Control
// invoked by 'onkeypress'
// Accepts: '-' 
// Numbers
//****************************************************
function validateIntegerInput(strItemValue, cKey, lUnSigned, l_bShowGroupSep) {
  if (cKey=="-") {
    if (!lUnSigned)
      return canInput(strItemValue, '-', 1);
  }
  if (cKey==g_strDecimalGroupingSymbol) {
    // = Tausender Trennzeichen ; darf mehrmals vorhanden sein; falls für dies Control erwünscht
    if (l_bShowGroupSep)
      return true;
    else
      return false;
  }
  if (isDigit(cKey)) {
    NewVal = strItemValue + cKey;
    return IsINTInRange(NewVal);
  }
  return false;
}

//****************************************************
// Input Handler for Currency Control
// invoked by 'onkeypress'
//****************************************************
function validateCurrencyInput(strItemValue, cKey, l_bShowGroupSep) {
  if (cKey==g_strMonetaryDecimalSymbol) {
    // = Dezimal Trennzeichen ; darf nur einmal vorhanden sein
    if (strItemValue.indexOf(g_strMonetaryDecimalSymbol) > -1)
      return false;
    return true;
  }
  if (cKey==g_strMonetaryDecimalGroupingSymbol) {
    // = Tausender Trennzeichen ; darf mehrmals vorhanden sein; falls für dies Control erwünscht
    if(l_bShowGroupSep)
      return true;
    else
      return false;
  }
  if (cKey=="-")
    return canInput(strItemValue, '-', 1);
  if (isDigit(cKey)) {
    NewVal =  strItemValue + cKey;
    return IsFLOATInRange(NewVal,"UPCurrency");
  }
  return false;
}

//****************************************************
// Input Handler for float Control
// invoked by 'onkeypress'
// Accepts: 
// '.' 
// Numbers
//****************************************************
function validateFloatInput(strItemValue, cKey, l_bShowGroupSep) {
  if (cKey==g_strDecimalSymbol) {
    // = Dezimal Trennzeichen ; darf nur einmal vorhanden sein
    if (strItemValue.indexOf(g_strDecimalSymbol) > -1)
      return false;
    return true;
  }
  if (cKey == g_strDecimalGroupingSymbol) {
    // = Tausender Trennzeichen ; darf mehrmals vorhanden sein; falls für dies Control erwünscht
    if(l_bShowGroupSep)
      return true;
    else
      return false;
  }
  if (cKey=="-")
    return canInput(strItemValue, '-', 1);
  if (isDigit(cKey)) {
    NewVal =  strItemValue + cKey;
    return IsFLOATInRange(NewVal, "UPFloat");
  }
  return false;
}

//****************************************************
// Input Handler for Date Control
// invoked by 'onkeypress'
// Accepts: '.'
// Numbers
//****************************************************
function validateDateInput(strItemValue, cKey) {
  switch (cKey) {
    case('.'):
      return canInput(strItemValue,'.',2);
      break;
    case('/'):
      return true;
      break;
    default:
      return isDigit(cKey);
  }
  return true;
}

//****************************************************
// Input Handler for DateTime Control
// invoked by 'onkeypress'
// Accepts: '.' but only two of them
// Numbers
// ':'
//****************************************************
function validateDateTimeInput(strItemValue, cKey) {
  switch (cKey) {
    case('.'):
      return canInput(strItemValue,'.',2);
    case(' '):
      return canInput(strItemValue,' ',2);
    case(':'):
      return canInput(strItemValue,':',2);
    case('/'):
    case('a'):
    case('A'):
    case('p'):
    case('P'):
    case('m'):
    case('M'):
      return true;
    default:
      return isDigit(cKey);
  }
  return true;  // ???
}

//****************************************************
// Input Handler for Time Control
// invoked by 'onkeypress'
// Accepts: ':'
// Numbers
//****************************************************
function validateTimeInput(strItemValue, cKey) {
  switch(cKey) {
    case(' '):
      return canInput(strItemValue,' ',1);
    case(':'):
      return canInput(strItemValue,':',1);
    case('a'):
    case('A'):
    case('p'):
    case('P'):
    case('m'):
    case('M'):
      return true;
    default:
      return isDigit(cKey);
  }
  return true;  // ???
}

//****************************************************
// Input Handler Control
// invoked by 'onkeypress'
//****************************************************
function processValidation(strItemValue, cKey, lControl, l_bShowGroupSep) {
  var bValidated;
  switch (lControl) {
    case(1):
      bValidated = validateCurrencyInput(strItemValue, cKey, l_bShowGroupSep);
      break;
    case(2):
      bValidated = validateDateInput(strItemValue, cKey);
      break;
    case(3):
      bValidated = validateTimeInput(strItemValue, cKey);
      break;
    case(4):
      bValidated = validateIntegerInput(strItemValue, cKey,0, l_bShowGroupSep);
      break;
    case(5):
      bValidated = validateIntegerInput(strItemValue, cKey,1, l_bShowGroupSep);
      break;
    case(6):
      bValidated = validateFloatInput(strItemValue, cKey, l_bShowGroupSep);
      break;
    case(7):
      bValidated = validateDateTimeInput(strItemValue, cKey);
      break;
  }
  return bValidated;
}

//****************************************************
// Input Handler Control
// invoked by 'onkeypress'
//****************************************************
function processKey(e) {
  var lControl;
  if (NS4 || W3C)
  {
    oItemObj = e.target;
  }
  else
  {
    oItemObj = e;
  }
  
  if(oItemObj.bShowGroupSep)
  {
    l_bShowGroupSep = oItemObj.bShowGroupSep; 
  }
  else
  {
    l_bShowGroupSep = false;
  }
  switch(oItemObj.UPtype)
  {
    case("UPCurrency"):
      lControl = 1;
      break;
    case("UPDate"):
      lControl = 2;
      break;
    case("UPTime"):
      lControl = 3;
      break;
    case("UPSignedInteger"):
      lControl = 4;
      break;
    case("UPUnsignedInteger"):
      lControl = 5;
      break;
    case("UPFloat"):
      lControl = 6;
      break;
    case("UPDateTime"):
      lControl = 7;
      break;
    default:
      lControl = 0;
      break;
  }
  if(lControl)
  {
    if (NS4 || W3C)
    {
      lWhichASC = e.which;
    }
    else
    {
      lWhichASC = event.keyCode;
    }
    
    if(lWhichASC == 0)
      return true;

    if(lWhichASC == 8)
      return true;
    cWhichKey       = String.fromCharCode(lWhichASC).toLowerCase();
    strItemName     = (NS4 || W3C) ? e.target.name : e.name;
    strItemValue    = (NS4 || W3C) ? e.target.value : e.value;
    bValidated      = processValidation(strItemValue,cWhichKey,lControl,l_bShowGroupSep);
    
    if(NS4 || W3C)
    {
       if (W3C && !bValidated)
       {
        e.preventDefault();
        e.stopPropagation();
       }
       return bValidated;
    }
    else
    {
      if(bValidated)
        return event.returnValue= lWhichASC;
      else
        return event.returnValue=false;
    }
   }
   else
   {
    return true;
   }
}

function GetParam(p_strIn, p_strParam) {
  l_strIn    = p_strIn;
  l_strParam = p_strParam;

  l_strIn.toUpperCase();
  l_strParam.toUpperCase();
  
  lFound  = l_strIn.indexOf(l_strParam + '=');
  
  lFound2 = l_strIn.indexOf('&',lFound);
  
  if (lFound == -1)
    return "-1";
  lFound += l_strParam.length + 1;
  l_strReturn =l_strIn.substring(lFound,lFound2);
  
  if(isNaN(parseInt(l_strReturn)))
    l_strReturn = "-1";
  return l_strReturn;
}


//****************************************************
// ValidateFields(l_oForm) - Überprüfung ob Eingabe in Pflichtfelder erfolgt ist
//****************************************************
function ValidateFields(l_oForm) {
  var l_aFormElements = l_aValFieldNames;
  var l_aFormNames    = l_aValFieldTitles;
  var l_bFCheck       = true;
  var l_strReturn     = "\n"+ l_strValAlert +"\n\n\t";
  var l_strFieldFocus = "";
  var l_strValue    = "";
  var l_oField    = null;

  if( GetParam(l_oForm.action,"rq_lSenderId") == "-1")
    return true;

  for(var l_lCount=0; l_lCount < l_aFormElements.length; l_lCount++) {
    l_oField = l_oForm.elements[l_aFormElements[l_lCount]];
    // Wert für SELECT Controls behandeln
    if(l_oField.type.substr(0,6)=="select")
    {
      // bei Listenfeldern (size>1) ist beim Aufbau der Seite selectedIndex=-1 
      if(l_oField.selectedIndex < 0)
      {
        l_oField.selectedIndex = 0;
      }
      if(l_oField.selectedIndex > -1)
      {
        l_strValue = l_oField[l_oField.selectedIndex].text;
      }
      else
      {
        l_strValue = "";
      } 
    }
    else
    {
      l_strValue = l_oField.value;
    }
      if ((l_strValue == "") ||
            (l_strValue == " "))
        {
      if (l_strFieldFocus == "")
      {
        l_strFieldFocus = l_oField.name;
      }
          l_strReturn += l_aFormNames[l_lCount] + "\n\t";
            l_bFCheck = false;
        }
    }
  
  if (l_bFCheck == true)
    {
        return true;
    }
    else
    {
        l_oFieldFocus = eval("l_oForm." + l_strFieldFocus);
        alert(l_strReturn);
        l_oFieldFocus.focus();
        return false;
    }
}

//****************************************************
// UpDelete() - Bestätigung zum Löschen einholen
//****************************************************
function UpDelete() {
  Check = confirm(l_strDelAlert);
  return Check;
}

//****************************************************
// ListId2Value(p_strFK) - Datapicker  - Wert über die Id holen
//****************************************************
function ListId2Value(p_strFK) {
l_strFK=p_strFK
  l_strInd=eval("window.document.__UpForm."+l_strFK+".selectedIndex");
  if(typeof l_strInd == 'undefined') {
    return;
  }
  if (l_strInd > -1) {
    l_strVar=eval("window.document.__UpForm."+l_strFK+".options["+l_strInd+"]");
    l_strVar.value=eval("window.document.__UpForm."+l_strFK+".options[window.document.__UpForm."+l_strFK+".selectedIndex].text");
  }
}

//****************************************************
// FetchFKFields(p_strFK,p_strTabPK) - Datapicker  - Werte holen
//****************************************************
function FetchFKFields(p_strFK,p_strTabPK,p_bActDir) {
  if (top.name=="wndInsert") {
    alert(l_strFuncNotAvailable);
    return;
  }
  var l_strFK = p_strFK;
  var l_strTabPK = p_strTabPK;
  var l_obSelect = null;
  var l_strDir;
  if(p_bActDir) {
    // Kommt von MatchCode
    l_strDir = "./";
    if(parent && parent.UpAppMain) {
      l_obSelect = eval("parent.UpAppMain.document.__UpForm."+l_strFK);
    } else {
      return;
    }
  } else {
    l_strDir = "../../../_UpInclude/script/";
    l_obSelect = eval("window.document.__UpForm."+l_strFK);
  }
  if(l_obSelect && l_obSelect.options && l_obSelect.options.length > 0 && l_obSelect.selectedIndex > -1) {
    l_lid = l_obSelect.options[l_obSelect.selectedIndex].value;
    l_strPageToOpen = l_strDir + "UpFillCrossRef.asp?rq_strFk="+l_strFK+"&rq_lid="+l_lid+"&rq_TabPK="+l_strTabPK;
    if (parent.UpAppTransfer)
        parent.UpAppTransfer.location.href=l_strPageToOpen;
  }
}

//****************************************************
// FetchFields(p_strFk,p_strTable,p_strForeignField,p_strType) - Datapicker  - Werte holen
//****************************************************
function FetchFields(p_strFk,p_strTable,p_strForeignField,p_strType,p_lPrecision) {
  if (top.name=="wndInsert") {
    alert(l_strFuncNotAvailable);
    return;
  }
  l_strFK             = p_strFk;
  l_strForeignTable   = p_strTable;
  l_strForeignField   = p_strForeignField;
  l_strForeignType    = p_strType;
  if(p_lPrecision && p_lPrecision!="")
    l_lPrecision    = p_lPrecision; 
  else
    l_lPrecision    = "0";
  l_lPrecision    = p_lPrecision;
  l_lSelValue     = eval("window.document.__UpForm." + l_strFK + ".value");
  l_lSelValue     = HexEncodeString(l_lSelValue);
  l_strPageToOpen="../../../_UpInclude/script/UpFillRef.asp?rq_Type=" + l_strForeignType + "&rq_strFk="+l_strFK+"&rq_strValue="+l_lSelValue+"&rq_strForeignField="+l_strForeignField+"&rq_strTable="+l_strForeignTable+"&rq_strPrecision="+l_lPrecision;
  if (parent.UpAppTransfer)
      parent.UpAppTransfer.location.href=l_strPageToOpen;
}

//****************************************************
// SubmitHandlerCrossRref() - Datapicker
//****************************************************
function SubmitHandlerCrossRref() 
{
  if(typeof g_arrFK != 'undefined')
  {  
    for (i = 0; i < g_arrFK.length; i++) 
    {
      if(typeof g_arrFK[i] != 'undefined') 
      {
      ListId2Value(g_arrFK[i]);
      }
    }
  }
  
  l_retVal = ValidateFields(window.document.__UpForm);

  if (l_retVal)
    return true;
  else
    return false;

}

//****************************************************
// SubmitHandlerMail() - Datapicker
//****************************************************
function SubmitHandlerMail() {
  l_retVal=ValidateFields(window.document.__UpForm);
  if (l_retVal) {
    PromptMailRcpt('');
    return true;
  }
  else
    return false;
}

//****************************************************
// Validate_Email(p_strVal) - eMail Adresse prüfen
//****************************************************
function Validate_Email(p_strVal) {
  if (!p_strVal.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/g) ||
    p_strVal.search(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/g) != -1)
  {
    alert(p_strVal + l_strValidMail);
    return false;
  }
  return true;
}

//****************************************************
// PromptforMail(p_strPromptedDefault) - Nach eMail Adresse fragen
//****************************************************
function PromptforMail(p_strPromptedDefault) {
  l_strPrompted = prompt(l_strPromptMail,p_strPromptedDefault);
  if (l_strPrompted == null)
    return "";
  if (!l_strPrompted || l_strPrompted=="")
  {
    alert(l_strNoMail);
    PromptforMail(p_strPromptedDefault);
  }
  if (l_strPrompted != null)
  {
    l_strPrompted = l_strPrompted.replace(/^ +/g, "");
    l_strPrompted = l_strPrompted.replace(/ +$/g, "");
    l_strPrompted=l_strPrompted.replace(/,+/,";");
    l_strPrompted=l_strPrompted.replace(/ +/,";");
    return l_strPrompted;
  }
  return "";
}

//****************************************************
// PromptMailRcpt(p_strPromptedDefault) 
//****************************************************
function PromptMailRcpt(p_strPromptedDefault) {
  l_strPrompted=PromptforMail(p_strPromptedDefault);
  l_arrPrompted=l_strPrompted.split(";");
  l_strPromptedSendTo="";
  
  for (i=0;i<l_arrPrompted.length;i++)
  {
    if ((l_arrPrompted[i]=="") || (l_arrPrompted[i]==" "))
    {
      continue;
    }
    else if (!Validate_Email(l_arrPrompted[i]))
    {
      PromptMailRcpt(l_strPrompted);
    }
    else
    {
      l_strPromptedSendTo=l_strPromptedSendTo + l_arrPrompted[i];
    }

    if (i<l_arrPrompted.length-1)
      l_strPromptedSendTo=l_strPromptedSendTo + ";"
  }
  
  l_strPromptedSendTo=l_strPromptedSendTo.replace(/;{2,}/,";");
  l_strPromptedSendTo=l_strPromptedSendTo.replace(/;$/,"");
  document.__UpForm.fr_strMailSendTo.value=l_strPromptedSendTo; 
}

//****************************************************
// makeOption(p_oSelect,p_strValue) legt ein Option Objekt an und fügt es einem SELECT hinzu
//****************************************************
function makeOption(p_obSelect,p_strText,p_strValue) {
  if(!p_obSelect)
  {
    return false;
  }
    var l_obNewOption = new Option(p_strText,p_strValue);
    p_obSelect.options[p_obSelect.options.length] =  l_obNewOption;
    return true;
}
