//---------------------------------------------------------------------------
// function isValidPassword( str )
// function isAllDigit(objInput, strErrMsg) 
// function isWide(objInput, numWidth, strErrMsg) 
// function isDate(objInput, strErrMsg)
// function DaysInMonth( monthNum, blnLeapYear )
// function isLeapYear(year)
// function isValidChars(checkOK, checkStr)
// function getRadioValue( radioObject )
// function isSelected( selectObject, strErrMsg)  
// function isUndef( val )
// function isBlank( str )
// function TrimLeft( str )
// function TrimRight( str )
// function Trim( str ) 
// function isAmount (objInput, nBefore, nAfter, strErrMsg) 
// function isAmountAbs (objInput, nBefore, nAfter, strErrMsg) 
// function isDigitWithDelim (objInput, nLength, strErrMsg) 
// fucntion onDel(submitPage)
// fucntion onCancel(submitPage)
//---------------------------------------------------------------------------
function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)	
		return null; 
	str += "";       
	if (str.length == 0) 
		resultStr = "";
	else {	
		len = str.length;
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
} // TrimLeft
//---------------------------------------------------------------------------
function TrimRight( str ) {
	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)	
		return null;
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
  		resultStr = str.substring(0, i + 1);
  	}
  	return resultStr;  	
} // TrimRight
//---------------------------------------------------------------------------
function Trim( str ) {
	var resultStr = "";
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	return resultStr;
} // Trim
//---------------------------------------------------------------------------
function isValidPassword( str ) {
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")	
		return false;
	var isValid = true;
	str += "";	
	for (i = 0; i < str.length; i++)
   	{
      		if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
      			((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ||
      			(str.charAt(i) == "_") || (str.charAt(i) == "$") || (str.charAt(i) == "#") ) )
      		{
   				isValid = false;
         		break;
      		}
	}
	return isValid;
}

function isValidChars(checkOK, checkStr) {
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) 
       return (false);
  }
  return (true);
}  // isValidChars
//---------------------------------------------------------------------------
 function isLeapYear(year)  {
   return ((year%4 == 0) && ((year%100 != 0) || (year%400 == 0)));
} // isLeapYear
//---------------------------------------------------------------------------
function DaysInMonth( monthNum, blnLeapYear ) {
  var days = 31;
  if (monthNum == 2) {
  	if (blnLeapYear)
	  days = 29;
	else
	  days = 28; }
  else if (monthNum%2 == 0) {
	     if (monthNum < 8)
		   days = 30;
	   }		
	   else
		if (monthNum > 8)		
	      days = 30;
  return days;
} // DaysInMonth
//---------------------------------------------------------------------------
function isUndef( val ) {
	var isValid = false;
 	if (val+"" == "undefined")
 		isValid = true;
	return isValid;
}  // IsUndef
//---------------------------------------------------------------------------
function isNull( val ) {
	var isValid = false;
 	if (val+"" == "null")
 		isValid = true;
	return isValid;
} // isNull
//---------------------------------------------------------------------------
function isDate(objInput, strErrMsg) { 
  var nDD, nMM, nYYYY, str;
  var checkStr = objInput.value;
  // Inserts missing chars into short date
  if(("/" == checkStr.charAt(1)) || ("." == checkStr.charAt(1))) 
    checkStr = "0" + checkStr;
  if(("/" == checkStr.charAt(4)) || ("." == checkStr.charAt(4))) 
    checkStr = checkStr.substring(0,3) + "0" + checkStr.substring(3,9);
  // Parses date  
  if (checkStr.length == 10) {
    if ((("/" == checkStr.charAt(2))  && ("/" == checkStr.charAt(5))) || (("." == checkStr.charAt(2))  && ("." == checkStr.charAt(5)))) {
       if (isValidChars("0123456789", checkStr.substring(0,2)) && isValidChars("0123456789", checkStr.substring(3,5)) && isValidChars("0123456789", checkStr.substring(6,10))) {
         str = checkStr.substring(0,2);
         if ("0" == str.charAt(0)) 
            str = str.substring(1,2);
		 nDD   = parseInt(str);
         str = checkStr.substring(3,5);
         if ("0" == str.charAt(0)) 
            str = str.substring(1,2);
         nMM   = parseInt(str);
         nYYYY = parseInt(checkStr.substring(6,10));
         if (((nMM > 0) && (nMM <= 12)) && (nYYYY > 1990) && (nDD > 0)) {
           if (nDD <= DaysInMonth( nMM, isLeapYear(nYYYY))) {
              objInput.value = checkStr;
              return (true);
           }   
         }     
       }
    }
  }
//  alert(strErrMsg);
//  objInput.focus();
  return (false);
} // isDate
//---------------------------------------------------------------------------
function compareDate(objInput1,objInput2) {
  var nDD, nMM, nYYYY, str, strValue;
  var dDate1, dDate2;
  strValue = objInput1.value;
  str = strValue.substring(0,2);
  if ("0" == str.charAt(0)) 
     str = str.substring(1,2);
  nDD = parseInt(str);
  str = strValue.substring(3,5);
  if ("0" == str.charAt(0)) 
     str = str.substring(1,2);
  nMM   = parseInt(str);
  nYYYY = parseInt(strValue.substring(6,10));
  dDate1 = new Date(nYYYY, nMM, nDD, 0, 0, 0); 
  //
  strValue = objInput2.value;
  str = strValue.substring(0,2);
  if ("0" == str.charAt(0)) 
     str = str.substring(1,2);
  nDD = parseInt(str);
  str = strValue.substring(3,5);
  if ("0" == str.charAt(0)) 
     str = str.substring(1,2);
  nMM   = parseInt(str);
  nYYYY = parseInt(strValue.substring(6,10));
  dDate2 = new Date(nYYYY, nMM, nDD, 0, 0, 0); 
  return (dDate1 - dDate2);
}
//---------------------------------------------------------------------------
function isWide(objInput, numWidth, strErrMsg) {
 if (objInput.value.length > numWidth) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
 }
 return (true);
} // isWide
//---------------------------------------------------------------------------
function isFilled(objInput, numWidth, strErrMsg) {
 if (objInput.value.length <= numWidth) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
 }
 return (true);
} // isWide
//---------------------------------------------------------------------------
function isAmount (objInput, nBefore, nAfter, strErrMsg) { 
  var checkStr= objInput.value;
  var strBefore = "", strAfter = "", i;
  if (!isValidChars( "-.,0123456789", checkStr) || (checkStr.indexOf(".") != checkStr.lastIndexOf(".")) ) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  if (checkStr.indexOf("-") > 0)  {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    if (ch == ".") 
       break;
    if ((ch != ",") && (ch != "-")) 
       strBefore += ch;
  }     
if ((strBefore.length > nBefore) || (strBefore.length < 1)) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
}
if (checkStr.indexOf(".") != -1)  {
  for (i = checkStr.length-1; i >= 0;  i--) {
    ch = checkStr.charAt(i);
    if (ch == ".") 
       break;
    if (ch != ",") 
       strAfter += ch;
  }     
  if (strAfter.length > nAfter) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
}  
  return (true);
}
//---------------------------------------------------------------------------
function isAmountAbs (objInput, nBefore, nAfter, strErrMsg) { 
  var checkStr= objInput.value;
  var strBefore = "", strAfter = "", i;
  if (!isValidChars( ".,0123456789", checkStr) || (checkStr.indexOf(".") != checkStr.lastIndexOf(".")) ) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    if (ch == ".") 
       break;
    if ((ch != ",")) 
       strBefore += ch;
  }     
