   // -------------------------------------------------------------------
   // Implementado o indexOf do arrat, pode ser melhorado
   // para a busca binária depois 
   // -------------------------------------------------------------------   
   Array.prototype.compareCustom = function ( a, b) {
      try {
         if ( a.toLowerCase() < b.toLowerCase() ) {
            return -1  
         } else {
            if ( a.toLowerCase() > b.toLowerCase() ) {
               return 1  
            } else {
               return 0
            }      
         }
      } catch (e) {      
         if ( Number(a) < Number(b) ) {
            return -1  
         } else {
            if ( Number(a) > Number(b) ) {
               return 1  
            } else {
               return 0
            }      
         }		 		 
	  }
   }
        
   Array.prototype.indexOf = function ( value) {
      //this.sort( this.compareCustom)
      for ( var i = 0; i < this.length; i++ ) {
	     if ( this[i] == value ) {
	        return i
	     }
      }	 
	  return -1
   }

   function CustomArray () {
      this.itens = new Array()
	  
	  this.push    = function ( ar ) {
	     this.itens.push(ar)
		 this.length += 1
	  }
	  
	  this.indexOf = function ( value ) {
         for ( var i = 0; i < this.itens.length; i++ ) {
	        if ( this.itens[i][0] == value ) {
	           return this.itens[i][1]
	        }
         }	 
		 return -1
	  }
	  
	  this.length = 0 
	  
   }

   // -------------------------------------------------------------------
   // Implementação de objetos para automatizar a criação doe forms
   // -------------------------------------------------------------------   
   function Form ( name, method, action ) {
	  // -------------------------------
      // Properties
	  // -------------------------------	  
	  this.name   = name
	  this.method = method
	  this.action = action
	  //	  
      this.formFields = new CustomArray()
	  
	  // -------------------------------
	  // Methods
	  // -------------------------------
      this.formField = function (name, type, valueDefault ) {
	     var indexField = this.formFields.indexOf(name)
	     if ( indexField >= 0 ) {
		    return this.formFields.itens[indexField][1]
		 } else {
		    var result = new FormField( name, type, valueDefault)
		    this.formFields.push([name, result])
			return result
		 }
	  } 
	  
	  this.create = function () {
	     var arResult = new Array()
		 arResult.push('<form name="' + this.name + '" method="' + this.method + '" action="' + this.action + '">/r/n')
		 for ( var i = 0; i < this.formFields.length; i++ ) {
		    //arResult.push(   
		 }
	  }
   }
   
   function FormField ( name, type, valueDefault ) {
      this.name         = name
      this.type         = type
      this.valueDefault = valueDefault
   }   
   
   
   // -------------------------------------------------------------------
   // Conatantes e pequenas funções usadas em todo o site
   // -------------------------------------------------------------------
   
	// Dates
   var now = new Date()
   function getDateString( date, dateSeparator, onlyHour, hourSeparator) {  
	   if ( onlyHour ) {
         if ( !hourSeparator ) {
	         hourSeparator = ':'
	      }
		   var hours   = ( now.getHours()   < 10 ? '0' + now.getHours()   : now.getHours() )
			var minutes = ( now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes() )
			return hours + hourSeparator + minutes
	   } else {
		   if ( date ) {
			   now = date
			}
			if ( !dateSeparator ) {
			  dateSeparator = '/'
			}
			var day   = ( now.getDate()         < 10 ? '0' + now.getDate()         : now.getDate() )
			var month = ( ( now.getMonth() + 1) < 10 ? '0' + ( now.getMonth() + 1) : ( now.getMonth() + 1) )
			var year  = now.getFullYear()
			return day + dateSeparator + month + dateSeparator + year
	   }
   }
	
	// Forms
   function submitForm () {
	   var arResult = new Array()
		arResult.push('Os seguintes campos são obrigatórios:\r\n\r\n')
	   for ( var i = 0; i < document.forms[0].elements.length; i++ ) {
		   if ( document.forms[0].elements[i].required == '1' && document.forms[0].elements[i].value == '') {
		      arResult.push(' - ' + document.forms[0].elements[i].id + '\r\n')
			}	
		}	  
		if ( arResult.length > 1 ){
		   alert(arResult.join(''))
			document.forms[0].elements[0].focus()
			return false
		} 
		document.forms[0].submit()
		return true
	}
	
	function formatValue ( sender ) {
	   if ( sender.dataType == 'date') {
		   if ( ( sender.value.length == 2 && sender.value.indexOf('/') < 0 ) || ( sender.value.length == 5  ) ) {
			   sender.value = sender.value + '/'
			}
		} else {
			if ( sender.dataType == 'hour') {
				if ( ( sender.value.length == 2 && sender.value.indexOf(':') < 0 ) ) {
					sender.value = sender.value + ':'
				}
			}		
		}
	}
	
	function getHelp( helpText) {
	   if ( helpText) {
	      document.write('&nbsp;<a href="javascript:void(0)" onClick="alert(\'' + helpText + '\')"><span class="admLabel">[?]</span></a>')
		}	
	}
	
   // ---------------------------------------
   // Funções para trabalhar com janelas
   // ---------------------------------------
	
   function openPoupUpWindow( urlToOpen, width, height, scrollBars, onCloseEvent) {
	   if ( scrollBars) {
//		   scrollBars = ( scrollBars == 1 ? 'yes' : 'no')
		} else {
		   scrollBars = 'yes'
		}
		
		if ( !width  ) { width  = 800 } 
		if ( !height ) { height = 550 } 		

      var poupUpWindow = open( urlToOpen, '','toolbar=no,scrollbars=' + scrollBars + ',resizable=no,titlebar=yes,location=no,directories=no,width=' + width + ',height=' + height)
      poupUpWindow.focus()

		if ( onCloseEvent) {
		   poupUpWindow.document.onunload = onCloseEvent
		}
	}	
	var targetListToDelete = null
	function checkCheckBox( keyList, checkBoxName ) {
	   if ( keyList) {
			var arKeyList = keyList.split(',')
			for ( var i = 0; i < document.forms[0].elements.length; i++) {
				if ( document.forms[0].elements[i].name.toLowerCase() == checkBoxName.toLowerCase() && arKeyList.indexOf( document.forms[0].elements[i].value) >= 0) {
					document.forms[0].elements[i].checked = true
				}
			}
	   }	
	}