
/*
 * jQuery blockUI plugin
 * Version 2.11 (12/13/2008)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://malsup.com/jquery/block/
 * Copyright (c) 2007-2008 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
 */

;(function($) {

if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
 alert('blockUI requires jQuery v1.2.3 or later! You are using v' + $.fn.jquery);
 return;
}

// global $ methods for blocking/unblocking the entire page
$.blockUI = function(opts) { install(window, opts); };
$.unblockUI = function(opts) { remove(window, opts); };

// plugin method for blocking element content
$.fn.block = function(opts) {
 return this.each(function() {
 if ($.css(this,'position') == 'static')
 this.style.position = 'relative';
 if ($.browser.msie) 
 this.style.zoom = 1; // force 'hasLayout'
 install(this, opts);
 });
};

// plugin method for unblocking element content
$.fn.unblock = function(opts) {
 return this.each(function() {
 remove(this, opts);
 });
};

$.blockUI.version = 2.11; // 2nd generation blocking at no extra cost!

// override these in your code to change the default behavior and style
$.blockUI.defaults = {
 // message displayed when blocking (use null for no message)
 message: '<h1>Please wait...</h1>',
 
 // styles for the message when blocking; if you wish to disable
 // these and use an external stylesheet then do this in your code:
 // $.blockUI.defaults.css = {};
 css: { 
 padding: 0,
 margin: 0,
 width: '30%', 
 top: '40%', 
 left: '35%', 
 textAlign: 'center', 
 color: '#000', 
 border: '3px solid #aaa',
 backgroundColor:'#fff',
 cursor: 'wait'
 },
 
 // styles for the overlay
 overlayCSS: { 
 backgroundColor:'#000', 
 opacity: '0.6' 
 },
 
 // z-index for the blocking overlay
 baseZ: 1000,
 
 // set these to true to have the message automatically centered
 centerX: true, // <-- only effects element blocking (page block controlled via css above)
 centerY: true,
 
 // allow body element to be stetched in ie6; this makes blocking look better
 // on "short" pages. disable if you wish to prevent changes to the body height
 allowBodyStretch: true,
 
 // be default blockUI will supress tab navigation from leaving blocking content;
 constrainTabKey: true,
 
 // fadeOut time in millis; set to 0 to disable fadeout on unblock
 fadeOut: 400,
 
 // if true, focus will be placed in the first available input field when
 // page blocking
 focusInput: true,
 
 // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
 applyPlatformOpacityRules: true,
 
 // callback method invoked when unblocking has completed; the callback is
 // passed the element that has been unblocked (which is the window object for page
 // blocks) and the options that were passed to the unblock call:
 // onUnblock(element, options)
 onUnblock: null,
 
 // don't ask (if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493)
 quirksmodeOffsetHack: 4
};

// private data and functions follow...

var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
var pageBlock = null;
var pageBlockEls = [];

function install(el, opts) {
 var full = (el == window);
 var msg = opts && opts.message !== undefined ? opts.message : undefined;
 opts = $.extend({}, $.blockUI.defaults, opts || {});
 opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
 var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
 msg = msg === undefined ? opts.message : msg;

 // remove the current block (if there is one)
 if (full && pageBlock) 
 remove(window, {fadeOut:0}); 
 
 // if an existing element is being used as the blocking content then we capture
 // its current place in the DOM (and current display style) so we can restore
 // it when we unblock
 if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
 var node = msg.jquery ? msg[0] : msg;
 var data = {};
 $(el).data('blockUI.history', data);
 data.el = node;
 data.parent = node.parentNode;
 data.display = node.style.display;
 data.position = node.style.position;
 data.parent.removeChild(node);
 }
 
 var z = opts.baseZ;
 
 // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
 // layer1 is the iframe layer which is used to supress bleed through of underlying content
 // layer2 is the overlay layer which has opacity and a wait cursor
 // layer3 is the message content that is displayed while blocking
 
 var lyr1 = ($.browser.msie) ? $('<iframe class="blockUI" style="z-index:'+ z++ +';border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="javascript:false;"></iframe>')
 : $('<div class="blockUI" style="display:none"></div>');
 var lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ z++ +';cursor:wait;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
 var lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';position:fixed"></div>')
 : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');

 // if we have a message, style it
 if (msg) 
 lyr3.css(css);

 // style the overlay
 if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform))) 
 lyr2.css(opts.overlayCSS);
 lyr2.css('position', full ? 'fixed' : 'absolute');
 
 // make iframe layer transparent in IE
 if ($.browser.msie) 
 lyr1.css('opacity','0.0');

 $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
 
 // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
 var expr = $.browser.msie && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
 if (ie6 || expr) {
 // give body 100% height
 if (full && opts.allowBodyStretch && $.boxModel)
 $('html,body').css('height','100%');

 // fix ie6 issue when blocked element has a border width
 if ((ie6 || !$.boxModel) && !full) {
 var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
 var fixT = t ? '(0 - '+t+')' : 0;
 var fixL = l ? '(0 - '+l+')' : 0;
 }

 // simulate fixed position
 $.each([lyr1,lyr2,lyr3], function(i,o) {
 var s = o[0].style;
 s.position = 'absolute';
 if (i < 2) {
 full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"')
 : s.setExpression('height','this.parentNode.offsetHeight + "px"');
 full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
 : s.setExpression('width','this.parentNode.offsetWidth + "px"');
 if (fixL) s.setExpression('left', fixL);
 if (fixT) s.setExpression('top', fixT);
 }
 else if (opts.centerY) {
 if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
 s.marginTop = 0;
 }
 });
 }
 
 // show the message
 lyr3.append(msg).show();
 if (msg && (msg.jquery || msg.nodeType))
 $(msg).show();

 // bind key and mouse events
 bind(1, el, opts);
 
 if (full) {
 pageBlock = lyr3[0];
 pageBlockEls = $(':input:enabled:visible',pageBlock);
 if (opts.focusInput)
 setTimeout(focus, 20);
 }
 else
 center(lyr3[0], opts.centerX, opts.centerY);
};

// remove the block
function remove(el, opts) {
 var full = el == window;
 var data = $(el).data('blockUI.history');
 opts = $.extend({}, $.blockUI.defaults, opts || {});
 bind(0, el, opts); // unbind events
 var els = full ? $('body').children().filter('.blockUI') : $('.blockUI', el);
 
 if (full) 
 pageBlock = pageBlockEls = null;

 if (opts.fadeOut) {
 els.fadeOut(opts.fadeOut);
 setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut);
 }
 else
 reset(els, data, opts, el);
};

// move blocking element back into the DOM where it started
function reset(els,data,opts,el) {
 els.each(function(i,o) {
 // remove via DOM calls so we don't lose event handlers
 if (this.parentNode) 
 this.parentNode.removeChild(this);
 });

 if (data && data.el) {
 data.el.style.display = data.display;
 data.el.style.position = data.position;
 data.parent.appendChild(data.el);
 $(data.el).removeData('blockUI.history');
 }

 if (typeof opts.onUnblock == 'function')
 opts.onUnblock(el,opts);
};

// bind/unbind the handler
function bind(b, el, opts) {
 var full = el == window, $el = $(el);
 
 // don't bother unbinding if there is nothing to unbind
 if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked'))) 
 return;
 if (!full) 
 $el.data('blockUI.isBlocked', b);
 
 // bind anchors and inputs for mouse and key events
 var events = 'mousedown mouseup keydown keypress';
 b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);

// former impl...
// var $e = $('a,:input');
// b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
};

