String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}

a='@';
function mailto(name, extension) {
  ext = extension+'.com';
  document.write('<a class="h3" href="mailto:'+name+a+ext+'"><h3>'+name+a+ext+'</h3></a>');
}

function check(e, nxt)
{
  var keynum;
  var keychar;
  var numcheck;

  if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which;
  } else if(window.event) // IE
  {
    e = window.event;
    keynum = e.keyCode;
  }

  keychar = String.fromCharCode(keynum);
  if ( keychar == '\r' ) {
    document.getElementById(nxt).focus();
  } else {
    numcheck = keychar;
  }
}

function checkblur(shiftOid, club, requestor, inm, eventOid, bagNum)
{
  var i;
  var somepin = new Array();

  for ( i = 0; i < 8; i++ ) {

    var elem = document.getElementById('start' + i);

    if ( elem != null && elem.value != null && elem.value.length > 0 ) {
      if ( !(elem.value.toUpperCase() in somepin ) ) {
        somepin[elem.value.toUpperCase()] = i;
      } else {
        elem.value = '';
      }
    }
  }

  verify( club, document.getElementById('start1').value,
                document.getElementById('start2').value,
                document.getElementById('start3').value,
                document.getElementById('start4').value,
                document.getElementById('start5').value,
                document.getElementById('start6').value,
                document.getElementById('start7').value,
                document.getElementById('start8').value,
                shiftOid, requestor, inm, eventOid, bagNum );
}

function verify( club, val1, val2, val3, val4, val5, val6, val7, val8, shiftOid, requestor, inm, eventOid, bagNum ) {
  $("#action").hide(0);
    var val1c = "0";
    var val2c = "0";
    var val3c = "0";
    var val4c = "0";
    var val5c = "0";
    var val6c = "0";
    var val7c = "0";
    var val8c = "0";
    if ( val1 != null && val1.trim().length > 0 ) {
        val1c = val1;
    }
    if ( val2 != null && val2.trim().length > 0 ) {
        val2c = val2;
    }
    if ( val3 != null && val3.trim().length > 0 ) {
        val3c = val3;
    }
    if ( val4 != null && val4.trim().length > 0 ) {
        val4c = val4;
    }
    if ( val5 != null && val5.trim().length > 0 ) {
        val5c = val5;
    }
    if ( val6 != null && val6.trim().length > 0 ) {
        val6c = val6;
    }
    if ( val7 != null && val7.trim().length > 0 ) {
        val7c = val7;
    }
    if ( val8 != null && val8.trim().length > 0 ) {
        val8c = val8;
    }
    var content_show = "val1=";
    content_show += val1c +
        "&val2=" + val2c +
        "&val3=" + val3c +
        "&val4=" + val4c +
        "&val5=" + val5c +
        "&val6=" + val6c +
        "&val7=" + val7c +
        "&val8=" + val8c +
        "&soid=" + shiftOid +
        "&club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&event=" + eventOid +
        "&number=" + bagNum;
//  console.debug( content_show );
  $.ajax
    (
      {
         method: "get",
         url: "addtest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show("fast");$("#action").html(html); } //show the html inside .content div
      }
    );
//  console.debug( "call complete" );
}

function checkblur2(requestor, inm, eventOid)
{
    loonies = null;
    val = document.getElementById('loonies');
    if ( val != null ) {
        loonies = val.value;
    }
    toonies = null;
    val = document.getElementById('toonies');
    if ( val != null ) {
        toonies = val.value;
    }

    verify2( document.getElementById('coins').value,
              loonies, toonies,
              document.getElementById('fives').value,
              document.getElementById('tens').value,
              document.getElementById('twenties').value,
              document.getElementById('fifties').value,
              document.getElementById('hundreds').value,
              document.getElementById('credittens').value,
              document.getElementById('credittwenties').value,
              document.getElementById('creditfifties').value,
              document.getElementById('credithundreds').value,
              document.getElementById('creditother').value,
              document.getElementById('other').value,
              document.getElementById('currencyother').value,
              requestor, inm, eventOid );
}

function verify2( val1, val2, val3, val4, val5, val6, val7, val8, val9, val10, val11, val12, val13, val14, val15, requestor, inm, eventOid ) {
//  $("#action").hide(0);
    var val1c = "0";
    var val2c = "0";
    var val3c = "0";
    var val4c = "0";
    var val5c = "0";
    var val6c = "0";
    var val7c = "0";
    var val8c = "0";
    var val9c = "0";
    var val10c = "0";
    var val11c = "0";
    var val12c = "0";
    var val13c = "0";
    var val14c = "0";
    var val15c = "0";
    if ( val1 != null && val1.trim().length > 0 ) {
        val1c = val1;
    }
    if ( val2 != null && val2.trim().length > 0 ) {
        val2c = val2;
    }
    if ( val3 != null && val3.trim().length > 0 ) {
        val3c = val3;
    }
    if ( val4 != null && val4.trim().length > 0 ) {
        val4c = val4;
    }
    if ( val5 != null && val5.trim().length > 0 ) {
        val5c = val5;
    }
    if ( val6 != null && val6.trim().length > 0 ) {
        val6c = val6;
    }
    if ( val7 != null && val7.trim().length > 0 ) {
        val7c = val7;
    }
    if ( val8 != null && val8.trim().length > 0 ) {
        val8c = val8;
    }
    if ( val9 != null && val9.trim().length > 0 ) {
        val9c = val9;
    }
    if ( val10 != null && val10.trim().length > 0 ) {
        val10c = val10;
    }
    if ( val11 != null && val11.trim().length > 0 ) {
        val11c = val11;
    }
    if ( val12 != null && val12.trim().length > 0 ) {
        val12c = val12;
    }
    if ( val13 != null && val13.trim().length > 0 ) {
        val13c = val13;
    }
    if ( val14 != null && val14.trim().length > 0 ) {
        val14c = val14;
    }
    if ( val15 != null && val15.trim().length > 0 ) {
        val15c = val15;
    }
    var content_show = "val1=";
    content_show += val1c +
        "&val2=" + val2c +
        "&val3=" + val3c +
        "&val4=" + val4c +
        "&val5=" + val5c +
        "&val6=" + val6c +
        "&val7=" + val7c +
        "&val8=" + val8c +
        "&val9=" + val9c +
        "&val10=" + val10c +
        "&val11=" + val11c +
        "&val12=" + val12c +
        "&val13=" + val13c +
        "&val14=" + val14c +
        "&val15=" + val15c +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&event=" + eventOid;
  $.ajax
    (
      {
         method: "get",
         url: "cashtest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show(0);$("#action").html(html); } //show the html inside .content div
      }
    );
}

