
document.onkeypress = keyListener;
function keyListener(e)
 {
  var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
  var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
  var actualKey=String.fromCharCode(unicode)
  if (actualKey == "~" || actualKey == "~")
   { 
    document.getElementById('optional').innerHTML = '<div>Login: <input type="text" id="login_username" name="login_username" value="" /> Password: <input type="password" name="login_password" value="" /><input type="submit" name="submit" value="&gt;&gt;" /></div>';
    document.getElementById('login_username').focus();
   }
 }
function calcHeight(id)
{
 alert(this.document.body.offsetHeight+"px");
 if (!window.opera && !document.mimeType && document.all && document.getElementById)
   parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
 else if(document.getElementById)
   parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
}    

function revealData(activator,newText,oldText,which)
 {
  if (document.getElementById(which).style.display != 'block') 
   {
    document.getElementById(which).style.display='block';
    activator.innerHTML = newText;
   }
  else
   {
    document.getElementById(which).style.display='none';
    activator.innerHTML = oldText;
   }
 }

 function expandBoot(e)
  {
   var el = document.getElementById(e);
   if (el.style.display != "block")
     el.style.display = "block";
   else
     el.style.display = "none";
  }

 function xmlhttpPost(outputTo,strURL,params) 
  {
   if (document.getElementById(outputTo).innerHTML != '' && params=='')
     document.getElementById(outputTo).innerHTML = '';
   else
    {
     document.getElementById(outputTo).innerHTML = 'Loading...';
     var xmlHttpReq = false;
     var self = this;
     if (window.XMLHttpRequest)        // Mozilla/Safari
       self.xmlHttpReq = new XMLHttpRequest();
     else if (window.ActiveXObject)    // IE
       self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
     self.xmlHttpReq.open('POST', strURL, true);
     self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     self.xmlHttpReq.onreadystatechange = function() 
      { 
       if (self.xmlHttpReq.readyState == 4) 
        updatePage(outputTo, self.xmlHttpReq.responseText); 
      }
     self.xmlHttpReq.send('activeDiv=' + outputTo + '&' + params);
    }
  }

 function updatePage(outputTo,value)
  {
   document.getElementById(outputTo).innerHTML = value;
  }
 function ajaxSubmit(fobj,submitTo,outputTo)
  {
   var getstr = '';
   for (i=0; i < fobj.elements.length; i++) 
    {
     var el = fobj.elements[i];
     switch(el.type)
      {
       case "textarea":
       case "hidden":
       case "text":
       case "password":
         getstr += encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value) + "&";
         break;
       case "select-one":
         if (el.options[el.selectedIndex].value)
           getstr += encodeURIComponent(el.name) + "=" + encodeURIComponent(el.options[el.selectedIndex].value) + "&";
         else if (el.options[el.selectedIndex].text)
           getstr += encodeURIComponent(el.name) + "=" + encodeURIComponent(el.options[el.selectedIndex].text) + "&";
         break;
       case "select-multiple":
         var selLen = el.options.length;
         for (var j=0; j < selLen; j++)
           if (el.options[j].selected)
             getstr += encodeURIComponent(el.name+"[]") + "=" + encodeURIComponent(el.options[j].value) + "&";
         break;
       case "checkbox":
       case "radio":
         if(el.checked)
           getstr += encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value) + "&";
         break;                
      }
    }
   xmlhttpPost(outputTo,submitTo,getstr);
  }

 function copyToList(fromList,toList)
 {
   if (toList.options.length > 0 && toList.options[0].value == 'temp')
     toList.options.length = 0;
   var sel = false;
   for (i=0;i<fromList.options.length;i++)
   {
     var current = fromList.options[i];
     if (current.selected)
     {
       sel = true;
       if (current.value == 'temp')
       {
         alert ('You cannot move this text!');
         return;
       }
       txt = current.text;
       val = current.value;
       toList.options[toList.length] = new Option(txt,val);
       fromList.options[i] = null;
       i--;
     }
   }
 }


// Depricated

 function setTextareaToTinyMCE(sEditorID,sEditorCheck)
  {
   var oEditor = document.getElementById(sEditorID);
   var isTiny = document.getElementById(sEditorCheck);
   if(oEditor && isTiny.value == 'false') 
    {
     tinyMCE.execCommand('mceAddControl', true, sEditorID);
     isTiny.value = 'true';
    }
   else
    {
     tinyMCE.execCommand('mceRemoveControl', true, sEditorID);
     isTiny.value = 'false';
    }
   return;
  }

 function selectAllOptions(el)
  {
   for (var j=0; j<el.options.length; j++) 
     if (!el.options[j].selected) 
       el.options[j].selected = true;
  }


 function CheckAll(thisForm)
  {
   for (var i=0; i < thisForm.elements.length; i++)
    {
     var e = thisForm.elements[i];
     if ((e.name != 'allbox') && (e.type=='checkbox'))
       e.checked = thisForm.allbox.checked;
    }
  }

function sH(e)
 {
  var el = document.getElementById(e);
  if (el)
   {
    if (el.style.display != 'block')
      el.style.display = 'block';
    else
      el.style.display = 'none';
   }
 }

function swapinfo()
 {
  if (document.getElementById('outline').style.display == 'none')
   {
    document.getElementById('outline').style.display='block';
    document.getElementById('details').style.display='none';
   }
  else
   {
    document.getElementById('outline').style.display='none';
    document.getElementById('details').style.display='block';
   }
 }

