$(document).ready(function() {
	$('img.roller').hover(
		function() {
			var imgsrc = $(this).attr('src');
			$(this).attr('src', imgsrc.replace('.jpg', '_over.jpg'));
		},
		function() {
			var imgsrc = $(this).attr('src');
			$(this).attr('src', imgsrc.replace('_over.jpg', '.jpg'));
		}
	);
	
	$('#signup_button').click(function() {
		if($('#email').val().length > 0 && $('#email').val() != $('#email').attr('title')) {
			$('#the_rest_of_the_form').fadeIn('slow', function() {
                $('#signup_button').fadeOut('fast');
            });
			//$('#form_top_text').fadeOut('fast');
		} else {
			alert('Please enter your email address first');
		}
	});
	
	$('input[title]').inputHints();
	$('#signup_form').submit(function() {
		return validate_signup_form();
	});
    $('#volunteer_form').submit(function() {
        return validate_volunteer_form();
    });
    $('#contribute_form').submit(function() {
        return validate_contribute_form();
    });

    if(typeof(show_email_updates_confirm) != "undefined") {
        $.fn.colorbox({width:"50%", html:email_updates_confirm});
    }

    if(typeof(show_volunteer_confirm) != "undefined") {
        $.fn.colorbox({width:"50%", html:volunteer_confirm});
    }

    if(typeof(show_contribute_confirm) != "undefined") {
        $.fn.colorbox({width:"50%", html:contribute_confirm});
    }

    $('#business_address, #business_city, #business_state, #business_zip').change(function() {
        $('#chkbox14').attr('checked', 'true');
    });
    
    $('#other_details').change(function() {
        $('#chkbox15').attr('checked', 'true');
    });
});

function validate_signup_form() {
	var errors = "";
	var reminders = "";
	if($('#email').val().length < 0 || $('#email').val() == $('#email').attr('title')) {
		errors += "Please fill in your email address.\n";
	}
	if($('#name_first').val().length < 0 || $('#name_first').val() == $('#name_first').attr('title')) {
		errors += "Please fill in your first name.\n";
	}
	if($('#name_last').val().length < 0 || $('#name_last').val() == $('#name_last').attr('title')) {
		errors += "Please fill in your last name.\n";
	}
	
	if($('#address').val().length < 0 || $('#address').val() == $('#address').attr('title')) {
		reminders += "You forgot your address.\n";
	}
	if($('#city').val().length < 0 || $('#city').val() == $('#city').attr('title')) {
		reminders += "You forgot your city.\n";
	}
	if($('#state').val().length < 0 || $('#state').val() == $('#state').attr('title')) {
		reminders += "You forgot your state.\n";
	}
	if($('#zip').val().length < 0 || $('#zip').val() == $('#zip').attr('title')) {
		reminders += "You forgot your zip.\n";
	}
	if($('#phone').val().length < 0 || $('#phone').val() == $('#phone').attr('title')) {
		reminders += "You forgot your phone.\n";
	}
	
	if(errors.length > 0) {
		alert(errors);
		return false;
	}
	
	if(reminders.length > 0) {
		var answer = confirm("Although not required, by providing the additional information we will be able to better update you on current events.\n\n" + reminders + "\nIf you would like to include any of this information, click Cancel now and update the form");
		if(!answer) {
			return false;
		}
	}
	return true;
}