// event handler to suppress keyboard/mouse events when blocking
function handler(e) {
 // allow tab navigation (conditionally)
 if (e.keyCode && e.keyCode == 9) {
 if (pageBlock && e.data.constrainTabKey) {
 var els = pageBlockEls;
 var fwd = !e.shiftKey && e.target == els[els.length-1];
 var back = e.shiftKey && e.target == els[0];
 if (fwd || back) {
 setTimeout(function(){focus(back)},10);
 return false;
 }
 }
 }
 // allow events within the message content
 if ($(e.target).parents('div.blockMsg').length > 0)
 return true;
 
 // allow events for content that is not being blocked
 return $(e.target).parents().children().filter('div.blockUI').length == 0;
};

function focus(back) {
 if (!pageBlockEls) 
 return;
 var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
 if (e) 
 e.focus();
};

function center(el, x, y) {
 var p = el.parentNode, s = el.style;
 var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
 var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
 if (x) s.left = l > 0 ? (l+'px') : '0';
 if (y) s.top = t > 0 ? (t+'px') : '0';
};

function sz(el, p) { 
 return parseInt($.css(el,p))||0; 
};

})(jQuery);


/* jQMinMax v0.1 - Copyright (c) 2006 Dave Cardwell (http://davecardwell.co.uk/)
 Released under the MIT License (http://www.opensource.org/licenses/mit-license.php) */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('u m(){$.5={D:y,v:y};$(G).12(m(){8 h=G.W(\'I\');$(h).e({\'3\':\'J\',\'6-3\':\'K\'});$(\'L\').M(h);$.5.v=(h.s&&h.s==2);$(h).N();b($.5.v)o;$.5.D=O;$.5.A();$(\':5\').5()});$.5.A=m(){8 p=u E(\'6-3\',\'6-4\',\'9-3\',\'9-4\');8 5=u E();Q(8 i=0;i<p.R;i++){8 n="$.e(a,\'"+p[i]+"\')!=\'S\'&&"+"$.e(a,\'"+p[i]+"\')!=\'z\'&&"+"$.e(a,\'"+p[i]+"\')!=f.g";b(p[i].U(2)==\'x\')n+="&&$.e(a,\'"+p[i]+"\')!=\'X\'";$.n[\':\'][p[i]]=n;5[i]=\'(\'+n+\')\'}$.n[\':\'][\'5\']=5.Y(\'||\')};$.Z.5=m(){o $(c).10(m(){8 7={\'6-3\':r(c,\'6-3\'),\'9-3\':r(c,\'9-3\'),\'6-4\':r(c,\'6-4\'),\'9-4\':r(c,\'9-4\')};8 3=c.s;8 4=c.w;8 k=3;8 l=4;b(7[\'9-3\']!=f.g&&k>7[\'9-3\'])k=7[\'9-3\'];b(7[\'6-3\']!=f.g&&k<7[\'6-3\'])k=7[\'6-3\'];b(7[\'9-4\']!=f.g&&l>7[\'9-4\'])l=7[\'9-4\'];b(7[\'6-4\']!=f.g&&l<7[\'6-4\'])l=7[\'6-4\'];b(k!=3)$(c).e(\'3\',k);b(l!=4)$(c).e(\'4\',l)})};m r(t,p){8 q=$(t).e(p);b(q==f.g||q==\'z\')o f.g;8 j;j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)%$/);b(j){o T.V(C((/3$/.h(p)?$(t).F().H(0).s:$(t).F().H(0).w)*j[1]/P))}j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)(?:11)?$/);b(j){o C(j[1])}o f.g}}();',62,65,'|||width|height|minmax|min|constraint|var|max||if|this||css|window|undefined|test||result|newWidth|newHeight|function|expr|return||raw|calculate|offsetWidth|obj|new|native|offsetHeight||false|auto|expressions|match|Number|active|Array|parent|document|get|div|1px|2px|body|append|remove|true|100|for|length|0px|Math|charAt|round|createElement|none|join|fn|each|px|ready'.split('|'),0,{}))

if(!this.JSON){JSON=function(){function f(n){return n<10?'0'+n:n}Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z'};var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapeable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapeable.lastIndex=0;return escapeable.test(string)?'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c}return'\\u'+('0000'+(+(a.charCodeAt(0))).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key)}if(typeof rep==='function'){value=rep.call(holder,key,value)}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null'}gap+=indent;partial=[];if(typeof value.length==='number'&&!(value.propertyIsEnumerable('length'))){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null'}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value,rep);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value,rep);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v}}return{stringify:function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' '}}else if(typeof space==='string'){indent=space}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}return str('',{'':value})},parse:function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+(+(a.charCodeAt(0))).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j}throw new SyntaxError('JSON.parse');}}}()}

$(document).ready(function(){
 $(document).pngFix();
 $('a[rel^="ext"]').attr('target', '_blank');
 $('a[rel*=facebox]').facebox();
 selectMainMenu("mainmenu-");
 selectSubMenu("pmenu-");


 $(".maincol").minmax();

 var v0 = $(".jvalidate-noerr").validate({
 errorPlacement: function() {},
 submitHandler: function(form) {

 var fid = $(form).attr("id");
 switch (fid){
 case "form-subscribe":
 jQuery(form).ajaxSubmit({
 beforeSubmit: preSubscribeSignup,
 success: submitSubscribeSuccess, // post-submit callback
 resetForm: false
 });
 break;
 default:
 }

 }
 });


 var v1 = $(".jvalidate").validate({
 submitHandler: function(form) {

 var fid = $(form).attr("id");
 switch (fid){
 case "form-subscribe":
 jQuery(form).ajaxSubmit({
 beforeSubmit: preSubscribeSignup,
 success: submitSubscribeSuccess, // post-submit callback
 resetForm: false
 });
 break;
 case "form-comment":
 jQuery(form).ajaxSubmit({
 beforeSubmit: preContact,
 success: preContactSuccess, // post-submit callback
 resetForm: false
 });
 break; 
 default:
 }

 },
 rules: {
 comment: {
 required: false,
 maxlength: 2500
 }
 }
 });

});

var aprice = 0;
var ashipping = 0;
var shippingcalculated = false;

function clearMessages(){
 $("#message-err").hide();
 $("#message-success").hide();
 $("#message-err").html('');
 $("#message-success").html('');
}

function preSummary(){
 
};

function preSummarySuccess(data){
 //msgresponse(data,"message-err","","message-success","",callbackSummary);
};

function callbackSummary(data){

};

function preContact(){
 clearMessages();
};

function preContactSuccess(data){
 msgresponse(data,"message-err","","message-success","",callbackContact);
};

function callbackContact(data){
 if(data.err != ""){
 $("#message-err").html(data.err);
 $("#captcha-img").html(data.payload);
 $("#message-err").show();
 }else if(data.err == ""){
 $("#message-success").html(data.msg);
 $("#message-success").show();
 $("#form-comment").hide();
 }

};


function preSubscribeSignup(){
 $('#form-subscribe-loading').show();
};

function submitSubscribeSuccess(data){
 msgresponse(data,"message-err","","message-success","",callbackSubscribe);
};

function callbackSubscribe(data){

 if(data.err == ""){
 $('#form-subscribe-loading').hide();
 $('#form-subscribe').hide();
 $('#form-subscribe-message').html(data.msg);
 }
};


var prevpage = "";
var prevsubpageactive = "";

function selectMainMenu(prefix){
 $("#"+prefix+thepage).addClass("selected");
 if(prevpage !=""){
 $("#"+prefix+prevpage).removeClass("selected");
 }
 prevpage ="#"+prefix+thepage;
};

function selectSubMenu(prefix){
 if(thepage == "products"){
 var thediv = "#"+prefix+thepage+"-"+thesubpage;
 $(thediv).addClass("selected");
 if(prevsubpageactive !=""){
 $("#"+prefix+thepage+"-"+prevsubpageactive).removeClass("visible");
 }
 prevsubpageactive = thediv;
 }
};