function checkblur3(phase, shiftOid, club, requestor, inm, review, eventOid) {
    var vals = '';
    var first = 1;
    var comm = document.getElementsByName( 'comments' );
    var comments = '';
    if ( comm != null ) {
      comments = comm[0].value;
    }

    var somepin = new Array();

    for ( var i=0; i < 40; i++ ) {
      var key = 'koid[' + i + ']';
      var elems = document.getElementsByName( key );
      for ( var j=0; j < elems.length; j++ ) {
        var elem = elems[j];
        var val = elem.value;
        if ( val != null && val.length > 0 ) {
          if ( !(val.toUpperCase() in somepin ) ) {
            somepin[val.toUpperCase()] = i;
            if ( first == 0 ) {
              vals += ",";
            }
            vals += val;
            first = 0;
          } else {
            elem.value = '';
          }
        }
      }
    }

    verify3( phase, club, vals, shiftOid, requestor, inm, comments, review, eventOid );
}

function verify3( phase, club, vals, shiftOid, requestor, inm, comments, review, eventOid )
{
  $("#action").hide(0);
  var content_show = {
        "p":phase,
        "vals":vals,
        "soid":shiftOid,
        "club":club,
        "inm":inm,
        "uoid":requestor,
        "comments":comments,
        "r":review,
        "event":eventOid};
  $.ajax
    (
      {
         method: "post",
         url: "cashouttest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show("fast");$("#action").html(html); } //show the html inside .content div
      }
    );
  $("#action").show(0);
}

function checkbackofbook(phase, shiftOid, club, requestor, inm, review, eventOid) {
    var vals = '';
    var vals1 = '';
    var first = 1;
    var comm = document.getElementsByName( 'comments' );
    var comments = '';
    if ( comm != null ) {
      comments = comm[0].value;
    }
    for ( var i=0; i < 40; i++ ) {
      var key = 'koid[' + i + ']';
      var elems = document.getElementsByName( key );
      var key1 = 'toid[' + i + ']';
      var elems1 = document.getElementsByName( key1 );
      for ( var j=0; j < elems.length; j++ ) {
        var val = elems[j].value;
        var val1 = elems1[j].value;
        if ( val.length > 0 ) {
          if ( first == 0 ) {
            vals += ",";
            vals1 += ",";
          }
          vals += val;
          vals1 += val1;
          first = 0;
        }
      }
    }

    verifybob( phase, club, vals, vals1, shiftOid, requestor, inm, comments, review, eventOid );
}

function verifybob( phase, club, vals, vals1, shiftOid, requestor, inm, comments, review, eventOid )
{
  $("#action").hide(0);
  var content_show = {
        "p":phase,
        "vals":vals,
        "vals1":vals1,
        "soid":shiftOid,
        "club":club,
        "inm":inm,
        "uoid":requestor,
        "comments":comments,
        "r":review,
        "event":eventOid};
  $.ajax
    (
      {
         method: "post",
         url: "cashouttest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show("fast");$("#action").html(html); } //show the html inside .content div
      }
    );
  $("#action").show(0);
}

function lotterytally( club, requestor, inm, eventOid )
{
  $("#action").hide(0);
  var content_show = "loid=" + document.getElementById('lottery').value +
        "&club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&event=" + eventOid;
  $.ajax
    (
      {
         method: "get",
         url: "lotterytally.php",
         data: content_show,
         beforeSend: function(){$("#loading").show(0);},
         complete: function(){$("#loading").hide(0);},
         success: function(html){ $("#action").show("fast");$("#action").html(html); } //show the html inside .content div
      }
    );
  $("#action").show(0);
}

function checkblur4(phase, shiftOid, club, requestor, inm, review, eventOid) {
    var voids = '';
    var first = 1;
    var somepin = new Array();
    for ( var i=0; i < 40; i++ ) {
      var key = 'toid[' + i + ']';
      var elems = document.getElementsByName( key );
      for ( var j=0; j < elems.length; j++ ) {
        var elem = elems[j];
        var vid = elem.value;
        if ( vid != null && vid.length > 0 ) {
          if ( !(vid.toUpperCase() in somepin ) ) {
            somepin[vid.toUpperCase()] = i;
            if ( first == 0 ) {
              voids += ",";
            }
            voids += vid;
            first = 0;
          } else {
            elem.value = '';
          }
        }
      }
    }

    verify4( phase, club, voids, shiftOid, requestor, inm, review, eventOid );
}

