$(function() {


// Finds a form on the page, instantiates a Calendar Popup and hides "other" fields if necessary
	$(this).find("form").each(function() {
		if ( window.CalendarPopup ) {
			// instantiate CalendarPopup and set some params
			
			// Sets starting date by yesterdays date
			var yesterday = new Date();
			yesterday.setDate( yesterday.getDate() - 1 );
			
			// new instance of Calendar popup
			cal = new CalendarPopup( "cp" );
			cal.addDisabledDates( null, formatDate( yesterday, "MM/dd/yyyy" ) );
			
			// create the <div> for calendar popup
			$("body").append("<div id=\"cp\"></div>");
		}
		//set focus background color for IE
		if (document.all) {
			$(".textfield").focus(function() {
				$(this).css({background: "fdfcfa"});
			});
			$(".textfield").blur(function() {
				$(this).css({background: "ffffff"});
			});
		}
		// hide all "other" fields
		$("ul.checkboxgroup input.other").filter(".textfield").hide();
		$("ul.checkboxgroup input").click(function() {
			// if the input has a class of other, show it's "other" field
			if ($(this).is(".other")){
				$(this).siblings(".other").show().addClass("required");
				// if it's a checkbox, remove the "other" field when it is unchecked
				if (!this.checked) {
					$.removeWarning($(this));
					$(this).siblings(".other").filter(".textfield").hide().removeClass("required");
				}
			}
			// if it's a radio button group, hide "other" fields if not needed
			else if ($(this).is(".radio")) {
				$.removeWarning($(this));
				$(this).parent().parent().find(".other").filter(".textfield").hide().removeClass("required");
			}
		});
		// hide all "select-other" divs
		$("div.select-other").hide();
		// if "Other" is selected, then show it's "other" field
		$("select.select-other").change( function () {
			if($(this).val() === "--") {
				$(this).parent().next().show();
				if($(this).is(".required")) {
					$(this).parent().next().find("label").addClass("required");
					$(this).parent().next().find("input").addClass("required");
				}
			} else {
				$(this).parent().next().hide().find("input").val("");
			}
		});
	});




});

function validate( frm ) {

	var returnValue = false;
	
	if ( BlankField( frm.prefix.value ) ) {
		alert ( "Please select a prefix." );
		frm.prefix.focus();
	
	} else if ( BlankField( frm.first_name.value ) ) {
		alert ( "Please enter your first name." );
		frm.first_name.focus();
	
	} else if ( BlankField( frm.last_name.value ) ) {
		alert ( "Please enter your last name." );
		frm.last_name.focus();
	
	} else if ( BlankField( frm.phone.value ) ) {
		alert ( "Please enter your telephone number." );
		frm.phone.focus();
	
	} else if ( !ValidEmail( frm.email.value ) ) {
		alert ( "Please enter a valid email address." );
		frm.email.focus();

	} else {
		returnValue = true;
		document.getElementById( "submit" ).disabled = "true";
	}
	
	return returnValue;

}