/**
 * The fieldMaxLength function limits the length of a field
 * to that which is defined in its maxlength attribute.
 * Mainly useful for textarea fields, and ideally called for
 * onKeyDown and onKeyUp events.
 *
 * Due to variations in javascript implementation, this
 * function *actually* limits field length to maxlength - 1.
 *
 * @author nwinant
 */
function fieldMaxLength(field) {
    var maxlength = jQuery(field).attr("maxlength");
    if (field.value.length >= maxlength) // if too long, trim.
    	field.value = field.value.substring(0, maxlength-1);
}


/**
 * The overlabel works with CSS to place text input labels 
 * "inside" the text field and hides the labels when the
 * input is in focus or when the input field has a value.
 *
 * the label and input field must be enclosed in a div or
 * span with the class of "overlabel_container" to set
 * relative positioning on the input field. For examples
 * of implementation, see the Build A List range (between) fields.
 */

/*function initOverLabels () {
	  if (!document.getElementById) return;      

	  var labels, id, field;

	  // Set focus and blur handlers to hide and show 
	  // labels with 'overlabel' class names.
	  labels = document.getElementsByTagName('label');
	  for (var i = 0; i < labels.length; i++) {

	    if (labels[i].className == 'overlabel') {

	      // Skip labels that do not have a named association
	      // with another field.
	      id = labels[i].htmlFor || labels[i].getAttribute('for');
	      if (!id || !(field = document.getElementById(id))) {
	        continue;
	      } 

	      // Change the applied class to hover the label 
	      // over the form field.
	      labels[i].className = 'overlabel-apply';

	      // Hide any fields having an initial value.
	      if (field.value !== '') {
	        hideLabel(field.getAttribute('id'), true);
	      }

	      // Set handlers to show and hide labels.
	      field.onfocus = function () {
	        hideLabel(this.getAttribute('id'), true);
	      };
	      field.onblur = function () {
	        if (this.value === '') {
	          hideLabel(this.getAttribute('id'), false);
	        }
	      };

	      // Handle clicks to label elements (for Safari).
	      labels[i].onclick = function () {
	        var id, field;
	        id = this.getAttribute('for');
	        if (id && (field = document.getElementById(id))) {
	          field.focus();
	        }
	      };

	    }
	  }
	};

	function hideLabel (field_id, hide) {
	  var field_for;
	  var labels = document.getElementsByTagName('label');
	  for (var i = 0; i < labels.length; i++) {
	    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
	    if (field_for == field_id) {
	      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
	      return true;
	    }
	  }
	}

	window.onload = function () {
	  setTimeout(initOverLabels, 50);
	};*/

jQuery(document).ready(function(){
    //Stripe Tables
    jQuery("table.stripeMe tbody tr:odd td").addClass("odd");

    initHelptips();
});
function initHelptips() {
    var helptip = jQuery('a.helptip, a.helpInstr');
    //Checks to see if these elements exist on the page, then initializes them
    if(helptip.length > 0) {
        helptip.unbind();
        helptip.cluetip({
            width:300,
            positionBy: 'bottomTop',
            topOffset:16,
            attribute: 'href',
            showTitle: true,
            cluetipClass: 'hoovers',
            waitimage: false,
            arrows: true,
            dropShadow: false,
            dropShadowSteps: 0,
            sticky: true,
            activation: 'click',
            closePosition: 'title',
            closeText: '',
            fx: {
                open: 'fadeIn'
            },
            ajaxCache: true
        });
        if (jQuery.browser.msie && /6.0/.test(navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent)) {
            helptip.bgiframe();
        }
    }
}