<!-- Hide from old browsers
var curdivElem=null;
var defaultDiv=null;
var ctrl2Focus=null;
var popWin=null;
var btnLast=null;
var btnUp=null;
var btnDn=null;
var isVisible=false;
var isToggled=false;
var pressed='';

/* String object additional functions */
function trim(str) {return str.replace(/^\s+|\s+$/g,"");}
function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() {return this.replace(/^\s+/,'').replace(/\s+$/,'');}
function isalpha() {return ((this >= 'a' && this <= 'z') || (this >= 'A' && this <= 'Z'));}
function isnum() {return (this >= '0' && this <= '9');}
function isalnum() {return (isalpha() || isnum());}
/* Add functions to String Object using prototype */
String.prototype.isalpha = isalpha;
String.prototype.isnum = isnum;
String.prototype.isalnum = isalnum;
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function extractFilename(elem, target) {
  var str = elem.value;
  var x = str.lastIndexOf("\\");
  if (x != -1) {
    ctrl2Focus = (document.getElementById(target) != null) ? document.getElementById(target) : ctrl2Focus;
    if (ctrl2Focus != null) { ctrl2Focus.value = str.substr(x+1); }

    fileElem = document.getElementById('file2send');
    if(fileElem != null) {
      document.getElementById('chkInclude').checked = confirm('Do you want to upload the original file also?');
      ctrlElem = document.getElementById('ctrl2use');
      if(ctrlElem != null) { ctrlElem.value = ctrl2Focus.name; }
    }
  }
  ctrl2Focus = null;
  showDiv(curdivElem.name);
}

function str_repeat(i, m) {
        for (var o = []; m > 0; o[--m] = i);
        return o.join('');
}
function sprintf() {
        var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
        while (f) {
                if (m = /^[^\x25]+/.exec(f)) {
                        o.push(m[0]);
                }
                else if (m = /^\x25{2}/.exec(f)) {
                        o.push('%');
                }
                else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
                        if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
                                throw('Too few arguments.');
                        }
                        if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
                                throw('Expecting number but found ' + typeof(a));
                        }
                        switch (m[7]) {
                                case 'b': a = a.toString(2); break;
                                case 'c': a = String.fromCharCode(a); break;
                                case 'd': a = parseInt(a); break;
                                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
                                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
                                case 'o': a = a.toString(8); break;
                                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
                                case 'u': a = Math.abs(a); break;
                                case 'x': a = a.toString(16); break;
                                case 'X': a = a.toString(16).toUpperCase(); break;
                        }
                        a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
                        c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
                        x = m[5] - String(a).length - s.length;
                        p = m[5] ? str_repeat(c, x) : '';
                        o.push(s + (m[4] ? a + p : p + a));
                }
                else {
                        throw('Huh ?!');
                }
                f = f.substring(m[0].length);
        }
        return o.join('');
}

function do_marquee(msg) {
 isNS = (navigator.appName == "Netscape")
 isIE = (navigator.appName == "Microsoft Internet Explorer")
 text = ("<i><font style='font-size:10pt'>"+msg+"</font></i>")
 if (isNS) {document.write("<blink>" + text + "</blink>")}
 else {
   if (isIE) {document.write("<MARQUEE DIRECTION=LEFT>" + text + "</MARQUEE>")}
   else {document.write(text)}
 }
}
function setWinPos(winId) {
 elem = document.getElementById(winId);
 elem.style.left = (parseInt(window.screen.width, 10) - parseInt(elem.style.width, 10)) / 2;
}

function showDiv(divName) {
  var divElem=document.getElementById(divName);
  if (divElem!=null) {
    if ((curdivElem != null) && (curdivElem != divElem)){
      curdivElem.style.display='none';
      curdivElem = null;
    }
    isVisible=(divElem.style.display=='block');
    divElem.style.display = (isVisible) ? 'none' : 'block';
    curdivElem = divElem;
  }
}

