// <script>

// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id          - id of a popup window;
// drag_id     - id of an element within popup window intended for dragging it
// exit_id     - id of an element within popup window intended for hiding it
// position    - positioning type:
//               "screen-corner", "screen-center"
//               "mouse-corner" , "mouse-center"
//               "element-right", "element-bottom"
// x, y        - offset
// position_id - for the last two types of positioning popup window will be
//               positioned relative to this element


// ----- Variables -------------------------------------------------------------

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;
var global_db_id;
var global_ioboard;
var global_div_id;
var global_stat_start;
var global_return_id;
var global_comment_id;
var global_status_id;
var toggle_ts_status;
var global_status_time_utc;

//var checkstatustimer=setTimeout("myloop()",5000);

function startloop(ioboard, seconds, cook_ST_status) {

    do_stat_time(cook_ST_status);
    d = new Date();
    $('refreshtime').innerHTML =  'Updated: ' + d.toLocaleString();

    // If seconds haven't been specified, do not start polling
    if (seconds == '') {
        return;
    }
    // Call ioboard and see if a refresh is needed.
    checkstatustimer=setTimeout("checkforrefresh('" + ioboard + "', '" + seconds + "')", 1000 * seconds);
}

function checkforrefresh(ioboard, seconds) {
    updaterefreshcheck(ioboard);
    checkstatustimer=setTimeout("checkforrefresh('" + ioboard + "', '" + seconds + "')", seconds * 1000);
}


function updaterefreshcheck(ioboard) {
  var vars = new Array();
  refreshdate = document.refresh.refreshdate.value
  vars['refreshdate'] = refreshdate;
  srvpath = '/iobee/' + ioboard + '/ajaxrefresh/'
  ajaxCaller.postForPlainText(srvpath, vars, ReturnRefreshCheck)
}

function ReturnRefreshCheck(id_newstring) {
    d = new Date();
    $('refreshtime').innerHTML =  'Updated: ' + d.toLocaleString();
    info_array = id_newstring.split("\t");
    if (info_array[0] == 'dorefresh' ) {
        location.reload();
    }
    //else {
        //if (info_array[1] != '0') {
            //$('ajax_google_ads').innerHTML =  info_array[1];
            //eval($('ajax_google_ads').innerHTML);
           //}
    //}
}



