var baseUrl;
var lastEventId = 0;

function Tnumeric(objEvent)
{
  isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
  isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  if(isIE)
  {
    iKeyCode = objEvent.keyCode;
  }
  else
  {
    iKeyCode = objEvent.which;
  }
  return (((iKeyCode - 48 >= 0) && (iKeyCode - 48 <= 9))
      || iKeyCode == 13 || iKeyCode == 0 || iKeyCode == 8 ) ? true : false;
}

keys = {
  getCharCode: function(evt)
  {
    return (evt.charCode) ? evt.charCode :
           ((evt.which) ? evt.which : evt.keyCode);
  },
  isEnter:function(charCode)
  {
    return (charCode == 13);
  },

  submitViaEnter:function(evt)
  {
    evt = (evt) ? evt : event;
    charCode = this.getCharCode(evt);
    if (this.isEnter(charCode))
    {
      document.loginform.submit();
      return false;
    }
    return true;
  }
}

/**
* Load new match score
**/
function loadMatches()
{
	$.getJSON(baseUrl + "jsonmatchday.htm?eventid=" + lastEventId,
    function(data)
    {
      var encoded = $.toJSON(data);
      var status = $.evalJSON(encoded).code;     
      var message = $.evalJSON(encoded).message;
      
      if ( status == '0' )
      {
        lastEventId = $.evalJSON(encoded).lastEventId;
      	for( i=0;i<$.evalJSON(encoded).matchesToday.length;i++)
      	{
        	var matchDay = $.evalJSON(encoded).matchesToday[i];
        	for( j=0;j<matchDay.matches.length;j++)
        	{
          	var match = matchDay.matches[j];
          	$('#score-' + match.id).html(match.morkHeimalids + "-" + match.morkUtilids);

            if ( match.stadaLeiks == 'Staðfest')
              $('#sms-' + match.id).html("Final");  
        	}       	
      	}
      }      				      
    });    
}

function loadTooltips()
{
	//Select all anchor tag with rel set to tooltip  
  $('a[rel=tooltip]').mouseover(function(e) {             
  	//Grab the title attribute's value and assign it to a variable  
    var tip = $(this).attr('title');                 
    //Remove the title attribute's to avoid the native tooltip from the browser  
    $(this).attr('title','');             
    //Append the tooltip template and its value  
    $(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');                  
    //Set the X and Y axis of the tooltip  
    $('#tooltip').css('top', e.pageY + 10 );  
    $('#tooltip').css('left', e.pageX + 20 );  
           
    //Show the tooltip with faceIn effect  
    $('#tooltip').fadeIn('500');  
    $('#tooltip').fadeTo('10',0.8);             
  }).mousemove(function(e) {         
  	//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse  
    $('#tooltip').css('top', e.pageY + 10 );  
    $('#tooltip').css('left', e.pageX + 20 );  
           
  }).mouseout(function() {         
  	//Put back the title attribute's value  
    $(this).attr('title',$('.tipBody').html());         
    //Remove the appended tooltip template  
    $(this).children('div#tooltip').remove();             
  });  
}