function toggleButtons(divName, btnName, ctrlName) {
  var divElem=document.getElementById(divName);
  var btnElem=document.getElementById(btnName);
  var btnUp=document.getElementById('btnMoveUp');
  var btnDn=document.getElementById('btnMoveDn');
  var editCtl=document.getElementById('ectrl');
  var listCtl=document.getElementById(ctrlName);

  if (divElem != null) {
    ctrl2Focus=document.getElementById('msg_content');
    if(ctrl2Focus==null) {ctrl2Focus=document.getElementById('compname');}
    isVisible=(curdivElem==null);
    if (btnLast!=null) {btnLast.value=btnLast.name.substring(3, btnLast.name.length);}
    if (btnElem.name=='btnEdit') {
      curdivElem = divElem;
      divElem.style.display=(isVisible) ? 'block' : 'none';
      if(editCtl != null) {editCtl.value=(isVisible) ? '1' : '0';}
      btnElem.value=(isVisible) ? 'Cancel' : 'Edit';
      if(isVisible) {loadData(listCtl, ctrl2Focus.name);}
      else { if(ctrl2Focus != null) { loadData(listCtl, ctrl2Focus.name);curdivElem = null;}}
    }
    else if (btnElem.name=='btnNew') {
      if(curdivElem!=null) {curdivElem.style.display='none';}
      if(editCtl != null) {editCtl.value='0';}
      isToggled = !(isToggled);
      btnElem.value=(isToggled) ? 'Cancel' : 'New';
      clearData();
      if(ctrl2Focus != null) { if (isToggled) {ctrl2Focus.focus();}}
      curdivElem = null;
    }
    if(btnUp !=null) btnUp.style.display=divElem.style.display;
    if(btnDn !=null) btnDn.style.display=divElem.style.display;
    btnLast = btnElem;
  }
}
function toggleRadio(thisForm, thisField, thisValue) {
  radioSet=eval("document."+thisForm+"."+thisField);
  for(i=0; i<radioSet.length;i++) {
    if(radioSet[i].value==thisValue)radioSet[i].checked=true;
  }
}
function toggleCheck(thisForm, thisField, thisValue) {
  checkSet=eval("document."+thisForm+"."+thisField);
  checkSet.checked=!(checkSet.checked);
}
function setAction(frmElem, frmAction) {
  var formElem=document.getElementById(frmElem);
  if(formElem!=null)
    formElem.action=frmAction;
}
function loadTicker(thisElem, ctrlName) {
  if (thisElem!=null){
    listElem=thisElem;
    var msgIdx=document.getElementById('idx');
    if (msgIdx!=null) {
      msgIdx.value=thisElem.selectedIndex;
      var msgNum=thisElem.options[msgIdx.value];
      var msgHdr=document.getElementById('hdr');
      if (msgHdr!=null) msgHdr.value=msgNum.text;
      var msgElem=document.getElementById(msgNum.value);
      if(msgElem!=null){ ctrl2Focus.value=msgElem.value; }
    }
  }
  else {if (ctrl2Focus!=null) clearData();}
}
function loadEvent(thisElem, ctrlName) {
  if (thisElem!=null){
    listElem=thisElem;
    var evtIdx=document.getElementById('idx');
    if (evtIdx!=null) {
      evtIdx.value=thisElem.selectedIndex;
      var evtNum=thisElem.options[evtIdx.value];
      var evtItm=document.getElementById(evtNum.value);
      if(evtItm!=null) {
        eInfo=evtItm.value.split(";");
        vals=eInfo[0].split("!");
        parts=vals[1].split("?");
        var itmDate=document.getElementById('edate');
        if(itmDate!=null) itmDate.value=vals[0];
        if(document.getElementById('specials')!=null) {
          document.getElementById('specials').checked=false; }
        document.getElementById('compname').value=parts[0];
        if(parts.length>1) {
          uri=parts[1];
          if (uri.charAt(0)=="*") { uri = uri.substr(1); document.getElementById('specials').checked=true;}
          document.getElementById('complink').value=uri;

        }
        else {document.getElementById('complink').value=''};
        document.getElementById('compdate').value=eInfo[1];
        document.getElementById('complocn').value=eInfo[2];
        document.getElementById('comporg').value=eInfo[3];
        document.getElementById('comptel').value=eInfo[4];

        fname=(eInfo[5]!=null) ? eInfo[5].split("/"): null;
        input_value=(fname!=null) ? fname[fname.length-1] : '';
        document.getElementById('compstrt').value=fname[fname.length-1];

        fname=(eInfo[6]!=null) ? eInfo[6].split("/"): null;
        input_value=(fname!=null) ? fname[fname.length-1] : '';
        document.getElementById('comprpt').value=fname[fname.length-1];

        encdateItm=document.getElementById('encdate');
        if(encdateItm!=null) {encdateItm.value=encodeDate(eInfo[1]);}
      }
    }
  }
  else {if (ctrl2Focus!=null) clearData();}
}
function loadData(listCtl, ctrlName) {
  if(document.getElementById('msg_content')!=null)
    loadTicker(listCtl, ctrlName);
  else
    loadEvent(listCtl, ctrlName);
}
function clearData() {

  if(ctrl2Focus==document.getElementById('msg_content')) {
    ctrl2Focus.value="";
  }
  else {
    elem = document.getElementById('compname'); if (elem != null) elem.value="";
    elem = document.getElementById('complink'); if (elem != null) elem.value="";
    elem = document.getElementById('specials'); if (elem != null) elem.checked="";
    elem = document.getElementById('compdate'); if (elem != null) elem.value="";
    elem = document.getElementById('complocn'); if (elem != null) elem.value="";
    elem = document.getElementById('comporg'); if (elem != null) elem.value="";
    elem = document.getElementById('comptel'); if (elem != null) elem.value="";
    elem = document.getElementById('compform'); if (elem != null) elem.value="";
    elem = document.getElementById('compstrt'); if (elem != null) elem.value="";
    elem = document.getElementById('comprpt'); if (elem != null) elem.value="";
    elem = document.getElementById('idx'); if (elem != null) elem.value="-1";
  }
  if(document.getElementById('cal')!=null) {
    closeCalendar();
  }
}

