/*
 * --- Global scripts ---
 */

$(document).ready(function() {
  $('.onlyNumbers').keydown(isNumeric);
  $('.aControl').focus(function(){
    var $this=$(this);
    var cs = $this.attr('class').split(' ');
    for(i=0; i<cs.length; i++){
      if(cs[i].substring(0, 5) == 'error'){
        $this.removeClass(cs[i]);
      }
    }
  });
});

function isNumeric(k){
  if(k.keyCode >= 96 && k.keyCode <= 105 )
    return true;
  if(k.keyCode >= 48 && k.keyCode <= 57 )
    return true;
  if(k.keyCode == 116 || k.keyCode == 37 || k.keyCode == 39 || k.keyCode == 9
    || k.keyCode == 8 || k.keyCode == 46 || k.keyCode == 13 )
    return true;
  return false;
}

function readMore(id){
  $('#readmore_'+id).hide();
  $('#content_'+id).show();
}

var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial() {
  if (document.getElementById != null) {
    var html = '<HTML>\n<HEAD>\n';

    if (document.getElementsByTagName != null) {
      var headTags = document.getElementsByTagName("head");
      if (headTags.length > 0)
        html += headTags[0].innerHTML;
    }

    html += '\n</HEAD>\n<BODY>\n';

    var printReadyElem = document.getElementById("printReady");

    if (printReadyElem != null) {
      html += printReadyElem.innerHTML;
    } else {
      alert("Could not find the printReady function");
      return;
    }

    html += '\n</BODY>\n</HTML>';

    var printWin = window.open("","printSpecial");
    printWin.document.open();
    printWin.document.write(html);
    if (gAutoPrint)
      printWin.print();
    printWin.document.close();
  } else {
    alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
  }
}

function addToFavorites() {
  var title = document.title;
  var url = window.location.href;

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title);
  } else if (window.opera && window.print) {
    window.external.AddFavorite(url, name);
  }
}