function verify4( phase, club, voids, shiftOid, requestor, inm, review, eventOid )
{
  $("#action").hide(0);
  var content_show = "p=" + phase +
        "&voids=" + voids +
        "&soid=" + shiftOid +
        "&club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&r=" + review +
        "&event=" + eventOid;
  $.ajax
    (
      {
         method: "get",
         url: "cashouttest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show("fast");$("#action").html(html); } //show the html inside .content div
      }
    );
  $("#action").show(0);
}

function updateTotals( tag ) {
    var overall = document.getElementById('overall');
    var booths  = document.getElementById('booths').value;
    var dates   = document.getElementById('dates').value;

    var boothOids = new Array();
    boothOids     = booths.split( ',' );
    var dateVals  = new Array();
    dateVals      = dates.split( ',' );

    var bits = new Array();
    bits     = tag.split( '_' );
    var dte  = bits[0];
    var bth  = bits[1];
    var tod  = bits[2];

    var i = 0;
    var boothTotal = 0;
    for ( i = 0; i < boothOids.length; i++ ) {
        var subtag = 'oid[' + dte + '_' + boothOids[i] + '_0]';
        boothTotal += document.getElementById(subtag).value;
        subtag = 'oid[' + dte + '_' + boothOids[i] + '_1]';
        boothTotal += document.getElementById(subtag).value;
        subtag = 'oid[' + dte + '_' + boothOids[i] + '_2]';
        boothTotal += document.getElementById(subtag).value;
    }
}

function checkTicketCount() {
    var strt = document.getElementById('start').value;
    var end  = document.getElementById('multi').value;

    var btn  = document.getElementById('sub');
    if ( strt != null && end != null ) {
        if ( ( end - strt + 1 ) > 80000 ) {
            window.alert( "Too many requested tickets at once. Please create less than 80000 tickets at a time." );
            btn.disabled = true;
        } else {
            btn.disabled = false;
        }
    } else {
        btn.disabled = false;
    }
    return btn.disabled;
}

function checkRoleValue() {
    var role = document.getElementById('role').value;

    var btn  = document.getElementById('submit');
    if ( role == -1 ) {
        btn.disabled = true;
        btn.title = "Choose a Role";
    } else {
        btn.disabled = false;
        btn.title = "";
    }
    return btn.disabled;
}

function setchecks( formname, field, checked ) {
    var elems;
    var form = document.getElementById(formname);
    if ( form != null ) {
        elems = form.elements;
    } else {
        elems = document.getElementsByTagName("input");
    }
    for ( var i = 0; i < elems.length; i++ ) {
        var elem = elems[i];
        if ( elem.name.indexOf( field ) != -1 ) {
            if ( checked == 1 ) {
                elem.checked = true;
            } else {
                elem.checked = false;
            }
        }
    }
}

function checkcontact() {
    var emailelem = document.getElementById("email");
    var nameelem = document.getElementById("firstName");
    var bodyelem = document.getElementById("body");
    var captchaelem = document.getElementById("holy");

    var result = "";

    if ( nameelem != null ) {
        var name = nameelem.value;
        if ( name.length <= 4 ) {
            result += "Please enter your name\n";
        }
    }
    if ( emailelem != null ) {
        var email = emailelem.value;
        if ( email.length <= 5 || email.indexOf("@") == -1 || email.indexOf(".") == -1 ) {
            result += "Invalid Email\n";
        }
    }
    if ( bodyelem != null ) {
        var body = bodyelem.value;
        if ( body.length <= 5 ) {
            result += "Please enter a message\n";
        }
    }
    if ( captchaelem != null ) {
        var cap = captchaelem.value;
        if ( cap.length == 0 ) {
            result += "Please answer the 'captcha' challenge\n";
        }
    }

    return result;
}

function getBookPreview( club, requestor, inm)
{
  var prefix = "-1";
  if ( document.getElementById('prefix') != null ) {
    if ( document.getElementById('prefix').value.length > 0 ) {
      prefix = document.getElementById('prefix').value;
    }
  }
  var start = "-1";
  if ( document.getElementById('start') != null ) {
    if ( document.getElementById('start').value.length > 0 ) {
      start = document.getElementById('start').value;
    }
  }
  var number = "-1";
  if ( document.getElementById('number') != null ) {
    if ( document.getElementById('number').value.length > 0 ) {
      number = document.getElementById('number').value;
    }
  }
  var cost = "-1";
  if ( document.getElementById('cost') != null ) {
    if ( document.getElementById('cost').value.length > 0  ) {
      cost = document.getElementById('cost').value;
    }
  }
  var finish = "-1";
  if ( document.getElementById('multi') != null ) {
    if ( document.getElementById('multi').value > 0 ) {
      finish = document.getElementById('multi').value;
    }
  }

  $("#preview").hide(0);
  var content_show = "club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&prefix=" + prefix +
        "&start=" + start +
        "&multi=" + finish +
        "&number=" + number +
        "&cost=" + cost;
  $.ajax
    (
      {
         method: "get",
         url: "bookpreview.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#preview").show("fast");$("#preview").html(html); } //show the html inside .content div
      }
    );
  $("#preview").show(0);
}