var ajaxCaller = {

  shouldDebug: false,
  shouldEscapeVars: false,
  shouldMakeHeaderMap: true,

  calls : new Array(),
  pendingResponseCount : 0,

   /**************************************************************************
      PUBLIC METHODS
   *************************************************************************/

  getXML: function(url, callbackFunction) {
    this.get(url, null, callbackFunction, true, null);
  },

  getPlainText: function(url, callbackFunction) {
    this.get(url, null, callbackFunction, false, null);
  },

  postForPlainText: function(url, vars, callbackFunction) {
    this.postVars(url, vars, null, callbackFunction, false,
                    null, "POST", null, null, null);
  },

  postForXML: function(url, vars, callbackFunction) {
    this.postVars(url, vars, null, callbackFunction, true,
                    null, "POST", null, null, null);
  },

  get: function(url, urlVars, callbackFunction, expectingXML, callingContext) {
    this._callServer(url, urlVars, callbackFunction, expectingXML,
                    callingContext, "GET", null, null, null);
  },

  postVars:
    function(url, bodyVars, optionalURLVars, callbackFunction, expectingXML,
             callingContext) {
      this._callServer(url, optionalURLVars, callbackFunction, expectingXML,
                      callingContext, "POST", bodyVars, null, null);
  },

  postBody:
    function(url, optionalURLVars, callbackFunction, expectingXML,
             callingContext, bodyType, body) {
      this._callServer(url, optionalURLVars, callbackFunction, expectingXML,
                      callingContext, "POST", null, bodyType, body);
  },

  putBody:
    function(url, optionalURLVars, callbackFunction, expectingXML,
             callingContext, bodyType, body) {
      this._callServer(url, optionalURLVars, callbackFunction, expectingXML,
                      callingContext, "PUT", null, bodyType, body);
  },

  options:
    function(url, optionalURLVars, callbackFunction, expectingXML,
             callingContext, bodyType, body) {
      this._callServer(url, optionalURLVars, callbackFunction, expectingXML,
                      callingContext, "OPTIONS", null, bodyType, body);
  },

  trace:
    function(url, optionalURLVars, callbackFunction, expectingXML,
             callingContext, bodyType, body) {
      this._callServer(url, optionalURLVars, callbackFunction, expectingXML,
                      callingContext, "TRACE", null, bodyType, body);
  },

  deleteIt: function(url, urlVars, callbackFunction,
                     expectingXML, callingContext) {
    this._callServer(url, urlVars, callbackFunction, expectingXML,
                    callingContext, "DELETE", null, null, null);
  },

  head: function(url, urlVars, callbackFunction, expectingXML, callingContext)
  {
    this._callServer(url, urlVars, callbackFunction, expectingXML,
                    callingContext, "HEAD", null, null, null);
  },

  /**************************************************************************
     PRIVATE METHODS
  *************************************************************************/

  _callServer: function(url, urlVars, callbackFunction, expectingXML,
                       callingContext, requestMethod, bodyVars,
                       explicitBodyType, explicitBody) {

    if (urlVars==null) {
      urlVars = new Array();
    }

    this._debug("_callServer() called. About to request URL\n"
                + "call key: [" + this.calls.length + "]\n"
                + "url: [" + url + "]\n"
                + "callback function: [" + callbackFunction + "]\n"
                + "treat response as xml?: [" + expectingXML + "]\n"
                + "Request method?: [" + requestMethod + "]\n"
                + "calling context: [" + callingContext + "]\n"
                + "explicit body type: [" + explicitBodyType + "]\n"
                + "explicit body: [" + explicitBody + "]\n"
                + "urlVars: [" + this._describe(urlVars) + "]\n"
                + "bodyVars: [" + this._describe(bodyVars) + "]"
              );


    var xReq = this._createXMLHttpRequest();
    xReq.onreadystatechange = function() {
      ajaxCaller._onResponseStateChange(call);
    }

    var call = {xReq: xReq,
                callbackFunction: callbackFunction,
                expectingXML: expectingXML,
                callingContext: callingContext,
                url: url};

    if (urlVars!=null) {
      var urlVarsString = this._createHTTPVarSpec(urlVars);
      if (urlVarsString.length > 0) { // TODO check if appending with & instead
        url += "?" + urlVarsString;
      }
    }

    xReq.open(requestMethod, url, true);

    if (   requestMethod=="GET"
        || requestMethod=="HEAD"
        || requestMethod=="DELETE") {
      this._debug("Body-less request to URL " + url);
      xReq.send(null);
      return;
    }

    if (   requestMethod=="POST"
        || requestMethod=="PUT"
        || requestMethod=="OPTIONS"
        || requestMethod=="TRACE") {
      bodyType = null;
      body = null;
      if (explicitBodyType==null) { // It's a form
        bodyType = 'application/x-www-form-urlencoded; charset=UTF-8';
        body = this._createHTTPVarSpec(bodyVars);
      } else {
        bodyType = explicitBodyType;
        body = explicitBody;
      }
      this._debug("Content-Type: [" + bodyType + "]\nBody: [" + body + "].");
      xReq.setRequestHeader('Content-Type',  bodyType);
      xReq.send(body);
      return;
    }

    this._debug("ERROR: Unknown Request Method: " + requestMethod);

  },

  // The callback of xmlHttpRequest is a dynamically-generated function which
  // immediately calls this function.
  _onResponseStateChange: function(call) {

    xReq = call.xReq;

    if (xReq.readyState < 4) { //Still waiting
      return;
    }

    if (xReq.readyState == 4) { //Transmit to actual callback
      this._debug("Call " + ajaxCaller._describe(call)
                + " with context [" + call.callingContext+"]"
                + " to " + call.url + " has returned.");
      callbackFunction = call.callbackFunction;
      if (!callbackFunction) { // Maybe still loading, e.g. in another JS file
        setTimeout(function() {
          _onResponseStateChange(call);
        }, 100);
      }
      var content = call.expectingXML ? xReq.responseXML : xReq.responseText;
      responseHeaders = xReq.getAllResponseHeaders();
      headersForCaller = this.shouldMakeHeaderMap ?
        this._createHeaderMap(responseHeaders) : responseHeaders;
      callbackFunction(content, headersForCaller, call.callingContext);
    }

    call = null; // Technically the responsibility of GC
    this.pendingResponseCount--;

  },

  // Browser-agnostic factory function
  _createXMLHttpRequest: function() {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
      try { return new XMLHttpRequest(); } catch(e) {}
      alert("XMLHttpRequest not supported");
      return null;
    },

  _createHTTPVarSpec: function(vars) {
      var varsString = "";
      for( key in vars ) {
        var value = vars[key];
        if (this.shouldEscapeVars) {
          escapePlusRE =  new RegExp("\\\+");
          value = value.replace(escapePlusRE, "%2B");
        }
        varsString += '&' + key + '=' + value;
      }
      if (varsString.length > 0) {
        varsString = varsString.substring(1); // chomp initial '&'
      }
      this._debug("Built var String: " + varsString)
      return varsString;
   },

  /* Creates associative array from header type to header */
  _createHeaderMap: function(headersText) {
    extractedHeaders = headersText.split("\n");
    delete extractedHeaders[extractedHeaders.length]; // Del blank line at end
    headerMap = new Array();
    for (i=0; i<extractedHeaders.length-2; i++) {
      head = extractedHeaders[i];
      fieldNameEnding = head.indexOf(":");
      field = head.substring(0, fieldNameEnding);
      value = head.substring(fieldNameEnding + 2, head.length);
      value = value.replace(/\s$/, "");
      headerMap[field] = value;
    }
    return headerMap;
  },

  _describe: function(obj) {
    return document.util ? 
      util.describe(obj) : "Include util.js to describe " + obj;
  },

  _debug: function(message) {
      if (this.shouldDebug) {
        alert("AjaxJS Message:\n\n" + message);
      }
  },

  _error: function(message) {
      if (this.shouldDebug) {
        alert("AjaxJS ERROR:\n\n" + message);
      }
  }

};

function updateuseradmin_rights(ioboard_id, rights) {
  var vars = new Array();

  info_array = ioboard_id.split("_xx_");
  vars['db_id'] = info_array[1];
  vars['rights'] = rights;
  srvpath = "/iobee/" + info_array[0] + '/ajaxupdate/admin_rights/';

  ajaxCaller.postForPlainText(srvpath, vars, ReturnAdminRights);

  return false;
}

function DeleteList(list_id, ioboard) {
    loc = '/iobee/' +  ioboard + '/myprofile/dellist/' + list_id;
    location.href = loc;
}

function DeleteAlertStatus(ioboard, alert_id, thename) {

    dodelete = confirm(thename + "\nAre you sure you want to delete this alert?");
    if (dodelete == true) {
        loc = '/iobee/' +  ioboard + '/myprofile/delstatusalert/' + alert_id;
        location.href = loc;
    }
}

