
	function makeArray(len) {
      for (var i = 0; i < len; i++) this [i] = 0;
      this.length = len;
   }


  var lineP = new makeArray(3);
  var lineH = new makeArray(3);
  var lineL = new makeArray(3);
  var lineW = new makeArray(3);
  var lineT = new makeArray(3);
  var lineIndex = new makeArray(3);
  var Cost = new makeArray(20);
  var Stitch = new makeArray(20);
  var QtyBreak = new makeArray(20);
  var Colors = new makeArray(50);

//Cost is the price per 1000 stitches Largest qty first
Cost[6] = .51;
Cost[5] = .55;
Cost[4] = .59;
Cost[3] = .62;
Cost[2] = .68;
Cost[1] = .78;
Cost[0] = 1.00;

Stitch[0] = 700;
Stitch[1] = 1000;
Stitch[2] = 1440;
Stitch[3] = 1650;
Stitch[4] = 1860;
Stitch[5] = 2660;

QtyBreak[6] = 72;
QtyBreak[5] = 61;
QtyBreak[4] = 49;
QtyBreak[3] = 37;
QtyBreak[2] = 25;
QtyBreak[1] = 12;
QtyBreak[0] = 1;

Colors[0] = "#121C26";
Colors[1] = "#ffffff";
Colors[2] = "#cf142b";
Colors[3] = "navy";
Colors[4] = "#F7E017";
Colors[5] = "#E0AD12";
Colors[6] = "#007336";
Colors[7] = "#7AABDE";
Colors[8] = "#94B5E0";
Colors[9] = "#9EC9E3";
Colors[10] = "#0033AB";
Colors[11] = "#00364A";
Colors[12] = "#1C1475";
Colors[13] = "#211A52";
Colors[14] = "#6699C2";
Colors[15] = "#0099BA";
Colors[16] = "#00476B";
Colors[17] = "#EDCC61";
Colors[18] = "#FAE042";
Colors[19] = "#E0AD12";
Colors[20] = "#00B07A";
Colors[21] = "#009687";
Colors[22] = "#1A3024";
Colors[23] = "#404714";
Colors[24] = "#004730";
Colors[25] = "#FAABB0";
Colors[26] = "#6E2636";
Colors[27] = "#DE1F82";
Colors[28] = "#FC8CA1";
Colors[29] = "#B01C2E";
Colors[30] = "#";
Colors[31] = "#FA9C6E";
Colors[32] = "#F57000";
Colors[33] = "#521C78";
Colors[34] = "#B591D6";
Colors[35] = "#B08057";
Colors[36] = "#";
Colors[37] = "tan";
Colors[38] = "#C9B582";
Colors[39] = "#473333";
Colors[40] = "#DBD9D1";
Colors[41] = "#CFC9C4";
Colors[42] = "#8C8F91";
Colors[43] = "#737373";

for (var l = 1; l < 4; l++) {
	lineIndex[l] = 0;
	lineP[l] = 0;
	lineH[l] = 0;
	lineL[l] = 0;
	lineW[l] = 0;
	lineT[l] = 0;}

function CheckQty() {
//Match Qty to QtyBreak array value to get value for n
// n determines which Stitch cost is applied to all costs
var m = 6;
	for (var n = 0; n < 6; n++) {
		if(qty >= QtyBreak[n]) {m = n;}
	}
	StitchCost = Cost[m]/1000;
}

	function ChangePrice() {
	//first get all current size and current # of characters minus spaces
	//calculat new price from base price plus.
	qty = parseInt(document.getElementById('qty').value);
	basePrice = eval(document.getElementById('Setup').value);
	CheckQty();
	line1 = document.getElementById('line_1_text').value;
	line1c = space(line1) * Stitch[document.getElementById('line_1_size').selectedIndex] * StitchCost;
//	line1c = space(line1) * document.getElementById('line_1_size').value;
	line2 = document.getElementById('line_2_text').value;
	line2c = space(line2) * Stitch[document.getElementById('line_2_size').selectedIndex] * StitchCost;
	line3 = document.getElementById('line_3_text').value;
	line3c = space(line3) * Stitch[document.getElementById('line_3_size').selectedIndex] * StitchCost;
	price = parseInt((line1c + line2c + line3c)*100)/100;
	price = price + "";
	len_p = price.length;
	if(price.indexOf(".") == -1) {price = price + ".00";}
	if(price.indexOf(".") == len_p -2) {price = price + "0";}

	orderprice = parseInt((basePrice + (price * qty))* 100)/100;
	orderprice = orderprice + "";
	len_p = orderprice.length;
	if(orderprice.indexOf(".") == -1) {orderprice = orderprice + ".00";}
	if(orderprice.indexOf(".") == len_p -2) {orderprice = orderprice + "0";}
	TotPrice.innerHTML = "$" + price;
	orderPrice.innerHTML = "$" + orderprice;
}
	function space(check) {
	var space = " ";
	var test = check.length;
	for (var i = 0; i < check.length; i++) {
		if(check.charAt(i) == space) {test--;}
	}
	return test;
}
	function TextColorChange(ID)  {
	var col = parseInt(window.event.srcElement.selectedIndex);
ID.style.color = Colors[col];
	//ID.style.color = window.event.srcElement.value;
//orderPrice.innerHTML = "color " + col ;
}