function checkblur5(phase, shift, club, requestor, inm, review, eventOid)
{
    loonies = null;
    val = document.getElementById('loonies');
    if ( val != null ) {
        loonies = val.value;
    }
    toonies = null;
    val = document.getElementById('toonies');
    if ( val != null ) {
        toonies = val.value;
    }
    verify5( phase, shift, club,
              document.getElementById('coins').value,
              loonies, toonies,
              document.getElementById('fives').value,
              document.getElementById('tens').value,
              document.getElementById('twenties').value,
              document.getElementById('fifties').value,
              document.getElementById('hundreds').value,
              document.getElementById('credittens').value,
              document.getElementById('credittwenties').value,
              document.getElementById('creditfifties').value,
              document.getElementById('credithundreds').value,
              document.getElementById('creditother').value,
              document.getElementById('other').value,
              document.getElementById('currencyother').value,
              requestor, inm, review, eventOid );
}

function verify5( phase, shift, club, val1, val2, val3, val4, val5, val6, val7, val8, val9, val10, val11, val12, val13, val14, val15, requestor, inm, review, eventOid ) {
    var val1c = "0";
    var val2c = "0";
    var val3c = "0";
    var val4c = "0";
    var val5c = "0";
    var val6c = "0";
    var val7c = "0";
    var val8c = "0";
    var val9c = "0";
    var val10c = "0";
    var val11c = "0";
    var val12c = "0";
    var val13c = "0";
    var val14c = "0";
    var val15c = "0";
    if ( val1 != null && val1.trim().length > 0 ) {
        val1c = val1;
    }
    if ( val2 != null && val2.trim().length > 0 ) {
        val2c = val2;
    }
    if ( val3 != null && val3.trim().length > 0 ) {
        val3c = val3;
    }
    if ( val4 != null && val4.trim().length > 0 ) {
        val4c = val4;
    }
    if ( val5 != null && val5.trim().length > 0 ) {
        val5c = val5;
    }
    if ( val6 != null && val6.trim().length > 0 ) {
        val6c = val6;
    }
    if ( val7 != null && val7.trim().length > 0 ) {
        val7c = val7;
    }
    if ( val8 != null && val8.trim().length > 0 ) {
        val8c = val8;
    }
    if ( val9 != null && val9.trim().length > 0 ) {
        val9c = val9;
    }
    if ( val10 != null && val10.trim().length > 0 ) {
        val10c = val10;
    }
    if ( val11 != null && val11.trim().length > 0 ) {
        val11c = val11;
    }
    if ( val12 != null && val12.trim().length > 0 ) {
        val12c = val12;
    }
    if ( val13 != null && val13.trim().length > 0 ) {
        val13c = val13;
    }
    if ( val14 != null && val14.trim().length > 0 ) {
        val14c = val14;
    }
    if ( val15 != null && val15.trim().length > 0 ) {
        val15c = val15;
    }
    var content_show = "p=" + phase +
        "&moneys=" + val1c +
        "," + val2c +
        "," + val3c +
        "," + val4c +
        "," + val5c +
        "," + val6c +
        "," + val7c +
        "," + val8c +
        "," + val9c +
        "," + val10c +
        "," + val11c +
        "," + val12c +
        "," + val13c +
        "," + val14c +
        "," + val15c +
        "&soid=" + shift +
        "&club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&r=" + review +
        "&event=" + eventOid;
  $.ajax
    (
      {
         method: "get",
         url: "cashouttest.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#action").show(0);$("#action").html(html); } //show the html inside .content div
      }
    );
}

function toggleComments(whichLayer, shows, hides) {
    toggleLayer(whichLayer);
    toggleLayer(shows);
    toggleLayer(hides);
}

function showComments(whichLayer, shows, hides) {
    showLayer(whichLayer);
    hideLayer(shows);
    showLayer(hides);
}

function hideComments(whichLayer, shows, hides) {
    hideLayer(whichLayer);
    showLayer(shows);
    hideLayer(hides);
}

function loadHtmlTopics(requestor,inm,club) {
  var keywords = document.getElementById("keys").value;
  var content_show = "club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor +
        "&main=" + keywords +
        "&tag=1";
  $.ajax
    (
      {
         method: "get",
         url: "helpl.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#answer").show("fast");$("#answer").html(html); } //show the html inside .content div
      }
    );
}

function setDivHtml(divid,keyword,requestor,inm,club,page,tog) {
  var content_show = "club=" + club +
        "&inm=" + inm +
        "&uoid=" + requestor;
  if ( tog==0 ) {
    content_show += "&main=" + keyword;
  } else {
    content_show += "&hoid=" + keyword;
  }
  $.ajax
    (
      {
         method: "get",
         url: page,
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#" + divid).show("fast");$("#" + divid).html(html); } //show the html inside .content div
      }
    );
}

function toggleLayer(whichLayer)
{
  var res = false;
  if (document.getElementById)
  {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    if ( style2.display == "block" ) {
      style2.display = "none";
      res = false;
    } else {
      style2.display = "block";
      res = true;
    }
  } else if (document.all) {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = (style2.display == "block" ) ? "none":"block";
  } else if (document.layers) {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = (style2.display == "block" ) ? "none":"block";
  }
  return res;
}

function showLayer(whichLayer)
{
  if (document.getElementById)
  {
    // this is the way the standards work
    var elem   = document.getElementById(whichLayer);
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "block";
    }
  } else if (document.all) {
    // this is the way old msie versions work
    var elem   = document.all[whichLayer];
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "block";
    }
  } else if (document.layers) {
    // this is the way nn4 works
    var elem   = document.layers[whichLayer];
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "block";
    }
  }
}

