/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*  
 * This will replace the "Search" text in the search box when the 
 * user clicks it - will replace with search when nothing is 
 * entered - and will not clear the box if anything other
 * than "Search" is the value of the input box.
 * 
 */
jQuery(document).ready(function(){
    jQuery("#search_input")
			.focus(function () {
        if(jQuery(this).val() == this.defaultValue){
          jQuery(this).val('');
        }
			})
			.blur(function () {
        if(jQuery(this).val() == ""){
            jQuery(this).val(this.defaultValue);
        }
			})
		;
 });
jQuery.noConflict();

/**
 * sets focus to the first field when loaded, and triggers
 *   the link with the id defaultSubmit when enter is pressed
 */
function formEventInit(formId, firstFieldId) {
	Event.observe(window, 'load', function() {
			$(formId+':'+firstFieldId).focus();
			Event.observe(formId, 'keypress', function(event) {
					if (Event.KEY_RETURN == event.keyCode)
						$(this.id+':defaultSubmit').onclick();
				}
			);
		}
	);
}

/**
 * Js for adding to the cart without a page reload/redirect
 *  looks for '.addToCartActions a' for links
 *  and the rich:toolTip 'toolTip' in the a4j:form 'cartAddDialog'
 */
Event.observe(window, 'load', function() {
		if($('cartAddDialog:toolTip')) {
			jQuery(".addToCartActions a").click(function(event) {
					var tip = $('cartAddDialog:toolTip').component;
					tip.toolTipContent.innerHTML = "Adding...";
					tip.show(event);
					clearTimeout(tip.timeout);
					new Ajax.Request(this+'&ajax=1', { method:'get',
							onSuccess: function(transport, json){
								$('cartLink').innerHTML = 'View Cart ('+json.cartSize+(json.cartSize!=1 ? ' Items)' : ' Item)');
								tip.toolTipContent.innerHTML = "Added to Cart.<p class='note'>(scroll down to checkout)</p>";
								tip.timeout = setTimeout("$('cartAddDialog:toolTip').component.hide({});", 3500);
							},
							onFailure: function() {
								alert("Could not add to cart, please try again later or disable javascript.");
							}
						}
					);
					return false;
				}
			);
		}
	}
);

function verifyAddress(el) {
        if(el.value.indexOf('@') != -1) {
                alert("Make sure that the address you just entered is a street address.");
        }
}