function validate_volunteer_form() {
	var errors = "";
	var reminders = "";
	if($('#vol_name_first').val().length < 0 || $('#vol_name_first').val() == $('#vol_name_first').attr('title')) {
		errors += "Please fill in your first name.\n";
	}
	if($('#vol_name_last').val().length < 0 || $('#vol_name_last').val() == $('#vol_name_last').attr('title')) {
		errors += "Please fill in your last name.\n";
	}
	if($('#vol_email').val().length < 0 || $('#vol_email').val() == $('#vol_email').attr('title')) {
		errors += "Please fill in your email address.\n";
	}
	if($('#vol_address').val().length < 0 || $('#vol_address').val() == $('#vol_address').attr('title')) {
		errors += "Please fill in your address.\n";
	}
	if($('#vol_city').val().length < 0 || $('#vol_city').val() == $('#vol_city').attr('title')) {
		errors += "Please fill in your city.\n";
	}
	if($('#vol_state').val().length < 0 || $('#vol_state').val() == $('#vol_state').attr('title')) {
		errors += "Please fill in your state.\n";
	}
	if($('#vol_zip').val().length < 0 || $('#vol_zip').val() == $('#vol_zip').attr('title')) {
		errors += "Please fill in your zip.\n";
	}
	//alert($('#vol_phone_home').val().length + "\n" + $('#vol_phone_mobile').val().length + "\n" + $('#vol_phone_work').val().length);
	//alert($('#vol_phone_home').val().length < 0 || $('#vol_phone_home').val() == $('#vol_phone_home').attr('title'));
    //alert($('#vol_phone_mobile').val().length < 0 || $('#vol_phone_mobile').val() == $('#vol_phone_mobile').attr('title'));
    //alert($('#vol_phone_work').val().length < 0 || $('#vol_phone_work').val() == $('#vol_phone_work').attr('title'));
	if(($('#vol_phone_home').val().length < 0 || $('#vol_phone_home').val() == $('#vol_phone_home').attr('title')) && ($('#vol_phone_mobile').val().length < 0 || $('#vol_phone_mobile').val() == $('#vol_phone_mobile').attr('title')) && ($('#vol_phone_work').val().length < 0 || $('#vol_phone_work').val() == $('#vol_phone_work').attr('title'))) {
		errors += "Please fill in at least 1 phone number.\n";
	}
	
    if($('#volunteer_form :checked').size() < 1) {
        errors += "Please check at least one method of volunteering.\n";
    }
    
    if($('#chkbox14').attr('checked') == true && (($('#business_address').val().length < 1 || $('#business_address').val() == $('#business_address').attr('title')) || ($('#business_city').val().length < 1 || $('#business_city').val() == $('#business_city').attr('title')) || ($('#business_state').val().length < 1 || $('#business_state').val() == $('#business_state').attr('title')) || ($('#business_zip').val().length < 1 || $('#business_zip').val() == $('#business_zip').attr('title')))) {
        errors += "Please provide the complete address information for the business where your sign would be located. We will contact you to confirm.\n";
    }
    
    if($('#chkbox15').attr('checked') == true && $('#other_details').val().length < 1) {
        errors += "Please provide details on other ways you would like to volunteer.\n";
    }
    
	if(errors.length > 0) {
		alert(errors);
		return false;
	}
	
	if(reminders.length > 0) {
		var answer = confirm("Although not required, by providing the additional information we will be able to better update you on current events.\n\n" + reminders + "\nIf you would like to include any of this information, click Cancel now and update the form");
		if(!answer) {
			return false;
		}
	}
	return true;
}

function validate_contribute_form() {
	var errors = "";
	var reminders = "";
	if($('#contrib_first_name').val().length < 0 || $('#contrib_first_name').val() == $('#contrib_first_name').attr('title')) {
		errors += "Please fill in your first name.\n";
	}
	if($('#contrib_last_name').val().length < 0 || $('#contrib_last_name').val() == $('#contrib_last_name').attr('title')) {
		errors += "Please fill in your last name.\n";
	}
	if($('#contrib_email_address').val().length < 0 || $('#contrib_email_address').val() == $('#contrib_email_address').attr('title')) {
		errors += "Please fill in your email address.\n";
	}
	if($('#contrib_address1').val().length < 0 || $('#contrib_address1').val() == $('#contrib_address1').attr('title')) {
		errors += "Please fill in your address.\n";
	}
	if($('#contrib_city').val().length < 0 || $('#contrib_city').val() == $('#contrib_city').attr('title')) {
		errors += "Please fill in your city.\n";
	}
	if($('#contrib_state').val().length < 0 || $('#contrib_state').val() == $('#contrib_state').attr('title')) {
		errors += "Please fill in your state.\n";
	}
	if($('#contrib_zip').val().length < 0 || $('#contrib_zip').val() == $('#contrib_zip').attr('title')) {
		errors += "Please fill in your zip.\n";
	}
    var contrib_value = $('input[name=amount]:checked').val();
    if(contrib_value == "other") contrib_value = $('#contrib_other_amount').val();
	if(contrib_value > 100 && ($('#contrib_occupation').val().length < 0 || $('#contrib_occupation').val() == $('#contrib_occupation').attr('title'))) {
		errors += "Please fill in your occupation.\n";
	}
	if($('#contrib_card_name').val().length < 0 || $('#contrib_card_name').val() == $('#contrib_card_name').attr('title')) {
		errors += "Please fill in the name on your card.\n";
	}

	if($('#contrib_card_number').val().length < 15 || $('#contrib_card_number').val().length > 16) {
		errors += "Please fill in your card number.\n";
	}

    var today = new Date();
	if($('#contrib_card_exp_yr').val() == today.getFullYear() && $('#contrib_card_exp_mo').val() < (today.getMonth() + 1)) {
		errors += "Your card expiration date is expired.\n";
	}

	if($('#contrib_card_cvv').val().length < 0 || $('#contrib_card_cvv').val() == $('#contrib_card_cvv').attr('title')) {
		errors += "Please fill in your card cvv.\n";
	}

	if(errors.length > 0) {
		alert(errors);
		return false;
	}
	
	return true;
}


