$(document).ready(function() {

//////   toggle the email address submission form   //////
$("a.emailicon").toggle(
    function() { 
        $("#emailpage").show("fast");
    },
    function() { 
        $("#emailpage").hide("fast");
    }
);
    
//////   process email address submission form   //////
$(".emailerror").hide();
$(".button").click(function() {

     $(".emailerror").hide();
     
     // validate the form
     var emailaddress = $("input#emailaddress").val();
     //var pagelink = $("input#pagelink").val();
     //var pageyear = $("input#pageyear").val();
     //var pageseason = $("input#pageseason").val();
     //var pagedate = $("input#pagedate").val();
     if (emailaddress == "") {
        $("label#emailaddress_error").show();
        $("input#emailaddress").focus();  
       return false;
     }
     
     //var dataString = 'emailaddress=' + email + '&pagelink=' + pagelink + '&pageyear=' + pageyear + '&pageseason=' + pageseason + '&pagedate=' + pagedate;
     var dataString = 'emailaddress=' + emailaddress;
     //alert (dataString); return false; 
     $.ajax( {
        type: "POST",
        url: "email.php",
        data: dataString,
        success: function() {
            $("#emailpage").html("<div id=\"confirm\"></div>");  
            $("#confirm").html("Email sent to " + emailaddress + ". Reload this page to send another email.");
        }
     }); // end .ajax
     return false;
});  // end .button.click

//////   hide and show in faq page   //////
//adapted from simple jQuery show/hide script: http://screwlewse.com/?p=30
// hide all blocks that have class faqhide
$('.hidetxt').hide();
// toggle aboutlink with abouttext
// using chaining for performance and ease
$('.hideheading').toggle(function(){
    $(this).parent().next().slideDown('fast').removeClass('hidetxt').preventDefault;
	},function(){
    $(this).parent().next().slideUp('fast').addClass('hidetxt').preventDefault;
});  //end .hideheading toggle  

// show and hide year-season  +/- toggle in the tree navigation  ////
//$('.children').hide();
// toggle aboutlink with abouttext
// using chaining for performance and ease
/*$('.yearparent').toggle(function(){
    $(this).parent().next().slideDown('fast').removeClass('children').preventDefault;
    $(this).html('<b> - Year </b>');
	},function(){
    $(this).parent().next().slideUp('fast').addClass('children').preventDefault;
	$(this).html('<b> + Year </b>');

});  */
//end year/season +/- toggle

// tree navigation for the year-season-date infocus area  ////
//$('.childreninfocus').show();
// toggle aboutlink with abouttext
// using chaining for performance and ease
/*$('.yearinfocus').toggle(function(){
    $(this).parent().next().slideUp('fast').addClass('children').preventDefault;
    $(this).html('<b> + Year </b>');
	},function(){
    $(this).parent().next().slideDown('fast').removeClass('children').preventDefault;
	$(this).html('<b> - Year </b>');

}) ;  */ 

//toggle between admin forms in admin page
$('#caldates_manager').click(function() {
    $('#caldatesfrm').show();
	$('#yearfrm').hide();
	$('#addyearfrm').hide();
	$('#helpdocs').hide(); 	
});
$('#year_manager').click(function() {
    $('#caldatesfrm').hide();
	$('#yearfrm').show();
	$('#addyearfrm').hide();
	$('#helpdocs').hide(); 
})
$('#addyear_manager').click(function() {
    $('#caldatesfrm').hide();
	$('#yearfrm').hide();
	$('#addyearfrm').show();
	$('#helpdocs').hide(); 
})
$('#help').click(function() {
    $('#caldatesfrm').hide();
	$('#yearfrm').hide();
	$('#addyearfrm').hide();
	$('#helpdocs').show(); 
})

// search result display page
$('.showhideswitch').toggle(function(){
    $(this).parent().children('.fulltextbox').slideDown();
	$(this).html("[Hide full text]");
	},function(){
    $(this).parent().children('.fulltextbox').slideUp();
	$(this).html("[Display full text]");
});  //end .fulltextbox toggle

// lections page: change citation hover to hand cursor
$('.lection_citation').hover(function() {
    $(this).css('cursor', 'pointer');
});


// toggle the icalendar file listing 
/*$('#icalendar').toggle(
    function() { $("#icalopts").show("fast"); },
    function() { $("#icalopts").hide("fast");}
);*/

$('#aboutheading').hover(
    function() { $(this).css('cursor', 'pointer'); },
    function() { $(this).css('cursor', 'default'); }
);
$('#linkheading').hover(
    function() { $(this).css('cursor', 'pointer'); },
    function() { $(this).css('cursor', 'default'); }
);
$('#printheading').hover(
    function() { $(this).css('cursor', 'pointer'); },
    function() { $(this).css('cursor', 'default'); }
);

});  // end document.ready

////////// other js functions ///////////

// AJAX CITATION LOOKUP
// from http://nodstrum.com/2007/09/19/autocompleter/
function lookup(inputString) {
    if(inputString.length == 0) {
        $('#suggestions').hide();  // hide the suggestion box if nothing's been entered yet
    } else {
        $.post("citation-lookup.php", {queryString: ""+inputString+""}, function(data){ 
            if(data.length >0) {
                $('#suggestions').show();
                $('#autoSuggestionsList').html(data);
            }
        });
    } //end of lookup
}

function fill(name, id) {
    $('#citation').val(name);
    $('#lookupid').val(id);
    $('#suggestions').hide();
}

//togglestatus is to disable the suggestionbox when doing a fulltext search
function toggletextbox() {
    if ($('#search-fulltext').is(':checked')) {
        $('#citation').hide();
		$('#autoSuggestionsList').hide(); 
		//$('#suggestionsBox').css('border-style','none'); 
		$('#fulltext').show();
    }
	if  ($('#search-citation').is(':checked')){
		$('#citation').show();
		$('#autoSuggestionsList').show();
		$('#fulltext').hide(); 
    }   
}

// show all divs on the faq and faq2 page. this is called if we're the printable page.
function showall() {
    $('#main_text').children("#abouttext").show();
    $('#main_text').children("#linktext").show();
    $('#main_text').children("#printtext").show();
    $('#main_text').children(".hidetxt").show();
}

function showcommentbox() {
    $('#commentbox').show('fadein');
    $('#comments').css('width','400px');
}

//for admin page, toggle among individual admin functions
function togglecalyearA() {
    $("#calyearA").toggle();
}
function togglecalyearB() {
    $("#calyearB").toggle();
}
function togglecalyearC() {
    $("#calyearC").toggle();
}

function togglecalyearinput() {
	if ($("#popA").is(":checked") ) {
		$('#calyearA').show();
	}else{ 
		$('#calyearA').hide(); 
	}
	if ($("#popB").is(":checked") ) {
		$('#calyearB').show();
	}else{ 
		$('#calyearB').hide(); 
	}
	if ($("#popC").is(":checked") ) {
		$('#calyearC').show();
	}else{ 
		$('#calyearC').hide(); 
	}
}	


		
	
