/**
 * Resets the contact method
 * As both fields (email, phone number) are required.
 * we have to fill the otehr one with some dummy data
 */

var dummyData = 'dummy@test.com';

function resetContactMethod( type )
{
	var value = $("input#" + type).val();

	// If we find the dummy data we empty it otherwise we leave the data entered by the user
	if( value == dummyData )
	{
		$("input#" + type).val('');
	}
}

/**
 * Checks teh contact method and dispalys the proper input fields
 */
function checkContactMethod()
{
	// Hide everything
	$('li.phone').hide();
	$('li.email').hide();

	resetContactMethod('emailAddress');
	resetContactMethod('phoneNumber');

	var contactMethod = $("input[name=contactMethod]:checked").val();
	var value = '';

	if(contactMethod == "phone" )
	{
		// put somehing in email to trick the validation
		value = $("input#emailAddress").val();
		if( 0 == value.length )
		{
			$("input#emailAddress").val(dummyData);
		}
	}
	else
	{
		// put somehing in email to trick the validation
		value = $("input#phoneNumber").val();
		if( 0 == value.length )
		{
			$("input#phoneNumber").val(dummyData);
		}
	}

	$('li.' + contactMethod).show();
}

$(document).ready(
		function()
		{
			// Controls what should be asked in the form
			checkContactMethod();

			$("input[name=contactMethod]").click(function(){
				checkContactMethod();
			});
		});
