$(document).ready(function() {
	//common elements for all pages
	if($("#email")){
		$("#email").blur(function() 
		{ 
			if (!$("#email").val().length){
				$("#email").val("Email Address");
			}
		}); 

		$("#email").click(function() 
		{ 
			if ($("#email").val()=="Email Address"){
				$("#email").val("");
			}
		}); 
	}

	//email box on the upper right of the global wrapper
	if($("#navUtility_email")){
		$("#navUtility_email").blur(function() 
		{ 
			if (!$("#navUtility_email").val().length){
				$("#navUtility_email").val("Enter Email Address");
			}
		}); 

		$("#navUtility_email").click(function() 
		{ 
			if ($("#navUtility_email").val()=="Enter Email Address"){
				$("#navUtility_email").val("");
				}
			}); 
	}

	/* BUTTON ROLLOVERS */
	if($("#goBtn")){
		$("#goBtn").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_go_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_go_off.gif");
		});
	}

	if($("#newsletter_home")){
		$("#newsletter_home").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/newsletter_sign_up_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/newsletter_sign_up_off.gif");
		});
	}

	if($("#newsletter_signup")){
		$("#newsletter_signup").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/teacher_newsletter_sign_up_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/teacher_newsletter_sign_up_off.gif");
		});
	}

	if($("#navUtility_emailsubmit")){
		$("#navUtility_emailsubmit").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/teacher_newsletter_sign_up_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/teacher_newsletter_sign_up_off.gif");
		});
	}
	//subpages
	if($("#searchByKeyword")){
		$("#searchByKeyword").blur(function(){ 
			if (!$("#searchByKeyword").val().length){
				$("#searchByKeyword").val("By Keyword");
			}
		}); 

		$("#searchByKeyword").click(function(){
			if ($("#searchByKeyword").val()=="By Keyword"){
				$("#searchByKeyword").val("");
			}
		});
	}

	if($("#link_goBtn")){
		$("#link_goBtn").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_go_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_go_off.gif");
		});
	}

	if($("#searchBattlefieldsBtn")){
		$("#searchBattlefieldsBtn").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_battlefields_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/search_battlefields_off.gif");
		});
	}

	if($("#find_campaign")){
		$("#find_campaign").hover(function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/find_campaign_on.gif");
		},function(){
			$(this).attr("src","http://www.civilwar.org/assets/images/forms/find_campaign_off.gif");
		});
	}			

	// apply to all png images 
	$('img[src$=".png"]').ifixpng(); 

	//Print
	$('a#printBtn').bind('click keypress', function(event){
		var code=event.charCode || event.keyCode;
		if(!code || (code && code == 13)) {// if no key code (mouse) or if enter is pressed
			window.print();
			event.preventDefault(); //prevent browser from following the actual href
		}
	});

	$('lLogonForm').action = "http://members.civilwar.org/site/UserLogin?NEXTURL=" + window.location;
});


function jumpto(x){
	if (document.searchBattlefields.state.value != "null") {
		document.location.href = x;
	}
}

function jumpto2(x){
	if (document.searchBattlefields.year.value != "null") {
		document.location.href = x;
	}
}
