$(document).ready(function() { 
	$('#image_rotate').innerfade({ 
		speed: 1000, 
		timeout: 6000, 
		type: 'sequence' 
	});

	$(".displayvideo").colorbox({iframe:true, innerWidth:656, innerHeight:385});
	
});
function check_amount(obj) {
	if($(obj).find(':selected').text()=='Other') {
		$('#donation_etc').css("display","inline");
	} else {
		$('#donation_etc').css("display","none");
	}
}
function submit_donation(obj) {
	var form = $(obj).parent().parent().parent();
	var sw = true
	$(".required input").each(function() {
		if($(this).val() == "") {
			alert("Please fill in the missing fields");
			$(this).focus();
			sw = false;
			return false;
		}
	});
	if(sw && !isValidEmailAddress($("#email_address").val())) {
		alert("Please fill in the email properly");
		$("#email_address").focus();
		sw = false;
	}
	if(sw && $("select option:selected").val() == "") {
		alert("please choose an amount of donation");
		$("select").focus();
		sw = false;
	}
	if(sw && $("select option:selected").text() == "Other" && $("#donation_etc").val() == "") {
		alert("please fill in the other amount");
		$("#donation_etc").focus();
		sw = false;
	}
	if(sw && $("select option:selected").text() == "Other" && isNaN($("#donation_etc").val())) {
		alert("please fill in the other amount only numbers");
		$("#donation_etc").focus();
		sw = false;
	}
	if(sw) {
		$("#dps_frame").slideDown();
		form.target = "payframe";
		//form.action = "/script/dps/PxPay.php";
		form.submit();
	}
}
function reset_payment() {
	$("#dps_frame").slideUp("fast");
	$("iframe[name='payframe']").attr("src","about:blank");
}
$(document).ready(function() {
	$("#donation_form form").attr("target","payframe");
});
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);return pattern.test(emailAddress);
}
