﻿// JScript File
var d = document
var browser = {
  isIE: (navigator.userAgent.indexOf("MSIE") != -1 && !(!window.attachEvent)),
  isFF: (navigator.userAgent.indexOf("Firefox") != -1 && !window.attachEvent),
  isOpera: navigator.userAgent.indexOf("Opera") != -1,
  isSafari: navigator.userAgent.indexOf("Safari") != -1,
  isCompliant: !(!window.addEventListener),
  height: 0,
  width: 0
};

if (browser.isCompliant)
  window.addEventListener('DOMContentLoaded', setBrowserDimensions, false);

window.onresize = setBrowserDimensions;

function setBrowserDimensions() {
  if (window.innerWidth)
  {
	  browser.width = window.innerWidth;
	  browser.height =  window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientWidth)
  {
	  browser.width = document.documentElement.clientWidth;
	  browser.height = document.documentElement.clientHeight;
  }
  else if (document.body)
  {
	  browser.width = document.body.clientWidth;
	  browser.height = document.body.clientHeight;
  }
}

String.prototype.startsWith = function(t, i) {
  if (i == false) {
    return
    (t == this.substring(0, t.length));
  } else {
    return (t.toLowerCase()
== this.substring(0, t.length).toLowerCase());
  }
}

String.prototype.endsWith = function(t, i) {
  if (i == false) {
    return (t
== this.substring(this.length - t.length));
  } else {
    return
    (t.toLowerCase() == this.substring(this.length -
t.length).toLowerCase());
  }
} 
 
function submitForm(btnID, e) {
  if (!e)
    return true;
    
  if (e.which || e.keyCode){
    if ((e.which == 13) || (e.keyCode == 13)) {
      var btn = document.getElementById(btnID);
      if (btn) {
        btn.click();  
      }
        return false;
    }
  } else {
    return true;
  }
}

function onInputFocus(e) {
  if (!e)
    return false;
    
  var obj = window.event ? e.srcElement : e.target;
  obj.className += " focus";
}

function onInputBlur(e) {
  if (!e)
    return false;
    
  var obj = window.event ? e.srcElement : e.target;
  obj.className = obj.className.replace("focus", "");
}

function openRadWindow(location, name, height, width) {
  if (!name)
    name = "popup";
    
  var wnd = window.radopen(location, name);
  var winHeight;
  var winWidth;

  if (height) { winHeight = height; } else { winHeight = 500 }
  
  if (width) { winWidth = width; } else { winWidth = 650; }
  
  wnd.setSize(winWidth, winHeight);
  wnd.center();
  if (browser.height <= (wnd.get_height()) || browser.width <= (wnd.get_width()))
    wnd.maximize();

  return false;
}

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

/********************************************************* Session Info ******************************************************/
var SessionInterval;
var timeRemaining;

function setSessionInfo(timeout) {
  var div = d.getElementById('divSessionInfo');
  if (!div)
    return;
  if (SessionInterval)
    clearInterval(SessionInterval);
    
  var now = new Date();
  time = new Date(timeout);
  timeRemaining = time.getTime();
  
  div.innerHTML = Math.floor((timeRemaining - now.getTime()) / (1000 * 60) + 1) + ' minutes';
  SessionInterval = setInterval('sessionTick()', '60000');
}

function sessionTick() {
  var div = d.getElementById('divSessionInfo');
  if (!div) {
    clearInterval(SessionInterval);
    return;
  }

  var now = new Date()  
  if (timeRemaining - now.getTime() <= 0) {
    div.innerHTML = "Expired";
    window.location = window.location;
  } else {
    div.innerHTML = Math.floor((timeRemaining - now.getTime()) / (1000 * 60) + 1) + ' minutes';
  }
}
