function duplicate_ship(){
	var dup = document.getElementById('bill_ship_same');
	var bill = new Array('bill_first_name','bill_day_phone','bill_last_name','bill_evening_phone','bill_address_1',
						 'bill_address_2','bill_city','bill_state','bill_zip');	
	
	for(var i = 0; i < bill.length; i++){
		var b = document.getElementById( bill[i] );
		var s = document.getElementById( bill[i].replace('bill_', 'ship_') );
		
		if( dup.checked ) s.value = b.value; else s.value = '';
	}
}

function confirm_delete( txtName, txtUrl ){
	var msg = 'Are you sure you want to delete ' + txtName + '?';
	var ok = confirm(msg);
	
	if( ok )
		document.location.href = txtUrl;
}

var sortAttribute;

function addOption(from,to){
	var foo = document.getElementById(from);
	var foo2 = document.getElementById(to);
	
	for( var i = 0; i < foo.options.length; i++ ){
		if( foo.options[i].selected == true ){
			var opt = foo2.appendChild(document.createElement('option'));
			opt.text = foo.options[i].text;
			opt.value = foo.options[i].value;

			foo.removeChild(foo.options[i]);

			--i;
			SortSelect(foo2);
		}
	}
}

function removeOption(to,from){
	var foo = document.getElementById(to);
	var foo2 = document.getElementById(from);

	for( var i = 0; i < foo.options.length; i++ ){
		if( foo.options[i].selected == true ){
			var opt = foo2.appendChild(document.createElement('option'));
			opt.text = foo.options[i].text;
			opt.value = foo.options[i].value;

			foo.removeChild(foo.options[i]);

			--i;
			SortSelect(foo2);
		}
	}
}	

function SortSelect(sel){
	if (!sel) return;
	sortAttribute = 'value';

	var numOpts=sel.options.length;
	var opts=[];
	for (var i=0;i<numOpts;i++) opts[i]=sel.options[i];
	opts.sort(SortBySortOrder);
	for (var i=0;i<numOpts;i++) sel.options[i].swapNode(opts[i]);
}

function SortBySortOrder(a,b){
	if (!sortAttribute) return 0;
	var aOrder = a.getAttribute(sortAttribute);
	var bOrder = b.getAttribute(sortAttribute);
	return (aOrder<bOrder?-1:aOrder>bOrder?1:0);
}

function selFields( fields ){
	
	for(var x = 0; x < fields.length; x++){
		var foo = document.getElementById( fields[x] );

		if( foo.options.length > 0 ){
			for( var i = 0; i < foo.options.length; i++ )
				foo.options[i].selected = true;
		}
	}
	
	return true;
}

function show_img(img,width,height){
	var w = window.open('','WeddingCakes','height='+(height+5)+',width='+width);
  
	w.document.write('<html><head><title>Annie Pies Wedding Cakes</title><style type="text/css">body{ margin:0; padding:0; }</style></head><body>');
	w.document.write('<center><a href="#" onclick="window.close()" style="color:#000;">close window</a><br />');
	w.document.write('<img src="' + img + '" border="0"></center>');
	w.document.write('</body></html>');
	w.document.close();
}