﻿/* Returns a document's object from its id */
function getObject(id)
{
	if(document.all) return document.all[id];
	else return document.getElementById(id);
}

function setCookie( name, value, expires, path, domain, secure ) 
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

/* Opens a new window */
function openWindow(url,width,height,toolbar,statusbar,linkbar,menubar,scrollbar,resize,blur)
{
	var x = (screen.width  - width) / 2;
	var y = (screen.height - height) / 2;
	var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y;
	toolbar=(toolbar)?'yes':'no'; statusbar=(statusbar)?'yes':'no'; linkbar=(linkbar)?'yes':'no'; menubar=(menubar)?'yes':'no'; scrollbar=(scrollbar)?'yes':'no'; resize=(resize)?'yes':'no';
	var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+scrollbar+',width='+width+',height='+height+',toolbar='+toolbar+',status='+statusbar+',menubar='+menubar+',links='+linkbar+',resizable='+resize+t);
	if(blur)
	{
	    try { x.blur(); } catch(ex) {}
	}
	else x.focus();
}

/* Add to favorites */
function addToFavorites()
{
  try
  {
  if (window.external)
  {
    if (arguments.length < 1)
      window.external.AddFavorite(location.href, document.title);
    if (arguments.length == 1)
      window.external.AddFavorite(location.href, arguments[0]);
    if (arguments.length == 2)
      window.external.AddFavorite(arguments[0], arguments[1]);
  }
  else
    alert("Sorry, your browser doesn't support automated bookmarks.\nYou'll have to do it manually.");
  }
  catch(ex) {alert("Sorry, your browser doesn't support automated bookmarks.\nYou'll have to do it manually.");}
}

function autoTab(input, len, e)
{
    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; // Filters out alt, tab, delete, ctrl, arrows, etc
    if (input.value.length >= len && !containsElement(filter,keyCode)) 
    {
      input.value = input.value.slice(0, len);
      input.form[(getIndex(input)+1) % input.form.length].focus();
    } 
    function containsElement(arr, ele) 
    {
      var found = false, index = 0;
      while(!found && index < arr.length)
      if(arr[index] == ele)
      found = true;
      else
      index++;
      return found;
    } 
    function getIndex(input) 
    {
          var index = -1, i = 0, found = false;
          while (i < input.form.length && index == -1)
          if (input.form[i] == input)index = i;
          else i++;
          return index;
    }
    return true;
}