function EditAlertStatus(ioboard, id){
    var vars = new Array();

    vars['alert_id'] = id;

//alert("EditAlertStatus - id = " + id);
    if ($('ideditsave_' + id).value == 'Edit'){
        vars['thisname'] = $('idname_' + id).innerHTML;
        vars['thisemail'] = $('idemail_' + id).innerHTML;
        vars['fsel'] = $('idstatusfrom_' + id).innerHTML;
        vars['tsel'] = $('idstatusto_' + id).innerHTML;
        $('ideditsave_' + id).value = 'Save';
        srvpath = "/iobee/" + ioboard + '/ajaxupdate/getalertstatus/';
        ajaxCaller.postForPlainText(srvpath, vars, Returnalertstatus)
    } else
    {
        $('ideditsave_' + id).value = 'Edit';
        thename = $('idnamesel_' + id).options[ $('idnamesel_' + id).selectedIndex].value;
        thefromstat = $('idfromsel_' + id).options[ $('idfromsel_' + id).selectedIndex].value;
        thetostat = $('idtosel_' + id).options[ $('idtosel_' + id).selectedIndex].value;
        theemail = $('ideditemail_' + id).value;
        //alert('The name = ' + thename + '  thefrom = ' + thefromstat + '   theto = ' + thetostat + '    email = ' + theemail);
        vars['personid'] = thename;
        vars['thefromstat'] = thefromstat;
        vars['thetostat'] = thetostat;
        vars['theemail'] = theemail;
        srvpath = "/iobee/" + ioboard + '/ajaxupdate/setalertstatus/';
        ajaxCaller.postForPlainText(srvpath, vars, Returnalertstatus)
    }
}

function Returnalertstatus(id_newstring) {
    //alert(id_newstring);
    info_array = id_newstring.split("\t");
    id = info_array[1];
    $('idname_' + id).innerHTML = info_array[2];
    $('idstatusfrom_' + id).innerHTML = info_array[3];
    $('idstatusto_' + id).innerHTML = info_array[4];
    $('idemail_' + id).innerHTML = info_array[5];
}


function user_customlist(ioboard_id, adddel) {
  var vars = new Array();

  info_array = ioboard_id.split("_xx_");
  vars['db_id'] = info_array[1];
  vars['adddel'] = adddel;
  vars['list_id'] = $('list_id').value;
  srvpath = "/iobee/" + info_array[0] + '/ajaxupdate/profilelist/';

  ajaxCaller.postForPlainText(srvpath, vars, ReturnProfileList);

  return false;
}

function ReturnProfileList(id_newstring) {
    info_array = id_newstring.split("\t");
}


function shownewlist(obj, ioboard) {
    thename = obj.options[obj.selectedIndex].value;  
    loc = '/iobee/' +  ioboard + '/myprofile/lists/' + thename;
    location.href = loc;
}

function shownamelist(obj, ioboard) {
    thename = obj.options[obj.selectedIndex].value;  
    loc = '/iobee/' +  ioboard + '/shownamelist/' + thename;
    location.href = loc;
}



function ReturnAdminRights(id_newstring) {
    info_array = id_newstring.split("\t");
}



function UpdateReturnTime() {
  var vars = new Array();

  thetype_element = document.getElementById('timeinfo');
  thenewtext = thetype_element.value;

  vars['db_id'] = global_db_id;
  vars['newtimeinfo'] = thenewtext;
  srvpath = "/iobee/" + global_ioboard + '/ajaxupdate/returntimeinfo/'

  popup_exit2('rtpopup');
  ajaxCaller.postForPlainText(srvpath, vars, ReturnUpdateTime)

  return false;

}

function SendEmail() {
  var vars = new Array();

  thetype_element = document.getElementById('emailbody');
  theemailmessage = thetype_element.value;
  thetype_element.value = '';

  //alert("The From email = " + $("thefromemail").value);
  vars['emailbody'] = escape(theemailmessage);

  vars['db_id'] = $("email_login_user").value;
  vars['toemailaddress'] = $("email_address").innerHTML;
  vars['fromemailaddress'] = $("thefromemail").value;
  vars['emailsubject'] = $("emailsubject").value;
  $("emailsubject").value = '';
  srvpath = '/iobee/' + global_ioboard + '/ajaxsendemail/'

  ajaxCaller.postForPlainText(srvpath, vars, ReturnEmailSend)
}

function UpdateComment() {
  var vars = new Array();

  thetype_element = document.getElementById('commentinfo');
  thenewtext = thetype_element.value;

  vars['db_id'] = global_db_id;
  vars['newcommentinfo'] = escape(thenewtext);
  srvpath = '/iobee/' + global_ioboard + '/ajaxupdate/returncommentinfo/'

  popup_exit2('cmtpopup');
  ajaxCaller.postForPlainText(srvpath, vars, ReturnUpdateComment)
}


function UpdateStatus() {
  var vars = new Array();

  theselect_element = document.getElementById('statuspop');
  newstatus = theselect_element.options[theselect_element.selectedIndex].value;

  cleartimeinfo = 'false';
  clearcommentinfo = 'false'
  if ($('clearrtntime').style.visibility == "visible" ) {
      cleartimeinfo = $('cleartimeid').checked;
      clearcommentinfo = $('clearcommentid').checked;
  }

  if ($('menu_time_comment').style.visibility == "visible" ) {
    timetext = $("timeinfo2").value;
    commenttext = $("commentinfo2").value;
    vars['timetext'] = timetext;
    vars['commenttext'] = commenttext;
    vars['do_time_comment'] = 'true'
  }

  vars['cleartimeinfo'] = cleartimeinfo;
  vars['clearcommentinfo'] = clearcommentinfo;
  vars['db_id'] = global_db_id;
  vars['newstatus'] = newstatus;

  srvpath = "/iobee/" + global_ioboard + '/ajaxupdate/status/'
  popup_exit2('popup');

  ajaxCaller.postForPlainText(srvpath, vars, ReturnUpdate)
}