var sponsor_image_path = '../images/sponsors/statics/';

function clearSponsor() {
  document.getElementById('spnsr_week').value="";
  document.getElementById('spnsr_name').value="";
  document.getElementById('spnsr_url').value="";
  document.getElementById('spnsr_logo').selectedIndex=0;
  /* Reset the sponsored weeks indicator */
  document.getElementById('spnsr_list').selectedIndex=-1;
  /* Set the available weeks indicator to first entry */
  if (document.getElementById('week_list').selectedIndex==-1)
    document.getElementById('week_list').selectedIndex=0;
  showSponsorLogo('');
}

function validWeek() {
  var spList = document.getElementById('spnsr_list');
  var wkList = document.getElementById('week_list');
  var isNew = wkList.selectedIndex != -1;
  if ((spList!=null) && (wkList!=null)) {
    var wkElem = document.getElementById('spnsr_week');
    var spElem = document.getElementById('spnsr_name');
    if ((wkElem!=null) && (spElem!=null)) {
      var theEntry = sprintf("%02d:%s:%s:%s\n", parseInt(wkElem.value,10),
                                               spElem.value,
                                               document.getElementById('spnsr_url').value,
                                               get_selection_text('spnsr_logo'));
      for (i=0; i<spList.options.length; i++) {
        if (parseInt(wkElem.value,10)==parseInt(spList.options[i].value, 10)) {
          var spEntry = sprintf('Week %02d: %s', parseInt(wkElem.value,10), spElem.value);
          if (!confirm("The Week "+parseInt(wkElem.value,10)+" is already assigned.\r\nDo you wish to overwrite the current entry?")){
            return false;
          }
          break;
        }
      }
      num = (isNew) ? spList.options.length : spList.selectedIndex;
      spItem = document.getElementById('spnsr'+ sprintf("%02d", num));
      if (spItem!=null) spItem.value = theEntry;
      return true;
    }
  }
  return false;
}
/* Display the logo graphic passed as parameter */
function showSponsorLogo(imgName) {
  elem=document.getElementById('spnsr_logo');
  if(elem!=null) {
    theImageFile = (elem.selectedIndex > 0) ? trim(imgName) : 'no_company_logo.jpg';
    theImageSrc = sponsor_image_path + theImageFile;
    imgBitmap = new Image();
    imgBitmap.src = theImageSrc;
    document.images["spnsr_img"].src=imgBitmap.src;
  }
}
/* Create a blank canvas for details of new Sponsor */
function addSponsor(ctrlName) {
  clearSponsor();
  week_no = trim(get_selection_text(ctrlName)).substr(5, 2);
  document.getElementById('spnsr_week').value=week_no;
}

