var pageText = $H({})
function submitForm() {
	document.forms[0].target = 'foo';
	window.open('',document.forms[0].target,'width=485,height=640 ,toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	document.forms[0].submit();
	return false; 
}
 function scrollCalendar() {
 	var calendar = document.getElementById("scroll-calendar");
 	if (calendar != null) {
 		calendar.scrollTop = 170;
 	}
 }
 function showHelp(id, message, unitId) {
    var help = document.getElementById(id);
    var helpShowHide = document.getElementById(id + 'ShowHide');
    var shownText = help.getAttribute("shownText");
    if (shownText == "\n" || shownText == "0") {
      help.innerHTML = pageText[unitId + "ShownText"];
      help.setAttribute("shownText","1");
      saveToCookie("portal.help", id, '1');  
      helpShowHide.innerHTML = '<img src="icons/close.gif"><img src="icons/help.png">';
    } else {
      help.setAttribute("shownText", "0");
      help.innerHTML = "";
      eraseFromCookie("portal.help", id);
      helpShowHide.innerHTML = '<img src="icons/open.gif"><img src="icons/help.png"><img src="Resources/spacer.gif" width="5"/><b>' + message + '</b>';
    }
  }
  
  function restoreHelp(id, message, unitId) {
    var help = document.getElementById(id);
    var helpShowHide = document.getElementById(id + 'ShowHide');
    var shownText = help.getAttribute("shownText");
    if (readFromCookie("portal.help", id, '0') == '0') {
      eraseFromCookie("portal.help", id);
      helpShowHide.innerHTML = '<img src="icons/open.gif"><img src="icons/help.png"><img src="Resources/spacer.gif" width="5"/><b>' + message+ '</b>';
    } else {
    	help.setAttribute("shownText", "1");
      help.innerHTML = eval(unitId + "ShownText");;
      saveToCookie("portal.help", id, '1'); 
      helpShowHide.innerHTML = '<img src="icons/close.gif"><img src="icons/help.png">';
    }

}
   function saveToCookie(cookieName, name, value)
{
    var cookieValue = getCookieValue(cookieName);
    cookieValue = addOrAppendToValue(name, value, cookieValue);

    saveCookie(cookieName, cookieValue, 365);
}

function readFromCookie(cookieName, name, defaultValue)
{
    var cookieValue = getCookieValue(cookieName);
    var value = getValueFrom(name, cookieValue);

    if(value != null)
    {
        return value;
    }

    return defaultValue;
}

function eraseFromCookie(cookieName, name)
{
    saveToCookie(cookieName, name,"");
}

function getValueFrom(name, cookieValue)
{
    var newCookieValue = null;
    // a null cookieValue is just the first time through so create it
    if(cookieValue == null)
    {
        cookieValue = "";
    }
    var eq = name + "=";
    var cookieParts = cookieValue.split('|');
    for(var i = 0; i < cookieParts.length; i++) {
        var cp = cookieParts[i];
        while (cp.charAt(0)==' ') {
            cp = cp.substring(1,cp.length);
        }
        // rebuild the value string exluding the named portion passed in
        if (cp.indexOf(name) == 0) {
            return cp.substring(eq.length, cp.length);
        }
    }
    return null;
}

//either append or replace the value in the cookie string
function addOrAppendToValue(name, value, cookieValue)
{
    var newCookieValue = "";
    // a null cookieValue is just the first time through so create it
    if(cookieValue == null)
    {
        cookieValue = "";
    }

    var cookieParts = cookieValue.split('|');
    for(var i = 0; i < cookieParts.length; i++) {
        var cp = cookieParts[i];

        // ignore any empty tokens
        if(cp != "")
        {
            while (cp.charAt(0)==' ') {
                cp = cp.substring(1,cp.length);
            }
            // rebuild the value string exluding the named portion passed in
            if (cp.indexOf(name) != 0) {
                newCookieValue += cp + "|";
            }
        }
    }

    // always append the value passed in if it is not null or empty
    if(value != null && value != '')
    {
        var pair = name + "=" + value;
        if((newCookieValue.length + pair.length) < 4020)
        {
            newCookieValue += pair;
        }
    }
    return newCookieValue;
}

function getCookieValue(name)
{
    var eq = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i<ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(eq) == 0) {
            return c.substring(eq.length,c.length);
        }
    }

    return null;
}

function saveCookie(name,value,days)
{
  var ex;
  if (days) {
    var d = new Date();
    d.setTime(d.getTime()+(days*24*60*60*1000));
    ex = "; expires="+d.toGMTString();
  }
  else {
    ex = "";
  }
  document.cookie = name + "=" + value + ex;
}

