$(document).ready(function(){
	
	
	
	$('div.billing_fields').not('.open').hide();
	
	$('input#different_billing').click(function()
	{
		if ($(this).attr('checked'))
		{
			$('div.billing_fields').show();
		}
		else
		{
			$('div.billing_fields').hide();
		}
	});
	
	var first_error = $('input.error, select.error').get(0);
	if (first_error)
	{
		//$(first_error).focus();
	}
	
	$('form input.price_update, form select.price_update').change(function()
	{
		// gather all the variables, if we have them all, then update price
		
		// since the package selection comes before company name, we'll check the company name first
		var company = $('input#company').attr('value');
		var company_2 = $('input#company_2').attr('value');
		var company_3 = $('input#company_3').attr('value');
		var company_4 = $('input#company_4').attr('value');
		
		var buy_package = $('select#package').attr('value');
		if (company)
		{
			// if we have a package selected, we can check prices
			if (buy_package != '')
			{
				var action = $('#order_form').attr('action');
				$.post(action + "?ajax=true",  $("#order_form").serialize(),
				  function(data){
				  	
				  	var result = data.split('|');
				    $('span#sub_total').html(result[0]);
				    $('span#discount').html(result[1]);
				    $('span#total').html(result[2]);
				  });
				
			}
		}
	});
});
