jQuery.fn.enable = function() {
  return this.each(function() {
    this.disabled = false;
  });
};

function Global() {
  this.ckEditorHeight = 600;
  this.ckEditorWidth = 700;
  this.fieldHighlightColor = '#FFCC66';
  this.fieldHighlightColorClear = '#FFFFFF';


  this.setupCkEditor = function(height, width){
    this.ckEditorHeight = height;
    this.ckEditorWidth = width;
  }
  this.submit = function(id) {
    $('#'+id).submit();    
  }

  this.validateFields = function(fields) {
    var errorArray = new Array();
    for (var i=0; i < fields.length; i++) {
      var check = true;
      try { check = this.validateSingleField(fields[i]); } catch (e) { check = true; }
      if (!check) {
        errorArray[errorArray.length] = fields[i];
      }
    }
    return errorArray;
  }

  this.validateFieldsWithDefaults = function(fields, defaults) {
    var errorArray = new Array();
    for (var i=0; i < fields.length; i++) {
      var check = true;
      try {
        if ($('#'+fields[i]).val().length == 0 || $('#'+fields[i]).val() == defaults[i]) {
          check = false;
        }
      } catch (e) {
        check = true;
      }
      if (!check) {
        errorArray[errorArray.length] = fields[i];
      }
    }
    return errorArray;
  }
  
  this.validateSingleField = function(id) {
    if (this.isSelect(id)) {
      var selected = $('select#'+id).val();
      if (selected <= -1) {
        return false;
      }
    } else {
      if ($('#'+id).val().length == 0) {
        return false;
      }
    }
    return true;
  }
   
  this.checkPasswords = function() {
    var one = $('#loginPassword').val();
    var two = $('#loginPasswordConfirm').val();
    if (one == two) {
      return true;
    } else {
      $('#loginPassword').val('');
      $('#loginPasswordConfirm').val('');
      $G.processErrors(new Array('loginPassword','loginPasswordConfirm'), this.errorMessagePasswords, this.errorMessagePasswordsID);
      $('#loginPassword').focus();
      return false;
    }
  }
  
  this.isCheckbox = function(id) {
    if ($('#'+id).attr('type') == 'checkbox') {
      return true;
    }
    return false;
  }
  
  this.isSelect = function(id) {
    var value = $('select#'+id).val();
    if (undefined != value) {
      return true;
    }
    return false;
  }
  
  this.resetErrors = function(fields, errorMessageID) {
    $('#'+errorMessageID).html('');
    for (var i=0; i < fields.length; i++) {
      try { $('#'+fields[i]).css('background-color', this.fieldHighlightColorClear); } catch (e) { }
    }
  }
  
  this.processErrors = function(errorArray, errorMessage, errorMessageID) {
    $('#'+errorMessageID).html(errorMessage);
    for (var i=0; i < errorArray.length; i++) {
      $('#'+errorArray[i]).css('background-color', this.fieldHighlightColor);
    }    
  }
  
  this.getLoader = function(message, target) {
    $.get("/loader.jsp?loaderMessage="+message, function(data) {
      $('#'+target).html($.trim(data));
    });
  }  
  
  this.getLoaderImageOnly = function(target) {
    $.get('/loaderImageOnly.jsp', function(data) {
      $('#'+target).html($.trim(data));
    });
  }

  this.changeClass = function(obj, className) {
    document.getElementById(obj).className = className;
  }
  
  this.formatTableRows = function(tableId, classOdd, classEven) {  // Use this function on tables that have the bg color in the rows <tr>
    if (undefined == classOdd || null == classOdd) { classOdd = 'dataTableRow2a'; } // set optional classOdd value
	if (undefined == classEven || null == classEven) { classEven = 'dataTableRow1a'; }  // set optional classEven value
	var tableObj = $('#'+tableId+' tr').each(function(i) {
  	  if (i > 0) {
	    if (this.className == classOdd || this.className == classEven) { // only effect rows with the odd or even CSS classes
	      if (i % 2 == 0) { // even
	        this.className = classEven;
	        $('#'+this.id).mouseover(function() { $G.changeClass(this.id,'dataTableRowOver'); });
	        $('#'+this.id).mouseout(function() { $G.changeClass(this.id,classEven); });
	      } else { // odd
	        this.className = classOdd;
	        $('#'+this.id).mouseover(function() { $G.changeClass(this.id,'dataTableRowOver'); });
	        $('#'+this.id).mouseout(function() { $G.changeClass(this.id,classOdd); });
	      }
	    }
   	  }
    });
  }
  
  this.execFunctionArray = function() {
  	if (undefined!= funcArray && null != funcArray && funcArray.length > 0) {
  		for (var i=0; i < funcArray.length; i++) {
  			// alert(funcArray[i]);
  			var t = setTimeout(funcArray[i], 0);
  		}
  		funcArray = new Array();
  	}
  }
  
  this.isIE6_7 = function() {
    return this.isIE([6, 7]);
  }
  
  this.isIE = function(version) {
    if ($.browser.msie) {
      if (undefined == version) {
        return true;
      } else {
        for (var i=0; i < version.length; i++) {
          if ($.browser.version.charAt(0) == version[i]) {
            return true;
          }
        }
      }
    }
    return false;
  }

  this.isIE6 = function() {
    if ($.browser.msie && $.browser.version.charAt(0) == '6') {
      return true;
    }
    return false;
  }
  
}

function blank() {
  //
}

var $G = new Global();
