var pgname=location.pathname

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(name) {
  var theCookie = "" + document.cookie;
  var ind = theCookie.indexOf(name);
  if (ind == -1 || name == "") return "";
  var ind1 = theCookie.indexOf(';',ind);
  if (ind1 == -1) ind1 = theCookie.length; 
  return unescape(theCookie.substring(ind + name.length + 1, ind1));
}

function Left(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else
    return String(str).substring(0,n);
}

function Right(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else {
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

function menuItem(pgtitle,pgurl){
  var pgmatch = Left(pgurl,10);
  if ((pgname.indexOf(pgmatch,0))>0) {
    document.write('<span class=menu>'+pgtitle+'&nbsp;&nbsp;</span>');}
  else{document.write('<a href="'+pgurl+'" class=menu>'+pgtitle+'</a>&nbsp;&nbsp;');}
}

function displayMenu() {
  var CmId = getCookie('CmId');
  if (CmId == '') {
    location.href="http://www.BuhsAlumni.org/" }
  else {
    var CmYr = Left(CmId,4);
    menuItem("Blog","blog.htm");
    menuItem("Hallway","hallway.htm");
    if (CmYr == 'teac' || CmYr == 'fobu') {
      menuItem("Lounge","HomeRm"+CmYr+".htm")}
    else {
      menuItem("HomeRoom","HomeRm"+CmYr+".htm")
    }
    menuItem("Library","library.htm");
    menuItem("Profile","profile.cgi?CmId="+CmId);
    menuItem("Visitors","visitors.htm");
    // menuItem("<font color=red>WEBCAMS</font>","sfwebcams.htm");
    menuItem("Weather","weather.htm");
  }
}

function lowerCase(frmObj) {
  var tmpStr;
  tmpStr = frmObj.value.toLowerCase();
  frmObj.value = tmpStr;
}

function upperCase(frmObj) {
  var tmpStr;
  tmpStr = frmObj.value.toUpperCase();
  frmObj.value = tmpStr;
}

function correctCase(frmObj) {
  var index;
  var tmpStr;
  var tmpChar;
  var preString;
  var postString;
  var strlen;
  tmpStr = frmObj.value.toLowerCase();
  strLen = tmpStr.length;
  if (strLen > 0) {
    for (index = 0; index < strLen; index++) {
      if (index == 0) {
        tmpChar = tmpStr.substring(0,1).toUpperCase();
        postString = tmpStr.substring(1,strLen);
        tmpStr = tmpChar + postString; }
      else {
        tmpChar = tmpStr.substring(index, index+1);
        if (tmpChar == " " && index < (strLen-1)) {
          tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
          preString = tmpStr.substring(0, index+1);
          postString = tmpStr.substring(index+2,strLen);
          tmpStr = preString + tmpChar + postString;
        }
      }
    }
  }
  frmObj.value = tmpStr;
}

function logonStart() {
  var CmEmail = getCookie('CmEmail');
  if (CmEmail != null  && CmEmail != "") {
    document.Logon.FormEmail.value = CmEmail;
    document.Logon.FormPassword.focus();
  }
  else {
    document.Logon.FormEmail.value = "";
    document.Logon.FormEmail.focus();
  }
}

function chkCookies() {
  setCookie('chkCookies','True','.1')
  if ( getCookie('chkCookies')) {
    setCookie('chkCookies','True','-1') }
  else {
    document.write('<font color=red><b>BROWSER ERROR!</b>&nbsp; Your web browser must be configured to accept cookies in order to logon and use this website!</font><br/><br/>') }
}

function validateInput() {
  if ( document.Logon.FormEmail.value == "" ) {
    alert("Please enter your email address!");
    document.Logon.FormEmail.focus();
    return false; }
  else {
    if ( document.Logon.FormEmail.value.indexOf ("@", 0) == -1 ) {
      alert("Please check your email address!");
      document.Logon.FormEmail.focus();
      return false; }
    else { 
      if ( document.Logon.FormEmail.value.indexOf (".", 0) == -1 ) {
        alert("Please check your email address!");
        document.Logon.FormEmail.focus();
        return false; }
      else { return true; }
    }
  }
}

function submitLogon() {
  if (!validateInput()) { return false; }
  else {
  document.Logon.submit(); return false; }
}

function blogSubmit() {
  OpenWindow = window.open("blogSubmit.cgi", "displayBlog", "resizable=yes, scrollbars=1, toolbar=0, left=400, top=50, width=500, height=400");
}

function obituaries(ClassYr) {
  OpenWindow = window.open("obituaries.cgi?ClassYr=" + ClassYr, "displayObituaries", "resizable=yes, scrollbars=1, toolbar=0, left=30, top=50, width=300, height=300");
}

function yearbook(ClassYr) {
  var CmDir=Right(ClassYr, 2);
  OpenWindow = window.open("Yb" + CmDir + "/Yb" + ClassYr + "1.htm", "displayYearbook", "resizable=yes, scrollbars=1, toolbar=0, left=5, top=1, width=430, height=700");
}

function search(SearchFor) {
  OpenWindow = window.open("search.cgi?SearchFor=" + SearchFor, "displaySearch", "resizable=yes, scrollbars=1, toolbar=0, left=30, top=50, width=300, height=300");
}

function searchFor() {
  OpenWindow = window.open("search.cgi?SearchFor=" + document.Search.SearchFor.value, "displaySearch", "resizable=yes, scrollbars=1, toolbar=0, left=30, top=50, width=300, height=300");
}

function about(CmId) {
  OpenWindow = window.open("aboutCm.cgi?CmId=" + CmId, "displayProfile", "resizable=1, scrollbars=1, toolbar=0, left=440, top=50, width=480, height=500");
}

function eMsg(doc) {
  OpenWindow = window.open(doc+".htm", "popup", "resizable=1, scrollbars=1, toolbar=0, left=20, top=50, width=500, height=550");
}

function eNews(doc) {
  OpenWindow = window.open("News"+doc+".htm", "popup", "resizeable=1, scrollbars=1, toolbar=0, left=20, top=50, width=500, height=550");
}

function killFlys() {
  OpenWindow = window.open("killFlys.htm", "popup", "resizeable=1, scrollbars=1, toolbar=0, location=0, left=20, top=50, width=850, height=650");
}

function PicFamily(picName) { 
  ShowingImage = new Image();
  ShowingImage.src = picName;
  wid = ShowingImage.width + 50;
  hei = ShowingImage.height + 60;
  if (wid < 30 || hei < 30) {
    wid=650;
    hei=490;
  }
  if (screen.width < wid || screen.height < hei) {
    wid = screen.width - 50;
    hei = screen.height - 50;
  }
  OpenWindow = window.open("", "remoteWin", "resizable=1, scrollbars=0, toolbar=0, left=450, top=10, width=" + wid + ", height=" + hei);
  OpenWindow.document.open();
  OpenWindow.document.write('<html><head><title>Family Picture</title></head>' + '<body style="background:url(imgs/parchment.jpg); font:8pt verdana; margin:2px"><center>' + '<br><br><img src=' + picName + '><br><a href="javascript:window.close();">close window</a></center></body></html>');
  OpenWindow.document.close();
}

if(window.attachEvent)
  window.attachEvent("onload",setListeners);

function setListeners(){
  inputList = document.getElementsByTagName("INPUT");
  for(i=0;i<inputList.length;i++){
    inputList[i].attachEvent("onpropertychange",restoreStyles);
    inputList[i].style.backgroundColor = "";
  }
  selectList = document.getElementsByTagName("SELECT");
  for(i=0;i<selectList.length;i++){
    selectList[i].attachEvent("onpropertychange",restoreStyles);
    selectList[i].style.backgroundColor = "";
  }
}

function restoreStyles(){
  if(event.srcElement.style.backgroundColor != "")
    event.srcElement.style.backgroundColor = "";
}

function reloadBlog() {
  window.opener.location.reload()}