function hideLayer(whichLayer)
{
  if (document.getElementById)
  {
    // this is the way the standards work
    var elem   = document.getElementById(whichLayer);
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "none";
    }
  } else if (document.all) {
    // this is the way old msie versions work
    var elem   = document.all[whichLayer];
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "none";
    }
  } else if (document.layers) {
    // this is the way nn4 works
    var elem   = document.layers[whichLayer];
    if ( elem != null ) {
      var style2 = elem.style;
      style2.display = "none";
    }
  }
}

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

// open hidden layer
function mopen(id)
{
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose;

function presentlist( requestor, inm, page, format, area, rpage, rtag, rval, where, draggable ) {
  var listbutton = document.getElementById('picklist');
  var iconbutton = document.getElementById('pickicon');
  var detailbutton = document.getElementById('pickdetail');

  // change the buttons
  if ( format == 1 ) {
    listbutton.src="images/b_list_sel.png";
    iconbutton.src="images/b_icon.png";
    detailbutton.src="images/b_detail.png";
  } else if ( format == 2 ) {
    listbutton.src="images/b_list.png";
    iconbutton.src="images/b_icon.png";
    detailbutton.src="images/b_detail_sel.png";
  } else if ( format == 3 ) {
    listbutton.src="images/b_list.png";
    iconbutton.src="images/b_icon_sel.png";
    detailbutton.src="images/b_detail.png";
  }

  // collect the search text
  var snippetId = document.getElementById('nf');
  var snippet = "";
  if ( snippetId != null ) {
    snippet = snippetId.value;
  }

  var content_show = "uoid=";
  content_show += requestor +
    "&inm=" + inm +
    "&wht=" + format;
  if ( snippet != null && snippet.length > 0 ) {
    content_show += "&nf=" + snippet;
  }
  if ( where != null && where.length > 0 ) {
    content_show += "&whr=" + where;
  }
  if ( rpage != null && rpage.length > 0 ) {
    content_show += "&pge=" + rpage;
  }
  if ( rtag != null && rtag.length > 0 ) {
    content_show += "&tag=" + rtag;
  }
  if ( rval != null && rval.length > 0 ) {
    content_show += "&val=" + rval;
  }

  $.ajax
    (
      {
         method: "get",
         url: page,
         data: content_show,
         beforeSend: function(){},
         complete: function(){draggie();},
         success: function(html){ $(area).show("fast");$(area).html(html); } //show the html inside .content div
      }
    );
}

function filterlist( requestor, inm, page, area, rpage, rtag, rval, where ) {
  // collect the search text
  var snippetId = document.getElementById('nf');
  var snippet = "";
  if ( snippetId != null ) {
    snippet = snippetId.value;
  }

  var content_show = "uoid=";
  content_show += requestor +
    "&inm=" + inm +
    "&for=1";
  if ( snippet != null && snippet.length > 0 ) {
    content_show += "&nf=" + snippet;
  }
  if ( where != null && where.length > 0 ) {
    content_show += "&whr=" + where;
  }
  if ( rpage != null && rpage.length > 0 ) {
    content_show += "&pge=" + rpage;
  }
  if ( rtag != null && rtag.length > 0 ) {
    content_show += "&tag=" + rtag;
  }
  if ( rval != null && rval.length > 0 ) {
    content_show += "&val=" + rval;
  }

  $.ajax
    (
      {
         method: "get",
         url: page,
         data: content_show,
         beforeSend: function(){},
         complete: function(){draggie();},
         success: function(html){ $(area).show("fast");$(area).html(html); } //show the html inside .content div
      }
    );
}

function selectrow( oid ) {
    var rowId = document.getElementById('row'+oid);

    if ( rowId != null ) {
        if ( rowId.className == "list0" ) {
            rowId.className = "list0sel";
        } else if ( rowId.className == "list1" ) {
            rowId.className = "list1sel";
        } else if ( rowId.className == "list0sel" ) {
            rowId.className = "list0";
        } else if ( rowId.className == "list1sel" ) {
            rowId.className = "list1";
        } else if ( rowId.className == "detail0" ) {
            rowId.className = "detail0sel";
        } else if ( rowId.className == "detail1" ) {
            rowId.className = "detail1sel";
        } else if ( rowId.className == "detail0sel" ) {
            rowId.className = "detail0";
        } else if ( rowId.className == "detail1sel" ) {
            rowId.className = "detail1";
        } else if ( rowId.className == "icon" ) {
            rowId.className = "iconsel";
        } else if ( rowId.className == "iconsel" ) {
            rowId.className = "icon";
        }
    }
}

function adminit( uoid, im, phases, pages, verifies) {
    var phaseId = document.getElementById('p');

    if ( phaseId != null && phaseId.value > 0 ) {
        var phase = phaseId.value;
        var lis = document.getElementsByTagName( 'div' );
        var selected = new Array();
        if ( lis != null ) {
            var ndx = 0;
            for ( i = 0; i < lis.length; i++ ) {
                var lirow = lis[i];
                if ( lirow.className != null && lirow.className.search( "sel" ) > 0 ) {
                    selected[ndx] = lirow;
                    ndx++;
                }
            }
        }
        if ( selected.length > 0 ) {
            var oidlist = "";
            var areyousure = "Are you sure you want to delete ";
            for ( i = 0; i < selected.length; i++ ) {
                var lirow = selected[i];

                if ( i > 0 ) {
                    oidlist += ",";
                    areyousure += ", ";
                }
                var chars = lirow.id.length-3;
                oidlist += lirow.id.substr( 3, chars );
                areyousure += lirow.attributes['name'].value;
            }
            areyousure += "?";

            var phasevals  = phases.split(',');
            var pagevals   = pages.split(',');
            var verifyvals = verifies.split(',');

            for ( i = 0; i < phasevals.length; i++ ) {
                var phasetemp = parseInt( phasevals[i] );
                if ( phase == phasetemp ) {
                    var verify = parseInt( verifyvals[i] );
                    var page   = pagevals[i];
                    if ( verify == 0 ) {
                        window.location = page + "?p=" + phase + "&oids=" + oidlist;
                    } else {
                        if ( confirm( areyousure ) ) {
                            window.location = page + "?p=" + phase + "&oids=" + oidlist;
                        }
                    }
                    break;
                }
            }
        } else {
            alert( "No selection made. Select items first, then choose action" );
            phaseId.value = 0;
        }
    }

}

function showAddCode( uoid, inm, category, tag ) {
  var content_show = "uoid=";
  content_show += uoid +
    "&inm=" + inm +
    "&category=" + category +
    "&tag=" + tag;

  $.ajax
    (
      {
         method: "get",
         url: "codeaction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#addcode").show("fast");$("#addcode").html(html); } //show the html inside .content div
      }
    );
}

