// Begin BRS Validation Script (version 12.18.08)

	function validateForm(event) {
		var a,e,e2,good,msg;
		var i,inputs,input,value;
		
		good = true;
		msg = "";
		
		// check the text fields and radio buttons
		inputs = $('input.required', event.target );
		for(i=0; i<inputs.length; i++) {
			input = $(inputs.get(i));
			if(input.attr('type') == 'text') {
				value = input.val();
			} else if (input.attr('type') == 'radio') {
				value = $('input[name=' + input.attr('name') + ']:checked').val() ? "1" : "";
			} else {
				value = "1";
			}
			if(value.length == 0 ) {
				if(msg.length) msg = msg + "\n";
				if(input.attr('requirednote').length)
					msg = msg + "\t" + input.attr('requirednote');
				else 
					msg = msg + "\tThis field is required.";
				good = false;
			}
		}

		if(!good) {
			alert ("The following fields are required:\n" + msg);
			event.preventDefault();
		}
	
		$('#accesskey').val('j' + $('#accesskey').val() );
	}


// Begin OverLabel Scripts

function initOverLabels () {
  var labels, id, input;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = $('label.overlabel');
  for (var i = 0; i < labels.length; i++) {
		var theLabel = $(labels.get(i));
		
      // Skip labels that do not have a named association
      // with another field.
      id = theLabel.attr('for');
			input = $('#' + id);
      if (input.length != 1) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      theLabel.addClass( 'overlabel-apply' );

      // Hide any fields having an initial value.
      if (input.val() !== '') {
        hideLabel(input.attr('id'), true);
      }

			//alert(field.id);
      // Set handlers to show and hide labels.
      input.focus(function () {
        hideLabel($(this).attr('id'), true);
      } );
      input.blur(function () {
        if ($(this).val() == '') {
          hideLabel($(this).attr('id'), false);
        }
      } );

      // Handle clicks to LABEL elements (for Safari).
      theLabel.click(function () {
        var id, field;
        id = $(this).attr('for');
        if (id && (field = $('#' + id))) {
          field.focus();
        }
      });

  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = $('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = $(labels[i]).attr('for'); 
    if (field_for == field_id) {
      $(labels[i]).css('text-indent', (hide) ? '-1000px' : '0px' );
      //labels[i].className = 'overlabel-marker'; `BKS
      return true;
    }
  }
}

function setRequiredFields(fieldarray) {
	var i;
	for(i=0; i<fieldarray.length; i++) {
		$('#' + fieldarray[i][0]).attr('requirednote', fieldarray[i][1]);
	}
}

$(document).ready(function() {
	setTimeout(initOverLabels, 50);
	
	// Create cross browser button hover `BKS
	$('input[@class="button"]').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	);
});
