var timerId;var currentView=1;var isFontMenuVisible=false;var isColorMenuVisible=false;var isOrderEntry=false;var arrFonts=new Array();var imagePath="images/";function GeneratePreview(){var PreviewImage=document.getElementById("PreviewImage");var Text1=document.getElementById("Text1");var FontFamilyId1=document.getElementById("FontFamilyId1");var FontCode1=document.getElementById("FontCode1");var LetterHeight1=document.getElementById("LetterHeight1");var ColorId1=document.getElementById("ColorId1");var TextValue1=" ";var Text2=document.getElementById("Text2");var FontFamilyId2=document.getElementById("FontFamilyId2");var FontCode2=document.getElementById("FontCode2");var LetterHeight2=document.getElementById("LetterHeight2");var ColorId2=document.getElementById("ColorId2");var TextValue2=" ";var VerticalAlign=document.getElementById("VerticalAlign");var Alignment=document.getElementById("Alignment");var PathType=document.getElementById("PathType");var PathHeight=document.getElementById("PathHeight");var PathWidth=document.getElementById("PathWidth");var LetterSpacing=document.getElementById("LetterSpacing");var previewStatus=document.getElementById("PreviewStatus");var widthField=document.getElementById("width");var heightField=document.getElementById("height");var BackgroundColor=document.getElementById("backgroundColor");var showGrid=document.getElementById("showgrid").checked?"Y":"N";var mirroredImage=document.getElementById("MirroredImage").checked?"Y":"N";var LetterHeight1=LetterHeight1.value;var LetterHeight2=LetterHeight2.value;var selectBox=document.getElementById("LetterHeightSelector");for(i=0;i<selectBox.options.length;i++){if(parseFloat(selectBox.options[i].value)==parseFloat(document.getElementById("LetterHeight"+currentView).value)){selectBox.selectedIndex=i;break}}toggleVerticalAlign();if(Text1.value.length>0){TextValue1=URLencode(Text1.value)}if(Text2.value.length>0){TextValue2=URLencode(Text2.value)}previewStatus.innerHTML="( Loading... )";var parameters="?FontFamilyId1="+FontFamilyId1.value+"&Text1="+TextValue1+"&ColorId1="+ColorId1.value+"&LetterHeight1="+LetterHeight1+"&FontFamilyId2="+FontFamilyId2.value+"&Text2="+TextValue2+"&ColorId2="+ColorId2.value+"&LetterHeight2="+LetterHeight2+"&Alignment="+Alignment.value+"&ShowGrid="+showGrid+"&MirroredImage="+mirroredImage+"&VerticalAlign="+VerticalAlign.value+"&BackgroundColor="+BackgroundColor.value.replace("#","")+"&FontCode1="+FontCode1.value+"&FontCode2="+FontCode2.value+"&PathType="+PathType.value+"&PathHeight="+PathHeight.value+"&PathWidth="+PathWidth.value+"&LetterSpacing="+LetterSpacing.value;xmlhttp.open("GET","SizeAndPriceCalculator.m"+parameters,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){eval(xmlhttp.responseText)}};xmlhttp.send(null);PreviewImage.src="GeneratePreviewImage.m"+parameters}function setTimer(B){if(B==null){B=1}clearTimeout(timerId);var A=document.getElementById("PreviewStatus");A.innerHTML="( Loading... )";timerId=setTimeout("GeneratePreview()",B*1000)}function ImageLoaded(){var A=document.getElementById("PreviewStatus");var B=document.getElementById("PreviewCustomText");var D=document.getElementById("PreviewTextarea");var C=document.getElementById("FontLabel");var E=document.getElementById("ColorLabel");A.innerHTML=""}function URLencode(A){return escape(A).replace(/\+/g,"%2B").replace(/\"/g,"%22").replace(/\'/g,"%27").replace(/\//g,"%2F")}function SetRGB(A){HexToDec(A.replace("#",""))}function switchPhrase(A){if(A==2&&document.getElementById("PathType").value!="0"){alert("Only one phrase is supported on expressions that use a text path other than straight.");document.getElementById("PathType").focus();return }currentView=A;document.getElementById("InputTextarea").value=document.getElementById("Text"+A).value;document.getElementById("FontLabel").innerHTML=document.getElementById("FontName"+A).value+" ("+document.getElementById("FontCode"+currentView).value+")";$("ColorLabel_colorSelector").set("html",$("ColorName"+A).value);$("ColorSwatch_colorSelector").setStyle("background-color",$("ColorBackground"+A).value);if($("ColorBackground"+A).value.toLowerCase()=="#ffffff"){$("ColorSwatch_colorSelector").setStyle("border","solid 1px #000000")}else{$("ColorSwatch_colorSelector").setStyle("border","none")}document.getElementById("TextEntryArea").style.visibility="visible";document.getElementById("TextEntryArea").style.display="block";document.getElementById("BackgroundColorPicker").style.visibility="hidden";document.getElementById("BackgroundColorPicker").style.display="none";setMenuSizes(document.getElementById("FontName"+A).value);ArrangeTabs(A)}function SwitchToBackgroundColorTab(){document.getElementById("TextEntryArea").style.visibility="hidden";document.getElementById("TextEntryArea").style.display="none";document.getElementById("BackgroundColorPicker").style.visibility="visible";document.getElementById("BackgroundColorPicker").style.display="block";ArrangeTabs(3)}function SetVisibility(B,A){if(A){B.style.visibility="visible";B.style.display="block"}else{B.style.visibility="hidden";B.style.display="none"}}function togglePathEntry(A){if(A==1||A==null){SetVisibility(document.getElementById("PathPanel"),true);SetVisibility(document.getElementById("PathProperties"),document.getElementById("PathType").value!="0");SetVisibility(document.getElementById("PathHelpMessage"),document.getElementById("PathType").value!="0")}else{SetVisibility(document.getElementById("PathPanel"),false)}}function ArrangeTabs(G){var F=document.getElementById("tab_leftEdge");var D=document.getElementById("tab1");var H=document.getElementById("tab_mid1");var C=document.getElementById("tab2");var E=document.getElementById("tab_mid2");var B=document.getElementById("tab3");var A=document.getElementById("tab_rightEdge");switch(G){case 1:F.src=imagePath+"designer/tab_l_on.gif";D.src=imagePath+"designer/tab_firstPhrase_on.gif";H.src=imagePath+"designer/tab_lr.gif";C.src=imagePath+"designer/tab_overlayPhrase_off.gif";E.src=imagePath+"designer/tab_divoff.gif";B.src=imagePath+"designer/tab_selectAWallColor_off.gif";A.src=imagePath+"designer/tab_r_off.gif";break;case 2:F.src=imagePath+"designer/tab_l_off.gif";D.src=imagePath+"designer/tab_firstPhrase_off.gif";H.src=imagePath+"designer/tab_rl.gif";C.src=imagePath+"designer/tab_overlayPhrase_on.gif";E.src=imagePath+"designer/tab_lr.gif";B.src=imagePath+"designer/tab_selectAWallColor_off.gif";A.src=imagePath+"designer/tab_r_off.gif";break;case 3:F.src=imagePath+"designer/tab_l_off.gif";D.src=imagePath+"designer/tab_firstPhrase_off.gif";H.src=imagePath+"designer/tab_divoff.gif";C.src=imagePath+"designer/tab_overlayPhrase_off.gif";E.src=imagePath+"designer/tab_rl.gif";B.src=imagePath+"designer/tab_selectAWallColor_on.gif";A.src=imagePath+"designer/tab_r_on.gif";break}togglePathEntry(G)}function toggleFontMenu(){var A=document.getElementById("FontMenu");if(isFontMenuVisible){A.style.visibility="hidden";A.style.display="none"}else{A.style.visibility="visible";A.style.display="block"}isFontMenuVisible=!isFontMenuVisible}function toggleColorMenu(){var A=document.getElementById("ColorMenu");if(isColorMenuVisible){A.style.visibility="hidden";A.style.display="none"}else{A.style.visibility="visible";A.style.display="block"}isColorMenuVisible=!isColorMenuVisible}function toggleVerticalAlign(){var A=document.getElementById("VerticalAlignment");if((document.getElementById("Text1").value!=""&&document.getElementById("Text2").value!="")||(document.getElementById("PathType").value!="")){A.style.display="block";A.style.visibility="visible"}else{A.style.display="none";A.style.visibility="hidden"}}function setMenuSizes(B){for(i=0;i<arrFonts.length;++i){if(arrFonts[i][0]==B){var A=document.getElementById("LetterHeightSelector");var C=arrFonts[i][1];var D=arrFonts[i][2];var E=false;A.options.length=0;for(x=0.5;x<=13;x=x+0.5){if(x>=C&&x<=D){A.options[A.options.length]=new Option(x,x)}}for(i=0;i<A.options.length;i++){if(parseFloat(A.options[i].value)==parseFloat(document.getElementById("LetterHeight"+currentView).value)){A.selectedIndex=i;E=true;break}}document.getElementById("LetterHeight"+currentView).value=A.options[A.selectedIndex].value;break}}}function CalculateCharacterWidth(){}function replaceAll(B,D,C){var A=B.indexOf(D);while(A>-1){B=B.replace(D,C);A=B.indexOf(D)}return B}function GenerateColorPicker(){var C=document.getElementById("ColorPicker");var E=document.getElementById("SaturationDropDown");var G="<table>";var A="";var F;var B;var D=E.options[E.selectedIndex].value/100;var H;var I=25;for(H=0;H<=359;H+=(360/I)){G+="<tr>";for(B=0.1;B<=1;B+=0.02){A=HlsToRgb(H,B,D);G+='<td style="width: 10px; height: 4px; background-color: #'+A+';" onclick="loadBackgroundColor(\'#'+A+"');\" onmouseover=\"setPreviewColor('#"+A+"');\"> </td>"}G+="</tr>"}G+="<tr>";for(F=0;F<=255;F+=5.7){A=ConvertToHex(F)+ConvertToHex(F)+ConvertToHex(F);G+='<td style="width: 10px; height: 10px; background-color: #'+A+';" onclick="loadBackgroundColor(\'#'+A+"');\" onmouseover=\"setPreviewColor('#"+A+"');\"> </td>"}G+="</tr>";C.innerHTML=G}function loadBackgroundColor(A){var B=document.getElementById("SelectedColor");B.style.backgroundColor=A;document.getElementById("backgroundColor").value=A;GeneratePreview()}function setPreviewColor(A){var B=document.getElementById("PreviewColor");B.style.backgroundColor=A}function HlsToRgb(D,B,C){var I;var G;var F;var E;var A;if(B<=0.5){G=B*(1+C)}else{G=B+C-B*C}I=2*B-G;if(C==0){F=(B*255);E=(B*255);A=(B*255)}else{F=(QqhToRgb(I,G,D+120)*255);E=(QqhToRgb(I,G,D)*255);A=(QqhToRgb(I,G,D-120)*255)}return ConvertToHex(F)+ConvertToHex(E)+ConvertToHex(A)}function QqhToRgb(A,C,B){if(B>360){B=B-360}else{if(B<0){B=B+360}}if(B<60){return A+(C-A)*B/60}else{if(B<180){return C}else{if(B<240){return A+(C-A)*(240-B)/60}else{return A}}}}function GiveDec(Hex){if(Hex=="A"){Value=10}else{if(Hex=="B"){Value=11}else{if(Hex=="C"){Value=12}else{if(Hex=="D"){Value=13}else{if(Hex=="E"){Value=14}else{if(Hex=="F"){Value=15}else{Value=eval(Hex)}}}}}}return Value}function HexToDec(A){Input=A;Input=Input.toUpperCase();a=GiveDec(Input.substring(0,1));b=GiveDec(Input.substring(1,2));c=GiveDec(Input.substring(2,3));d=GiveDec(Input.substring(3,4));e=GiveDec(Input.substring(4,5));f=GiveDec(Input.substring(5,6));document.getElementById("red"+currentView).value=(a*16)+b;document.getElementById("green"+currentView).value=(c*16)+d;document.getElementById("blue"+currentView).value=(e*16)+f}function ConvertToHex(E){var C=16;var A="",D=Math.floor(Math.abs(E)),B;while(true){B=D%C;A="0123456789abcdefghijklmnopqrstuvwxyz".charAt(B)+A;D=(D-B)/C;if(D==0){break}}A=((E<0)?"-"+A:A);A="00"+A;A=A.substring(A.length-2,A.length);return A}function UpdateColor(B,A){document.getElementById("ColorName"+currentView).value=$("ColorLabel_colorSelector").get("html");$("ColorBackground"+currentView).value="#"+A;document.getElementById("ColorId"+currentView).value=B;GeneratePreview()};