/*
Reads a cookie. If none exists, then it returns and 
*/
function readCookie(name, defaultValue)
{
  var cookieVal = getCookieValue(name);
  if(cookieVal != null)
  {
      return cookieVal;
  }

  // No cookie found, then save a new one as on!
  if (defaultValue)
  {
      saveCookie(name, defaultValue, 365);
      return defaultValue;
  }
  else
  {
      return null;
  }
}

function eraseCookie(name)
{
  saveCookie(name,"",-1);
}
function show(evt, elementId) {
  var elem = document.getElementById(elementId);
  evt = (evt) ? evt : ((window.event) ? window.event : "");
  if (elem) {
    if (elem.style.visibility=="visible") {
      elem.style.visibility="hidden";
    } else {
      elem.style.visibility="visible";
      elem.style.left = evt.clientX - 200;
      elem.style.top = evt.clientY;
    }
  }
}


function disableOther(array) {
  for (var i = 0; i < array.length; i++) {
    document.getElementById(array[i]).disabled = 'disabled';
  }
}

/*function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}*/

function changeTimes(first, second, action) {
  firstElem = document.getElementById(first);
  secondElem = document.getElementById(second);
  if (firstElem == null) {
    firstElem = document.getElementsByName(first)[0];
  }
  
  if (secondElem == null) {
    secondElem = document.getElementsByName(second)[0];
  }
  
  
  if (action == 'disable') {
    start = firstElem.selectedIndex;
    end = secondElem.selectedIndex;
    firstElem.selectedIndex = 1;
    secondElem.selectedIndex = secondElem.options.length - 1;
  } else {
    firstElem.selectedIndex = start;
    secondElem.selectedIndex = end;
  }
}

function refreshPanels() {
  var elem = document.getElementById("refresh");
  elem.style.display='inline';
}

function confirm_deletion(dluLink){
      	if (confirm('Delete selected item ?')) { return true; };
	return false; 
}