img_ref = "images/thumb-crop.php?cropy=100&maxd=150&name=";
font_ref = "images/";

	function Style()  {
	style_img = img_ref + window.event.srcElement.value.toLowerCase() + ".jpg";
	debug = "Results: ";
	document.style.src = style_img;
}


	function Font()  {
	font_img = font_ref + "f-" + window.event.srcElement.value.toLowerCase() + ".jpg";
	debug = "Results: ";
	document.font.src = font_img;
}


	function SizeChange(ID)  {
	var size = window.event.srcElement.value + "in";
	ID.style.fontSize = size;
	ChangePrice();
	LineState();
	ImageTop();
	NewLoc();
}

	function PosChange(ID,LINE)  {
	var line = parseInt(LINE);
	newpos = 0;
	pos = window.event.srcElement.value.charAt(0);
	debug = "Results: ";
	LineState();
	ImageTop();
NewLoc();
}

function render(ID) {
	ID.innerHTML = window.event.srcElement.value;
	ChangePrice();
//	NUM= ID.value.charAt(5);
	LineState();
	ImageTop();
	NewLoc();
//	Location();
}


function LineState() {
debug = "line state ";
	for(var k = 1;k <= 3; k++) {
		var lineX = "line_"+k;
		lineH[k] = eval(document.getElementById(lineX).offsetHeight);
		debug += "H " + k + " " + lineH[k] + " ";
		lineT[k] = eval(document.getElementById(lineX).offsetTop);
		debug += "T " + k + " " + lineT[k] + " ";
		lineW[k] = eval(document.getElementById(lineX).offsetWidth);
		debug += "W " + k + " " + lineW[k] + " ";
		lineL[k] = eval(document.getElementById(lineX).offsetLeft);
		debug += "L " + k + " " + lineL[k] + " ";
		var lineX = "line_"+k+"_pos";
		lineP[k] = document.getElementById(lineX).value.charAt(0);
		debug += "P " + k + " " + lineP[k] + "<br>";
	}
}

function ImageTop () {
NewImgT = 0;
//debug += "image ";
	imgh = eval(image.offsetHeight);
	imgw = eval(image.offsetWidth);
	l1w = eval(L1.clientWidth);
	imgL = (l1w - imgw)/2;
	imgR = imgL + imgw;
	for(var k = 1;k <= 3; k++) {
		if(lineP[k] =='O' && lineW[k] > 0) {NewImgT = NewImgT + lineH[k];}
	}
	debug += "H " + imgh + " left " + imgL; 
	image.style.position = "absolute";
	image.style.pixelTop = NewImgT;
	image.style.left = imgL;
	document.getElementById('img_T').value = NewImgT;
	document.getElementById('img_L').value = imgL;
	imgB = NewImgT + imgh;
//	debug += " top " + NewImgT + " bot " + imgB + "<br>";
//test_out.innerHTML = debug; 
}

function NewLoc () {
//debug += "Loc ";
L = 0;
T = 0;
U = 2;
	for(var k = 1;k <= 3; k++) {
		var lineX = "line_"+k;
		if(lineP[k] == 'L') {
			lineT[k] = NewImgT + (imgh/2 - lineH[k]/2);
		lineL[k] = imgL - lineW[k];
			L = 1;
		}
		if(lineP[k] == 'R') {
			lineT[k] = NewImgT + (imgh/2 - lineH[k]/2);
		lineL[k] = imgR;
			L = 1;
		}
		if(lineP[k] == 'O') {
			lineL[k] = (l1w - lineW[k])/2;
			lineT[k] = T;
			T = T + lineH[k];
		}
		if(lineP[k] == 'U'){
			lineL[k] = (l1w - lineW[k])/2;
			lineT[k] = imgB + U;
			U = U + lineH[k];
		}
//	debug += "New T " + lineT[k] + " New left " + lineL[k] + "<br>";
//	test_out.innerHTML = debug;
	}
	line_1.style.pixelTop = lineT[1];
	document.getElementById('line_1_T').value = lineT[1];
	line_1.style.pixelLeft = lineL[1];
	document.getElementById('line_1_L').value = lineL[1];
	line_2.style.pixelTop = lineT[2];
	document.getElementById('line_2_T').value = lineT[2];
	line_2.style.pixelLeft = lineL[2];
	document.getElementById('line_2_L').value = lineL[2];
	line_3.style.pixelTop = lineT[3];
	document.getElementById('line_3_T').value = lineT[3];
	line_3.style.pixelLeft = lineL[3];
	document.getElementById('line_3_L').value = lineL[3];
//test_out.innerHTML = debug;	
	L1h = eval(L1.clientHeight);
	 H = T + U + imgh;
	 if(L1h <= H +20) {H = H + 20;}
		else {H = 300;}
	L1.style.height = H;
}


/*
var message="Sorry, Leblanc Embroidery Can't let you do that!";
function click(e) {
	if (document.all) {
		if (event.button==2||event.button==3) {
		alert(message);
		return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
		alert(message);
		return false;
		}
	}
}
	if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	}

document.onmousedown=click;
*/

