popupW = 600;
popupH = 680;

kid = new Array();
kidSh = new Array();

function WriteCookie (name,val,hrs) {
var expire,exp;
if (hrs) {
 expire=new Date();
 expire.setTime(expire.getTime()+(hrs*3600000)); // msecs
 exp='; expires='+expire.toGMTString();
}
document.cookie=name+'='+escape(val)+exp+'; path=/';
}

function sWarn (where) { if (confirm('Warning: Continuing will Delete all events in this Series.')) self.location.href=where; }
function sorter (s) {
 if (document.searcher) {
  document.searcher.usort.value=s;
  document.searcher.submit();
 }
}

function popup (Url) {
 var specs = 'toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,dependent=1,width='+popupW+',height='+popupH+',screenX=75,screenY=50,top=50,left=75';
 window.open(Url,"popup",specs);
}
function prnt (Url) {
 popup(Url+'&print=1');
}
function publish () {
if (confirm("Publish calendar to Production?")) popup(pubReturn);
}

function mutExclude (tF,mn,allowAll) {
if (kid.length < 1 || !tF.qui2 || mn==2 && !allowAll) return 0;
var sel,frs,frs2,O,i,j,n;
if (mn==2 && allowAll) {
 if (tF.qui2.options[0].value=='') {tF.qui2.options[0] = null; return 1;}
 else return 0;
}

// metas:
sel = tF.qui.selectedIndex;
frs = tF.qui.options[0].value;
if (frs=='-' || frs=='') {
 if (allowAll && frs=='-') sel -= 1;
 else { // remove null/`ALL`
  tF.qui.options[0] = null;
  if (sel > 0) sel -= 1;
 }
}

// submetas:
qu2 = tF.qui2.options[tF.qui2.selectedIndex].value;
for (i=tF.qui2.options.length-1; i>=2; i--) tF.qui2.options[i] = null; // remove
kd = new Array();
for (i=0; i<kidSh.length; i++) kd[kd.length]=kidSh[i];  // prepend common
if (sel>=0 && kid.length > sel) { for (i=0; i<kid[sel].length; i++) kd[kd.length]=kid[sel][i]; } // append rest
f = (qu2=='-' || allowAll && kd.length==0) ? 1 : 0;
O = new Option(' (select '+subTitl+') ','');
eval("tF.qui2.options[0]=O");
O = new Option('-- '+allSubs+' --','-');
eval("tF.qui2.options[1]=O");
n=2;
for (i=0; i<kd.length; i++) { // finish menu
 j=kd[i].indexOf("\t");
 id = kd[i].substr(0,j);
 if (j<1 || id=='') continue;
 O = new Option(kd[i].substr(j+1),id);
 eval("tF.qui2.options[n]=O");
 if (qu2==id) f=n;
 n+=1;
}
tF.qui2.selectedIndex=f;

if (f>0) {
 if (allowAll) {
  if (tF.qui2.options[0].value=='') tF.qui2.options[0] = null;
  return 1;
 }
 else return 0; // go (no choice)
}
else {
 tF.qui2.focus();
 return 1; // no go (choice)
}
}

function refrsh () { if (document.layers) self.history.go(0); } // netscape (!7)
function showSelects (tF,menu,fram) { if (mutExclude(tF,menu,1)) refrsh(); }

function showMeta (tF,menu,fram) {
if (tF.stopper && tF.stopper.value=='1') return;
if (!mutExclude(tF,menu,0)) {
 if (parent.frames['view']) tF.viewurl.value = parent.view.location.href;
 if (tF.stopper && fram != 'nav') tF.stopper.value='1';
 tF.submit()
}
else refrsh();
}

function showMonth (tF) {
if (parent.frames['view']) tF.viewurl.value = parent.view.location.href;
tF.submit()
}

function showMo (tF,cy,cm) {
if (parent.frames['view']) tF.viewurl.value = parent.view.location.href;
tF.cyear.value = cy;
tF.cmon.value = cm;
tF.submit()
}

function showCat (tF,act) {
if (parent.frames['view']) tF.viewurl.value = parent.view.location.href;
tF.action=act + tF.unull.options[tF.unull.selectedIndex].value;
tF.unull.selectedIndex=0;
tF.submit()
}

function searchCheck (tF) {
var da1 = tF.usearch_yr1.selectedIndex+tF.usearch_mo1.options[tF.usearch_mo1.selectedIndex].value;
var da2 = tF.usearch_yr2.selectedIndex+tF.usearch_mo2.options[tF.usearch_mo2.selectedIndex].value;
if (da2 <= da1) {alert("ERROR: `From` date must be earlier than `Through` date!");tF.usearch_yr1.focus();}
else if (tF.qui2 && tF.qui2.selectedIndex==0 && tF.qui2.options[tF.qui2.selectedIndex].value=='') {alert("Please select a(n) "+subTitl);tF.qui2.focus();}
else {tF.submit()}
}

function searchToday (tF,idx) {if (tF.usearch_mo1.options[0].selected == true) {tF.usearch_yr1.selectedIndex = idx}}
