<!--
//-------------------------------------------------------------------------------
// G L O B A L   V A R I A B L E S 
//-------------------------------------------------------------------------------
var gsAlert;
var gbRaiseOnLoadEvent = false ;
//-------------------------------------------------------------------------------
// G L O B A L   F U N C T I O N S
//-------------------------------------------------------------------------------
function WindowOnLoad() {
  //if(!CheckSystem()){return;}
  CheckSystem() ;
  if(gbRaiseOnLoadEvent) {
    WindowOnLoadEvent() ;}
}
//-------------------------------------------------------------------------------
function CheckSystem() {
  // obtain browser application name
  var appName = window.navigator.appName ;
  // check browser application name
  if (appName!="Microsoft Internet Explorer") {
    GoToPage('TextBrowser.asp') ;
    //window.alert(BROWSER_TYPE) ;
    return false;}
  return true ;  
}
//-------------------------------------------------------------------------------
function GoToPage(aPage){
  var arrURL = aPage.split("?") ;
  var objRE = /.pdf/ig ;
  var strFeatures = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,copyhistory=no,resizable=yes" ;
  if(objRE.test(arrURL[0])) {
    window.open(aPage, "_blank", strFeatures) ; }
  else {  
    SetCursor("wait") ;
    DisableInputType("BUTTON", true) ;
    window.location = aPage ; }
}
//-------------------------------------------------------------------------------
function SubmitToServer(aForm){
  DisableForm(false) ;
  SetCursor("wait") ;
  DisableInputType("BUTTON", true) ;
  aForm.submit() ;
}
//-------------------------------------------------------------------------------
function DisableInputType(aType, aLockStatus) {
  var strType ;
  var arrInput = document.getElementsByTagName("INPUT") ;
  for (var i=0; i < arrInput.length; i++) {
    strType = arrInput[i].type.toUpperCase() ;
    if(strType==aType) {
      Disable(arrInput[i], aLockStatus) ; }}
}
//-------------------------------------------------------------------------------
function CatchJSError() {
  // empty
}
//-------------------------------------------------------------------------------
function SetCursor(aCursorType) {
  document.body.style.cursor = aCursorType ;}
