// Disables menu items by id... 
function disableMenuItems(ItemList)
{

	for (i = 0; i < ItemList.length; i++) 
	{
		if (ItemList[i] != "#")
		{
			document.getElementById(ItemList[i]).className += " disabled";
			document.getElementById(ItemList[i]).getElementsByTagName("a")[0].href = "#";
		}
	} 
}

// Enable menu items by id; disable all others... 
function enableMenuItems(MenuItems, OptionList) 
{
	var ItemList = MenuItems.split(",");

	for (i = 0; i < ItemList.length; i++)
	{
		for (j = 0; j < OptionList.length; j++)
		{
			if (ItemList[i] == OptionList[j])
			{
				OptionList[j] = "#";
			}
		}
	}
	disableMenuItems(OptionList);
}

 // Workaround for Internet Explorer's lack of li:hover support
ieHover = function() 
{
	var ieElements = document.getElementById("menu").getElementsByTagName("li");
	for (var i = 0; i < ieElements.length; i++)
  {
		ieElements[i].onmouseover=function()
    {
			this.className+=" iehover";
		}
		ieElements[i].onmouseout=function()
    {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
	return true;
}

// Enables ieHover
if (window.attachEvent) window.attachEvent("onload", ieHover);

// Preloader for the submenu arrow mouseover
sArrow = new Image();
sArrow.src = "http://www.cydex.com/menuarrow_white.gif";

// Swaps submenu arrow image
function sub(name, toggle)
{
  if (toggle == "on")
  {
    document.getElementById(name + 'Arrow').src = "http://www.cydex.com/menuarrow_black.gif";
  }
  else
  {
    document.getElementById(name + 'Arrow').src = "http://www.cydex.com/menuarrow_white.gif";
  }
  return true;
}

 // Creates a cookie
 function setCookie(name, value, expires, days) {
   var cookies = document.cookie;            // cookies for site
   var ix1;                                  // index
   var n1 = name;                            // main cookie name
   var n2 = "";                              // crumb name
   var out;                                  // returned value
   var p2 = value;                           // new value
   var p3 = expires;                         // param work area
   var p4 = days;
   var msd = 1000 * 60 * 60 * 24;            // millisecs per day
   if (!p3) {                                // no expiration
     if (!p4) { p4 = 1; }                    // no days: use 1
     p3 = new Date();
     p3.setTime(p3.getTime() + msd * days);
   }
   ix1 = n1.indexOf(";");                    // cookie/crumb break
   if (ix1 != -1) {
     n2 = n1.substring(ix1 + 1);             // crumb name
     n1 = n1.substring(0, ix1);              // main cookie name
   }
   out = getCookieCrumb(cookies, n1);
   if (n2) {
     if (out) { out = getCookieCrumb(out, n2); }
     else { rest = ""; }
     if (rest) { p2 = rest + ";" + n2 + "=" + p2; }
     else      { p2 =              n2 + "=" + p2; }
   }
   document.cookie=n1+"="+escape(p2)+"; expires="+p3.toGMTString();
   return true;
 }
 
 // Retrieves a cookie
 function getCookie(name)
 {
   var cookies = document.cookie;            // cookies for site
   var ix1;                                  // loop index
   var n1 = name;                            // main cookie name
   var n2;                                   // crumb name
   var out;                                  // returned value
   ix1 = n1.indexOf(";");                    // cookie/crumb break
   if (ix1 != -1) 
   {
     n2 = n1.substring(ix1 + 1);             // crumb name
     n1 = n1.substring(0, ix1);              // main cookie name
   }
   out = getCookieCrumb(cookies, n1);
   if (n2 && out) 
   { 
     out = getCookieCrumb(out, n2);
   }
   cookie = rest;
   return out;
 }
 
 // Retrieves a cookie crumb
 function getCookieCrumb(instring, seeking)
 {
   var c1;                                   // cookies work area
   var c2;                                   // cookie work area
   var c3;                                   // cookie name
   var c4;                                   // cookie value
   var ix1; var ix2; var ix3; var ix4;       // indexes
   var out;                                  // return value
   rest = "";          
   c1 = instring;
   c1 = c1.replace(/\n/g, "");               // drop nl chars
   c1 = c1.replace(/\r/g, "");               // drop cr chars
   c1 = c1 + ";";                            // for final cookie
   ix1 = 0;                                  // from beginning
   if (seeking.substring(0, 1) == "#") 
   {
     if (seeking == "#0" && !instring) 
     { 
       return 0; 
     }
     ix4 = seeking.substring(1);             // which item wanten
     ix3 = 0;                                // none so far
     while (c1.indexOf(";", ix1) != -1) 
     {
       ix2 = c1.indexOf(";", ix1);
       cookie = c1.substring(ix1, ix2);
       ix3 += 1;
       if (ix3 == ix4) 
       { 
         return cookie; 
       }
       ix1 = ix2 + 1;
     }
     if (ix4 == 0) 
     { 
       return ix3;            // count of items
     }
     return "";
   }
   while (c1.indexOf(";", ix1) != -1) 
   {
     ix2 = c1.indexOf(";", ix1);             // next cookie break
     if (ix2 == -1) 
     { 
       ix2 = c1.length; 
     }
     cookie = c1.substring(ix1, ix2);        // a single cookie
     c2 = cookie;                            // cookie work area
     ix1 = ix2 + 1;
     ix3 = c2.indexOf("=", 0);               // name=value break
     if (ix3 == -1) 
     { 
       ix3 = c2.length; 
     }
     c3 = c2.substring(0, ix3);              // get the name
     c4 = c2.substring(ix3 + 1);             // get the value
     c3 = c3.replace(/ /g, "");              // drop all space
     if (c3 == seeking) 
     {
       out = unescape(c4);
     } 
     else 
     {
       if (rest) 
       { 
         rest = rest + ";" + cookie; 
       }
       else      
       { 
         rest = cookie; 
       }
     }
   }
   return out;
 }
 
 // Code for the entrance page
 function initializeCydex()
 {
   if(getCookie("cydex;exists") == "true")
   {
     window.location = "home.html";
   }
   else
   {
     setCookie("cydex;exists", "true", "", 365);
     setCookie("cydex;name", "", "", 365);
     setCookie("cydex;userid", "", "", 365);
     setCookie("cydex;passcode", "", "", 365);
     setCookie("cydex;autologin", "false", "", 365);
     setCookie("cydex;access", "default", "", 365);
     if(getCookie("cydex;exists") == "true")
     {
       window.open('intro.html','Cydex Introduction','width=500,height=200,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=yes,menubar=no');
     }
     else
     {
       alert("You appear to have cookies disabled. You will not be able to log in to our site unless cookies are enabled in your browser.\nYou can bypass our Flash Player introduction by going directly to:\nhttp://www.cydex.com/home.html");
     }
     window.location = "home.html";
   }
 }
 
 // Autofills the login form if possible
 function fillForm()
 {
   if (getCookie("cydex;name") != "" && getCookie("cydex;name") != undefined)
   {
     document.getElementById('welcome').innerHTML = "Welcome back, " + getCookie("cydex;name") + "!";
   }
   if (getCookie("cydex;autologin") == "true")
   {
     document.prefs.userid.value = getCookie("cydex;userid");
     document.prefs.passcode.value = getCookie("cydex;passcode");
     document.prefs.autologin.checked = true;
   }
 }
 
 // Stores form data in cookie
 function submitForm()
 {
   var name, userid, passcode; 
 
   userid = document.prefs.userid.value;
   passcode = document.prefs.passcode.value;
 
   setCookie("cydex;userid", userid, "", 365);
   setCookie("cydex;passcode", passcode, "", 365);
 
   if (document.prefs.autologin.checked == true)
   {
     setCookie("cydex;autologin", "true", "", 365);
   }
   else
   {
     setCookie("cydex;autologin", "false", "", 365);
   }
 }
 
 // Changes location to the main page immediately
 function goHomeNow()
 {
   parent.location = "home.html";
 }
 
 // Changes location to the main page in a given number of seconds
 function goHome(time)
 {
   ms = time * 1000;
   setTimeout(goHomeNow(), ms);
 }

// Displays the current date in format: Dayname, Monthname Numberth
function updateDate()
{
  var dateString = "";
  var curDate = new Date();
  
  var dayArray = new Array();
  dayArray[0] = "Sunday";
  dayArray[1] = "Monday";
  dayArray[2] = "Tuesday";
  dayArray[3] = "Wednesday";
  dayArray[4] = "Thursday";
  dayArray[5] = "Friday";
  dayArray[6] = "Saturday";
  
  var monthArray = new Array();
  monthArray[0] = "January";
  monthArray[1] = "February";
  monthArray[2] = "March";
  monthArray[3] = "April";
  monthArray[4] = "May";
  monthArray[5] = "June";
  monthArray[6] = "July";
  monthArray[7] = "August";
  monthArray[8] = "September";
  monthArray[9] = "October";
  monthArray[10] = "November";
  monthArray[11] = "December";
  
  var suffix = "";
  switch(curDate.getDate())
  {
    case 1: case 21: case 31:
      suffix = "st.";
      break;
    case 2: case 22:
      suffix = "nd.";
      break;
    case 3: case 23:
      suffix = "rd.";
      break;
    default:
      suffix = "th.";
      break;
  }
  
  document.getElementById('date').innerHTML = dayArray[curDate.getDay()] 
                                            + ", "
                                            + monthArray[curDate.getMonth()] 
                                            + " "
                                            + curDate.getDate()
                                            + suffix;
  
  return dateString;
}

// Expands a hidden area of the site
// target is the name, offText is the "Show Details" equiv., onText is the "Hide Details" equiv.
function expandSectionORIGINAL(target, offText, onText)
{
  var expTxtString = "exptxt_" + target;
  var expString = "exp_" + target;
  if (document.getElementById(expTxtString).innerHTML == onText)
  {
    document.getElementById(expTxtString).innerHTML = offText;
    document.getElementById(expString).style.display = "none";
  }
  else
  {
    document.getElementById(expTxtString).innerHTML = onText;
    document.getElementById(expString).style.display = "block";
  }
}

/* Expands a text area (<DIV>)... */
function expandText(target)
{
  if (document.getElementById(target).style.display == "block")
  {
    document.getElementById(target).style.display = "none";
  }
  else
  {
    document.getElementById(target).style.display = "block";
  }
}

/* Expands a hidden area of a page...
	'target' is the area reference
	'onText' is the "Show Details" link 
	'offText' is the "Hide Details" link
   If the 'details' link is text, then that text will be displayed; otherwise (if the
   'details link' is an image file - .gif, .jpg, or .png), the image will be displayed.
*/
function expandSection(target, offText, onText)
{
  var expTriggerString = "exptxt_" + target;
  var expString = "exp_" + target;
  var extension = offText.substring(offText.lastIndexOf("."));

  if (extension == ".gif" || extension == ".jpg" || extension == ".png")
  {
	if (document.getElementById(expString).style.display == "block")
    {
      document.getElementById(expTriggerString).getElementsByTagName("img")[0].src = offText;
      document.getElementById(expString).style.display = "none";
    }
    else
    {
      document.getElementById(expTriggerString).getElementsByTagName("img")[0].src = onText;
      document.getElementById(expString).style.display = "block";
    }
  }
  else
  {
    if (document.getElementById(expTriggerString).innerHTML == onText)
    {
      document.getElementById(expTriggerString).innerHTML = offText;
      document.getElementById(expString).style.display = "none";
    }
    else
    {
      document.getElementById(expTriggerString).innerHTML = onText;
      document.getElementById(expString).style.display = "block";
    }
  }
}

// Interrupts IE right clicks with an alert
function blockRightClick(e) 
{
  if (document.all) 
  {
    if (event.button == 2) 
    {
      alert("Right-click disabled");
      return false;
    }
  }
  if (document.layers) 
  {
    if (e.which == 3) 
    {
      alert("Right-click disabled");
      return false;
    }
  }
}
function startBRC()
{
  if (document.layers) 
  {
  document.captureEvents(Event.MOUSEDOWN);
  }
  document.onmousedown=blockRightClick;
}

function Wink(imgName)
{
    var runString;
	
    runString = "changeOpacity('" + imgName + "', 10);";    	
	window.setTimeout(runString, 1);	
	
    runString = "changeOpacity('" + imgName + "', 100);";
	window.setTimeout(runString, 150);		
}

function changeOpacity(imgName, newOpacity)
{
  document.getElementById(imgName).style.opacity = newOpacity / 100;
  document.getElementById(imgName).style.filter = "alpha(opacity:" + newOpacity + ")";
  document.getElementById(imgName).style.KHTMLOpacity = newOpacity / 100;
  document.getElementById(imgName).style.MozOpacity = newOpacity / 100;
}

function Blinker()
{
	var blink = document.all.tags("BLINK") 
	for (var i=0; i < blink.length; i++) 
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
} 
function startBlink() 
{ 
	if (document.all) 
		setInterval("Blinker()",500) 
} 

// Disable form buttons...

function disableButtons(formID)
{
	for(counter=0;counter<document.getElementById(formID).elements.length;counter++)
	{
		if(document.getElementById(formID).elements[counter].type == 'button' || document.forms[0].elements[counter].type == 'submit' || document.forms[0].elements[counter].type == 'reset')
		{
			document.getElementById(formID).elements[counter].disabled = true;
		}
	}
	return true;
}

// Highlight the currently focused FORM field...

function FormField(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}

sfFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}

sfTarget = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) {
					aEls[j].targetEl = sfEls[i];
					aEls[j].onclick = function() {
						if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
						this.targetEl.className+=" sftarget";
						document.lastTarget=this.targetEl;
						return true;
					}
				}
			}
		}
	}
}

FormField(sfFocus, "INPUT");
FormField(sfFocus, "TEXTAREA");
FormField(sfTarget, "DIV", "content");

// Checks for a logged-in visitor and updates the sidebar HTML appropriately...

function checkLogin()
{
	if(readCookie('Name'))
	{
		var User = readCookie('Name');
            document.getElementById('sblogin').innerHTML = "<img src=\"http://www.cydex.com/bullet.gif\" width=\"13\" height=\"7\" alt=\"\" /><a href=\"http://www.cydex.com/Quick%20Links/Resources.asp\">Privileged Resources</a>";
	}
	return true;
}

// Cookie reader...

function readCookie(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) return c.substring(nameEQ.length,c.length);
	}
	return false;
}
