function get_screen_width()
{
    return screen.width;
}

function get_screen_height()
{
    return screen.height;
}

function get_window_width()
{
    /*
     * See also:
     *    http://www.quirksmode.org/dom/w3c_cssom.html
     *    http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
     */
    var width = 0;
    if ( window.innerWidth != null) {
	width = window.innerWidth;
    } else if (document.documentElement.clientWidth) {
	width = document.documentElement.clientWidth;
    } else if (document.body.clientWidth != null) {
	width = document.body.clientWidth;
    }
    return width;
}
function get_window_height()
{
    /*
     * See also:
     *    http://www.quirksmode.org/dom/w3c_cssom.html
     *    http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
     */
    var height = 0;
    if ( window.innerHeight != null) {
	height = window.innerHeight;
    } else if (document.documentElement.clientHeight) {
	height = document.documentElement.clientHeight;
    } else if (document.body.clientHeight != null) {
	height = document.body.clientHeight;
    }
    return height;
}

function update_width(form)
{
    if ( form ) {
	form.screenx.value = get_screen_width();
	form.windowx.value = get_window_width();
	form.screeny.value = get_screen_height();
	form.windowy.value = get_window_height();
    }
}


// function resizeLink()
// {
//   obj = document.getElementById('viewlink');
//   if (obj) {
//     obj.href = obj.href + '&screenx='+get_screen_width() + '&windowx=' + get_window_width();
//   }
// }

function getElementByName(target)
{
    if( document.getElementById ) {
	element = document.getElementById(target);
    } else if( document.all ) {
	element = document.all[target];
    } else if( document.layers ) {
	element = document.layers[target];
    }
    return element;
}

function decToHex(dec)
{
  var hexStr = "0123456789ABCDEF";
  var low = dec % 16;
  var high = (dec - low)/16;
  hex = "" + hexStr.charAt(high) + hexStr.charAt(low);
  return hex;
}

function SecToTime(seconds)
{
  var hours = Math.floor(seconds/3600);
  var seconds = seconds%3600;
  var minutes = Math.floor(seconds/60);
  seconds = Math.round(seconds%60);

  if (hours) {
    time = hours + " " + (hours == 1 ? stringHour : stringHours) + ", ";
    time += minutes + " " + (minutes == 1 ? stringMinute : stringMinutes) + ", ";
    time += seconds + " " + (seconds == 1 ? stringSecond : stringSeconds);
  } else if (minutes) {
    time = minutes + " " + (minutes == 1 ? stringMinute : stringMinutes) + ", ";
    time += seconds + " " + (seconds == 1 ? stringSecond : stringSeconds);
  } else {
    time = seconds + " " + (seconds == 1 ? stringSecond : stringSeconds);
  }
  return time;
}

function MillisToDate(millis)
{
  var date = new Date(millis);

  var year = date.getFullYear();

  var month = date.getMonth() + 1;
  if (month < 10)
    month = "0" + month;

  var day = date.getDate();
  if (day < 10)
    day = "0" + day;

  var hours = date.getHours();
  if (hours < 10)
    hours = "0" + hours;

  var minutes = date.getMinutes();
  if (minutes < 10)
    minutes = "0" + minutes;

  var seconds = date.getSeconds();
  if (seconds < 10)
    seconds = "0" + seconds;

  return year  + "-" + month   + "-" + day + "_" +
    hours + "-" + minutes + "-" + seconds;
}

function getXMLHTTPRequest() {
  try {
    req = new XMLHttpRequest();
  } catch(err1) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (err2) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (err3) {
        req = false;
      } 
    } 
  }
  return req;
}

function useHttpResponse_startul(http_obj) {
  if (http_obj.readyState == 4) {
    if (http_obj.status == 200) { 
      // TODO: check response?
    }
  }
}

function getCurrentSec() {
  var da = new Date();
  currtime_sec = Math.round(da.getTime()/1000);
  return currtime_sec;
}

function confirmAnchor(url,message)
{
  if (!confirm(message))
    return;
  location.href=url;
}

