finType = 0;
    cooArr = new Array;
    typedArr = new Array;
    texture = false;

    function getObj(f) {
        this.oForm = f;
        this.oUppht = 0;
        this.oFont = "";
        this.oUpPrice = "0.00";
        this.oLoPrice = "0.00";
        this.oFract = 0;
        this.oDepth = 0;
        this.oMount = 0;
        this.oStud = f.stud;
        this.oTempl = 0;
        this.oColor = "";
        this.oPhrase = "";
        this.oPgTotal = "0.00";
        this.oQty = f.qty;
        this.oPattern = "0.00";
        this.oFin = "0.00";
        this.oTotal = f.pgTotal;
        this.oMatte = f.matteColor;
        this.di = document.images;
        return this, resetForm(), initmb(), doSize(1), doSize(2), doSize(3), doSize(4), prep(), tot_cook(), doBgCols(0),createPigmentedList() ;
    };


    function data() {
        var ucpr = 0, lcpr = 0, cUpfee = 0, clrFee = 0, mtfee = 0;
        var siz = oUppht; //if(oDepth>3) siz=siz-1;
        var dep = (oDepth==.125)? 0 : (oDepth==.186)? 1 :(oDepth==.25)? 2 :(oDepth==.375)? 3 : (oDepth==.5)? 4 : (oDepth==.75)? 5 : 6;
        var daColor = oColor.substr(0, 1) == "p" ? oColor.substr(1, 4) : oColor.substr(0, 4);
        siz = oFract > 0 ? (siz = siz + 1) : siz;
        
		this.dStr = dArr[dep][siz];
        ucpr = dStr[1];
        var percent=100;
	   	if ((oColor.substr(0, 1) == "p" || oColor.substr(0, 1) == "m") && dep < 5) {
            percent += (oMatte.checked)? 60 : 30;
        };
        percent += (/Flush|Keyhole/.test(oMount))? 25 : (/Tape|Stud Mount|Pad|Combination|Combo/.test(oMount))? 5 :  0;
        ucpr = ucpr*percent/100;
        oUpPrice = fixP(ucpr);
		if(siz > 0){
			var x= testFont(oFont,oPhrase);
			if(x) oPhrase=oPhrase.toUpperCase();
		}else{
			var x=true;
			oPhrase=oPhrase.toUpperCase();
		};
        oLoPrice = (x == true)? "N/A" : fixP(ucpr * 90 / 100);
    };

	function testFont(fon,txt){
		var x=false;
		var fons = Fltr.split("~"); 
		var myfon = fon.toLowerCase().replace(/\s/g, "");
		for (k = 0; k < fons.length; k++) {
			//alert(fons[k]+'---'+myfon)
			if(fons[k] == myfon){
				x=true;
				break;
			};
		};
		return x;
	};

 function analysis() {        
	oPgTotal  = '0.00';
 	var inPut      = oPhrase;
	var outPut     = '';
	var pStart       = 0;  if (oPhrase.selectionStart) {pStart=oPhrase.selectionStart;};
	var pEnd         = 0;  if (oPhrase.selectionEnd  ) {pEnd  =oPhrase.selectionEnd;};
 	var pLen       = oPhrase.length;

 	for(var i=0; i< pLen; i++) { var x = inPut.charAt(i);
			outPut +=
 			x.match(/[A-Z]/)? updatePrice(x, 'upper_case') :
			x.match(/[0-9]/)? updatePrice(x, 'nums') :
 			x.match(/[\-\.,~']/)?  updatePrice(x, 'sm_punc') :
			x.match(/[\/&\!@#$%\(\)?<>\+\*\\]/)?  updatePrice(x, 'lg_punc') :
			x.match(/[;:="]/)?  updatePrice(x, 'colo_chars') :
 			x.match(/[a-z]/)? updatePrice(x, 'lower_case') : " ";
	};
	oPhrase = outPut;
	if (oPhrase.selectionStart)
	{
		oPhrase.selectionStart=pStart;
		oPhrase.selectionEnd=pEnd  ;
	};
};

function updatePrice(x, kind) {    

 	var subT =oPgTotal-0;
 	var upcP =oUpPrice-0;
 	var locP =oLoPrice-0;


 	oPgTotal =
 		(kind =='upper_case')? fixP(subT +upcP) :
		(kind =='nums')?  fixP(subT +upcP):
		(kind =='sm_punc')? fixP(subT +(upcP-0)/3) :
		(kind =='lg_punc')? fixP(subT +(upcP-0)) :
		(kind =='colo_chars')? fixP(subT +((upcP-0)/3)*2) :
		(kind =='lower_case' && locP == 0)?
		(x=x.toUpperCase(),fixP(subT +upcP)) : fixP(subT + locP);
	return x;        //to oPhrase.value
 };



    function prep() {
        var Qty = parseFloat(oQty.value);
        var pt = "";
        var mnt = 0;
        oPhrase = "";
        oPattern = "0.00";
		var ptn=0, myGt=0, sLen=0;
		for (i = 1; i < 5; i++) {
            var pObj = "line" + i, sObj = "upperheight" + i, fObj = "font" + i, dObj = "depth" + i, cObj = "color" + i, mObj = "mount" + i, tObj = "template" + i, frObj = "fraction" + i;
            if (oForm[pObj].value.replace(/\s/g, "").length > 0) {
                if (i > 1 && i < 5) g_id('L' + i).style.display = "";
                if (i > 1 && i < 5) g_id("mnts" + i).style.display = "";
                if (i > 0 && i < 4) g_id("I" + i).style.display = "";
				oPhrase = oForm[pObj].value;
                oFont = oForm[fObj].value
				oUppht = oForm[sObj].selectedIndex;
                oDepth = oForm[dObj][oForm[dObj].selectedIndex].value;
				oFract = oForm[frObj].selectedIndex;
                oColor = oForm[cObj].value;
                oMount = oForm[mObj].value;
                oTempl = oForm[tObj].selectedIndex;
                data();
                analysis();
                oForm[pObj].value = oPhrase;
                sLen += oForm[pObj].value.replace(/\s/g, "").length;
                g_id('LD' + i).innerHTML = oForm[dObj][oForm[dObj].selectedIndex].text;
                g_id('UC' + i).innerHTML = oUpPrice;
                g_id('LC' + i).innerHTML = oLoPrice != "N/A" ? oLoPrice : "N/A";
                g_id('LT' + i).innerHTML = oPgTotal;
                if (oLoPrice != "N/A" && typedArr[i] != null) {
                    oForm[pObj].value = typedArr[i];
                };
			   pt = oForm[tObj].value.substr(0, 2);
                if (pt == "St" || pt == "Po") {
                    daHeight = oForm[sObj][oForm[sObj].selectedIndex].value;
                    daLen = oForm[pObj].value.replace(/\s/g, "").length;
                    addon = 2.25;
                    ptn += addon * daLen;
                    g_id("PP"+i).innerHTML = "$" + fixP(addon * daLen);
                    oPattern = fixP(addon * daLen);
                } else {
                    g_id("PP"+i).innerHTML = "0.00";
                    oPattern = "0.00";
                };
				g_id('TP'+i).innerHTML = "$" + fixP(parseFloat(oPgTotal) + parseFloat(oPattern) + parseFloat(oFin));
				myGt += parseFloat(oPgTotal);
                oForm[frObj].disabled = oForm[sObj].selectedIndex == oForm[sObj].options.length - 1 ||
                    oForm[sObj][oForm[sObj].selectedIndex].value < 1 ? (oForm[frObj].selectedIndex = 0, true) : false;
            } else {
                if (i < 4) {
                    oForm["line" + (i + 1)].value = "";
                    g_id("I" + i).style.display = "none";
				};
                if (i > 1 && i < 5) g_id('L' + i).style.display = "none";
                if (i > 1 && i < 5) g_id("mnts" + i).style.display = "none";
                typedArr[i] = null;
            };
        };
        g_id('ptn').innerHTML= oPattern =  fixP(ptn);
        g_id("bl").innerHTML = "$" + fixP(myGt + ptn);
        g_id('tLtrs').innerHTML = sLen * Qty;
        g_id('tfl').innerHTML = oPgTotal = fixP(myGt * Qty);
        g_id('pgTotal').innerHTML = fixP(parseFloat(oPgTotal) + parseFloat(oPattern));

    };


    function doAbility(lObj, x) {return
        var fObj = "font" + x;
        var sObj = "upperheight" + x;
        var cObj = "color" + x;
        var dObj = "depth" + x;
        var frObj = "fraction" + x;
        if (lObj.value.replace(/\s/g, "").length == 0) {
            if (x > 1) {
                for (i = x; i < 5; i++) {
                    oForm[fObj].disabled = true;
                    oForm[sObj].disabled = true;
                    oForm[cObj].disabled = true;
                    oForm[dObj].disabled = true;
                };
            };

        } else {
            oForm[fObj].disabled = false;
            oForm[sObj].disabled = false;
            oForm[cObj].disabled = false;
            oForm[dObj].disabled = false;
        };
        oForm[frObj].disabled = oForm[sObj].selectedIndex == oForm[sObj].options.length - 1 ||
            oForm[sObj][oForm[sObj].selectedIndex].value < 1 ? (oForm[frObj].selectedIndex = 0, true) : false;
    };


// dyn Template
//function dyTemp(x) {
//	var mObj='mount'+x, tObj='template'+x;
//	var mnt=oForm[mObj].value;
//	z= (/Stud|Combination|Combo|Keyhole/.test(oForm[mObj].value))? 1 : 0;
//		var daLen = pArr[z].length;
//		for (var j =(oForm[tObj].options.length -1); j >0; j--) { oForm[tObj].options[j] = null; };
//		for(var k=0; k< daLen; k++) {
//			oForm[tObj].options[k] = new Option(pArr[z][k][0], pArr[z][k][1]);
//		};
//};




    function doSize(x) {
        if (oUppht == -1) {
            oUppht = 0;
        };
        hObj = "upperheight" + x;
        dObj = "depth" + x;
        var oldVal = oForm[hObj][oForm[hObj].selectedIndex].text;
        var dep = oForm[dObj].selectedIndex;
        dep = dep == -1 ? 0 : dep;
        for (j = oForm[hObj].options.length - 1; j > 0; j--) {
            oForm[hObj].options[j] = null;
        };
        var daLen = dArr[dep].length;
        for (k = 0; k < daLen; k++) {
            oForm[hObj].options[k] = new Option(dArr[dep][k][0] + "\"", dArr[dep][k][0]);
            if (dArr[dep][k][0] + "\"" == oldVal) {
                oForm[hObj].selectedIndex = k;
            };
        };
    };

 	function doDepth(x) {
        dObj = "depth" + x;
        hObj = "upperheight" + x;
        var dOld = oForm[dObj][oForm[dObj].selectedIndex].text;
        for (var j = oForm[dObj].options.length - 1; j > 0; j--) {
            oForm[dObj].options[j] = null;
        };
        var z = oForm[hObj][oForm[hObj].selectedIndex].value < 2 ? 0 : 1;
        var daLen = tArr[z].length;
        var newVal = 0;
        for (var k = 0; k < daLen; k++) {
            oForm[dObj].options[k] = new Option(tArr[z][k][0] + "\"", tArr[z][k][1]);
            if (tArr[z][k][0] + "\"" == dOld) {
                newVal = k;
            };
        };
        oForm[dObj].selectedIndex = newVal;
    };
	
	
    function checkDepth() {
        var myFlag = false;
        for (var i = 1; i < 5; i++) {
            var dObj = "depth" + i;
            if (oForm[dObj].selectedIndex > 4) {
                myFlag = true;
            };
        };
        if (myFlag == true) {
            oForm.finish[0].checked = false;
            oForm.finish[0].disabled = true;
            if (oForm.finish[1].checked == false) {
                oForm.finish[1].click();
            };
        } else {
            oForm.finish[0].disabled = false;
        };
    };

    function addTo() {
        prep();
        var qVal = oForm.qty.value;
	if(oForm.line1.value.replace(/\s/g, "").length == 0) return alert("No letters have been entered in Line 1!");
	for (i = 1; i < 5; i++) {
		var pObj = "line" + i, mObj = "mount" + i, cObj = "color" + i, tpObj = "template" + i;
		if (oForm[pObj].value.replace(/\s/g, "").length > 0) {
				if(/Choose/.test(oForm[cObj].value)) return alert("Please select Color on line "+i); 
				if(/Choose/.test(oForm[mObj].value)) return alert("Please Select Mount on line "+i);
		};
	};
    
	var cookStr = "", lTotal = 0,ptnPr = 0, lookahead = "", cnt = 1;
        var daColor = null, daHeight = 0;
        for (i = 1; i < 5; i++) {
            cnt++;
            var pObj = "line" + i, sObj = "upperheight" + i, dObj = "depth" + i, fObj = "font" + i,tObj = "gt" + i,cObj = "color" + i, laObj = "line" + cnt, mObj = "mount" + i;
            var stObj = "stud" + i,spObj = "spacer" + i,tpObj = "template" + i, bkObj = "brick" + i, frObj = "fraction" + i;
            lookahead = cnt == 5 || oForm[laObj].value.length == 0 ? doChars(g_id("oImg").src) : pObj;
            if (oForm[pObj].value.replace(/\s/g, "").length > 0) {
                daColor = doMatte(oForm[cObj].value);
                
				// calcs total allows for price of one pattern only
				lTotal =  parseFloat(g_id('LT'+i).innerHTML);
				ptnPr = parseFloat(g_id('PP'+i).innerHTML.substr(1));
				lTotal = (lTotal * qVal)+ptnPr;
                
				daHeight = oForm[frObj].selectedIndex > 0 ? parseFloat(oForm[sObj][oForm[sObj].selectedIndex].value) + parseFloat(oForm[frObj][oForm[frObj].selectedIndex].value) : oForm[sObj][oForm[sObj].selectedIndex].text;
                
				cookStr = 
					"Type   		~ Flat Cut Acrylic" + 
					"|Letters  		~ " + doChars(oForm[pObj].value) + 
					"|Font          ~ " + oForm[fObj].value + 
					"|Height        ~ " + daHeight + 
					"|Depth         ~ " + oForm[dObj][oForm[dObj].selectedIndex].text + 
					"|Color         ~ " + daColor + 
					"|Mount         ~ " + oForm[mObj].value + 
					"|Ptn    		~ " + oForm[tpObj].value + 
					"|sLen   		~ " + oForm[stObj][oForm[stObj].selectedIndex].text + 
					"|Spacer Length	~ " + (oForm[spObj].disabled == false ? oForm[spObj][oForm[spObj].selectedIndex].text : "") + 
					"|Mortar Gap    ~ " + oForm[bkObj].value + 
					"|Image         ~ " + lookahead + 
					"|Qty      		~ " + parseFloat(qVal) + 
					"|Price         ~ " + fixP(lTotal);
					
                cookStr = cookStr.replace(/\s+\~\s/g, "~");
                cookStr = cookStr.replace(/\s+\|\s/g, "|");
                cookStr = cookStr.replace(/["]/g, "#Y");
                cookStr = cookStr.replace(/[']/g, "#Z");
                toCook("item_", cookStr);
            };
        };
        location.href = "s_viewCart.htm";
    };


    function doMatte(daColor) {
        if (oMatte.checked) {
            if (daColor.substr(0, 1) == "c") {
                daColor = daColor.substr(0, 5) + " Matte " + daColor.substr(5);
            } else {
                daColor = daColor.substr(0, 4) + " Matte " + daColor.substr(5);
            };
        } else {
            return daColor;
        };
        return daColor;
    };




oForm=document.forms['itemsform'];
function showPicker(inputObj, formField, line){
	    var myObj=formField.substr(0,formField.length-1)+'_picker_div';
		g_id(myObj).linenum=line;		
		g_id(myObj).elem=formField;
		if(myObj=='font_picker_div') {
			createFontList();
			g_id(myObj).style.left = getLeftPos(inputObj) - 600 + "px";
        	g_id(myObj).style.top = getTopPos(inputObj) + inputObj.offsetHeight + 2 + "px";
			
		}else if(myObj=='mount_picker_div') {
			createMountList();
			g_id(myObj).style.left = getLeftPos(inputObj) -138 + "px";
        	g_id(myObj).style.top = getTopPos(inputObj) + inputObj.offsetHeight -394 + "px";
			doMounts(line);
		}else if(myObj=='color_picker_div') {
			var dObj='depth'+line;
			createPigmentedList();
			createPaintedList();
			g_id(myObj).style.left = getLeftPos(inputObj) - 650 + "px";
			g_id(myObj).style.top = getTopPos(inputObj) + inputObj.offsetHeight + 2 + "px";
			doColors(line);
		}else{
			createPatternList(line);
			g_id(myObj).style.left = getLeftPos(inputObj) -258 + "px";
        	g_id(myObj).style.top = getTopPos(inputObj) + inputObj.offsetHeight -271 + "px";
		};
		closePickers(myObj);
		g_id(myObj).style.display="block";
		

};


//colors

function createPigmentedList(){
        var line=(typeof(g_id('color_picker_div')!='undefined'))? 1 : g_id('color_picker_div').linenum;
		var dObj='depth'+line, cObj='color'+line;
		var dep=oForm[dObj][oForm[dObj].selectedIndex].value;
		if(g_id('pigmentedList').innerHTML.length>10000 && dep < .375){
			return;
		};
        var z=(dep<.375)? 0 : 2;
		g_id('pig').style.display= (dep >.5)? (TabbedPanels2.showPanel(1), "none") : (TabbedPanels2.showPanel(0),"block");
		if(dep >.5)	return;
		var myList = '<table border="0" bgColor="#D7D2CD"><tr>';
        for (i = 0; i < colors[z].length; i++) {
            var c=colors[z][i].split('/');
			var mImg = (/2037|2051|2030|2287/.test(c[0]) && dep <.375)? "__colors/tiles/painted/" + c[0].substr(1,4) + "T.jpg" :  "__colors/tiles/painted/" + c[0].substr(1,4) + ".jpg";
			var oImg = "__colors/tiles/painted/swatch/" + c[0].substr(1,4) + ".jpg";
			if(i%9 ==0) myList +='</tr><tr>';
			myList += '<td align="center"><img id="'+c[0].substr(0,5)+'" src="'+mImg+'" onmouseover="getImgLabel(this.id,\''+oImg+'\',\''+c[0]+'\')" onclick="if(this.src.indexOf(\'_d.jpg\')==-1) {colorSelect(\''+c[0]+'\',\''+c[1]+'\')}" /><br /><span class="s" style="align:center">'+c[2]+'</span></td>';
		};
        myList += '</tr></table>';
		g_id('pigmentedList').innerHTML = myList;
};

function createPaintedList(){
        if(g_id('paintedList').innerHTML.length>0) return;
		var myList = '<table border="0" bgColor="#D7D2CD"><tr>';
        for (i = 0; i < colors[1].length; i++) {
			var c=colors[1][i].split('/');
			var mImg = "__colors/tiles/painted/" + c[0].substr(1,4) + ".jpg";
			var oImg = "__colors/tiles/painted/swatch/" + c[0].substr(1,4) + ".jpg";
			if(i%9 ==0) myList +='</tr><tr>';
			myList += '<td align="center"><img id="'+c[0].substr(0,5)+'" src="'+mImg+'" onmouseover="this.style.cursor=\'pointer\'; g_id(\'pSwatch\').src=\''+oImg+'\'" onclick="colorSelect(\''+c[0]+'\',\''+c[1]+'\')" /><br /><span class="s" style="align:center">'+c[2]+'</span></td>';
		};
        
		myList += '</tr></table>';
		g_id('paintedList').innerHTML = myList;
};

function getImgLabel(id,Img,tag){
	var line=g_id('color_picker_div').linenum;
	var dObj='depth'+line;
	var dep=oForm[dObj][oForm[dObj].selectedIndex].value;
	g_id(id).style.cursor=(g_id(id).src.indexOf('_d.jpg')==-1)? 'pointer' : 'default';
	g_id('cSwatch').src= (/2037|2051|2030|2287/.test(id) && dep <.375)? '__colors/tiles/painted/swatch/'+ id.substr(1,4) +'T.jpg' : Img; 
};

function colorSelect(color,hex){
		var myObj=g_id('color_picker_div').elem;
		g_id(myObj).value = color; g_id(myObj).alt = hex.substr(1);
		g_id('color_picker_div').style.display="none";
		oMatte.disabled=(color.substr(0,1)=='p')? false : (oMatte.checked=false,true);
		prep();
		if(oForm.autoupdate.checked) oForm.update.click();
};
lastColorChoice=null;
function doColors(line){	
	var cObj='color'+line;
	var dObj='depth'+line;
	var dep= oForm[dObj][oForm[dObj].selectedIndex].value;
	if(dep <.375){
		if(lastColorChoice !=null){
			oForm[cObj].value=lastColorChoice;
			lastColorChoice=null;
		};
	}else if(dep >.25 && dep < .75){
		if(/2037|2287|2030/.test(oForm[cObj].value)) {
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value=oForm[cObj].value.replace('Translucent', '');
		}else if(/7328/.test(oForm[cObj].value)) {
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value="c7508 White";
		}else if(/2146/.test(oForm[cObj].value)) {
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value="c2718 Ivory";
		}else if(/Translucent/.test(oForm[cObj].value)) {
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value="Choose Color";
			g_id('cSwatch').src= '__colors/tiles/painted/swatch/2222.jpg'; 
		}else if(lastColorChoice !=null){
			if(/Translucent/.test(lastColorChoice)==false){
				oForm[cObj].value=lastColorChoice;
				lastColorChoice=null;
			};
		};
	}else if(dep >.5){
		if(/2222/.test(oForm[cObj].value)) {
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value="p2225 Optical Clear";
		}else if(oForm[cObj].value.substr(0,1) == 'c'){
			lastColorChoice=oForm[cObj].value;
			oForm[cObj].value=oForm[cObj].value.replace('Translucent', '');
			oForm[cObj].value="p"+oForm[cObj].value.substr(1);
			g_id('pSwatch').src= '__colors/tiles/painted/swatch/7508.jpg';
		};
	}
};



//fonts
function createFontList(){
	   if(g_id('fontlist0').innerHTML.length>0) return;
	   for (j = 0; j < fonts.length; j++) { 
			var fObj = 'fontlist'+j;
			var lName = "";
			var myList = '<table border="0" width="100%" bgColor="#ffffff">';
			for (i = 0; i < fonts[j].length; i++) {
				var fIdx =i;
				var daFon = "fontimages/smallfonts/" + fonts[j][i].replace(/\s/g, "") + ".gif";
				daFon=daFon.toLowerCase();
				lName =fonts[j][i];
				myList += '<tr><td id='+lName+' style="height:26px" onmouseover="this.style.cursor=\'pointer\'" onclick="fontSelect(\''+fonts[j][i]+'\',\''+fIdx+'\')">';
				myList += '<img src="'+daFon+'" onmouseover="this.style.borderStyle=\'solid\'; this.style.borderWidth=\'thin\'" onmouseout="this.style.border=\'none\'" ></img></td></tr>';
			};
			myList += '</table>';
			g_id(fObj).innerHTML = myList;
			myList="";
	   };
};

function fontSelect(myfont,fonIdx){
		var line=g_id('font_picker_div').linenum;
		var myObj=g_id('font_picker_div').elem;
		g_id(myObj).value = myfont; g_id(myObj).alt = fonIdx;
        g_id('font_picker_div').style.display="none";
		doSize(line);
		prep();
		if(oForm.autoupdate.checked) oForm.update.click();
};

function doFontTabs(line){
	// code to hide/show the font tabs
	var sObj='upperheight'+line,fObj='font'+line;
	var siz = oForm[sObj][oForm[sObj].selectedIndex].value;
	if(siz==1 && g_id('fontstyles0').style.display=="block"){
		// hides all tabs except block
		var oldVal=oForm[fObj].value;
		for(i=0;i<6;i++){
			var tabObj = 'fontstyles' +i;
			g_id(tabObj).style.display= (i==1)? "block" : "none";
			TabbedPanels3.showPanel(1);
		};
		//attempts to keep the users chosen font if available in the new list
		for(i=0;i<fonts[1].length;i++){
			if(fonts[1][i] == oldVal){
				oForm[fObj].value=oldVal;
				break;
			}else{
				oForm[fObj].value="Antique Olive Medium";
			};
		};
	
	}else if(siz>1 && g_id('fontstyles0').style.display=="none"){
		//view all tabs
		for(i=0;i<6;i++){
			var tabObj = 'fontstyles' +i;
			g_id(tabObj).style.display="block";
			TabbedPanels3.showPanel(0);
		};
	};
};

//mounts
mountNames = new Array('plain','tape','holes','stud','pad','combo','comboall','flushstud','keyhole');
mountLabels = new Array('No Mounts','Doubleface Tape','Through Holes','Stud Mount','Pad Mount','Combination Mount','Combo All Mount','Flush Stud Mount','Keyhole Mount');
function createMountList(){
        if(g_id('mountList').innerHTML.length>0) return;
		var myList = '<table border="0" bgColor="#D7D2CD"><tr>';
        for (i = 0; i < mountNames.length; i++) {
            mImg = "__mounts/tiles/acrylic/" + mountNames[i] + ".jpg";
			lName = mountNames[i];
		if(i==5) myList +='</tr><tr>';
		var myid="mountchoices"+i;
		myList += '<td><img id="'+myid+'" src="'+mImg+'" width="120" height="120" onmouseover="this.style.cursor=(this.src.indexOf(\'_d.jpg\')==-1)? \'pointer\' : \'default\'; showLabel(this.id,'+i+')" onclick="if(this.src.indexOf(\'_d.jpg\')==-1) mountSelect(\''+mountLabels[i]+'\')" /></td>';
		};
        myList += '</tr></table>';
		g_id('mountList').innerHTML = myList;
};

function mountSelect(mount){
		var myObj=g_id('mount_picker_div').elem;
		g_id(myObj).value = mount;
		g_id('mount_picker_div').style.display="none";
		var line=g_id('mount_picker_div').linenum;
		var stObj='stud'+line, spObj='spacer'+line, mObj='mount'+line, bkObj='brick'+line, tpObj='template'+line;
		oForm[stObj].disabled=(/(Stud|Combination|Combo)/.test(oForm[mObj].value))? false : (oForm[stObj].selectedIndex=0,true); 
		oForm[spObj].disabled=(/(Stud)/.test(oForm[mObj].value))? false : (oForm[spObj].selectedIndex=0,true); 
		oForm[bkObj].disabled=(/(Stud|Combo)/.test(oForm[mObj].value))? (oForm[bkObj].value='0',false) : (oForm[bkObj].value='N/A',true); 
		if(/(Pounce|Stud)/.test(oForm[tpObj].value)){
			oForm[tpObj].value= (/(Pounce)/.test(oForm[tpObj].value) && /(Stud|Combination|Combo)/.test(oForm[mObj].value))? 'Stud Pattern' : 'Pounce Pattern';
		};
		prep();
};

function doMounts(line){
	var o=g_id('mountchoices1');if(!o) return;
	var sObj='upperheight'+line, dObj = 'depth'+line, cObj = 'color'+line, mObj = 'mount'+line;
	var siz= oForm[sObj][oForm[sObj].selectedIndex].value;
	var dep= oForm[dObj][oForm[dObj].selectedIndex].value;
	var oldval = oForm[mObj].value;
	var nArr= new Array();
	for(var i=0;i<mountNames.length;i++){
		var myid='mountchoices'+i;
		var greyImg='__mounts/tiles/acrylic/'+mountNames[i]+'_d.jpg';
		var Img='__mounts/tiles/acrylic/'+mountNames[i]+'.jpg';
		if(i<2){
			//plain and tape
			g_id(myid).src=Img;
			nArr[i]=true;
		}else if(i<7){
			//through holes//studblock//pad - combo
			g_id(myid).src=(siz > 1)? (nArr[i]=true,Img) : (nArr[i]=false,greyImg);
		}else if(i==7){
			//flush stud
			g_id(myid).src=(siz>1 && dep > .25)? (nArr[i]=true,Img) : (nArr[i]=false,greyImg);
		}else{
			//keyhole
			var z=checkMIM(line);
			g_id(myid).src=(siz > 5 && dep > .25 && dep < 1 && z == true)? (nArr[i]=true,Img) : (nArr[i]=false,greyImg);
		};
		if(oldval==mountLabels[i]) var itm = i;
	};
	// try to keep users chosen mount
	oForm[mObj].value = (nArr[itm]==true)? oldval : "Choose Mount";
};


function showLabel(id,idx){
	var naTxt = (idx==2)? "Only Available on letters at least 2 inch tall." : 
				(idx==3)? "Only Available on letters at least 2 inch tall and less than 3/8 inch thick." :
				(idx <7)? "Only Available on letters at least 2 inch tall." : 
				(idx==7)? "Only Available on letters at least 2 inch tall and more than 1/4 in thick." : 
				"Only Available on letters at least 6 inch tall and 3/8 to 3/4 inch thick, in black, white or platinum pigmented colors, or any painted color.";
	var bImg = g_id(id).src;
	if(bImg.indexOf('_d.jpg') == -1) { 
		g_id("mountinfo").innerHTML = mount[idx];
	}else{
		g_id("mountinfo").innerHTML = naTxt;
	};
}

function checkMIM(line){
	var sObj='upperheight'+line, dObj = 'depth'+line, cObj = 'color'+line;
	var siz= oForm[sObj][oForm[sObj].selectedIndex].value;
	var dep= oForm[dObj][oForm[dObj].selectedIndex].value;
	var colr=oForm[cObj].value.substr(0,5);
	var mim=false;
	if(siz <18){
		if(colr.substr(0,1) =="c"){	
			if(dep<.375){
				mim=(/c2025|c2037|c2793|c2240|c2767|c2050|c2648|2030|c2162|c2418|c7508|c8807|c8886|c3130|c2222/.test(colr))? true : false;
			}else if(dep==.375){
				mim=(/c2025|c7508|c8807|c8886|c2222/.test(colr))? true : false;
			}else if(dep==.5){
				mim=(/c2025|c7508|c8807|c8886/.test(colr))? true : false;
			}else{
				mim=(/c2225/.test(colr))? true : (/p/.test(colr))? true : false;
			};
		}else{
			mim==true;
		};
	};
	return mim;
};

//pattern

function createPatternList(line){
        g_id('patternList').innerHTML ="";
		var mObj = 'mount'+line;
		patternNames = (/(Stud|Combination|Combo)/.test(oForm[mObj].value))? new Array('yuk','stud','tape'): new Array('yuk','pounce','tape');
		patternLabels = (/(Stud|Combination|Combo)/.test(oForm[mObj].value))? new Array('No Pattern','Stud Pattern','Free Spacing Tape') : new Array('No Pattern','Pounce Pattern','Free Spacing Tape');
		var myList = '<table border="0" bgColor="#D7D2CD"><tr>';
        for (i = 0; i < patternNames.length; i++) {
            mImg = "__mounts/patterns/" + patternNames[i] + ".jpg";
			lName = patternNames[i];
		if(i==5) myList +='</tr><tr>';
		var myid="patternchoices"+i;
		myList += '<td><img id="'+myid+'" src="'+mImg+'" width="170" height="120" onmouseover="this.style.cursor=(this.src.indexOf(\'_d.jpg\')==-1)? \'pointer\' : \'default\'; pattInfo(\''+patternLabels[i]+'\','+i+')" onclick="if(this.src.indexOf(\'_d.jpg\')==-1) patternSelect(\''+patternLabels[i]+'\')" /></td>';
		};
        myList += '</tr></table>';
		g_id('patternList').innerHTML = myList;
};

function patternSelect(patt){
		var myObj=g_id('template_picker_div').elem;
		g_id(myObj).value = patt;
		g_id('template_picker_div').style.display="none";
		var line=g_id('template_picker_div').linenum;
		prep();
};

function pattInfo(id,idx){
	idx = (/(Pounce)/.test(id))? 1 : (/(Stud)/.test(id))? 2 : (/(Free)/.test(id))? 3 : idx;
	g_id("patterninfo").innerHTML = pattinfo[idx];
}


function loadTooltips(){
			g_id("sprytooltip1").innerHTML="<div class='content'><p>To get started, type in the letters, numbers and punctuation, exactly as you want it to read when you make your sign. For multiple line signs, there are 3 other lines that will become available. What you type is what you will get. If lower case letters typed and the size is too small or lower case is not available in the chosen font, those letters will automatically convert to upper case and should convert back again when you change the height or size to something that has availability. What you type here will display in the area below with correct real world dimensions when you leave the text box.</p></div><div class='bottom'></div>";
			g_id("sprytooltip2").innerHTML="<div class='content'><p>Select the uppercase height for the line you are working on. The fraction box will add a fractional unit to the inch box ie; 3-1/2&quot; This gives you a lot of adjustment in your finished line lengths for a set of letters. Only one size can be on one line so if you want large capitals followed by small capitals, you would have to those in an empty line. For those using all lower case, only the ascenders such as 'd I h' are the same height as the corresponding uppercase letter. Body letters such as 'a c s' will be about 2/3rds smaller.</p></div><div class='bottom'></div>";
			g_id("sprytooltip3").innerHTML="<div class='content'><p>The depth measurement is the thickness of the letter when measured front to back. The width of a letter is controlled by the font. Letter depth for sheet cut letters in metal and plastic will determine the price, along with other factors. Depths can be accentuated during installation by choosing spacer stand offs from the mounting options. These allow letters to stand away by a pre-determined length of spacer, giving the letters a shadow effect.</p></div><div class='bottom'></div>";
			g_id("sprytooltip4").innerHTML="<div class='content'><p>The color list is a multi-part selection box allowing you to choose a pigmented color or painted finish to apply to the material. All colors are representative, not actual. Color samples for pigmented acrylic are available for a $50 deposit plus shipping. Our website allows you to buy a single letter as a sample.</p></div><div class='bottom'></div>";
			g_id("sprytooltip5").innerHTML="<div class='content'><p>The Matte checkbox will only be available when a painted finish is chosen. It is also not available when a metallic color is chosen. Matte paint modifiers add 30% to an order.</p></div><div class='bottom'></div>";
			g_id("sprytooltip6").innerHTML="<div class='content'><p>The font list contains a selection of the most popular fonts. The font does not contribute to the price nor does it have to be on this list for us to be able to cut it, which means we can cut your provided font, usually at no extra charge. The font chosen will control the width of a given line of text. For shorter lenghts choose a condensed type font.</p></div><div class='bottom'></div>";
			g_id("sprytooltip7").innerHTML="<div class='content'><p>Aligns the display output below either left, right or center justified. TIP: You can also indent display view text by using spaces before the text to move the line text to the right. </p></div><div class='bottom'></div>";
			g_id("sprytooltip8").innerHTML="<div class='content'><p>The backgrounds allow you to see how your chosen letter color might look against a chosen background color. This is helpful for determining the correct color letter to apply to your wall color. No backgrounds are included with actual order. We do not make finished signs. All letters are individual unless specified otherwise.</p></div><div class='bottom'></div>";
			g_id("sprytooltip10").innerHTML="<div class='content'><p>Which mounting hardware best suits your project requires an understanding of the various mounts available for different types of letters. If you are not sure what kind of mounts to get, we strongly recommend reviewing our installation page with helpful videos explaining many of the mounting methods and their uses. A link to the page can be found on the site menu.</p></div><div class='bottom'></div>";
			g_id("sprytooltip11").innerHTML="<div class='content'><p>Standard stud length is the same as no preference. The factory will decide what lengths to include based on the type of letter, its height and depth. Unless you have a specific need for a specific length, this setting can be left at standard.</p></div><div class='bottom'></div>";
			g_id("sprytooltip12").innerHTML="<div class='content'><p>Stand off is where you want your letters to stand slightly away from the mounting surface for effect. Spacers are pre cut hollow tubes the slip over studs to provide a space between the letter and wall. On Vacuum Formed and Injection Molded letters, a combination all mount replaces the sleeve type mount with adjustable pads that can provide multiple depths by screwing the pad in or out along its stud.</p></div><div class='bottom'></div>";
			g_id("sprytooltip13").innerHTML="<div class='content'><p>Stud for brick applys only to letters with stud/combo type mounts on brick and mortar walls. To avoid you having to drill into the actual brick or block, the factory aligns the stud mounts in equal lines that should fall on the mortar gaps between the bricks. </p><img src='__images/brick.jpg' ><p>You need to supply the center to center measurement vertically, center of mortar gap on top to center of mortar gap below.</p></div></img></div><div class='bottom'></div>";
			g_id("sprytooltip14").innerHTML="<div class='content'><p>A mounting pattern is a full size drawing of the letters you order, laid out with proper spacing and alignment. A pattern is critical for stud type mounts and shows you where to drill for the studs. NOTE: Gemini products require multiple patterns for multiple sets of letters. Without it, you will not get a good result and spend much time and frustration. For other types of mounts, a full size pounce pattern with inked letters that are perforated on their outlines, allows you to rub chalk through leaving an impression on the wall.</p></div><div class='bottom'></div>";

	var sprytooltip1 = new Spry.Widget.Tooltip("sprytooltip1","#ttLetters", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip2 = new Spry.Widget.Tooltip("sprytooltip2","#ttHeight", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip3 = new Spry.Widget.Tooltip("sprytooltip3","#ttDepth", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip4 = new Spry.Widget.Tooltip("sprytooltip4","#ttColor", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip5 = new Spry.Widget.Tooltip("sprytooltip5","#ttMatte", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip6 = new Spry.Widget.Tooltip("sprytooltip6","#ttFont", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip7 = new Spry.Widget.Tooltip("sprytooltip7","#ttAlign", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip8 = new Spry.Widget.Tooltip("sprytooltip8","#ttBackground", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip10 = new Spry.Widget.Tooltip("sprytooltip10","#ttMounts", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip11 = new Spry.Widget.Tooltip("sprytooltip11","#ttStud", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip12 = new Spry.Widget.Tooltip("sprytooltip12","#ttStandoff", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip13 = new Spry.Widget.Tooltip("sprytooltip13","#ttBrick", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
	var sprytooltip14 = new Spry.Widget.Tooltip("sprytooltip14","#ttPattern", {useEffect:"blind", showDelay:250, hideDelay:500, followMouse:true});
};
