$(document).ready(function() { 
    // Toggle the registration lists
    $(".registration_item").click( function() {
	// console.log("I got clicked.");
	$(this).children().toggle();
    });

    //Handle jquery change event for IE
    if ($.browser.msie) {
    	$("#copy_personal").click(function() {
    	    this.blur();
    	    this.focus();
    	});
    }

    // Copy personal to billing information
    $("#copy_personal").change(function() {
	//console.log("I got clicked.");
	if(this.checked) {
	    //console.log("I am checked.");
	    $("#bill_name").val($("#student_name").val());
	    $("#bill_street_1").val($("#street_1").val());
	    $("#bill_street_2").val($("#street_2").val());
	    $("#bill_city").val($("#city").val());
	    $("#bill_state").val($("#state").val());
	    $("#bill_zip").val($("#zip").val());
	} else {
	    //console.log("not any more.");
	    $("#bill_name").val("");
	    $("#bill_street_1").val("");
	    $("#bill_street_2").val("");
	    $("#bill_city").val("");
	    $("#bill_state").val("");
	    $("#bill_zip").val("");
	}
	
    });

    //Handle jquery change event for IE
    if ($.browser.msie) {
    	$("#membership_personal").click(function() {
    	    this.blur();
    	    this.focus();
    	});
    }

    // Copy personal to billing information
    $("#membership_personal").change(function() {
	//console.log("I got clicked.");
	if(this.checked) {
	    //console.log("I am checked.");
	    $("#bill_name").val($("#first_name").val()+" "+$("#last_name").val());
	    $("#bill_street_1").val($("#street_1").val());
	    $("#bill_street_2").val($("#street_2").val());
	    $("#bill_city").val($("#city").val());
	    $("#bill_state").val($("#state").val());
	    $("#bill_zip").val($("#zip").val());
	} else {
	    //console.log("not any more.");
	    $("#bill_name").val("");
	    $("#bill_street_1").val("");
	    $("#bill_street_2").val("");
	    $("#bill_city").val("");
	    $("#bill_state").val("");
	    $("#bill_zip").val("");
	}
	
    });

// Toggle the Join Now Form for Billing
    // $("#kwtc_join_now").click(function() {
    // 	// console.log("clicked");
    // 	$("#membership_billing_box").slideToggle();
    // 	$("#registration_submit_button").val("Register");
    // });

    //Handle jquery change event for IE
    if ($.browser.msie) {
    	$("#membership_personal").click(function() {
    	    this.blur();
    	    this.focus();
    	});
    }

    // Copy personal to billing information
    $("#membership_organization").change(function() {
	//console.log("I got clicked.");
	if(this.checked) {
	    //console.log("I am checked.");
	    $("#bill_name").val($("#organization_name").val());
	    $("#bill_street_1").val($("#street_1").val());
	    $("#bill_street_2").val($("#street_2").val());
	    $("#bill_city").val($("#city").val());
	    $("#bill_state").val($("#state").val());
	    $("#bill_zip").val($("#zip").val());
	} else {
	    //console.log("not any more.");
	    $("#bill_name").val("");
	    $("#bill_street_1").val("");
	    $("#bill_street_2").val("");
	    $("#bill_city").val("");
	    $("#bill_state").val("");
	    $("#bill_zip").val("");
	}
	
    });

    //Handle jquery change event for IE
    if ($.browser.msie) {
    	$("#kwtc_memb").click(function() {
    	    this.blur();
    	    this.focus();
    	});
    }

    // Copy personal to billing information
    $("#kwtc_memb").change(function() {
	//console.log("I got clicked.");
	if(this.checked) {
	    //console.log("I am checked.");
	    $('#kwtc_phone').css('display', 'block');
	    $('#phone').attr('class','required');

	} else {
	    //console.log("Not anymore");
	    $('#kwtc_phone').css('display', 'none');
	    $('#phone').attr('class','');
}
    });

// Validate IP Forms with jQuery Validate plugin.
    $("#ip_login").validate();
    $("#ip_get_password").validate();
    $("#ip_create_profile").validate();
    $("#ip_edit_profile").validate();
    $("#class_registration_form").validate();
    $("#ip_org_profile").validate();
    

});
