
function copyMailingToPhysical(cb){
	if(cb.checked){ // Only copy when the checkbox is checked.
		var theForm = cb.form;
		// The number of elements must match in mailingFields and billingFields. The type of input element must also match between the arrays.
		var mailingFields = new Array('bill_address', 'bill_city', 'bill_zip');
		var billingFields = new Array('map_address', 'map_city', 'map_zip');
		
		for(var i=0;i<mailingFields.length;i++){
			var mailingObj = theForm.elements[mailingFields[i]];
			var billingObj = theForm.elements[billingFields[i]];
			if(mailingObj && billingObj){
				if(mailingObj.tagName){ // non-radio groups
					var tagName = mailingObj.tagName.toLowerCase();
					if(tagName == 'select'){
						billingObj.selectedIndex = mailingObj.selectedIndex;
					}
					else if((mailingObj.type && billingObj.type ) && (mailingObj.type == 'checkbox' || mailingObj.type == 'radio')){
						billingObj.checked = mailingObj.checked;
					}
					else{ // textareas and other inputs
						billingObj.value = mailingObj.value;
					}					
				}
				else if(mailingObj.length){ // radio group
					for(var r=0;r<mailingObj.length;r++){
						billingObj[r].checked = mailingObj[r].checked;
					}
				}
			}
		}
	}
}




function copyPhysicalToBilling(cb){
	if(cb.checked){ // Only copy when the checkbox is checked.
		var theForm = cb.form;
		// The number of elements must match in physicalFields and billingFields. The type of input element must also match between the arrays.
		var physicalFields = new Array('first_name', 'last_name', 'map_address', 'map_city', 'map_state', 'map_zip');
		var billingFields = new Array('card_name_first', 'card_name_last', 'bill_address', 'bill_city', 'bill_state', 'bill_zip');
		
		for(var i=0;i<physicalFields.length;i++){
			var physicalObj = theForm.elements[physicalFields[i]];
			var billingObj = theForm.elements[billingFields[i]];
			if(physicalObj && billingObj){
				if(physicalObj.tagName){ // non-radio groups
					var tagName = physicalObj.tagName.toLowerCase();
					if(tagName == 'select'){
						billingObj.selectedIndex = physicalObj.selectedIndex;
					}
					else if((physicalObj.type && billingObj.type ) && (physicalObj.type == 'checkbox' || physicalObj.type == 'radio')){
						billingObj.checked = physicalObj.checked;
					}
					else{ // textareas and other inputs
						billingObj.value = physicalObj.value;
					}					
				}
				else if(physicalObj.length){ // radio group
					for(var r=0;r<physicalObj.length;r++){
						billingObj[r].checked = physicalObj[r].checked;
					}
				}
			}
		}
	}
}
