var months=["January","February","March","April","May","June","July","August","September","October","November","December"];
var mnth=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var dow=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var eom=[31,29,31,30,31,30,31,31,30,31,30,31];
var intMon=0;
var todaysdate=new Date();

var contPage='';
var banArr=new Array();
var cceArr=new Array();
var tmpArr=new Array();
var holdArr=new Array();
var hdrArr=new Array();
var schedArr=new Array();
var _ts=new Array();
var myType='';
var cbOne;
var idSelected=-1;
var nameToFind='';
var _month=todaysdate.getMonth();
var _year=todaysdate.getFullYear();

function ss(_off) {
locatString = 'mailto:'+_off+'@lochruadh.org';
window.location.replace(locatString);
}

function showMe(_id) {
	var x = document.getElementsByTagName("div");
	for (var y=0; y<x.length;y++) {
		if(x[y].name=='myEvent') {
			document.getElementById(x[y].id).style.display = 'none';		
		}
	}
	document.getElementById(_id).style.display = 'inline';
}

function hideMe(_id) {
	document.getElementById(_id).style.display = 'none';
}

function getFile(pURL,pFunc,pType) {
    contPage=pURL;
    myType=pType;
    tmpArr=new Array();
    holdArr=new Array();
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
        xmlhttp=new XMLHttpRequest();
        eval('xmlhttp.onreadystatechange='+pFunc+';');
        xmlhttp.open("GET", pURL, true); // leave true for Gecko
        xmlhttp.send(null);
    }
    else if (window.ActiveXObject) { //IE
        xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
        if (xmlhttp) {
            eval('xmlhttp.onreadystatechange='+pFunc+';');
            xmlhttp.open('GET', pURL, false);
            xmlhttp.send();
        }
    }
    if(pType!='lugh') {
        menuLayers.hide( );
    }
}

// Calendar
function makeCal() {    
     if (xmlhttp.readyState==4) {         
        if (xmlhttp.status==200) {             
            var tmpArray=xmlhttp.responseText.split('\n'); 
            for (var idx=0;idx<tmpArray.length;idx++) {
                if(tmpArray[idx]!=''){tmpArr[idx]=tmpArray[idx].split(','); }
            }
            holdArr=tmpArr;
            tmpArr=new Array();
            findMonth();
            createmonth();
        }
    }   
}
// Calendar Listing
function makeCalList() {    
     if (xmlhttp.readyState==4) {         
        if (xmlhttp.status==200) {             
            var tmpArray=xmlhttp.responseText.split('\n'); 
            for (var idx=0;idx<tmpArray.length;idx++) {
                if(tmpArray[idx]!=''){tmpArr[idx]=tmpArray[idx].split(','); }
            }
            holdArr=tmpArr;
            tmpArr=new Array();
            findMonth();
            createList();
//            createmonth();
        }
    }   
}

function makeTable() {    
     if (xmlhttp.readyState==4) {         
        if (xmlhttp.status==200) {             
            var tmpArray=xmlhttp.responseText.split('\n'); 
            for (var idx=0;idx<tmpArray.length;idx++) {
                if(idx==0){
                    hdrArr=tmpArray[0].split(',');
                }
                else {
                    if(tmpArray[idx]!=''){tmpArr[idx-1]=tmpArray[idx].split(','); }
                }
            }
            holdArr=tmpArr;
            makeCombo();
            newTable();
        }
    }   
}

function findMonth() {
    var _i=0;
    var _m=new Array();
    for (var idx=0;idx<holdArr.length;idx++) {
        tmp=holdArr[idx];
        _m=tmp[0].split('/');
        if(_m[0]==_month+1) {
            if(_m[2]==_year) {
                tmpArr[_i]=tmp;
                _i += 1;
            }
        }
    }
}

function findSched(_sd) {
    var _i=0;
    var _m=new Array();
    var _n=new Array();
    for (var idx=0;idx<tmpArr.length;idx++) {
        tmp=tmpArr[idx];
        _m=tmp[0].split('/');
        _n=tmp[1].split('/');
        if((_sd>=_m[1])&&(_sd<=_n[1])) {
            _ts[_i]=idx;
            schedArr[_i]=tmp;
            _i+=1;
        }
    }
}
function findName(_co) {
    var _i=0;
    for (var idx=0;idx<holdArr.length;idx++) {
        tmp=holdArr[idx];                
        if(tmp[_co]==nameToFind) {
            tmpArr[_i]=tmp;
            _i += 1;
        }
    }
}

