// BEGIN DOM
$(document).ready(function()
{

	$('a[rel*=spemail]').spemail('|,:','linkbase');

	// Lets remove the last border bottom from news item links.
	$('.newsItem:last').css("border-bottom","none");
	
	// Any link with the rel of backlink will go back history -1
	$('a[rel="backlink"]').click( function() {
		parent.history.back(-1);		
        return false;
    });
	
	
	// Any External Link will open up a new window.
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	// Will handle any PDF to open up without sending you to a new page	
	/*$("a[href*=.pdf]").click(function()	{
		$(this).attr({"target":"_self"});
		return false;
	});*/

	// Any External Link will open up a new window.
	$('a[rel="confirm"]').click(confirmTheClick);
	
	
	$('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input[type="text"]').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	// for the contact textarea	
	$('#comment').addClass("idleField");
	$('#comment').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#comment').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	
	
	// for How to Apply Form
	$('#projectDescription').addClass("idleField");
	$('#projectDescription').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#projectDescription').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	// for How to Apply Form
	$('#moreInformation').addClass("idleField");
	$('#moreInformation').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#moreInformation').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	// for How to Apply Form
	$('#whyNominate').addClass("idleField");
	$('#whyNominate').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#whyNominate').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	// for How to Apply Form
	$('#contactInformation').addClass("idleField");
	$('#contactInformation').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#contactInformation').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	// to execute the toggle between the news section and the donate information	
	$('#donateButton').click(function(){
		var $buttonID = $(this).attr("id");
		//alert($buttonID);
		if( $buttonID == "donateButton")
		{
			//alert("You hit the donate button");
			$(this).attr("src","/img/news_banner.jpg");
			$(this).attr("id","updateButton");
			$('#updateContainer').hide();
			$('#donateContainer').show();
		}
		else
		{
			//alert("You hit the update button");
			$(this).attr("src","/img/donate_banner_interior.png");
			$(this).attr("id","donateButton");
			$('#updateContainer').show();
			$('#donateContainer').hide();
		}
	});

	
	
	
	
	// VALIDATE : ADD BLOG
	$("#contactForm").validate({
		rules: {
			fullName: "required",
			userEmail: "required",
			comment: "required"
		},
		messages: {
			fullName: "Required",
			userEmail: "Required",
			comment: "Required"
		}
	});
	
	
	// VALIDATE : ADD BLOG
	$("#nominationForm").validate({
		rules: {
			fullname: "required",
			emailAddress: "required",
			phoneNumber: "required",
			projectTitle: "required",
			projectDescription: "required",
			regionLocation: "required",
			neededIncome: "required"
		},
		messages: {
			fullname: "Required",
			emailAddress: "Required",
			phoneNumber: "Required",
			projectTitle: "Required",
			projectDescription: "Required",
			regionLocation: "Required",
			neededIncome: "Required"
		}
	});
	
	
	
	

}); // END DOM


// Confirm the click...to make sure that there are no mistakes
function confirmTheClick()
{
	var agree="Are you sure you wish to perform this action?\nCheck your work!";
	if ( confirm( agree ) )
		return true;
	else
		return false;
}

