function setProduct(prodname) {
	if(prodname != '') document.getElementById('product1').value = prodname;
}

function changestate_a(){
   document.register.state.value= document.register.selectstate.value

}

function changecountry_a(){
   document.register.country.value= document.register.selectcountry.value

}

function updateCard() {
	if(flash) {
		var card = flash.getCardFromFlash();
		
		if(card.custom) document.getElementById('custom').value = card.custom;
		if(card.papercolor) document.getElementById('paper_color').value = card.papercolor;
		if(card.border) document.getElementById('border_style').value = card.border;
		if(card.toptext) document.getElementById('cover_text_top').value = card.toptext;
		if(card.topsubtext) document.getElementById('cover_subtext_top').value = card.topsubtext;
		if(card.bottomtext) document.getElementById('cover_text_bottom').value = card.bottomtext;
		if(card.bottomsubtext) document.getElementById('cover_subtext_bottom').value = card.bottomsubtext;
		if(card.coverfont) document.getElementById('cover_font').value = card.coverfont;
		if(card.bodytext) document.getElementById('inside_text').value = card.bodytext;
		if(card.insidefont) document.getElementById('inside_font').value = card.insidefont;
	}
}

function updateVisible() {
	if($('update').style.display == 'none')
		$('update').style.display = 'inline';
		$('subtotal').style.display = 'none';
		$('subtotal_info').style.display = 'none';
}

function updateHidden() {
	if($('update').style.display == 'inline')
		$('update').style.display = 'none';
		$('subtotal').style.display = 'inline';
		$('subtotal_info').style.display = 'inline';
}

function updatePricing(card) {
	//alert(dumpObj(card, "card", "   ", 1));
	var qty = document.getElementById('qty1').value;
	// 10/21/09: all prices $3
	document.getElementById('price1').value = 3;
	/*if(card.custom == 'standard' || card.custom == 'blank') {
		if(qty >= 1 && qty <= 9)
			document.getElementById('price1').value = 3;
		if(qty >= 10 && qty <= 24)
			document.getElementById('price1').value = 2.5;
		if(qty >= 25 && qty)
			document.getElementById('price1').value = 2.25;
	}*/
	
	if (card.custom == 'custom') {
		//alert(card.customizable);
		var qty = parseInt(document.getElementById('qty1').value);
		if (qty < 25) document.getElementById('qty1').value = 25;
		/*if (card.customizable == 'y') document.getElementById('price1').value = 2.5;
		if (card.customizable == 'p') document.getElementById('price1').value = 3;*/
	}
	
	subTotal();
}

function checkCustomQty() {
	if(flash) var card = flash.getCardFromFlash();
	
	var qty = document.getElementById('qty1').value;
	
	if(card.custom == 'custom') {
		var qty = parseInt(document.getElementById('qty1').value);
		if (qty < 25) document.getElementById('qty1').value = 25;
		// 10/21/09: all prices $3
		/*if(card.customizable == 'y') document.getElementById('price1').value = 2.5;
		if(card.customizable == 'p') document.getElementById('price1').value = 3;*/
		document.getElementById('price1').value = 3
		subTotal();
	}
}

function subTotal() {
	var qty = document.getElementById('qty1').value;
	var price = document.getElementById('price1').value;
	
	document.getElementById('subtotal').value = formatAsMoney((qty * price));
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

function submitCard() {
	updateCard();
	new Ajax.Request("/content/scripts/email_custom.php", {requestHeaders: {Accept:'application/x-json'}, method: "post", parameters: $('subtomals').serialize(), onComplete: function(transport) {
		//alert(transport.responseText);
		var order = transport.responseText.evalJSON(true);
		
		$('product').value = order.product;
		$('price').value = order.price;
		$('qty').value = order.qty;
		
		$('order').submit();
	}});
}