$(document).ready(function(){
	//toggle payment option 
	$('input[name=payment_method]').click(function() {
		val = $(this).val();
		if (val == 'CC') {
			$('#cc_elements').show();
			$('#pp_elements').hide();			
		}
		else {
			$('#cc_elements').hide();
			$('#pp_elements').show();
		}
		//drop-shadow correction
		var myWidth = $("form#renew_account_form").width();			
		var myHeight = $("form#renew_account_form").height();
		$("div.shadow, div.shadow1, div.shadow2").height(myHeight).width(myWidth);
	});
	
	//form validation in case of 'cc' 
	$('form#renew_account_form').submit(function() {
		payment_method = $('input[name=payment_method]:checked').val();
		valid = true;
		if (payment_method == 'CC') {
			//CC type not selected 
			cc_type = $('input[name=cc_type]:checked').val();
			if (cc_type == undefined) {
				alert('Please choose the card type');
				valid = false;
			}
			
			//textbox empty or select invalid
			$('form#renew_account_form input[type=text], form#renew_account_form select').each(function(){
				val = $(this).val();
				if (!val || val == '0') {
					alert('Please enter all fields');
					valid = false;
					$(this).focus();
					return false;
				}
			});			
		}		
		return valid;		
	});	
});

