$(document).ready(function(){
  
  $('#search_text').focus(function(){
    $(this).css('color','#333');
  });
  $('#search_text').blur(function(){
    if($(this).val() == ''){
      $(this).val('Search');
    }
    $(this).css('color','#999');
  });

    //css magic
    $('.newsletters_description').find('a').css('text-decoration','underline');
    $('.newsletters_description').find('a').css('color','#333');
    $('.newsletters_description').find('a').attr('target','_blank');

    $('.event_body').find('a').css('text-decoration','underline');
    $('.event_body').find('a').css('color','#333');
    $('.event_body').find('a').attr('target','_blank');

    $('#vsvg').find('a').css('text-decoration','underline');
    $('#vsvg').find('a').css('color','#333');
    $('#vsvg').find('a').attr('target','_blank');

    $('.format_news_letters').find('a').css('text-decoration','underline');
    $('.format_news_letters').find('a').css('color','#333');
    $('.format_news_letters').find('a').attr('target','_blank');

    $('.format_news_letters').find('img').css('height','auto');

    $('.leadership_body').find('a').css('text-decoration','underline');
    $('.leadership_body').find('a').css('color','#333');
    $('.leadership_body').find('a').attr('target','_blank');

    $('.blog_post_content').find('a').css('text-decoration','underline');
    $('.blog_post_content').find('a').css('color','#333');
    $('.blog_post_content').find('a').attr('target','_blank');

    $('.messagebody').find('a').css('text-decoration','underline');
    $('.messagebody').find('a').css('color','#333');
    $('.messagebody').find('a').attr('target','_blank');
    
    $('#file_detail').find('a').attr('target', '_blank');
    $('.a_blank').find('a').attr('target', '_blank');

    $('.smaller_video').find('object').attr('width','210px');
    $('.smaller_video').find('embed').attr('width','200px');

    $img = $('.small_column_right').find('img');    
    //$img.css('height','auto');
    $img.css('max-width','300px');

    $('.feed_underline').find('a').attr('target','_blank');    

    $('li.nextli:first').removeClass('bg_blue');
    $('li.nextli:first').addClass('light_blue');
    //$('#form_paypal').find('tr').find('td:first').css('text-align','right');
    
      $("a").click(function(even){
        even.stopPropagation();
      })
      
      $("select[name='dinamic_sort']").change(function(){
        $file = $(this).parent().find("input[name='dinamic_file']").val();        
        $parent = $(this).parent().parent().parent();
        $.get($file,{dinamic_sort:$(this).val()},function(data){
          $parent.find('.main_p').html(data);
        });
      })

      //for only text pages zebra

      $('#ccidhelp').hover(
      function(){
        $('#cciddesc').show();
      },
      function(){
        $('#cciddesc').hide();
      });
      
      //for sort zebra table
      $.tablesorter.defaults.widgets = ['zebra'];      
      $("#library_search_results").tablesorter();
      $('#library_search_results').find('.simple_row').find('td:first').addClass('grey_border_left');
      $(".print_this").tablesorter();

      //clear last punct_line
      $('.main_p').find('.punct_line:last').hide();
      $('.groups_home').find('.search_listing:last').addClass('no_border');

      //for navigation
      var urlpage = document.URL;      
      var events = /event_calendar/;
      var blog = /blog/;
      var forum = /forum/;
      var jobs =/view-jobs/;

      var vendors = /pg\/vendors/;

      var invitefriends = /invitefriends/;
      var search_members = /search-members/;
      var find_member =/find_member=on/;
      var all_members =/all-members/;

      var groups =/groups/;

      //var club_blog = /pg\/thecmoclub\/blog\/pete_krainik/;
      var club_blog = /pg\/thecmoclub\/blog/;
      var view_club_blog = /pg\/thecmoclub\/view-blog/;
      var find_in_lead = /find_th_lead_libr\=on/;
      var leadership_library =/leadership\_library/;
      var thank_you = /pg\/thecmoclub\/thank-you/;
      var policies = /policies/;
      //var terms =/terms-of-use/;

      var thot_led = /thought-leadership/;
      var search_thought_leadership =/search-thought-leadership/;
      var contribute_to_library = /contribute-to-library/;
      var summit_and_dinner = /summit-and-dinner/;
      var pg_poll_all = /pg\/poll/;
      var add_video = /pg\/thecmoclub\/add_video/;
      //var all_video = /pg\/thecmoclub\/all_video/;

      var parthner_quotes = /parthner-quotes/;

      var event_recaps = /event-recaps/;

      var demographics = /demographics/;
      var member_quotes = /member-quotes/;
      //var map = /pg\/thecmoclub\/map/;

      var partner = /view-thought-leadership/;

      if(demographics.test(urlpage)
      || member_quotes.test(urlpage)
      //|| map.test(urlpage)
      ){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/about";
      }else
      if(partner.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/current_partners";
      }else
      if(club_blog.test(urlpage) 
      || view_club_blog.test(urlpage)
      ){
        //urlpage = "http://"+document.domain+"/pg/thecmoclub/blog/pete_krainik";
        urlpage = "http://"+document.domain+"/pg/thecmoclub/blog";
      }else
      if(parthner_quotes.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/partnership_programs";
      }else
      if(search_thought_leadership.test(urlpage)
        || contribute_to_library.test(urlpage)
        || summit_and_dinner.test(urlpage)
        || pg_poll_all.test(urlpage)
        || thank_you.test(urlpage)
        || add_video.test(urlpage)
        //|| all_video.test(urlpage)
        || thot_led.test(urlpage)
        || leadership_library.test(urlpage)
        || find_in_lead.test(urlpage)
      ){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/leadership_library";
      }else      
      
      if(events.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/event_calendar/";
      }else
      if(invitefriends.test(urlpage) || 
          search_members.test(urlpage) ||
          find_member.test(urlpage) ||
          all_members.test(urlpage)
      ){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/members"
      }else
      if(jobs.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/jobs";
      }else
      if(forum.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/forum";
      }else
      if(blog.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/member-resources";
      }else
      if(groups.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/groups/world/";
      }else
      if(event_recaps.test(urlpage)){
        urlpage = "http://"+document.domain+"/pg/thecmoclub/event-recaps/";
      }else
      if(vendors.test(urlpage)
        || policies.test(urlpage) )
      {
        urlpage = "http://"+document.domain+"/pg/vendors/menu/";
      }
      
      
      $(".mainmenu a[href='"+urlpage+"']").css('text-decoration','underline');
      $(".mainmenu a[href='"+urlpage+"']").parent('li').parent('ul').css('display','block');

      $("a[href='"+urlpage+"']").parent('li').parent('ul').prev('.dropbutton2').addClass('open');
      $("a[href='"+urlpage+"']").parent('li').parent('ul').next('.open_menu_footer').addClass('open');

      $("a[href='"+urlpage+"']").parent('div').parent('li').find('.dropbutton2').addClass('open');
      $("a[href='"+urlpage+"']").parent('div').find('.close_list').addClass('open');
      $("a[href='"+urlpage+"']").parent('li').parent('ul').prev('div').find('.close_list').addClass('open');

      $("a[href='"+urlpage+"']").parent('div').parent('li').find('ul').css('display','block');
      $("a[href='"+urlpage+"']").parent('div').parent('li').find('.open_menu_footer').addClass('open');

      //for drop menu
      $('.quick_drop').hover(function(){
        $(this).find('.drop_me').find('li').css('float','none');
        $(this).find('.drop_me').show();
        
      },
      function(){
        $(this).find('.drop_me').hide();
        
      });

      // for voting
      $('.vote').click(function(){
        $parent = $(this).parent();
        $user = $parent.find('#userguid').val();
        $content = $parent.find('#contentguid').val();
        $parent.html("<img class='gray_animate' src='/mod/thecmoclub/graphics/animate/gray.gif' alt=''>");
        $.get("/mod/thecmoclub/ajaxphp/ajax.php",{user:$user,content:$content,operation:$(this).attr('name')},function(data){
          $parent.html(data);
          //$parent.find('#vot').html(data);
        });
      })

      // for features
      $('.feat').click(function(){
        $parent = $(this).parent();
        $user = $parent.find('#userguid').val();
        $content = $parent.find('#contentguid').val();
        $parent.html("<img class='gray_animate' src='/mod/thecmoclub/graphics/animate/gray.gif' alt=''>");
        $.get("/mod/thecmoclub/ajaxphp/featured.php",{user:$user,content:$content},function(data){
          $parent.html(data);
        });
      })

      //for dropdown menu
      $('.dropdown_menu > li').click(
        function(even) {
          status = $(this).find('ul:first').css('display');
          switch(status){
            case 'none':{
              $(this).find('ul:first').slideDown();
              break;
            }
            case 'block':{
              $(this).find('ul:first').slideUp();
              break;
            }
          }
          even.stopPropagation();
        }
      );

        function main_menu_drop($li){
          $status = $li.find('ul:first').css('display');
          switch($status){
            case 'none':{
              $li.find('ul:first').slideDown();
              $li.find('.close_list').addClass('open');
              $li.find('.dropbutton2').addClass('open');
              $li.find('.open_menu_footer').addClass('open');

              //$(this).find('#')//menu_dropbutton_open.jpg
              break;
            }
            case 'block':{
              $li.find('ul:first').slideUp();
              $li.find('.close_list').removeClass('open');
              $li.find('.dropbutton2').removeClass('open');
              $li.find('.open_menu_footer').removeClass('open');

              //menu_dropbutton2.jpg
              break;
            }
          }
        }

      $('.mainmenu li .close_list').click(function(event){
        $parent = $(this).parent().parent().parent();        
        main_menu_drop($parent);
        event.stopPropagation();
        
      });

      // for dropdown mainmenu
      $('.mainmenu li').click(function(){
        main_menu_drop($(this));
          //even.stopPropagation();
        }
      );

      $('.param-head').click(function(){
        $(this).next('ul').slideToggle();
      })

      $('.mainmenu li').hover(function(){
        $(this).find('.dropbutton2').addClass('hover');
        $(this).find('.open_menu_footer').addClass('hover');
      },
      function () {
        $(this).find('.dropbutton2').removeClass('hover');
        $(this).find('.open_menu_footer').removeClass('hover');
      }

      );

      // for scrolling latest activity
      $('#right').click(function(){
        if($('.startpanel > .river_item_list > .showitem:last').next('div').hasClass('item')){
          $('.startpanel > .river_item_list > .showitem:first').removeClass('showitem');
          $('.startpanel > .river_item_list > .showitem:last').next('div').addClass('showitem');
        }
      })
      $('#left').click(function(){
        if($('.startpanel > .river_item_list > .showitem:first').prev('div').hasClass('item')){
          $('.startpanel > .river_item_list > .showitem:last').removeClass('showitem');
          $('.startpanel > .river_item_list > .showitem:first').prev('div').addClass('showitem');
        }
      })

      $('.startpanel > .river_item_list > .river_item').addClass('item');
      $('.startpanel > .river_item_list > .river_item:first').addClass('showitem');
      $('.startpanel > .river_item_list > .river_item:first').next('div').addClass('showitem');
      $('.startpanel > .river_item_list > .river_item:first').next('div').next('div').addClass('showitem');


      $('.blockintab .personal_line_height1').hover(
        function () {
          $('.blockintab .personal_line_height1 li').show();
          $('.blockintab .personal_line_height1').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board.jpg) no-repeat');
        },
        function () {
          $('.blockintab .personal_line_height1 li').hide();
          $('.blockintab .personal_line_height1').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board1.jpg) no-repeat');
        }
      );

      $('.blockintab .personal_line_height2').hover(
        function () {
          $('.blockintab .personal_line_height2 li').show();
          $('.blockintab .personal_line_height2').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board.jpg) no-repeat');
        },
        function () {
          $('.blockintab .personal_line_height2 li').hide();
          $('.blockintab .personal_line_height2').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board2.jpg) no-repeat');
        }
      );

      $('.blockintab .personal_line_height3').hover(
        function () {
          $('.blockintab .personal_line_height3 li').show();
          $('.blockintab .personal_line_height3').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board.jpg) no-repeat');
        },
        function () {
          $('.blockintab .personal_line_height3 li').hide();
          $('.blockintab .personal_line_height3').css('background', 'url(/mod/thecmoclub/graphics/main/tab_white_board3.jpg) no-repeat');
        }
      );

      // for tab menu
      $('#tabs > li.nextli').hover(function(){
        var id = $(this).attr('id');
        $tabblock = $(this).parent().parent().parent();
        $tabblock.find('#blocks > div.qq').hide();

        $tabblock.find('#tabs > li').addClass('bg_blue');
        $tabblock.find('#tabs > li').removeClass('light_blue');
        if(id!=0){
          $tabblock.find('#blocks').show();
          $tabblock.find('#block'+id).show();

          $tabblock.find('#'+id).addClass('light_blue');
          $tabblock.find('#'+id).removeClass('bg_blue');
        }
      });

     $('#adv_search').find('#blocks >div').hide();
      $('#adv_search').find('#blocks >div:first').show();
      
      $('#gen_search').find('#blocks >div').hide();
      $('#gen_search').find('#blocks >div:first').show();

      $('#adv_search > .res_border > .tabblock').find('#blocks >div').hide();
      $('#adv_search > .res_border > .tabblock').find('#blocks >div:first').show();      


      /*$('.nextmon').click(function(){
        $first = $(".calendar_block:first");
        $last = $(".calendar_block:last");
        $curr = $(".calendar_block.visible");
        $next = $curr.next('.calendar_block');
        
        $curr.hide();
        $curr.removeClass('visible');
        
        if($next.length==0){
          $first.addClass('visible');
          $first.show();
        }else{
          $next.addClass('visible');
          $next.show();
        }
      })
      $('.prevmon').click(function(){
        $first = $(".calendar_block:first");
        $last = $(".calendar_block:last");
        $curr =$(".calendar_block.visible");
        $next = $curr.prev('.calendar_block');

        if($next.length==0){
          $last.addClass('visible');
          $last.show();
        }else{
          $next.addClass('visible');
          $next.show();
        }
        $curr.hide();
        $curr.removeClass('visible');
        $next.addClass('visible');
        $next.show();
      })

      $('.calendar_block').hide();
      $('.calendar_block:first').addClass('visible');
      $('.calendar_block:first').show();*/

      function load_new_calendar_month(prevnext){
        $('.prevmon').hide();
        $('.nextmon').hide();
        $('#calendar_date').find('.floatleft').html('loading...');
        $month = $('input[name=calendar_month]').val();
        $year = $('input[name=calendar_year]').val();
        $showevent = $('input[name=show_event]').val();
        $context = $('input[name=calendar_context]').val();
        $('.calendar_area').load("/mod/thecmoclub/ajaxphp/calendar.php",{month:$month,year:$year,prevnext:prevnext,showevent:$showevent,context:$context});
      }

      $('.prevmon').live('click',function(){
        load_new_calendar_month('prev');
      })

      $('.nextmon').live('click',function(){
        load_new_calendar_month('next');
      })

      //for search
      $('#all').click(function(){
        var checked = $(this).attr('checked');
        $('.notall').attr('checked', checked);
        if(checked == true){
          $('#param_member').slideDown();
          $('#param_group').slideDown();
          $('#param_event').slideDown();
        }else{
          $('#param_member').slideUp();
          $('#param_group').slideUp();
          $('#param_event').slideUp();
        }
      })

      $('.notall').click(function(){
        var id = $(this).attr('id');
        var checked = $(this).attr('checked');
        if(checked==true){
          $('#param_'+id).slideDown();
        }else{
          $('#param_'+id).slideUp();
        }
        var i=0;
        var count=0;
        $('.notall').each(function(){
          count++;
          var checked = $(this).attr('checked');
          if(checked==true){
            i++;
          }
        })
        if(count == i){
          $('#all').attr('checked',true);
        }else{
          $('#all').attr('checked',false);
        }
      })

    // for image gallery
    $(".openme").click(function(){
      $('#image_container').show();
      $("#stage").attr('src','/mod/tidypics/thumbnail.php?file_guid='+$(this).attr('id')+'&size=large');      
    })
    $("#close").click(function(){
      $('#image_container').hide();
    })
    
    function sure(){
      return confirm('Are you sure?');
    }

    $(".pagination:first").hide();

    /*$("#tabs #2").hover(function(){
     max_height = 0;
     $('#blocks #block2 .newslatters_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    
    $('#blocks #block2 .search_listing').height(max_height);
    });

    $("#tabs #3").hover(function(){
     max_height = 0;
     $('#blocks #block3 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block3 .search_listing').height(max_height);
    });

    $("#tabs #4").hover(function(){
     max_height = 0;
     $('#blocks #block4 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block4 .search_listing').height(max_height);
    });

    $("#tabs #5").hover(function(){
     max_height = 0;
     $('#blocks #block5 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block5 .search_listing').height(max_height);
    });

    $("#tabs #6").hover(function(){
     max_height = 0;
     $('#blocks #block6 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block6 .search_listing').height(max_height);
    });

    $("#tabs #7").hover(function(){
     max_height = 0;
     $('#blocks #block7 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block7 .search_listing').height(max_height);
    });

    $("#tabs #8").hover(function(){
     max_height = 0;
     $('#blocks #block8 .search_listing').each(function(){
      if($(this).height() > max_height) max_height = $(this).height();
    });
    $('#blocks #block8 .search_listing').height(max_height);
    });
*/
     var t=setTimeout("$('.ui-datepicker-next a').text('');",1000);


      $("select[name='youtubeback']").change(function(){
        $value = $(this).val();        
        if($value != 'youtube_video'
          && $value != 'event-recaps'
        ){
          document.location.href='/pg/thecmoclub/contribute-to-library?type='+$value;
        }
      })

      $("select.input_fields").change(function(){
        $files = $('.one_row');
        $value = $(this).val();

        if($value == 'youtube_video'){
          document.location.href='/pg/thecmoclub/add_video';
        }
        if($value == 'event-recaps'){
          document.location.href='/pg/thecmoclub/add-event-recaps';
        }

        if($value !='great-campaigns' && $files.length>4){
          $('.one_row:last').remove();
          if($files.length>4){
            $('.one_row:last').remove();
          }
        }
      })
      $('.add_file').live('click',function(){
        $files = $('.one_row');

        $doc_type = $("select.input_fields").val();

        if($doc_type =='great-campaigns' && $files.length>=6){
          return false;
        }else 
        if($doc_type !='great-campaigns' && $files.length>=4){
          return false;
        }

        $parent = $(this).parent().parent().parent().parent().parent().parent();
        $first_child =$parent.find('.one_row:first');        
          $html = $first_child.html();
          $parent.append("<div class='one_row'>"+$html+"</div>");
      })

    
      // For vendore rating
      $(".vendors_categories tr td").click(function(){
        $('#add_vendore .parameters_position > a').attr('href','/pg/vendors/add-vendor/'+$(this).attr('id'));
        $('#add_vendore').css('display','block')
        $('#vendors_list_by_category').html("<img src='/mod/thecmoclub/graphics/animate/white.gif' alt=''>");
        $('#vendors_list_by_category').load("/mod/vendors/ajax/vendors.php",{category:$(this).attr('id')});
      })

      $(".vendors_categories tr td").hover(function(){
        $('#moved_category').html($(this).children('.table_cell').html());

      }, function(){
        $('#moved_category').html("");
      });

      $(".contract_with_vendor input[type=radio]").click(function(){
        if($(this).val()=='Yes'){
          $('#add_vendor > form').show();
          $('.contract_with_vendor').hide();
        }else{
          alert('Vendor Reviews are Only Allowed for Vendors You Have had a Contract With in the Last 18 Months.');
          document.location.href='/pg/vendors/write-review/';
        }
      })
      
      $('#vendor_category > li').click(function(e){
        if(!e.ctrlKey){
          $('#vendor_category > li').removeClass('choisen');
        }
        if($(this).attr('id')=='all'){
          $('#vendor_category > li').addClass('choisen');
          $('#vendor_category')
        }else{
          $(this).toggleClass('choisen');
        }
      })

      $('#vendor_category').change (function(){
        $first = $(this).val();
        if($first[0]=='all'){
          $(this).find('option').attr('selected','selected');
        }
      })
      
      $('#vendor_criteria > li').click(function(){
        $('#vendor_criteria > li').removeClass('choisen');
        $(this).addClass('choisen');
      })
      
      $('#search_reviews').click(function(){
        //$categories = $('#vendor_category > .choisen');
        $categories = $('#vendor_category').val();
        
        if(!$categories){
          alert('Please choose category for vendor!');
          return false;
        }
        //$criteria = $('#vendor_criteria > .choisen').attr('id');
        $criteria = $('#vendor_criteria').val();
        if($criteria==''){
          alert('Please choose criteria for vendor!');
          return false;
        }
        $check_geography_covered = $("#check_geography_covered").attr('checked')
        $check_company_size = $("#check_company_size").attr('checked');

        $geography_covered =$('#geography_covered').val();
        $company_size = $('#company_size').val();
                
        var mass_categories = new Array();
        for(var i=0;i<$categories.length;i++){          
          mass_categories[i]=$categories[i].id;
        }

        $("#search_reviews_results").html("<div class='main_p'><img src='/mod/thecmoclub/graphics/animate/white.gif' alt=''></div>");
        $("#search_reviews_results").load("/mod/vendors/ajax/review_search.php",{
          criteria:$criteria,
          categories:[$categories],
          check_geography_covered:$check_geography_covered,
          check_company_size:$check_company_size,
          company_size:$company_size,
          geography_covered:[$geography_covered]
        });
      })

      $('#print').live('click',function(){
        $html = $('.print_this').parent().html();
        myWin= open("", "displayWindow",
        "width=850,height=400,status=yes,toolbar=yes,menubar=yes");
        myWin.document.open();
        myWin.document.write("<html><head><title></title>");
        myWin.document.write("<link rel='stylesheet' href='/mod/thecmoclub/css/css.css' type='text/css'></head>");
        myWin.document.write("<body style='background-color:#FFF;' onload='window.print()'>");
        myWin.document.write("<div class='main_p'>"+$html+"</div>");
        myWin.document.write("</body></html>");
        myWin.document.close();
      })

      $('textarea.input_fields').keypress(function(e){
        if(e.keyCode==0){
          $limit = 250;
          if($(this).hasClass('limit_1000')){
            $limit = 1000;
          }
          $text = $(this).val();          
          if($text.length>=$limit){
            alert($text.length);
            return false;
          }
        }
        return true;
      })

      $(".top_two_areas .reg_check_box label input[type='checkbox']").click(function(){
        $count = $(".top_two_areas .reg_check_box label input[type='checkbox']:checked").length;
        $checked = $(this).attr('checked');        

        if($checked && $count>3){
          $(this).attr('checked','');
        }

      })

      $(".captcha-right").live('click',function(){
        /*$(".generate_capcha").html("<img src='/mod/thecmoclub/graphics/animate/white.gif' alt=''>");
        $(".generate_capcha").load("/mod/captcha/ajax/captcha.php");
        */
      })

      $("#donation_method").change(function(){
        $value = $(this).val();        
        if($value =='Paypal'){
          $('.hide_for_paypal').hide();
          $('#paypalinforedirect').show();
        }
        else{
          $('.hide_for_paypal').show();
          $('#paypalinforedirect').hide();
        }
      })

      $("#country_label").change(function(){
        $value = $(this).val();
        if($value !='US'){
          $('#us_only').hide();
          $('#state_label').val('all');
        }
        else{
          $('#us_only').show();
        }
      })

      function clear_fees($this){        
        if($checked){
          $("input[name='fees']").attr('disabled',true);
          $("input[name='fees2']").attr('disabled',true);
          $("input[name='fees']").val('');
          $("input[name='fees2']").val('');
        }else{
          $("input[name='fees']").attr('disabled',false);
          $("input[name='fees2']").attr('disabled',false);
        }
      }

      $("#free_members").click(function(){
        $checked = $(this).attr('checked');
        if($checked){
          $("#free_non_members").attr('checked',false);
        }
        clear_fees($(this));
      })
      $("#free_non_members").click(function(){
        $checked = $(this).attr('checked');
        if($checked){
          $("#free_members").attr('checked',false);
        }
        clear_fees($(this));
      })

      $("input[name='fees2']").keydown(function(){
        $("#free_non_members").attr('checked',false);
        $("#free_members").attr('checked',false);
      });
      $("input[name='fees']").keydown(function(){
        $("#free_non_members").attr('checked',false);
        $("#free_members").attr('checked',false);
      });

      $('#youtube_form').submit(function(){
        $file = $('#file_to_youtube');
        if($file.val()==""){
          alert("Please choose video file!");
          return false;
        }else{
          return true;
        }       
      });

      $('#members_sort').change(function(){
          document.location.href='/pg/thecmoclub/all-members?sort='+$(this).val();
      });
      $('#small_members_sort').change(function(){
          document.location.href='/pg/thecmoclub/members?sort='+$(this).val();
      });

      $(".formatting_advanced_search").find("input[value='all_sections']").click(function(){
        $(".formatting_advanced_search").find("input[type='checkbox']").attr('checked',true);        
      })
      $(".formatting_advanced_search").find("input[type='checkbox']").click(function(){
        $i=0;
        $(".formatting_advanced_search").find("input[type='checkbox']").each(function(){          
          if($(this).attr('checked')==false){
            $i++;
            $(".formatting_advanced_search").find("input[value='choisen_sections']").attr('checked',true);
          }        
        })
        if($i==0){
          $(".formatting_advanced_search").find("input[value='all_sections']").attr('checked',true);
        }
      })

      $('#exporteventsinfo').click(function(){
        $query = "";
        $events = $('input[name=eventguid]').each(function(){  
          if($(this).attr('checked') == true){
            if($query != ""){
              $query = $query + ",";
            }
            $query = $query + $(this).val();
          }
        });

        if($query !=""){
          document.location.href ='/action/thecmoclub/xls/event?events='+$query;
        }else
          alert('Please choose events');
      })

      $('#selectalleventsinfo').click(function(){
        $('input[name=eventguid]').each(function(){
          $(this).attr('checked','checked');
        });
      });
      $('#deselectalleventsinfo').click(function(){
        $('input[name=eventguid]').each(function(){
          $(this).attr('checked','');
        });
      });

      $('.paypalsubmit').click(function(){
        $(this).hide();
        /*$('.paypalsubmitattention').show();*/
        return true;
      });

      /* NEW FORMS FOR THOUGHT LEADERSHIP LIBRARY*/
      $("#newcontribute input[name='doctype']").click(function(){
        $('#newcontribute #content').html("<img src='/mod/thecmoclub/graphics/animate/white.gif' alt=''/>");
        switch($(this).val()){
          case "video":
            $.get("/mod/thecmoclub/views/default/thecmoclub/forms/thought_leadership/tabs/video.php",{},function(data){
              $('#newcontribute #content').html(data);
            });
            break;
          case "great-campaigns":
            $.get("/mod/thecmoclub/views/default/thecmoclub/forms/thought_leadership/tabs/campaign.php",{},function(data){
              $('#newcontribute #content').html(data);
            });
            break
          case "summit_content":
            $.get("/mod/thecmoclub/views/default/thecmoclub/forms/thought_leadership/tabs/dinnersummitcontent.php",{type:'summit'},function(data){
              $('#newcontribute #content').html(data);
            });
            break
          case "dinner_content":
            $.get("/mod/thecmoclub/views/default/thecmoclub/forms/thought_leadership/tabs/dinnersummitcontent.php",{type:'dinner'},function(data){
              $('#newcontribute #content').html(data);
            });
            break
          default:
            $.get("/mod/thecmoclub/views/default/thecmoclub/forms/thought_leadership/tabs/document.php",{},function(data){
              $('#newcontribute #content').html(data);
            });
            break;
        }
      });

      $('#newcontribute #add_file').live('click',function(){
        $files = $(this).parents().children('.files');
        $files_count = $('#newcontribute').find('.filewrapper').length;
        if($files_count>=6){
          alert("You can upload only 6 elements for this document");
          return false;
        }
        $newradionames = "choose"+$files_count+"[]";
        $html = $files.children('.filewrapper:first').html();
        $html = $html.replace(/choose.*?\[\]/g,$newradionames);

        $files.append("<div class='filewrapper bg_grey'>"+$html+"</div>");
        $files.find('.filewrapper:last').find("input[type=text]").val('');
        $files.find('.filewrapper:last').find("textarea").val('');
      });

      function hideOppositElement(){
        $value = $(this).val();
        $parent = $(this).parent().parent();
        if($value == "link"){
          $parent.children('div').children("input[type='file']").val('');
        }else{
          $parent.children('div').children('textarea').val('');
        }
      }
      
      $("#newcontribute .files .filewrapper div input[type='radio']").live('click',hideOppositElement);

      $("#newcontribute .files .filewrapper div input[type='file']").live('click',function(){
        $parent = $(this).parent();
        $parent.find("input[type='radio']").attr('checked','checked');
        $parent.parent().find("textarea[name='orlink[]']").val('');
      });
      
      $("#newcontribute .files .filewrapper div textarea").live('click',function(){
        $parent = $(this).parent();
        $parent.find("input[type='radio']").attr('checked','checked');
        $parent.parent().find("input[name='vid[]']").val('');
      });

      $('#newcontribute #getuploadform').live('click',function(){
        $title =$("#newcontribute input[name='videotitle']").val();
        $author =$("#newcontribute input[name='videoauthor']").val();
        $description =$("#newcontribute textarea[name='videotext']").val();
        if($title == '' || $description == '' || $author == ''){
          alert('All mandatory fields must be filled in');
          return false;
        }
        $wrapper = $(this).parent().parent();        

        $.post("/action/thecmoclub/youtube/getuploadform",
        {
          title:$title,
          author:$author,
          description:$description
        }
        ,function(data){
          if(data == ''){
            alert('All mandatory fields must be filled in');
          }else{
            $wrapper.html(data);
          }          
        });
      });

      $('#newcontribute .closegreatefile').live('click',function(){
        $files = $(this).parent().parent().find('.filewrapper');
        if($files.length>1){
          if(confirm("Are you sure you want to delete this file?")){
            $(this).parent().remove();
          }
        }else if($files.length == 1){
          alert("You can't remove the only form for uploading this type of files");
        }

      });

      window.setInterval("animateSlides();",7000);
      $('.slides > img').css('cursor','pointer');
      $('.slides > img').click(function(){
        document.location.href="/pg/thecmoclub/events";        
      })

      $('.deletealll').change(function(){
        $checked = $(this).attr('checked');

        if($checked){
          $("input[type='checkbox']").attr('checked',true);
        }else{
          $("input[type='checkbox']").attr('checked',false);
        }        
      });

      $("select[name='user_group']").change(function(){
        $guid = $(this).val();
        $('#animateimage').show();
        $('#group_description').html('');
        $.post('/action/thecmoclub/getgroupinfo',
          {guid:$guid},
          function(data){
            $('#animateimage').hide();
            $('#group_description').html(data);
          }
        );
      });

      $(".checkfirstdinner").click(function(){
        $email = $("input[name='email']").val();
        $dinnerguid = $("input[name='event']").val();

        if($email == ''){
          alert('Please fill in all mandatory fields');
        }else{
          $.post('/action/thecmoclub/checkforfirstdinner',
            {dinnerguid:$dinnerguid,email:$email},
            function(data){
              alert(data);
              $('.firstdinnertext').html(data);
            }
          );
        }
        return false;
      });
      
      $("select[name='expertise']").change(function(){
        $value = $(this).val();
        if($value == 'Other'){
          $(this).parent().parent().find('.other').show();
        }else{
          $(this).parent().parent().find('.other').hide();
          $(this).parent().parent().find('.other').find('input').val('');
        }        
      });
      
      $("select[name='expertise_and_challenges[]']").change(function(){
        $value = $(this).val();        
        var other = false;
        for(var i =0; i<$value.length;i++){
          if($value[i] == 'Other'){
            other = true;
          }
        }        
        if(other){
          $(this).parent().parent().find('.other').show();        
        }else{
          $(this).parent().parent().find('.other').hide();
          $(this).parent().parent().find('.other').find('input').val('');
        }        
      });
      
      $("select[name='company_industry[]']").change(function(){
        $value = $(this).val();        
        var other = false;
        for(var i =0; i<$value.length;i++){
          if($value[i] == 'Other'){
            other = true;
          }
        }        
        if(other){
          $(this).parent().find('.other').show();        
        }else{
          $(this).parent().find('.other').hide();
          $(this).parent().find('.other').find('input').val('');
        }        
      });

      $("select[name='pos_reporting']").change(function(){
        if($(this).val()=='other'){
          $(this).parent().parent().find('.other').show();
        }else{
          $(this).parent().parent().find('.other').val('')
          $(this).parent().parent().find('.other').hide();
        }
      })      

    });

    function animateSlides(){
      $show = $('.slides > .show');
      $hide = $('.slides > .hide');

      $show.animate({opacity:0},1000,'swing',function(){
        $hide.removeClass('hide');
        $hide.addClass('show');

        $slideno = $("input[name='hiddenslidenom']").val();
//        $show.attr('src','/mod/thecmoclub/graphics/slides/'+$slideno+'.jpg?new=1');
        $show.attr('src','/mod/thecmoclub/graphics/slides/'+$slideno+'.jpg');
        $show.removeClass('show');
        $show.addClass('hide');
        $show.css('opacity','1');

        $slideno++;
        if($slideno>38){
          $slideno = -8
        }
        $("input[name='hiddenslidenom']").val($slideno);
      });

    }