function formatAsMoney(mnt) {
 mnt -= 0;
 mnt = (Math.round(mnt*100))/100;
 return (mnt == Math.floor(mnt)) ? mnt + '.00'
 : ( (mnt*10 == Math.floor(mnt*10)) ?
 mnt + '0' : mnt);
};

function setActiveButton(thenav, pagematch){

 $("."+thenav).each(function (i) {
 var thebut = $(this);
 var theclasses = thebut.attr('class').split(" ");

 if(theclasses[1] == pagematch){
 thebut.removeClass(pagematch+"-On");
 thebut.addClass(pagematch+"-On");
 }

 if(theclasses[1].indexOf("-On") >= 0){
 var normalclass = theclasses[1].split("-");
 thebut.removeClass(theclasses[1]);
 thebut.addClass(normalclass[0]);
 }

 }
 );
};

function setshipBox(){
 var sb = $('#ship-code');
 var sm = $('#ship-method');

 if($('#ship-required').attr("checked")){
 sm.removeAttr("disabled");
 sb.removeAttr("disabled");
 }else{
 sm.attr("disabled","disabled");
 sb.attr("disabled","disabled");
 }

};

function setPrice(abox){

 var b = $(abox);
 var inputqty = b.val();
 var theid = b.attr('id').split("-");
 theid = theid[1];
 var pricelabel = $("#pricelabel-"+theid);

 if(prices[theid].length > 0){
 pricelabel.html(findPrice(inputqty,theid));
 }

}

function findPrice(theqty, theid){
 var discount;
 if(prices[theid].length == 1){
 return prices[theid][0].price;
 }else{
 for(var i = 0; i < prices[theid].length; i++){
 discount = prices[theid][i];
 if(parseInt(theqty) <= parseInt(discount.qty)){
 return discount.price;
 break;
 }
 }

 return prices[theid][prices[theid].length-1].price;
 }

 return null;
};

function showShipping(){
 $(".ifshipping").show();
};

function hideShipping(){
 $(".ifshipping").hide();
 ashipping = 0;
 $('#postalzip').val("") ;
 updatePrices();
};

function updatePrices(loc){
 //alert(aprice);
 $('#vc-subtotal').html("$"+formatAsMoney(aprice));
 updateSubTotals();
 var final_price = 0;
 /*if(thesubpage == "viewcart" && loc === undefined){

 }else if(thesubpage == "viewcart" && loc === 'shipping'){
 }*/
 if(!isNaN(ashipping)){
 $('#sp-total').html("$"+formatAsMoney(ashipping));
 final_price = parseFloat(aprice)+parseFloat(ashipping)
 }else{
 $('#sp-total').html(ashipping);
 final_price = parseFloat(aprice);
 }
 
 $('#shipgt-total-hidden').val(formatAsMoney(final_price));
 $('#shipgt-total').html("$"+formatAsMoney(final_price));
};

function updateSubTotals(){
 $(".cart-qty").each(function (i) {
 var sel = $(this);
 var theid = sel.attr('id').split("-");
 theid = theid[1];
 var theqty = $("#qty-"+theid).val();
 var cost = formatAsMoney(theqty * prices[theid]);
 $("#vc-st-"+theid).html(cost);
 });
};

function submitForm(theform){
 $('#'+theform).submit();
};

function showOverlay(themess){
 $.prompt(themess ,{opacity: 0.6})
};

function showCart(){
 var scriptdir = "/showCart/";
 var id = "";
 $.post(scriptdir,
 {'pid' : id},
 function(data){
 alert(data);
 }
 );

};

function addItem(prodname, id, price, aqty, displayOverlay){
 if(displayOverlay === undefined){
 displayOverlay = true;
 }

 var theqty;
 if(aqty === undefined){
 theqty = $('#qty-'+id).val();
 }else{
 theqty = aqty;
 }

 var scriptdir = "/products/addtocart/";
 var theprice = (price == '') ? findPrice(theqty, id) : price;

 //alert("id: " + id + " - price: " + theprice + " - qty " + theqty);

 if(displayOverlay)
 showOverlay("Successfully Added "+ theqty + "' "+ prodname + "' at $"+ theprice+"/unit to your cart");
 //showOverlay("Successfully Added '" + prodname + "' to your cart");
 $.post(scriptdir,
 {'pid' : id,'price' : theprice,'qty' : theqty},
 function(data){
 //alert(data);
 var numitems = updateCartDisplay(data,"add");
 }
 );

};

function removeItem(id){
 var scriptdir = "/products/removefromcart/";

 $.post(scriptdir,
 {'pid' : id},
 function(data){
 //alert(data);
 $('#prodrow-'+id).remove();
 var numitems = updateCartDisplay(data,"remove");
 if(numitems <= 0){
 /*$('#subtotal').hide();
 $('#pay-data').hide();
 $('#form1').hide();*/
 $('#shipping-container').hide();
 $('#updatecartlink').hide();
 aprice = 0;
 ashipping = 0;
 updatePrices();
 }
 }
 );

};

function updateCart(refreshc){
 var scriptdir = "/products/updatecart/";
 var theid, theqty, range;
 var aId = [];
 var aQty = [];
 var noerr = true;


 $(".cart-qty").each(function (i) {
 theid = $(this).attr("id").split("-");
 range = $(this).attr("class").split(" ");
 range = range[1];
 //alert(range);
 theid = parseInt(theid[1]);
 $(this).val(jQuery.trim($(this).val()))
 theqty = $(this).val();


 if(isInteger(theqty)){
 if(1){
 //if(isValidAmount(range, theqty)){
 aId.push(theid);
 aQty.push(theqty);
 //alert(theid[1] + " - " + $(this).val());
 if(theqty <= 0){
 removeItem(theid);
 }
 }else{
 noerr = false;
 $(this).focus();
 return false;
 }
 }else{
 alert("Please select a valid Number in the Quantity Field");
 noerr = false;
 }
 });

 //alert(aId.toString() + " - " + aQty.toString());
 if(noerr){
 $.post(scriptdir,
 {'ids': aId.toString(), 'qtys' : aQty.toString()},
 function(data){ 
 
 if(refreshc !== undefined){
 window.location = sitebase+"products/refreshcart/"
 }else{
 updateCartDisplay(data,"clear");
 updatePrices();
 }
 
 }
 );
 return true;
 }else{
 return false;
 }

};


function isValidAmount(therange, theval){
 if(therange.indexOf("-") >= 0){
 var minmax = therange.split("-");
 var aval = parseInt(theval);
 var themin = parseInt(minmax[0]);
 var themax = parseInt(minmax[1]);


 if(isNaN(themax) || themax == 0){

 if(aval >= themin){
 return true;
 }else{
 alert("Please Enter a Number of at least "+ themin + " in the Quantity Field");
 return false;
 }


 }else{
 if(aval >= themin && aval <= themax){
 return true;
 }else{
 alert("Please Enter a Number between "+ minmax[0] + " and " + minmax[1] + " in the Quantity Field");
 return false;
 }
 }

 }

 return true;

};

function clearCart(){
 var scriptdir = "/products/clearcart/";

 $.post(scriptdir,
 {},
 function(data){
 updateCartDisplay(data,"clear");
 }
 );

};

function validPostalZip(s){
 var val = s.toUpperCase();
 var re = new RegExp(/\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\b/);
 var re_zip = new RegExp(/\b[0-9]{5}\b/); 
 return (re.exec(val) || re_zip.exec(val));
}