function imageswap(name, imagesrc)  
{
   eval("document." + name + ".src = '" + imagesrc + "'");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function gen(texts,links,t,tl)
{
  //var texts = new Array("","","")
  //var links = new Array("","","")
  //var t
  //var tl
  var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  
  var map = InternetExplorer ? menu : document.embeds("menu");
	for (i=0;i<=t;i++)
	{
  	map.SetVariable('m' + (i+1), texts[i]);
  	map.SetVariable('l' + (i+1), links[i]);
	}
	map.SetVariable('nt', t);
	map.SetVariable('title', tl);
  
  	
}
  
function gens(texts,links,t,tl)
{
  //var texts = new Array("","","")
  //var links = new Array("","","")
  //var t
  //var tl
  var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  
  var map = InternetExplorer ? menu : document.embeds("menu");
	for (i=0;i<=t;i++)
	{
  	map.SetVariable('ms' + (i+1), texts[i]);
  	map.SetVariable('ls' + (i+1), links[i]);
	}
	map.SetVariable('nts', t);
	map.SetVariable('titles', tl);
  
	
}
/*
Adds a class name to the given element
*/
function addClassName(element, classNameToAdd) 
{
    if (element)
    {
        element.className = element.className + ' ' + classNameToAdd;
    }
}

/*
 Removes all class names to from the given element
 */
function removeClassName(element, classNameToRemove) {
    if (element)
    {
        element.className = (' ' + element.className + ' ').replace(' ' + classNameToRemove + ' ', ' ');
    }
}

function toggleMenu(elementId) {
  var elem = document.getElementById(elementId);
  var img = document.getElementById(elementId + 'Img');
  if (elem) {
    if (readFromCookie("bts.cookie", elementId, '1') == '1') {
      elem.style.display = "none";
      saveToCookie("bts.cookie", elementId, '0');   
      img.src='icons/show.gif';
    } else {
      elem.style.display = "";
      eraseFromCookie("bts.cookie", elementId);
      img.src='icons/hide.gif';
    }
  }
}
function restoreMenu(elementId) {
  var elem = document.getElementById(elementId);
  var img = document.getElementById(elementId + 'Img');
  if (elem) {
    if (readFromCookie("bts.cookie", elementId, '1') != '1') {
      elem.style.display = "none";   
      img.src='icons/show.gif';   
    } else {
      elem.style.display = "";
      img.src='icons/hide.gif';
    }
  }
}
function toggle(node) 
  {
    var table = node.parentNode.parentNode;
    var toHide = table.getElementsByTagName("tr").item(1);
    var parentTr = node.parentNode;
    
    if (readFromCookie("bts.cookie", node.id, '1') == '1') {
      toHide.style.display = "none";
      removeClassName(parentTr, 'headerOpened');
      addClassName(parentTr, 'headerClosed');
      saveToCookie("bts.cookie", node.id, '0');
      
    } else {
      toHide.style.display = "";
      removeClassName(parentTr, 'headerClosed');
      addClassName(parentTr, 'headerOpened');
      eraseFromCookie("bts.cookie", node.id);
    }
  }
    /*
 Similar to toggle. Run this on page load.
*/
function restore(elementId)
{
    var node = document.getElementById(elementId);
    var table = node.parentNode.parentNode;
    var parentTr = node.parentNode;
    var toHide = table.getElementsByTagName("tr").item(1);
    if (toHide)
    {
        if (readFromCookie("bts.cookie", elementId, '1') != '1')
        {
            toHide.style.display = "none";
            removeClassName(parentTr, 'headerOpened');
            addClassName(parentTr, 'headerClosed');
        }
        else
        {
            toHide.style.display = "";
            removeClassName(parentTr, 'headerClosed');
            addClassName(parentTr, 'headerOpened');
        }
    }
}
    function saveToCookie(cookieName, name, value)
{
    var cookieValue = getCookieValue(cookieName);
    cookieValue = addOrAppendToValue(name, value, cookieValue);

    saveCookie(cookieName, cookieValue, 365);
}

function readFromCookie(cookieName, name, defaultValue)
{
    var cookieValue = getCookieValue(cookieName);
    var value = getValueFrom(name, cookieValue);

    if(value != null)
    {
        return value;
    }

    return defaultValue;
}

function eraseFromCookie(cookieName, name)
{
    saveToCookie(cookieName, name,"");
}

function getValueFrom(name, cookieValue)
{
    var newCookieValue = null;
    // a null cookieValue is just the first time through so create it
    if(cookieValue == null)
    {
        cookieValue = "";
    }
    var eq = name + "=";
    var cookieParts = cookieValue.split('|');
    for(var i = 0; i < cookieParts.length; i++) {
        var cp = cookieParts[i];
        while (cp.charAt(0)==' ') {
            cp = cp.substring(1,cp.length);
        }
        // rebuild the value string exluding the named portion passed in
        if (cp.indexOf(name) == 0) {
            return cp.substring(eq.length, cp.length);
        }
    }
    return null;
}

//either append or replace the value in the cookie string
function addOrAppendToValue(name, value, cookieValue)
{
    var newCookieValue = "";
    // a null cookieValue is just the first time through so create it
    if(cookieValue == null)
    {
        cookieValue = "";
    }

    var cookieParts = cookieValue.split('|');
    for(var i = 0; i < cookieParts.length; i++) {
        var cp = cookieParts[i];

        // ignore any empty tokens
        if(cp != "")
        {
            while (cp.charAt(0)==' ') {
                cp = cp.substring(1,cp.length);
            }
            // rebuild the value string exluding the named portion passed in
            if (cp.indexOf(name) != 0) {
                newCookieValue += cp + "|";
            }
        }
    }

    // always append the value passed in if it is not null or empty
    if(value != null && value != '')
    {
        var pair = name + "=" + value;
        if((newCookieValue.length + pair.length) < 4020)
        {
            newCookieValue += pair;
        }
    }
    return newCookieValue;
}

function getCookieValue(name)
{
    var eq = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i<ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(eq) == 0) {
            return c.substring(eq.length,c.length);
        }
    }

    return null;
}

function saveCookie(name,value,days)
{
  var ex;
  if (days) {
    var d = new Date();
    d.setTime(d.getTime()+(days*24*60*60*1000));
    ex = "; expires="+d.toGMTString();
  }
  else {
    ex = "";
  }
  document.cookie = name + "=" + value + ex;
}

/*
Reads a cookie. If none exists, then it returns and 
*/
function readCookie(name, defaultValue)
{
  var cookieVal = getCookieValue(name);
  if(cookieVal != null)
  {
      return cookieVal;
  }

  // No cookie found, then save a new one as on!
  if (defaultValue)
  {
      saveCookie(name, defaultValue, 365);
      return defaultValue;
  }
  else
  {
      return null;
  }
}

function eraseCookie(name)
{
  saveCookie(name,"",-1);
}
function show(evt, elementId) {
  var elem = document.getElementById(elementId);
  evt = (evt) ? evt : ((window.event) ? window.event : "");
  if (elem) {
    if (elem.style.visibility=="visible") {
      elem.style.visibility="hidden";
    } else {
      elem.style.visibility="visible";
      elem.style.left = evt.clientX - 200;
      elem.style.top = evt.clientY;
    }
  }
}



