// javascript library
//cb vars
var CBwin = null;
var sCBT = "";

// timer vars & other globs
var lH, lM, lS, lZ, lT;
var lDur, sU, lTo;

function checkparent() {
// return to index if this is not a frame
  if (self.parent == self) {
    self.location.href = '/';
  }
}

function fire (n, u) {
// got ot url U after n minutes; set globs
  sU = u;   lDur = n;   lH = 0;
  lT = 0;   lM = 0;   lS = 0; lZ = 0;
  // start timer
  lTo = setTimeout("timer()", 1000);
}

function timer() {
var d = new Date();
var sT = '';
var w, h;

  lS++; lZ++; 

  if (lS == 59) {
    lM++;     lT++;     lS = 0;
    if (lM == 59) {lH++; lM = 0; }
  }
  lH < 10 ? sT = '0' + lH : sT = lH;
  lM < 10 ? sT = sT + ':0' + lM : sT = sT + ':' + lM;
  lS < 10 ? sT = sT + ' 0' + lS : sT = sT + ' ' + lS;

  with (self.document.mForm) {
    sDur.value = sT;

    if (lZ >= lDur) {
      w = (screen.availWidth||screen.width) - 60
      h = (screen.availHeight||screen.height) - 60

      clearTimeout(lTo);
      //Mwin = window.open('','aWin','width=' + w + ',height=' + h + ',left=15,top=15 resizable=yes,status=yes,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
      Mwin = window.open('','aWin','width=' + w + ',height=' + h + ',left=15,top=15 resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');

      target = 'aWin';
      //lI.value = '1';

      submit();
      //self.close();
      setTimeout("closeme('0');", 1000);
      //closeme('0');
    }
    else {
      lTo = setTimeout ("timer()", 1000);
    }
  }
}

function closeme(n) {
  if (n == 0) {
    self.close();
  }
  else {
    self.document.mForm.submit();
    self.close();
  }
}