function $(id) { return document.getElementById(id); }

function ReturnUpdate(id_newstring) {
    info_array = id_newstring.split("\t");
    $(global_div_id).innerHTML = info_array[0];
    $(global_div_id).style.background = info_array[1];
    // info_array[2] is returntime; info_array[3] is comment
    if (info_array[2] == 'true') {
        $(global_return_id).innerHTML = '';
    }
    if (info_array[3] == 'true') {
        $(global_comment_id).innerHTML = '';
    }
    $('mycallnumber_' + global_db_id).innerHTML = info_array[4];
    time_array = global_status_time_utc.split("_");
    if (info_array[5] == 'true') {
        $(global_return_id).innerHTML = info_array[6];
        $(global_comment_id).innerHTML = info_array[7];
        $(global_status_time_utc).value = info_array[8];
        do_time(global_status_time_utc, 'id_lt_' + time_array[2]);
    } else {
        $(global_status_time_utc).value = info_array[6];
        do_time(global_status_time_utc, 'id_lt_' + time_array[2]);
    }
}


function ReturnUpdateTime(id_newstring) {
    info_array = id_newstring.split("\t");
    $(global_div_id).innerHTML = info_array[0];
}

function ReturnUpdateComment(id_newstring) {
    info_array = id_newstring.split("\t");
    $(global_div_id).innerHTML = info_array[0];
}

function ReturnEmailSend(id_newstring) {
    info_array = id_newstring.split("\t");
    if (info_array[0].substring(0,1) == 's') {
        $("divemailstatus").innerHTML = 'Your Message Has Been Sent';
    }
    else {
        $("divemailstatus").innerHTML = 'ERROR: message could not be sent!!';
    }
    fade('divemailstatus');
}


function popup_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- popup_mousedown -------------------------------------------------------

function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction      = document.onselectstart;
  else popup_oldfunction      = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}

// ----- popup_mousemove -------------------------------------------------------

function popup_mousemove(e)
{
  if (!popup_dragging) return;

  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  var mouseX = ie ? window.event.clientX : e.clientX;
  var mouseY = ie ? window.event.clientY : e.clientY;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

// ----- popup_mouseup ---------------------------------------------------------

function popup_mouseup(e)
{
  if (!popup_dragging) return;
  popup_dragging = false;

  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}

// ----- popup_exit ------------------------------------------------------------

function popup_exit(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  popup_mouseup(e);
  element.style.visibility = 'hidden';
  element.style.display    = 'none';
}


function popup_exit2(e) {
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(e);


  popup_mouseup(e);
  element.style.visibility = 'hidden';
  element.style.display    = 'none';

  if (e == 'emailpopup') {
      $("emailsubject").value = '';
      $('emailbody').value = '';
  }

}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}


// ----- popup_show ------------------------------------------------------------

function popup_show(id, drag_id, div_id, db_id, ioboard, return_id, comment_id, lastname, status_time_utc, thecolor, current_status)
{
  //alert('Popup_show id = ' + id)
  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);
  etime = document.getElementById("clearrtntime");


  thetype_element = document.getElementById('thetype');

  theselect_element = document.getElementById('statuspop');
  //current_status = $(div_id).innerHTML;

  etime.style.visibility = "hidden";
  etime.style.display    = "none";


  if (current_status == 'IN') {
      theselect_element.selectedIndex = 1;
      theselect_element.style.backgroundColor = thecolor;
      $('menu_time_comment').style.visibility = "visible";
      $('menu_time_comment').style.display    = "block";

      $("timeinfo2").value = $(return_id).innerHTML;
      $("commentinfo2").value = $(comment_id).innerHTML;
      
      //thetype_element.value  = 'Hello';

      global_stat_start = 'IN';
  }
  else {
      theselect_element.selectedIndex = 0;
      theselect_element.style.backgroundColor = thecolor;
      $('clearrtntime').style.visibility = "visible";
      $('clearrtntime').style.display    = "block";
      $('menu_time_comment').style.visibility = "hidden";
      $('menu_time_comment').style.display    = "none";
      global_stat_start = 'OUT';
  }

  $('pop_lastname').innerHTML = lastname;

  global_db_id = db_id;
  global_ioboard = ioboard;
  global_div_id = div_id;
  global_comment_id = comment_id;
  global_return_id = return_id;
  global_status_time_utc = status_time_utc;

  element.style.position   = "absolute";
  element.style.display    = "block";

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;
  element.style.visibility = "visible";

  element.style.left = (getScrollWidth()+popup_mouseposX-element.clientWidth /2+81)+'px';
  element.style.top  = (getScrollHeight()+popup_mouseposY-element.clientHeight/2+60)+'px';


}
function popup_returntime(id, drag_id, div_id, db_id, ioboard, lastname)
{
  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);

  thetype_element = document.getElementById('timeinfo');
  thetype_element.value  = $(div_id).innerHTML;

  element.style.position   = "absolute";
  element.style.display    = "block";

  global_db_id = db_id;
  global_ioboard = ioboard;
  global_div_id = div_id;
  $('pop_time_lastname').innerHTML = lastname;

    //element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-element.clientWidth /2-10)+'px';
    //element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-element.clientHeight/2+20)+'px';
    element.style.left = (getScrollWidth()+popup_mouseposX-element.clientWidth /2-10)+'px';
    element.style.top  = (getScrollHeight() +popup_mouseposY-element.clientHeight/2+20)+'px';
  element.style.visibility = "visible";

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;
  $('timeinfo').focus()
}

