$(document).ready(function(){
  //  if($.browser.msie) alert("internet Explorer");
  //  if($.browser.mozilla) alert("firefox");
    
  ///////////////////////// Hover Functions //////////////////////////
    $('#i_header_headerSearchButton').hover(
      function(){$(this).attr('src','../img/btn_search_hover.gif');}
      ,function(){$(this).attr('src','../img/btn_search.gif');
    });
  ////////////////////////////////////////////////////////////////////
    
  ///////////  Keyword auto-clear (course quick find) ///////////////
    $('#search_txtKeywordSearch').bind('focus',function(){
      if($(this).val()=='Browse by Keyword'){
        $(this).val('');      
        $("#search_selTopicSearch option:first-child").attr("selected","selected");
      }
    });
    //$('#courseSearch_txtKeywordSearch').focus(function(){$(this).blur();return false;});
    $('#search_txtKeywordSearch').bind('blur',function(){
      if($(this).val()==''){
        $(this).val('Browse by Keyword');}
    });
    $("#search_selTopicSearch").bind('change',function(){
      $('#search_txtKeywordSearch').val('Browse by Keyword');
    });


//////////////////////////////////////////////////////////////////
///                Laws & Statutes                              //
//////////////////////////////////////////////////////////////////
  $('.statuteSectionHeader a').each(function(){
    $(this).bind('click',function(){
      $(this).parents().children('.statuteSectionLinks').toggle();
      $(this).toggleClass("open");
      return false;
    });
  });
  
  var lawStatuteSection = $.jqURL.get('ls');
  var lawStatuteID = '#ls'+$.jqURL.get('lid');
  switch (lawStatuteSection){
    case "i":
      $('#internationalSection a').click();
      break;
    case "n":
      $('#nationalSection a').click();
      break;
    case "s":
      $('#stateSection a').click();
      break;      
  }  
  if ($(lawStatuteID).attr('href')!= undefined){
    if (confirm('Would you like to open the search item "'+$(lawStatuteID).attr('href') +'"') ){
      $.jqURL.loc($(lawStatuteID).attr('href'),{wintype:'_blank'});
    }
    location.replace($.jqURL.strip({keys:'lid'})); // Location.replace is used here to remove current page from browser history
  }
});

//////////////////////////////////////////////////////////////////
///                Reference Center                             //
//////////////////////////////////////////////////////////////////

$('document').ready(function(){
  var rcID = '#rc'+$.jqURL.get('rid'); 
  if ($(rcID).attr('href')!= undefined){
    if (confirm('Would you like to open the search item "'+$(rcID).attr('href') +'"') ){
      $.jqURL.loc($(rcID).attr('href'),{wintype:'_blank'});
    }
    location.replace($.jqURL.strip({keys:'rid'})); // Location.replace is used here to remove current page from browser history
  }
 });


///////////  Bookstore filter binding ////////////////////////
$('document').ready(function(){
  $('#bookstoreShowAll').addClass('selected');
  $('#bookstoreShowAll').click(function(){
    $('#bookstoreListContainer').fadeOut(300,function(){
      $('.bookOverview').each(function(){
        if ($(this).css('display')=='none'){
          $(this).show(function(){
            $('#bookstoreListContainer').fadeIn(400);
          });
        }
      });
    });
    $('.bookstoreFilter').removeClass('selected');
    $(this).addClass('selected');
    return false;
  });
  $('#bookstoreShowBooks').click(function(){
    $('#bookstoreListContainer').fadeOut(300,function(){
      $('.subscription').hide(function(){
        $('.book').show(function(){
          $('#bookstoreListContainer').fadeIn(400);
        });
      });
    });
    $('.bookstoreFilter').removeClass('selected');
    $(this).addClass('selected');
    return false;
  });  
  $('#bookstoreShowSubscriptions').click(function(){
    $('#bookstoreListContainer').fadeOut(300,function(){
      $('.book').hide(function(){
        $('.subscription').show(function(){
          $('#bookstoreListContainer').fadeIn(400);
        });
      });
    });          
    $('.bookstoreFilter').removeClass('selected');
    $(this).addClass('selected');
    return false;
  });
});
////////////////////////////////////////////////////////////////////////
//                  E-card Form Submission                            //
////////////////////////////////////////////////////////////////////////
$(function(){
    $('.removeColleague').show();
    $('.ecardColleagueData').hide();
    $('.ecardColleagueData').find(":text").attr('disabled','disabled');
    $('.ecardColleagueData:first').show(); 
    $('.ecardColleagueData:first').find(":text").attr('disabled','');  
    $('.ecardColleagueData:first .removeColleague').hide();
    $('#addColleague').click(function(){
      $('.removeColleague').show();
      $('.ecardColleagueData:hidden:first').find(":text").attr('disabled','');  
      $('.ecardColleagueData:hidden:first').show(); 
      if ($('.ecardColleagueData:hidden').length==0){
        $('#addColleague').hide();
      }
      return false;
    });
    $('.removeColleague').click(function(){
      $(this).parents('.ecardColleagueData').find(":text").val('').attr('disabled','disabled');
      $(this).parents('.ecardColleagueData').find(".errorMessage").remove();
      $(this).parent('.ecardColleagueData').hide();
      if ($('.ecardColleagueData:visible').length==1) 
        $('.ecardColleagueData:visible .removeColleague').hide();
      $('#addColleague').show();
      return false;
    });
    $('#eCardForm').bind('submit',function(){
      var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      $('.errorMessage').remove();
      var error=false;
      $(this).find('input:enabled').each(function(){
        temp=jQuery.trim($(this).val());
        if(temp==""){
          $(this).siblings("label").after("<span class='errorMessage'>Required</span>");
          error=true;
        }else if ($(this).is('.email')){
          if (!filter.test($(this).val())){
            $(this).siblings("label").after("<span class='errorMessage'>Invalid Email</span>");
            error=true;
          }
        }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        //////////////////////////////////////////////////////////////////////////
        //////////////////////   Remove error message when text field gains focus   //////////////////
        $(this).bind('focus',function(){
          $(this).siblings(".errorMessage").remove();
        });
      });
      if(error) return false;
      return true;
    });
  });