if ((strBefore.length > nBefore) || (strBefore.length < 1)) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
}
if (checkStr.indexOf(".") != -1)  {
  for (i = checkStr.length-1; i >= 0;  i--) {
    ch = checkStr.charAt(i);
    if (ch == ".") 
       break;
    if (ch != ",") 
       strAfter += ch;
  }     
  if (strAfter.length > nAfter) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
}  
  return (true);
}
//---------------------------------------------------------------------------
function isDigitWithDelim (objInput, nLength, strErrMsg) { 
  var str = "", i;
  var checkStr= objInput.value;
  if (!isValidChars( ",0123456789", checkStr)) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    if (ch != ",") 
       str += ch;
  }     
  if (str.length > nLength) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  return (true);
}
//---------------------------------------------------------------------------
function isAllDigit(objInput, strErrMsg) { 
  var checkStr= objInput.value;
  if (!isValidChars( "0123456789", checkStr)) {
    alert(strErrMsg);
    objInput.focus();
    return (false);
  }
  return (true);
} // isAllDigit
//---------------------------------------------------------------------------
function isSelected( selectObject, strErrMsg) { 

 if ((selectObject == null) || (selectObject.selectedIndex == 0)) {
    alert(strErrMsg);
    selectObject.focus();
    return (false);
 }
 return (true);
} // isSelected
//---------------------------------------------------------------------------
function isBlank( str ) {
	var isValid = false;
 	if ( isNull(str) || isUndef(str) || (str+"" == "") )
 		isValid = true;
	return isValid;
}  // isBlank
//---------------------------------------------------------------------------
function onDel(submitPage){
	var truthBeTold = window.confirm("Are you sure want to delete this record?");
	
	if (truthBeTold) {	//If User sure wants to delete record
		document.forms[0].action = submitPage+"?act=d";
		document.forms[0].submit();
	}  
	
	return true;
}//onDel
//---------------------------------------------------------------------------
function onCancel(submitPage){
	location.href = submitPage;
	
	return true;
}//onCancel
//----------------------------------------------------------------------------
function checkLen(obj, len, contr, req){
	var st = obj.value;

	if (req && (Trim(st).length == 0)){
			alert("You must enter text for " + contr + " .");
			obj.focus();			
			return(false);			
	}
	else{
		if (st.length > len){
			alert("The entered text for " + contr + " is too long. Maximal " + len + " characters are allowed!");
			obj.focus();			
			return(false);
		}
	}
		
	return(true);
}

function checkLenDe(obj, len, contr, req){

	var st = obj.value;

	if (req && (Trim(st).length == 0)){
			alert("Sie mussen fuer " + contr + " Text eingeben.");
			obj.focus();			
			return(false);			
	}
	else{
		if (st.length > len){
			alert("Der Text fuer " + contr + " ist zu lang. Es sind maximal " + len + " Zeichen erlaubt!");
			obj.focus();			
			return(false);
		}
	}
		
	return(true);
}
