// JavaScript Document

var percent=0;

function infoBar(message,delay){

infoBarObject=document.getElementById('infoBar');
document.getElementById('infoMessage').innerHTML=message;
( (delay) ? barUp(delay) : barUp(1000) );
}

function barUp(){
 percent=percent+10;
 if(percent<=100){
  infoBarObject.style.height=(1.3*(percent/100))+'em';
  t=setTimeout("barUp();",0);
 } 
}
 
function barDown(){
 percent=percent-10;
 if(percent>=1){
  infoBarObject.style.height=(1.3*(percent/100))+'em';
  t=setTimeout("barDown();",0);
 } else {}
}

var xmlhttp=new Array();
image1 = new Image();
image1.src = "http://www.elkram.com/ajax/wait.gif";

image2 = new Image();
image2.src = "http://www.elkram.com/ajax/good.gif";
image2 = new Image();
image2.src = "http://www.elkram.com/ajax/bad.gif";

var answer;

function sendRequest(target, postNames, postValues, notifier, result){ //Ajax interface
document.getElementById(notifier).innerHTML='<img src="http://www.elkram.com/ajax/wait.gif">';
x=xmlhttp.length;
var sendString='';
for(i in postNames){sendString+=postNames[i]+'='+postValues[i]+'&';}
//alert(sendString);
try {// XMLHttpRequest tester
xmlhttp[x] = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
infobar('xmlHTTPrequest is required for this site, please use a modern browser',3000);
}

    xmlhttp[x].onreadystatechange = triggered;
    xmlhttp[x].open("POST",target,true);
    xmlhttp[x].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp[x].send(sendString); //Send post variables
    
    
    function triggered() { //state change
    
    if ((xmlhttp[x].readyState == 4) && (xmlhttp[x].status == 200)) { //Done loading and it's all good
    document.getElementById(notifier).innerHTML='<img src="http://www.elkram.com/ajax/good.gif">'
    answer=xmlhttp[x].responseText; // return a result from php
    result;
    } else if((xmlhttp[x].readyState == 4) && (xmlhttp[x].status != 200)){
    document.getElementById(notifier).innerHTML='<img src="http://www.elkram.com/ajax/bad.gif">'
    }
    }
}

function gbID(elementID){
return document.getElementById(elementID);
}

function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.update = function(passNames,passValues,notifierArray,postMethod) { 
    //notifier array is [notifier element ID, loading HTML, ok HTML, bad HTML]
    if(notifierArray[0] != ''){
    that.notifier=gbID(notifierArray[0]);
    that.notifier.innerHTML=notifierArray[1];
    }
    
    that.sendString='';
    that.cleanValue=new Array();
    for(i in passNames){
      
      passValues[i]=String(passValues[i]).replace(/&/g, "%26").replace(/\+/g,"%2B");
      that.sendString+=passNames[i]+'='+passValues[i]+'&';
      
      }
    
    if (that.updating) { return false; }
    that.AJAX = null; 

    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest(); //non IE             
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP"); //IE
    }                                             
    if (that.AJAX==null) {                             
      return false;  //no ajax
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4 && that.AJAX.status == 200) {             
          that.notifier.innerHTML=notifierArray[2];                            
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                
          
        } else if(that.AJAX.readyState==4 && that.AJAX.status != 200){
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null; 
          that.notifier.innerHTML=notifierArray[3];
          }                                                     
      }                                                       
      if (/post/i.test(postMethod)) {
        var uri=urlCall;
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length",that.sendString);
        that.AJAX.send(that.sendString);
      } else {
        var uri=urlCall+'?'+that.sendString; 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

function checkExecute(e,focusToID){ //checks for important keypresses
  var keynum
  if(window.event){ //IE
    keynum = e.keyCode
  }else if(e.which){ // Netscape/Firefox/Opera
    keynum = e.which
  }
  
  if(keynum==13){//enter
    focusOn(focusToID);
    return false;
  }
  

}

