$(document).ready(function() {
	$('#make_payment').ajaxForm({ 
		beforeSubmit:  CheckTerms,
		success:   MakePaymentCallback
	});     
	
	
    $('#trip_date').datepicker({ 
	    showOn: "both", 
	    buttonImage: "images/calendar.gif", 
	    buttonImageOnly: true 
	});     

});
function CheckTerms()
{
	if(!$('#authorize_payment').attr('checked') || !$('#agree_conditions').attr('checked'))
	{
		alert('You have to agree with both terms and conditions in order to make payment');
		return false;
	}
	return true;
		
}
function MakePaymentCallback(result)
{
	try
		{
			result = JSON.decode(result);
			$('.required').html('').hide();		
			if(result.STATUS == 'FALSE')
			{
				for(var key in result.ERROR)
				{
					if( $('#spn'+key).length > 0) 
					{
						$('#spn'+key).css({fontWeight:'bold'}).html(result.ERROR[key]).fadeIn();
						
					}
					else
					{
						if(typeof result.ERROR[key]!= 'undefined') alert(result.ERROR[key]);
						else alert(result.ERROR[key]);
					}
				}
			}
			else
			{
				
				$('#tblmake_payment').hide();
				$('#make_payment').clearForm();
				$('#tblThankYou').show();
			}
		}
	catch(e){}
	
	
}
function process_choice() 
{
	with (document.make_payment) 
	{
		if (payment_method.options[payment_method.selectedIndex].value=="American Express") {
			document.getElementById("cvv1").style.display = "none";
			document.getElementById("cvv2").style.display = "block";
		}
		else 
		{
			document.getElementById("cvv1").style.display = "block";
			document.getElementById("cvv2").style.display = "none";
		}
	}
}