function commitAddCode( uoid, inm, category, customer, tag ) {
  var nameo="";
  var deaf=0;

  var namer = document.getElementById('nameo');
  if ( namer != null ) {
    nameo = namer.value;
  }
  var defaulto = document.getElementById("codercombo");
  if ( defaulto != null ) {
    deaf = defaulto.value;
  }

  var content_show = "uoid=";
  content_show += uoid +
    "&inm=" + inm +
    "&category=" + category +
    "&tag=" + tag +
    "&customer=" + customer +
    "&wht=2&name=" + nameo +
    "&val=" + deaf;

  $.ajax
    (
      {
         method: "get",
         url: "codeaction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#codecombo").show("fast");$("#codecombo").html(html); } //show the html inside .content div
      }
    );
  document.getElementById("addcode").style.display = "none";
}

function showsetprogress( taskoid ) {
  var loc = "setprogress" + taskoid;
  document.getElementById(loc).style.display = "block";
}

function showslider( formname, inputname, destname ) {

    var A_TPL1h = {
    'b_vertical' : false,
    'b_watch': true,
    'n_controlWidth': 120,
    'n_controlHeight': 16,
    'n_sliderWidth': 16,
    'n_sliderHeight': 15,
    'n_pathLeft' : 1,
    'n_pathTop' : 1,
    'n_pathLength' : 103,
    's_imgControl': '../images/blueh_bg.gif',
    's_imgSlider': '../images/blueh_sl.gif',
    'n_zIndex': 1
    }
    var A_INIT1h = {
    's_form' : '" . formname . "',
    's_name': '" . inputname . "',
    'n_minValue' : 0,
    'n_maxValue' : 100,
    'n_value' : 20,
    'n_step' : 1
    }
    new slider(A_INIT1h, A_TPL1h, destname);
}

function commitsetprogress( uoid, inm, taskoid, ndx ) {
  var nameo="";

  var namer = document.getElementById('percentcomplete' + ndx);
  if ( namer != null ) {
    nameo = namer.value;
  }

  var content_show = "uoid=";
  content_show += uoid +
    "&wht=2&inm=" + inm +
    "&cnoid=" + taskoid +
    "&percentcomplete=" + nameo;

  $.ajax
    (
      {
         method: "get",
         url: "taskaction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#progress" + taskoid).show("fast");$("#progress" + taskoid).html(html); } //show the html inside .content div
      }
    );
  var loc = "setprogress" + taskoid;
  document.getElementById(loc).style.display = "none";
}

function draggie() {
    $('.draggie').draggable({
        opacity: 0.7,
        helper: 'clone',
        containment: 'document',
        cursor: 'move'
    });
}

var months = new Array();
months[1]="Jan";
months[2]="Feb";
months[3]="Mar";
months[4]="Apr";
months[5]="May";
months[6]="Jun";
months[7]="Jul";
months[8]="Aug";
months[9]="Sep";
months[10]="Oct";
months[11]="Nov";
months[12]="Dec";

function taskpostdrag( event, ui, taskoid, equipmentstart ) {
    var oid = taskoid;
    var earliestdate = Date.parse( equipmentstart );
    var millidelta = (ui.position.left - ui.originalPosition.left)/12 * 86400000;
    var originalstartelem = document.getElementById( 'taskstart' + oid );
    var originalfinishelem = document.getElementById( 'taskfinish' + oid );
    if ( originalstartelem != null && originalfinishelem != null ) {
        var originalstart = originalstartelem.value;
        var originalfinish = originalfinishelem.value;
        var syear = originalstart.substring( 0, 4 );
        var fyear = originalfinish.substring( 0, 4 );
        var subs  = originalstart.substring( 5, 6 );
        var vals  = 1;
        if ( subs == "0" )
            vals = parseInt(originalstart.substring( 6, 7 ) );
        else
            vals = parseInt(originalstart.substring( 5, 7 ) );
        var smnth = months[vals];
        subs  = originalfinish.substring( 5, 6 );
        vals  = 1;
        if ( subs == "0" )
            vals = parseInt(originalfinish.substring( 6, 7 ) );
        else
            vals = parseInt(originalfinish.substring( 5, 7 ) );
        var fmnth = months[vals];
        var sday = originalstart.substring( 8 );
        var fday = originalfinish.substring( 8 );
        var stime = Date.parse( smnth + ' ' + sday + ', ' + syear );
        var ftime = Date.parse( fmnth + ' ' + fday + ', ' + fyear );
        var newstime = stime + millidelta;
        if ( newstime < earliestdate ) {
            millidelta = earliestdate - stime;
        }
        var newtimes = new Date(stime + millidelta);
        var newtimef = new Date(ftime + millidelta);
        var d  = newtimes.getDate();
        var day = (d < 10) ? '0' + d : d;
        var m = newtimes.getMonth() + 1;
        var month = (m < 10) ? '0' + m : m;
        var year = newtimes.getFullYear();
        originalstartelem.value = year + '-' + month + '-' + day;
        d  = newtimef.getDate();
        day = (d < 10) ? '0' + d : d;
        m = newtimef.getMonth() + 1;
        month = (m < 10) ? '0' + m : m;
        year = newtimef.getFullYear();
        originalfinishelem.value = year + '-' + month + '-' + day;
    }
}

