var isExplorer = /msie/i.test(navigator.userAgent)
                 && !/opera/i.test(navigator.userAgent);

var lsBaseLoc    = getBaseLoc();
var lsImagesLoc  = getImagesLoc();

function paginate(newPageNum, formName) {
  $j("#currentPage").val(newPageNum);
  submitForm(formName);
}


/**
 *  This function submits a form. It will check to see if an onsubmit function
 *  is present; if one is, that method will be called before the form is
 *  submitted and be given the opportunity to cancel the submission.
 *
 *  @param string form_name The name of the form to be submitted.
 */
function submitForm(form_name) {
  eval('var form = document.' + form_name + ';');

  // Submit the form, calling its onsubmit method first, if present.
  if (form) {
    if (typeof form.onsubmit == "function") {
      // Make sure the onsubmit function is run and doesn't return false.
      if (form.onsubmit()) {
        form.submit();
      }
    } else {
      form.submit();
    }
  }
}

function updateInputCounter(element, maxLen, countDownElementId) {
  if($j(element) && 
     $j("#"+countDownElementId) &&
     element.value.length <= maxLen) {
    $j("#"+countDownElementId).text(maxLen - element.value.length);
  }
}

/**
 * Prevents the user from typing too many characters in an 
 * input element (specifically for textarea elements since
 * there is no maxlength attribute for them)
 */
function limitInputLength(element, maxLen, countDownElementId) {
  if (element.value.length > maxLen) {
		$j(element).val(element.value.substring(0, maxLen));
	} 
	
	updateInputCounter(element, maxLen, countDownElementId);
}
  

/*
 * An IE safe way to log messages to the Firebug console.   Use this function
 * instead of calling "console.log" directly to help prevent breaking IE
 *
 * @param message string  The message you want to print to the console
 * @author gbruins
 */
function c(message) {
  if (window.console && console.log) {
    console.log(message);
  }
}


function strip_html_tags(dirtyText, escapeText) {
  var escapeText = escapeText || false;
  var ajaxUrl = getAjaxLoc();
	$j.ajax({
  	type: "POST",
  	data: ({ 
					'dirty': dirtyText,
					'escape': escapeText
				}),
  	url: ajaxUrl + "strip_html_tags.php",
  	success: function(msg){
  	 return(msg);
  	}
	});
}


/* Validator object */
var Validator = {

  isNull: function(val) {
    return(val == null);
  },
  
  /* 
   * Returns true if value only contains spaces
   */
  isBlank: function(val){
    c("val is "+val);
  	if(Validator.isNull(val)){
  	  return true;
  	}
  	for(var i=0; i<val.length; i++) {
  	  c(val.charAt(i));
  		if ((val.charAt(i) != ' ') &&
  		    (val.charAt(i)!="\t") &&
  		    (val.charAt(i)!="\n") &&
  		    (val.charAt(i)!="\r")){
  	    return false;
  		}
  	}
  	return true;
  },
  
  /*
   * Returns true if value is a 1-character digit
   */
  isDigit: function(num) {
  	if (num.length > 1){
  	  return false;
  	}
  	
  	var string="1234567890";
  	if (string.indexOf(num) != -1){
  	  return true;
  	}
  	return false;
  },
  
  /*
   * Returns true if value contains all digits
   */
  isInteger: function(val){
  	if(Validator.isBlank(val)){
  	  c("is blank");
  	  return false;
    }
    
  	for(var i=0; i<val.length; i++){
  		if(!Validator.isDigit(val.charAt(i))){
  		  return false;
  		}
  	}
  	return true;
  },
  
  /*
   * Returns true if value contains a positive float value
   */
  isNumeric: function(val){
    return( parseFloat(val,10) == (val*1));
  },
  
  /* 
   * Returns true if the object is an array, else false
   */
  isArray: function(obj){
    return(typeof(obj.length) == "undefined") ? false : true;
  }
}