var browser_name = navigator.appName;
var browser_ver = parseInt(navigator.appVersion, 10);
var browser_colourdepth = window.screen.colorDepth;
var browser_width = 0;
var browser_height = 0;
var setlist = "";
var setlist_page = "";
var setlist_width = 0;
var setlist_height = 0;


function init_setlist(width, height)
{
  setlist_width = width;
  setlist_height = height;
  resize_setlist();
  //setlist_height = height + 16;
  window.onresize = resize_setlist;
  init() ;
}

function init()
{ 
  if (!document.getElementsByTagName)
  {
    return; 
  }
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++)
  { 
    var anchor = anchors[i]; 
    if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) 
    {
      anchor.target = "_blank"; 
    } 
  } 
}


function select_active_image(name)
{
  document.getElementById("img_" + name).src = "images/" + name + "_active.jpg" ;
}

  
function highlight_image(name)
{
  document.getElementById("img_" + name).src = "images/" + name + "_hi.jpg" ;
}


function unhighlight_image(name)
{
  document.getElementById("img_" + name).src = "images/" + name + ".jpg" ;
}


function load_setlist()
{
  var setlist = window.location.search.substr(1, 3) ;
  if ( setlist == "" )
  {
    var setlist_page = "select_date.html" ;
  }
  else
  {
    var setlist_page = "set" + setlist + ".html" ;
  }
  document.write('<object id="setlist_obj" type="text/html" data="' + setlist_page + '"') ;
  document.write(' width="200" height="300" border="0">') ;
  document.write('Your browser does not appear to support embedded objects.') ;
  document.write('</object>') ;
  resize_setlist() ;
}


function resize_setlist()
{
  calc_window_size() ;
  var object_width = Number(browser_width - setlist_width - 15) ;
  var object_height = Number(browser_height - setlist_height - 15) ;
  if (object_width < 10)
  {
    object_width = 10
  }
  if (object_height < 10)
  {
    object_height = 10
  } 

  if (document.setlist_obj_width != String(object_width) || document.setlist_obj.height != String(object_height))
  {
    document.setlist_obj.width = String(object_width);
    document.setlist_obj.height = String(object_height);
    //force_refresh();
  }
  else
  {
//    document.setlist_obj.width = String(object_width);
//    document.setlist_obj.height = String(object_height);
  }
}


function force_refresh()
{
  window.location.reload( false );
}


function calc_window_size()
{
  if ( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    browser_width = window.innerWidth - 20;
    browser_height = window.innerHeight -20;
  }
  else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )  )
  {
    //IE 6+ in 'standards compliant mode'
    browser_width = document.documentElement.clientWidth - 10;
    browser_height = document.documentElement.clientHeight - 10;
  }
  else if ( document.body && ( document.body.clientWidth || document.body.clientHeight )  )
  {
    //IE 4 compatible (inc. IE6 in non-standards mode)
    browser_width = document.body.clientWidth - 10;
    browser_height = document.body.clientHeight;
  }
  else
  {
    // set to 600x400 if we cannot determine size
    browser_width = 600 ;
    browser_height = 400 ;
  }
}


function modify_link(link_id, link_href)
{
  document.getElementById(link_id).href = link_href ;
}

function generate_mailto(person, domain)
{
  var link = "mailto: " + person + "@" + domain;
  window.location = link;
}
