String.prototype.count=function(s1){return(this.length-this.replace(new RegExp(s1,"g"),'').length)/s1.length;}
String.prototype.repeat=function(l){return new Array(l+1).join(this);};(function($){$.fn.quick_pen_store=function(options){var defaults={setup_id:'',convert_id:'',namelist_id:'',show_cap:true,data:{}};var options=$.extend(defaults,options);return this.each(function(){var $this=$(this);if(!$this.val()){$this.val(options.newid);}
var tmpid=$this.val();var $setupInput=$(options.setup_id+" input").css('visibility','hidden').insertAfter($this);var $convertCapInput=$(options.convert_cap_id+" input").css('visibility','hidden').insertAfter($this);var $convertBarrelInput=$(options.convert_barrel_id+" input").css('visibility','hidden').insertAfter($this);var $namelistInput=$(options.namelist_id+" input").css('visibility','hidden').insertAfter($this);$(options.setup_id+" h4").remove();$(options.convert_cap_id+" h4").remove();$(options.convert_barrel_id+" h4").remove();$(options.namelist_id+" h4").remove();$(options.setup_id+" label").remove();$(options.convert_cap_id+" label").remove();$(options.convert_barrel_id+" label").remove();$(options.namelist_id+" label").remove();$(options.setup_id+" br").remove();$(options.convert_cap_id+" br").remove();$(options.convert_barrel_id+" br").remove();$(options.namelist_id+" br").remove();$(options.setup_id+" div[id^=options-gallery]").remove();$(options.convert_cap_id+" div[id^=options-gallery]").remove();$(options.convert_barrel_id+" div[id^=options-gallery]").remove();$(options.namelist_id+" div[id^=options-gallery]").remove();$(options.setup_id+" .wrapperAttribsOptions").remove();$(options.convert_cap_id+" .wrapperAttribsOptions").remove();$(options.convert_barrel_id+" .wrapperAttribsOptions").remove();$(options.namelist_id+" .wrapperAttribsOptions").remove();$(options.setup_id).css('padding','0');$(options.convert_cap_id).css('padding','0');$(options.convert_barrel_id).css('padding','0');$(options.namelist_id).css('padding','0');function buildLine(area,id){var line='<select name="ps_'+area+'_line'+id+'_select">'+'<option value="0" selected="selected"> - Select - </option>'+'<option value="1">None</option>'+'<option value="2">Text</option>'+'<option value="3">Name List</option>'+'</select>'+'</td><td>'+'<input name="ps_'+area+'_line'+id+'" title="'+area+'" type="text" size="30" maxlength="25" style="width: 95%" />';return line;}
function buildCapBarrelArea(label,id){var area='<div style="width: 250px; text-align: left;">'+'<input type="radio" name="ps_'+id+'_mode" id="'+id+'_mode_1" value="none" /><label for="'+id+'_mode_1">None</label>'+'<input type="radio" name="ps_'+id+'_mode" id="'+id+'_mode_2" value="text" checked="checked" /><label for="'+id+'_mode_2">Text</label>'+'<input type="radio" name="ps_'+id+'_mode" id="'+id+'_mode_4" value="logo" /><label for="'+id+'_mode_4">Logo</label>'+'</div>'+'<table id="'+id+'_edit" width="95%" cellpadding="3" cellspacing="0" class="penstore_graytable">'+'<tr>'+'<td rowspan="2" style="width: 26px; background-color: #434343;" align="center" valign="center">'+'<img src="/images/other/'+id+'_text.jpg" border="0" />'+'</td>'+'<td style="width: 80px">'+
buildLine(id,'1')+'</td>'+'</tr>'+'<tr>'+'<td style="width: 80px">'+
buildLine(id,'2')+'</td>'+'</tr>'+'</table>';return area;}
var html='<input type="hidden" name="penstore_id" value="'+$this.val()+'" />'+'<table width="740" cellpadding="0" cellspacing="0">'+'<tr>'+'<td align="center" width="44%">'+
buildCapBarrelArea('Cap','cap')+'</td>'+'<td width="2%"></td>'+'<td align="center" width="54%">'+
buildCapBarrelArea('Barrel','barrel')+'</td>'+'</tr>'+'<tr>'+'<td colspan="3">'+'</td>'+'</tr>'+'<tr>'+'<th colspan="3" align="center">'+'<p align="center">'+'<h4 class="attributesComments">Paste Name List Below</h4>'+'<input type="checkbox" id="ps_namelist_avail" name="ps_namelist_avail" value="not_avail"/>'+'<label for="ps_namelist_avail">I am not sure of my name list, I will provide it later.</label>'+'</p>'+'</th>'+'</tr>'+'<tr>'+'<td colspan="3">'+'<table width="100%">'+'<tr>'+'<td width="50%">'+'<textarea name="ps_namelist" id="ps_namelist" style="width: 100%;" rows="10"></textarea>'+'</td>'+'<td width="50%" align="center" valign="center">'+'<input type="checkbox" name="ps_waive_logo" id="ps_waive_logo" value="1"/><label for="ps_waive_logo">Waive my logo conversion fee, my logo is already on file.</label>'+'<br/>'+'<br/>'+'<table width="80%" class="penstore_total_table" cellpadding="3" cellspacing="0" border="0">'+'<tr>'+'<th align="center">Fees</td><th width="50" align="center">Total</td>'+'</tr>'+'<tr>'+'<td align="left">Setup Charge</td><td align="right"><span id="ps_setup">$0.0</span></td>'+'</tr>'+'<tr>'+'<td align="left">Cap Logo Conversion Fee</td><td align="right"><span id="ps_cap_logo">$0.0</span></td>'+'</tr>'+'<tr>'+'<td align="left">Barrel Logo Conversion Fee</td><td align="right"><span id="ps_barrel_logo">$0.0</span></td>'+'</tr>'+'<tr>'+'<td align="left"><span id="ps_names">0</span> Names @ $0.99 each</td><td align="right"><span id="ps_name_charge">$0.0</span></td>'+'</tr>'+'<tr>'+'<td align="left" class="total">Total</td><td align="right" class="total"><span id="ps_charge">$0.0</span></td>'+'</tr>'+'</table>'+'</td>'+'</tr>'+'<tr>'+'<td>'+'(Be sure there is <span class="warn">ONLY ONE NAME PER LINE<span> and <span class="warn">DOUBLE CHECK SPELLING</span>)'+'</td>'+'<td>'+'</td>'+'</tr>'+'</table>'+'</td>'+'</tr>'+'</table>';$explanation='<p align="center">'+'<a href="" id="penstore_explanation_title">'+'<img src="/images/question.jpg" border="0"/>EXPLANATION & PRICING'+'</a>'+'</p>'+'<div id="penstore_explanation">'+'<h4 class="attributesComments" id="penstore_explanation_title">EXPLANATION</h4>'+'<table width="740" cellpadding="0" cellspacing="0" class="penstore_explanation" >'+'<tr>'+'<td align="center">None</td>'+'<td>Choose if you want no engraving on the pen'+'</td>'+'</tr>'+'<tr>'+'<td align="center">Cap/Barrel</td>'+'<td>Depending on the model, we can engrave on the cap, the barrel, or both.  If the respective area above has a grey shadow over it, the model you have chosen does not allow engraving in that area.  For any other engraving layouts (engraving on both sides of a pen, logo and company name together on cap or barrel, etc.), please call and speak to one of our friendly customer service representatives.</td>'+'</tr>'+'<tr>'+'<td align="center">Text</td>'+'<td>Choose if you want the same text engraved on every pen.  Our standard font is Times New Roman.  Other choices may be available upon request.'+'</td>'+'</tr>'+'<tr>'+'<td align="center">Name List</td>'+'<td>Choose if you want a unique name or text engraved on each pen. A $0.99 per pen charge applies for each pen.'+'</td>'+'</tr>'+'<tr>'+'<td align="center">Logo</td>'+'<td>A $29.95 Charge applies for a first time logo conversion.  If we have previously converted a logo for your company for engraving on our pens, this fee will be waived for all subsequent orders using the same logo.'+'</td>'+'</tr>'+'<tr>'+'<td align="center">Logo File Details</td>'+'<td>Logos should be forwarded to <a href="mailto:logos@djbpens.com">logos@djbpens.com</a>.  We can work with virtually any file format, however, for best results VECTOR ART (.eps or .ai) files.  If not available, .jpeg, .tiff, .pdf, .gif, .png, .bmp, .cdr can also be used although results may vary.'+'</td>'+'</tr>'+'<tr>'+'<td align="center">Laser Setup Fees</td>'+'<td>One or more Laser Setup Fees may apply for all personalized orders.  Each time a laser needs to be setup for an order or a portion of an order, we must take time to "reset" our lasers.  We charge a $9.95 setup fee EACH TIME WE CHANGE A SETUP.  (Example - 100 Pens are ordered, 60 pens are engraved with a company name and logo, and 40 pens are engraved with the company logo and a unique employee name.  For this example, there would be 2 setup charges.)'+'</td>'+'</tr>'+'</table>'+'<div>';$("#options-"+options.stepid).append($explanation);$this.hide();$this.after(html);$this.delay(100,function(){$('#ps_namelist_avail').click(function(){if($(this).is(':checked')){$('#ps_namelist').attr('disabled',true);$('#ps_namelist').addClass('input_disabled');}else{$('#ps_namelist').attr('disabled',false);$('#ps_namelist').removeClass('input_disabled');}
calcCharges();});$('#ps_namelist').attr('disabled',false);$('#ps_namelist_table').attr('disabled',true);$('#options-comment-'+options.stepid).html($('#options-comment-'+options.stepid).text()+' - <span class="penstore_comment">(25 Characters per line - 2 Line Max)</span>');var $cap_mode=$("input[name='ps_cap_mode']");var $barrel_mode=$("input[name='ps_barrel_mode']");var $ps_cap_line1=$('input[name=ps_cap_line1]');var $ps_cap_line2=$('input[name=ps_cap_line2]');var $ps_barrel_line1=$('input[name=ps_barrel_line1]');var $ps_barrel_line2=$('input[name=ps_barrel_line2]');var $setup=$setupInput;var $namelist=$namelistInput;var $convert_cap=$convertCapInput;var $convert_barrel=$convertBarrelInput;var cap_line1_select=$('select[name=ps_cap_line1_select]');var cap_line2_select=$('select[name=ps_cap_line2_select]');var barrel_line1_select=$('select[name=ps_barrel_line1_select]');var barrel_line2_select=$('select[name=ps_barrel_line2_select]');var cap_line_mode='text';var barrel_line_mode='text';var cap='text';var barrel='text';$('#penstore_explanation_title').click(function(){$('#penstore_explanation').toggle();return false;});$('#penstore_explanation').hide();function setBlock(id,img,$target){var $target=$target
$('#'+id).remove();var attachTarget=null
var style="";if(img!=null){style=' style="background-image: url('+img+'); background-position: center; background-position-x: center; background-position-y: center;" ';}
var div='<div id="'+id+'" class="block_box"'+style+'>&nbsp;</div>';if(jQuery.browser.msie){$('body').append(div);}else{$target.after(div);}
var $id=$('#'+id);$id.visible=true;$("div#options-"+options.stepid).bind('hidding',function(){$id.hide();$id.visible=false;});$("div#options-"+options.stepid).bind('showing',function(){$id.show();$id.visible=true;});$id.wait_fn=function(){var tpos=$target.offset();if($target.width()>0&&$target.height()>0){var cssAdj={'width':parseInt($target.width())+2,'height':parseInt($target.height())+2,'top':parseInt(tpos.top),'left':parseInt(tpos.left)};$id.css(cssAdj);if($id.visible){$id.fadeTo('slow',.5);}}
$id.delay(100,$id.wait_fn);}
$id.delay(100,$id.wait_fn);}
function removeBlock(id){$('#'+id).showing_fn=null;$('#'+id).hidding_fn=null;$('#'+id).wait_fn=null;$('#'+id).remove();}
var modes_fn=function(){cap=$("input[name='ps_cap_mode']:checked").val();barrel=$("input[name='ps_barrel_mode']:checked").val();var cap_line=false;var cap_line1=false;var cap_line2=false;var namelist=false;var namelist_avail=false;var barrel_line=false;var barrel_line1=false;var barrel_line2=false;if(cap=='none'&&options.show_cap){cap_line=false;}else if(cap=='text'){cap_line=true;if(cap_line1_select.val()==2){cap_line1=true;}
if(cap_line2_select.val()==2){cap_line2=true;}
if(cap_line1_select.val()==3||cap_line2_select.val()==3){namelist_avail=true;namelist=true;}}else if(cap=='logo'&&options.show_cap){cap_line=false;}
if(barrel=='none'){barrel_line=false;}else if(barrel=='text'){barrel_line=true;if(barrel_line1_select.val()==2){barrel_line1=true;}
if(barrel_line2_select.val()==2){barrel_line2=true;}
if(barrel_line1_select.val()==3||barrel_line2_select.val()==3){namelist_avail=true;namelist=true;}}else if(barrel=='logo'){barrel_line=false;}
if(cap_line&&options.show_cap){if(cap_line1){$('input[name=ps_cap_line1]').attr('disabled',false).removeClass('input_disabled');}else{$('input[name=ps_cap_line1]').attr('disabled',true).addClass('input_disabled');}
if(cap_line2){$('input[name=ps_cap_line2]').attr('disabled',false).removeClass('input_disabled');}else{$('input[name=ps_cap_line2]').attr('disabled',true).addClass('input_disabled');}
removeBlock('cap_block');}else{$('input[name=ps_cap_line1]').attr('disabled',true);$('input[name=ps_cap_line2]').attr('disabled',true);$('input[name=ps_cap_line1]').addClass('input_disabled');$('input[name=ps_cap_line2]').addClass('input_disabled');if(options.show_cap){var blockImg='/images/other/logoHere.png';if(cap=='none'){blockImg='';}
setBlock('cap_block',blockImg,$('#cap_edit'));}}
if(barrel_line){if(barrel_line1){$('input[name=ps_barrel_line1]').attr('disabled',false).removeClass('input_disabled');}else{$('input[name=ps_barrel_line1]').attr('disabled',true).addClass('input_disabled');}
if(barrel_line2){$('input[name=ps_barrel_line2]').attr('disabled',false).removeClass('input_disabled');}else{$('input[name=ps_barrel_line2]').attr('disabled',true).addClass('input_disabled');}
removeBlock('barrel_block');}else{$('input[name=ps_barrel_line1]').attr('disabled',true);$('input[name=ps_barrel_line2]').attr('disabled',true);$('input[name=ps_barrel_line1]').addClass('input_disabled');$('input[name=ps_barrel_line2]').addClass('input_disabled');var blockImg='/images/other/logoHere.png';if(barrel=='none'){blockImg='';}
setBlock('barrel_block',blockImg,$('#barrel_edit'));}
if(namelist_avail){$('#ps_namelist_avail').attr('disabled',false);$('#ps_namelist_avail').removeClass('input_disabled');if($('#ps_namelist_avail').is(':checked')){$('#ps_namelist').attr('disabled',true);$('#ps_namelist').addClass('input_disabled');}else{$('#ps_namelist').attr('disabled',false);$('#ps_namelist').removeClass('input_disabled');}}else{$('#ps_namelist_avail').attr('disabled',true);$('#ps_namelist_avail').addClass('input_disabled');$('#ps_namelist').attr('disabled',true);$('#ps_namelist').addClass('input_disabled');}
if(!options.show_cap){$cap_mode.attr('disabled',true);cap_line1_select.attr('disabled',true);cap_line2_select.attr('disabled',true);$cap_mode.addClass('input_disabled');cap_line1_select.addClass('input_disabled');cap_line2_select.addClass('input_disabled');}
calcCharges();};function calcCharges(){var charge_setup=false;var charge_cap_convert=false;var charge_barrel_convert=false;var total=0;if(cap=='text'||barrel=='text'){if($ps_cap_line1.val()||$ps_cap_line2.val()||$ps_barrel_line1.val()||$ps_barrel_line2.val()){if(((cap_line1_select.val()==2||cap_line2_select.val()==2)&&cap=='text')||((barrel_line1_select.val()==2||barrel_line2_select.val()==2)&&barrel=='text')){charge_setup=true;}}}
if(cap=='logo'||barrel=='logo'){if(!$('input[name=ps_waive_logo]').is(':checked')){if(cap=='logo'){charge_cap_convert=true;}
if(barrel=='logo'){charge_barrel_convert=true;}}
charge_setup=true;}
if((cap_line1_select.val()==3||cap_line2_select.val()==3||barrel_line1_select.val()==3||barrel_line2_select.val()==3)&&(cap=='text'||barrel=='text')&&$namelistInput.val().length>0&&!$('#ps_namelist_avail').is(':checked')){var numPatt=new RegExp("\\d+");var nl_count=parseFloat(numPatt.exec($namelistInput.val()));var nl_charge=0.99*nl_count;charge_setup=true;total+=nl_charge;$('#ps_names').html(nl_count);$('#ps_name_charge').html('$'+nl_charge.toFixed(2));}
else{$('#ps_names').html('0');$('#ps_name_charge').html('$0.00');}
if(charge_setup){$setup.attr('checked','checked');$('#ps_setup').html('$9.95');total+=9.95;}else{$setup.removeAttr('checked');$('#ps_setup').html('$0.00');}
if(charge_cap_convert){$convert_cap.attr('checked','checked');$('#ps_cap_logo').html('$29.95');total+=29.95;}else{$convert_cap.removeAttr('checked');$('#ps_cap_logo').html('$0.00');}
if(charge_barrel_convert){$convert_barrel.attr('checked','checked');$('#ps_barrel_logo').html('$29.95');total+=29.95;}else{$convert_barrel.removeAttr('checked');$('#ps_barrel_logo').html('$0.00');}
$('#ps_charge').html('$'+total.toFixed(2));}
if(options.show_cap){$('select[name=ps_cap_line1_select]').change(modes_fn);$('select[name=ps_cap_line2_select]').change(modes_fn);}
$('select[name=ps_barrel_line1_select]').change(modes_fn);$('select[name=ps_barrel_line2_select]').change(modes_fn);$('#ps_namelist').blur(function(){if($(this).val().length>0&&!$('#ps_namelist_avail').is(':checked')&&(cap_line1_select.val()==3||cap_line2_select.val()==3||barrel_line1_select.val()==3||barrel_line2_select.val()==3)){var val=$(this).val().replace(/\n\s*$/,'');val=$.trim(val);$(this).val(val);if(val.length>0){var count=val.count("\n")+1;$namelistInput.val(count+" Names at $0.99");}else{$namelistInput.val("0 Names at $0.99");}}else{$namelistInput.val('');}
calcCharges();});$('input[name=ps_waive_logo]').click(calcCharges);if(options.show_cap){$ps_cap_line1.blur(calcCharges);$ps_cap_line2.blur(calcCharges);$cap_mode.click(modes_fn);}else{setBlock('no_show_cap','/images/other/notAvail.png',$('#cap_edit'));}
$ps_barrel_line1.blur(calcCharges);$ps_barrel_line2.blur(calcCharges);$barrel_mode.click(modes_fn);if(options.data!=null){var data=options.data;if(options.show_cap){$('input[name=ps_cap_mode][value='+data.ps_cap_mode+']').attr('checked','checked');$('input[name=ps_cap_line1]').val(data.ps_cap_line1);$('input[name=ps_cap_line2]').val(data.ps_cap_line2);$('select[name=ps_cap_line1_select] option[selected=selected]').removeAttr('selected');$('select[name=ps_cap_line2_select] option[selected=selected]').removeAttr('selected');$('select[name=ps_cap_line1_select] option[value='+data.ps_cap_line1_select+']').attr('selected','selected');$('select[name=ps_cap_line2_select] option[value='+data.ps_cap_line2_select+']').attr('selected','selected');}
$('input[name=ps_barrel_mode][value='+data.ps_barrel_mode+']').attr('checked','checked');$('input[name=ps_barrel_line1]').val(data.ps_barrel_line1);$('input[name=ps_barrel_line2]').val(data.ps_barrel_line2);$('select[name=ps_barrel_line1_select] option[selected=selected]').removeAttr('selected');$('select[name=ps_barrel_line2_select] option[selected=selected]').removeAttr('selected');$('select[name=ps_barrel_line1_select] option[value='+data.ps_barrel_line1_select+']').attr('selected','selected');$('select[name=ps_barrel_line2_select] option[value='+data.ps_barrel_line2_select+']').attr('selected','selected');if(!data.ps_namelist_avail){$('input[name=ps_namelist_avail]').attr('checked','checked');}
$('textarea[name=ps_namelist]').val(data.ps_namelist);if(data.ps_waive_logo==1){$('input[name=ps_waive_logo]').attr('checked','checked');}}
modes_fn();calcCharges();});});};})(jQuery);