function validPostalCode(s){
 s = s.toUpperCase();
 var re = new RegExp(/\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\b/);
 return re.exec(s);
};

function isInteger(s) {
 return (s.toString().search(/^-?[0-9]+$/) == 0);
};

function isFloat(s)
{
 var n = jQuery.trim(s);
 return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
};

function updateCartDisplay(data, theaction){
 var pieces = data.split(':');
 if(pieces.length >0){
 $('#cart-quantity').html(pieces[0]);
 $('#cart-total').html('$' + pieces[1]);
 aprice = pieces[1];
 //alert(aprice);
 updatePrices();
 }else{
 alert("Error: "+ data);
 }
 return pieces[0];
};

var clearedboxes = [];
function clearBox(abox){
 if(clearedboxes[abox.id] === undefined){
 abox.value = "";
 clearedboxes[abox.id] = true;
 }
};

/*************************
QUICK QUOTE CHECKOUT
**************************/


var qq_step = 1;
var qq_step_max = 3;
var shiprequired = 1;


function proceedQuickQuote(){
 qq_step++;
 shiprequired = $("input[name='shipping']:checked").val();
 if(qq_step > qq_step_max){
 qq_step = qq_step_max;
 submitForm('form-qq');
 return;
 }

 $('#qq-step-'+(qq_step-1)).hide();

 if(qq_step > 1){
 $('#previous-link').show();
 }
 
 if(qq_step == qq_step_max){

 //if there is an error don't advance
 if(!qqShipping()){
 qq_step--;
 $('#qq-step-'+(qq_step)).show();
 return;
 }else{

 
 
 $('#shipping-timeline').show();
 
 
 }
 }else if(qq_step == 2){
 qqClearCartandAdd(shiprequired);
 $('#shipping-timeline').hide();
 }
 
 //don't display the frame if shipping not required, since ajax call will show frame
 //after successful call
 if(!(shiprequired == 0 && qq_step == 2))
 $('#qq-step-'+qq_step).fadeIn(800); 
};

function previousQuickQuote(){
 qq_step--;
 shiprequired = $("input[name='shipping']:checked").val();
 
 if(qq_step < 1){
 qq_step = 1;
 return;
 }

 $('#qq-step-'+(qq_step+1)).hide();
 
 if((qq_step == 2) && shiprequired == 0){
 qq_step = 1;
 }

 if(qq_step == 1){
 $('#previous-link').hide();
 }

 //always hide the timeline
 $('#shipping-timeline').hide();

 $('#qq-step-'+qq_step).fadeIn(600);

};

function qqClearCartandAdd(shiprequired){
 var scriptdir = "/products/clearcart/";

 $.post(scriptdir,
 {},
 function(data){
 updateCartDisplay(data,"clear");
 var prodsubid = $('#qq-pid').val();
 var prodname = $('#qq-pid :selected').text()
 var qty = $('#qq-qty').val();
 addItem(prodname, prodsubid, '', qty, false);

 if(shiprequired == 0){
 gatherQQInfo();
 qqCheckout();
 qq_step++;
 $('#qq-step-'+qq_step).fadeIn(800);
 }


 }
 );

};

var qq_shipcost = 0;
var prodname, theqty, prodsubid, maxdays, shipname, proddays;

function gatherQQInfo(){
 prodsubid = $('#qq-pid').val();
 prodname = $("#qq-pid :selected").text();
 shipname = $("#servicelevelid :selected").text();
 prodsubid = 1; //treat all products as one (temporary measure)
 theqty = $('#qq-qty').val();
}

function clearShipping(){
 $('#qq-3-shipping-time').html("");
 $('#qq-3-shipping').html("");
 $('#qq-3-order').html("");
 $('#sp-total-hidden').val("");
 $('#need-shipping').val("");
 $('#postalzip').val("");
 $('#hshipping-method-id').val("");
 $('#hshipping-method').val("");
}

function qqShipping(){
 clearShipping();
 var scriptdir = "/products/calcshipping/";
 gatherQQInfo();
 var t = $('#servicelevelid').val().split("-");
 var service = t[0];
 maxdays = t[1];
 var postal = $('#postalcode').val();
 $('#qq-step-3').block({
 message: '<img src="/_img/busy-red.gif" alt="busy" class="left" /><div style="float: left; margin: 2px 0px 0px 0px;"> &nbsp; Calculating Shipping</div>',
 css: { 
 border: '1px solid #a00', 
 padding: '5px',
 margin: '10px', 
 color: '#666', 
 width: '170px'
 }
 }); 

 if(!validPostalZip(postal.toUpperCase())){
 alert("Please enter a valid Postal/Zip Code");
 return false;
 }else{

 //alert($('#qq-pid').val() + " - " +prodname)
 var shiprequired = $("input[name='shipping']:checked").val();

 $.post(scriptdir,
 {'qty' : theqty,'id': $('#qq-pid').val(),'service' : service,'postal' : postal, 'prodsubid' : prodsubid,'shiprequired' : shiprequired,'shipname': shipname},
 function(data){
 $('#qq-step-3').unblock();
 $("#debug").html(data);
 var pieces = data.split('|');
 qq_shipcost = pieces[0];
 
 if(!isNaN(qq_shipcost)){
 $('#qq-3-shipping').html("$"+formatAsMoney(pieces[0]) + " (" + shipname + ")");
 }else{ 
 $('#sp-specialorder').val("1");
 $('#qq-3-shipping').html(pieces[0]);
 }
 $('#qq-3-order').html(theqty + " - " + prodname);
 $('#sp-total-hidden').val(pieces[0]);
 $('#need-shipping').val(shiprequired);
 $('#postalzip').val(postal);
 $('#hshipping-method-id').val(service);
 $('#hshipping-method').val(pieces[1]);
 proddays = pieces[4];
 //$('#qq-3-shipping-time').html(shipname);
 
 var param = [proddays,maxdays];
 param =param.join("/");
 //alert(sitebase+"shipping_timeline/"+param);
 var callink = sitebase+"shipping_timeline/"+param;
 $('#st-link').attr('href',callink);
 $('#hst-link').val(param);
 

 qqCheckout();
 //$('#checkout-shipmethodid').val(pieces[2]);
 /*aship = pieces[0];
 updatePrices("shipping");
 $('#form1').show();*/
 }
 );
 return true;
 }

};

function qqCheckout(){
 var scriptdir = "/checkoutCartQQ/";

 $.post(scriptdir,
 {},
 function(data){
 //alert(data);
 //$("#debug").html(data);
 //msgresponse(data,"message-err","","message-success","",callbackqqCheckout);
 data = JSON.parse(data);
 callbackqqCheckout(data);
 }
 );

};

function callbackqqCheckout(data){
 var cost = 0;
 jQuery.each(data.payload, function(i, val) {
 //alert(i + " - " + val.price);
 cost += (val.price*val.qty)
 });
 qq_shipcost = (shiprequired == 1) ? qq_shipcost : 0; 
 var final_cost = 0;
 if(!isNaN(qq_shipcost))
 final_cost = parseFloat(cost) + parseFloat(qq_shipcost);
 else
 final_cost = parseFloat(cost);
 $('#qq-3-subtotal').html("$" + formatAsMoney(cost));
 $('#qq-3-total').html("$" + formatAsMoney(final_cost) + " (Plus Tax)"); 

 if(shiprequired == 0){
 $('#qq-3-shipping').html("N/A");
 $('#qq-3-order').html(theqty + " - " + prodname);
 }else{
 $('#shipgt-total-hidden').val(formatAsMoney(final_cost));
 }



};

/*************************
VIEW CART
**************************/