function taskpostresize( event, ui, taskoid, equipmentstart ) {
    var oid = taskoid;
    var millidelta = (ui.size.width - ui.originalSize.width)/12 * 86400000;
    var originalfinishelem = document.getElementById( 'taskfinish' + oid );
    if ( originalfinishelem != null ) {
        var originalfinish = originalfinishelem.value;
        var fyear = originalfinish.substring( 0, 4 );
        var subs  = originalfinish.substring( 5, 6 );
        var vals  = 1;
        if ( subs == "0" )
            vals = parseInt(originalfinish.substring( 6, 7 ) );
        else
            vals = parseInt(originalfinish.substring( 5, 7 ) );
        var fmnth = months[vals];
        var fday = originalfinish.substring( 8 );
        var ftime = Date.parse( fmnth + ' ' + fday + ', ' + fyear );
        var newtimef = new Date(ftime + millidelta);
        var d  = newtimef.getDate();
        var day = (d < 10) ? '0' + d : d;
        var m = newtimef.getMonth() + 1;
        var month = (m < 10) ? '0' + m : m;
        var year = newtimef.getFullYear();
        originalfinishelem.value = year + '-' + month + '-' + day;
    }
}

function toggleprojectdashboard(uoid, inm) {
    var header = document.getElementById('titledash');
    var link   = document.getElementById('togglelink');
    var pge    = "taskaction.php";

    var setting = 0;
    if ( header != null && header.innerHTML == 'Tasks' ) {
        header.innerHTML = 'Projects';
        link.innerHTML   = 'Task Centric';
        setting = 1;
        pge     = "projectaction.php";
    } else {
        header.innerHTML = 'Tasks';
        link.innerHTML   = 'Project Centric';
    }

    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&dir=" + setting +
        "&page=index.php" +
        "&tab=1&p=17";

  $.ajax
    (
      {
         method: "get",
         url: "pref_.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){} //discard the return html
      }
    );

    content_show = "uoid=" + uoid +
        "&inm=" + inm +
        "&wht=1";

  $.ajax
    (
      {
         method: "get",
         url: pge,
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#projdash").show("fast");$("#projdash").html(html); } //show the html inside .content div
      }
    );

}

function commitmonthchoice(uoid, inm, page, tag, val) {
    var input  = document.getElementById('mnths');
    var months = 1;
    var link   = document.getElementById('mcnt');
    var pge    = "calendaraction.php";

    var setting = 0;
    if ( input != null ) {
        months = input.value;
    }
    link.innerHTML = months;

    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&dir=" + months +
        "&page=index.php" +
        "&tab=2&p=17";

  $.ajax
    (
      {
         method: "get",
         url: "pref_.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){} //discard the return html
      }
    );

    var dateo = document.getElementById('dte').value;

    content_show = "uoid=" + uoid +
        "&inm=" + inm +
        "&wht=1&dte=" + dateo +
        "&pge=" + page +
        "&tag=" + tag +
        "&val=" + val;

  $.ajax
    (
      {
         method: "get",
         url: pge,
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#calendar1").show("fast");$("#calendar1").html(html); } //show the html inside .content div
      }
    );

    document.getElementById( 'monthchoice' ).style.display = 'none';
}

function commitdisplaychoice(uoid, inm, page, tag, val) {
    var choices = 0;
    var input = null;
    for ( var i = 0; i < 5; i++ ) {
        input  = document.getElementById('choice'+i);
        if ( input != null && input.checked==true ) {
            choices += input.value;
        }
    }
    var pge    = "calendaraction.php";

    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&dir=" + choices +
        "&page=index.php" +
        "&tab=3&p=17";

  $.ajax
    (
      {
         method: "get",
         url: "pref_.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){} //discard the return html
      }
    );

    var dateo = document.getElementById('dte').value;

    content_show = "uoid=" + uoid +
        "&inm=" + inm +
        "&wht=1&dte=" + dateo +
        "&pge=" + page +
        "&tag=" + tag +
        "&val=" + val;

  $.ajax
    (
      {
         method: "get",
         url: pge,
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#calendar1").show("fast");$("#calendar1").html(html); } //show the html inside .content div
      }
    );

    document.getElementById( 'itemlist' ).style.display = 'none';
}

