// JavaScript Document
$(document).ready(function(){
	//add billing name to BillingName form
	
	$('#cart_sop35_firstName, #cart_sop35_lastName').keyup(function(){
		$('#cart_sop35_billing_name').val($('#cart_sop35_firstName').val() + ' ' + $('#cart_sop35_lastName').val());	
	});
	
	
	$('#cart_sop35_billing_countryCode').change(function(){
		var code =$(this).val();
		var isAU = false;
		var isNZ = false;
		
		if (code == 'AU') { isAU = true };
		if (code == 'NZ') { isNZ = true };

		if (isAU || isNZ){
			$('.payPal_form').fadeOut('fast',function(){
				$('.main_form').fadeIn();									   
			});
			
			$('.del_cost').empty()
						  .append('DVD delivered to your door for FREE, just fill in your details below...</strong> and we\'ll put your DVD in the mail.')	
						  .css("color","black")
		}else{
			$('.main_form').fadeOut('fast',function(){
				$('.payPal_form').fadeIn();											  
			});
			
			$('.del_cost').empty()
						  .append('Orders Outside of Australia and New Zealand incur a fee of $10 AUD<br /><br /> Just click the PayPal link below to pay for postage...</strong> and we\'ll put your DVD in the mail.<br /><br /> To change back to an Australian or New Zealand simply refresh this page.')
						  .css("color","red");
		}
	});
	$('form.bazooka').submit(function(){
		$('#submit-warning').remove();
		var required_msg = '<ul><li class=\'title\'>The following Fileds are required</li> ';
		var have_errors = false;
		var field =  '';
		$(':input.required_field').each(function(){
			if (this.value == ''){
				switch (this.name.replace('cart_sop35_',''))
				{
					case 'firstName':
						field = 'First Name';
						break;
					case 'email':
						field = 'Email Address';
						break;
					case 'phoneHome':
						field = 'Home Phone';
						break;
					case 'billing_address1':
						field = 'Address 1';
						break;
					case 'billing_city':
						field = 'City / Suburb';
						break;
					case 'billing_state':
						field = 'State / Province';
						break;
					case 'billing_stateAU':
						field = 'State / Province';
						break;
					case 'billing_postcode':
						field = 'Postcode / Zip';
						break;
 				}
				
				
				
				required_msg += '<li>' + field + '</li> ';
				have_errors = true;
			}		
		});
		required_msg += '</ul>';

		required_msg.replace("_"," ");
		if (have_errors){
			//alert(required_msg);
			$('<div></div>')
				.attr({'id':'submit-warning','class':'warning'})
				.append(required_msg.replace('_',''))
				.insertBefore('#send');
			return false
		}
		
  });

});
