

// commented out heather,bud 11/7/2011
//
// // For Master page
// //function LOADING() {
// //    if (document.forms[0].elements[0].type == "text")
// //      //  document.forms[0].elements[0].focus();
//     //    else {    
//     //if (document.forms) {
//        // var inpObj = document.forms[0].getElementsByTagName("input");
//      //   if (inpObj) {
//    //         for (var i = 0; i < inpObj.length; i++) {
//             //    if (inpObj[i].type == "text") {
//                     //      inpObj[i].focus();                                       
//           //          return true;
//         //        }
//       //      }
//     //    }
//   //  }
//     //}
// }
// 
// 
// function submitenter(myfield, e) {
//     var keycode;
//     if (window.event) keycode = window.event.keyCode;
//     else if (e) keycode = e.which;
//     else return true;
// 
//     if (keycode == 13) {
//         myfield.form.submit();
//         return false;
//     }
//     else
//         return true;
// }
// function isValid(form) {
//     if (form.user.value == "") {
//         alert("Please enter your Username");
//         form.user.focus();
//         return false;
//     }
//     else if (form.pass.value == "") {
//         alert("Please enter your Password");
//         form.pass.focus();
//         return false;
//     }
//     else return true;
// }
// 
// function getCookie(name) {
//     var pos;
//     var token = name + "=";
//     var tnlen = token.length;
//     var cklen = document.cookie.length;
//     var i = 0;
//     var j;
//     while (i < cklen) {
//         j = i + tnlen;
//         if (document.cookie.substring(i, j) == token) {
//             pos = document.cookie.indexOf(";", j);
//             if (pos == -1)
//                 pos = document.cookie.length;
//             return unescape(document.cookie.substring(j, pos));
//         }
//         i = document.cookie.indexOf(" ", i) + 1;
//         if (i == 0) break;
//     } //End While
//     return null;
// }
// 
// function authorizedUserRedirect() {
//     var myCookieVal;
//     var retVal;
// 
//     // myCookieVal = getCookie('dirpdfraws');
//     myCookieVal = getCookie('Member_User');
//     if (myCookieVal == "") {
//         myCookieVal = getCookie('pdfraws');
// 
//         if (myCookieVal == "")
//             retVal = false;
//         else
//             retVal = true;
//     }
//     else
//         retVal = true;
// 
//     if (document.all && document.all("hIsMemberOrAlasStaff")) {
//         document.all("hIsMemberOrAlasStaff").value = myCookieVal;        
//     }
//     //  alert(myCookieVal);
//       
//     //  return retVal;
// }

function getStyleObject(objectId) {
    // checkW3C DOM, then MSIE 4, then NN 4.  
    if (document.getElementById && document.getElementById(objectId)) {
        return document.getElementById(objectId).style;
    }
    else if (document.all && document.all(objectId)) {
        return document.all(objectId).style;
    }
    else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
    } else {
        return false;
    }
}

//function hideAll()
//{
//   changeObjectVisibility("brd","hidden");
//   changeObjectVisibility("board","hidden");
//}

function changeObjectVisibility(objectId, newVisibility) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);

    // then if we find a stylesheet, set its visibility
    // as requested
    //
    if (styleObject) {
        styleObject.visibility = newVisibility;
        if (newVisibility == 'visible')
            styleObject.display = 'inline';
        return true;
    }
    else {
        return false;
    }
}

function switchDiv(div_id) {
    var style_sheet = getStyleObject(div_id);
    if (style_sheet) {
        //    hideAll();
        changeObjectVisibility(div_id, "visible");
    }
    //  else 
    //  {
    //    alert("sorry, this only works in browsers that do Dynamic HTML");
    //  }
}

function ispage(page) {
    if (page == 'P') {
        var style_sheet = getStyleObject("membersmenu");
        var hide_style = getStyleObject("membersmenu");
        hide_style.display = 'none';
        switchDiv('publicmenu');
    }
    if (page == 'M') {
        var style_sheet = getStyleObject("publicmenu");
        var hide_style = getStyleObject("publicmenu");
        hide_style.display = 'none';
        switchDiv('membersmenu');
    }
}