function Select1_onchange() {
    nameToFind=document.test.scadian.value;
    tmpArr=new Array();
    findName(0);
    newTable();
}

function Select2_onchange() {
    nameToFind=document.test.award.value;
    tmpArr=new Array();
    findName(2);
    newTable();
}

function showAll() {
    tmpArr=holdArr;
    newTable();
}

// Calendar View
function createmonth() {
    var Cdate=new Date();
    Cdate.setDate(1);
    var currMonth=false;
    var currYear=false;
    var dd=todaysdate.getMonth();
    dd+=intMon;
    Cdate.setMonth(dd);
    var month=Cdate.getMonth();
    var CurrYear = Cdate.getFullYear();
    var CurrMonth=months[month];
    var fulldate=CurrMonth+' '+CurrYear;
    var content='<table border="1" bgcolor="#FFFFFF" width="98%">'
    if(Cdate.getdate!=1) {
        Cdate.setDate(1);
    }
    var day1=Cdate.getDay();
    var aa=0;
    var bgc='>';
    currMonth=todaysdate.getMonth()==Cdate.getMonth();
    currYear=todaysdate.getFullYear()==Cdate.getFullYear();
    content+='<tr>';
    content+='<th style="text-align:center;"><a class="button" href="javascript:void(prev())">Previous</th>';
    content+='<th colspan="5"><center><b><size=14>';
    content+=fulldate;
    content+='</size></b></center></th>';
    content+='<th style="text-align:center;"><a class="button" href="javascript:void(next())">Next</th>';
    content+='<th>Click on an item to see<br />the full description</th>';
    content+='</tr>';
    content+='<tr><td style="width:80px; max-width:80px; min-width:80px;" bgcolor="D9D9D9"><center>Sun</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;"><center>Mon</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;"><center>Tue</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;"><center>Wed</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;"><center>Thu</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;"><center>Fri</center></td>';
    content+='<td style="width:80px; max-width:80px; min-width:80px;" bgcolor="D9D9D9"><center>Sat</center></td>';
    content+='<td style="min-width:240px;" rowspan="7" valign="Top"><div id="sdescript">&nbsp;</div></td></tr>';
    for (xx=0; xx<6; xx++) {
        content+='<tr style="height:80px;" valign="Top">';
        for (ii=0; ii < 7; ii++) {
            bgc='>';
            if (ii==0) {
                bgc=' bgcolor="D9D9D9">';
            }
            if (ii==6) {
                bgc=' bgcolor="D9D9D9">';
            }
            if (((todaysdate.getDate()==(aa+1))&&currMonth==true)&&currYear==true) {
                bgc=' bgcolor="ffcc66">';
            }
            content+='<td style="height:80px;width:80px;"'+bgc;
            if ((ii<day1&&aa==0)||aa>=eom[month]) {
                content+=' &nbsp; ';
            }
            else {
                aa++;
                content+=aa;
                schedArr=new Array;
                _ts=new Array;
                findSched(aa);
                if(schedArr.lenth!=0) {
                    for (var idx=0;idx<schedArr.length;idx++) {
                        tmp=schedArr[idx];
                        content+='<br />';
                        if(tmp[8]!='') {
                            content+='<a href="javascript:void(ShowAppt('+_ts[idx]+'))"';
                            if(tmp[4]=='Cancelled') { content+=' style="color:Red;"'; }
                            content+='>'+tmp[2]+'</a>'; 
                        }
                        else {
                            content+=tmp[2];
                        }
                    }
                }
            }
            content+='</td>';
        }
        content+='</tr>';
        if (aa>eom[month]) {
            xx=6;
        }
    }
    content+='</table>';
    content+='<a href="javascript:void(curr())">Go to Current Month</a>';
    document.getElementById("content").innerHTML = content;
}

