﻿/*****************************************************************\
*******************************************************************
**********    Tag Designer Created By Leonard Sperry      **********
**********  If you you would like to use this script,    **********
**********    Please Contact Seattle Engraving at        **********
**********          info@seattleengraving.com            **********
**********      or leonards@seattleengraving.com         **********
*******************************************************************
\*****************************************************************/



		var cb=new Array('black','white','#e01','#fff','#037','#fff','#ee2','#000','#f70','#f70','#0f0','#190');
		var ct=new Array('White','black','#fff','#e01','#fff','#037','#000','#ee2','#000','#fff','#fff','#fff');
		heightflag = 0;
		initFlag = 0;
		l=2;
		var display;
		var StartUp;
		var Resetting;
	
function updatetagtext(z) 
	{
			tagSpan = document.getElementById('innerTagTextDiv' + z.toString(10));
			tagSpan.innerHTML = eval('document.forms[0].tctagtext' + z.toString(10) + '.value.toUpperCase();');
			checkWidth(z);
	}
	
function changewidth() 
	{
		x = document.forms[0].tcwidth.value + document.forms[0].TcWidthFract.value;
		display.style.width= 150*x + 'px';
		changefont();		
	}
	
function changeheight() 
	{
		y = document.forms[0].tcheight.value;
		y2 = document.forms[0].TcHeightFract.value
		if(y == "0" && (y2 == "" || y2 == ".25"))
		{
		    alert("Tag Height cannot be less than 1/2 in.");
		    document.forms[0].tcheight.selectedIndex = 1;
		    document.forms[0].TcHeightFract.selectedIndex = 0;
		    y = document.forms[0].tcheight.value;
		    y2 = document.forms[0].TcHeightFract.value
		}
		y = y+y2;
		object = document.getElementById('tctagcontent');
		object.style.height= 150*y + 'px';
		centertext();
	}
function changefont() 
	{
		for ( z = 1 ; z <= l ; ++z) 
		{
	        eval('f = document.forms[0].tcfontsize' + z.toString(10) + '.value;');
	        temp = "tagtextdiv" + z.toString(10) ;
	        tagDiv = document.getElementById(temp);	        
	        fontpx = 150*f;
			tagDiv.style.fontSize = fontpx + 'px';
			checkWidth(z);
		}
		centertext();
	}
	
function changecolor() 
	{
		c2 = ct[document.forms[0].tccolor.value];
		c1 = cb[document.forms[0].tccolor.value];
		object = document.getElementById('tctagcontent');
		object.style.backgroundColor = c1;
		object.style.color = c2;
	}

function changelines() 
	{
		l = document.forms[0].tclines.value;		
		for ( z=1 ; z <= 6 ; ++z) 
		{
			if (z<=l)
			{
				if (navigator.userAgent.indexOf("MSIE") != -1)
				{
					document.getElementById('TcTextEntry'+z.toString(10)).style.display = 'inline';
					document.getElementById('tagtextdiv'+z.toString(10)).style.display = 'inline';
				}
				else
				{
					document.getElementById('TcTextEntry'+z.toString(10)).style.display = 'table-row';
					document.getElementById('tagtextdiv'+z.toString(10)).style.display = 'table-row';
				}
			    updatetagtext(z);
			}
			else
			{
				document.getElementById('TcTextEntry'+z.toString(10)).style.display = 'none';
				document.getElementById('tagtextdiv'+z.toString(10)).style.display = 'none';
		        document.getElementById("outerLine"+z.toString(10)+"Height").value = '0';
			}
		}	
		changefont();
	}
		