/* Store the details of new or updated Sponsor */
function saveSponsor(formName) {
  if (validWeek()) {
    document.getElementById(formName).submit();
  }
  else { }
}

/* Create a blank canvas for details of new Sponsor */
function deleteSponsor(formName) {
  var spList = document.getElementById('spnsr_list');
  if (spList!=null){
    num = sprintf("%02d", parseInt(spList.selectedIndex, 10));
    var spItem=document.getElementById('spnsr'+num);
    if(spItem!=null) {
      spItem = document.getElementById('spnsr'+num);
      if (spItem!=null) {
        if (confirm('Are you sure that you want to remove this sponsored week?')) { spItem.value = ''; }
      }
    }
  }
  document.getElementById(formName).submit();
}

/* Display the details of selected Sponsor */
function loadSponsor(ctrlName) {
  var spList = document.getElementById(ctrlName);
  if (spList!=null){
    /* Reset the available weeks indicator */
    document.getElementById('week_list').selectedIndex=-1;
    num = sprintf("%02d", parseInt(spList.selectedIndex, 10));
    var spItem=document.getElementById('spnsr'+num);
    if(spItem!=null) {
      vals=spItem.value.split(":");
      var elem=document.getElementById('spnsr_week');
      if(elem!=null) elem.value=vals[0];
      elem=document.getElementById('spnsr_name');
      if(elem!=null) elem.value=vals[1];
      elem=document.getElementById('spnsr_url');
      if(elem!=null) elem.value=vals[2];
      elem=document.getElementById('spnsr_logo');
      if(elem!=null) match_selection_to_text('spnsr_logo', vals[3]);
    }
  }
}

/* Get the currently selected text string associated with a SELECT Object */
function get_selection_text(ctrlName) {
  inputElem = document.getElementById(ctrlName);
  if (inputElem!=null) { return inputElem.options[inputElem.selectedIndex].text; }
}
/* Set the SELECT Object index value from string passed as parameter */
function match_selection_to_text(selName, textStr) {
  selElem =document.getElementById(selName);
  for(i=0; i<selElem.options.length; i++) {
    if (trim(textStr)==trim(selElem.options[i].text)) {
      selElem.selectedIndex=i;
      showSponsorLogo(trim(textStr));
      return;
    }
  }
}
/* Store text from SELECT Object to text control element */
function store_selection_text(ctrl, elemName) {
  document.getElementById(elemName).value=get_selection_text(ctrl.name);
}

/* Copy text from input text control to output text control element */
function store_copied_text(inputCtrlName, outputCtrlName) {
  iCtrl = document.getElementById(inputCtrlName);
  oCtrl = document.getElementById(outputCtrlName);
  if ((iCtrl != null) && (oCtrl != null)) { oCtrl.value=iCtrl.value; }
}