// Calendar Listing
function createList() {
    var Cdate=new Date();
    Cdate.setDate(1);
    var ckDate=new Date();
    var currMonth=false;
    var currYear=false;
    var dd=todaysdate.getMonth();
    dd+=intMon;
    Cdate.setMonth(dd);
    var month=Cdate.getMonth();
    var CurrYear = Cdate.getFullYear();
    var CurrMonth=months[month];
    var fulldate=CurrMonth+' '+CurrYear;
    var content='<table border="0" bgcolor="#FFFFCC" width="90%" cellpadding="0" cellspacing="0">'
    if(Cdate.getdate!=1) {
        Cdate.setDate(1);
    }
    var day1=Cdate.getDay();
    var aa=0;
    var bgc='>';
    var pastEvent='';
    var _ampm=' AM';
    currMonth=todaysdate.getMonth()==Cdate.getMonth();
    currYear=todaysdate.getFullYear()==Cdate.getFullYear();
    content+='<tr>';
    content+='<th style="width:100px;"><a class="button" href="javascript:void(prevList())">Previous</th>';
    content+='<th style="width:80%;"><center><b>';
    content+=fulldate;
    content+='</b></center></th>';
    content+='<th style="width:100px;"><a class="button" href="javascript:void(nextList())">Next</th>';
    content+='</tr><tr><th colspan="7"><hr></th></tr>';
    for (var idx=0;idx<tmpArr.length;idx++) {
        tmp=tmpArr[idx];
        var _m=tmp[0].split('/');
        ckDate.setFullYear(_m[2],_m[0]-1,_m[1]);
        if(ckDate<todaysdate) {
            pastEvent=' style="background-color:#e6e6e6;"'; //e0e085
        }
        else {
            pastEvent='';
        }
        getDescr(tmp[2]);
        if(meetDescr!='') {
          content+='<tr'+pastEvent+'><th valign="top" rowspan="4">'+dow[ckDate.getDay()]+' '+_m[1];
        }
        else {
          content+='<tr'+pastEvent+'><th valign="top" rowspan="3">'+dow[ckDate.getDay()]+' '+_m[1];
        }
        if(tmp[0]!=tmp[1]) {
            var _n=tmp[1].split('/');
            content+=' - '+_n[1];
        }
        content+='</th>';
        content+='<td colspan="2">'+tmp[3]+'</td></tr>';
        content+='<tr'+pastEvent+'><td colspan="2"';
        if(tmp[4]=='Cancelled') {
            content+=' style="color:Red;font-weight:bold;">'+tmp[4];
        }
        else {
            content+='>';
            if(tmp[9]!='') {
                if((tmp[4]=='All Day')||(tmp[4]=='')) {
                    content+=tmp[4]+' ';
                }
                else {
                    _m=tmp[4].split(':');
                    if(_m[0]>'12') { 
                        _m[0]-=12;
                        _ampm=' PM'; 
                    }
                    content+=_m[0]+':'+_m[1]+_ampm+' ';
                }
                if(tmp[5]!='') {
                    content+=' at ';
                    if(tmp[6]!='') {
                        content+='<a href="'+tmp[6]+'" target="new" title="View a map to this location">'+tmp[5]+'</a>,';
                    }
                    else {
                        content+=tmp[5]+',';
                    }
                }
                content+=' contact the <a href="mailto:'+tmp[8]+'" title="Send an e-mail">';
                content+=tmp[7]+'</a>, '+tmp[9]+', '+tmp[10]+' for more information.';
            }
        }
        content+='</td></tr>';
        if(meetDescr!='') {
            content+='<tr'+pastEvent+'><td colspan="2">'+meetDescr+'<br /> * '+ModGarb+'</td></tr>';
        }
        content+='<tr'+pastEvent+'><td colspan="2"><hr></td></tr>';                    
    }
    content+='</table>';
    document.getElementById("content").innerHTML = content;
}

function prev() {
    intMon -= 1;
    _month -= 1;
    if(_month<0) {
        _month=11;
        _year-=1;
    }
    tmpArr=new Array();
    findMonth();
    createmonth();
}

function curr() {
    intMon = 0;
    _month = todaysdate.getMonth();
    _year = todaysdate.getFullYear();
    tmpArr=new Array();
    findMonth();
    createmonth();
}

