// JavaScript Document
function slideSwitch(){
	var $current=$(".logo div.cur");
	if($current.length==0) $current=$(".logo div:last");
	var $next=$current.next().length?$current.next():$(".logo div:first");
	$current.addClass('prev');
	$next.css({opacity:0.0}).addClass("cur").animate({opacity:1.0},1000,function(){
		$current.removeClass("cur prev");
	});
}


function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		con.style.display=i==cursel?"block":"none";
	}
}


function isEmail(strEmail){
	var patrn = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	return patrn.test(strEmail);
}

function isDate(s)
{
	var patrn=/^(\d{4}(\/|-)\d{1,2}(\/|-)\d{1,2})$|^(\d{8})$/;
	if (!patrn.exec(s)) return false;
	return true;
}

function isPhone(s)
{
	var patrn=/^(\d{10,})$/;
	if (!patrn.exec(s)) return false;
	return true;
}

function isValidCSC(s) 
{ 
	var patrn=/^[0-9]{3,4}$/; 
	if (!patrn.exec(s)) return false;
	return true;
} 

function isValidCCN(s) 
{ 
	var patrn=/^[0-9]{13,16}$/; 
	if (!patrn.exec(s)) return false;
	return true;
} 

function isValidInput(s)
{
	var patrn=/^([a-zA-Z0-9]|[. -]){1,}$/; 
	if (!patrn.exec(s)) return false;
	return true;
}


function onAfter(curr,next,opts)
{
	var index=opts.currSlide;
	//$("#play_text li").eq(index).css("color","#000").siblings().css({'color':'#666'});
	$("#play_info").html($("#play_list img").eq(index).attr('alt'));
}

