/* Global JavaScript for DPC Registration */
$(document).ready(function() {
/*
if($("body").hasClass("registration-form")) {
// Set up validation on Registration Form
$("#dpc-registration-form").validate();
}
	
if($("body").hasClass("registration-rules")) {
// Set up validation on Rules page
$("#registration-rules-form").validate();
}
	*/
if ($("#module-samplelessonplans-small").length > 0) {
    // Set up binding for Sample Lesson Plans download form
    $("img#samplelessonplans-form-btn").click(function() {
    loadLesson();
    });
		
    // Set up binding for State Standards link form
    $("img#samplelessonplans-btn-download").click(function() {
    loadStandard();
    });
}

	if($("div#content").hasClass("home")) {
		
		// Functionality for Announcements Module modal
		$("a.welcome-modal-link").click(function() {
			
			// load title
			var modalTitle = $(this).parent().prev("h2").html();
			$("div#welcome-modal-content h2").html(modalTitle);
			
			// load content
			var modalContent = $(this).parent().next("div.welcome-modal-content").html();
			$("div#welcome-modal-copy").html(modalContent);
			
			// spawn the modal window
			$("div#welcome-modal-content").modal({
				escClose: false,
				overlayClose: false
			});
			
			return false;
			
		});
		
		$("a.sub-open-modal-link").click(function() {

            // load title
            var modalTitle = $(this).parent().prev("h2").html();
            $("div#welcome-modal-content h2").html(modalTitle);

            // load content
            var modalContent = $(this).parent().next("div.welcome-modal-content").html();
            $("div#welcome-modal-copy").html(modalContent);

            // spawn the modal window
            $("div#welcome-modal-content").modal({
                escClose: false,
                overlayClose: false
            });

            return false;

        });
	}
});

function loadLesson() {
	
	/* 
		This function generates a link to a specific Sample Lesson Plan PDF based on the values of the 
		<select> elements in the Sample Lesson Plans module on the Project Resources page. The expected
		naming scheme for the PDFs is:
		
		pdf/samplelessons/<full state name>/<2 letter state abbreviation>Grade<grade number>.pdf
		
		If a certain state-grade combination results in a 404 error, check that the PDF for that particular
		combo follows the naming scheme and is not missing from the directory structure.
	*/

    var stateName = $("#samplelessonplans-form-state option:selected").text(); // Full state name - i.e. California
    var stateAbbr = $("#samplelessonplans-form-state").val(); // State abbreviation - i.e. CA
    var grade = $("#samplelessonplans-form-grade").val(); // Grade Number
	
	// Assemble the form values into a filename that follows the naming convention
	if(grade && stateAbbr !== "") {
	    var lessonLink = "global/pdf/samplelessons/" + stateName + "/" + stateAbbr + "Grade" + grade + ".pdf";
	    // Launch the link in a new window
	    window.open(lessonLink);
	}
	
	
}

function loadStandard() {
	/*
		This function loads the appropriate State Standards PDF for the Download button based on the value
		of the <select> dropdown in the State Standards module. The expected naming scheme for the PDFs is:
		
		pdf/statestandards/<full state name>-statestandards.pdf
		
		If a State Standard download attempt results in a 404 error, check that the PDF for that particular state
		follows the naming scheme and is not missing from the directory structure.
	*/
	
	var stateLink = $("#statestandards-form-state option:selected").val();
	
	// Assemble the form values into a filename that follows the naming convention
	if(stateLink !== "") {
		// Launch the link in a new window
		window.open(stateLink);
	}
}