function next() {
    intMon += 1;
    _month += 1;
    if(_month>11) {
        _month=0;
        _year+=1;
    }
    tmpArr=new Array();
    findMonth();
    createmonth();
}
function prevList() {
    intMon -= 1;
    _month -= 1;
    if(_month<0) {
        _month=11;
        _year-=1;
    }
    tmpArr=new Array();
    findMonth();
    createList();
}

function nextList() {
    intMon += 1;
    _month += 1;
    if(_month>11) {
        _month=0;
        _year+=1;
    }
    tmpArr=new Array();
    findMonth();
    createList();
}
// Calendar view Show the Scheduled item
function ShowAppt(_sd) {
  tmp=tmpArr[_sd];
  var descr='';
  var _m=new Array;
  var _ampm=' AM';
  descr+='<table width="100%">';
  descr+='<tr><th bgcolor="#add8e6"><center>What</center></th></tr>';
  descr+='<tr><td><center>'+tmp[3]+'</center></td></tr>';
  getDescr(tmp[2]);
  if(meetDescr!='') {
      descr+='<tr><td><center>'+meetDescr+'</center></td></tr>';
      descr+='<tr><td bgcolor="#ffff55"><center>'+ModGarb+'</center></td></tr>';
  }
  descr+='<tr><th bgcolor="#add8e6"><center>When</center></th></tr>';
  descr+='<tr><td><center>';
  if(tmp[4]=='Cancelled') {
      descr+='<span style="color:red;font-weight:Bold;">'+tmp[4]+'</span>';
  }
  else {
    if(tmp[0]!=tmp[1]) {
        descr+=tmp[0]+' - '+tmp[1];
    }
    else {
      descr+=tmp[0]+' '
      if((tmp[4]=='All Day')||(tmp[4]=='')) {
        descr+=tmp[4];
      }
      else {
        _m=tmp[4].split(':');
        if(_m[0]>'12') { 
          _m[0]-=12;
          _ampm=' PM'; 
        }
        if(_m[0]==12) {
          _ampm=' PM';
        }
        descr+=_m[0]+':'+_m[1]+_ampm;
      }
    }
  }
  descr+='</center></td></tr>';
  if(tmp[5]!='') {
      descr+='<tr><th bgcolor="#add8e6"><center>Where</center></th></tr>';
      descr+='<tr><td><center>';
      if(tmp[6]!='') {
          descr+='<a href="'+tmp[6]+'" target="new" title="View a map to this location">'+tmp[5]+'</a>';
      }
      else {
          descr+=tmp[5];
      }
      descr+='</center></td></tr>';
  }
  descr+='<tr><th bgcolor="add8e6"><center>For more information</center></th></tr>';
  descr+='<tr><td><center>Contact the<br /><a href="mailto:'+tmp[8]+'" title="Send an e-mail">'+tmp[7]+'</a><br />'+tmp[9]+'<br />'+tmp[10]+'</center></td></tr></table>';
  document.getElementById("sdescript").innerHTML = descr;
}
var meetDescr='';
var ModGarb='m';