//-------------------------------------------------------------------------------
// Disable or enable form elements
function Disable(aFormItem, aLockStatus) {
  if(aFormItem==null){return;}
  var strClassEnabled, strClassDisabled ;
  var strObjectType = aFormItem.type;
  var strClassName ;
  switch (strObjectType.toUpperCase()) {
    case "SELECT-ONE" :
    case "TEXT" :  
    case "TEXTAREA" :  
      strClassEnabled = "InputEnabled" ;
      strClassDisabled = "InputDisabled" ;
      break ;
    case "BUTTON" :
      strClassName = aFormItem.className.toUpperCase() ;
      if(strClassName=="BUTTONSMALL") {
        strClassEnabled = "ButtonSmall" ;
        strClassDisabled = "ButtonSmall" ;
      }
      else {
        strClassEnabled = "ButtonEnabled" ;
        strClassDisabled = "ButtonDisabled" ;
      }
      break ; }
  if (aLockStatus==true) {
    aFormItem.disabled=true ;
    aFormItem.className=strClassDisabled ; }
  else {
    aFormItem.disabled=false ;
    aFormItem.className=strClassEnabled ; }
}
//-------------------------------------------------------------------------------
function DisableForm(aLockStatus) {
  var arrInput = document.getElementsByTagName("INPUT") ;
  var arrSelect = document.getElementsByTagName("SELECT") ;
  for (var i=0; i < arrInput.length; i++) {
    Disable(arrInput[i], aLockStatus) ; }
  for (i=0; i < arrSelect.length; i++) {
    Disable(arrSelect[i], aLockStatus) ; }
}
//-------------------------------------------------------------------------------
// Trim the string passed as an argument
function Trim(aString) {
  var re1 = /^\s*/g ; // white spaces at the beginning of the string
  var re2 = /\s*$/g ; // white spaces at the end of the string
  aString = aString.replace(re1, "") ;
  aString = aString.replace(re2, "") ;
  return aString ;
}  
//-------------------------------------------------------------------------------
function DisplayAlert(aFormItem, aAlert) {
  alert(aAlert) ;
  aFormItem.focus() ;
  switch(aFormItem.tagName){
    case "SELECT" :
    case "OPTION" :
      return ;
      break ;
    default :
      aFormItem.select() ; }
}
//-------------------------------------------------------------------------------
function CheckIsNotEmpty(aFormItem) {
  if(aFormItem.getAttribute("mandatory")=="true") {
    if(Trim(aFormItem.value).length==0){
      gsAlert = FIELD_ENTERED.replace("%1", aFormItem.title) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; }}
  return true ;
}
//-------------------------------------------------------------------------------
function CheckMinLength(aFormItem) {
  var minLength = aFormItem.getAttribute("minlength") ;
  var actualLength = Trim(aFormItem.value).length ;
  if(minLength!=null){
    if (actualLength < minLength) {
      gsAlert = FIELD_MIN_LENGTH.replace("%1", aFormItem.title) ;
      gsAlert = gsAlert.replace("%2", minLength) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; } }
  return true ;
}
//-------------------------------------------------------------------------------
function CheckMaxLength(aFormItem) {
  var maxLength = aFormItem.getAttribute("maxlength") ;
  var actualLength = Trim(aFormItem.value).length ;
  if(maxLength!=null){
    if (actualLength > maxLength) {
      gsAlert = FIELD_MAX_LENGTH.replace("%1", aFormItem.title) ;
      gsAlert = gsAlert.replace("%2", maxLength) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; } }
  return true ;
}
//-------------------------------------------------------------------------------
function CheckFormat(aFormItem) {
  // don't check expressions of empty non mandatory fields
  if(Trim(aFormItem.value).length==0 && aFormItem.getAttribute("mandatory")!="true") {return true ;}
  var re = aFormItem.getAttribute("regexp") ;
  if (re!=null) {
    re = new RegExp(re, "i") ;
    if (!re.test(Trim(aFormItem.value))) {
      gsAlert = FIELD_CONTENT.replace("%1", aFormItem.title) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; }} 
  return true ;
}
//-------------------------------------------------------------------------------
function CheckMinValue(aFormItem) {
  var minValue = aFormItem.getAttribute("minvalue") ;
  if (minValue!=null) {
    if (parseInt(aFormItem.value)<parseInt(minValue)) {
      gsAlert = FIELD_MIN_VALUE.replace("%1", aFormItem.title) ;
      gsAlert = gsAlert.replace("%2", minValue) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; }} 
  return true ;
}
//-------------------------------------------------------------------------------
function CheckMaxValue(aFormItem) {
  var maxValue = new String(aFormItem.getAttribute("maxvalue")) ;
  if (maxValue!=null) {
    if (parseInt(aFormItem.value)>parseInt(maxValue)) {
      gsAlert = FIELD_MAX_VALUE.replace("%1", aFormItem.title) ;
      gsAlert = gsAlert.replace("%2", maxValue) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; }} 
  return true ;
}
//-------------------------------------------------------------------------------
function CheckFormElement(arrFormItem) {
  var strObjectType ;
  // for all input fields in the array ...
  for(var i=0; i<arrFormItem.length; i++) {
    // check only text fields, passwords and textareas
    strObjectType = arrFormItem[i].type;
    switch (strObjectType.toUpperCase()) {
      case "TEXT" :
      case "PASSWORD" :
      case "TEXTAREA" :
      case "FILE" :
        // check if value in this field is mandatory
        if (arrFormItem[i].getAttribute("disabled")==false && arrFormItem[i].type!="hidden") {
          // check if value for the required field is entered
          if (!CheckIsNotEmpty(arrFormItem[i])) {return false;}
          // check for minimal length if applicable
          if (!CheckMinLength(arrFormItem[i])) {return false;}
          // check for maximal length if applicable
          if (!CheckMaxLength(arrFormItem[i])) {return false;}
          // check for pattern if applicable
          if (!CheckFormat(arrFormItem[i])) {return false;}
          // check for minimal value if applicable
          if (!CheckMinValue(arrFormItem[i])) {return false;}
          // check for maximal value if applicable
          if (!CheckMaxValue(arrFormItem[i])) {return false;}   }
    }
  }
  return true ;
}
//-------------------------------------------------------------------------------
function CheckSelect(arrFormItem) {
// for all input fields in the array ...
  for(var i=0; i<arrFormItem.length; i++) {
    if(!CheckSelectItem(arrFormItem[i])) { return false ; }
  }  
  return true ;
}
//-------------------------------------------------------------------------------
function CheckSelectItem(aFormItem) {
  // check if value in this field is mandatory
  if (aFormItem.getAttribute("disabled")==false) {
    if(aFormItem.getAttribute("mandatory")=="true" && parseInt(aFormItem.value,10)==0){
      gsAlert = COMBO_SELECTED.replace("%1", aFormItem.title) ;
      DisplayAlert(aFormItem, gsAlert) ;
      return false ; }}
  return true ;    
}
//-------------------------------------------------------------------------------
function ValidateForm(aForm) {
  var arrSelect = aForm.getElementsByTagName("SELECT") ;
  var arrInput = aForm.getElementsByTagName("INPUT") ;
  var arrTextArea = aForm.getElementsByTagName("TEXTAREA") ;
  if(!CheckSelect(arrSelect)) { return false ;}
  if(!CheckFormElement(arrInput)) { return false ;}
  if(!CheckFormElement(arrTextArea)) { return false ;}
  return true ;
}
//-------------------------------------------------------------------------------
function Login() {
  // note: leave name form as is otherwise error occur - duplicate form names for pages where
  // user is not logged in
  if (!ValidateForm(document.frmLogin)) {return false;}
  SetCursor("wait") ;
  return true ;
}
//-------------------------------------------------------------------------------
// don't allow the user to enter spaces
function CheckKey() {
  if (window.event.keyCode==32) {
    window.event.returnValue=false ; }}