$(document).ready(function() {
    // logo switch
    $(".logo div.cur").css("opacity", "1.0");
    setInterval("slideSwitch()", 3500);


		$("#play_list").cycle({
			speed: 2000,
			timeout: 6000,
			pager: '#play_text',
			pagerEvent: 'click',
			pauseOnPagerHover: true,
			after: onAfter
		});


    $(".menu a, .donation a").focus(function() { $(this).blur(); });

    if ($(".menu li a").hasClass("cur"))
    { $(".menu .cur img").attr("src", $(".menu .cur img").attr("src").replace(".gif", "_on.gif")); }

    $(".menu li a img").not($(".menu li a.cur img")).hover(
		function() { $(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif")); },
		function() { $(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif")); }
	);

    $(".press_left li a img").not($(".menu li a.cur img")).hover(
		function() { $(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif")); },
		function() { $(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif")); }
	);

    $(".press_top li a img").hover(
		function() { $(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif")); },
		function() { $(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif")); }
	);

    $(".donation li a img").not($(".donation li a.cur img")).hover(
		function() { $(this).attr("src", $(this).attr("src").replace(".gif", "_on.gif")); },
		function() { $(this).attr("src", $(this).attr("src").replace("_on.gif", ".gif")); }
	);

    if ($(".donation li a").hasClass("cur"))
    { $(".menu a img").eq(3).attr("src", "/images/menu_donations_on.gif"); $(".donation .cur img").attr("src", $(".donation .cur img").attr("src").replace(".gif", "_on.gif")); }

    $('.press_bottom .pitem').click(function() {
    press_bottom_pitem_click(this);
    });
});

function press_bottom_pitem_click(obj) {
    location.href=($(obj).next().attr('href'));
}



$(document).ready(function(){
	$("#contact_fm,#subscribe_fm").submit(function(){
		if ($("input#Name").val()=="")
		{alert("Please enter a value for the \"Name\" field.");$("input#Name").focus();return false;}
		if ($("input#Name").val().length<2)
		{alert("Please enter at least 2 characters in the \"Name\" field.");$("input#Name").focus();return false;}
		if ($("input#Name").val().length>50)
		{alert("Please enter at most 50 characters in the \"Name\" field.");$("input#Name").focus();return false;}
		if (!isValidInput($("input#Name").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Name\" field.");$("input#Name").focus();return false;}

		if ($("input#Email").val()=="")
		{alert("Please enter your email address.");$("input#Email").focus();return false;}
		if (!isEmail($("input#Email").val()))
		{alert("Please enter a valid email address.");$("input#Email").focus();return false;}		

		if ($("textarea#Message").val()=="")
		{alert("Please enter a value for the \"Message\" field.");$("textarea#Message").focus();return false;}
		if ($("textarea#Message").val().length<5)
		{alert("Please enter at least 5 characters in the \"Message\" field.");$("textarea#Message").focus();return false;}
		if ($("textarea#Message").val().length>500)
		{alert("Please enter at most 50 characters in the \"Message\" field.");$("textarea#Message").focus();return false;}
		if (!isValidInput($("textarea#Message").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Message\" field.");$("textarea#Message").focus();return false;}
	});
	

	$("#amount_td :checkbox").click(function(){
		$("#amount_td :text").attr("disabled","disabled");
		$("#amount_td :checkbox").removeAttr("checked");
		$(this).attr("checked","checked");
		if($(this).attr("id")=="m8")
		{$("#amount_td :text").removeAttr("disabled");}
	});

	
	$("#donations_fm").submit(function(){
		if($.trim($("#amount_td :checkbox[checked]").attr("id"))==""){
			alert("Please select a donation amount.");
			return false;
		}
		
		if($.trim($("#amount_td :checkbox[checked]").attr("id"))=="m8"){
			if($.trim($("#amount_td :text").val())==""){
				alert("Please enter a donation amount.");
				$("#amount_td :text").focus();
				return false;
			}
		}
	
		if($("#ccfirstname").val()==""){
			alert("Please enter a value for \"First Name\" field.");
			$("#ccfirstname").focus();
			return false;
		}
		if($("#cclastname").val()==""){
			alert("Please enter a value for \"Last Name\" field.");
			$("#cclastname").focus();
			return false;
		}
		if($("#cctype").val()==""){
			alert("Please enter a value for \"Credit Card Type\" field.");
			$("#cctype").focus();
			return false;
		}
		if($("#ccnumber").val()==""){
			alert("Please enter a value for \"Credit Card Number\" field.");
			$("#ccnumber").focus();
			return false;
		}
		if(!isValidCCN($("#ccnumber").val()))
		{
			alert("Please enter a valid value for \"Credit Card Number\" field.");
			$("#ccnumber").focus();
			return false;
		}
		/*
		if($("#ccexpires").val()==""){
			alert("Please enter a value for \"Expiration Date\" field.");
			$("#ccexpires").focus();
			return false;
		}
		if(!isDate($("#ccexpires").val()))
		{
			alert("Please enter a valid value for \"Expiration Date\" field.");
			$("#ccexpires").focus();
			return false;
		}
		*/
		if($("#authcode").val()==""){
			alert("Please enter a value for \"Security Code\" field.");
			$("#authcode").focus();
			return false;
		}
		if(!isValidCSC($("#authcode").val()))
		{
			alert("Please enter at least 3 digit in the \"Security Code\" field.");
			$("#authcode").focus();
			return false;
		}
		/*
		if($("#organization").val()==""){
			alert("Please enter a value for \"Organization\" field.");
			$("#organization").focus();
			return false;
		}
		
		if($("#title").val()==""){
			alert("Please enter a value for \"Title\" field.");
			$("#title").focus();
			return false;
		}
		if($("#address2").val()==""){
			alert("Please enter a value for \"Apt \/ Floor \/ Suite\" field.");
			$("#address2").focus();
			return false;
		}
		*/
		if($("#firstname").val()==""){
			alert("Please enter a value for \"First Name\" field.");
			$("#firstname").focus();
			return false;
		}
		if($("#lastname").val()==""){
			alert("Please enter a value for \"Last Name\" field.");
			$("#lastname").focus();
			return false;
		}
		if($("#address1").val()==""){
			alert("Please enter a value for \"Address\" field.");
			$("#address1").focus();
			return false;
		}

		if($("#city").val()==""){
			alert("Please enter a value for \"City\" field.");
			$("#city").focus();
			return false;
		}
		if($("#state").val()==""){
			alert("Please enter a value for \"State \/ Provience\" field.");
			$("#state").focus();
			return false;
		}
		if($("#postal").val()==""){
			alert("Please enter a value for \"Zip \/ Postal Code\" field.");
			$("#postal").focus();
			return false;
		}
		if($("#country").val()==""){
			alert("Please enter a value for \"Country\" field.");
			$("#country").focus();
			return false;
		}
		if($("#phone").val()==""){
			alert("Please enter a value for \"Phone\" field.");
			$("#phone").focus();
			return false;
		}
		if(!isPhone($("#phone").val()))
		{
			alert("Please enter at least 10 digit in the \"Phone\" field.");
			$("#phone").focus();
			return false;
		}
		if($("#email").val()==""){
			alert("Please enter a value for \"Email\" field.");
			$("#email").focus();
			return false;
		}
		if(!isEmail($("#email").val()))
		{
			alert("Please enter a valid value for \"Email\" field.");
			$("#email").focus();
			return false;
		}
		
		/*
		if($("#sname").val()==""){
			alert("Please enter a value for \"Gift in honor of\" field.");
			$("#sname").focus();
			return false;
		}
		if($("#sfirstname").val()==""){
			alert("Please enter a value for \"First Name\" field.");
			$("#sfirstname").focus();
			return false;
		}
		if($("#slastname").val()==""){
			alert("Please enter a value for \"Last Name\" field.");
			$("#slastname").focus();
			return false;
		}
		if($("#saddress1").val()==""){
			alert("Please enter a value for \"Address\" field.");
			$("#saddress1").focus();
			return false;
		}
		if($("#saddress2").val()==""){
			alert("Please enter a value for \"Apt \/ Floor \/ Suite\" field.");
			$("#saddress2").focus();
			return false;
		}
		if($("#scity").val()==""){
			alert("Please enter a value for \"City\" field.");
			$("#scity").focus();
			return false;
		}
		if($("#sstate").val()==""){
			alert("Please enter a value for \"State \/ Provience\" field.");
			$("#sstate").focus();
			return false;
		}
		if($("#spostal").val()==""){
			alert("Please enter a value for \"Zip \/ Postal Code\" field.");
			$("#spostal").focus();
			return false;
		}
		if($("#scountry").val()==""){
			alert("Please enter a value for \"Country\" field.");
			$("#scountry").focus();
			return false;
		}
		*/
		
	});
});

function killErrors(){
	return true;
}
window.onerror = killErrors;
