function openwin(loc,name,x,y) {
	xpos = (screen.width/2) - (x/2);
	ypos = (screen.height/2) - (y/2);
	attr = "width=" + x + ", height=" + y + ", location=no, menubar=no, resizable=no, toolbar=no, status=no, scrollbars=yes, top=" + ypos + ", left=" + xpos;
	window.open(loc, name, attr);
}

function openwinns(loc,name,x,y) {
	xpos = (screen.width/2) - (x/2);
	ypos = (screen.height/2) - (y/2);
	attr = "width=" + x + ", height=" + y + ", location=no, menubar=no, resizable=no, toolbar=no, status=no, scrollbars=no, top=" + ypos + ", left=" + xpos;
	window.open(loc, name, attr);
}

function addarcticle(registry, id, needed) {
	var qty = document.getElementById("qty" + id).value;
	if(qty > needed) {
		alert("Please set the quantity to a maximum of " + needed);
		document.getElementById("qty" + id).value = needed;
	} else {
		openwin("/content/add_article.php?registry_cart=" + registry + "&id=" + id + "&qty=" + qty,"addarticle", 250, 110);
	}
}
/*
function giftwrapping(registry, subtotal) {
	var qty = document.getElementById("cb_giftwrapping" + registry);

	if(qty.checked) {
		document.getElementById("costsgiftwrapping" + registry).innerHTML = '$3.00';
		subtotal = subtotal + 3;
		if(subtotal != Math.round(subtotal)) {
			document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal;
		} else {
			document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal + '.00';
		}
		
		total = parseFloat(document.getElementById("total").innerHTML.substr(1)) + 3;
		if(total != Math.round(total)) {
			document.getElementById("total").innerHTML = '$' + total;
		} else {
			document.getElementById("total").innerHTML = '$' + total + '.00';
		}
	} else {
		document.getElementById("costsgiftwrapping" + registry).innerHTML = '$0.00';
		if(subtotal != Math.round(subtotal)) {
			document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal;
		} else {
			document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal + '.00';
		}
		
		total = parseFloat(document.getElementById("total").innerHTML.substr(1)) - 3;
		if(total != Math.round(total)) {
			document.getElementById("total").innerHTML = '$' + total;
		} else {
			document.getElementById("total").innerHTML = '$' + total + '.00';
		}
	}
}
*/
function update_subtotal(registry, articlesubtotal) {
	var currentsubtotal;
	var finalsubtotal = 0;
	var costs;
	var total;
	
	currentsubtotal = parseFloat(document.getElementById("subtotal" + registry).innerHTML.substr(1));
	
	if(registry != 0) {
		if(document.getElementById("cb_giftwrapping" + registry).checked) {
			finalsubtotal += 3;
			document.getElementById("costsgiftwrapping" + registry).innerHTML = '$3.00';
		} else {
			document.getElementById("costsgiftwrapping" + registry).innerHTML = '$0.00';
		}
	}
	
	/*if(document.getElementById("shipping_method_a" + registry).checked) {
		costs = parseFloat(document.getElementById("shipping_method_a" + registry).value);
	}
	if(document.getElementById("shipping_method_b" + registry).checked) {
		costs = parseFloat(document.getElementById("shipping_method_b" + registry).value);
	}
	document.getElementById("costsshipping_method" + registry).innerHTML = '$' + costs + '.00';
	finalsubtotal += costs;*/

	subtotal = articlesubtotal + finalsubtotal;
	if(subtotal != Math.round(subtotal)) {
		document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal;
	} else {
		document.getElementById("subtotal" + registry).innerHTML = '$' + subtotal + '.00';
	}

	total = parseFloat(document.getElementById("total").innerHTML.substr(1)) + (articlesubtotal + finalsubtotal - currentsubtotal);
	if(total != Math.round(total)) {
		document.getElementById("total").innerHTML = '$' + total;
	} else {
		document.getElementById("total").innerHTML = '$' + total + '.00';
	}
}
	
function switch_view() {
	if($('back').style.display == 'none') {
		new Effect.Parallel([
			new Effect.Fade('front', { queue: { position: 'end', scope: 'efx' } }),
			new Effect.Appear('back',{ queue: { position: 'end', scope: 'efx' } })
		], { 
		  duration: 1,
		  queue: { position: 'end', scope: 'switch' }
		});
		$('view_link').innerHTML = 'show front';
	} else {
		new Effect.Parallel([
			new Effect.Fade('back', { queue: { position: 'end', scope: 'efx' } }),
			new Effect.Appear('front',{ queue: { position: 'end', scope: 'efx' } })
		], { 
		  duration: 1,
		  queue: { position: 'end', scope: 'switch' }
		});
		$('view_link').innerHTML = 'show back';
	}
}