function showDisclaimer(){
 var sl = $('#servicelevelid :selected').val();
 var theid = sl.split("-");
 theid = theid[0];

 if(theid < 3){
 $('#sd-1').hide();
 $('#sd-36').fadeIn();
 }else{
 $('#sd-1').fadeIn();
 $('#sd-36').hide();
 }
 
}

function countQtys(){
 var q = 0;
 $(".cart-qty").each(function (i) {
 var sel = $(this);
 var theid = sel.attr('id').split("-");
 theid = theid[1];
 var theqty = $("#qty-"+theid).val();
 q += parseInt(theqty);
 });
 return q;
}

function calcShipping(){
 var scriptdir = "/products/calcshipping/";
 var shipname = $("#servicelevelid :selected").text();
 var t = $('#servicelevelid').val().split("-");
 var service = t[0];
 maxdays = t[1];
 var postal = $('#postalzip').val();

 if(!validPostalZip(postal.toUpperCase())){
 alert("Please enter a valid Postal/Zip Code");
 return false;
 }else{
 var qty = countQtys();
 
 $('#shipping-selection-right').block({
 message: '<img src="/_img/busy-red.gif" alt="busy" class="left" /><div style="float: left; margin: 2px 0px 0px 0px;"> &nbsp; Calculating Shipping</div>',
 css: { 
 border: '1px solid #a00', 
 'font-weight': 'bold',
 padding: '5px', 
 color: '#666', 
 width: '170px'
 }
 }); 

 $.post(scriptdir,
 
 {'qty' : qty,'id': prodsubid,'service' : service,'postal' : postal, 'shiprequired' : shiprequired,'shipname': shipname},
 function(data){
 //alert(data);
 $('#shipping-selection-right').unblock();
 shippingcalculated = true;
 var pieces = data.split('|');
 ashipping = pieces[0];
 if(!isNaN(pieces[0])){
 qq_shipcost = pieces[0];
 $('#sp-total').html("$"+pieces[0]);
 $('#sp-total-hidden').val(pieces[0]);
 }else{
 $('#sp-specialorder').val("1");
 }
 updatePrices("shipping");
 $('#hshipping-method').val($('#servicelevelid :selected').text());
 $('#hshipping-method-id').val(service);

 $('#ss-type').html("("+shipname+")");
 $('#ss-name').html(pieces[1]);
 

 var day_length = pieces[4];
 var param = [day_length,maxdays];
 param =param.join("/");
 $('#hst-link').val(param);
 $('#st-container-checkout').fadeIn("slow");
 $('#st-link').attr('href',sitebase+"shipping_timeline/"+param);
 

 }
 );
 return true;
 }

};

function submitShipping(theform){
 var shipping = $("input[name='need-shipping']:checked").val();
 var pc = jQuery.trim($('#postalzip').val()).toUpperCase();

 if(shipping == 1){

 if(!validPostalZip(pc)){
 alert("Please Enter a valid Postal Code/Zip for Shipping Information");
 $('#postalzip').focus();
 return;
 }

 if(!shippingcalculated){
 alert("Please press the Calculate Shipping Button to confirm/calculate the Shipping Cost");
 $('#postalzip').focus();
 return;
 }

 }

 $('#'+theform).submit();

};

/*************************
ARTWORK
**************************/
var passed = true;
var uploading = false;

function artworkAdd(id, afile, ext){ 
 passed = true;
 
 if (! (ext && /^(pdf|psd|ai|eps|tiff)$/.test(ext))){
 alert('Error: invalid file extension. Please upload only PDFs, AIs, EPSs, PSDs or TIFFs');
 if(!uploading)
 passed = false;
 return false;
 }


 if(uploading){
 alert("Please Wait Till All Files are Uploaded");
 return false;
 }

 
 if(filesuploaded[id] === undefined){
 filesuploaded[id] = [];
 filesuploaded[id]['[-filecount-]'] = 0;
 filesuploaded[id]['[-intemplate-]'] = [];
 }


 if(filesuploaded[id][afile] === undefined || filesuploaded[id][afile] == null){
 $('#busy-'+id).show();
 uploading = true;
 filesuploaded_num++;
 filesuploaded[id]['[-intemplate-]'][filesuploaded[id]['[-filecount-]']] = 1;
 filesuploaded[id]['[-filecount-]']++; 
 filesuploaded[id][afile] = [];

 if(filesuploaded.length > 0){
 $('#cg-text-'+id).hide();
 }

 /*$('.cg-button').block({
 message: '<h1>Uploading: '+afile+"."+ext+'</h1>',
 css: { border: '3px solid #c00' }
 });*/
 }else{
 alert("Please Select a Different Template File");
 passed = false;
 return false;
 }

};

function artworkRemove(id, index, afile){

 filesuploaded_num--;
 filesuploaded[id]['[-filecount-]']--;
 filesuploaded[id][afile] = null;
 
 var ok = "input[@name=intemplate-"+id+"-"+index+"]:checked";
 var ischecked = $(ok).val();
 if(ischecked == 0){
 removeTemplateCharge(id, index, afile);
 }
 
 
 $('#file-row-'+id+"-"+index).remove();

 if(filesuploaded[id]['[-filecount-]'] == 0){
 $('#cg-text-'+id).show();
 }
 
 var scriptdir = "/removeTemplateItem/"+id+"/"+index;
 $.post(scriptdir,
 {afile : afile},
 function(data){
 //alert(data);
 }
 );

};

function artworkComplete(id, afile, response){

 if(passed){
 uploading = false;
 $('#busy-'+id).hide();
 //$('.cg-button').unblock();
 var fv = $('#fileview-'+id);
 var index = filesuploaded[id]['[-filecount-]']-1;

 var html = '<tr id="file-row-'+id+"-"+index+'" class="file-row"><td class="filename fr-cell"><img src="/_img/icon-file.gif" alt="File icon" class="left" /><div class="left">&nbsp; '+afile+'</div></td><!-- td class="quantity fr-cell"><select><option>Quantity</option></select></td --><td class="template fr-cell"><input onclick="removeTemplateCharge('+id+','+index+')" checked="checked" type="radio" name="intemplate-'+id+"-"+index+'" value="1" />&nbsp; Yes &nbsp;&nbsp;&nbsp;<input onclick="addTemplateCharge('+id+','+index+')" type="radio" name="intemplate-'+id+"-"+index+'" id="charge-'+id+"-"+index+'" value="0" />&nbsp; No<p>($10.00 charge if artwork is not in <a target="_blank" href="/templates/">template</a>)</p></td><td class="remove fr-cell"><a href="javascript:void(0)" onclick="artworkRemove('+id+',\''+index+'\',\''+afile+'\')">Remove</a></td></tr>';
 //fv.fadeIn();
 fv.append(html);
 }


};

function artworkError(id, afile, response){
 alert("Could Not Upload " + afile + ". Please try again.");
};

function addTemplateCharge(id, index){
 if(filesuploaded[id]['[-intemplate-]'][index] == 1){
 filesuploaded[id]['[-intemplate-]'][index] = 0;
 modifyCharges(template_charge);
 
 var scriptdir = "/modifyTemplate/"+id+"/"+index+"/0";
 $.post(scriptdir,
 {},
 function(data){

 }
 );
 
 }
};

function removeTemplateCharge(id, index, del){

 if(filesuploaded[id]['[-intemplate-]'][index] == 0){
 filesuploaded[id]['[-intemplate-]'][index] = 1;
 modifyCharges(template_charge*-1);
 if(del === undefined)
 var scriptdir = "/modifyTemplate/"+id+"/"+index+"/1";
 else
 var scriptdir = "/removeTemplateItem/"+id+"/"+index;
 
 $.post(scriptdir,
 {'afile' : del},
 function(data){
 //alert("hi; "+ data);
 }
 );
 }
};