$('document').ready(function(){
    $('#loginLink').click(function(){
      $('.validator').onsubmit=new function(){"Page_ValidationActive=false"};    
      $('#loginBox').show();
      $('#closeLogin').click(function(){
          $('#loginBox').hide();
        });
      $('#i_header_txtUserName').focus();              
      return true;
    });
  });

////////////////////////////////////////////////////////////////////////
//                  Today in ADR link modification                    //
////////////////////////////////////////////////////////////////////////
$('document').ready(function(){
  $('#todayInADRHeadline').attr('href','http://www.adrworld.com');
  $('#todayInADRHeadline').attr('target','_blank');
});

$('document').ready(function(){
  $('.shippingCosts').hide();
  $('.shippingTrigger').bind('click',function(){
    $('.shippingCosts').toggle();
    if ($(this).is('.open'))
      $(this).removeClass('open');
    else
      $(this).addClass('open');
    return false;
  });
});

////////////////////////Registration Type///////     
        
        
        
        
        
//        $(function(){
//    $('.remove').show();
//    $('.RegtypeData').hide();
//    $('.RegtypeData').find(":text").attr('disabled','disabled');
//    $('.RegtypeData:first').show(); 
//    $('.RegtypeData:first').find(":text").attr('disabled','');  
//    $('.RegtypeData:first .removeColleague').hide();
//    $('#add').click(function(){
//      $('.remove').show();
//      $('.RegtypeData:hidden:first').find(":text").attr('disabled','');  
//      $('.RegtypeData:hidden:first').show(); 
//      if ($('.RegtypeData:hidden').length==0){
//        $('#add').hide();
//      }
//      return false;
//    });
//    $('.remove').click(function(){
//      $(this).parents('.RegtypeData').find(":text").val('').attr('disabled','disabled');
//      $(this).parents('.RegtypeData').find(".errorMessage").remove();
//      $(this).parent('.RegtypeData').hide();
//      if ($('.RegtypeData:visible').length==1) 
//        $('.RegtypeData:visible .removeColleague').hide();
//      $('#add').show();
//      return false;
//    });
//    });
//    
            $(function(){
    $('.remove').show();
    $('.RegtypeData').hide();
    $('.RegtypeData').find(":text").attr('disabled','disabled');
    $('.RegtypeData:first').show(); 
    $('.RegtypeData:first').find(":text").attr('disabled','');  
    $('.RegtypeData:first .removeColleague').hide();
    $('#add').click(function(){
      $('.remove').show();
      $('.RegtypeData:hidden:first').find(":text").attr('disabled','');  
      $('.RegtypeData:hidden:first').show(); 
      if ($('.RegtypeData:hidden').length==0){
        $('#add').hide();
      }
      return false;
    });
    $('.remove').click(function(){
      $(this).parents('.RegtypeData').find(":text").val('').attr('disabled','disabled');
      $(this).parents('.RegtypeData').find(".errorMessage").remove();
      $(this).parent('.RegtypeData').hide();
      if ($('.RegtypeData:visible').length==1) 
        $('.RegtypeData:visible .removeColleague').hide();
      $('#add').show();
      return false;
    });
    });
    
    $('#frmEditCourse').bind('submit',function(){
alert("test");
      var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      $('.errorMessage').remove();
      var error=false;
      //    Loop through all enabled inputs.
      $(this).find('input:enabled').each(function(){
        temp=jQuery.trim($(this).val());
        if(temp==""){
          $(this).siblings("label").after("<span class='errorMessage'>Required</span>");
          error=true;
        }
      });
    });
    
/*
  Return the prefix appended to the beginning of a .NET web control by the 
  server.  The supplied string represents a classname that has been applied to 
  one of the web controls.  Using jquery, we can obtain the id attribute of a 
  form element with that class name, strip out the server-appended prefix and 
  return it.
  @param strFieldClassName the class attribute of one of the form fields
*/

function fGetDotNetPrefix(strFieldClassName) {
//alert("fGetDotNetPrefix(\"" + strFieldClassName + "\") called.");
  var strResponse = $("." + strFieldClassName).attr("id");
//alert("strResponse = " + strResponse);
  if(strResponse == undefined) {
		strResponse = "";
  } else {
		var intIndex = strResponse.lastIndexOf("_");
		if(intIndex == -1) {
			strResponse = "";
		} else {
			strResponse = strResponse.substr(0, intIndex + 1);
//alert("strResponse = " + strResponse);
		}
  }
  return strResponse;
}