google.load("jquery", "1");
google.setOnLoadCallback(function() {
$(document).ready(setupPopups);
});

function setupPopups() {
	if($('.cartpopup-open-link'))
		$('.cartpopup-open-link').bind('click',function(){$('.cart-box ul.popup').toggle();});
	if($('.deliverycheckbox')) {
		$('.deliverycheckbox').bind('click',setDeliveryAddress);
	}
}

function setDeliveryAddress(el){

	var check = $('#deliverycheck').attr('checked');
	if(el.target.id!='deliverycheck') {
		if(check)
			check = false;
		else
			check = true;
		$('#deliverycheck').attr('checked',check);
	}
	if(check) {
		$('.detail-form input:text').each(function(){
				if(this.id.match('orderaddress-')) {
					$('#'+this.id.replace('orderaddress-','deliveryaddress-')).val(this.value);
				}
			});
		$('.detail-form select').each(function(){
				if(this.id.match('orderaddress-')) {
					$('#'+this.id.replace('orderaddress-','deliveryaddress-')).get(0).selectedIndex = this.selectedIndex;
				}
			});
	}
}

function handlePayment() {
	if(validatePaymentForm()) {
		document.paymentform.submit();
		$("#paymentButton").attr('onclick','');
		$("#paymentButton .c").text("Processing, please wait...");
		$("#paymentButton .c").css({'font-weight':'bold','color':'red'});
	}
	return false;
}
