var Grt=window.Grt?window.Grt:{};Array.prototype.__ARRAY=true;Grt.unqClsMap={};Grt.asnCls=function(el,cls,replace,unique){if(unique){if(Grt.unqClsMap[cls]){Grt.remCls(Grt.unqClsMap[cls],cls)}Grt.unqClsMap[cls]=el}if(replace){if(el.className!=cls){el.className=cls;return true}else{return false}}else{var curCls=el.className+" ";if(curCls.indexOf(cls+" ")==-1){el.className=curCls+cls;return true}else{return false}}};Grt.remCls=function(el,cls,all){if(all){el.className="";return}var curCls=el.className+" ",curInd=curCls.indexOf(cls+" ");el.className=curCls.substr(0,curInd)+curCls.substr(curInd+cls.length+1)};Grt.hasCls=function(el,cls){var curCls=" "+el.className+" ",curInd=curCls.indexOf(" "+cls+" ");if(curInd==-1){return false}return true};Grt.$=function(elName){return document.getElementById(elName)};Grt.json2String=function(obj){if(typeof(obj)!="object"){return(typeof(obj)=="string")?"\""+obj+"\"":obj}if(typeof(obj)=="object"){var buffer,fi;if(obj.__ARRAY){buffer=["["];fi=true;for(var i=0;i<obj.length;i++){if(!fi){buffer.push(",")}else{fi=false}buffer.push(Grt.json2String(obj[i]))}buffer.push("]");return buffer.join("")}else{buffer=["{"];fi=true;for(var prop in obj){if(!fi){buffer.push(",")}else{fi=false}buffer.push(prop,":",Grt.json2String(obj[prop]))}buffer.push("}");return buffer.join("")}}};Grt.addListener=function(obj,event,handler){var tempHandler=function(e){if(!e.stopPropagation){e.stopPropagation=function(){e.cancelBubble=true}}if(!e.preventDefault){e.preventDefault=function(){e.returnValue=false}}e.keyCharCode=!e.charCode&&e.keyCode?e.keyCode:e.charCode;if(!e.target){e.target=e.srcElement}handler.apply(obj,arguments)};if(obj.addEventListener){obj.addEventListener(event,tempHandler,false)}else if(obj.attachEvent){obj.attachEvent("on"+event,tempHandler)}};Grt.copyProperties=function(toObj,fromObj,force){for(var prop in fromObj){if(force||(!force&&!toObj[prop])){toObj[prop]=fromObj[prop]}}return toObj};Grt.getNthString=function(num){var h=num%100;if(h>=4&&h<=20){return"th"}var t=num%10;switch(t){case 1:return"st";case 2:return"nd";case 3:return"rd";default:return"th"}};Grt.createClass=function(subProto,superClass){if(superClass&&superClass.prototype){Grt.copyProperties(subProto,superClass.prototype);subProto.superClass=superClass.prototype}var newClass=function(){if(this.init){this.init.apply(this,arguments)}};newClass.prototype=subProto;if(superClass){newClass.prototype._superClass=superClass.prototype;newClass.prototype._super=function(name,args){var fToCall,_superClass=this._superClass;while(_superClass&&!fToCall){fToCall=_superClass[name];superClass=_superClass._superClass}if(fToCall){fToCall.apply(this,args)}}}return newClass};Grt.doForEach=function(list,todo){for(var i=0;i<list.length;i++){todo(list[i])}};var __GRT_undef;Grt.undef=__GRT_undef;Grt.XMLHTTP_PROGIDS=['Msxml2.XMLHTTP','Microsoft.XMLHTTP','Msxml2.XMLHTTP.4.0'];Grt.getXmlhttpObject=function(){var http=null,e;try{http=new XMLHttpRequest()}catch(ex){}if(!http){for(var i=0;i<3;++i){var progid=Grt.XMLHTTP_PROGIDS[i];try{http=new ActiveXObject(progid)}catch(ex){}if(http){Grt.XMLHTTP_PROGIDS=[progid];break}}}return http};Grt.xhr=function(url,callback,postdata){var http=this.getXmlhttpObject();if(callback){http.onreadystatechange=function(){if(4==http.readyState){if((!http.status)||((200<=http.status)&&(300>http.status))){if(callback.onSuccess){callback.onSuccess.apply(callback.scope,[http.responseText])}}else{if(callback.onFailure){callback.onFailure.apply(callback.scope,[http.responseText])}}}}}http.open(postdata?'POST':'GET',url,callback?true:false);if(postdata){http.setRequestHeader("Content-type","application/x-www-form-urlencoded");http.setRequestHeader("Content-length",postdata.length)}http.send(postdata);if(callback||http.status&&(200>http.status||300<=http.status)){return null}return http.responseText};Grt.UndoManager=function(){var Cls=function(){var t=this,undoset=[],redoset=[],limit=100;t.undoset=undoset;t.redoset=redoset;t.undo=function(){var undoObjs=t.undoSet().pop(),temp,undo;if(undoObjs){for(var i=0;i<undoObjs.length;i++){undo=undoObjs[i];temp=undo.obj[undo.prop];if(undo.value!=Grt.undef){undo.obj[undo.prop]=undo.value}else{delete undo.obj[undo.prop]}undo.value=temp}t.redoSet().push(undoObjs)}Grt.PageManager.setActivePage(Grt.PageManager.activePage)};t.redo=function(){var redoObjs=t.redoSet().pop(),temp,redo;if(redoObjs){for(var i=0;i<redoObjs.length;i++){redo=redoObjs[i];temp=redo.obj[redo.prop];if(redo.value!=Grt.undef){redo.obj[redo.prop]=redo.value}else{delete redo.obj[redo.prop]}redo.value=temp}this.undoSet().push(redoObjs)}Grt.PageManager.setActivePage(Grt.PageManager.activePage)};t.assignValue=function(obj,prop,value){var undoObjs,singleTran=false;if(!t.activeOpSet){t.beginTran();singleTran=true}undoObjs=t.activeOpSet;undoObjs.push({obj:obj,prop:prop,value:obj[prop]});if(value!=Grt.undef){obj[prop]=value}else{delete obj[prop]}if(singleTran){t.endTran()}};t.beginTran=function(){t.redoSet().splice(0,t.redoSet().length);var opSet=[],undoObjs=t.undoSet();if(undoObjs.length>=t.limit){undoObjs.shift()}undoObjs.push(opSet);t.activeOpSet=opSet};t.endTran=function(){t.activeOpSet=null};t.undoSet=function(){var pageNum=Grt.PageManager.activePage;return undoset[pageNum]?undoset[pageNum]:undoset[pageNum]=[]};t.redoSet=function(){var pageNum=Grt.PageManager.activePage;return redoset[pageNum]?redoset[pageNum]:redoset[pageNum]=[]}};return new Cls()}();Grt.ColorUtil={getRgbString:function(c){return["rgb(",c.r,",",c.g,",",c.b,")"].join("")},getHexString:function(rgbObj){return[].join("")},parseColor:function(str){var cols;if(str.indexOf("#")===0){cols=str.replace(/#([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])/g,"$1,$2,$3").split(",");return{r:parseInt(cols[0],16),g:parseInt(cols[1],16),b:parseInt(cols[2],16),hex:str}}else if(str.indexOf("rgb")===0){cols=str.replace(/rgb\((.*)\)/,"$1").split(",");return{r:cols[0],g:cols[1],b:cols[2],hex:"#"+parseInt(cols[0],10).toString(16)+parseInt(cols[1],10).toString(16)+parseInt(cols[2],10).toString(16)}}}};Grt.hookupPanelWithControl=function(panel,control,propagateEvent,callback,existingValue){Grt.addListener(control,"click",function(e){var offsetLeft=control.offsetLeft,offsetTop=control.offsetTop,curEl=control.offsetParent;while(curEl&&curEl.tagName.toLowerCase()!="body"){if(curEl.offsetLeft){offsetLeft=offsetLeft+curEl.offsetLeft}if(curEl.offsetTop){offsetTop=offsetTop+curEl.offsetTop}curEl=curEl.offsetParent}panel.show(offsetLeft,offsetTop+control.offsetHeight,callback,existingValue);if(!propagateEvent){e.stopPropagation()}})};Grt.FloatingElement=Grt.createClass({base:9000,floatingStack:[],floatIndex:null,focus:function(el){var t=this;t.clearFocus();t.floatingStack.push({el:el,wrapper:t});t.floatIndex=t.floatingStack.length-1;t.reassignZIndex()},clearFocus:function(){var t=this;if(t.floatIndex||t.floatIndex===0){t.floatingStack.splice(t.floatIndex,1);t.floatIndex=null}},reassignZIndex:function(){var t=this;for(var i=0;i<t.floatingStack.length;i++){if(t.floatingStack[i]){t.floatingStack[i].el.style.zIndex=t.base+i;t.floatingStack[i].wrapper.floatIndex=i}}}});Grt.Panel=Grt.createClass({init:function(id){this.dom=Grt.$(id);var t=this;Grt.addListener(this.dom,"click",function(e){e.stopPropagation()});Grt.addListener(document,"click",function(e){t.hide()});Grt.addListener(document,"keypress",function(e){if(e.keyCode==27){t.hide()}})},show:function(x,y,callback,curVal){if(x&&y){this.dom.style.left=x+"px";this.dom.style.top=y+"px"}this.dom.style.display="block";this.callback=callback;this.setVal(curVal);this.focus(this.dom)},hide:function(){this.dom.style.display="none";this.clearFocus()},setVal:function(curVal){}},Grt.FloatingElement);Grt.ColPicker=new (Grt.createClass({init:function(id){var color=["000000","585858","727272","888888","B8B8B8","D0D0D0","E8E8E8","FFFFFF","004F69","006587","007CA5","0092C3","00A9E1","00BFFF","3CCEFF","78DDFF","69003D","87004F","A5006E","B300C3","8300E1","FF78F4","FF98F4","FFC8FF","006946","00875A","00A56E","00C382","00E196","00FFAA","3CFFBE","78FFD2","9B7400","AF8300","CCD700","F2FF00","FFFF78","FFF278","FFFFAA","FFFFBB","550B00","690E00","7D1900","913000","A54D00","917400","B99400","B9A03A","694F00","876500","C39200","E1A900","FFB050","FF9650","FFBF00","FFD350","690B00","870E00","A52100","C31400","E11700","FF1A00","FF3E28","FF6250"],buffer=[],t=this,panel=Grt.$(id);buffer.push("<div id='colSamples'>");for(var i=0;i<64;i++){buffer.push("<span style='background-color:#",color[i],"' onmouseout='return false'></span>")}buffer.push("</div>");panel.innerHTML=buffer.join("");var colours=panel.getElementsByTagName("div")[0];Grt.addListener(colours,"click",function(e){if(t.callback){t.callback(e.target.style.backgroundColor)}t.hide()});this._super("init",arguments);this.hide()}},Grt.Panel))('colPicker');Grt.WindowController=Grt.createClass({init:function(win,title,close){var t=this;t.win=win;t.win.style.left="300px";t.win.style.top="70px";Grt.addListener(win,"mousedown",function(e){t.focus(t.win)});Grt.addListener(title,"mousedown",function(e){t.mouseDown=true;t.xRef=e.clientX;t.yRef=e.clientY;var left=t.win.style.left,top=t.win.style.top;t.winXRef=left.indexOf("px")!=-1?parseInt(left.substring(0,left.length-2),10):left;t.winYRef=top.indexOf("px")!=-1?parseInt(top.substring(0,top.length-2),10):top});Grt.addListener(document,"mouseup",function(){t.mouseDown=false});Grt.addListener(document,"mousemove",function(e){if(t.mouseDown){var xDif=e.clientX-t.xRef,yDif=e.clientY-t.yRef;t.win.style.left=(t.winXRef+xDif)+"px";t.win.style.top=(t.winYRef+yDif)+"px"}});Grt.addListener(close,"click",function(){t.close()})},close:function(){this.win.style.display="none";this.clearFocus()},open:function(){this.win.style.display="block";if(this.onOpen){this.onOpen.apply(this,arguments)}this.focus(this.win)}},Grt.FloatingElement);Grt.doForEach(["im","me","mu","ma"],function(id){Grt[id+"WinController"]=new Grt.WindowController(Grt.$(id+"Cntnr"),Grt.$(id+"PnlTtl"),Grt.$(id+"PnlClose"));Grt.addListener(Grt.$(id+"MenuItem"),"click",function(id){return function(){Grt[id+"WinController"].open()}}(id))});Grt.copyProperties(Grt.imWinController,{im_static_folder:"/lib/im",im_pgs:5,im_padPgs:2,im_perPg:10,catLib:{},onOpen:function(){var t=this,imPnlCatCntnt=Grt.$("imPnlCatCntnt");t.imWWWLnk=Grt.$("imWWWLnk");t.imLibraryLnk=Grt.$("imLibraryLnk");t.imWWWCntnt=Grt.$("imWWWCntnt");t.imLibraryCntnt=Grt.$("imLibraryCntnt");t.wwwButton=Grt.$("wwwImgButton");t.wwwInput=Grt.$("wwwImgInput");if(imPnlCatCntnt.innerHTML===""){Grt.addListener(t.wwwButton,"click",function(e){var imgSrc=t.wwwInput.value;if(imgSrc){if(imgSrc.indexOf("http")!==0){imgSrc="http://"+imgSrc}t.addImageToCard(imgSrc)}else{alert("Please enter a valid image URL on the www")}});Grt.addListener(Grt.$("imSubMenu"),"click",function(e){switch(e.target.id){case"imWWWLnk":Grt.asnCls(t.imWWWLnk,"imSubMenuLnkSel",false,true);Grt.asnCls(t.imWWWCntnt,"addImCntntSel",false,true);break;case"imLibraryLnk":Grt.asnCls(t.imLibraryLnk,"imSubMenuLnkSel",false,true);Grt.asnCls(t.imLibraryCntnt,"addImCntntSel",false,true);break}});Grt.asnCls(t.imLibraryLnk,"imSubMenuLnkSel",false,true);setTimeout(function(){Grt.asnCls(t.imLibraryCntnt,"addImCntntSel",false,true)},10);Grt.xhr(t.im_static_folder+"-index/_index.txt",{onSuccess:function(data){var cats=data.split(","),content=[];for(var i=0;i<cats.length;i++){content.push('<a onclick="return false" onmousedown="return false" onmousemove="return false" href="#" id="',cats[i],'">',cats[i],'</a>')}imPnlCatCntnt.innerHTML=content.join("")},scope:this});Grt.addListener(imPnlCatCntnt,"click",function(e){var tgt=e.target;if(tgt.tagName.toLowerCase()=="a"){if(t.catLib[tgt.id]){t.changeSelectedTag(tgt.id,t.catLib[tgt.id])}else{Grt.xhr(t.im_static_folder+"-index/"+tgt.id+".txt",{onSuccess:function(data){var imgList=[];data=data.split(",");for(var i=0;i<data.length;i++){if(data[i]){imgList.push(data[i])}}t.catLib[tgt.id]=imgList;t.changeSelectedTag(tgt.id,imgList)},scope:t})}}});Grt.addListener(Grt.$("imPnlFltrInpt"),"keyup",function(){var fltrCnt=this.value,tags=imPnlCatCntnt.getElementsByTagName("a");for(var i=0;i<tags.length;i++){if(tags[i].innerHTML.indexOf(fltrCnt)===0){tags[i].style.display="block"}else{tags[i].style.display="none"}}});Grt.addListener(Grt.$("imPnlPrv"),"click",function(e){var tgt=e.target;if(tgt.tagName.toLowerCase()=="img"){t.addImageToCard(tgt.src)}else if(!isNaN(tgt.id)){t.renderImageMenu(parseInt(tgt.id,10))}})}},changeSelectedTag:function(tag,imageList){this.tagSelected=tag;this.imageList=imageList;this.renderImageMenu()},renderImageMenu:function(pg){if(!this.imageList){return}if(!pg||isNaN(pg)){pg=1}var buffer=[],t=this,imgs=this.imageList,numOfImgs=imgs.length,numOfPgs=Math.ceil(numOfImgs/t.im_perPg),pgMnIt=1;buffer.push("<div id='imPgsMenu'>");if(numOfPgs>t.im_pgs){pgMnIt=pg-t.im_padPgs>0?(pg-t.im_padPgs):1;if(pgMnIt+t.im_pgs>numOfPgs){pgMnIt=pgMnIt-((pgMnIt+t.im_pgs-1)-numOfPgs)}}else{pgMnIt=1}if(pgMnIt>1){buffer.push("<span class='pageLink' id='",pgMnIt-1,"'>&lt;</span>")}for(var i=pgMnIt,ct=0;i<=numOfPgs&&ct<t.im_pgs;i++,ct++){buffer.push("<span class='",(pg==i?"selPageLink":"pageLink"),"' id='",i,"'>",i,"</span>")}if(pgMnIt+t.im_pgs<numOfPgs){buffer.push("<span class='pageLink' id='",pgMnIt+t.im_pgs,"'>&gt;</span>")}buffer.push("</div>");for(i=(pg-1)*t.im_perPg,ct=0;i<numOfImgs&&ct<t.im_perPg;i++,ct++){buffer.push("<img src='",this.im_static_folder,"/",this.imageList[i],"' style='cursor:pointer;width:50px;margin:0 0 0 15px'>")}Grt.$("imPnlPrv").innerHTML=buffer.join("")},addImageToCard:function(src){var curPage=Grt.PageManager.pages[Grt.PageManager.activePage];curPage.objCounter=curPage.objCounter+1;curPage.canvas.maxZIndex+=curPage.canvas.maxZIndex;Grt.UndoManager.assignValue(curPage.objects,curPage.objCounter,{type:"image",id:curPage.objCounter,src:src,top:"0",left:"0",zIndex:curPage.canvas.maxZIndex});Grt.UndoManager.endTran();Grt.PageManager.setActivePage(Grt.PageManager.activePage)}});Grt.copyProperties(Grt.meWinController,{initialized:false,fontValues:{"Arial":null,"Brush Script MT Italic":null,"Comic Sans MS":null,"Impact":null,"Verdana":null,"Arial Black":null},defaultTextObj:{width:"200",top:"10",left:"10",face:"Arial",size:11,color:"#000000",type:"text"},onOpen:function(obj){var t=this,index,buffer;if(!t.initialized){t.fontface=Grt.$("fontface");t.fontsize=Grt.$("fontsize");t.fontcolour=Grt.$("fontcolour");t.messageBox=Grt.$("messageBox");t.bold=Grt.$("bold");t.italic=Grt.$("italic");t.left=Grt.$("left");t.right=Grt.$("right");t.center=Grt.$("center");t.justify=Grt.$("justify");index=0;buffer=[];t.fontface.innerHTML="";for(var font in t.fontValues){t.fontValues[font]=index;if(document.all){t.fontface.options[t.fontface.options.length]=new Option(font,font)}else{buffer.push("<option value='",font,"'>",font,"</option>")}index++}if(!document.all){t.fontface.innerHTML=buffer.join("")}Grt.addListener(t.fontface,"change",function(){t.setFace(this.options[this.options.selectedIndex].value)});index=0;buffer=[];t.fontsize.innerHTML="";for(;index<=56;index++){if(document.all){t.fontsize.options[t.fontsize.options.length]=new Option(index+8,index+8)}else{buffer.push("<option value='",index+8,"'>",index+8,"</option>")}}if(!document.all){t.fontsize.innerHTML=buffer.join("")}Grt.addListener(t.fontsize,"change",function(){t.setSize(this.options[this.options.selectedIndex].value)});Grt.addListener(t.messageBox,"change",function(){t.setText(this.value)});Grt.addListener(Grt.$("updateMessage"),"click",function(){t.updateObj()});Grt.hookupPanelWithControl(Grt.ColPicker,t.fontcolour,false,function(val){t.setColor(val)});Grt.doForEach([t.left,t.right,t.center,t.justify],function(el){Grt.addListener(el,"click",function(e){t.setAlignment(el.id)})});Grt.doForEach([t.bold,t.italic],function(el){Grt.addListener(el,"click",function(e){if(Grt.hasCls(el,"fontstyleSelected")){t.setStyle(el.id,false)}else{t.setStyle(el.id,true)}})});t.initialized=true}t.setObjToEdit(obj);t.setStyle("italic",t.obj.italic);t.setStyle("bold",t.obj.bold);t.setColor(t.obj.color);t.setAlignment(t.obj.align);t.setFace(t.obj.face);t.setSize(t.obj.size);t.setText(t.obj.text)},setText:function(text){if(!text){return}var t=this;text=text.replace(/&quot;/g,"\"");text=text.replace(/<br\/>/g,"\n");t.messageBox.value=text;text=text.replace(/"/g,"&quot;");text=text.replace(/\r\n/g,"<br/>");text=text.replace(/\n/g,"<br/>");t.updatedObj.text=text},setSize:function(size){var t=this;t.fontsize.options.selectedIndex=size-8;t.updatedObj.size=size;t.messageBox.style.fontSize=size+"px"},setFace:function(face){var t=this;t.fontface.options.selectedIndex=t.fontValues[face];t.updatedObj.face=face;t.messageBox.style.fontFamily=face},setAlignment:function(align){if(!align){return}var t=this;Grt.asnCls(t[align],"textalignSelected",false,true);t.updatedObj.align=align;t.messageBox.style.textAlign=align},setColor:function(color){var t=this;t.fontcolour.style.backgroundColor=color;t.messageBox.style.color=color;t.updatedObj.color=color},setStyle:function(style,applied){var t=this;if(!applied){applied=false}t.updatedObj[style]=applied;if(applied){Grt.asnCls(t[style],"fontstyleSelected")}else{Grt.remCls(t[style],"fontstyleSelected")}t.messageBox.style[style=="bold"?"fontWeight":"fontStyle"]=applied?style:""},setObjToEdit:function(obj){var t=this;if(!obj){obj=Grt.copyProperties({},t.defaultTextObj);t.newObj=true}else{t.newObj=false}t.obj=obj;t.updatedObj={}},updateObj:function(){var t=this,prop;if(t.newObj){for(prop in t.updatedObj){if(t.updatedObj[prop]!=t.obj[prop]){t.obj[prop]=t.updatedObj[prop]}}t.addTextToCard(t.obj);t.newObj=false}else{Grt.UndoManager.beginTran();for(prop in t.updatedObj){if(t.updatedObj[prop]!=t.obj[prop]){var curPage=Grt.PageManager.pages[Grt.PageManager.activePage];Grt.UndoManager.assignValue(curPage.objects[t.obj.id],prop,t.updatedObj[prop])}}Grt.UndoManager.endTran()}Grt.PageManager.setActivePage(Grt.PageManager.activePage);this.close()},addTextToCard:function(obj){var t=this;var curPage=Grt.PageManager.pages[Grt.PageManager.activePage];Grt.UndoManager.beginTran();curPage.objCounter=curPage.objCounter+1;obj.id=curPage.objCounter;curPage.canvas.maxZIndex+=1;obj.zIndex=curPage.canvas.maxZIndex;Grt.UndoManager.assignValue(curPage.objects,curPage.objCounter,obj);Grt.UndoManager.endTran()}});Grt.copyProperties(Grt.maWinController,{initialized:false,MAIL_REGEX:/[.]*@[.]*/,cardTypes:{"greeting card":{subject:"A greeting card for you"},"message card":{subject:"A message for you"},"invitation":{subject:"Invitation"},"good luck charm":{subject:"Here's a good luck charm"}},onOpen:function(obj){var t=this,index,buffer,date;if(!t.initialized){t.sendday=Grt.$("sendday");t.cardtype=Grt.$("cardtype");t.sendername=Grt.$("sendername");t.sendermail=Grt.$("sendermail");t.subject=Grt.$("subject");t.rcptRows=Grt.$("rcptRows");t.sendCardButton=Grt.$("sendCard");var curDate=new Date(),option,value,i,months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];buffer=[];for(i=0;i<30;i++){curDate.setTime(curDate.getTime()+86400000);option="on "+curDate.getDate()+Grt.getNthString(curDate.getDate())+" "+months[curDate.getMonth()]+", "+curDate.getFullYear();date=curDate.getDate();if(date<10){date="0"+date}value=date+months[curDate.getMonth()]+(curDate.getFullYear()+"").substring(2,4);if(document.all){t.sendday.options[t.sendday.options.length]=new Option(option,value)}else{buffer.push("<option value='",value,"'>",option,"</option>")}}if(!document.all){t.sendday.innerHTML+=buffer.join("")}index=0;buffer=[];for(var type in t.cardTypes){t.cardTypes[type].index=index;if(document.all){t.cardtype.options[t.cardtype.options.length]=new Option(type,type)}else{buffer.push("<option value='",type,"'>",type,"</option>")}index++}if(!document.all){t.cardtype.innerHTML=buffer.join("")}Grt.addListener(t.cardtype,"change",function(){if(model.type&&t.cardTypes[model.type]&&t.subject.value==t.cardTypes[model.type].subject){t.subject.value=""}model.type=this.options[this.options.selectedIndex].value;if(!t.subject.value){t.subject.value=t.cardTypes[model.type].subject;Grt.mdl.envelope.subject=t.subject.value}});Grt.addListener(t.sendday,"change",function(){Grt.mdl.envelope.sendDate=this.options[this.options.selectedIndex].value});Grt.addListener(t.sendername,"change",function(){Grt.mdl.envelope.senderName=this.value});Grt.addListener(t.sendermail,"change",function(){Grt.mdl.envelope.senderMail=this.value});Grt.addListener(t.subject,"change",function(){Grt.mdl.envelope.subject=this.value});Grt.addListener(Grt.$("rcptAddNew"),"click",function(){t.addRecipient()});Grt.addListener(t.sendCardButton,"click",function(){t.sendCard()});if(model.type&&t.cardTypes[model.type]){t.cardtype.options.selectedIndex=t.cardTypes[model.type].index}if(!Grt.mdl.envelope.subject){t.subject.value=t.cardTypes[t.cardtype.options[t.cardtype.options.selectedIndex].value].subject;Grt.mdl.envelope.subject=t.subject.value}else{t.subject.value=Grt.mdl.envelope.subject}t.addRecipient()}t.initialized=true},addRecipient:function(){var t=this,rcpts=Grt.mdl.envelope.recipients,rcpt={name:"",email:""},indx=rcpts.length,inputEls,delRcptRow,cntnr=document.createElement("div");cntnr.className="rcptRow";cntnr.innerHTML='<div class="control"><div class="label">Name </div><div class="field"><input class="mailInput" type="text"/></div></div><div class="control"><div class="label">e-mail </div><div class="field"><input class="mailInput" type="text"/></div></div>'+(indx>0?'<div id="delRcptRow'+indx+'" class="delRcptRow">x</div>':'');t.rcptRows.appendChild(cntnr);inputEls=cntnr.getElementsByTagName("input");if(inputEls[0]){Grt.addListener(inputEls[0],"change",function(){rcpt.name=this.value});inputEls[0].focus()}if(inputEls[1]){Grt.addListener(inputEls[1],"change",function(){rcpt.email=this.value})}delRcptRow=document.getElementById("delRcptRow"+indx);if(delRcptRow){Grt.addListener(delRcptRow,"click",function(indx){return function(){rcpts[indx]=null;t.rcptRows.removeChild(cntnr)}}(indx))}rcpts.push(rcpt)},validateEnvelope:function(env){var buffer=[],i,rCount=1,rcp,t=this,validRcptExists;if(!env.senderName){buffer.push("Please enter your name and e-mail address")}else if(!t.MAIL_REGEX.test(env.senderMail)){buffer.push("Please enter your valid e-mail address")}for(i=0;i<env.recipients.length;i++){rcp=env.recipients[i];if(rcp){if((rcp.name&&!rcp.email)||(rcp.email&&!t.MAIL_REGEX.test(rcp.email))){buffer.push("Please enter a valid email for the ",Grt.getNthString(rCount)," recipient")}if(rcp.email){validRcptExists=true}rCount++}}if(!validRcptExists){buffer.push("Please provide the name and e-mail adrress of at least one recipient")}if(buffer.length===0){return true}else{alert(buffer.join("\n"));return false}},sendCard:function(){var t=this,env=Grt.mdl.envelope,rcpt,mdl=model,envPacked=[],rcptIndex=1;if(!t.validateEnvelope(env)){return}mdl.subject=env.subject?env.subject:mdl.type;envPacked.push("card="+encodeURIComponent(Grt.json2String(mdl)));envPacked.push("cardType="+encodeURIComponent(mdl.type));envPacked.push("subject="+encodeURIComponent(mdl.subject));envPacked.push("senderName="+encodeURIComponent(env.senderName));envPacked.push("senderMail="+encodeURIComponent(env.senderMail));for(var i=0;i<env.recipients.length;i++){rcpt=env.recipients[i];if(rcpt){if(rcpt.email){if(!rcpt.name){rcpt.name=rcpt.email}envPacked.push("recipientMail"+rcptIndex+"="+encodeURIComponent(rcpt.email));envPacked.push("recipientName"+rcptIndex+"="+encodeURIComponent(rcpt.name));rcptIndex++}}}envPacked.push("numOfRecipients="+(rcptIndex-1));if(env.sendDate){envPacked.push("sendDate="+encodeURIComponent(env.sendDate))}envPacked=envPacked.join("&");t.sendCardButton.disabled=true;Grt.xhr("../mailer/envelope.php",{onSuccess:function(){alert("Your card has been sent!");t.close();t.sendCardButton.disabled=false},onFailure:function(){alert("There was a problem sending your card. Please try again in a while.");t.sendCardButton.disabled=false}},envPacked)}});Grt.Canvas=new function(el,editMode){var t=this;this.clipboard=[];this.editMode=editMode;this.container=el;this.selectedObjs=[];t.setHeight=function(height){t.container.style.height=height+"px";model.dimensions.height=height};t.setWidth=function(width){t.container.style.width=width+"px";model.dimensions.width=width};t.setHeight(model.dimensions.height);t.setWidth(model.dimensions.width);this.renderPage=function(page){t.page=page;var buffer=[],image,object;t.container.style.backgroundColor=page.canvas.color;t.container.innerHTML="<div id='selMarker'></div>";for(var i in page.objects){object=page.objects[i];switch(object.type){case"image":this.container.innerHTML=this.container.innerHTML+["<div class='unselected' oncontextmenu='return false' onmousedown='return false' onmousemove='return false' id='",object.id,"' style='position:absolute;left:",object.left,"px;","z-index:",object.zIndex,";top:",object.top,"px;","'><img src='",object.src,"' style='",(object.width?"width:"+object.width+"px;":""),(object.height?"height:"+object.height+"px;":""),"' class='notSelected' /><span class='resizeImage'></span></div>"].join("");break;case"text":this.container.innerHTML=this.container.innerHTML+["<div class='unselected' oncontextmenu='return false' onmousedown='return false' onmousemove='return false' id='",object.id,"' style='position:absolute;left:",object.left,"px;","color:",object.color,";font-family:",object.face,";font-size:",object.size,"px;","z-index:",object.zIndex,";top:",object.top,"px;width:",object.width,"px;",(object.align?"text-align:"+object.align+";":""),(object.italic?"font-style:italic;":""),(object.bold?"font-weight:bold;":""),"'>",object.text,"<span class='resizeText'></span></div>"].join("");break}}if(t.editMode){t.selMarker=t.container.getElementsByTagName("div")[0];var els=this.container.getElementsByTagName("div"),curEl;for(var j=1;j<els.length;j++){curEl=els[j];object=page.objects[curEl.id];if(object.type=="text"){Grt.addListener(curEl,"dblclick",function(object){return function(e){Grt.meWinController.open(object)}}(object))}Grt.addListener(curEl,"mousedown",function(e){Grt.ContextMenuHandler.hide();t.selectObj(this,e.ctrlKey||e.shiftKey,e);t.inFocus=true;t.mousedownOnObj=true;if(e.target.className=="resizeImage"||e.target.className=="resizeText"){t.tempStore={};t.mode="resize"}else{t.mode="move"}t.xRef=e.clientX;t.yRef=e.clientY;e.stopPropagation()});Grt.addListener(curEl,"click",function(e){e.stopPropagation()});Grt.addListener(curEl,"contextmenu",function(e){Grt.ContextMenuHandler.setContextToDisplayAt(function(operation){switch(operation){case"moveForward":t.bringToFront();break;case"moveStepForward":t.bringForward();break;case"moveBehind":t.sendBack();break;case"moveStepBehind":t.sendBackward()}},"objContext",e.clientX,e.clientY);e.stopPropagation()})}}};this.selectObj=function(obj,appendToSelection,e){if(Grt.asnCls(obj,"selectedObject")){if(!appendToSelection){t.clearSelection()}t.selectedObjs.push(obj)}else if(e.ctrlKey||e.shiftKey){for(var i=0;i<t.selectedObjs.length;i++){if(t.selectedObjs[i]===obj){t.selectedObjs.splice(i,1);Grt.remCls(obj,"selectedObject");break}}}};this.clearSelection=function(){var selEl=t.selectedObjs.pop();while(selEl){Grt.remCls(selEl,"selectedObject");selEl=t.selectedObjs.pop()}};this.removeSelectedObjects=function(){var selEl=t.selectedObjs.pop();Grt.UndoManager.beginTran();while(selEl){Grt.UndoManager.assignValue(t.page.objects,selEl.id,Grt.undef);selEl=t.selectedObjs.pop()}Grt.UndoManager.endTran();t.renderPage(t.page,true)};this.copyToClipboard=function(){t.clipboard=[];Grt.doForEach(t.selectedObjs,function(obj){var newObj={};Grt.copyProperties(newObj,t.page.objects[obj.id]);newObj.presentOn={};newObj.presentOn[t.page.id]={x:newObj.left,y:newObj.top};t.clipboard.push(newObj)})};this.cutToClipboard=function(){t.copyToClipboard();t.removeSelectedObjects()};this.pasteFromClipboard=function(){Grt.UndoManager.beginTran();Grt.doForEach(t.clipboard,function(obj){t.page.objCounter=t.page.objCounter+1;t.page.canvas.maxZIndex+=1;var newObj={zIndex:t.page.canvas.maxZIndex};Grt.copyProperties(newObj,obj);if(newObj.presentOn[t.page.id]){newObj.top=parseInt(newObj.presentOn[t.page.id].y)+5;newObj.left=parseInt(newObj.presentOn[t.page.id].x)+5;obj.presentOn[t.page.id].y=newObj.top;obj.presentOn[t.page.id].x=newObj.left}else{obj.presentOn[t.page.id]={x:newObj.left,y:newObj.top}}delete newObj.presentOn;newObj.id=t.page.objCounter;Grt.UndoManager.assignValue(t.page.objects,newObj.id,newObj)});Grt.UndoManager.endTran();t.renderPage(t.page,true)};this.bringForward=function(){if(t.selectedObjs&&t.selectedObjs.length){this.applyZIndex(1,true)}};this.sendBackward=function(){if(t.selectedObjs&&t.selectedObjs.length){this.applyZIndex(-1,true)}};this.bringToFront=function(){if(t.selectedObjs&&t.selectedObjs.length){t.page.canvas.maxZIndex+=1;this.applyZIndex(t.page.canvas.maxZIndex)}};this.sendBack=function(){if(t.selectedObjs&&t.selectedObjs.length){t.page.canvas.minZIndex-=1;this.applyZIndex(t.page.canvas.minZIndex)}};this.applyZIndex=function(zIndex,diff){Grt.UndoManager.beginTran();Grt.doForEach(t.selectedObjs,function(obj){var mObj=t.page.objects[obj.id];if(diff){if(!mObj.zIndex){mObj.zIndex=0}zIndex=mObj.zIndex+zIndex;if(zIndex>t.page.canvas.maxZIndex){t.page.canvas.maxZIndex=zIndex}if(zIndex<t.page.canvas.minZIndex){t.page.canvas.minZIndex=zIndex}}Grt.UndoManager.assignValue(mObj,"zIndex",zIndex);obj.style.zIndex=zIndex});Grt.UndoManager.endTran()};Grt.addListener(this.container,"click",function(e){t.inFocus=true;e.stopPropagation();return false});Grt.addListener(this.container,"mousedown",function(e){Grt.ContextMenuHandler.hide();if(!(e.ctrlKey||e.shiftKey)){t.clearSelection()}t.xRef=e.clientX;t.yRef=e.clientY;t.xCanLeft=!e.pageX?e.x:e.pageX-e.target.offsetLeft;t.yCanTop=!e.pageY?e.y:e.pageY-e.target.offsetTop;t.xCanRight=e.target.offsetWidth-t.xCanLeft;t.yCanBottom=e.target.offsetHeight-t.yCanTop;t.mousedown=true;t.selMarker.style.left=t.xCanLeft+"px";t.selMarker.style.top=t.yCanTop+"px";t.selMarker.style.width=0;t.selMarker.style.height=0;t.selMarker.style.display="block";return false});Grt.addListener(this.container,"mouseup",function(e){var i,obj;t.mousedown=false;t.mousedownOnObj=false;if(t.objectsMoved){if(t.selectedObjs.length>0){Grt.UndoManager.beginTran()}t.objectsMoved=false;if(t.mode=="resize"){for(i=0;i<t.selectedObjs.length;i++){obj=t.selectedObjs[i].getElementsByTagName("img")[0];var width,height,isText=false;if(!obj){obj=t.selectedObjs[i];isText=true}width=obj.style.width;width=width.indexOf("px")!=-1?width.substring(0,width.length-2):width;Grt.UndoManager.assignValue(t.page.objects[t.selectedObjs[i].id],"width",width);if(!isText){height=obj.style.height;height=height.indexOf("px")!=-1?height.substring(0,height.length-2):height;Grt.UndoManager.assignValue(t.page.objects[t.selectedObjs[i].id],"height",height)}}}else if(t.mode=="move"){for(i=0;i<t.selectedObjs.length;i++){obj=t.selectedObjs[i];var top=obj.style.top,left=obj.style.left;top=top.indexOf("px")!=-1?top.substring(0,top.length-2):top;left=left.indexOf("px")!=-1?left.substring(0,left.length-2):left;Grt.UndoManager.assignValue(t.page.objects[obj.id],"top",top);Grt.UndoManager.assignValue(t.page.objects[obj.id],"left",left)}}else{var els=t.container.getElementsByTagName("div"),curEl,selEl=els[0],x1=els[0].offsetLeft,x2=els[0].offsetWidth+x1,y1=els[0].offsetTop,y2=els[0].offsetHeight+y1;window.status=(x1+" "+x2+" "+y1+" "+y2);for(var j=1;j<els.length;j++){curEl=els[j];if(curEl.offsetTop>y1&&curEl.offsetLeft>x1&&(curEl.offsetLeft+curEl.offsetWidth)<x2&&(curEl.offsetTop+curEl.offsetHeight)<y2){t.selectObj(curEl,true)}}}Grt.UndoManager.endTran()}t.mode=null;t.selMarker.style.display="none";t.objectsMoved=false});Grt.addListener(this.container,"mousemove",function(e){if(t.mousedown||t.mousedownOnObj){t.objectsMoved=true;var i,xVar=e.clientX-t.xRef,yVar=e.clientY-t.yRef,obj=null;if(t.mousedownOnObj&&t.mode=="resize"){for(i=0;i<t.selectedObjs.length;i++){var isText=null;obj=t.selectedObjs[i].getElementsByTagName("img")[0];if(!obj){obj=t.selectedObjs[i];isText=true}if(!t.tempStore[t.selectedObjs[i].id]){t.tempStore[t.selectedObjs[i].id]={width:obj.offsetWidth,height:obj.offsetHeight}}var selObj=t.page.objects[t.selectedObjs[i].id],width=t.tempStore[t.selectedObjs[i].id].width+(xVar*1),height=t.tempStore[t.selectedObjs[i].id].height+(yVar*1);obj.style.width=width+"px";if(!isText){obj.style.height=height+"px"}}}else if(t.mousedownOnObj){for(i=0;i<t.selectedObjs.length;i++){obj=t.selectedObjs[i];var top=(t.page.objects[obj.id].top*1)+(yVar*1);var left=(t.page.objects[obj.id].left*1)+(xVar*1);obj.style.top=top+"px";obj.style.left=left+"px"}}else{if(xVar>=0){t.selMarker.style.right=null;t.selMarker.style.left=t.xCanLeft+"px";t.selMarker.style.width=xVar+"px"}else{t.selMarker.style.left=null;t.selMarker.style.right=t.xCanRight+"px";t.selMarker.style.width=(xVar*-1)+"px"}if(yVar>=0){t.selMarker.style.bottom=null;t.selMarker.style.top=t.yCanTop+"px";t.selMarker.style.height=(yVar)+"px"}else{t.selMarker.style.top=null;t.selMarker.style.bottom=t.yCanBottom+"px";t.selMarker.style.height=(yVar*-1)+"px"}}}});Grt.addListener(document,"keyup",function(e){if(e.ctrlKey&&e.target.tagName.toLowerCase()!="input"&&e.target.tagName.toLowerCase()!="textarea"){switch(e.keyCode){case 67:Grt.Canvas.copyToClipboard();break;case 86:Grt.Canvas.pasteFromClipboard();break;case 88:Grt.Canvas.cutToClipboard();break;case 89:Grt.UndoManager.redo();break;case 90:Grt.UndoManager.undo();break}}});Grt.addListener(document,"click",function(e){t.inFocus=false});Grt.addListener(document,"keydown",function(e){if(e.keyCode==46&&t.inFocus){t.removeSelectedObjects()}});Grt.addListener(this.container,"contextmenu",function(e){Grt.ContextMenuHandler.setContextToDisplayAt(function(operation){if(operation=="undo"){Grt.UndoManager.undo()}else if(operation=="redo"){Grt.UndoManager.redo()}},"genContext",e.clientX,e.clientY);e.preventDefault()});return this}(Grt.$("canvasEl"),true);Grt.DimensionManager=new function(){var t=this;t.minVal=100;t.maxVal=1240;t.cdHeightCtrl=Grt.$("cdHeight");t.cdWidthCtrl=Grt.$("cdWidth");t.cdHeightCtrl.value=model.dimensions.height;t.cdWidthCtrl.value=model.dimensions.width;t.setDimension=function(dimension,val){val=parseInt(val,10);if(!isNaN(val)&&val>=t.minVal&&val<=t.maxVal){if(dimension=="width"){Grt.Canvas.setWidth(val)}else{Grt.Canvas.setHeight(val)}}else{alert("The card can have a minimum "+dimension+" of "+t.minVal+" and a maximimum "+dimension+" of "+t.maxVal);this.value=model.dimensions[dimension]}};Grt.addListener(t.cdHeightCtrl,"change",function(){t.setDimension("height",this.value)});Grt.addListener(t.cdWidthCtrl,"change",function(){t.setDimension("width",this.value)});Grt.doForEach([t.cdHeightCtrl,t.cdWidthCtrl],function(el){Grt.addListener(el,"keypress",function(e){if(!((e.keyCharCode>=48&&e.keyCharCode<=57)||(e.keyCharCode>=37&&e.keyCharCode<=40)||e.keyCharCode==8||e.keyCharCode==9||e.keyCharCode==47)){e.stopPropagation();e.preventDefault()}});Grt.addListener(el,"keyup",function(e){var value=parseInt(this.value,10);if(!isNaN(value)&&value>=t.minVal&&this.value<=t.maxVal){if(this.id=="cdWidth"){t.setDimension("width",this.value)}else{t.setDimension("height",this.value)}}})});return t}();Grt.ContextMenuHandler=new function(menuPanelEl){var t=this;Grt.addListener(menuPanelEl,"contextmenu",function(e){e.preventDefault()});this.setContextToDisplayAt=function(contextCallback,contextCls,x,y){this.callback=contextCallback;menuPanelEl.className=contextCls;menuPanelEl.style.top=(y-10)+"px";menuPanelEl.style.left=(x-10)+"px"};this.hide=function(){menuPanelEl.className="noConext"};var menuEls=menuPanelEl.getElementsByTagName("a"),menuEl;for(var i=0;i<menuEls.length;i++){menuEl=menuEls[i];Grt.addListener(menuEl,"click",function(){if(t.callback){t.callback(this.className)}t.hide()});Grt.addListener(menuEl,"mouseout",function(e){e.stopPropagation()})}return this}(Grt.$("contextMenu"));Grt.PageManager=new function(pgCon,addBut,previewCard,model){var t=this,pages=model.pages;t.pages=pages;t.defaultCanvas={color:"#ffffff",minZIndex:0,maxZIndex:0};this.renderPageButtons=function(){t.pgActivators=[];var buffer=[],pageNum,els,el;for(pageNum=0;pageNum<pages.length;pageNum++){var page=pages[pageNum];page.id=pageNum;buffer.push('<div class="pageButtonPad"></div><div class="pageButton"><div class="title">',(pageNum>0?'<div class="pageDelete" id="pageDelete'+pageNum+'">X</div>':''),'Page ',(pageNum+1),'</div><div class="label">Background Color</div><div id="bgcolor'+pageNum+'" class="color"></div>',(pageNum>0?'<select class="pageTime" id="pageTime'+pageNum+'"></select>':''),'</div>')}pgCon.innerHTML=buffer.join("");pageNum=0;previewCard.style.display="none";els=pgCon.getElementsByTagName("div");for(var i=0;i<els.length;i++){el=els[i];if(Grt.hasCls(el,"pageButton")){this.pgActivators[pageNum]=function(curPage,el){return function(e){t.activePage=curPage;Grt.asnCls(el,"pageButtonSel",false,true);Grt.Canvas.renderPage(model.pages[curPage]);if(e){e.stopPropagation()}}}(pageNum,el);Grt.addListener(el,"click",this.pgActivators[pageNum]);var pageTimeEl=Grt.$("pageTime"+pageNum),optBuffer,visibleAfter;if(pageTimeEl){optBuffer=[];pageTimeEl.innerHTML="";for(var j=1;j<=60;){if(document.all){pageTimeEl.options[pageTimeEl.options.length]=new Option('Display after '+j+' second'+(j>1?'s':''),j)}else{optBuffer.push('<option>Display after ',j,' second',(j>1?'s':''),'</option>')}j=j>4?j+5:j+1}if(!document.all){pageTimeEl.innerHTML=optBuffer.join("")}Grt.addListener(pageTimeEl,"change",function(pageNum){return function(){var selIndex=this.options.selectedIndex;selIndex=selIndex>3?(selIndex-4)*5:selIndex+1;model.pages[pageNum].visibleAfter=selIndex}}(pageNum));visibleAfter=model.pages[pageNum].visibleAfter;if(visibleAfter&&visibleAfter>0){visibleAfter=visibleAfter>5?4+(visibleAfter/5):visibleAfter-1;pageTimeEl.options.selectedIndex=visibleAfter}}var pageDelEl=Grt.$("pageDelete"+pageNum);if(pageDelEl){Grt.addListener(pageDelEl,"click",function(index){return function(e){e.stopPropagation();pages.splice(index,1);Grt.UndoManager.undoset.splice(index,1);Grt.UndoManager.redoset.splice(index,1);t.renderPageButtons();t.pgActivators[0]()}}(pageNum))}var dummy=function(colPickEl,pageNum){colPickEl.style.backgroundColor=model.pages[pageNum].canvas.color;Grt.hookupPanelWithControl(Grt.ColPicker,colPickEl,true,function(val){colPickEl.style.backgroundColor=val;model.pages[pageNum].canvas.color=val;t.pgActivators[pageNum]()})}(Grt.$('bgcolor'+pageNum),pageNum);if(pageNum==1){previewCard.style.display="inline"}pageNum++}}};this.setActivePage=function(num){this.pgActivators[num]()};Grt.addListener(addBut,"click",function(e){model.pageCounter=model.pageCounter+1;var id=pages.length,canvas=Grt.copyProperties({},t.defaultCanvas);pages[id]={id:id,objCounter:0,objects:{},canvas:canvas};Grt.PageManager.renderPageButtons();t.setActivePage(id)});Grt.addListener(previewCard,"click",function(e){var curPage=0;function activatePage(){t.setActivePage(curPage);curPage++;var page=model.pages[curPage];if(curPage<model.pageCounter&&page){setTimeout(activatePage,page.visibleAfter?page.visibleAfter*1000:1000)}}activatePage()})}(Grt.$("pageButtons"),Grt.$("addPage"),Grt.$("previewCard"),model);Grt.PageManager.renderPageButtons();Grt.PageManager.setActivePage(0);Grt.addListener(Grt.$("cpBTN"),"click",function(){Grt.Canvas.copyToClipboard()});Grt.addListener(Grt.$("ctBTN"),"click",function(){Grt.Canvas.cutToClipboard()});Grt.addListener(Grt.$("ptBTN"),"click",function(){Grt.Canvas.pasteFromClipboard()});Grt.addListener(Grt.$("deBTN"),"click",function(){Grt.Canvas.removeSelectedObjects()});Grt.addListener(Grt.$("udBTN"),"click",function(){Grt.UndoManager.undo()});Grt.addListener(Grt.$("rdBTN"),"click",function(){Grt.UndoManager.redo()});Grt.addListener(Grt.$("muBTN"),"click",function(){Grt.Canvas.bringToFront()});Grt.addListener(Grt.$("mdBTN"),"click",function(){Grt.Canvas.sendBack()});
