// <![CDATA[

function setCheckboxes(the_form, the_elements, do_check) {
    var elts      = document.forms[the_form].elements[the_elements]
    var elts_cnt  = elts.length;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        }
    }

    return true;
}

function invertSelection(the_form, element_name) {
    var elements    = document.forms[the_form].elements[element_name];
    var count    = elements.length;

    if (count) {
        for (var i = 0; i < count; i++) {
            if(elements[i].checked == true) {
                elements[i].checked = false;
            } else {
                elements[i].checked = true;
            }
        }
    }

    return true;
}

function Popup(url, window_name, window_width, window_height) {
    settings=
    "toolbar=no,location=no,directories=no,"+
    "status=no,menubar=no,scrollbars=yes,"+
    "resizable=yes,width="+window_width+",height="+window_height;


    NewWindow=window.open(url,window_name,settings);
}


function icon(theicon) {
    document.input.message.value += theicon;
    document.input.message.focus();
}

self.name = 'mainwindow';

$(document).ready(function(){

  if ( $('#cpaPromo').length > 0 )
  {
    $.ajax({
      type:'get',
      dataType:'jsonp',
      url:SITE_URL + 'apps/cpa/ajax',
      success:function( data )
      {
        $( '#cpaPromo' ).removeClass( 'cpaLoading' ).html( data.markup );
        CPA.Init();
        eval( data.uiJS );
        if ( data.assets )
        {
          $( 'head' ).append( data.assets );
        }
      }
    });
  }

  /**
   * Quick Search
   */
  var qsText = $('#quickSearchBox').val();
  var qsColor = $('#quickSearchBox').css('color');
  $('#quickSearchBox').click(function(){
    var val = $.trim( $(this).val() );
    if ( val == qsText )
    {
      $(this).val('').css('color', '#CCC');
    }
  }).blur(function(){
    if ( $.trim( $(this).val() ) == '' )
    {
      $(this).val( qsText ).css('color', qsColor);
    }
  });

 /**
  * Account dropdown
  * IMPORTANT: If updating this code, please also update it in common.js, pimp index.tpl, and site.unpack.js
  */
  $( '#accountIcon' ).click( function(){
    showAccountMenu();
  });

  /* 
   * show the account dropdown menu and change the necessary css
   */
  function showAccountMenu()
  {
    adsControl.hideAds();

    $( '#accountMenu' ).slideDown( 'fast', function(){
      $( document ).one( 'click.account', hideAccountMenu );
    });

    $( '#accountIcon' ).addClass( 'accountBoxOpen' );
  }

  /* 
   * hide the account dropdown menu and change the necessary css back
   */
  function hideAccountMenu()
  {
    $( '#accountMenu' ).slideUp( 'fast', function(){
      $( '#accountIcon' ).removeClass( 'accountBoxOpen' );
      $( document ).unbind( 'click.account' );
    });

    adsControl.showAds( );
  }

  /**
   * Search dropdown
   */
  $( '#searchIcon' ).click(function(){
    showSearchMenu();
  });

  /**
   * Show the search dropdown menu and change necessary css
   */
  function showSearchMenu()
  {
    $( '#siteSearchMenu' ).slideDown( 'fast', function(){
      $(document).bind('click.search', function(e) {
        hideSearchMenu();
      });
    });

    $( '#searchIcon' ).addClass( 'searchBoxOpen' );
  }
  /**
   * Hide the search dropdown menu and revert css
   */
  function hideSearchMenu()
  {
    $( '#siteSearchMenu' ).slideUp( 'fast', function(){
      $( '#searchIcon' ).removeClass( 'searchBoxOpen' );
      $(document).unbind( 'click.search' );
    });
  }

  /**
   * Profile dropdown
   */
  $('#profileIconOverlay').click(function(){
    showProfileMenu();
  });

  /**
   * Show the profile dropdown menu and change necessary css
   */
  function showProfileMenu()
  {
    adsControl.hideAds( );
    $('#profileMenu').slideDown('fast',function(){
      $(document).one('click.profile', hideProfileMenu);
    });
    $('#profileIcon').addClass( 'profileBoxOpen' );

  }
  /**
   * Hide the profile dropdown menu and revert css
   */
  function hideProfileMenu()
  {
    $('#profileMenu').slideUp('fast',function(){
      $('#profileIcon').removeClass( 'profileBoxOpen' );
      $(document).unbind('click.profile');
    });
    adsControl.showAds( );
  }

});

var adsControl = {
  hiddenAds : [ ],

  hideAds : function( )
  {
	adsControl.hiddenAds = $('embed, object, iframe').filter(':visible');
	adsControl.hiddenAds.each( function( ){
      var t = $(this);
      var p = t.parent( );
      t.parent( ).width( p.width( ) );
      t.parent( ).height( p.height( ) );
    }).hide( );
  },

  showAds : function( )
  {
    adsControl.hiddenAds = $('embed, object, iframe').filter(':hidden');
    if ( adsControl.hiddenAds.length > 0 )
    {
      adsControl.hiddenAds.show( );
    }
  }
};

var MyYearbook = {
  BootLoader : {
    add : function ( url )
    {
      if ( url ) {
        script = document.createElement("script");
        script.setAttribute("type","text/javascript");
        script.setAttribute("src",url);
        document.getElementsByTagName("head").item(0).appendChild(script);
      }
    }
  },
  isLegacy : function( )
  {
    return true;
  }
};

MyYearbook.currentServiceName = 'quiz';

// ]]>

