/*
	JavaScript: prefellow
	Version: 	1.0
	Date		2010-02-09
	Author:		elementalblend.com (brandon burkett)
	
	Desc:		Class will process eligibility on step 1 of the prefellow contact form
				
	Note:		Custom class for JFDP, probably will not be able to reuse as is.
*/

/* prefellow class */
var prefellow = 
{
	/* properties */
	
	// valid country list used for questions 1-3
	validCountry:
	[
		'Albania', 'Armenia', 'Azerbaijan', 'Bosnia and Herzegovina', 'Croatia', 'Georgia', 'Kazakhstan',
		'Kosovo', 'Kyrgyzstan', 'Macedonia', 'Montenegro', 'Serbia', 'Tajikistan', 'Turkmenistan', 'Uzbekistan'
	],
	
	// messages to be outputted to the user
	messages:
	{
		'citizenshipCountry': 'Your country of citizenship is not participating in JFDP this year. You are not currently eligible to participate, but you are welcome to continue submitting your contact information below.',
		'residenceCountry': 'Your country of residence does not match your citizenship country. You may be ineligible to participate if you do not currently reside in your citizenship country, but you are welcome to continue submitting your contact information below.',
		'workCountry': 'The country where you work does not match your citizenship country. You are not currently eligible to participate in JFDP, but you are welcome to continue submitting your contact information below.',
		'bachelors': 'You are currently not eligible for JFDP based on your place of work, but you are welcome to continue submitting your contact information below.', 
		'workTwoYears': 'You are not currently eligible for JFDP based on the lack of university-level work experience, but you are welcome to continue submitting your contact information below.',
		'immigrationLottery': 'You are not currently eligible if you or your spouse has applied for US immigrant visas within the past three years, but you are welcome to submit your contact information.',
		'deniedVisa': 'You are not currently eligible for JFDP. Please contact your local American Councils representative if you have additional inquiries.',
		'convicted': 'You are not currently eligible for JFDP. Please contact your local American Councils representative if you have additional inquiries.'
	},

	/* methods */		
	validate: function(jqObject)
	{
		var id = jqObject.attr('id');
		var msgContainer = $('#fellowErrorMessage');
				
		//  country questions
		if(id == 'citizenshipCountry')
		{
			if($.inArray(jqObject.val(), prefellow.validCountry) == -1)
			{
				// display message if it doesn't exist
				if($('#'+id+'Msg').length == 0)
				{
					msgContainer.append('<p id="'+id+'Msg"><em><strong>'+prefellow.messages[id]+'</strong></em></p>');
				}
			}			
			else
			{
				$('#'+id+'Msg').remove();
			}
		}
		
		if(id == 'residenceCountry')
		{
			if($('#citizenshipCountry').val() != jqObject.val())
			{
				// display message if it doesn't exist
				if($('#'+id+'Msg').length == 0)
				{
					msgContainer.append('<p id="'+id+'Msg"><em><strong>'+prefellow.messages[id]+'</strong></em></p>');
				}
			}			
			else
			{
				$('#'+id+'Msg').remove();
			}
		}
		
		if(id == 'workCountry')
		{
			if($('#citizenshipCountry').val() != jqObject.val())
			{
				// display message if it doesn't exist
				if($('#'+id+'Msg').length == 0)
				{
					msgContainer.append('<p id="'+id+'Msg"><em><strong>'+prefellow.messages[id]+'</strong></em></p>');
				}
			}			
			else
			{
				$('#'+id+'Msg').remove();
			}
		}
		// end country questions
		
		// yes/no questions	
		if(id == 'bachelors' || id == 'workTwoYears')
		{
			if(jqObject.val() == 'N')
			{
				// display message if it doesn't exist
				if($('#'+id+'Msg').length == 0)
				{
					msgContainer.append('<p id="'+id+'Msg"><em><strong>'+prefellow.messages[id]+'</strong></em></p>');
				}
			}			
			else
			{
				$('#'+id+'Msg').remove();
			}
		}
		
		if(id == 'immigrationLottery' || id == 'deniedVisa')
		{
			if(jqObject.val() == 'Y')
			{
				// display message if it doesn't exist
				if($('#'+id+'Msg').length == 0)
				{
					msgContainer.append('<p id="'+id+'Msg"><em><strong>'+prefellow.messages[id]+'</strong></em></p>');
				}
			}			
			else
			{
				$('#'+id+'Msg').remove();
			}
		}
		// end yes/no questions
		
		// toggle button status based on last two questions
		prefellow.toggleButton();
		
		// show messages
		msgContainer.show();
		
	},
	
	toggleButton: function()
	{
		var denied = $('#deniedVisa');
		//var convicted = $('#convicted');
		
		if(denied.val() == 'N')
		{
			// both no, so enable button
			$('#formButton').attr('disabled','');
			$('#nextStep').val('eligible');			
		}
		else
		{
			$('#formButton').attr('disabled','disabled');
			$('#nextStep').val('');
		}
	},
	
	init: function()
	{
		// add events to prefellow contact step 1
		$('select').bind('change', function() { prefellow.validate($(this)); });
	}
}

// on document load
$(document).ready(function() { prefellow.init(); });
