// JavaScript Document

function eCart_copyBillingToShipping(cb){
	if(cb.checked){ // Only copy when the checkbox is checked.
		var theForm = cb.form;
		// The number of elements must match in billingFields and shippingFields. The type of input element must also match between the arrays.
		var billingFields = new Array('title_usr', 'firstname_usr', 'lastname_usr', 'email_usr', 'tel_usr', 'fax_usr', 'mailingaddress_usr', 'mailingaddress2_usr', 'mailingcity_usr', 'mailingstate_usr', 'mailingpostcode_usr', 'mailingcountry_usr');
		var shippingFields = new Array('deliverynametitle_usr', 'deliveryfirstname_usr', 'deliverylastname_usr', 'deliveryemail_usr', 'deliveryphone_usr', 'deliveryfax_usr', 'deliveryaddress_usr', 'deliveryaddress2_usr', 'deliverycity_usr', 'deliverystate_usr', 'deliverypostcode_usr', 'deliverycountry_usr');
		
		for(var i=0;i<billingFields.length;i++){
			var billingObj = theForm.elements[billingFields[i]];
			var shippingObj = theForm.elements[shippingFields[i]];
			if(billingObj && shippingObj){
				if(billingObj.tagName){ // non-radio groups
					var tagName = billingObj.tagName.toLowerCase();
					if(tagName == 'select'){
						shippingObj.selectedIndex = billingObj.selectedIndex;
					}
					else if((billingObj.type && shippingObj.type ) && (billingObj.type == 'checkbox' || billingObj.type == 'radio')){
						shippingObj.checked = billingObj.checked;
					}
					else{ // textareas and other inputs
						shippingObj.value = billingObj.value;
					}					
				}
				else if(billingObj.length){ // radio group
					for(var r=0;r<billingObj.length;r++){
						shippingObj[r].checked = billingObj[r].checked;
					}
				}
			}
		}
	}
}
