/**********************************************************************
Function SWD5Search (to validate form input)
***********************************************************************/
function SWD5Search(oForm, sDateFormat){

  if(oForm.fldDateFrom != undefined){
    // Field exists        
    if(!CheckDateTime(oForm.fldDateFrom, sDateFormat)){
      return false; 
    }
  }

  if(oForm.fldDateUntil != undefined){
    // Field exists    
    if(!CheckDateTime(oForm.fldDateUntil, sDateFormat)) {
      return false;
    }
  }
  
  return true;
}

/**********************************************************************
Function CheckDateTime 

Note: 
- date is compulsory and must contain "YYYY", "MM" and "DD" 
- time is optional and (if set) must contain "HH", "NN" and "SS"
***********************************************************************/
function CheckDateTime(oField, sDateFormat){
  var i;
  var cDF,cV;
  var sValue;
  
  sValue = oField.value

  // Check date if set 
  if(sValue != ""){
    if(sDateFormat.length != sValue.length){  
      ShowMsgInvalidDate(oField,sValue,sDateFormat);	
      return false; 
    }

    // Check format char by char
    for (i=0; i < sDateFormat.length; i++){         
      cDF = sDateFormat.charAt(i);            

      switch(cDF){
        case "Y": // Part of year
        case "M": // Part of month
        case "D": // Part of day          
        case "H": // Part of hours          
        case "N": // Part of minutes          
        case "S": // Part of seconds          
          cV = sValue.charAt(i);

          if(cV<"0" || cV>"9"){
            ShowMsgInvalidDate(oField,sValue,sDateFormat);	        
	    return false;  
          }
          break;

        default: // Seperators
          cV = sValue.charAt(i);

          if(cV != cDF){
            ShowMsgInvalidDate(oField,sValue,sDateFormat);	        
            return false;  
          }  
          break;
      }  
    }
  }

  return true;
}

/**********************************************************************
Function ShowMsgInvalidDate
***********************************************************************/
function ShowMsgInvalidDate(oField, sDate, sDateFormat){
  alert("Datum '" + sDate + "' voldoet niet aan formaat '" + sDateFormat +"'!");
  oField.focus();
  oField.select();
  return true;
}
