function updateimage()
{
	var img = document.getElementById("gen");
	if (img)
	{
		var face = document.tform.face.options[document.tform.face.selectedIndex].value;
		var text = escape(document.tform.box.value);
		var color = document.tform.color.options[document.tform.color.selectedIndex].value;
		var bcolor = document.tform.bcolor.options[document.tform.bcolor.selectedIndex].value;
		img.src = "gen.php?font=" + face + "&color=" + color + "&bcolor=" + bcolor + "&text=" + text;
	}
}

function updateprice()
{
	var pricing = new Array(0, 0.35, 0.45, 0.55, 0.70, 0.80, 0.90, 1.15, 1.45, 1.85, 2.15);
	var text = document.tform.box.value;
	var element = document.getElementById("pricing");
	if (element)
	{
		var price = Math.round(text.length * pricing[document.tform.lheight.options[document.tform.lheight.selectedIndex].value] * 100) / 100 + "";
		var pos = price.indexOf(".");
		if (pos == -1)
			price = price + ".00";
		else
		{
			var decimal = price.substring(pos);
			var first = price.substring(0, pos);
			if (decimal.length > 3)
				decimal = decimal.substring(0, 3);
			else if (decimal.length == 2)
				decimal = decimal + "0";
			price = first + decimal;
		}
		if (price < 4.49 && price != 0)
			price = "4.49";
		if (price == 0)
			price = "0.00";

		element.innerHTML = "<span class=\"revtit\">Your Price:</span> $" + price;
		document.checkoutform.amount.value = price;
	}
	updatereview();
}

function selectcolor(a)
{
	if (document.tform.color.selectedIndex != a)
	{
		document.tform.color.selectedIndex = a;
		updateimage();
		updatereview();
	}
}

function selectbcolor(a)
{
	if (document.tform.bcolor.selectedIndex != a)
	{
		document.tform.bcolor.selectedIndex = a;
		updateimage();
	}
}

function selectfont(a)
{
	if (document.tform.face.selectedIndex != a)
	{
		document.tform.face.selectedIndex = a;
		updateimage();
		updatewidth();
		updatereview();
	}
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  var a = window.open(theURL,winName,features);
  a.focus();
}

function updatewidth()
{
	var width = false;
	var xmlhttp = false;

	if (document.getElementById)
		 width = document.getElementById("width");

	if (typeof ActiveXObject != 'undefined') // IE
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		if (!xmlhttp)
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}

	if (xmlhttp && width)
	{
		xmlhttp.open("GET", "width.php?text=" + escape(document.tform.box.value) + "&height=" +
			document.tform.lheight.options[document.tform.lheight.selectedIndex].value + "&face=" +
			document.tform.face.options[document.tform.face.selectedIndex].value, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				width.innerHTML = "<span class=\"revtit\">Approximate Length:</span> " + xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	else
		tform.document.tform.submit();
}


function updatereview()
{
	var phrase = document.tform.box.value;
	var element = document.getElementById("rphrase");
	if (element)
	{
		if (phrase == "")
			element.innerHTML = "<span class=\"revtit\">Your Phrase:</span> <i><font color=\"#CCCCCC\">Please enter a phrase</font></i>";
		else
			element.innerHTML = "<span class=\"revtit\">Your Phrase:</span> " + phrase;
	}

	var fontx = document.tform.face.options[document.tform.face.selectedIndex].id;
	element = document.getElementById("rfont");
	if (element)
		element.innerHTML = "<span class=\"revtit\">Lettering Style:</span> " + fontx;

	var fontcolor = document.tform.color.options[document.tform.color.selectedIndex].id;
	var elementcolor = document.getElementById("rcolor");
	if (elementcolor)
		elementcolor.innerHTML = "<span class=\"revtit\">Lettering Color:</span> " + fontcolor;

	var lineh = document.tform.lheight.options[document.tform.lheight.selectedIndex].value + "\"";
	elementcolor = document.getElementById("rheight");
	if (elementcolor)
		elementcolor.innerHTML = "<span class=\"revtit\">Line Height:</span> " + lineh;

	var promo = document.checkoutform.promo.value;
	document.checkoutform.os0.value = phrase + " (Style: " + fontx + "; " + fontcolor + "; Height: " + lineh + "; Promo#: " + promo + ")";
}
