/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
function popWin(url,win,para) {
    var win = window.open(url,win,para);
    win.focus();
}

function setLocation(url){
    window.location.href = url;
}

function setPLocation(url, setFocus){
    if( setFocus ) {
        window.opener.focus();
    }
    window.opener.location.href = url;
}

function setLanguageCode(code, fromCode){
    //TODO: javascript cookies have different domain and path than php cookies
    var href = window.location.href;
    var after = '', dash;
    if (dash = href.match(/\#(.*)$/)) {
        href = href.replace(/\#(.*)$/, '');
        after = dash[0];
    }

    if (href.match(/[?]/)) {
        var re = /([?&]store=)[a-z0-9_]*/;
        if (href.match(re)) {
            href = href.replace(re, '$1'+code);
        } else {
            href += '&store='+code;
        }

        var re = /([?&]from_store=)[a-z0-9_]*/;
        if (href.match(re)) {
            href = href.replace(re, '');
        }
    } else {
        href += '?store='+code;
    }
    if (typeof(fromCode) != 'undefined') {
        href += '&from_store='+fromCode;
    }
    href += after;

    setLocation(href);
}

/**
 * Add classes to specified elements.
 * Supported classes are: 'odd', 'even', 'first', 'last'
 *
 * @param elements - array of elements to be decorated
 * [@param decorateParams] - array of classes to be set. If omitted, all available will be used
 */
function decorateGeneric(elements, decorateParams)
{
    var allSupportedParams = ['odd', 'even', 'first', 'last'];
    var _decorateParams = {};
    var total = elements.length;

    if (total) {
        // determine params called
        if (typeof(decorateParams) == 'undefined') {
            decorateParams = allSupportedParams;
        }
        if (!decorateParams.length) {
            return;
        }
        for (var k in allSupportedParams) {
            _decorateParams[allSupportedParams[k]] = false;
        }
        for (var k in decorateParams) {
            _decorateParams[decorateParams[k]] = true;
        }

        // decorate elements
        // elements[0].addClassName('first'); // will cause bug in IE (#5587)
        if (_decorateParams.first) {
            Element.addClassName(elements[0], 'first');
        }
        if (_decorateParams.last) {
            Element.addClassName(elements[total-1], 'last');
        }
        for (var i = 0; i < total; i++) {
            if ((i + 1) % 2 == 0) {
                if (_decorateParams.even) {
                    Element.addClassName(elements[i], 'even');
                }
            }
            else {
                if (_decorateParams.odd) {
                    Element.addClassName(elements[i], 'odd');
                }
            }
        }
    }
}

/**
 * Decorate table rows and cells, tbody etc
 * @see decorateGeneric()
 */
function decorateTable(table, options) {
    var table = $(table);
    if (table) {
        // set default options
        var _options = {
            'tbody'    : false,
            'tbody tr' : ['odd', 'even', 'first', 'last'],
            'thead tr' : ['first', 'last'],
            'tfoot tr' : ['first', 'last'],
            'tr td'    : ['last']
        };
        // overload options
        if (typeof(options) != 'undefined') {
            for (var k in options) {
                _options[k] = options[k];
            }
        }
        // decorate
        if (_options['tbody']) {
            decorateGeneric(table.select('tbody'), _options['tbody']);
        }
        if (_options['tbody tr']) {
            decorateGeneric(table.select('tbody tr'), _options['tbody tr']);
        }
        if (_options['thead tr']) {
            decorateGeneric(table.select('thead tr'), _options['thead tr']);
        }
        if (_options['tfoot tr']) {
            decorateGeneric(table.select('tfoot tr'), _options['tfoot tr']);
        }
        if (_options['tr td']) {
            var allRows = table.select('tr');
            if (allRows.length) {
                for (var i = 0; i < allRows.length; i++) {
                    decorateGeneric(allRows[i].getElementsByTagName('TD'), _options['tr td']);
                }
            }
        }
    }
}

/**
 * Set "odd", "even" and "last" CSS classes for list items
 * @see decorateGeneric()
 */
function decorateList(list, nonRecursive) {
    if ($(list)) {
        if (typeof(nonRecursive) == 'undefined') {
            var items = $(list).select('li')
        }
        else {
            var items = $(list).childElements();
        }
        decorateGeneric(items, ['odd', 'even', 'last']);
    }
}

/**
 * Set "odd", "even" and "last" CSS classes for list items
 * @see decorateGeneric()
 */
function decorateDataList(list) {
    list = $(list);
    if (list) {
        decorateGeneric(list.select('dt'), ['odd', 'even', 'last']);
        decorateGeneric(list.select('dd'), ['odd', 'even', 'last']);
    }
}

/**
 * Formats currency using patern
 * format - JSON (pattern, decimal, decimalsDelimeter, groupsDelimeter)
 * showPlus - true (always show '+'or '-'),
 *      false (never show '-' even if number is negative)
 *      null (show '-' if number is negative)
 */

function formatCurrency(price, format, showPlus){
    precision = isNaN(format.precision = Math.abs(format.precision)) ? 2 : format.precision;
    requiredPrecision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision;

    //precision = (precision > requiredPrecision) ? precision : requiredPrecision;
    //for now we don't need this difference so precision is requiredPrecision
    precision = requiredPrecision;

    integerRequired = isNaN(format.integerRequired = Math.abs(format.integerRequired)) ? 1 : format.integerRequired;

    decimalSymbol = format.decimalSymbol == undefined ? "," : format.decimalSymbol;
    groupSymbol = format.groupSymbol == undefined ? "." : format.groupSymbol;
    groupLength = format.groupLength == undefined ? 3 : format.groupLength;

    if (showPlus == undefined || showPlus == true) {
        s = price < 0 ? "-" : ( showPlus ? "+" : "");
    } else if (showPlus == false) {
        s = '';
    }

    i = parseInt(price = Math.abs(+price || 0).toFixed(precision)) + "";
    pad = (i.length < integerRequired) ? (integerRequired - i.length) : 0;
    while (pad) { i = '0' + i; pad--; }

    j = (j = i.length) > groupLength ? j % groupLength : 0;
    re = new RegExp("(\\d{" + groupLength + "})(?=\\d)", "g");

    /**
     * replace(/-/, 0) is only for fixing Safari bug which appears
     * when Math.abs(0).toFixed() executed on "0" number.
     * Result is "0.-0" :(
     */
    r = (j ? i.substr(0, j) + groupSymbol : "") + i.substr(j).replace(re, "$1" + groupSymbol) + (precision ? decimalSymbol + Math.abs(price - i).toFixed(precision).replace(/-/, 0).slice(2) : "")

    if (format.pattern.indexOf('{sign}') == -1) {
        pattern = s + format.pattern;
    } else {
        pattern = format.pattern.replace('{sign}', s);
    }

    return pattern.replace('%s', r).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};

function expandDetails(el, childClass) {
    if (Element.hasClassName(el,'show-details')) {
        $$(childClass).each(function(item){item.hide()});
        Element.removeClassName(el,'show-details');
    }
    else {
        $$(childClass).each(function(item){item.show()});
        Element.addClassName(el,'show-details');
    }
}

// Version 1.0
var isIE = navigator.appVersion.match(/MSIE/) == "MSIE";

if (!window.Varien)
    var Varien = new Object();

Varien.showLoading = function(){
    Element.show('loading-process');
}
Varien.hideLoading = function(){
    Element.hide('loading-process');
}
Varien.GlobalHandlers = {
    onCreate: function() {
        Varien.showLoading();
    },

    onComplete: function() {
        if(Ajax.activeRequestCount == 0) {
            Varien.hideLoading();
        }
    }
};

Ajax.Responders.register(Varien.GlobalHandlers);

/**
 * Quick Search form client model
 */
Varien.searchForm = Class.create();
Varien.searchForm.prototype = {
    initialize : function(form, field, emptyText){
        this.form   = $(form);
        this.field  = $(field);
        this.emptyText = emptyText;

        Event.observe(this.form,  'submit', this.submit.bind(this));
        Event.observe(this.field, 'focus', this.focus.bind(this));
        Event.observe(this.field, 'blur', this.blur.bind(this));
        this.blur();
    },

    submit : function(event){
		
		/******feb9 2012*****************/
			
        if (this.field.value == 'birthday cakes' || this.field.value == 'birthday' || this.field.value == 'birthday cake' || this.field.value == ' kids birthday cakes' || this.field.value == '50th birthday cake'){
			
			window.location.href = 'http://www.wetakethecake.com/birthdays.html';
            Event.stop(event);
            return false;
        }
			/***********************/
		
		/******september8*****************/
			
			 if (this.field.value == 'birthday caked' || this.field.value == 'birthday caked 21'  || this.field.value == '21'  || this.field.value == '21 birthday cake'  || this.field.value == '21st'  || this.field.value == '50th birthday cakes'  || this.field.value == 'Birthdats'   || this.field.value == 'Birthdat' || this.field.value == 'birthdY'   || this.field.value == 'cheesecake'
		  || this.field.value == 'anniversary cakes' || this.field.value == 'blueberry' || this.field.value == 'coconut' || this.field.value == 'bannana' || this.field.value == 'burnt almond' || this.field.value == 'carmel'  || this.field.value == 'cheescake' 
		  || this.field.value == 'Decorated birthday cakes' || this.field.value == 'pies' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/birthdays.html';
		
         Event.stop(event);
            return false;
        }
		
		 if (this.field.value == 'Sale' || this.field.value == 'sales'  || this.field.value == 'discount'  || this.field.value == 'discounts'  || this.field.value == 'coupon'  || this.field.value == 'coupons'  || this.field.value == 'code'   || this.field.value == 'codes' || this.field.value == 'special'   || this.field.value == 'specials')
		 {
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/sales.html';
		
         Event.stop(event);
            return false;
        }
		
		  if (this.field.value == 'contest' || this.field.value == 'contests'){
		
		
		window.location.href = 'http://www.wetakethecake.com/sweepstakes';
		
         Event.stop(event);
            return false;
        }
		
		
		
			/*************************************/
		
		
		
		
		
		
		
		
		
        if (this.field.value == this.emptyText || this.field.value == ''){
			
			window.location.href = 'http://www.wetakethecake.com/all-products.html';
            Event.stop(event);
            return false;
        }
		
		
		    if (this.field.value =='cost of shipping' || this.field.value == 'shipping rates' || this.field.value =='shipping costs'){
		
		
		window.location.href = 'http://www.wetakethecake.com/shipping-policy';
		
         Event.stop(event);
            return false;
        }
		
		  if (this.field.value == 'sweepstakes' || this.field.value == 'sweepstake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/sweepstakes';
		
         Event.stop(event);
            return false;
        }
		
			
		
			/******august17*****************/
			
			  if (this.field.value == 'birthday' || this.field.value == 'birthdays'){
		
		
		window.location.href = 'http://www.wetakethecake.com/all-products.html';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value == 'tropcal' || this.field.value == 'pina colada' || this.field.value == 'tahitian'){
		
		
		window.location.href = 'http://www.wetakethecake.com/productsearch/?id=2';
		
         Event.stop(event);
            return false;
        }
		  if (this.field.value == 'samples'){
		
		
		window.location.href = 'http://www.wetakethecake.com/productsearch/?id=1';
		
         Event.stop(event);
            return false;
        }
		
		
		
				  if (this.field.value =='lemon layer cake' || this.field.value =='seven layer cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/layer-cakes.html';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value =='directions' || this.field.value =='International' || this.field.value =='job' || this.field.value =='location' || this.field.value =='employment'){
		
		
		window.location.href = 'http://www.wetakethecake.com/contacts';
		
         Event.stop(event);
            return false;
        }
			  if (this.field.value =='cup of joe'){
		
		
		window.location.href = 'http://www.wetakethecake.com/in-store-only/starbucks-coffee.html';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value =='"via"'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+VIA+';
		
         Event.stop(event);
            return false;
        }
		
		 if (this.field.value =='orange chocolate'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/result/?q=orange&x=0&y=0';
		
         Event.stop(event);
            return false;
        }
		
		 if (this.field.value =='strawbery cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/fresh-strawberry-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
		 if (this.field.value == 'bridal' || this.field.value == 'weddings'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/result/?q=wedding&x=0&y=0';
		
         Event.stop(event);
            return false;
        }
		
		  if (this.field.value == 'strawbery cake' || this.field.value == 'strabbery cake'  || this.field.value == 'strawbbery cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/fresh-strawberry-cake.html';
		
         Event.stop(event);
            return false;
        }
		/*********************************/
		
		
		
		
		
		/******august16*****************/
		
		  if (this.field.value == 'birthday' || this.field.value == 'birthdays'){
		
		
		window.location.href = 'http://www.wetakethecake.com/all-products.html';
		
         Event.stop(event);
            return false;
        }
		/*********************************/
	/**********august12****************/
	
	
	  if (this.field.value == 'columbia' || this.field.value == 'columbian' || this.field.value == 'via columbia' || this.field.value == 'via columbian' || this.field.value == 'colombia' || this.field.value == 'colombian' || this.field.value == 'via colombia' || this.field.value == 'via colombian'
	  || this.field.value == 'columbA' || this.field.value == 'columbia]' || this.field.value == 'columbina'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+VIA+Colombia+-+Instant+Coffee+';
		
         Event.stop(event);
            return false;
        }
		
		
		
	  if (this.field.value == 'italia' || this.field.value == 'italian' || this.field.value == 'via italia' || this.field.value == 'via italian' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+VIA+Italian+-+Instant+Coffee+';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value == 'house' || this.field.value == 'house blend coffee' || this.field.value == 'house blend' || this.field.value == 'house coffee' || this.field.value == 'house coffee' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+Coffee+House+Blend+';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value == 'caffe' || this.field.value == 'verona' || this.field.value == 'caffee verona' || this.field.value == 'verona coffee' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+Caff%C3%A8+Verona+';
		
         Event.stop(event);
            return false;
        }
		
		
		
		
		  if (this.field.value =='via'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/advanced/result/?name=Starbucks+VIA+';
		
         Event.stop(event);
            return false;
        }
		
		/********august4*/
		
				  if (this.field.value =='kosher bundt cakes'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes.html';
		
         Event.stop(event);
            return false;
        }
		 
		
	
		
		
		
			  if (this.field.value == 'prices'  || this.field.value == "father's day"  || this.field.value == "father's day cake"  || this.field.value == 'fathers' 
			  || this.field.value == 'fathers day cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/all-products.html';
		
         Event.stop(event);
            return false;
        }
		
		
		
		  if (this.field.value =='cake of the month club' || this.field.value == 'Cake of the month'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/banana-chocolate-bundt.html';
		
         Event.stop(event);
            return false;
        }
		
		
			/*****************************************************************/
		
		
		
		
		
						  if (this.field.value =='Birthday cupcakes' || this.field.value =='cupcake flavors'){
		
		
		window.location.href = 'http://www.wetakethecake.com/cupcakes.html';
		
         Event.stop(event);
            return false;
        }
		
		
		
				  if (this.field.value =='egg less' || this.field.value =='eggless'){
		
		
		window.location.href = 'http://www.wetakethecake.com/vegan-chocolate-layer-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
		
		
		
		
		
		
				  if (this.field.value =='costom cakes'){
		
		
		window.location.href = 'http://www.wetakethecake.com/in-store-only.html';
		
         Event.stop(event);
            return false;
        }
		
		
			  if (this.field.value =='19.95'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/mothers-butter-cake.html';
		
         Event.stop(event);
            return false;
        }
			  if (this.field.value =='cake of the month club' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/mothers-butter-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value =='triple chocolate chip fudge cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/triple-chocolate-chip-fudge-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
		  if (this.field.value =='hello kitty cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/result/?q=hello+kitty&x=0&y=0';
		
         Event.stop(event);
            return false;
        }
		
		
		
		  if (this.field.value =='hello kitty cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/result/?q=hello+kitty&x=0&y=0';
		
         Event.stop(event);
            return false;
        }
		
		
		
		  if (this.field.value =='prize wininning chocolate cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/layer-cakes/chocolate-layer-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
				  if (this.field.value =='Cake of the month'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/mothers-butter-cake.html';
		
         Event.stop(event);
            return false;
        }
		
				  if (this.field.value == 'rum cake'){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/caribbean-rum-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		  if (this.field.value == 'weddingcakes'){
		
		
		window.location.href = 'http://www.wetakethecake.com/catalogsearch/result/?q=wedding&x=0&y=0';
		
         Event.stop(event);
            return false;
        }
		
		
		
		  if (this.field.value == 'key lime cake recipes' || this.field.value =='Key lime pie'  || this.field.value =='key lime recipes'  || this.field.value =='KEYLIME'  || this.field.value =='KEYLIMECAKE' ){
		
		
		window.location.href = 'http://www.wetakethecake.com/bundt-cakes/key-lime-bundt-cake.html';
		
         Event.stop(event);
            return false;
        }
		
		
			  if (this.field.value == 'corporate' || this.field.value == 'corporate gift'  || this.field.value == 'corporate gifts'  || this.field.value == 'corporate gift cake'  || this.field.value == 'corporate gift cakes'  || this.field.value == 'corporate program'  || this.field.value == 'corporate gift program'  || this.field.value == 'corporate gifts program'){
		
		
		window.location.href = 'http://www.wetakethecake.com/corporate-gift-cakes.html';
		
         Event.stop(event);
            return false;
        }
		
		
		
				  if (this.field.value == 'fathers day cake' || this.field.value == 'fathers day cakes'  || this.field.value == 'graduate'  || this.field.value == 'graduation'  || this.field.value == 'kid'  || this.field.value == 'kosher'  || this.field.value == 'speacialty cakes'  || this.field.value == 'the collection'  || this.field.value == 'kosher bundt cakes'  || this.field.value == 'the collection'){
		
		
		window.location.href = 'http://www.wetakethecake.com/all-products.html';
		
         Event.stop(event);
            return false;
        }
        return true;
    },

    focus : function(event){
        if(this.field.value==this.emptyText){
            this.field.value='';
        }

    },

    blur : function(event){
        if(this.field.value==''){
            this.field.value=this.emptyText;
        }
    },

    initAutocomplete : function(url, destinationElement){
        new Ajax.Autocompleter(
            this.field,
            destinationElement,
            url,
            {
                paramName: this.field.name,
                minChars: 2,
                updateElement: this._selectAutocompleteItem.bind(this),
                onShow : function(element, update) { 
                    if(!update.style.position || update.style.position=='absolute') {
                        update.style.position = 'absolute';
                        Position.clone(element, update, {
                            setHeight: false, 
                            offsetTop: element.offsetHeight
                        });
                    }
                    Effect.Appear(update,{duration:0});
                }

            }
        );
    },

    _selectAutocompleteItem : function(element){
        if(element.title){
            this.field.value = element.title;
        }
        this.form.submit();
    }
}

Varien.Tabs = Class.create();
Varien.Tabs.prototype = {
  initialize: function(selector) {
    var self=this;
    $$(selector+' a').each(this.initTab.bind(this));
  },

  initTab: function(el) {
      el.href = 'javascript:void(0)';
      if ($(el.parentNode).hasClassName('active')) {
        this.showContent(el);
      }
      el.observe('click', this.showContent.bind(this, el));
  },

  showContent: function(a) {
    var li = $(a.parentNode), ul = $(li.parentNode);
    ul.getElementsBySelector('li', 'ol').each(function(el){
      var contents = $(el.id+'_contents');
      if (el==li) {
        el.addClassName('active');
        contents.show();
      } else {
        el.removeClassName('active');
        contents.hide();
      }
    });
  }
}

Varien.DOB = Class.create();
Varien.DOB.prototype = {
    initialize: function(selector, required, format) {
        var el        = $$(selector)[0];
        this.day      = Element.select($(el), '.dob-day input')[0];
        this.month    = Element.select($(el), '.dob-month input')[0];
        this.year     = Element.select($(el), '.dob-year input')[0];
        this.dob      = Element.select($(el), '.dob-full input')[0];
        this.advice   = Element.select($(el), '.validation-advice')[0];
        this.required = required;
        this.format   = format;

        this.day.validate = this.validate.bind(this);
        this.month.validate = this.validate.bind(this);
        this.year.validate = this.validate.bind(this);

        this.advice.hide();
    },

    validate: function() {
        var error = false;

        if (this.day.value=='' && this.month.value=='' && this.year.value=='') {
            if (this.required) {
                error = 'This date is a required value.';
            } else {
                this.dob.value = '';
            }
        } else if (this.day.value=='' || this.month.value=='' || this.year.value=='') {
            error = 'Please enter a valid full date.';
        } else {
            var date = new Date();
            if (this.day.value<1 || this.day.value>31) {
                error = 'Please enter a valid day (1-31).';
            } else if (this.month.value<1 || this.month.value>12) {
                error = 'Please enter a valid month (1-12).';
            } else if (this.year.value<1900 || this.year.value>date.getFullYear()) {
                error = 'Please enter a valid year (1900-'+date.getFullYear()+').';
            } else {
                this.dob.value = this.format.replace(/(%m|%b)/i, this.month.value).replace(/(%d|%e)/i, this.day.value).replace(/%y/i, this.year.value);
                var testDOB = this.month.value + '/' + this.day.value + '/'+ this.year.value;
                var test = new Date(testDOB);
                if (isNaN(test)) {
                    error = 'Please enter a valid date.';
                }
            }
        }

        if (error !== false) {
            try {
                this.advice.innerHTML = Translator.translate(error);
            }
            catch (e) {
                this.advice.innerHTML = error;
            }
            this.advice.show();
            return false;
        }

        this.advice.hide();
        return true;
    }
}

Validation.addAllThese([
    ['validate-custom', ' ', function(v,elm) {
        return elm.validate();
    }]
]);

function truncateOptions() {
    $$('.truncated').each(function(element){
        Event.observe(element, 'mouseover', function(){
            if (element.down('div.truncated_full_value')) {
                element.down('div.truncated_full_value').addClassName('show')
            }
        });
        Event.observe(element, 'mouseout', function(){
            if (element.down('div.truncated_full_value')) {
                element.down('div.truncated_full_value').removeClassName('show')
            }
        });

    });
}
Event.observe(window, 'load', function(){
   truncateOptions();
});
