 /*** PHOTOGRAPHER BY EVENT RADIUS INTERFACE CLASSES **************************************************/


function Conn() {};

Conn.prototype.serverroot = "xml/";
Conn.prototype.server = "";
Conn.prototype.xmlPageName = "";
Conn.prototype.version = "1.0.1";
Conn.prototype.responseXML = "";
Conn.prototype.report = "";
Conn.prototype.func = "";
Conn.prototype.url = "";
Conn.prototype.status = "";
Conn.prototype.reqXML;
Conn.prototype.callback;
Conn.prototype.errorcallback;

Conn.prototype.AddProperty = function (propname,propvalue) {
  eval('Conn.prototype.'+propname+' = "'+propvalue+'";')
}


Conn.prototype.Run = function (xmlpagename) {  
  this.xmlpagename = xmlpagename;
  this.url = this.serverroot + xmlpagename + "?func=" + this.func + "&rpt=" + this.report;
  var arArgs = '';
  if (arguments.length) {
    for(var i = 0; i < arguments.length; i++) {
      if(arguments[i].indexOf(','))
        arArgs = arguments[i].split(',')
        this.url += '&'+arArgs[0]+'=' + arArgs[1];
    }
  }
  //alert(this.url)
  //get the report data from the xml generated by the this.url property
  this.GetData();
}

Conn.prototype.registerCallback = function (callbackFunction) {
  callback = callbackFunction;
}

Conn.prototype.registerErrorCallback = function (callbackFunction) {
  errorcallback = callbackFunction;
}

Conn.prototype.GetData = function () {

  if (window.XMLHttpRequest) {
    reqXML = new XMLHttpRequest();
    if (reqXML) {
      reqXML.onreadystatechange = this.onDataReceived;
      reqXML.open("GET", this.url, true);
      reqXML.send(null);
    }
  } else if (window.ActiveXObject) {
    reqXML = new ActiveXObject("Microsoft.XMLHTTP");
    if (reqXML) {
      reqXML.onreadystatechange = this.onDataReceived;
      reqXML.open("GET", this.url, true);
      reqXML.send(null);
    }
  }
}

Conn.prototype.onDataReceived = function () {
  var reportString = '';
  if (reqXML.readyState == 4) {
    if (reqXML.status == 200) {
      var oXML = reqXML.responseXML;
      callback(oXML);
      this.status = 'done';
    }else{
      errorcallback(reqXML.status);
    }
  }

}

/*** UTILITY FUNCTIONS *******************************************/

/* --- IsNumeric(sText) ----------------------------------------
 * Determines if the supplied text value is numeric.
 * ------------------------------------------------------------- */
function IsNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;

 
  for (var i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}


/* --- changeOnclick(obj,func) ---------------------------------
 * Changes the ONCLICK Event of an ANCHOR Object
 * ------------------------------------------------------------- */
function changeOnclick(obj,func)
{
  if ((document.all)&&(document.getElementById))
  {
    obj["onclick"] = '';
    obj["onclick"]=new Function(func);
  }else{
    obj.setAttribute('onclick','');
    obj["onclick"]=new Function(func);
  }
}


/* --- createLink(id,onclick,html,classname,attributes)---------
 * Creates an ANCHOR Element.
 * ------------------------------------------------------------- */
function createLink(id,onclick,html,classname,attributes)
{
  var tmpLink = document.createElement('A');
  if(id) tmpLink.id = id;
  if(html) tmpLink.innerHTML = '['+html+']';
  if(classname) tmpLink.setAttribute('CLASS',classname);
  if(onclick) changeOnclick(tmpLink,onclick);
  return tmpLink;
}


/* --- createTextBox(id, name, value, classname, size, attributes)
 * Creates an INPUT Element with TYPE=TEXT.
 * ------------------------------------------------------------- */    
function createTextBox(id, name, value, classname, size, attributes)
{
  var tmpBox = document.createElement('INPUT');
  tmpBox.value = value
  tmpBox.id = id
  tmpBox.name = name
  tmpBox.setAttribute('CLASS',classname);
  tmpBox.setAttribute('SIZE',size);
     
  if(attributes && attributes.length > 0) 
  {
    var name = '';
    var value = '';
    var temp = new Array();
    temp = attributes.split(',');
        
    for(j=0;j<temp.length;j++)
    {
      name = temp[j].substring(0,temp[j].indexOf('|'));
      value = temp[j].substring(temp[j].indexOf('|')+1);
      tmpBox.setAttribute(name,value)
    }
  }      
  return tmpBox;
}


/* --- markField(fld)--------------------------------------------
 * Marks the parent TD tag of an element as red.
 * ------------------------------------------------------------- */  
function markField(fld)
{
  fld.parentNode.style.backgroundColor = '#990000';
}


/* --- clearField(fld)-------------------------------------------
 * Marks the parent TD tag of an element as red.
 * ------------------------------------------------------------- */  
function clearField(fld)
{
  fld.parentNode.style.backgroundColor = '';
}