function modifyCharges(charge){
 charge = parseFloat(charge);
 totals_grand = parseFloat(totals_grand)+ charge;
 totals_template =+ parseFloat(totals_template) + charge;
 
 var final_grand = formatAsMoney(totals_grand);
 var final_templates = formatAsMoney(totals_template);
 
 $('#total-grand').html("$"+final_grand);
 $('#htotal-grand').val(final_grand);
 $('#total-templates').html("$"+final_templates);
 $('#htotal-templates').val(final_templates);

};

/*************************
SUMMARY
**************************/
var same = false;
function copyShipping(theform, copyfields, prefix){ 
 same = (!same) ? true : false;
 
 $("."+copyfields).each(function (i) {
 var sel = $(this);
 var theid = sel.attr('id');
 var theval = (!same) ? "" : sel.val();
 $('#'+prefix+theid).val(theval);
 });
 $("#"+theform).validate().form(); 
};

function submitSummary(){
 var res = $("#form-summary").validate().form(); 
 if(res){
 submitForm('form-summary');
 }else{
 
 }
};



/*
 * This script is written by Geert Van Aken
 * Please read the official documentation for more information
 * about the functions of this file.
 *
 * http://altum.be/products/emailobfuscator
 *
 * Please do not remove this information from the file and
 * report improvements that you make to this sourcecode
 *
 * Version 1.1.0
 * Date 2006/04/11
 */

var monkeyCode = 4 << 4;
var oldStatusText = "";

function EOa() {
 return String.fromCharCode(monkeyCode);
}

function EOd(pText) {
 var splitted = pText.split(",");
 var result = "";

 for (i = 0 ; i < splitted.length ; i++) {
 result += String.fromCharCode(splitted[i]);
 }
 return result;
}

function EOp() {
 var prefix = EOd('109,97,105');
 prefix += EOd('108,116');
 return prefix + EOd('111,58');
}

function EOad(pName, pdomain) {
 EOad(pName, pDomain, null);
}

function EOinitStatus(pName, pDomain) {
 oldStatusText = window.status;
 window.status = Loc(pName, pDomain);
}

function EOrestoreStatus() {
 window.status = oldStatusText;
}

function EOae(pName, pDomain, pSubj, pHover, pText, pClass) {

// alert("pName = " + pName + "\npDomain = " + pDomain + "\npSubj = " + pSubj + "\npHover = " + pHover + "\npText = " + pText + "\npClass = " + pClass);

 var result = "<a href=\"JavaScript:EOad('" + pName + "','" + pDomain + "'";
 if (pSubj != null && pSubj.length > 2) {
 result += ",'" + pSubj + "'";
 }
 result += ");\"";

 if (pHover != null && pHover.length > 0) {
 result += " title=\"" + EOd(pHover) + "\"";
 }

 if (pClass != null && pClass.length > 0) {
 result += " class=\"" + pClass + "\"";
 }

 result += " onMouseOver=\"EOinitStatus('" + pName + "','" + pDomain + "');return true;\" onMouseOut=\"EOrestoreStatus();\"";

 result += ">" + EOd(pText) + "</a>";

// alert(result);

 document.write(result);

}

function EOad(pName, pDomain, pSubj) {
 var loc = Loc(pName, pDomain);
 if (pSubj != null && pSubj.length > 0) {
 loc += "?" + EOd('115,117,98,106,101,99,116') + "=" + encodeURIComponent(EOd(pSubj));
 }

 document.location = loc;
}

function Loc(pName, pDomain) {
 var first = EOd(pName);
 var second = EOd(pDomain);
 var loc = EOp() + first + EOa() + second; 
 
 return loc;
}

/*
------------------------------------------------------
Common JS Functions
------------------------------------------------------
*/

$().ready(function() {

if(jQuery.validator !== undefined){
 
 jQuery.validator.addMethod("nospaces", function(value) {
 if(jQuery.trim(value) == ""){
 return true;
 }else{
 return (value.indexOf(" ") >= 0) ? false : true;
 }
 }, "Please enter a value without spaces");

 jQuery.validator.addMethod("nospecialchars", function(s) {
 if(jQuery.trim(s) == ""){
 return true;
 }else{

 var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~`";
 for (var i = 0; i < s.length; i++) {
 if (iChars.indexOf(s.charAt(i)) != -1) {
 return false;
 }
 }
 return true;

 }
 }, "Please enter a value without special characters.");

 jQuery.validator.addMethod("nospecialcharsbutcomma", function(s) {
 if(jQuery.trim(s) == ""){
 return true;
 }else{

 var iChars = "!@#$%^&*()+=-[]\\\';./{}|\":<>?~`";
 for (var i = 0; i < s.length; i++) {
 if (iChars.indexOf(s.charAt(i)) != -1) {
 return false;
 }
 }
 return true;

 }
 }, "Please enter a value without special characters.");

 jQuery.validator.addMethod("postalzipcode", function(value) {
 if(jQuery.trim(value) == ""){
 return true;
 }else{
 var val = value.toUpperCase();
 var re = new RegExp(/\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\b/);
 var re_zip = new RegExp(/\b[0-9]{5}\b/);
 
 return (re.exec(val) || re_zip.exec(val));
 }
 }, "Please enter a valid Postal or Zip Code");

 jQuery.validator.addMethod("postalcode", function(value) {
 if(jQuery.trim(value) == ""){
 return true;
 }else{
 var re = new RegExp(/\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\b/);
 return re.exec(value.toUpperCase());
 }
 }, "Please enter a valid Postal Code");

 jQuery.validator.addMethod("phone", function(value) {
 /* Make the Phone # Optional - Only validate when value is present */
 if(jQuery.trim(value) == ""){
 return true;
 }else{
 var re = new RegExp(/\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b/);
 return re.exec(value.toUpperCase());
 }
 }, "Please enter a valid Phone Number");


 jQuery.validator.addMethod("creditcard", function(value) {
 if(jQuery.trim(value) == ""){
 return true;
 }else{
 var re = new RegExp(/^^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13}|(?:2131|1800)\d{11})$/);
 return re.exec(value.toUpperCase());
 }
 }, "Please enter a valid Credit Card Number");


}


//end ready
});

