// run it right away


$(document).ready(function(){

	if($('.overlay-rollup').length > 0){
		if( $('.overlay-rollup')[0].scrollHeight > ($('.overlay-rollup').height() + 8)){
			
			$('.overlay-rollup').after("<span class='rollup-read-more'>More...</span>");
			$('.rollup-read-more').toggle(
				function(){
					var heightVar = $('.overlay-rollup')[0].scrollHeight;
					$('.overlay-rollup').css( {'background-color':"#020817",opacity:0}).animate( {height: heightVar, opacity:0.92} );
					
					$('.rollup-read-more').html('Less')
				},
				function(){
					$('.rollup-read-more').html('More...')
					$('.overlay-rollup').css( {'background-color':"",border:"none",opacity:1}).animate( {height: '3.9em' } );
				}
			)
			
		}
	
	
	}
	
	
	$(".family-buttons a").click(function(){
		
		if( $($(this).attr("href")+":hidden").length > 0 ){
			
			$(".family-image").hide();
			$("#overlay").fadeOut();
			$($(this).attr("href")).fadeIn();
			$(".family-buttons a").removeClass("active").find('span em').html('show');
			$(this).addClass("active").find('span em').html('hide');
		
		}else{
			$(this).find('span em').html('show');
			$(".family-buttons a").removeClass("active");
			$($(this).attr("href")).fadeOut();
			$("#overlay").fadeIn();
		}
		
		return false;
			
	});
	
});



function sameaddressasabove() {
	var form = document.cardonation;
	if (form.vehicleaddress[1].checked) {
		form.vehicle_address.value = "";
		form.vehicle_address2.value = "";
		form.vehicle_city.value = "";
		form.vehicle_country.value = "";
		form.vehicle_province.value = "";
		form.vehicle_postal.value = "";
	} else {
		form.vehicle_address.value = form.owner_address.value;
		form.vehicle_address2.value = form.owner_address2.value;
		form.vehicle_city.value = form.owner_city.value;
		form.vehicle_country.value = form.owner_country.value;
		form.vehicle_province.value = form.owner_state.value;
		form.vehicle_postal.value = form.owner_postal.value;
	}
}


function validEmail(email) {
	invalidChars = ' !#$%^&*(){}[]+=~`?/:;,"'
	
	
	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) { //does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)  		//there must be one "@" symbol
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) { //and only one "@"
		return false;
	}
	periodPos = email.indexOf(".",atPos+1)  //and at least one "." after the "@"
	if (periodPos == -1) {
		return false;
	}
	if (email.charAt(atPos+1) == ".") {	//is there a "." right after the "@"
		return false;
	}
	if (periodPos+3 > email.length) {  	//must be at least 2 characters after the "."
		return false;
	}
	return true;
}
