$(document).ready(function() {
    $('a').focus(function() {
        $(this).blur();
    });
    
    $("#box-images").cycle({
		fx: 'fade',
		timeout: 8000,
		pager:  '#nav', 
        pagerAnchorBuilder: function(idx, slide) { 
            if (idx == 0) return '<li><a href=\"#1\" class=\"participants\" title=\"Participants\">Participants</a></li>';
            if (idx == 1) return '<li><a href=\"#1\" class=\"parents\" title=\"Parents\">Parents</a></li>';
            if (idx == 2) return '<li><a href=\"#1\" class=\"volunteers\" title=\"Volunteers\">Volunteers</a></li>';
            if (idx == 3) return '<li><a href=\"#1\" class=\"partners\" title=\"Partners\">Partners</a></li>';
            if (idx == 4) return '<li><a href=\"#1\" class=\"schools\" title=\"Schools\">Schools</a></li>';
            if (idx == 5) return '<li><a href=\"#1\" class=\"military-families\" title=\"Military Families\">Military Families</a></li>';
            
        }
	});
	$("#box-slides-links ul li a").click(function() {
	    $('#box-images').cycle('pause'); 
	});
	
    $("#nine-core-values").cycle({
		fx: 'fade',
		timeout: 8000,
		cleartype: true,
		cleartypeNoBg: true
	});
	$("#footer #list-partners").cycle({
		fx: 'fade'
	});
	
	$('#accordion').accordion({
	    autoheight: false,
	    active: 3,
	    header: ".header-links"
	});
	$("#accordion a.header-links").click(function() {
	    if ($(this).is(".selected")) {
	        $('#accordion').accordion("activate", 3);
	    }
	});
	
	//$("#box-images .panel .popup-form").html($("#box-form-email-list").html());
	$("#box-images .panel .popup-form").each(function() {
	    $(this).html($("#box-form-email-list").html());
	    
	    if($(this).parent("div").parent("div").attr("id") == "popup1") {
	        var idToSelect = "7144";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-1");
	    }
	    if($(this).parent("div").parent("div").attr("id") == "popup2") {
	        var idToSelect = "7146";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-2");
	    }
	    if($(this).parent("div").parent("div").attr("id") == "popup3") {
	        var idToSelect = "7145";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-3");
	    }
	    if($(this).parent("div").parent("div").attr("id") == "popup4") {
	        var idToSelect = "7143";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-4");
	    }
	    if($(this).parent("div").parent("div").attr("id") == "popup5") {
	        var idToSelect = "7147";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-5");
	    }
	    if($(this).parent("div").parent("div").attr("id") == "popup6") {
	        var idToSelect = "7148";
	        $(this).find("#MKTGFRM_ID").val(idToSelect);
	        $(this).find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+idToSelect);
	        $(this).find("#reasonForVisit option[selected]").removeAttr("selected");
	        $(this).find("#reasonForVisit option[value='"+idToSelect+"']").attr("selected","selected");
	        
	        $(this).attr("id","box-form-popup-6");
	    }
	})
});

function mChangeReasonForVisit(obj) {
    $(obj).parent("form").find("#MKTGFRM_ID").val($(obj).val());
    $(obj).parent("form").find("#SRC_URL").val("/club/scripts/contact/contact_info.asp?FID="+$(obj).val());
}


function validateData(theForm) {
    //	Check Contact Fields
    theForm.txtSafeClick.value = 'human click';

    if ((theForm.MKTG_FIRSTNAME.value == "") || (theForm.MKTG_FIRSTNAME.value == "First Name")) {
        alert("Please enter a value for \"First Name\" ");
        theForm.MKTG_FIRSTNAME.focus();
        return (false);
    }
    if ((theForm.MKTG_LASTNAME.value == "") || (theForm.MKTG_LASTNAME.value == "Last Name")) {
        alert("Please enter a value for \"Last Name\" ");
        theForm.MKTG_LASTNAME.focus();
        return (false);
    }
    if (theForm.MKTG_STATE.value == ""){
        alert("Please enter a value for \"State\" ");
        theForm.MKTG_STATE.focus();
        return (false);
    }
    if ((theForm.MKTG_ZIP.value == "") || (theForm.MKTG_ZIP.value == "Zip Code")) {
        alert("Please enter a value for \"Zip Code\" ");
        theForm.MKTG_ZIP.focus();
        return (false);
    }
    if ((theForm.MKTG_EMAIL.value == "") || (theForm.MKTG_EMAIL.value == "Email Address")) {
        alert("Please enter a value for \"Email Address\" ");
        theForm.MKTG_EMAIL.focus();
        return (false);
    }
    
    $.ajax({
        type: 'POST',
        url: $(theForm).attr("action"),
        data: $(theForm).serialize(),
        beforeSend: function(data) {
            $(theForm).parent("#form-email-list").append("<p style='width: 100%; float: left; margin-top: 22px; text-align: center;'>Loading...</p>");
			$(theForm).hide();
        },
        success: function(data) {
            //if ($(data).filter("td:contains('Request')")) {
                $(theForm).parent("#form-email-list").find("p").hide();
    			$(theForm).parent("#form-email-list").append("<p style='width: 100%; float: left; margin-top: 22px; text-align: center;'>Thank you for<br /> your submission!</p>");
    		//} else {
    			//alert('uh oh');
    			//var errorMessage = $('#formdump td#main_area_td center font b:contains("Unable")').text();
    			//alert("Error: \n" + errorMessage);
    		//}
        }
    });
    
    return false;
}