try {
 document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


function msgresponse(data, thediv, erroraction, successdiv, anaction, callback){

 //alert(callback);
 
 if (typeof anaction == "undefined") {
 anaction = "";
 }
 
 if (typeof erroraction == "undefined") {
 erroraction = "";
 }
 
 if (typeof callback != "function") {
 callback = false;
 }

 var displaydiv = null;
 var mess = "";
 var theaction = null;
 try{
 data = JSON.parse(data);

 if(data.err != ''){
 mess = data.err;
 if(typeof(mess) != "string"){
 mess = formatErrs(mess);
 }
 displaydiv = thediv;
 theaction = erroraction;

 }else{
 mess = data.msg;
 displaydiv = successdiv;
 theaction = anaction;
 }

 if(theaction == ""){
 //clearMessages();
 $('#'+displaydiv).html(mess);
 }else if(theaction == "redirect"){
 window.location = mess;
 }else if(theaction == "debug"){
 alert(mess);
 }
 

 if(callback != false){
 callback(data);
 }


 }catch(err){
 var txt = err + "\n\n";
 txt += data;
 alert(txt);
 }
 
};


function errorresponse(xhr, status, e){
 alert("Error: Could not Submit Form. Please try again.");
}

function formatErrs(anarr){
 var str = "<ul>";
 for(var i = 0; i < anarr.length; i++){
 str += '<li>'+anarr[i]+'</li>';
 } 
 str += "</ul>";
 
 return str;
}

/*
------------------------------------------------------
Utility JS Functions
------------------------------------------------------
*/

function showarray(arrname){
 var arr = eval(arrname);
 for(var i =0; i< arr.length; i++){
 alert(arr[i]);
 }
}

function removeWhitespace(s){
 return s.replace(/\s+/g,'');
}

function findItem(s, arr, task){
 for(var i=0; i< arr.length; i++){
 if(s==arr[i]){

 if(task == "remove"){
 arr.splice(i, 1);
 }

 return true;
 }
 }

 return false;
}

function isInteger(s) {
 return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function isFloat(s)
{
 var n = jQuery.trim(s);
 return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
 window.open(theURL,winName,features);
}

function submitForm(theform){
 $('#'+theform).submit();
}

function resetForm(theform){
 $('#'+theform)[0].reset();
}

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 * http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s($){3.1s.1k=s(j){j=3.1a({12:\'1m.1j\'},j);8 k=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 5.5")!=-1);8 l=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 6.0")!=-1);o(3.17.16&&(k||l)){3(2).L("1r[@m$=.M]").z(s(){3(2).7(\'q\',3(2).q());3(2).7(\'p\',3(2).p());8 a=\'\';8 b=\'\';8 c=(3(2).7(\'K\'))?\'K="\'+3(2).7(\'K\')+\'" \':\'\';8 d=(3(2).7(\'A\'))?\'A="\'+3(2).7(\'A\')+\'" \':\'\';8 e=(3(2).7(\'C\'))?\'C="\'+3(2).7(\'C\')+\'" \':\'\';8 f=(3(2).7(\'B\'))?\'B="\'+3(2).7(\'B\')+\'" \':\'\';8 g=(3(2).7(\'R\'))?\'1d:\'+3(2).7(\'R\')+\';\':\'\';8 h=(3(2).1c().7(\'1b\'))?\'19:18;\':\'\';o(2.9.y){a+=\'y:\'+2.9.y+\';\';2.9.y=\'\'}o(2.9.t){a+=\'t:\'+2.9.t+\';\';2.9.t=\'\'}o(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}8 i=(2.9.15);b+=\'<x \'+c+d+e+f;b+=\'9="13:11;1q-1p:1o-1n;O:W-V;N:1l;\'+g+h;b+=\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\';b+=\'J:I:H.r.G\'+\'(m=\\\'\'+3(2).7(\'m\')+\'\\\', D=\\\'F\\\');\';b+=i+\'"></x>\';o(a!=\'\'){b=\'<x 9="13:11;O:W-V;\'+a+h+\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\'+\'">\'+b+\'</x>\'}3(2).1i();3(2).1h(b)});3(2).L("*").z(s(){8 a=3(2).T(\'N-S\');o(a.E(".M")!=-1){8 b=a.X(\'1g("\')[1].X(\'")\')[0];3(2).T(\'N-S\',\'1f\');3(2).Q(0).Y.J="I:H.r.G(m=\'"+b+"\',D=\'F\')"}});3(2).L("1e[@m$=.M]").z(s(){8 a=3(2).7(\'m\');3(2).Q(0).Y.J=\'I:H.r.G\'+\'(m=\\\'\'+a+\'\\\', D=\\\'F\\\');\';3(2).7(\'m\',j.12)})}1t 3}})(3);',62,92,'||this|jQuery||||attr|var|style|||||||||||||src|navigator|if|height|width|Microsoft|function|padding|px|appVersion|margin|span|border|each|class|alt|title|sizingMethod|indexOf|scale|AlphaImageLoader|DXImageTransform|progid|filter|id|find|png|background|display|appName|get|align|image|css|parseInt|block|inline|split|runtimeStyle|Explorer|Internet|relative|blankgif|position|MSIE|cssText|msie|browser|hand|cursor|extend|href|parent|float|input|none|url|after|hide|gif|pngFix|transparent|blank|line|pre|space|white|img|fn|return'.split('|'),0,{}))

/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
 Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
 This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();

/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 *
 * Examples at http://famspam.com/facebox/
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 *
 * Usage:
 * 
 * jQuery(document).ready(function() {
 * jQuery('a[rel*=facebox]').facebox() 
 * })
 *
 * <a href="#terms" rel="facebox">Terms</a>
 * Loads the #terms div in the box
 *
 * <a href="terms.html" rel="facebox">Terms</a>
 * Loads the terms.html page in the box
 *
 * <a href="terms.png" rel="facebox">Terms</a>
 * Loads the terms.png image in the box
 *
 *
 * You can also use it programmatically:
 * 
 * jQuery.facebox('some html')
 * jQuery.facebox('some html', 'my-groovy-style')
 *
 * The above will open a facebox with "some html" as the content.
 * 
 * jQuery.facebox(function($) { 
 * $.get('blah.html', function(data) { $.facebox(data) })
 * })
 *
 * The above will show a loading screen before the passed function is called,
 * allowing for a better ajaxy experience.
 *
 * The facebox function can also display an ajax page, an image, or the contents of a div:
 * 
 * jQuery.facebox({ ajax: 'remote.html' })
 * jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')
 * jQuery.facebox({ image: 'stairs.jpg' })
 * jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')
 * jQuery.facebox({ div: '#box' })
 * jQuery.facebox({ div: '#box' }, 'my-groovy-style')
 *
 * Want to close the facebox? Trigger the 'close.facebox' document event:
 *
 * jQuery(document).trigger('close.facebox')
 *
 * Facebox also has a bunch of other hooks:
 *
 * loading.facebox
 * beforeReveal.facebox
 * reveal.facebox (aliased as 'afterReveal.facebox')
 * init.facebox
 *
 * Simply bind a function to any of these hooks:
 *
 * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
 *
 */
(function($) {
 $.facebox = function(data, klass) {
 $.facebox.loading()

 if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
 else if (data.image) fillFaceboxFromImage(data.image, klass)
 else if (data.div) fillFaceboxFromHref(data.div, klass)
 else if ($.isFunction(data)) data.call($)
 else $.facebox.reveal(data, klass)
 }

 /*
 * Public, $.facebox methods
 */

 $.extend($.facebox, {
 settings: {
 opacity : 0.3,
 overlay : true,
 loadingImage : '/_img/facebox/loading.gif',
 closeImage : '/_img/facebox/closelabel.gif',
 imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],
 faceboxHtml : '\
 <div id="facebox" style="display:none;"> \
 <div class="popup"> \
 <table id="main-table"> \
 <tbody> \
 <tr> \
 <td class="tl"/><td class="b"/><td class="tr"/> \
 </tr> \
 <tr> \
 <td class="b"/> \
 <td class="body"> \
 <div class="content"> \
 </div> \
 <div class="footer"> \
 <a href="#" class="close"> \
 <img src="/facebox/closelabel.gif" title="close" class="close_image" /> \
 </a> \
 </div> \
 </td> \
 <td class="b"/> \
 </tr> \
 <tr> \
 <td class="bl"/><td class="b"/><td class="br"/> \
 </tr> \
 </tbody> \
 </table> \
 </div> \
 </div>'
 },

 loading: function() {
 init()
 if ($('#facebox .loading').length == 1) return true
 showOverlay()

 $('#facebox .content').empty()
 $('#facebox .body').children().hide().end().
 append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')

 $('#facebox').css({
 top: getPageScroll()[1] + (getPageHeight() / 10),
 left: $(window).width() / 2 - 205 
 }).show()

 $(document).bind('keydown.facebox', function(e) {
 if (e.keyCode == 27) $.facebox.close()
 return true
 })
 $(document).trigger('loading.facebox')
 },

 reveal: function(data, klass) {
 $(document).trigger('beforeReveal.facebox')
 if (klass) $('#facebox .content').addClass(klass)
 $('#facebox .content').append(data)
 $('#facebox .loading').remove()
 $('#facebox .body').children().fadeIn('normal')
 $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
 $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
 },

 close: function() {
 $(document).trigger('close.facebox')
 return false
 }
 })

 /*
 * Public, $.fn methods
 */

 $.fn.facebox = function(settings) {
 init(settings)

 function clickHandler() {
 $.facebox.loading(true)

 // support for rel="facebox.inline_popup" syntax, to add a class
 // also supports deprecated "facebox[.inline_popup]" syntax
 var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
 if (klass) klass = klass[1]

 fillFaceboxFromHref(this.href, klass)
 return false
 }

 return this.bind('click.facebox', clickHandler)
 }

 /*
 * Private methods
 */

 // called one time to setup facebox on this page
 function init(settings) {
 if ($.facebox.settings.inited) return true
 else $.facebox.settings.inited = true

 $(document).trigger('init.facebox')
 makeCompatible()

 var imageTypes = $.facebox.settings.imageTypes.join('|')
 $.facebox.settings.imageTypesRegexp = new RegExp('\.(' + imageTypes + ')$', 'i')

 if (settings) $.extend($.facebox.settings, settings)
 $('body').append($.facebox.settings.faceboxHtml)

 var preload = [ new Image(), new Image() ]
 preload[0].src = $.facebox.settings.closeImage
 preload[1].src = $.facebox.settings.loadingImage

 $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
 preload.push(new Image())
 preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
 })

 $('#facebox .close').click($.facebox.close)
 $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
 }
 
 // getPageScroll() by quirksmode.com
 function getPageScroll() {
 var xScroll, yScroll;
 if (self.pageYOffset) {
 yScroll = self.pageYOffset;
 xScroll = self.pageXOffset;
 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
 yScroll = document.documentElement.scrollTop;
 xScroll = document.documentElement.scrollLeft;
 } else if (document.body) {// all other Explorers
 yScroll = document.body.scrollTop;
 xScroll = document.body.scrollLeft; 
 }
 return new Array(xScroll,yScroll) 
 }

 // Adapted from getPageSize() by quirksmode.com
 function getPageHeight() {
 var windowHeight
 if (self.innerHeight) { // all except Explorer
 windowHeight = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
 windowHeight = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
 windowHeight = document.body.clientHeight;
 } 
 return windowHeight
 }

 // Backwards compatibility
 function makeCompatible() {
 var $s = $.facebox.settings

 $s.loadingImage = $s.loading_image || $s.loadingImage
 $s.closeImage = $s.close_image || $s.closeImage
 $s.imageTypes = $s.image_types || $s.imageTypes
 $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
 }

 // Figures out what you want to display and displays it
 // formats are:
 // div: #id
 // image: blah.extension
 // ajax: anything else
 function fillFaceboxFromHref(href, klass) {
 // div
 if (href.match(/#/)) {
 var url = window.location.href.split('#')[0]
 var target = href.replace(url,'')
 $.facebox.reveal($(target).show().replaceWith("<div id='facebox_moved'></div>"), klass)

 // image
 } else if (href.match($.facebox.settings.imageTypesRegexp)) {
 fillFaceboxFromImage(href, klass)
 // ajax
 } else {
 fillFaceboxFromAjax(href, klass)
 }
 }

 function fillFaceboxFromImage(href, klass) {
 var image = new Image()
 image.onload = function() {
 $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
 }
 image.src = href
 }

 function fillFaceboxFromAjax(href, klass) {
 $.get(href, function(data) { $.facebox.reveal(data, klass) })
 }

 function skipOverlay() {
 return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 
 }

 function showOverlay() {
 if (skipOverlay()) return

 if ($('#facebox_overlay').length == 0) 
 $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

 $('#facebox_overlay').hide().addClass("facebox_overlayBG")
 .css('opacity', $.facebox.settings.opacity)
 .click(function() { $(document).trigger('close.facebox') })
 .fadeIn(200)
 return false
 }

 function hideOverlay() {
 if (skipOverlay()) return

 $('#facebox_overlay').fadeOut(200, function(){
 $("#facebox_overlay").removeClass("facebox_overlayBG")
 $("#facebox_overlay").addClass("facebox_hide") 
 $("#facebox_overlay").remove()
 })
 
 return false
 }

 /*
 * Bindings
 */

 $(document).bind('close.facebox', function() {
 $(document).unbind('keydown.facebox')
 $('#facebox').fadeOut(function() {
 if ($('#facebox_moved').length == 0) $('#facebox .content').removeClass().addClass('content')
 else $('#facebox_moved').replaceWith($('#facebox .content').children().hide())
 hideOverlay()
 $('#facebox .loading').remove()
 })
 })

})(jQuery);


/* jQMinMax v0.1 - Copyright (c) 2006 Dave Cardwell (http://davecardwell.co.uk/)
 Released under the MIT License (http://www.opensource.org/licenses/mit-license.php) */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('u m(){$.5={D:y,v:y};$(G).12(m(){8 h=G.W(\'I\');$(h).e({\'3\':\'J\',\'6-3\':\'K\'});$(\'L\').M(h);$.5.v=(h.s&&h.s==2);$(h).N();b($.5.v)o;$.5.D=O;$.5.A();$(\':5\').5()});$.5.A=m(){8 p=u E(\'6-3\',\'6-4\',\'9-3\',\'9-4\');8 5=u E();Q(8 i=0;i<p.R;i++){8 n="$.e(a,\'"+p[i]+"\')!=\'S\'&&"+"$.e(a,\'"+p[i]+"\')!=\'z\'&&"+"$.e(a,\'"+p[i]+"\')!=f.g";b(p[i].U(2)==\'x\')n+="&&$.e(a,\'"+p[i]+"\')!=\'X\'";$.n[\':\'][p[i]]=n;5[i]=\'(\'+n+\')\'}$.n[\':\'][\'5\']=5.Y(\'||\')};$.Z.5=m(){o $(c).10(m(){8 7={\'6-3\':r(c,\'6-3\'),\'9-3\':r(c,\'9-3\'),\'6-4\':r(c,\'6-4\'),\'9-4\':r(c,\'9-4\')};8 3=c.s;8 4=c.w;8 k=3;8 l=4;b(7[\'9-3\']!=f.g&&k>7[\'9-3\'])k=7[\'9-3\'];b(7[\'6-3\']!=f.g&&k<7[\'6-3\'])k=7[\'6-3\'];b(7[\'9-4\']!=f.g&&l>7[\'9-4\'])l=7[\'9-4\'];b(7[\'6-4\']!=f.g&&l<7[\'6-4\'])l=7[\'6-4\'];b(k!=3)$(c).e(\'3\',k);b(l!=4)$(c).e(\'4\',l)})};m r(t,p){8 q=$(t).e(p);b(q==f.g||q==\'z\')o f.g;8 j;j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)%$/);b(j){o T.V(C((/3$/.h(p)?$(t).F().H(0).s:$(t).F().H(0).w)*j[1]/P))}j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)(?:11)?$/);b(j){o C(j[1])}o f.g}}();',62,65,'|||width|height|minmax|min|constraint|var|max||if|this||css|window|undefined|test||result|newWidth|newHeight|function|expr|return||raw|calculate|offsetWidth|obj|new|native|offsetHeight||false|auto|expressions|match|Number|active|Array|parent|document|get|div|1px|2px|body|append|remove|true|100|for|length|0px|Math|charAt|round|createElement|none|join|fn|each|px|ready'.split('|'),0,{}))
