var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;

function getRef(i, p) {
	p = !p ? document : p.navigator ? p.document:p;
	return isIE ? p.all[i]:isDOM ? (p.getElementById ? p : p.ownerDocument ).getElementById(i) : isNS4 ? p.layers[i] : null;
}

function refreshprice() {
	var preview = getRef('preview');
	aspect_ratio = preview.width/preview.height;
	var winput = getRef('width');
	var hinput = getRef('height');
	winput.value = Number(hinput.value*aspect_ratio).toFixed(2);
	var totinput = getRef('price');
	var line1 = getRef('line1');
	var line2 = getRef('line2');
	
	if (line2.value == '')
		tempcost = Number(winput.value*hinput.value*sqinch_cost_line1).toFixed(2);
	else
		tempcost = Number(winput.value*(hinput.value/2)*sqinch_cost_line1
														+winput.value*(hinput.value/2)*sqinch_cost_line2).toFixed(2);
	
	if (tempcost < minimum_cost)
		tempcost = minimum_cost;
		
	totinput.value = tempcost;
		
	// Refresh product description
	var description = getRef('product');
	var font = getRef('font');
	description.value = winput.value+'" width x '+hinput.value+'" height - font: '+font.options[font.selectedIndex].text+' - line 1: '+line1.value;
	if (line2.value != '')
		description.value = description.value+' - line 2: '+line2.value
}

function refreshimage() {
	var preview = getRef('preview');
	var line1 = getRef('line1');
	var line2 = getRef('line2');
	var font = getRef('font');
	preview.src = 'createimage.php?line1='+encodeURIComponent(line1.value)+'&line2='+encodeURIComponent(line2.value)+'&font='+font.options[font.selectedIndex].value+'.ttf';
	window.setTimeout('refreshprice()', 3000);
}

function refreshheight() {
	var winput = getRef('width');
	var hinput = getRef('height');
	hinput.value = Number(winput.value/aspect_ratio).toFixed(2);
	refreshprice();
}

function refreshwidth() {
	var winput = getRef('width');
	var hinput = getRef('height');
	winput.value = Number(hinput.value*aspect_ratio).toFixed(2);
	refreshprice();
}

function ShowFonts() {
	var text = getRef('line1');
	window.open('showfonts.php?text='+encodeURIComponent(text.value), null, 'width=600,height=400,scrollbars');
}