// JavaScript Document

var xmlHttp

var ajaxFieldId   // general variable of the field for returned code from Ajax
var fdBackField    // general variable for the field of feedback error
var fdBackMsgField    // general variable for the field of feedback error message
var errorMsgField    // general variable for the error message field



// a commonly used function: generalRequest()  - used when no parameter is passed
function generalRequest(theField, theFile)
{
// theField : the ajax field where the returned text goes
// theFile : the php file to call

  ajaxFieldId=theField
  fdBackField="generalfdbk"
  fdBackMsgField="generalfdbkmsg"
  errorMsgField="generalErrorMsg"


xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  }
  

var url=theFile
url=url+"?sid="+Math.random()
url=encodeURI(url);
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 









//two commonly used functions: stateChanged and GetXmlHttpObject
function stateChanged()
{ 
document.getElementById("busysign").setAttribute("style","display:none")


if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  { 

  document.getElementById(ajaxFieldId).innerHTML = xmlHttp.responseText
  document.getElementById(errorMsgField).innerHTML = ""

  if(document.getElementById(fdBackField).getAttribute("name")=="n")
    {document.getElementById(errorMsgField).innerHTML=document.getElementById(fdBackMsgField).getAttribute("name")}
  if(document.getElementById(fdBackField).getAttribute("name")=="y")
    {window.location.reload()}
  if(document.getElementById(fdBackField).getAttribute("name")=="r")
    {window.location = document.getElementById(fdBackMsgField).getAttribute("name")}  } 
}


function GetXmlHttpObject()
{

document.getElementById("busysign").setAttribute("style","display:inline")

var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
