<!-- Script pour Fenetre pop-up-->
<!-- Begin
function Start(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=600,height=500");
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// End -->

(function($) {
	$(function() {
	/*  --------------------------------------------------------------
		Complete navigation popup ------------------------------------ */
		$('#li_departments > a').click(function () {$('#fullnav').show().focus(); return false;});
		$('#li_departments').hoverIntent({
			over: function() {
				
				if ($('#fullnav').css('display') == "none")
					$('#fullnav').slideDown(200).focus();
			},
			out: function () {$('#fullnav').hide();},
			timeout: 100,
			sensitivity: 12
		});
		$('#footer .redundant a.fullnavToggler').click(function () {
			$('#fullnav').show().focus();
			window.scrollTo(0, 0);
			return false;
		});
		$('#fullnav a.b_close').click(function () {$('#fullnav').hide(); return false;});
		
	/*  --------------------------------------------------------------
		Handle "Notify Me" Form -------------------------------------- */
		$('#frm_notify').submit( function (event) {
			var email = $('#notify_email').val()
			var product_code = $('#product_code').val()
			var url = $(this).attr('action');
			
			$('label', this).removeClass('error');
			$('label span', this).remove();
			if (email == '') {$('label', this).addClass('error').append('<span>: please enter an email.</span>'); return false;}
			if (!validateEmail(email)) { $('label', this).addClass('error').append('<span>: please enter a valid email.</span>'); return false;}

			$.post(url, {email: email,product_code: product_code}, function (resp) {
				$('#notify_popup').remove();
				$popup = createPopup();
				$popup.append('<h1>Thanks</h1><p>You will be notified as soon as your product is back in stock.</p>');
			});
			return false;
		});
	/*  --------------------------------------------------------------
		Handle "Sign Up for Specials" Form --------------------------- */	
         /* 
		$('#frm_signup').submit( function (event) {
			var $self = $(this);
			var email = $('#email_address').val()
			var url = $(this).attr('action');
			
			$('label', this).removeClass('error');
			$('label span', this).remove();
			if (email == '') {$('label', this).addClass('error').append('<span>: please enter an email.</span>'); return false;}
			if (!validateEmail(email)) { $('label', this).addClass('error').append('<span>: please enter a valid email.</span>'); return false;}

			$.post(url, {email: email}, function (resp) {
				$('div', $self).remove();
				$self.append('<div><p>Thank you for signing up to our newsletter. We will keep you informed about our future specials.</p></div>');
			});
			return false;
		});
           */	
	/*  --------------------------------------------------------------
	    Handle generic | no-ajax forms ------------------------------- */
		$('#frm_search').submit( function (event) {
			if ($('#search').val().length < 2) {
				$('#search').animate({opacity: "show"}, 1000);
				return false;
			}
		});
	
	
	/*  --------------------------------------------------------------
		Confirm Purchase Page ---------------------------------------- */	
		$('#form3 a[@href="#guarantee"]').click(function () {
			$content = $('#guarantee');
			$popup = createPopup();
			$popup.append($content);
			return false;
		});
		
		/*  --------------------------------------------------------------
		Event Main Page ---------------------------------------- */	
		$('#frm_event a[@href="#guarantee"]').click(function () {
			$content = $('<strong>Event Date Guarantee</strong><br>When an event date is entered on this page we will insure that your order is not delivered after your event. If the event date is too soon for ground shipping a representative will contact you with alternate service levels. Only guaranteed or confirmed orders are shipped when the event date is entered. Orders are typically shipped within 2 business days. A confirmation email is sent when orders are shipped. If the event date field is left empty we will process your order within the normal timeline (up to 1 week) and ship it.</p>');
			$popup = createPopup();
			$popup.append($content);
			return false;
		});
	
	/*  --------------------------------------------------------------
		Process Payment Page ----------------------------------------- */
		if ($("#PINdesc").size() == 1) {
			$("#PINdesc").append('<br /><a href="javascript:void();" />Where can I find my security code?</a>');
			$("#PINdesc a").click( function () {
				$popup = createPopup();
				expl  = '<h1>Security Code</h1>';
				expl += '<p>The card security code is a three or four digit security code imprinted on credit cards to help merchants verify that the customer has a legitimate card in hand at the time of the order.</p>';
				expl += '<p>The merchant asks the customer for the security code and then sends it to the card issuer as part of the authorization request. The card issuer checks the security code to determine its validity, then sends a result back to the merchant along with the authorization.</p>';
				expl += '<p>Please refer to the images below to locate your security code.</p>';
				expl += '<table cellspacing="0"><tr><td width="180"><strong>For American Express</strong></td><td><strong>For Visa and Mastercard<strong></td></tr></table>';
				expl += '<img src="/images/cvv_big.gif" alt="" />';
				$popup.append(expl);
				return false;
			});
		}
	});

/*  --------------------------------------------------------------
	Generic function for popup generation ------------------------
	Return a jQuery wrapper -------------------------------------- */
	function createPopup() {
		if ($('#popup').size() == 1) {
			$('#popup .wrapper').empty();
		} else {
			$popup = $('<div id="popup"><div class="wrapper"></div><div class="popup-footer"></div><a href="javascript:closePopup();" class="b_close">Close <span>X</span></a></div>');
			$('#container').append($popup);
		}
		if (!document.documentElement.scrollTop)
			scrollY = document.body.scrollTop;
		else scrollY = document.documentElement.scrollTop;
		$('#popup').css('top', scrollY+278+'px').show();
		return $('#popup .wrapper');
	}
})(jQuery);



function closePopup() {
	jQuery('#popup').hide();
}

function validateEmail (value) {
	var reEmail = /^(?:\w+(?:[-.+]?\w+)*@\w+(?:[\.-]?\w+)*\.(?:\w{2,4}|museum))?$/;
	return reEmail.test(value);
}
