var WebDoxNotesTimeout;
var WebDoxNotesTimeoutPass=0;

var http = getHTTPObject(); // We create the HTTP Object

//START: function ProcessWebDoxNotesField()
// This function flashes and fades the transmitted message

function CollapseElement(ElementName)
{
  document.getElementById(ElementName).setAttribute("style", "visibility: collapse;");
  document.getElementById(ElementName).setAttribute("style", "display: none;");

  document.getElementById(ElementName).style.display = 'none';
}

function ShowElement(ElementName)
{
  document.getElementById(ElementName).setAttribute("style", "visibility: visible;"); 
  document.getElementById(ElementName).setAttribute("style", "display: block;");

  document.getElementById(ElementName).style.display = 'block';
}

function ProcessWebDoxNotesField()
{
 WebDoxNotesTimeoutPass++;

 if(WebDoxNotesTimeoutPass==1)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #aaccaa;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #aaccaa;border:  #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==2)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #bbddbb;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #bbddbb;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==3)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #cceecc;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #cceecc;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
 }
 else if(WebDoxNotesTimeoutPass==4)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ddffdd;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ddffdd;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==5)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #f0fff0;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #f0fff0;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",5000);
  }
 else if(WebDoxNotesTimeoutPass==6)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:#608060 1px solid;color: #7f7f7f;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:#608060 1px solid;color: #7f7f7f;";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
   }
 else if(WebDoxNotesTimeoutPass==7)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:#b0d0b0 1px solid;color: #bbbbbb;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:#b0d0b0 1px solid;color: #bbbbbb;";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
   else if(WebDoxNotesTimeoutPass==8)
  {
   document.getElementById('WebDoxNotes').innerHTML='';
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:0;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:0";
   WebDoxNotesTimeoutPass=0;
  }

}
//END:function ProcessWebDoxNotesField()

// Convert MM/DD/YYYY to YYYY-MM-DD
function DateUSAtoDB(ThisDate)
{
//alert(ThisDate);
 if(ThisDate=='Any Date')  //handle 'any date'
   NewDate='Any Date';
  else //convert the date
    {
      DateParts=ThisDate.split('/');
      NewDate=DateParts[2]+'-'+DateParts[0]+'-'+DateParts[1];
    }
 return NewDate;
}

function handleServerRequestResponse() 
{

  if (http.readyState == 4) 
   {

    //results = http.responseText.split(",");
    //document.getElementById('city').value = results[0];
    //document.getElementById('state').value = results[1];
    var ResponseLines=new Array();
    var LineFields=new Array();

    ServerResponse='';
    WebDoxMessage='';
    
    ServerResponse=http.responseText;
    
    //alert('line 82: '+"Raw Server Response:["+ServerResponse+"]");
    
    ResponseLines=ServerResponse.split('<!--LINE-->');
    
    //alert('line 86: '+ResponseLines.length); 
    
    for(Counter=0;Counter<ResponseLines.length-1;Counter++)
      {
       LineFields=ResponseLines[Counter].split('<!--FIELD-->');
       
       ActionType=LineFields[0];
       ObjectName=LineFields[1];
       UpdateType=LineFields[2];
       DataContent=LineFields[3];
       
       //alert('line 86: '+'Line['+Counter+'] Action is ['+ActionType+']');
       if(ActionType=='ALERT')
         {
	  alert(DataContent);
	 }
	else if(ActionType=='EXEC') //this is to fire off innerhtml event handlers
	 {
	  //alert('going to try to execute: ['+DataContent+']');
	  //eval(DataContent);
	  var TemporaryFunction=new Function(DataContent); //Chrome refuses to function with eval
	  TemporaryFunction();
	 }
        else if(ActionType=='UPDATE')
	 {
	  if(UpdateType=='HTML')
	    {
	     //alert('Update: '+ObjectName+'='+DataContent);	     
	     document.getElementById(ObjectName).innerHTML = DataContent;
	    }
	  else if(UpdateType=='VALUE')
	   {
	    document.getElementById(ObjectName).value = DataContent;
	   }
	  else if(UpdateType=='BACKGROUNDCOLOR')
	   {
	    //alert('backgroundcolor');
	    document.getElementById(ObjectName).style.backgroundColor = DataContent;
	   }
         else if(UpdateType=='CHECKBOX')
           {
            if(DataContent=='1')
              CheckedValue=true;
             else
              CheckedValue=false;

	    //alert('trying to set checkbox - ObjectName=['+ObjectName+'] CheckedValue=['+CheckedValue+']');

            document.getElementById(ObjectName).checked=CheckedValue;
           }

	  
	 }//else if(ActionType=='UPDATE')
	 
        else if(ActionType=='NEW')
	 {
	  if(UpdateType=='DOCUMENT')
	    {
	     myWin= open("", "displayWindow", "status=yes,toolbar=yes,menubar=yes");

	     myWin.document.write(DataContent);
	     
	     myWin.document.close();
	    }
	  
	 }//else if(ActionType=='NEW')

       else if(ActionType=='ALERT')
        {
	 alert(DataContent);
	}
       else if(ActionType=='MESSAGE')
        {
	 document.getElementById('WebDoxNotes').innerHTML = DataContent;
 	 WebDoxNotesTimeoutPass=0;
	 WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",1000);
        }
       //alert(ResponseLines[Counter]);
      } //for (Counter...

    
//    document.getElementById('WebDoxNotes').innerHTML = "Message";
//    WebDoxNotesTimeoutPass=0;
//    WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",1000);

    delete ResponseLines;
    delete LineFields;
    
  } //if (http.readyState == 4)

} //function handleServerRequestResponse() 

function ServerRequest(FunctionName,Data)
{
  //alert("In Javascript Server Request, requesting :["+FunctionName+"]");
  
  
  RequestString= "Remote=1&FunctionName="+escape(FunctionName)+Data;
  RequestString+='&RND='+Math.floor(Math.random()*1000000);
  RequestString+='&EndRequest=1';
  
  //alert(RequestString);
  //alert(ServiceURL);  
  http.open("POST", ServiceURL, true); //RequestString, true); 
  
  //alert('line 164');
  
  //return false;
  
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", RequestString.length);
  http.setRequestHeader("Connection", "close");
  
  http.onreadystatechange = handleServerRequestResponse; 
  
  http.send(RequestString);
  //http.send(null);
  
  return false;

} //function ServerRequest(FunctionName,Data)

function getHTTPObject() 
{ 
var xmlhttp; 
  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }
  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}// END: function getHTTPObject() 

function FormHasEmptyField(FormName)
{
 //alert('Formname='+FormName);
 
var MyForm = document.getElementById(FormName).elements;

MyString='';
HasEmptyField=0;

for(var i = 0; i < MyForm.length; i++)
        {
          if(MyForm[i].type != 'submit')
              {
                MyString+='&'+MyForm[i].name+'='+MyForm[i].value;
                //MyForm[i].value= GetDefaultValueForField(FormName,MyForm[i].name);  //'';
                //alert('Name is :'+MyForm[i].name);
                //alert('value is :'+MyForm[i].value);
		//alert('length is:'+MyForm[i].value.length);
		if(MyForm[i].value.length==0)
		   HasEmptyField=1;
              }
        };

 //alert('HasEmptyField='+HasEmptyField);
 //alert(MyString);
 return HasEmptyField;
 
}