//-------------------------------------------------------------------------------
function CheckKeyChar() {
  var re = /\w/ ;   // any letter, numeral or underscore
  var strChar = String.fromCharCode(window.event.keyCode) ;
  if(re.test(strChar)==false) {
    window.event.returnValue=false ;}
}    
//-------------------------------------------------------------------------------
function CheckKeyNumber(aNumberType) {
  var re ;  
  var strChar = String.fromCharCode(window.event.keyCode) ;
  switch (aNumberType) {
    case 1 : //positive integer
      re = /\d/ ;
      break ;
    case 2 : //positive and negative integer
      re = /(\d|\-)/ ;
      break ;
    case 3 : //positive decimal
      re = /(\d|\.)/ ;
      break ;
    case 4 : //positive and negative decimal
      re = /(\d|[\.\-])/ ;
      break ;  
  }
  if(re.test(strChar)==false) {
    window.event.returnValue=false ;}
}
//-------------------------------------------------------------------------------
// Prevents users changing content of the combo box by locking it
function LockCombo() {
  var colInput = document.getElementsByTagName("SELECT") ;
  for(var i=0;i<colInput.length;i++){
    Disable(colInput[i], true) ; }
}
//-------------------------------------------------------------------------------
function GetOptionItemValueSelected(aCombo) {
  for(var i=0;i<aCombo.options.length; i++) {
    if(aCombo.options[i].selected==true) {
      return aCombo.options[i].value ;}}
}
//-------------------------------------------------------------------------------
//-->