function chkstr (s, e) {
// check string s for 'suspicious' rude words and dump results in e (a form element)
var pa, se, v;
  se = new String(s);
  se.replace (/\n/, ' '); // replace newline chars

  //pa = /\b[a-z]+([^a-z0-9 \n\t]|[^a-z0-9\n\t]+ *[^a-z0-9\n\t]+)\b[a-z]+/i;  

  pa = /\b[a-z]+([^a-z0-9 \n\t\.\,\'\"\;]+ *[^a-z0-9\n\t\.\,\'\"\;]*)\b[a-z]+/i;  
  v = pa.test(se) ? 10 : 0;

  eval('document.' + e).value = v;
}

function hpmgr(u) {
var rWin = window.open(u,'Kiosk','width=780,height=480,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
rWin.focus();
}

function kiosk(u, u2) {
var rWin = window.open('','Kiosk','width=780,height=480,resizable=yes,status=no,scrollbars=no,buttons=no,location=no,menubar=no,directories=no,toolbar=no');

  if (u == null) { u = 'about:blank'; }
  if (u2 != null) { // two-frame kiosk  
    rWin.document.open();
    with (rWin.document) {
      write('<frameset rows="*,26" frameborder="0">\n');
      write('<frame src="' + u + '" name="kMain">\n');
      write('<frame src="' + u2 + '" name="kBot">\n');
      write('</frameset>\n');
    }
    rWin.document.close();
  }
  else { // 1 window
    rWin.location.href = u;
  }
}

function help(u) {
window.open("/help/help.asp",'Help','width=320,height=400,resizable=yes,status=yes,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
}

function chatwindow()
{
window.open ("../asp/appCmnChatRoomFrameset.asp","new_window","width=600,height=400,resizable=yes,status=yes,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no"); 
}

function viewurl(u) {
  var vWin = window.open(u,'vWin');
}

function recwin(p)
{
window.open (p,"recwin","width=400,height=300,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no"); 
}

function msgwin(p)
{
window.open (p,"msgwin","width=300,height=300,resizable=yes,status=no,scrollbars=no,buttons=no,location=no,menubar=no,directories=no,toolbar=no"); 
}

function alive() 
{
var awin = open("","alive","width=250,height=150,resizable=no,status=no,scrollbars=no,buttons=no,location=no,menubar=no,directories=no,toolbar=no");
awin.document.open;
with (awin.document)
{
write('<html>\n');
write('<head><title>Keeping Session Alive</title></head>\n');
write('<frameset rows="0,*" frameborder=0>\n');
write('<frame name="top" src="/asp/alivetop.asp">\n');
write('<frame name="bottom" src="/asp/alivebottom.asp">\n');
write('</frameset>\n');
write('</html>');
}
awin.document.close;
}

function combanks(u, s) {
//open comment banks

var p1, p2;

  p1 = u == null ? 0 : u;
  p2 = s == null ? 0 : s;

  CBwin = window.open ('/asp/cbgetcommentsbox.asp?lP=' + p1 + '&lS=' + p2,"CBwin","width=800,height=480,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no"); 

  CBwin.focus();
}

function getcbtext (u, s) {
// return selected cb text
var r = false;

  sCBT = "Sorry, comments were not found.\n\nMake sure you have selected a comment in the comments bank window first."
  if ( (CBwin==null) || (CBwin.closed) || (CBwin.document.bForm.sCom==null) ) {
    combanks(u, s);
  }
  else {
    sCBT = CBwin.document.bForm.sCom.value;
    r = true;
  }

  return (r);
}

function mainwin() {
  if ( (self.opener != null) && (!self.opener.closed) ) {
    self.opener.focus();
  }
  else {
    alert('Sorry, the main browser window is not open');
  }
}

function amend (o, u, s){
  if ( (CBwin==null) || (CBwin.closed) || (CBwin.document.bForm.sCom==null) )
    combanks(u, s);
  else
    CBwin.document.bForm.sCom.value = eval(o).value;

  CBwin.focus();

}


function paste (o, u, s) {

  if (getcbtext(u, s)) {
    eval(o).value += sCBT;
  }
  else {
    if ( (CBwin != null) && (!CBwin.closed) ) { CBwin.focus(); }
  }
}

function popwin(u, x, y, n) {

var r = n;
  if (r == null) {r = '1';}

window.open(u,'Browse' + n,'width=' + x + ',height=' + y + ',resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
}

function imagewin(u, t) {
 var st = t;
 var iwin = window.open('','iwin','width=300,height=300,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
 if (st == null) { st = "image"; }
 iwin.document.open();
 with (iwin.document) {
  write('<center><img src="' + u + '" border=0 alt="' + t + '"><p>\n');
  write('<a href="javascript:self.close()"><img src="/img/close0.gif" border="0" alt="close box"></a>\n');
 }
 iwin.document.close();
}

function modulewin(u) {
var w = (screen.availWidth||screen.width) - 60
var h = (screen.availHeight||screen.height) - 60
var ModWin = window.open(u,'Module','width=' + w + ',height=' + h + ',left=15,top=15,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
  ModWin.focus();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function browsewin(u) {

window.open(u,'Browse','width=550,height=400,resizable=yes,status=no,scrollbars=yes,buttons=no,location=no,menubar=no,directories=no,toolbar=no');
}

function showlayer(layername, Str)
{
 obj = (document.layers)?document.layers[layername]:document.all[layername];
 if(obj && document.all) obj = obj.style;
 if(obj) obj.visibility=Str;
}

//simple browser check 
f7_v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0 
f7_ie=(document.all && f7_v4)?1:0 
f7_ns=(document.layers && f7_v4)?1:0

//code for drops
function f7_showdrop(thelayer){
  f7_keep=thelayer; f7_hideall(); f7_showitnow=1
  f7_showit(thelayer)
  }
function f7_showit(thelayer){
  if(f7_ie){ eval(f7_droplayer[thelayer]+ '.style.visibility="visible"') }
  if(f7_ns){ eval('document.'+f7_droplayer[thelayer]+ '.visibility="show"');}
  }
function f7_hidedrop(){
  f7_keep=-1; setTimeout('f7_hideall()',500)
  }
f7_keep=-1
function f7_hideall(){
  for(i=0;i<f7_droplayer.length;i++){ 
    f7_hideit=0; f7_checkmousepos(i)
    if(f7_ie && f7_keep!=i){ 
      if(f7_hideit){ eval(f7_droplayer[i]+'.style.visibility="hidden"') } 
      }
    if(f7_ns && f7_keep!=i){ 
      if(f7_hideit){ eval('document.'+f7_droplayer[i]+'.visibility="hide"') }
      }
    }
  }

//deal with cursor over layer
document.onmousemove = f7_getmousepos
if (f7_ns) document.captureEvents(Event.MOUSEMOVE)
function f7_getmousepos(e){
  if(f7_ns){f7_mousex=e.pageX; f7_mousey=e.pageY}
  if(f7_ie){f7_mousex=event.clientX; f7_mousey=event.clientY;}
  }
function f7_checkmousepos(i){ 
  if(f7_ns){ 
    f7_x_min=eval('document.'+f7_droplayer[i]+'.left')
    f7_x_max=f7_x_min+eval('document.'+ f7_droplayer[i]+ '.clip.width')
    f7_y_min=eval('document.'+f7_droplayer[i]+'.top')
    f7_y_max=f7_y_min+eval('document.'+ f7_droplayer[i]+ '.clip.height')
    } 
  if(f7_ie){ 
    f7_x_min=eval(f7_droplayer[i]+'.style.pixelLeft')
    f7_x_max=f7_x_min+eval(f7_droplayer[i]+ '.style.pixelWidth')
    f7_y_min=eval(f7_droplayer[i]+'.style.pixelTop')
    f7_y_max=f7_y_min+eval(f7_droplayer[i]+ '.style.pixelHeight')
    }
  if (f7_mousex>=f7_x_min && f7_mousex<=f7_x_max && f7_mousey>=f7_y_min && f7_mousey<=f7_y_max){
  f7_hideit=0; setTimeout('f7_hideall()',500)
    }
  else { f7_hideit=1 }
  return f7_hideit
  }
function fontchange(p){
document.font.lP.value = p;
document.font.submit();
}

// sOf code inserted by Gavin

/**
 * Function to select a matching option from a <select> control
 * vSelStatus   Variant - the value to match
 * sSelector    HTML control - the <select> being set up
 */
function populateSelector(vSelStatus, sSelector) {
  for(var i = 0; i < sSelector.options.length; i++) {
    if (sSelector.options[i].value == vSelStatus) {
      sSelector.selectedIndex = i;
      break;
    }
  }
}

var lCurrentPos_wg = 0;
function addUserToWG(sUserIDs) {
  document.getElementById("wgAdd_" + sUserIDs).src = "/img/user1_preferences.png";
  document.getElementById('f_WG').src="/inc/appCtrWorkingGroups.asp?a=1&sU=" + sUserIDs + "&rnd=" + Math.random() + "&lC=" + lCurrentPos_wg;
  lCurrentPos_wg = 1;
}
function removeUserFromWG(lUserID) {
document.getElementById('f_WG').src="/inc/appCtrWorkingGroups.asp?a=2&sU=" + lUserID + "&rnd=" + Math.random() + "&lC=" + lCurrentPos_wg;
  document.getElementById("u_" + lUserID + "_wg").style.display="none";
}
function removeGroupFromWG(lGroupID) {
  document.getElementById('f_WG').src="/inc/appCtrWorkingGroups.asp?a=2&sU=&rnd=" + Math.random() + "&lC=" + lGroupID;
  document.getElementById("g_" + lGroupID + "_wg").style.display="none";
}
function setWGCount(lUserCount, lGroupCount) {
  if (lGroupCount > 0) {
    document.getElementById('s_WG').style.display = "";
    document.getElementById('s_WG_u').innerHTML = lUserCount;
    document.getElementById('s_WG_g').innerHTML = lGroupCount;  
  }
}

function toggleElement(sElID,obj) {
  if (document.getElementById(sElID).style.display=='') {
    document.getElementById(sElID).style.display='none';
    document.getElementById(sElID + "_im").src = "/img/showLayer.gif";
  } else {
    document.getElementById(sElID + "_im").src = "/img/hideLayer.gif";
    document.getElementById(sElID).style.display='';
  }
}
function showStatus(s) {
  // Does not use switch statement as not all browsers are js1.2 compliant
  if (s == 0) {
    return("disabled");
  } else if (s == 7) {
    return("refused");
  } else if (s == 8) {
    return("accepted");
  } else if (s == 10) {
    return("enabled");
  } else if (s == 11) {
    return("new");
  }
}

// function to set every checkbox in a group to a given value
function setCheckboxGroupStatus(sPrefix, bActive, lElements) {
  for (var i = 0; i < lElements; i++) {
    document.getElementById(sPrefix + i).checked = bActive;
  }
}

function setCheckedAllCheckBoxesInGroup(oGroup, bChecked) {
    var arBoxes = document.getElementById(oGroup).getElementsByTagName('input');
    for(var i = 0; i < arBoxes.length; i++)
    {
        arBoxes[i].checked = bChecked;
    }
}

// eOf code inserted by Gavin