/* Display a pop-up style window containing a graphical image */
function openWin(fname, isResizeable, wSize) {
// Check for popup already open
 if(popWin!=null) { popWinClose(popWin); }
 popWinFile=fname;
 wWidth=-1;
 wHeight=-1;
 if(wSize!=null) {
   wDims=wSize.split(':');
   if(wDims[0]!=null) {wWidth=wDims[0].split('=')[1];}
   if(wDims[0]!=null) {wHeight=wDims[1].split('=')[1];}
 }
 win_width=(wWidth==-1) ? (window.screen.width/2) : wWidth;
 win_height=(wHeight==-1) ? (window.screen.height/2) : wHeight;
 if(wSize==null) {
   if (win_width<510) {win_width=510;}
   if (win_height<450) {win_height=450;}
 }
 win_left=(window.screen.width-win_width)/2;
 win_top =(window.screen.height-win_height)/2;
 win_opts="left="+win_left+",top="+win_top+",width="+win_width+",height="+win_height+",scrollbars=yes";
 if(isResizeable) {win_opts+=",resizable=yes";}
 if((fname.indexOf('.jpg')!= -1) || (fname.indexOf('.gif')!=-1)) {
  popWin=window.open("","gw",win_opts);

var theDoc=popWin.document;
  with(theDoc) {
   open();
   writeln('<HTML>');
   writeln('<HEAD>');
   writeln('<TITLE>'+fname+'</TITLE>');
   writeln('</HEAD>');
   writeln('<BODY BGCOLOR="#FFFFFF">');
   writeln('<P ALIGN="CENTER"><IMG SRC="'+fname+'" ALT=""></P>');
   writeln('</BODY>');
   writeln('</HTML>');
   close();
  }
 }
 else {popWin=window.open(fname,"gw",win_opts);}
}

function popWinClose(winObj){
  if(winObj!=null) {winObj.close();}
}
/* Display a zoomed image file */
function zoomImg(imgFile){

 // Check for popup already open
 if(popWin!=undefined) { popWinClose(popWin); }

 img = new Image();
 img.src = imgFile;
 ratio = Math.round(parseFloat(sprintf("%0.2f", (600/img.height)*100)));
 iWide=(img.width*(ratio/100));
 iHigh=(img.height*(ratio/100));
 wWide=iWide+20;
 wHigh=iHigh+60;
 win_opts="width="+wWide+",height="+wHigh+",top=100,left=100,scrollbars=no,resizable=no";
 popWin=this.window.open("","Zoom",win_opts);
 with(popWin) {

   document.writeln("<html><body>");
   document.writeln("<center><img src='"+imgFile+"' width='"+iWide+"px' height='"+iHigh+"px'></center>");
   document.writeln("<center><p><input type='button' value='Closewindow' onClick='window.close();'></p></center>");
   document.writeln("</body></html>");
 }
 popWin.focus();
}
function getPosition(e) {
  var cursor = {x:0, y:0};
  if (e.pageX || e.pageY) {
    cursor.x = e.pageX;
    cursor.y = e.pageY;
  }
  else {
    var de = document.documentElement;
    var b = document.body;
    cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
    cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
  }
  return cursor;
}
function displayPop(divname, evt, h_step, v_step) {
  elem=document.getElementById(divname);
  if(elem!=null) {
    h_ofs = (h_step == null) ? 10 : h_step;
    v_ofs = (v_step == null) ? 10 : v_step;
    evt = evt || window.event;
    elemX=getPosition(evt).x;
    elemY=getPosition(evt).y;
    elem.style.left=(elemX+h_ofs).toString()+"px";
    elem.style.top=(elemY-v_ofs).toString()+"px";
    isVisible=(elem.style.display=='block');
    elem.style.display=(isVisible)?'none':'block';
  }
}
// -->