function centertext() 
	{
		totalLineHeight = 0;
		tempLineHeight = 0;
		fontHeight = 0
		y = document.getElementById('tctagcontent').offsetHeight;
		for ( z=1 ; z <= l ; ++z) 
		{
			object = document.getElementById('tagtextdiv' + z.toString(10) );
			object.style.height = 1.5+'em';
			tempLineHeight = object.offsetHeight;
			totalLineHeight = totalLineHeight + tempLineHeight;
		}
		toppad = (y - totalLineHeight)/2-5;
        var tempTopPad = toppad;
		for ( z=1 ; z <= l ; ++z) 
        {
            object = document.getElementById('tagtextdiv'+z.toString(10));
            object.style.top = tempTopPad+object.offsetHeight/4 + 'px';
            tempTopPad=tempTopPad+(object.offsetHeight);
        }
//check height		
		if (totalLineHeight > y-25)
		{
			if  (StartUp==false)
			{
			    alert("TOO TALL!!\n\nThe number of lines or the \nfont sizes you entered \nare too tall for the tag. \n\nSuggestions: \n\n\xbb   adjust the number of lines \n\xbb   adjust the height \n\xbb   adjust the font size");
		    }
		}
	}
		
	function resetTC()
	{
	    Resetting = true;
	    ReInit();
	    Resetting=false;
	}	
		
	function initPage() 
		{
		display = document.getElementById('tctagcontent');
			changeheight();
			changewidth();
			changelines();
			changecolor();
		}
		
	function ReInit()
	{
		StartUp=true;
		if (document.getElementById('PostSubmit').value != "true" || Resetting == true)
		{
		display = document.getElementById('tctagcontent');
	    obj = document.getElementById('tcheight');
	    obj.selectedIndex = 8; 
	    obj = document.getElementById('TcHeightFract');
	    obj.selectedIndex = 0;  
	    changeheight();
	    obj = document.getElementById('tcwidth');
	    obj.selectedIndex = 11;
	    obj = document.getElementById('TcWidthFract');
	    obj.selectedIndex = 0;
	    changewidth();
	    obj = document.getElementById('tclines');
	    obj.selectedIndex = 1;
	    for (var i = 1 ; i <= 6 ; i++)
	    {
	        obj = document.getElementById('tctagtext'+i.toString(10));
	        obj.value = "";
	        obj = document.getElementById('tcfontsize'+i.toString(10));
	        obj.selectedIndex = 8;   
	    }
	    changelines();     
	    obj = document.getElementById('tcheight');
	    obj.selectedIndex = 1;  
	    changeheight();
	    obj = document.getElementById('tcwidth');
	    obj.selectedIndex = 2; 
	    changewidth();
	    obj = document.getElementById('tccolor');
	    obj.selectedIndex = 0;
	    changecolor();
	    for (var i = 1 ; i <= 2 ; i++)
	    {
            object = document.getElementById('innerTagTextDiv' + i.toString(10) );
	        object.innerHTML = "YOUR TEXT";
	    }
	    changefont();
	    }
	    else
	    {
	        initPage();
	    }
	    StartUp=false;
	}
		
	function checkWidth (z)
	{
	    tagDiv = document.getElementById('tagtextdiv' + z.toString(10));	        
	    tagSpan = document.getElementById('innerTagTextDiv' + z.toString(10));	        
		outerWidth = tagDiv.offsetWidth;
		outerHeight= tagDiv.offsetHeight;
		innerWidth = tagSpan.offsetWidth;
		innerHeight = tagSpan.offsetHeight;
		document.getElementById("line"+z.toString(10)+"width").value = tagSpan.offsetWidth;
		document.getElementById("line"+z.toString(10)+"height").value = tagSpan.offsetHeight;
        document.getElementById("outerLine"+z.toString(10)+"Height").value = tagDiv.offsetHeight;
		if ((innerWidth > outerWidth-50) || (innerHeight>outerHeight))
		{
		    if (StartUp==false)
		    {
		        alert("TOO WIDE!!\n\nThe text you entered is too long.\n\nSuggestions\n\xbb   adjust the font size\n\xbb   adjust the width\n\xbb   add another line");
		    }
		}
	}