function getDescr(tesTR) {
  meetDescr='';
  ModGarb='';
  if(tesTR=='Officers') {
    ModGarb='Modern Clothing';
    meetDescr='The populace is encouraged to attend.  Please do not arrive before 7:30 pm.  If you want to eat you can order at 7:30 in the back room.  The meeting will not start until 8:00 pm. Officers Meeting is a monthly gathering of the Officers of the Shire for planning purposes. Upcoming events, purchases and other items are discussed, and will then be brought before the group for voting at the next Populace Meeting. Also the forum where Officers make the Seneschal aware of any problems and/or potential trouble spots pertaining to the running of and the general well-being of the Shire.';
  }
  if(tesTR=='Populace') {
    ModGarb='Modern Clothing';
    meetDescr='Everyone is welcome to attend to learn more about what the group is currently doing.';
  }
  if(tesTR=='Fighter') {
    ModGarb='Wearing garb is encouraged ';
    meetDescr='Fighter Practice generally refers to the gathering of Chivalric or "heavy" fighters to train, practice and get authorized as a fighter. Newcomers are welcome and can try the activities.';
  }
  if(tesTR=='Archery') {
    ModGarb='Wearing garb is encouraged';
    meetDescr='Archery Practice is an opportunity to practice target shooting with bow and arrows. Newcomers are welcome and can try the activities.';
  }
  if(tesTR=='Meet-n-Greet') {
    ModGarb='Modern Clothing';
    meetDescr='This is a great time for people who are interested in the SCA to get ask question over coffee, tea & desserts.  All are welcome to attend.  This will provide a time for people to sit down and chat.  Long term players are encouraged to attend to help out with new comers and bring a dessert.';
  }
  if(tesTR=='Bowyers') {
    ModGarb='Modern Clothing';
    meetDescr='Bowyers & Fletchers is an activity time for archers to work on equipment.  If you have an interset in archery, you may want to attend to learn more about the equipment.';
  }
  if(tesTR=='Bardic') {
    ModGarb='Wearing garb is encouraged';
    meetDescr='Bardic is a gathering of folks to share entertainment. In Loch Ruadh, our bardic gatherings are mostly group singing, interspersed with individual performances. (Note: it is not required to perform or even sing along to attend bardic - just coming to listen is perfectly acceptable).';
  }
  if(tesTR=='Scribes') {
    ModGarb='Modern Clothing';
    meetDescr='Scribe & Illuminators is an activity to work on Kingdom Award Charters. Please come by even if you do not paint.';
  }
  if(tesTR=='Brewers') {
    ModGarb='Modern Clothing';
    meetDescr='The Brewers get together to discuss receipts, tips and tricks to brewing alcoholic and non-alcohol beverages.  ';
  }
}
//Make the Combos for the OP, OM, and Pop Lists
function makeCombo() {
    
//    if(myType!='om') {
        sortASC(0,false);
//    }
//    else {
//        sortASC(2,true);
//    }
    var tmp;
    var idx=0;
    cbOne='<form name="test">Select a Name: <select name="scadian" onchange="Select1_onchange()"  style="width:250px">';
    cbOne += '<option selected>Select a Name</option>';
    var meIn='';
    for (idx=0;idx<tmpArr.length;idx++) {
        tmp=tmpArr[idx];                
        if(meIn!=tmp[0]) {
            cbOne += '<option value="'+tmp[0]+'">'+tmp[0]+'</option>';
            meIn=tmp[0];
        }
    }
    if(myType=='op') {
        cbOne += '</select> Select an Award: <select id="Select2" style="width:250px" onchange="Select2_onchange()" name="award"><option selected="selected">Select an Award</option>';
        sortNow(2,false);
        for (idx=0;idx<tmpArr.length;idx++) {
            tmp=tmpArr[idx];                
            if(meIn!=tmp[2]) {
                cbOne += '<option value="'+tmp[2]+'">'+tmp[2]+'</option>';
                meIn=tmp[2];
            }
        }
    }
    cbOne += '</select>';
    cbOne += '&nbsp;&nbsp;<input type="button" value="Show All" onClick="showAll()" />';
    if(myType=='op') {
        cbOne+='<table cellpadding="0" cellspacing="0"  width="97%"><tr><td width="50%"><a href="AwardRecGuideline.doc" target="_new">How to recommend someone for an Award?</a> </td>';
        cbOne += '<td width="47%" style="font-size: small;text-align:right;">Italicised Entries are from Local Herald/Seneschal all others are <br />extracted from Kingdom of Ansteorra - Order of Precedence.</td></tr></table>';
   }
    cbOne += '</form>';
    if(myType!='om') {
        sortASC(0,false);
    }
    else
    {
        sortASC(2,true);
    }
}