function hideAll() {
    changeObjectVisibility("mgmt", "hidden");
    changeObjectVisibility("ms", "hidden");
    changeObjectVisibility("lp", "hidden");
    changeObjectVisibility("cm", "hidden");
    changeObjectVisibility("fi", "hidden");
    changeObjectVisibility("is", "hidden");
    changeObjectVisibility("ad", "hidden");

    changeObjectVisibility("a", "hidden");
    changeObjectVisibility("b", "hidden");
    changeObjectVisibility("c", "hidden");
    changeObjectVisibility("d", "hidden");
    changeObjectVisibility("e", "hidden");
    changeObjectVisibility("f", "hidden");
}

function showDiv(div_id)
//Used only on alas professionals page to hide or show div based on link
{
    var style_sheet = getStyleObject(div_id);
    if (style_sheet) {
        hideAll();
        changeObjectVisibility(div_id, "visible");
    }
}

function showTableRow(tr_id)
//Used only on alas professionals page to hide or show div based on link
{
    var style_sheet = getStyleObject(tr_id);
    if (style_sheet) {

        if (style_sheet.visibility == 'visible') {
            style_sheet.visibility = 'hidden';
            style_sheet.display = 'none';
        }
        else {
            style_sheet.visibility = 'visible';
            style_sheet.display = 'table-row';
        }

    }
	if (tr_id='reg' && style_sheet.visibility == 'visible') {
	  if (document.getElementById('lpM')) {
	    document.getElementById('lpM').height = '5700px';
	    document.getElementById('leftnav').style.height = '5700px';
	    document.getElementById('content').style.height = '5700px';
	  }
	}
	else
	 {
	 resize();
	 
	 }
}

function start_for_conf() {
    /* This function is for the conferences page that will decide which menu to display depending
    on whether the cookie is found.
    */
    var bko = "<";
    var bkc = ">";
    var lf = "\n";
    var CookieString = document.cookie;
    var CookieSet = CookieString.split(';');
    var SetSize = CookieSet.length;
    var CookiePieces
    var ReturnValue = "";
    var x = 0;
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
        CookiePieces = CookieSet[x].split('=');
        if (CookiePieces[0].substring(0, 1) == ' ') {
            CookiePieces[0] = CookiePieces[0].substring(1, CookiePieces[0].length);
        }
        if (CookiePieces[0] == 'pdfraws' || CookiePieces[0] == 'dir_pdfraws') {
            ReturnValue = CookiePieces[1];
        }
    }
    if (ReturnValue == "") {
        // no cookie
        ispage('P');
    }
    else {
        ispage('M');
    }
}

function checkCookie() {
    //determines if user is board member and then displays board menu option.
    var lf = "\n";
    var CookieString = document.cookie;    
    var CookieSet = CookieString.split(';');
    var SetSize = CookieSet.length;
    var CookiePieces
    var ReturnValue = "";
    var x = 0;    
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
        CookiePieces = CookieSet[x].split('=');
        if (CookiePieces[0].substring(0, 1) == ' ') {
            CookiePieces[0] = CookiePieces[0].substring(1, CookiePieces[0].length);
        }        
        if (CookiePieces[0] == 'dir_pdfraws') {
            ReturnValue = CookiePieces[1];
        }
    }    
   
    ispage('M');
    switchDiv('signout');
    if (ReturnValue == "") {
        // no cookie
        switchDiv('brd');
    }
    else {
        switchDiv('board');
    }
}

function welcomeCookie() {
    //same as above except in addition it will display different items on welcome page if director.
    var lf = "\n";
    var CookieString = document.cookie;
    var CookieSet = CookieString.split(';');
    var SetSize = CookieSet.length;
    var CookiePieces
    var ReturnValue = "";
    var x = 0;
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
        CookiePieces = CookieSet[x].split('=');
        if (CookiePieces[0].substring(0, 1) == ' ') {
            CookiePieces[0] = CookiePieces[0].substring(1, CookiePieces[0].length);
        }
        if (CookiePieces[0] == 'dir_pdfraws') {
            ReturnValue = CookiePieces[1];
        }
    }
    if (ReturnValue == "") {
        // no cookie
        switchDiv('memb');
        switchDiv('brd');
    }
    else {
        switchDiv('dirs');
        switchDiv('board');
        switchDiv('brdmtg');
    }
}

