//##Usage

//#  oEvent=top.oEventQ.CreateEvent()
//#  oEvent.cEvent=""
//#  oEvent.cURL=""
//#  oEvent.oForm=""
//#  oEvent.cEventType="URL"
//#  oEvent.cEventName="Validating dash control field"
//#  oEvent.cEventOk="woohoo"
//#  oEvent.cEventFail="doh"
//#  top.oEventQ.PostEvent(oEvent)

function clsEvent()
{
  this.cEvent="";
  this.cURL="";
  this.oForm="";
  this.cEventType="";
  this.cEventName="";
  this.cEventOk="";
  this.cEventFail="";
  this.cObj1="";
  this.cObj2="";
  this.cObj3="";
}

function evq()
{
this.dummy="hello";
this.calcFrame=""

this.aQueue=new Array();
this.lQ=false;
this.nLastEvent=0;
};


function evq_CreateEvent(){
  var oEV;
oEV=new clsEvent;


  return oEV;
}
function evq_PostEvent(oE){
  nLast=this.nLastEvent;
  this.aQueue[nLast]=oE;
  this.nLastEvent=this.nLastEvent+1;

  if(this.lQ==false){
    this.pollQueue();
  }

}

function evq_Success(){
  oEv=this.aQueue[0];
  cMess=oEv.cEventOk;
  if(cMess.length>0){
    alert(cMess);
  }
  this.DeleteEvent();
  this.pollQueue();
}

function evq_Failed(){
  oEv=this.aQueue[0];
  cMess=oEv.cEventFail;
  if(cMess.length>0){
    alert(cMess);
  }
  else{
    alert("There was a problem with your request")
  }
  this.DeleteEvent();
  this.pollQueue();

}

function evq_DeleteEvent(){


  this.aQueue[0]="";
  nLast=this.nLastEvent-1;
  this.nLastEvent=this.nLastEvent-1

  if(nLast>0){
    for(n=0;n<nLast;n++){
	this.aQueue[n]=this.aQueue[n+1];
        this.aQueue[n+1]="";
    }
  }
  else {
    this.lQ=false
  }
}

function evq_pollQueue()
{
var lDebug
lDebug=false


  if(this.nLastEvent>0)
  {
     this.lQ=true
     oEV=this.aQueue[0];

     switch(oEV.cEventType){
     case "AJAX":
       var xmlHttp;
       try
       {
         xmlHttp=GetXmlHttpObject()
         xmlHttp.onreadystatechange=function()
         {
           if(xmlHttp.readyState==4)
           {
             if(lDebug){
		alert(xmlHttp.responseText)
             }
             else {
             eval(xmlHttp.responseText);
             }
           }
         }
         xmlHttp.open("GET",oEV.cURL,true);
         xmlHttp.send(null);
       }
       catch (e)
       {
         try
         {  // Firefox, Opera 8.0+, Safari  
           xmlHttp=new XMLHttpRequest();
           xmlHttp.onreadystatechange=function()
           {
             if(xmlHttp.readyState==4)
             {
             if(lDebug){
		alert(xmlHttp.responseText)
             }
             else {
               eval(xmlHttp.responseText);
             }
             }
           }
           xmlHttp.open("GET",oEV.cURL,true);
           xmlHttp.send(null);
         }
         catch (e)
         {  // Internet Explorer  
           try
           {    
             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
             xmlHttp.onreadystatechange=function()
             {
               if(xmlHttp.readyState==4)
               {
             if(lDebug){
		alert(xmlHttp.responseText)
             }
             else {

                 eval(xmlHttp.responseText)
}
               }
             }
             xmlHttp.open("GET",oEV.cURL,true);
             xmlHttp.send(null);
           }
           catch (e)
           {    
           try
           {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
             xmlHttp.onreadystatechange=function()
             {
               if(xmlHttp.readyState==4)
               {
             if(lDebug){
		alert(xmlHttp.responseText)
             }
             else {
                 eval(xmlHttp.responseText)
}
               }
             }
             xmlHttp.open("GET",oEV.cURL,true);
             xmlHttp.send(null);
           }
           catch (e)
           {
              this.Failed();
           }
         }
       }
     }


     break;
     case "URL":
	oDoc=top.frames['calc1'].document
	cURL=oEV.cURL
	cObj1=oEV.cObj1
	cObj2=oEV.cObj2
	cObj3=oEV.cObj3
	if(cObj1.length>0){
	  oObj1=eval("top.frames['main'].document.forms[0]."+cObj1)
	  cURL=cURL+"&"+cObj1+"="+escape(oObj1.value)
        }
	if(cObj2.length>0){
	  oObj2=eval("top.frames['main'].document.forms[0]."+cObj2)
	  cURL=cURL+"&"+cObj2+"="+escape(oObj2.value)
        }
	if(cObj3.length>0){
	  oObj3=eval("top.frames['main'].document.forms[0]."+cObj3)
	  cURL=cURL+"&"+cObj3+"="+escape(oObj3.value)
        }


  	oDoc.location.replace(cURL);


        break;
    case "FORM":
        oForm=oEv.oForm;
        oForm.submit();
        break;
	
    }
  }
  else {
    this.lQ=false;
  }
}


evq.prototype.CreateEvent=evq_CreateEvent;
evq.prototype.PostEvent = evq_PostEvent;
evq.prototype.Success=evq_Success;
evq.prototype.Failed=evq_Failed;
evq.prototype.DeleteEvent=evq_DeleteEvent;
evq.prototype.pollQueue=evq_pollQueue;
