function ajax_1()
{
  http_request = false;
  if (window.XMLHttpRequest){http_request = new XMLHttpRequest();if (http_request.overrideMimeType)  http_request.overrideMimeType('text/xml');}
  else if (window.ActiveXObject){try{http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){try{ http_request = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {}}}
  if (!http_request){alert('Giving up :( Cannot create an XMLHTTP instance');return false;}
}

function ajax_2(NestedFunction1,NestedFunction2)
{
  http_request.onreadystatechange = function()
  {
    NestedFunction1();
    if (http_request.readyState == 4)
    {
      if (http_request.status == 200) NestedFunction2();
      else alert('There was a problem with the request. Request status: '+http_request.status);
    }
  };
}

function ajax_3(Place,PostedStuff)
{
  http_request.open('POST', Place, true);
  http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http_request.send(PostedStuff);
}

function ajax_post(Place,PostedStuff,NestedFunctionWhile,NestedFunctionDone)
{
  ajax_1();
  ajax_2(NestedFunctionWhile,NestedFunctionDone);
  ajax_3(Place,PostedStuff);
}

function ProgressBar(place)
{
  if(document.getElementById(place))
  {
         if(http_request.readyState==0) document.getElementById(place).style.visibility='visible';
    else if(http_request.readyState==1) document.getElementById(place).style.visibility='visible';
    else if(http_request.readyState==2) document.getElementById(place).style.visibility='visible';
    else if(http_request.readyState==3) document.getElementById(place).style.visibility='visible';
    else if(http_request.readyState==4) document.getElementById(place).style.visibility='hidden';
  }
}

function AdjournStatus(place)
{
        var status = new Array;
        status[0]='(request: <b>uninitialized<\/b>)';
        status[1]='(request: <b>please wait while the data is loaded<\/b>)';
        status[2]='(request: <b>loaded<\/b>)';
        status[3]='(request: <b>interactive<\/b>)';
        status[4]='(request: <b>complete<\/b>)';
        if(document.getElementById(place))  document.getElementById(place).innerHTML = status[http_request.readyState];
}

var pop_up_params="scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,width=500,height=400";




function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}