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') {
        ReturnValue = CookiePieces[1];
      }
     }
     if(ReturnValue=="") {
         // no cookie
		 document.write("<script language=javascript src = '/js/tabmenu_pub.js'>"+bko+"/script"+bkc);
		 }
	 else {
		 document.write("<script language=javascript src = '/js/tabmenu_mem.js'>"+bko+"/script"+bkc);
         }
}

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 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 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];
      }
     }
     if(ReturnValue=="") {
         // no cookie
		 switchDiv('signout');
		 switchDiv('brd');
		 }
	 else {
		 switchDiv('signout');
	 	 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;
}

// 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 fieldLink(fieldID, fieldValue, hashValue)
{
    var fieldLinkUrl = 'http://members.alas.com/propub/template.htm?view=emailref';
    fieldLinkUrl += '&s_context=field';
    fieldLinkUrl += '&s_action=newSearch';
    fieldLinkUrl += '&s_complex=all';
    fieldLinkUrl += '&s_type=all';
    fieldLinkUrl += '&s_fieldSearch=' + fieldID + '|^"' + fieldValue +'"$';

    fieldLinkUrl += '&hash=' + hashValue;

    fieldLinkUrl += '&doc_action=setHitDoc';
    fieldLinkUrl += '&doc_hit=1';
    fieldLinkUrl += '&hilite=no';
    fieldLinkUrl += '&doc_searchcontext=field';

    
    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");
