var fontLengthFront=15; var fontLengthBack=10; var strErrorPreview = "You have to update your preview first"; var strErrorRemoveBack = "Are you sure you want to remove the back of this design?"; var strDefaultsFront = "WARNING!\nYou have left some of our example text on your design.\nPlease remove any text not required and preview again."; var strLetterheadLaserWarning = "PLEASE NOTE: Letterhead quantities of 25, 50, 100, 250 and 500 are not guaranteed for use on a laser printer."; var strLeaveWarning = "You are about to leave the designer interface.\nYour work has been saved.\nYou can retrieve your work by clicking view recent items at the top of the screen."; var strInvalidFileTypeFront = "You need to select a file for the front of the design first"; var strInvalidFileTypeBack = "You need to select a file for the back of the design first"; var strSelectFileFront = "You need to select a file for the front of the design first"; var strSelectFileBack = "You need to select a file for the back of the design first"; var strAutoSave = "Auto save in progress..."; var strAutoSaveComplete = "Auto save complete!"; var strFront = "Front"; var strFrontAndBack = "Front and back"; document.domain = "smileprint.co.uk"; window.onunload = MJDisplaySavedMessage; // Define global variables var g_frm = document.card_form; var g_timer; // Used to timer how long preview takes to return var g_sfront = "front"; var g_sback = "back"; var g_ipreviewcount = 0; var g_activecontent, g_activestage; var g_pulldown; var g_seenselectback = false; var fontLength=fontLengthFront; var colorTarget, fontTarget; ////////////////////////////////////////////////////////////////////////////////////////////// // Functions called when requesting a preview function MJPreview(side){ // This sends the form to printra to generate a preview timer = new Date().getTime(); MJSaveForm(); MJSetPreviewImages(side, MJGetBuildingImage()); g_frm.action = "/import/"; g_frm.kinds.value = g_frm["kinds_"+side].value; g_frm.side.value = side; g_frm.target = 'frame_'+side; if(side==g_sfront) g_frm.url.value = ""; else g_frm.urlback.value = ""; g_frm.submit(); } function MJGetBuildingImage() { // Gets the filename of the animated gif that plays whilst we are waiting for printra return "http://www.smileprint.co.uk:80/images/bi"+g_frm.baseproductid.value+g_frm.isupload.value+g_frm.o.value+"_uk.gif"; } ////////////////////////////////////////////////////////////////////////////////////////////// // Functions called when printra responds with a preview function ShowProof(side){ var oFrame = window["frame_"+side]; if(side==g_sfront){ g_frm.url.value = oFrame.i_ImgUrl; g_frm.token.value = oFrame.i_token; if(g_frm.uploaded_logo) g_frm.uploaded_logo.value = oFrame.i_uploaded_logo; if(g_frm.uploaded_bg) g_frm.uploaded_bg.value = oFrame.i_uploaded_bg; if(g_frm.uploaded_eps) g_frm.uploaded_eps.value = oFrame.i_uploaded_eps; setTimeout("MJSetPreviewImages('"+side+"', '"+g_frm.url.value+"')", 100); } else { g_frm.token_back.value = oFrame.i_token g_frm.urlback.value = oFrame.i_ImgUrl; // The current serve stationery is used by styles that return a back and a front if(g_frm.uploaded_logo_pc) g_frm.uploaded_logo_pc.value = oFrame.i_uploaded_logo_pc; if(g_frm.uploaded_eps2) g_frm.uploaded_eps2.value = oFrame.i_uploaded_eps2; setTimeout("MJSetPreviewImages('"+side+"', '"+g_frm.urlback.value+"')", 100); } MJSetAllowFinish(true); MJSetUpdateImage(true); if(oFrame.i_uploaded_logo!="" && g_frm.isupload.value!=0){ // Create a cookie to store the path to any uploaded file var now = new Date(); now.setTime(now.getTime() + 14 * 24 * 60 * 60 * 1000); // 14 days in advance MJSetCookie('upload'+side, oFrame.i_uploaded_logo, now, '/'); if(document.getElementById("uploadfld").style.display=='block') MJSwapUploadFields(); } g_ipreviewcount++; g_timer = new Date().getTime() - g_timer; g_frm.encoding = "application/x-www-form-urlencoded"; MJSaveWork(true); } function MJSetUpdateImage(b){ // Sets whether basket should update the image of this item if(b) g_frm.updateimage.value = "True"; else g_frm.updateimage.value = ""; } function MJSaveWork(){ // This saves every update to an item window.status = strAutoSave; if(g_frm.itemqty.value=="") g_frm.itemqty.value = g_frm.itemqty_single.options[1]; g_frm.timer.value = g_timer; g_frm.action = "/savework.php"; g_frm.target = "util"; g_frm.submit(); setTimeout("MJAutoSave()", 1000); } function MJSetQuantity() { if(MJIsDoubleSided()) g_pulldown = g_frm.itemqty_double; else g_pulldown = g_frm.itemqty_single; if(g_frm.kinds.value == "text_lh"){ // Horrible code as goodprint doesnt print small quantities the same if(g_pulldown.value<=500){ alert(strLetterheadLaserWarning); } } g_frm.itemqty.value = g_pulldown.value; return true; } function MJAutoSave(){ window.status = strAutoSaveComplete; setTimeout("MJClearStatus()", 4000); } function MJClearStatus(){ window.status = ""; } ////////////////////////////////////////////////////////////////////////////////////////////// // Utlity functions function MJCheckDefaultsHaveChanged() { // This is to stop people leaving defaults such as Your Name in the fields var fld; if(g_frm.isprivate.value==0) { // dont do this check if private design for (var loop=0; loop < g_frm.elements.length; loop++) { fld = g_frm.elements[loop]; if(fld.type == 'text' || fld.type == 'textarea') { if(fld.value != "" && fld.value == fld.defaultValue && fld.getAttribute('validateFront')=="Yes") { fld.focus(); fld.select(); alert(strDefaultsFront); return false; } } } } return true; } function MJSetPreviewImages(side, image) { resizewidth = g_frm.resizewidth.value; resizeheight = g_frm.resizeheight.value; if(side==g_sfront) { // Set front images if(document.images['_img']) document.images["_img"].src = image; if(document.images["_imgacceptterms"]) document.images["_imgacceptterms"].src = image; if(document.images['_imgapproval']) { document.images["_imgapproval"].src = image; document.images["_imgapproval"].src = "/getexternalimage.php?url="+escape(image)+"&w="+resizewidth+"&h="+resizeheight; } } else { // Set back images if(document.images["_imgback"]) document.images["_imgback"].src = image; if(document.images["_imgbackacceptterms"]) document.images["_imgbackacceptterms"].src = image; if(document.images["_imgbackapproval"]) { if(document.images["_imgbackapproval"]) document.images["_imgbackapproval"].src = image; if(document.images["_imgbackapproval"]) document.images["_imgbackapproval"].src = "/getexternalimage.php?url="+escape(image)+"&w="+resizewidth+"&h="+resizeheight; } } } function MJSetAllowFinish(b){ // Sets whether user can proceed adding this design to basket if(b) g_frm.allowfinish.value = "True"; else g_frm.allowfinish.value = ""; } function MJGetAllowFinish(){ return (g_frm.allowfinish.value!=""); } function MJSaveForm() { // Saves the form values in a cookie if they have changed. var now = new Date(); var str, fld; now.setTime(now.getTime() + 14 * 24 * 60 * 60 * 1000); // Set now variable to 14 days in advance for (var loop=0; loop < g_frm.elements.length; loop++) { fld = g_frm.elements[loop]; if((fld.type == 'text' || fld.type == 'textarea') && (fld.defaultValue!=fld.value || g_frm.basketitemid.value!=""||g_frm.preview.value==1)) str += ';' + fld.name + '=' + fld.value; } MJSetCookie("designer", str, now, '/'); } function MJLoadForm() { // Loads the form values from cookie var strCookie = MJGetCookie("designer"); if(strCookie) { var arrValues = strCookie.split(";"); var arrNameValue; for(var i = 0; i fontLength) strFont2 = strFont.substr(0,fontLength)+'...'; } theElement = document.getElementById('f'+fontTarget.name); if(theElement) { theElement.innerHTML = strFont2; theElement.setAttribute('title', strFont); } MJSetAllowFinish(false); } function MJSwapUploadFields() { var tmp; tmp = document.getElementById("uploadmsg").style.display; document.getElementById("uploadmsg").style.display = document.getElementById("uploadfld").style.display; document.getElementById("uploadfld").style.display = tmp; } function fSwapFontColorCMYK(c,m,y,k,hex,id,name){ g_frm['c'+id].value = c; g_frm['m'+id].value = m; g_frm['y'+id].value = y; g_frm['k'+id].value = k; g_frm['hex'+id].value = hex; theElement = document.getElementById('col_box'+id); if(hex!='' && theElement) { theElement.style.backgroundColor = '#'+hex; theElement.setAttribute('title', name);; } MJSetAllowFinish(false); } function MJResizeTextarea(name) { if(g_frm[name]) { if(g_frm[name].type == 'textarea') { var lines = g_frm[name].value.split("\n").length; if(lines<4) lines=4; g_frm[name].style.height = (lines*18)+"px"; } } } function MJResizeTextBoxes(){ // Resize the front boxes MJResizeTextarea('card_department'); MJResizeTextarea('card_department2'); MJResizeTextarea('postcard1'); MJResizeTextarea('postcard2'); MJResizeTextarea('postcard3'); MJResizeTextarea("postcardback1"); MJResizeTextarea("postcardback2"); MJResizeTextarea("postcardback3"); MJResizeTextarea("postcardback4"); MJResizeTextarea("postcardback5"); } function MJDisplaySavedMessage() { if(g_ipreviewcount>0) { alert(strLeaveWarning); } } function MJValidateFront(isedit) { if(!MJGetAllowFinish()){ alert(strErrorPreview); try { g_frm.preview.focus() }catch (e){ return; } return; } if(!isedit && g_frm.preview.value==0 && g_frm.isprivate.value==0) { // Single sided items call this function first, doubles call DoneEditingFront if(!MJCheckDefaultsHaveChanged()) return false; } return true; } function MJFinishingoptionChange(finishingside) { var ofinishingsides = g_frm.finishingside; var ofinishingsidesdiv = document.getElementById("finishingsidesdiv"); var iqty = g_pulldown.value; var finishingoptionid, fname, fsymbol, fisdefault, basefinishingoptionid; var ofinishingoption = g_frm.finishingoptionid; var selectedfinishingoptionid = ofinishingoption.value; // Get the current value so it isnt lost when changing qty var omaterialoption = g_frm.materialoptionid; var selectedmaterialoptionid = omaterialoption.value; // Get the current value so it isnt lost when changing qty if(ofinishingoption.type!="select-one") return; ofinishingsidesdiv.style.display = "none"; // Start by hiding the Sides select ofinishingoption.options.length = 0; // clear the material select to start with x=0; for(i=0;i0) { // Need to check if this finish can be applied to the selected material ! for(j=0;j0) { frontprice = frontprice*((100-discount)/100); frontbackprice = frontbackprice*((100-discount)/100); } frontprice = formatNumber(frontprice,2); frontbackprice = formatNumber(frontbackprice,2); ofinishingsides.options.length = 0; // clear the select ofinishingsides.options[0] = new Option(strFront+' - '+symbol+frontprice, 0,finishingside==0,finishingside==0); ofinishingsides.options[1] = new Option(strFrontAndBack+' - '+symbol+frontbackprice,1,finishingside==1,finishingside==1); ofinishingsidesdiv.style.display = "block"; } } optionselected = (selectedfinishingoptionid==finishingoptionid); ofinishingoption.options[x] = new Option(fname, finishingoptionid, optionselected, optionselected); x++; } } function MJFinishingoptionChangeOLD(finishingside) { var ofinishingoption = g_frm.finishingoptionid; var ofinishingsides = g_frm.finishingside; var ofinishingsidesdiv = document.getElementById("finishingsidesdiv"); var iqty = g_pulldown.value; if(ofinishingoption.type!='hidden') { ofinishingsidesdiv.style.display = "none"; if(ofinishingoption.value>0) { // Need to dynamically populate side select sid = ofinishingoption.value; // Find the details array for(i=0;i0) { frontprice = frontprice*((100-discount)/100); frontbackprice = frontbackprice*((100-discount)/100); } frontprice = formatNumber(frontprice,2); frontbackprice = formatNumber(frontbackprice,2); ofinishingsides.options.length = 0; // clear the select ofinishingsides.options[0] = new Option(strFront+' - '+symbol+frontprice, 0,finishingside==0,finishingside==0); ofinishingsides.options[1] = new Option(strFrontAndBack+' - '+symbol+frontbackprice,1,finishingside==1,finishingside==1); if(isnone==0) ofinishingsidesdiv.style.display = "block"; } } } function MJShowFontFields() { // This is called on startup var aFront = new Array("font_1", "font_2", "font_3", "font_4", "font_5", "font_6"); var aBack = new Array("postcardback1_font", "postcardback2_font", "postcardback3_font", "postcardback4_font", "postcardback5_font"); // Do front fonts fontLength = fontLengthFront; // This defines how many chars can fit in the space in the design for(var i=0; i