﻿// see http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/
function clickButton(e, buttonid) {
  if (e.keyCode == 13) {
    var b = document.getElementById(buttonid);
    if (b) {
      if (typeof (b.click) == 'undefined') {
        b.click = function() {
          var result = true;
          if (b.onclick) result = b.onclick();
          if (typeof (result) == 'undefined' || result) {
            eval(b.getAttribute('href'));
          }
        }
      }

      if (typeof (b.click) != "undefined") {
        b.click();
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
        return false;
      }
    }
  }
  return true;
}

// Functions for JW wmv player (see http://www.jeroenwijering.com/?item=JW_WMV_Player)

// height is 158px (video) + 20px (control bar) = 178px
function createWMVPlayer(thePlaceholder, theFile, theImage, theHeight, theWidth, theAutostart) {
  var src = '/_layouts/BSA/js/wmvplayer.xaml';
  if (!theFile) theFile='';
  if (!theHeight) theHeight='178';
  if (!theWidth) theWidth='280';
  if (!theAutostart) theAutostart='false';
  if (!theImage) theImage='';
  var cfg = {
      file:theFile
    , image:theImage
    , width:theWidth
    , height:theHeight
    , backgroundcolor:'000000'
    , screencolor:'666666'
    , windowless:'true'
    , autostart:theAutostart
  };
  var ply = new jeroenwijering.Player(document.getElementById(thePlaceholder), src, cfg);
  return ply;
}

// Get the query parameter string.
// Usage:  If URL is "blah.com/index.html?view=classic", then do this to get the value of "view":
//   var parm = $.urlParam('view');
// See http://stackoverflow.com/questions/901115/get-querystring-with-jquery.
$.urlParam = function (name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return 0; }
    return results[1] || 0;
};


// Utility functions that require jQuery
$(function() {
  // This implements target="_blank" for XHTML-Strict for all external URLs.  See http://www.badlydrawntoy.com/2009/03/03/replacing-target_blank-for-strict-xhtml-using-jquery-redux/
  $("a[href*='http://']:not([href*='"+location.hostname+"'])").click( function() { window.open(this.href); return false; });

  // Implement table zebra-striping (when table has class="zebra")
  $(".zebra tr:odd").addClass("alt");
  
  // Popups.  Put width and height in "rel" attribute.  Example: <a class="popupitem" href="blah.aspx" rel="width=420,height=230">Click me</a>
  $("a.popupitem").click( function() { window.open(this.href, '', $(this).attr('rel')+',scrollbars=1,resizable=1'); return false; });

  // NOTE: Following is no longer applicable since we're using SiteMapProvider="CurrentNavSiteMapProviderNoEncode" in the master page.
  // Hide "Pages" node from breadcrumbs.  Find the "Pages" nodes by looking for href that ends with "PageType=0".
  //$("#cstm-crumbs a[href$='PageType=0']").css('display', 'none');
});

