$(document).ready(function() {
    //Sets observers to hide/show the FAQ items.  Hides the answers
    //assuming javascript is enabled.
    $('.faq-list .faq-answer').hide();

    openClose = document.createElement('SPAN');
    openClose.className = 'open-close';
    openClose.innerHTML = '(+)';

    $(openClose).insertBefore('.faq-list .faq-question span');

    $('.faq-list .faq-question span').click(function() {
        faqQ = $(this).parent();
        faqA = $(faqQ).next();
        faqI = $(faqQ).parent();
        faqO = $(faqQ).children('span.open-close');

        if ($(faqI).hasClass('active')) {

            $(faqI).removeClass('active');
            $(faqA).hide('slow');
            $(faqO).html('(+)');
        }
        else {
            $('.faq-item.active .faq-answer').hide('slow');
            $('.faq-item.active .open-close').html('(+)');
            $('.faq-item.active').removeClass('active');
            $(faqI).addClass('active');
            $(faqO).html('(&ndash;)');
            $(faqA).show('slow');
            // $(faqA).scrollTo();
        }
    });

    // Hide the stage-one .disabled overlay by default -DN
    if ($('.cart-box').length != 0) {
        $('.cart-box .stage-one .disabled').hide();
    }

    $('#ctl00_BodyContentPlaceHolder_wzdCheckout_passwordRepeatRequiredFieldValidator').live('load', function() {
        console.log("I'm loaded");
    });
	
	var tbOverlay;
	if((tbOverlay = $('#TB_overlay') ).length != 0  ) {
		
		$('body').append(tbOverlay);

		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		  $("body","html").css({height: "100%", width: "100%"});
		  $("html").css("overflow","hidden");
		  if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			tbOverlay.before("<iframe id='TB_HideSelect'></iframe>");
		  }
		}
		
		if(tb_detectMacXFF()){
		  tbOverlay.addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
		  tbOverlay.addClass("TB_overlayBG");//use background and opacity
		}
	}
	
});


function popup(url)
{
	window.open(url,'','width=480,height=360,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	return false;
}

// Turns on/off disabled panels in shoppingCart.aspx takes one argument (the stage to enable [one, two, or three])
function enableStage(stage, language)
{
    if (language == '1033' || language == '')
    {	
	    switch(stage)
	    {
		    case 'one' || 1:
			    $('.cart-box .stage-one input').attr('disabled', '');
			    $('.cart-box .stage-two input, .cart-box .stage-two select, .cart-box .stage-three input').attr('disabled', 'true');
			    $('.cart-box .stage-one .disabled').hide();
			    $('.cart-box .stage-two .disabled').show();
   			    $('.cart-box .stage-three .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(in progress)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(pending)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(pending)');
   			    break;
       			
   		    case 'two' || 2:
   			    $('.cart-box .stage-two input, .cart-box .stage-two select').attr('disabled', '');
   			    $('.cart-box .stage-one input, .cart-box .stage-three input').attr('disabled', 'true');
   			    $('.cart-box .stage-two .disabled').hide();
   			    $('.cart-box .stage-one .disabled').show();
   			    $('.cart-box .stage-three .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(completed)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(in progress)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(pending)');
   			    break;
       			
   		    case 'three' || 3:
   			    $('.cart-box .stage-three input, .cart-box .stage-three select').attr('disabled', '');
   			    $('.cart-box .stage-one input, .cart-box .stage-one select, .cart-box .stage-two input, .cart-box .stage-two select').attr('disabled', 'true');
   			    $('.cart-box .stage-three .disabled').hide();
   			    $('.cart-box .stage-one .disabled').show();
   			    $('.cart-box .stage-two .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(completed)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(completed)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(in progress)');
   			    break;
	    }
	}
	else
	{
	    switch(stage)
	    {
		    case 'one' || 1:
			    $('.cart-box .stage-one input').attr('disabled', '');
			    $('.cart-box .stage-two input, .cart-box .stage-two select, .cart-box .stage-three input').attr('disabled', 'true');
			    $('.cart-box .stage-one .disabled').hide();
			    $('.cart-box .stage-two .disabled').show();
   			    $('.cart-box .stage-three .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(en progreso)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(pendiente)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(pendiente)');
   			    break;
       			
   		    case 'two' || 2:
   			    $('.cart-box .stage-two input, .cart-box .stage-two select').attr('disabled', '');
   			    $('.cart-box .stage-one input, .cart-box .stage-three input').attr('disabled', 'true');
   			    $('.cart-box .stage-two .disabled').hide();
   			    $('.cart-box .stage-one .disabled').show();
   			    $('.cart-box .stage-three .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(terminado)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(en progreso)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(pendiente)');
   			    break;
       			
   		    case 'three' || 3:
   			    $('.cart-box .stage-three input, .cart-box .stage-three select').attr('disabled', '');
   			    $('.cart-box .stage-one input, .cart-box .stage-one select, .cart-box .stage-two input, .cart-box .stage-two select').attr('disabled', 'true');
   			    $('.cart-box .stage-three .disabled').hide();
   			    $('.cart-box .stage-one .disabled').show();
   			    $('.cart-box .stage-two .disabled').show();
   			    $('.cart-wrap .cart-box-top .stage-one .status').html('(terminado)');
   			    $('.cart-wrap .cart-box-top .stage-two .status').html('(terminado)');
   			    $('.cart-wrap .cart-box-top .stage-three .status').html('(en progreso)');
   			    break;
	    }
	}
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}