// generic function to set a cookie with given name and value (days usually 0)
function set_cookie(cookieName, cookieValue, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
        var expires = "";
              
    document.cookie = cookieName + "=" + escape(cookieValue) + expires;
  //  alert(document.cookie);
}

// this function reads the alas_contacts cookie, runs showDiv for the value of the cookie, and deletes the cookie.
function readContactCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) {
            showDiv(c.substring(nameEQ.length, c.length));
            set_cookie(name, 'cm', -1);
        }
    }
    return null;
}


// pop-up function
var newWin = null;
function closeWin() {
    if (newWin != null) {
        if (!newWin.closed)
            newWin.close();
    }
}
function popup_save(strURL) {
    closeWin();
    var w = screen.width / 2;
    var h = screen.height / 1.5;
    var strOptions = "";
    strOptions = "status,height=" + h + ",width=" + w;
    newWin = window.open(strURL, 'newWin', strOptions);
    newWin.focus();
}

function popup_open(x, y) {
    // This function pops open a window about half the screen size with url x
    var w = screen.width / 2;
    var h = screen.height / 1.5;
    var win;
    //   win = window.open("",'pop','width='+w+',height='+h+',resizable=yes,scrollbars=yes');
    //   win.close();
    win = window.open(x, y, 'width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes');
    win.focus();
}


function fieldLinkN(collValue, docValue, anchorValue) {
    var vidValue;
    vidValue = "ALAS_id";

    var CookieString = document.cookie;
    var CookieSet = CookieString.split(';');
    var SetSize = CookieSet.length;
    var CookiePieces;
    var ReturnValue = "";
    var x = 0;

    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
        CookiePieces = CookieSet[x].split('=');
        if (CookiePieces[0].substring(0, 1) == ' ') {
            CookiePieces[0] = CookiePieces[0].substring(1, CookiePieces[0].length);
        }
        if (CookiePieces[0] == 'dir_pdfraws') {
            vidValue = "Directors";
        }
        if (CookiePieces[0] == 'pdfraws') {
            if (CookiePieces[1].substring(0, 1) == 'M') {
                vidValue = "Basic";
            }
            if (CookiePieces[1].substring(0, 1) == 'F') {
                vidValue = "FirmAdm";
            }
        }
    }

    var fieldLinkUrl = '/NXT/gateway.dll?f=id$id=' + docValue + '$cid=' + collValue + '$t=default.htm$vid=ALAS:' + vidValue;

    if (anchorValue != "")
        fieldLinkUrl += '#' + anchorValue;

    self.location.href = fieldLinkUrl;
}


// ShowItem and HideItem: JavaScript functions to show and hide drop-down menus.
// Using x.style.visibility seems to have better cross browser support than using 
// x.style.display="block" and x.style.display="none" to show and hide the menu.

function ShowItem(itemID) {
    var x = document.getElementById(itemID);
    if (x)
        x.style.visibility = "visible";
    return true;
}

function HideItem(itemID) {
    var x = document.getElementById(itemID);
    if (x)
        x.style.visibility = "hidden";
    return true;
}

function addScript(src) {

  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", src);
  
    document.getElementsByTagName("head")[0].appendChild(fileref);

}

addScript("/js/main.css");
addScript("/js/topnavbar.css");

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
    var ffversion = new Number(RegExp.$1); // capture x.x portion and store as a number
}

function resize() {
    if (document.getElementById('leftnav') && document.getElementById('content')) {
        // document.getElementById('leftnav').style.height = document.getElementById('content').offsetHeight - 20 + 'px';
        if (document.getElementById('content').offsetHeight >= 698) {            
            document.getElementById('leftnav').style.height = document.body.clientHeight - 60 + 'px';
            document.getElementById('content').style.height = document.body.clientHeight - 60 + 'px';
       }
    }
}
