function swap_image(id, new_path){
	$(id).src = new_path
}

function add_to_cart(id){
	blind('working')
	var quote = "'"
	var id_array = id.split("|");
	var id_l = id_array.length
	var url = 'core/add_to_cart.cfm'
	if(id_l == 1){
		//var qty = $('qty_').value
		var qty = 1
		url = url + '?parent_id=' + id_array[0] + '&qty=' + qty
		new Ajax.Request(url, {asynchronous:true, onSuccess:create_timeout(1000, "added_to_cart('parent', "+id_array[0]+")")});
	}
	else{
		//var qty = $('qty_'+id_array[1]).value
		var qty = 1
		url = url + '?parent_id=' + id_array[0] + '&child_id=' + id_array[1] + '&qty=' + qty
		new Ajax.Request(url, {asynchronous:true, onSuccess:create_timeout(1000, "added_to_cart('child', "+id_array[1]+")")});
	}
}

function added_to_cart(prod_type, id){
	/*if(prod_type == 'child'){
		blind('add_to_cart_'+id)
	}
	else{

	}*/
	blind('working')
	show_cart()
}
function show_cart(){
	cart_display_status = $('cart').style.display
	var rand  = parseInt(Math.random()*99999);
	var url = 'core/cart_information.cfm'
	new Ajax.Updater(
		'cart',
		url+'?rand='+rand,
		{method:'get', onSuccess:show_cart_done, evalScripts:true}
	);	
		
}
function show_cart_done(){
	if(cart_display_status == 'none'){
		create_timeout(1500, "blind('cart')")
	}
	
}
function sign_in(){
	blind('sign_in')
}
function update_cart_qty(ele, id, value){
	if(value < 1 && value.length > 0){
		alert("You must have at least 1 in the quantity field\nIf you want to remove this product click the 'x'")	
		$(ele).value = 1
	}
	else{
		$(ele).disabled = true
		var url = 'core/send_update.cfm?id='+id+'&value='+value+'&table=cart&field=qty'
		new Ajax.Request(url, {asynchronous:true, onSuccess:update_cart_complete(ele)});
	}
}	
function update_cart_complete(ele){
	$(ele).disabled = false
	create_timeout(500, "show_cart()")
}
function remove_cart_line(id){
	var url = 'core/cfcs/cart.cfc?method=remove_line&id='+id
	new Ajax.Request(url, {asynchronous:true, onSuccess:create_timeout(750, "show_cart()")});
}
function copy_from_billing(){
	if($('same_as_billing').checked){
		$('d_firstname').value = $F('b_firstname')
		$('d_lastname').value = $F('b_lastname')
		$('d_address1').value = $F('b_address1')
		$('d_address2').value = $F('b_address2')
		$('d_address3').value = $F('b_address3')
		$('d_address4').value = $F('b_address4')
		$('country').value = $F('b_country')
		$('d_postcode').value = $F('b_postcode')
		$('d_telephone').value = $F('b_telephone')	}
}
function copy_from_account(){
	if($('same_as_billing').checked){
		$('D_FirstName').value = $F('FirstName')
		$('D_LastName').value = $F('LastName')
		$('D_Address1').value = $F('Address1')
		$('D_Address2').value = $F('Address2')
		$('D_Address3').value = $F('Address3')
		$('D_Address4').value = $F('Address4')
		$('d_country').value = $F('country')
		$('D_Postcode').value = $F('Postcode')
	}
}
function checkout_summary(){
	var rand  = parseInt(Math.random()*99999);
	var ajax = new Ajax.Updater(
		
		 'checkout_summary',        // DIV id (XXX: doesnt work?)
		 'checkout_summary.cfm?rand=' + rand,        // URL
		 
		 {                // options
		 method:'get',asynchronous:true,evalScripts:true
			 });	
}

function checkout_change_country(id){
	var url = 'core/aj_change_country.cfm?id='+id
	new Ajax.Request(url, {asynchronous:true, onSuccess:checkout_summary});
}
function pay_now(){
	if(validate_form('b_firstname','customer_details')){
		$('customer_details').submit()
	}
	
}

// Size Select
function show_size(){
	var size = $('sizes').value	
	window.location = 'size_select.cfm?size='+unescape(size)
}