function ov(_o,_tf)
{
  if(_tf)_o.className="header2";
  else _o.className="header1";
}
function stripHTML(_str)
{
  if(!_str)return;

  var _str2;
  var _reg=/<.*?>/gi;
  while(_str.match(_reg)!=null)
  {
    _str=_str.replace(_reg,"");
  }
  return _str;
}
function bubbleSort(_a,c,_ud,_isNumber)
{
  for(var i=0;i<_a.length;i++)
  {
    for(var j=i;j<_a.length;j++)
    {
      var _left=_a[i][c];
      var _right=_a[j][c];
      var _sign=_ud?">":"<";
      var _yes=false;
      if(_isNumber)
      {
         if(_ud && (parseInt(_left)-parseInt(_right)>0))_yes=true;
         if(!_ud && (parseInt(_left)-parseInt(_right)<0))_yes=true;
      }
      else
      {
        if(_ud && _left.toLowerCase() > _right.toLowerCase())_yes=true;
        if(!_ud && _left.toLowerCase() < _right.toLowerCase())_yes=true;
        /* if Names same sort by date of award */
        if(c==0 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
        /* if Award same sort by date of award */
        if(c==2 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
      }
      if(_yes)
      {
        /* swap rows */
        for(var x=0;x<_a[i].length;x++)
        {
          var _t=_a[i][x];
          _a[i][x]=_a[j][x];
          _a[j][x]=_t;
        }
      }
    }
  }
  return _a;
}

function bubSort(_a,c,_ud,_isNumber)
{
  for(var i=0;i<_a.length;i++)
  {
    for(var j=i;j<_a.length;j++)
    {
      var _left=_a[i][c];
      var _right=_a[j][c];
      var _yes=false;
      if(_ud)
      {
          if(_isNumber)
          {
             if(parseInt(_left)-parseInt(_right)>0)_yes=true;
          }
          else
          {
            if(_left.toLowerCase() > _right.toLowerCase())
            {
                _yes=true;
            }
            else
            {
                /* if Names same sort by date of award */
                if(c==0 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
                /* if Award same sort by date of award */
                if(c==2 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
            }
          }
      }
      else
      {
          if(_isNumber)
          {
             if(parseInt(_left)-parseInt(_right)<0)_yes=true;
          }
          else
          {
            if(_left.toLowerCase() < _right.toLowerCase())
            {
                _yes=true;
            }
            else
            {
                /* if Names same sort by date of award */
                if(c==0 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
                /* if Award same sort by date of award */
                if(c==2 && _left.toLowerCase() == _right.toLowerCase() && _a[i][1] > _a[j][1])_yes=true; 
            }
          }
      }
      if(_yes)
      {
        /* swap rows */
        for(var x=0;x<_a[i].length;x++)
        {
          var _t=_a[i][x];
          _a[i][x]=_a[j][x];
          _a[j][x]=_t;
        }
      }
    }
  }
  return _a;
}

var lastSort=null;

function sortNow(_c,_isNumber)
{
  var _a=tmpArr;
  _a=bubbleSort(_a,_c,lastSort!=_c,_isNumber);
  tmpArr=_a;
  newTable();
  if(lastSort!=_c) {
    lastSort=_c; 
  }
  else {
    lastSort=null;
  }
}

function sortASC(_c,_isNumber)
{
  var _a=tmpArr;
  _a=bubSort(_a,_c,true,_isNumber);
  tmpArr=_a;
  newTable();
}

function sortDEC(_c,_isNumber)
{
  var _a=tmpArr;
  _a=bubSort(_a,_c,false,_isNumber);
  tmpArr=_a;
  newTable();
}



function pageWidth()
{
   return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight()
{
   return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function mt() {    
     if (xmlhttp.readyState==4) {         
        if (xmlhttp.status==200) {             
            var tmpArr=xmlhttp.responseText; 
            document.getElementById("content").innerHTML=tmpArr;
        }
    }   
}
    
function newTable() {
    var out; 
    out = '';
    if(myType=='ca') {
        out+='<p>NOTE: The Shire does not have a copy of the ones that are highlighted in yellow. If you would like to donate a copy, please do as we are always glad to accept donations.</p>';
    }
    else {
        if(myType!='lib') {
            out+=cbOne;
            out+='<div id="listing" style="overflow:auto; height:86%; max-height:86%;">';
        }
        else {
            out+='';
        }
    }
    out+='<table class="header" id="box" cellspacing="1" cellpadding="3" width="98%" border="0" style="background-color:#777777;">';
    out+='<tbody><tr>';
    var tmp=new Array();            
    var rowstyle='row0';
    var cols=0;         
    var myid='g0';
    var oldName='test';
    for (var xdi=0;xdi<hdrArr.length;xdi++) 
    {
        var ckIt=hdrArr[xdi].replace('_','');
        if(hdrArr[xdi]==ckIt) 
        {
            out += '<td class="header1" onmouseover="ov(this, true)" onclick="sortNow('+xdi+',false);" onmouseout="ov(this, false)">'+hdrArr[xdi]+'</td>';
            cols+=1;
        }
    }
    
    
    for (var idx=0;idx<tmpArr.length;idx++) {                
        myid='g'+idx;
        tmp=tmpArr[idx];
        scadian = tmp[0].replace('"','');                
        scadian = scadian.replace('"','');                
        if(oldName!=scadian) 
        {
            if(rowstyle=='row0') 
            {
                rowstyle='row1';
            }
            else 
            {
                rowstyle='row0';
            }
        }
        if (myType=='ca') {
            if ((tmp[3]=='0')||(tmp[2]=='0')) {
                rowstyle='rowNone';
            }
        }
        out += '<tr class="'; 
        out += rowstyle; 
        out += '" id="'; 
        out += myid; 
        out += '">';
        if (oldName!=scadian) {
            out+='<td id="h'+idx+'_0" title="'+scadian+'" style="text-align: left;">'+scadian+'</td>';
        }
        else {
            out+='<td id="h'+idx+'_0" title="'+scadian+'"></td>';
        }
        if(tmp.length!=cols) {
            for(xdi=1;xdi<cols;xdi++) {
                var test=tmp[cols].substring(0,4);
                if(test=='TRUE') {
                    out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;font-style:italic;">'+tmp[xdi]+'</td>';
                }
                else {
                    if (test=='FALS') {
                        out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">'+tmp[xdi]+'</td>';
                    }
                    else {
                        out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">'+tmp[xdi]+'</td>';
                    }
                }
            }
        }
        else {
            if(myType=='pop') {
                for(xdi=1;xdi<tmp.length;xdi++) {
                    if ((xdi+1)==tmp.length) {
                        out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">';
                        if (tmp[xdi].length<2) {
                            out+='<img src="images/noarms.gif"  style="border: 0;" alt="No device registerer." />';
                        }
                        else {
                            out+='<a href="arms/'+tmp[xdi]+'" onclick="return wrapContent(event, this.href, 650, 500)"><img src="images/arms.gif"  style="border: 0;" alt="View Device of '+scadian+'" /></a>';
                        }
                        out+='</td>';
                    }
                    else {
                        if (tmp[xdi]=='No') {
                            out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">&nbsp;</td>';
                        }
                        else {
                            out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">'+tmp[xdi]+'</td>';
                        }
                    }
                }
            }
            else {
                for(xdi=1;xdi<tmp.length;xdi++) {
                    out+='<td id="h'+idx+'_'+xdi+'" style="text-align: center;">'+tmp[xdi]+'</td>';
                }
            }
        }
        out+='</tr>';
        oldName=scadian; 
    }            
    out+='</tbody></table>';   
    if(myType=='op') { 
        out+='</div>'; 
    }
    document.getElementById('content').innerHTML=out;
}    

function getLugh(pURL,pFunc,pType) {
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
        xmlhttp=new XMLHttpRequest();
        eval('xmlhttp.onreadystatechange='+pFunc+';');
        xmlhttp.open("GET", pURL, true); // leave true for Gecko
        xmlhttp.send(null);
    }
    else if (window.ActiveXObject) { //IE
        xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
        if (xmlhttp) {
            eval('xmlhttp.onreadystatechange='+pFunc+';');
            xmlhttp.open('GET', pURL, false);
            xmlhttp.send();
        }
    }
}


function lug() {
     if (xmlhttp.readyState==4) {         
        if (xmlhttp.status==200) {             
            var tmpArr=xmlhttp.responseText; 
            document.getElementById("lugh-main").innerHTML=tmpArr;
        }
    }   
}
function lugMenu(mnuName, onOff) {
  var myMnu
  myMnu = document.getElementById(mnuName);
  if(onOff==false) { //screen background color
    myMnu.style.backgroundColor='#ffffcc';
  }
  else {
    myMnu.style.backgroundColor='#ffff88';
  }
}

var qsParm = new Array();
function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
    if(qsParm['id']!=""){
        var tester;
        tester=qsParm['id'] +'.html';
        getLugh(tester,'lug','');
    }
}
 
function scarletLetter() {


} 