function popup_admin_help(id, drag_id)
{

  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);

  element.style.position   = "absolute";
  element.style.display    = "block";
    //element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-element.clientWidth /2-10)+'px';
    //element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-element.clientHeight/2+20)+'px';
    element.style.left = (getScrollWidth()+popup_mouseposX-element.clientWidth /2-10)+'px';
    element.style.top  = (getScrollHeight() +popup_mouseposY-element.clientHeight/2+20)+'px';

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;

  element.style.visibility = "visible";
  thetype_element.focus();
}

function popup_comment(id, drag_id, div_id, db_id, ioboard, lastname)
{

  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);

  thetype_element = document.getElementById('commentinfo');
  //thetype_element.value  = $(div_id).innerHTML;
  uescape = $(div_id).innerHTML;

  uescape = uescape.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/, "<");

  thetype_element.value = uescape;
  $('pop_comment_name').innerHTML = lastname;

  global_db_id = db_id;
  global_ioboard = ioboard;
  global_div_id = div_id;

  element.style.position   = "absolute";
  element.style.display    = "block";
    //element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-element.clientWidth /2-10)+'px';
    //element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-element.clientHeight/2+20)+'px';
    element.style.left = (getScrollWidth()+popup_mouseposX-element.clientWidth /2-10)+'px';
    element.style.top  = (getScrollHeight() +popup_mouseposY-element.clientHeight/2+20)+'px';

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;

  element.style.visibility = "visible";
  thetype_element.focus();
}
function doEmailClient(db_id, ioboard)
{
  var vars = new Array();
  vars['db_id'] = db_id;
  vars['person_emailing_id'] = $("email_login_user").value;

  srvpath = "/iobee/" + ioboard + '/ajaxgetemailclient/';
  ajaxCaller.postForPlainText(srvpath, vars, Return_emailclient);
}

function Return_emailclient(id_newstring) {
    // Fire off the client email program
    info_array = id_newstring.split("\t");
    if (info_array[0].toLowerCase() == 'success') {
        document.location = "mailto:" + info_array[1];
    }
}

function popup_email(db_id, id, drag_id,ioboard, return_email)
{
  var vars = new Array();
  vars['db_id'] = db_id;
  // This should probably be a passed parameter
  vars['person_emailing_id'] = $("email_login_user").value;


  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);

  $("email_from").innerHTML = return_email;

  global_ioboard = ioboard;

  element.style.position   = "absolute";
  element.style.display    = "block";
  element.style.left = (getScrollWidth()+(document.body.clientWidth -element.clientWidth )/2+ -10)+'px';
  element.style.top  = (getScrollHeight() +(element.clientHeight)/2 + -10)+'px';

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;

  element.style.visibility = "visible";
  $('emailsubject').focus();

  srvpath = "/iobee/" + ioboard + '/ajaxgetemail/';
  ajaxCaller.postForPlainText(srvpath, vars, Return_pickemail);
}
function Return_pickemail(id_newstring) {

    info_array = id_newstring.split("\t");
    if (info_array[0].toLowerCase() == 'success') {
        $("email_address").innerHTML = info_array[1];
        $("email_from").innerHTML = info_array[2];
        if (info_array[3] != '') {
        $("hideemail").innerHTML = info_array[3];
        }
    }
}

function setcookiesession(obj, ioboard, db_id)
{
  var vars = new Array();

  vars['db_id'] = db_id;
  //vars['cookiesession'] = $('idbrowsercookie').options[ $('idbrowsercookie').selectedIndex].value;
  vars['cookiesession'] = obj.options[ obj.selectedIndex].value;
  srvpath = "/iobee/" + ioboard + '/ajaxupdate/sessioncookie/';
  ajaxCaller.postForPlainText(srvpath, vars, Returncookiesession);
}

function Returncookiesession(id_newstring) {
    //alert(id_newstring);
    info_array = id_newstring.split("\t");
}

function setmailicon(obj, ioboard, db_id)
{
  var vars = new Array();

  vars['db_id'] = db_id;
  //vars['mailicon'] = $('idmailicon').options[ $('idmailicon').selectedIndex].value;
  vars['mailicon'] = obj.options[ obj.selectedIndex].value;
  srvpath = "/iobee/" + ioboard + '/ajaxupdate/mailicon/';
  ajaxCaller.postForPlainText(srvpath, vars, Returnmailicon);
}

function Returnmailicon(id_newstring) {
    //alert(id_newstring);
    info_array = id_newstring.split("\t");
}


function mini_admin_save(ioboard)
{
  var vars = new Array();

  vars['db_id'] = global_db_id;
  vars['status'] = $('statuspop_mini').options[ $('statuspop_mini').selectedIndex].value;
  vars['returntime'] = $("xreturntime").value;
  //vars['comment'] = $('xcomment').innerHTML;
  vars['comment'] = $('xcomment').value;
  srvpath = "/iobee/" + ioboard + '/ajaxupdate/mini_admin_update/';

  ajaxCaller.postForPlainText(srvpath, vars, Returnminiupdate)
}

function Returnminiupdate(id_newstring) {
    info_array = id_newstring.split("\t");
    $(global_return_id).innerHTML = $("xreturntime").value;
    $(global_comment_id).innerHTML = $("xcomment").value;
    istatus = $('statuspop_mini').options[ $('statuspop_mini').selectedIndex].value.toUpperCase();
    $(global_status_id).className = info_array[2];
    $(global_status_id).innerHTML = info_array[3];
    popup_exit2('personpopup');
}


