
function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc;}
function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)
if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}
function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&document.getElementById)x=document.getElementById(n);return x;}
function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2];}}
(function($){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'array':function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a[a.length]=v;b=true;}}}
a[a.length]=']';return a.join('');},'boolean':function(x){return String(x);},'null':function(x){return"null";},'number':function(x){return isFinite(x)?String(x):'null';},'object':function(x){if(x){if(x instanceof Array){return s.array(x);}
var a=['{'],b,f,i,v;for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a.push(s.string(i),':',v);b=true;}}}
a[a.length]='}';return a.join('');}
return'null';},'string':function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
return'"'+x+'"';}};$.toJSON=function(v){var f=isNaN(v)?s[typeof v]:s['number'];if(f)return f(v);};$.parseJSON=function(v,safe){if(safe===undefined)safe=$.parseJSON.safe;if(safe&&!/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
return undefined;return eval('('+v+')');};$.parseJSON.safe=false;})(jQuery);
jQuery.extend({createUploadIframe:function(id,uri)
{var frameId='jUploadFrame'+id;if(window.ActiveXObject){var io=document.createElement('<iframe id="'+frameId+'" name="'+frameId+'" />');if(typeof uri=='boolean'){io.src='javascript:false';}
else if(typeof uri=='string'){io.src=uri;}}
else{var io=document.createElement('iframe');io.id=frameId;io.name=frameId;}
io.style.position='absolute';io.style.top='-1000px';io.style.left='-1000px';document.body.appendChild(io);return io},createUploadForm:function(id,fileElementId)
{var formId='jUploadForm'+id;var fileId='jUploadFile'+id;var form=$('<form  action="" method="POST" name="'+formId+'" id="'+formId+'" enctype="multipart/form-data"></form>');var oldElement=$('#'+fileElementId);var newElement=$(oldElement).clone();$(oldElement).attr('id',fileId);$(oldElement).before(newElement);$(oldElement).appendTo(form);$(form).css('position','absolute');$(form).css('top','-1200px');$(form).css('left','-1200px');$(form).appendTo('body');return form;},ajaxFileUpload:function(s){s=jQuery.extend({},jQuery.ajaxSettings,s);var id=new Date().getTime()
var form=jQuery.createUploadForm(id,s.fileElementId);var io=jQuery.createUploadIframe(id,s.secureuri);var frameId='jUploadFrame'+id;var formId='jUploadForm'+id;if(s.global&&!jQuery.active++)
{jQuery.event.trigger("ajaxStart");}
var requestDone=false;var xml={}
if(s.global)
jQuery.event.trigger("ajaxSend",[xml,s]);var uploadCallback=function(isTimeout)
{var io=document.getElementById(frameId);try
{if(io.contentWindow)
{xml.responseText=io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;xml.responseXML=io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;}else if(io.contentDocument)
{xml.responseText=io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;xml.responseXML=io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;}}catch(e)
{jQuery.handleError(s,xml,null,e);}
if(xml||isTimeout=="timeout")
{requestDone=true;var status;try{status=isTimeout!="timeout"?"success":"error";if(status!="error")
{var data=jQuery.uploadHttpData(xml,s.dataType);if(s.success)
s.success(data,status);if(s.global)
jQuery.event.trigger("ajaxSuccess",[xml,s]);}else
jQuery.handleError(s,xml,status);}catch(e)
{status="error";jQuery.handleError(s,xml,status,e);}
if(s.global)
jQuery.event.trigger("ajaxComplete",[xml,s]);if(s.global&&!--jQuery.active)
jQuery.event.trigger("ajaxStop");if(s.complete)
s.complete(xml,status);jQuery(io).unbind()
setTimeout(function()
{try
{$(io).remove();$(form).remove();}catch(e)
{jQuery.handleError(s,xml,null,e);}},100)
xml=null}}
if(s.timeout>0)
{setTimeout(function(){if(!requestDone)uploadCallback("timeout");},s.timeout);}
try
{var form=$('#'+formId);$(form).attr('action',s.url);$(form).attr('method','POST');$(form).attr('target',frameId);if(form.encoding)
{form.encoding='multipart/form-data';}
else
{form.enctype='multipart/form-data';}
$(form).submit();}catch(e)
{jQuery.handleError(s,xml,null,e);}
if(window.attachEvent){document.getElementById(frameId).attachEvent('onload',uploadCallback);}
else{document.getElementById(frameId).addEventListener('load',uploadCallback,false);}
return{abort:function(){}};},uploadHttpData:function(r,type){var data=!type;data=type=="xml"||data?r.responseXML:r.responseText;if(type=="script")
jQuery.globalEval(data);if(type=="json")
eval("data = "+data);if(type=="html")
jQuery("<div>").html(data).evalScripts();return data;}})
$.fn.SpinButton=function(cfg){return this.each(function(){this.spinCfg={min:cfg&&!isNaN(parseFloat(cfg.min))?Number(cfg.min):null,max:cfg&&!isNaN(parseFloat(cfg.max))?Number(cfg.max):null,step:cfg&&cfg.step?Number(cfg.step):1,page:cfg&&cfg.page?Number(cfg.page):10,upClass:cfg&&cfg.upClass?cfg.upClass:'up',downClass:cfg&&cfg.downClass?cfg.downClass:'down',reset:cfg&&cfg.reset?cfg.reset:this.value,delay:cfg&&cfg.delay?Number(cfg.delay):500,interval:cfg&&cfg.interval?Number(cfg.interval):100,onChange:cfg&&cfg.onChange?cfg.onChange:null,_btn_width:20,_btn_height:12,_direction:null,_delay:null,_repeat:null};this.adjustValue=function(i){var v=(isNaN(this.value)?this.spinCfg.reset:Number(this.value))+Number(i);if(this.spinCfg.min!==null)v=Math.max(v,this.spinCfg.min);if(this.spinCfg.max!==null)v=Math.min(v,this.spinCfg.max);this.value=v;if(this.spinCfg.onChange)this.spinCfg.onChange(this);};$(this).addClass(cfg&&cfg.spinClass?cfg.spinClass:'spin-button').mousemove(function(e){var x=e.pageX||e.x;var y=e.pageY||e.y;var el=e.target||e.srcElement;var direction=(x>coord(el,'offsetLeft')+el.offsetWidth-this.spinCfg._btn_width)?((y<coord(el,'offsetTop')+this.spinCfg._btn_height)?1:-1):0;if(direction!==this.spinCfg._direction){switch(direction){case 1:$(this).removeClass(this.spinCfg.downClass).addClass(this.spinCfg.upClass);break;case-1:$(this).removeClass(this.spinCfg.upClass).addClass(this.spinCfg.downClass);break;default:$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);}
this.spinCfg._direction=direction;}}).mouseout(function(){$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);this.spinCfg._direction=null;}).mousedown(function(e){if(this.spinCfg._direction!=0){var self=this;var adjust=function(){self.adjustValue(self.spinCfg._direction*self.spinCfg.step);};adjust();self.spinCfg._delay=window.setTimeout(function(){adjust();self.spinCfg._repeat=window.setInterval(adjust,self.spinCfg.interval);},self.spinCfg.delay);}}).mouseup(function(e){window.clearInterval(this.spinCfg._repeat);window.clearTimeout(this.spinCfg._delay);}).dblclick(function(e){if($.browser.msie)
this.adjustValue(this.spinCfg._direction*this.spinCfg.step);}).keydown(function(e){switch(e.keyCode){case 38:this.adjustValue(this.spinCfg.step);break;case 40:this.adjustValue(-this.spinCfg.step);break;case 33:this.adjustValue(this.spinCfg.page);break;case 34:this.adjustValue(-this.spinCfg.page);break;}}).bind("mousewheel",function(e){if(e.wheelDelta>=120)
this.adjustValue(this.spinCfg.step);else if(e.wheelDelta<=-120)
this.adjustValue(-this.spinCfg.step);e.preventDefault();}).change(function(e){this.adjustValue(0);});if(this.addEventListener){this.addEventListener('DOMMouseScroll',function(e){if(e.detail>0)
this.adjustValue(-this.spinCfg.step);else if(e.detail<0)
this.adjustValue(this.spinCfg.step);e.preventDefault();},false);}});function coord(el,prop){var c=el[prop],b=document.body;while((el=el.offsetParent)&&(el!=b)){if(!$.browser.msie||(el.currentStyle.position!='relative'))
c+=el[prop];}
return c;}};
var global_id_counter=1;var template;function debug(msg){if(window.console&&console.debug)
{console.debug(msg);}}
function JS_GiftCertificate_Template(id){this.items=[];this.id=id;var layout_element;var config_element;}
JS_GiftCertificate_Template.prototype.register_item=function(item){this.items.push(item);};JS_GiftCertificate_Template.prototype.as_hash=function(){var hash={id:this.id,items:[]};for(var item_nr in this.items){var item=this.items[item_nr];hash.items.push(item.as_hash());}
return hash;};JS_GiftCertificate_Template.prototype.to_json=function(){var hash=this.as_hash();return $.toJSON(hash);};JS_GiftCertificate_Template.prototype.submit=function(form,name){var json=this.to_json();var $form=$("form[name='"+form+"']");var input=$('<input type="hidden" name="'+name+'" />');input.val(json);input.appendTo($form);$form.submit();};function JS_GiftCertificate_Item(template,options_in){var _self=this;var defaults={id:global_id_counter++,x:50,y:50,z:50,w:null,h:null,font_size:100};if(template){this.template=template;this.template.register_item(this);this.options=$.extend(defaults,options_in);this.config=$('<tr/>');this.config.appendTo($('#gift_certificate_config'));this.delete_button=$('<button/>').html('X');this.delete_button.addClass('delete_button');$('<td/>').append(this.delete_button).appendTo(this.config);this.delete_button.click(function(){_self.delete_me();});}}
JS_GiftCertificate_Item.prototype.add_hidden_config=function(){var key='gcitem_'+this.item_nr
+'__template_'+this.template.id
+'__type_'+this.type;this.hidden=$('<input type="hidden" name="'+key+'" value="" />');this.hidden.appendTo(this.config);};JS_GiftCertificate_Item.prototype.as_hash=function(){var x=this.element.css('left');x=x.substring(0,x.length-2);var y=this.element.css('top');y=y.substring(0,y.length-2);var hash={type:this.type,id:this.options.id,x:x,y:y,z:this.options.z,w:this.options.w,font_size:this.options.font_size};return hash;};JS_GiftCertificate_Item.prototype.delete_me=function(){this.element.remove();this.config.remove();};JS_GiftCertificate_Item.prototype.place_element=function(){this.element.css('left',this.options.x+'px');this.element.css('top',this.options.y+'px');};JS_GiftCertificate_Item.prototype.update_width=function(){this.config_width=this.config_width.val();this.element.css('width',this.width+'px');};JS_GiftCertificate_Item.prototype.add_width_config=function(){var _self=this;this.config_width=$('<input size="3"/>');this.config_width.val(this.options.w);$('<td/>').append(this.config_width).appendTo(this.config);this.config_width.SpinButton({min:5,max:10000,step:5,onChange:function(){_self.w=_self.config_width.val();_self.element.css('width',_self.w+'px');}});this.config_width.change(function(){_self.w=_self.config_width.val();_self.element.css('width',_self.w+'px');});};JS_GiftCertificate_Item_Text.prototype=new JS_GiftCertificate_Item();function JS_GiftCertificate_Item_Text(template,options_in)
{var _self=this;if(!template)return;this.type='Text';JS_GiftCertificate_Item.call(this,template,options_in);debug("Creating a GiftCertificate_Item_Text('"+this.options.text+"')");this.font_weight='bold';this.text=this.options.text?this.options.text:'Write here';this.make_element();this.place_element();this.make_config();}
JS_GiftCertificate_Item_Text.prototype.as_hash=function(){var hash=JS_GiftCertificate_Item.prototype.as_hash.call(this);hash.text=this.text;return hash;};JS_GiftCertificate_Item_Text.prototype.make_element=function(){this.element=$('<div/>');this.element.html(this.text);this.element.appendTo($('#gift_certificate_layout'));this.element.addClass('gift_certificate_item');this.element.draggable({containment:'#gift_certificate_layout',scroll:false});};JS_GiftCertificate_Item_Text.prototype.make_config=function(){var _self=this;this.config_label=$('<label/>');this.config_label.html(this.type);$('<td/>').append(this.config_label).appendTo(this.config);this.config_input=$('<input/>');this.config_input.val(this.text);this.config_input.change(function(){_self.element.html(_self.config_input.val());});$('<td/>').append(this.config_input).appendTo(this.config);this.config_size=$('<input size="3"/>');this.config_size.val(this.options.font_size);$('<td/>').append(this.config_size).appendTo(this.config);this.config_size.SpinButton({min:5,max:10000,step:5,onChange:function(){_self.update_font_size();}});this.config_size.change(function(){_self.update_font_size();});this.config_size.change();};JS_GiftCertificate_Item_Text.prototype.update_font_size=function(){this.options.font_size=this.config_size.val();this.element.css('font-size',this.options.font_size+'%');};JS_GiftCertificate_Item_Input.prototype=new JS_GiftCertificate_Item_Text();function JS_GiftCertificate_Item_Input(template,options_in)
{var _self=this;this.type='Input';JS_GiftCertificate_Item.call(this,template,options_in);debug("Creating a GiftCertificate_Item_Input('"+this.options.text+"')");this.text=this.options.text?this.options.text:'Write here';this.make_element();this.place_element();this.make_config();this.options.w=this.options.w?this.options.w:this.element.width();this.add_width_config();this.config_width.change();}
JS_GiftCertificate_Item_Code.prototype=new JS_GiftCertificate_Item_Text();function JS_GiftCertificate_Item_Code(template,options_in)
{var _self=this;this.type='Code';JS_GiftCertificate_Item.call(this,template,options_in);debug("Creating a GiftCertificate_Item_Code()");this.text='012345678901';this.make_element();this.place_element();this.config_label=$('<label/>');this.config_label.html('Code');$('<td/>').append(this.config_label).appendTo(this.config);$('<td/>').appendTo(this.config);this.config_size=$('<input size="3"/>');this.config_size.val(this.options.font_size);$('<td/>').append(this.config_size).appendTo(this.config);this.config_size.SpinButton({min:5,max:10000,step:5,onChange:function(){_self.update_font_size();}});this.config_size.change(function(){_self.update_font_size();});this.config_size.change();this.config.append('<br/>');}
JS_GiftCertificate_Item_BarCode.prototype=new JS_GiftCertificate_Item();function JS_GiftCertificate_Item_BarCode(template,options_in)
{var _self=this;this.type='BarCode';JS_GiftCertificate_Item.call(this,template,options_in);debug("Creating a GiftCertificate_Item_BarCode()");this.img_url="http://www.terryburton.co.uk/barcodewriter/generator/tmp/88e01b06b22fd0c2c7cf97eb403347d56766fbfb/barcode.png";this.element=$('<img/>');this.element.attr('src',this.img_url);this.element.css('width',this.options.w+'px');this.element.appendTo($('#gift_certificate_layout'));this.element.addClass('gift_certificate_item');this.element.draggable({containment:'#gift_certificate_layout',scroll:false});this.place_element();this.config_label=$('<label/>');this.config_label.html('BarCode');$('<td/>').append(this.config_label).appendTo(this.config);$('<td/>').appendTo(this.config);$('<td/>').appendTo(this.config);this.add_width_config();this.config.append('<br/>');}
$.extend({JS_GiftCertificate_Item_Text:JS_GiftCertificate_Item_Text,JS_GiftCertificate_Item_Input:JS_GiftCertificate_Item_Input,JS_GiftCertificate_Item_BarCode:JS_GiftCertificate_Item_BarCode,debug:debug});