function setErrorBorders()
{
  $('input').filter(function(){return $(this).attr('Validators');}).bind('change', function(){setElementBorders(this);});
  $('radio').filter(function(){return $(this).attr('Validators');}).bind('change', function(){setElementBorders(this);});
  $('textarea').filter(function(){return $(this).attr('Validators');}).bind('change', function(){setElementBorders(this);});
  $('select').filter(function(){return $(this).attr('Validators');}).bind('change', function(){setElementBorders(this);});
  $('input,radio,textarea,select').filter(function(){return $(this).attr('Validators');}).bind('blur', function(){setElementBorders(this);});

  function setElementBorders(el)
  {
    var arr = $(el).attr('Validators');
    var bValid = true;

    for(var i=0;i < arr.length;i++)
    {
      if(!arr[i].isvalid){
        bValid = false;
      }
    }
    if(!bValid)
    {
          $(el).addClass('errorBorder');
    }else
    {
      $(el).removeClass('errorBorder');
    }
  }  
} 

   function loadDreamgiftShopping(sDictPoints,sDictProducts, doctype)
    {
      if(doctype == 'GiftsFolder' || doctype == 'GiftsCategory')
	{ loadShopping(sDictPoints, sDictProducts);}else{
      $.ajaxSetup({ cache: false });
      var loadURL = "/fr/dreamgiftshoppingcart";
      if(window.location.href.indexOf('/nl') > 0)
      {
        loadURL = "/nl/dreamgiftshoppingcart";
      }
      
      var container = $("#loader");
      container.children().fadeOut('fast', function(){
        container.empty().addClass('loading');
      });
      
      var temp = $('<div/>').load(loadURL + " #loading", 
        function()
        {
          container.html($(this).html()).find('#loading').hide();
          try{
            $("#cart .item:first").addClass("first");
          }catch(ex){}

          try{
            if($("#cart .item").length > 2 )
            {
              //collapse
              var aantal = 0;
              var aantalProd = 0;
              var aantalPunt = 0;
              $("#cart .item").each(function(){
                aantal+=1;
                if (aantal > 11)
                {
                  aantalProd += parseInt($(this).find(".count").text());
                  aantalPunt += parseInt($(this).find(".points").text());
                  $(this).css("display","none");
                }
              })
              $("#cart #cart_bottom").before('<div class="item"><a href="checkout">+ ' + (aantal-2) + '&nbsp;' + sDictProducts + '</a><span class="points">' + aantalPunt + ' ' + sDictPoints + '</span><span class="count">' + aantalProd + '</span><div class="clear"></div></div>');
            }
          }catch(ex){}
          
          tb_init('a.thickbox, area.thickbox, input.thickbox');
          
          $('#loading').fadeIn('fast', function(){
            container.removeClass('loading');
          });
        });
	}
    }

   function loadShopping(sDictPoints,sDictProducts)
    {
      $.ajaxSetup({ cache: false });
      var loadURL = "/fr/shoppingcart";
      if(window.location.href.indexOf('/nl') > 0)
      {
        loadURL = "/nl/shoppingcart";
      }
      
      var container = $("#loader");
      container.children().fadeOut('fast', function(){
        container.empty().addClass('loading');
      });
      
      var temp = $('<div/>').load(loadURL + " #loading", 
        function()
        {
          container.html($(this).html()).find('#loading').hide();
          try{
            $("#cart .item:first").addClass("first");
          }catch(ex){}

          try{
            if($("#cart .item").length > 2 )
            {
              //collapse
              var aantal = 0;
              var aantalProd = 0;
              var aantalPunt = 0;
              $("#cart .item").each(function(){
                aantal+=1;
                if (aantal > 11)
                {
                  aantalProd += parseInt($(this).find(".count").text());
                  aantalPunt += parseInt($(this).find(".points").text());
                  $(this).css("display","none");
                }
              })
              $("#cart #cart_bottom").before('<div class="item"><a href="checkout">+ ' + (aantal-2) + '&nbsp;' + sDictProducts + '</a><span class="points">' + aantalPunt + ' ' + sDictPoints + '</span><span class="count">' + aantalProd + '</span><div class="clear"></div></div>');
            }
          }catch(ex){}
          tb_init('a.thickbox, area.thickbox, input.thickbox');
          
          $('#loading').fadeIn('fast', function(){
            container.removeClass('loading');
          });
        });
    }

$(document).ready(function(){
  
    try{
      $(".faq_response").css("display","none");
      $(".faq_question").css("cursor","pointer");
      $(".faq_response").css("cursor","pointer");  
      $(".faq_question").click(function(){
        if($(this).hasClass('faq_question'))
        {
          $(this).removeClass('faq_question');
          $(this).addClass('faq_question_open');
        }else{
          $(this).removeClass('faq_question_open');
          $(this).addClass('faq_question');
        }
        $(this).next(".faq_response").slideToggle("normal");
      });
    }catch(ex){}

   $('#login input').keypress(function(e){
    if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
    {
      eval($('#login a').attr('href'))
      return false;
    }else{return true;}
  });

   $('#forgotPassword input').keypress(function(e){
    if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
    {
      eval($('#forgotPassword a').attr('href'))
      return false;
    }else{return true;}
  });

  setErrorBorders();

});
    