function UpdateStatusField() {
  var vars = new Array();

  i = document.newstatusinfo.status.options.selectedIndex;
  statvalue = 'in';
  if (i == 1){
      statvalue = 'out';
  }
  else if (i == 2){
      statvalue = 'about';
  }

  vars['db_id'] = global_db_id;
  vars['div_id'] = global_div_id;
  vars['db_field'] = global_db_field;
  vars['newfield'] = statvalue;
  srvpath = '/iobee/' + global_ioboard + '/ajaxupdate/updateuserfield/'

  popup_exit2('changestatpopup');
  ajaxCaller.postForPlainText(srvpath, vars, ReturnUpdateStatusField)
}

function ReturnUpdateStatusField(id_newstring) {
    info_array = id_newstring.split("\t");
    this_div_id = info_array[1].replace(/\s+$/g,"");
    s = info_array[0];
    if (s == 'in') {
        $(this_div_id).className = 'statin'
        $(this_div_id).innerHTML = 'IN'
    }
    else if (s == 'out') {
        $(this_div_id).className = 'statout'
        $(this_div_id).innerHTML = 'OUT'
    }
    else if (s == 'about') {
        $(this_div_id).className = 'statabout'
        $(this_div_id).innerHTML = 'ABOUT'
    }
    //$(this_div_id).className = info_array[0];
}


function popup_person(id, drag_id, div_id, db_id, ioboard, mini_admin, status_id, return_id, comment_id)
{
  var vars = new Array();

  global_db_id = db_id;
  global_return_id = return_id;
  global_comment_id = comment_id;
  global_status_id = status_id;
  vars['db_id'] = db_id;
  vars['div_id'] = div_id;
  vars['mini_admin'] = mini_admin;
  srvpath = '/iobee/' + ioboard + '/ajaxpersondata/'

  ajaxCaller.postForPlainText(srvpath, vars, ReturnPersonData)
}


// ReturnPersonData:  Receives person details.  Fields separated by tabs
//
//   Last Name,  First Name, Status, Return Time, Email, Work#, Mobile#, Home#, Fax#, Comment
function ReturnPersonData(id_newstring) {
    info_array = id_newstring.split("\t");
    mini_admin = info_array[0];

    element      = document.getElementById('personpopup');
    drag_element = document.getElementById('personpopup_drag');
    innervalue = '<img class="menu_form_exit"   id="popup_exit" src="/iobee/ioboardimages/form_exit.png" onclick="popup_exit2(\'personpopup\')" alt="" />';
    innervalue = innervalue + '&nbsp;&nbsp;&nbsp;' + info_array[1] + ' ' + info_array[2];
    drag_element.innerHTML = innervalue;

    $('xfirstname').innerHTML = info_array[1];
    $('xlastname').innerHTML = info_array[2];
    if (mini_admin == 'no'){
        $('xstatus').innerHTML = info_array[3];
        $('xstatus').style.backgroundColor = info_array[12];
    }
    if (mini_admin == 'yes'){
        if (info_array[3] == 'IN') {
            $('statuspop_mini').selectedIndex = 0;
        }
        else if (info_array[3] == 'OUT') {
            $('statuspop_mini').selectedIndex = 1;
        }
        else if (info_array[3] == 'ABOUT') {
            $('statuspop_mini').selectedIndex = 2;
        }
        $('statuspop_mini').style.backgroundColor = info_array[12];
    }
    //$('xreturntime').innerHTML = info_array[4];
    $("xreturntime").value = info_array[4];
    $('xemail').innerHTML = info_array[5];
    $('xemail').href = "mailto:" + info_array[5];
    $('xworknumber').innerHTML = info_array[6];
    $('xmobilenumber').innerHTML = info_array[7];
    $('xhomenumber').innerHTML = info_array[8];
    $('xfaxnumber').innerHTML = info_array[9];
    $('xcomment').innerHTML = info_array[10];
    uescape = info_array[11];

    $('xprettyface').innerHTML = uescape;

    //element.style.left = (document.documentElement.scrollLeft+(document.body.clientWidth -element.clientWidth )/2+ -10)+'px';
    //element.style.top  = (document.documentElement.scrollTop +(document.body.clientHeight-element.clientHeight)/4+ -10)+'px';

    ie = navigator.appName == "Microsoft Internet Explorer";
    if (ie) {
        width = document.body.offsetWidth;
        height = document.body.offsetHeight;
    }
    else {
        var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
        var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
    }

    var ScrollTop = document.body.scrollTop;
    var ScrollTop = getScrollHeight();

    element.style.display    = "block";
    element.style.position   = "absolute";

    //element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+0)+'px';
    //element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)/2+ ScrollTop)+'px';
    //element.style.left = (getScrollWidth()+(width -element.clientWidth )/2+0)+'px';
    //element.style.top  = (getScrollHeight() +(height-element.clientHeight)/2+ ScrollTop)+'px';


  element.style.left = (getScrollWidth()+(document.body.clientWidth -element.clientWidth )/2+ -10)+'px';
  //element.style.top  = (getScrollHeight() +(document.body.clientHeight-element.clientHeight)/4+ -10)+'px';
  element.style.top  = (getScrollHeight() +(element.clientHeight)/2 + -10)+'px';



    drag_element['target']   = 'personpopup';
    drag_element.onmousedown = popup_mousedown;

    element.style.visibility = "visible";
}


// ----- popup_mousepos --------------------------------------------------------