function changemonthdate( uoid, inm, dateo, page, tag, val ) {
    var input  = document.getElementById('dte');
    if ( input != null ) {
        input.value = dateo;
    }

    content_show = "uoid=" + uoid +
        "&inm=" + inm +
        "&wht=1&dte=" + dateo +
        "&pge=" + page;
    if ( tag != null && tag.length > 0 ) {
        content_show += "&tag=" + tag +
            "&val=" + val;
    }

  $.ajax
    (
      {
         method: "get",
         url: "calendaraction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $("#calendar1").show("fast");$("#calendar1").html(html); } //show the html inside .content div
      }
    );

}

function markstarted( uoid, inm, page, tag, val, phase, div ) {

    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&wht=" + phase +
        "&" + tag + "=" + val;

  $.ajax
    (
      {
         method: "get",
         url: page,
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){ $(div).show("fast");$(div).html(html); } //show the html inside .content div
      }
    );
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

function messageinput( uoid, inm, phase, tag, oid, page, ptag, value ) {
    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&" + tag + "=" + oid +
        "&wht=1" +
        "&pge=" + page +
        "&tag=" + ptag +
        "&val=" + value +
        "&p=" + phase;
  $.ajax
    (
      {
         method: "get",
         url: "messageaction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){$("#activity").show("fast");$("#activity").html(html);} //use the return html to set the style attribute
      }
    );

}

function messageaction( uoid, inm, moid, phase ) {
    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&p=" + phase +
        "&msgoid=" + moid;
  $.ajax
    (
      {
         method: "get",
         url: "messageaction.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){
            if(html!=null && html.length > 0){
                $("#message").show("fast");
                $("#message").html(html);
            }else{
                $("#message").hide("fast");
            }
         } //use the return html to set the style attribute
      }
    );

}

function toggleauditlist( divname, buttonname ) {
    var div = document.getElementById( divname );
    var btn = document.getElementById( buttonname );

    if ( div != null ) {
        if ( div.style.display == 'none' || div.style.display == '' ) {
            div.style.display = 'block';
            btn.src   = 'images/b_up.png';
            btn.title = 'Hide Audit History';
        } else {
            div.style.display = 'none';
            btn.src   = 'images/b_down.png';
            btn.title = 'Show Audit History';
        }
    }

}

function fadeIn( elemid ) {
    var toggelem = document.getElementById(elemid+'togg');
    if ( toggelem.value == 'in' ) {
        var opacelem = document.getElementById(elemid+'opac');
        var opac = parseFloat( opacelem.value );
        if ( opac < 1 ) {
            var elem = document.getElementById( elemid );
            elem.style.opacity = opac;
            if ( opac > 0.2 ) {
                elem.style.display = "block";
            }
            var fade = function() { fadeIn(elemid); };
            setTimeout(fade,10);
            opac += 0.01;
            opacelem.value = opac;
            var table = document.getElementById(elemid+'tbl');
            var url = "url(images/thumb_background.png)";
            if ( opac > 0.2 ) {
                table.style.backgroundImage = url;
            }
        } else {
            var elem = document.getElementById( elemid );
            elem.style.opacity = 1;
            elem.style.display = "block";
            opacelem.value = 1;
            var url = "url(images/thumb_background.png)";
            table.style.backgroundImage = url;
        }
    }
}

function fadeOut( elemid ) {
    var toggelem = document.getElementById(elemid+'togg');
    if ( toggelem.value == 'out' ) {
        var opacelem = document.getElementById(elemid+'opac');
        var opac = parseFloat( opacelem.value );
        if ( opac > 0 ) {
            var elem = document.getElementById( elemid );
            elem.style.opacity = opac;
            if ( opac < 0.8 ) {
                elem.style.display = "none";
            }
            var fade = function() { fadeOut(elemid); };
            var table = document.getElementById(elemid+'tbl');
            setTimeout(fade,10);
            opac -= 0.01;
            opacelem.value = opac;
            if ( opac < 0.8 ) {
                table.style.backgroundImage = "";
            }
        } else {
            var elem = document.getElementById( elemid );
            elem.style.opacity = 0;
            elem.style.display = "none";
            opacelem.value = 0;
            var table = document.getElementById(elemid+'tbl');
            table.style.backgroundImage = "";
        }
    }
}

function changepointdaterange( roid, inm, uoid, pagename ) {
    var elem = document.getElementById('dte');
    var content_show = "uoid=";
    content_show += roid +
        "&inm=" + inm +
        "&val=" + uoid +
        "&doid=" + elem.value;

    var content_show1 = content_show;
    content_show1 += "&wht=1";
    var content_show2 = content_show;
    content_show2 += "&wht=2";

    $.ajax
    (
      {
         method: "get",
         url: "points.php",
         data: content_show1,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){$("#pointslist").show("fast");$("#pointslist").html(html);} //use the return html to set the style attribute
      }
    );

    $.ajax
    (
      {
         method: "get",
         url: "points.php",
         data: content_show2,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){
                var elem = document.getElementById("page_title");
                elem.innerHTML = "Points" + html;
                document.title = pagename + " - " + elem.innerHTML;
             } //use the return html to set the page title
      }
    );
}

function getbalance( uoid, inm, tag, divdest ) {
    var elem = document.getElementById(tag);
    var content_show = "uoid=";
    content_show += uoid +
        "&inm=" + inm +
        "&val=" + elem.value +
        "&wht=3";

    $.ajax
    (
      {
         method: "get",
         url: "points.php",
         data: content_show,
         beforeSend: function(){},
         complete: function(){},
         success: function(html){$("#" + divdest).show("fast");$("#" + divdest).html(html);} //use the return html to set the style attribute
      }
    );
}