function popup_mousepos(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

// ----- Attach Events ---------------------------------------------------------

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousedown', popup_mousepos);
else document.addEventListener('mousedown', popup_mousepos, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);



/**
The JavaScript functions below will gradually enlarge or shrink an image
on the current page. I use this for mouseover effects, but there might be
some other interesting applications of it as well.

You can use these scripts in any way you'd like, just don't pretend like
you wrote them yourself.

version 1.0
March 17, 2005
Julian Robichaux, http://www.nsftools.com
*/

/**** adjust these two parameters to control how fast or slow
 **** the images grow/shrink ****/
// how many milliseconds we should wait between resizing events
var resizeDelay = 10;
// how many pixels we should grow or shrink by each time we resize
var resizeIncrement = 5;

// this will hold information about the images we're dealing with
var imgCache = new Object();


/**
The getCacheTag function just creates a (hopefully) unique identifier for
each <img> that we resize.
*/
function getCacheTag (imgElement) {
	return imgElement.src + "~" + imgElement.offsetLeft + "~" + imgElement.offsetTop;
}


/**
We're using this as a class to hold information about the <img> elements
that we're manipulating.
*/
function cachedImg (imgElement, increment) {
	this.img = imgElement;
	this.cacheTag = getCacheTag(imgElement);
	this.originalSrc = imgElement.src;
	
	var h = imgElement.height;
	var w = imgElement.width;
	this.originalHeight = h;
	this.originalWidth = w;
	
	increment = (!increment) ? resizeIncrement : increment;
	this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
	this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}


function resizeImg (imgElement, percentChange, newImageURL) {
	// convert the percentage (like 150) to an percentage value we can use
	// for calculations (like 1.5)
	var pct = (percentChange) ? percentChange / 100 : 1;
	
	// if we've already resized this image, it will have a "cacheTag" attribute
	// that should uniquely identify it. If the attribute is missing, create a
	// cacheTag and add the attribute
	var cacheTag = imgElement.getAttribute("cacheTag");
	if (!cacheTag) {
		cacheTag = getCacheTag(imgElement);
		imgElement.setAttribute("cacheTag", cacheTag);
	}
	
	// look for this image in our image cache. If it's not there, create it.
	// If it is there, update the percentage value.
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal) {
		imgCache[cacheTag] = new Array(new cachedImg(imgElement), pct);
	} else {
		cacheVal[1] = pct;
	}
	
	// if we're supposed to be using a rollover image, use it
	if (newImageURL)
		imgElement.src = newImageURL;
	
	// start the resizing loop. It will continue to call itself over and over
	// until the image has been resized to the proper value.
	resizeImgLoop(cacheTag);
	return true;
}


/**
This is the function that actually does all the resizing. It calls itself
repeatedly with setTimeout until the image is the right size.
*/
function resizeImgLoop (cacheTag) {
	// get information about the image element from the image cache
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal)
		return false;
	
	var cachedImageObj = cacheVal[0];
	var imgElement = cachedImageObj.img;
	var pct = cacheVal[1];
	var plusMinus = (pct > 1) ? 1 : -1;
	var hinc = plusMinus * cachedImageObj.heightIncrement;
	var vinc = plusMinus * cachedImageObj.widthIncrement;
	var startHeight = cachedImageObj.originalHeight;
	var startWidth = cachedImageObj.originalWidth;
	
	var currentHeight = imgElement.height;
	var currentWidth = imgElement.width;
	var endHeight = Math.round(startHeight * pct);
	var endWidth = Math.round(startWidth * pct);
	
	// if the image is already the right size, we can exit
	if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
		return true;
	
	// increase or decrease the height and width, making sure we don't get
	// larger or smaller than the final size we're supposed to be
	var newHeight = currentHeight + hinc;
	var newWidth = currentWidth + vinc;
	if (pct > 1) {
		if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	} else {
		if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	}
	
	// set the image element to the new height and width
	imgElement.height = newHeight;
	imgElement.width = newWidth;
	
	// if we've returned to the original image size, we can restore the
	// original image as well (because we may have been using a rollover
	// image in the original call to resizeImg)
	if ((newHeight == cachedImageObj.originalHeight) || (newWidth == cachedImageObj.originalwidth)) {
		imgElement.src = cachedImageObj.originalSrc;
	}
	
	// shrink or grow again in a few milliseconds
	setTimeout("resizeImgLoop('" + cacheTag + "')", resizeDelay);
}

// Dynamic execute java script in DIV

function execJS(node1)
{
  var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
  var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var bMoz = (navigator.appName == 'Netscape');

  if (!node1) return;

  var node = $(node1);
  /* IE wants it uppercase */
  var st = node.getElementsByTagName('SCRIPT');
  var strExec;

  for(var i=0;i<st.length; i++)
  {
    if (bSaf) {
      strExec = st[i].innerHTML;
      st[i].innerHTML = "";
    } else if (bOpera) {
      strExec = st[i].text;
      st[i].text = "";
    } else if (bMoz) {
      strExec = st[i].textContent;
      st[i].textContent = "";
    } else {
      strExec = st[i].text;
      st[i].text = "";
    }

    try {
      var x = document.createElement("script");
      x.type = "text/javascript";

      /* In IE we must use .text! */
      if ((bSaf) || (bOpera) || (bMoz))
        x.innerHTML = strExec;
      else x.text = strExec;

      document.getElementsByTagName("head")[0].appendChild(x);
    } catch(e) {
      alert(e);
    }
  }
};

function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

function popup_personfield(id, drag_id, div_id, db_id, ioboard, title, db_field_name)
{

  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);

  thetype_element = document.getElementById('fieldvalue');

  uescape = $(div_id).innerHTML;
  $('title_id').innerHTML = title;
  $('changebutton_id').innerHTML = title;

  uescape = uescape.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/, "<");

  thetype_element.value = uescape;

  global_db_id = db_id;
  global_ioboard = ioboard;
  global_div_id = div_id;
  global_db_field = db_field_name;

  element.style.position   = "absolute";
  element.style.display    = "block";
    //element.style.left = (document.documentElement.scrollLeft+popup_mouseposX-element.clientWidth /2-10)+'px';
    //element.style.top  = (document.documentElement.scrollTop +popup_mouseposY-element.clientHeight/2+20)+'px';
    element.style.left = (getScrollWidth()+popup_mouseposX-element.clientWidth /2-10)+'px';
    element.style.top  = (getScrollHeight() +popup_mouseposY-element.clientHeight/2+20)+'px';

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;

  element.style.visibility = "visible";
  thetype_element.focus();
}

function UpdateUserField() {
  var vars = new Array();

  thetype_element = document.getElementById('fieldvalue');
  thenewtext = thetype_element.value;

  vars['db_id'] = global_db_id;
  vars['div_id'] = global_div_id;
  vars['db_field'] = global_db_field;
  vars['newfield'] = escape(thenewtext);
  srvpath = '/iobee/' + global_ioboard + '/ajaxupdate/updateuserfield/'
  $(global_div_id).innerHTML = thenewtext;

  popup_exit2('changefieldpopup');
  ajaxCaller.postForPlainText(srvpath, vars, ReturnUpdateUserField)
  return false;
}
function ReturnUpdateUserField(id_newstring) {
    // Rather than making the display change after returning from 
    // the server I decided to assume success and make the display
    // before the server changes the database.  If there is a failure
    // I don't believe it should be a major problem.  I'm going to 
    // leave all of this in place for handling after return from the
    // server as it might prove necessary in the future.

    //info_array = id_newstring.split("\t");
    //this_div_id = info_array[1].replace(/\s+$/g,"");
    //$(this_div_id).innerHTML = info_array[0];
}

function LZ(x) {return(x<0||x>9?"":"0")+x}

 var MONTH_NAMES=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function do_time (utc_t, lt_t) {

     var utc_time_div   = document.getElementById (utc_t);
     var local_time_div = document.getElementById (lt_t);
     var utc_time = new Date (utc_time_div.value);

     var M1=utc_time.getMonth();
     var M = MONTH_NAMES[M1];
     var d=utc_time.getDate();
     var H1=utc_time.getHours();
     var H = LZ(H1);
     var m=LZ(utc_time.getMinutes());
     var s=LZ(utc_time.getSeconds());

     displaydate = M + ' ' + d + ', ' + H + ':' + m + ':' + s;

     local_time_div.innerHTML = displaydate;
}

function do_stat_time( cook_ST_status) {
    var i = 1;
    var usercount = $('id_usercount').value;
    while (i <= usercount) {
        if ($('id_utc_' + i)) {
            if ($('id_utc_' + i).value != ' UTC') {
                do_time('id_utc_' + i, 'id_lt_' + i);
            }
        }
        i = i + 1;
       }

    if (cook_ST_status == 'on') {
          changecss('.status_date', 'visibility', 'visible');
          changecss('.status_date', 'display', 'block');
    }
    else {
          changecss('.status_date', 'visibility', 'hidden');
          changecss('.status_date', 'display', 'none');
    }

    toggle_ts_status = cook_ST_status;

}

function show_stat_time(ioboard) {
  var vars = new Array();
  if (toggle_ts_status == 'on') {
      toggle_ts_status = 'off';
      changecss('.status_date', 'visibility', 'hidden');
      changecss('.status_date', 'display', 'none');
      vars['TS_State'] = 'off';
      $('showhide_time').innerHTML = 'Show Time';
  }
  else {
      toggle_ts_status = 'on';
      changecss('.status_date', 'visibility', 'visible');
      changecss('.status_date', 'display', 'block');
      vars['TS_State'] = 'on';
      $('showhide_time').innerHTML = 'Hide Time';
  }
  srvpath = "/iobee/" + ioboard + '/ajaxtoggle/status/'
  ajaxCaller.postForPlainText(srvpath, vars, Return_TS_State)
}

function Return_TS_State(rtn_value) {
  //alert("Return from ts rtn_value = " + rtn_value);
}


function assign_status(classname, thecolor) {
      theclass = '.' + classname;
      changecss(theclass, 'padding-left', '0px');
      changecss(theclass, 'padding-top', '0px');
      changecss(theclass, 'padding-bottom', '0px');
      changecss(theclass, 'font-size', '12px; color:#000');
      changecss(theclass, 'text-align', 'center');
      changecss(theclass, 'font-family', 'Verdana, sans-serif');
      changecss(theclass, 'font-weight', 'bold');
      changecss(theclass, 'border', '1px solid #404040');
      changecss(theclass, 'margin', '0px');
      changecss(theclass, 'background-color', thecolor);
}

function changecss(theClass,element,value) {
      //alert('the class c = ' + theClass  + ' the element = ' + element + ' value = ' + value);
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 var added = false;
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
    if(document.styleSheets[S][cssRules][R].style[element]){
    document.styleSheets[S][cssRules][R].style[element] = value;
    added=true;
    break;
    }
   }
  }

  if(!added){
  if(document.styleSheets[S].insertRule){
          document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
        } else if (document.styleSheets[S].addRule) {
            document.styleSheets[S].addRule(theClass,element+': '+value+';');
        }
  }
 }
}

function setStyle (theList) {
    if (navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        return;
    }
    var bg = theList.options[theList.selectedIndex].style.backgroundColor;
    var fg = theList.options[theList.selectedIndex].style.color;
    theList.style.backgroundColor = bg;
    theList.style.color           = fg;
}
