﻿// *********************************************************************
// Browser Detection
// *********************************************************************
	
	if(document.getElementById) { // IE 5 and up, NS 6 and up
		var upLevel = true;
		}
	else if(document.layers) { // Netscape 4
		var ns4 = true;
		document.getElementById = function() { return null; }
		}
	else if(document.all) { // IE 4
		var ie4 = true;
		document.getElementById = function() { return null; }
		}
		
	var agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_safari = (agt.indexOf("safari") != -1);
	var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
	&& (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1)
	&& (!is_safari) );
	var is_nav2 = (is_nav && (is_major == 2));
	var is_nav3 = (is_nav && (is_major == 3));
	var is_nav4 = (is_nav && (is_major == 4)); 
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
	(agt.indexOf("; nav") != -1)) );
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)
	&& (!is_safari) );
	var is_ie3 = (is_ie && (is_major < 4));
	var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1) );
	var is_ie4up = (is_ie && (is_major >= 4));
	var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1) );
	var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
	var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1) );
	var is_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	var is_opera = (agt.indexOf("opera") != -1);
	var is_mac = (agt.indexOf("mac") != -1);
	var is_iemac = (is_ie && is_mac);


// *********************************************************************
// Page Element Manipulating Functions
// *********************************************************************

	// Gets a page element
	function getObject(id) {
		if(upLevel) {
			var obj = document.getElementById(id);
			}
		else if(obj) {
			var obj = eval('document.' + id);
			}
		else if(obj) {
			var obj = eval('document.all.' + id);
			}
		return obj
	}	
	
	// Hides a page element
	function hideObject(id) {
		var obj = getObject(id);
		if(obj!=null)
		{	
			if (ns4) {
				obj.visibility = "hide";
			}
			if (ie4 || upLevel) {
				obj.style.visibility = "hidden";
			}
		}

	}		
	
	// Shows a hidden page element
	function showObject(id) {
		var obj = getObject(id);
		if(obj!=null)
		{		
			if (ns4) {
				obj.visibility = "show";
			}
			if (ie4 || upLevel) {
				obj.style.visibility = "visible";
			}	
		}
	}
	
	// Removes a page element
	function removeObject(id) {
		var obj = getObject(id);	
		if(obj!=null)
		{				
			if (ns4) {
				obj.display = "none";
			}
			if (ie4 || upLevel) {
				obj.style.display = "none";
			}
		}
	}	
	
	// Restores a page element
	function restoreObject(id) {
		var obj = getObject(id);	
		if(obj!=null)
		{				
			if (ns4) {
				obj.display = "";
			}
			if (ie4 || upLevel) {
				obj.style.display = "";
			}
		}
	}	
	
	// Toggles the hiding and display of the div in id
	function toggleDisplay(id)
	{	
		var div = getObject(id);
		if(div != null)
		{
			if (ns4) {
				if(div.display == 'none')
					restoreObject(div.id);
				else
					removeObject(div.id);
			}
			if (ie4 || upLevel) {
				if(div.style.display == 'none')
					restoreObject(div.id);
				else
					removeObject(div.id);
			}
		}
	}	
	
	function toggleEnable(id) {
	    var control = getObject(id);
	    if(control.disabled = true)
	        control.disabled = false;
	    else
	        control.disabled = true;
	}
	
	// Selects an item from the list
	function selectFromList(list,value)
	{
		list = getObject(list);
		
		for (i=0; i < list.length; i++) {
			list.options[i].selected = false;
		} 
		for (i=0; i < list.length; i++) {
			if(list.options[i].value==value) {
				list.options[i].selected = true;
				return;
			}
		} 	
	}
	
	// Empties a page element that contains a list.
	function emptyList(id)
	{
		var list = getObject(id);
		for (x = list.length; x >= 0; x = x - 1) {
			list[x] = null;
		}
	}		
	
	// Fills a page element with text/value data.
	function fillListItems(id, listItems)
	{
		var list = getObject(id);

		// Clear the options currently in the list
		emptyList(id);
		
		// Load the items into the list	
		for(var k=0; k < listItems.length; k++)
		{
			var item = listItems[k];
			list[k] = new Option(leftTrim(item.Text),item.Value);
		}		
	} 
	
	// Inserts a list item	
	function insertListItem(id, index, text, value)
	{
		var list = getObject(id);
		var listItem = new Option(text,value);
		var existingItem = list.options[index];  
		try {
			list.add(listItem, existingItem); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			list.add(listItem, index); // IE only
		}
	}
	
	// Removes a List item at the given index
	function removeListItem(id, index)
	{
		// Get the list to update
		var list = getObject(id);
		if(index<list.options.length-1) list.remove(index);
	}
	
	// Gets the contents of the object
	function getContents(id) {
	    var div = getObject(id);
	    if(div) return div.innerHTML;
	}
	
	// Trims spaces from the left.
	function leftTrim(sString) 
	{
		if(sString)
		{
			while (sString.substring(0,1) == ' ')
			{
				sString = sString.substring(1, sString.length);
			}
		}
		return sString;
	}
	
    // Removes all spaces from a string
	function removeSpaces(sString) 
	{
	   var newString = '';
		if(sString)
		{		   
		   for(i=0;i<sString.length;i++)  {
		      if(sString.substring(i,i+1)!=' ') {
		         newString += sString.substring(i,i+1);
		      }	      
			}
		}
		return newString;
	}	
	
	// Adds on OnloadEvent to the document
	function addOnloadEvent(fnc)
	{
		if ( typeof window.addEventListener != "undefined" )
			window.addEventListener( "load", fnc, false );
		else if ( typeof window.attachEvent != "undefined" ) 
		{
			window.attachEvent( "onload", fnc );
		}
		else {
			if ( window.onload != null ) 
			{
				var oldOnload = window.onload;
				window.onload = function ( e ) 
					{
						oldOnload( e );
						window[fnc]();
					};
			}
			else 
				window.onload = fnc;
		}
	}		

	// This activates a controls post-back event
	function clickIt(control, validate)
	{
		if (validate == 'True') 
		{
			if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate())
			{
				__doPostBack(control,'');
			}
		} 
		else 
		{
			__doPostBack(control,'');
		}
		return true;	
	}
	
	// Creates a cookie
    function makeCookie(Name,Value,Expiry,Path,Domain,Secure){ 
	    if (Expiry!= null) { 
		    var datenow = new Date(); 
		    datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry)); 
		    Expiry = datenow.toGMTString(); 
	    } 

	    Expiry = (Expiry!= null)? '; expires='+Expiry : ''; 
	    Path = (Path!= null)?'; path='+Path:''; 
	    Domain = (Domain!= null)? '; domain='+Domain : ''; 
	    Secure = (Secure!= null)? '; secure' : ''; 

	    document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure; 
    } 
    
    // Reads a cookie
    function readCookie(Name) { 
	    var cookies = document.cookie; 
	    if (cookies.indexOf(Name + '=') == -1) return null; 
	    var start = cookies.indexOf(Name + '=') + (Name.length + 1); 
	    var finish = cookies.substring(start,cookies.length); 
	    finish = (finish.indexOf(';') == -1)? cookies.length : start + finish.indexOf(';'); 
	    return unescape(cookies.substring(start,finish)); 
    } 	
    
    // Opens a new  window
    function openWindow(url)
    {
       window.open(url, 'New Window');
    }
    
    // Opens a new window, automaticly sized
    function openPopup(url, name)
    {
       window.open(url, name, 'location=no,resizable=yes,scrollbars=yes,height=500, width=500');
    }
    
    // Toggles an expandable div
    function toggleExpand(expander, container)
    {
       var expanderImg = getObject(expander);
       var container = getObject(container);
       if(expanderImg.src.indexOf("plus.gif")>-1) {
          expanderImg.src="images/big_minus.gif";
          container.title = expanderImg.alt = "click to hide details";
       } else {
          expanderImg.src="images/big_plus.gif"; 
          container.title = expanderImg.alt = "click to show details";
       }
    }
    
    // Fires the browser print method
    function printThis(){
       alert('The print command has been sent to your browser. \nSome browsers take a few minutes to load the print dialog. \nPlease wait a few seconds before click this button again.');
       window.print();
    }
    
    // Like clicking the back button in the browser
    function goBack()
    {
       history.go(-1);
    }
    
    // This function gives ajax buttons, the "Please Wait" text.
    function progressing(cmd, group) {
        if(Page_ClientValidate(group)) {
            cmd.value = 'Please wait...';
            cmd.style.cursor = 'wait';   
            return true;
        } 
        return false;            
    }
  
   
    
/*------------------------*/    
    
    function toggle(obj1, cmd) {
	    var el = document.getElementById(obj1);
	    var display = (el.style.display != 'none');
	    el.style.display = ( display ? 'none' : '' );
	    
	    if(cmd!='undefined') {	    
	        cmd.innerHTML = (display ? 
	            cmd.innerHTML.replace('Hide','Show') : 
	            cmd.innerHTML.replace('Show','Hide'));
	    }
    }

    function toggleColor(obj2) {
	    var e2 = document.getElementById(obj2);
	    alert (e2);
	    e2.style.backgroundColor = (e2.style.backgroundColor != '#eeeeee' ? '#ffffff' : '#eeeeee' );
    }

    function setCookie(name, value, expires, path, domain, secure) {
      var curCookie = name + "=" + escape(value) +
          ((expires) ? "; expires=" + expires.toGMTString() : "") +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          ((secure) ? "; secure" : "");
      document.cookie = curCookie;
    }

    var userType;
    function getCookie(name) {
      var dc = document.cookie;
      var prefix = name + "=";
      var begin = dc.indexOf("; " + prefix);
      if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
      } else
        begin += 2;
      var end = document.cookie.indexOf(";", begin);
      if (end == -1)
        end = dc.length;
      return unescape(dc.substring(begin + prefix.length, end));
    }

    function userType(cookieName) {
	    uname = getCookie('ad')
	    if (uname!=null && uname!="") {
		    return uname;
	    } else {
		    return "an Unknown User Type"
	    }
    }

    function deleteCookie(name, path, domain) {
      if (getCookie(name)) {
        document.cookie = name + "=" +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
    }

    function isDefined(objToTest) {
        if (null == objToTest || "undefined" == typeof(objToTest) )
	        return false;
        return true;
    }

    
// Download Module Scripting -----------------------------------

    var FileID, FileUrl, OpenFull = false;    
    
	function SetFile(fileID, fileUrl, iframe, agr, open) {
	    FileID = fileID;
	    FileUrl = fileUrl;
	    $get(iframe).src = agr;
	    OpenFull = open;
	    if(isDefined(LogEvent))
	        LogEvent('ReadAgreement');
	    try {
	        _hbLink(agr, 'DownloadList');
	    } catch(ex) {}
	} 		
	function DeclineAgreement() { 
	    if(isDefined(LogEvent))
	        LogEvent('DeclinedAgreement');
	} 			
	function InitDownload(file) {
	    FileUrl = file;
	    if(typeof(Page_ClientValidate) == 'function') {
	        if(Page_ClientValidate()) 
	            DownloadFile();
	    } else DownloadFile();
	}
	
	function DownloadFile() { 
	    var windowArgs = 'height=10,width=10';
	    if(OpenFull) 
	        windowArgs='';
	    window.open(FileUrl, 'downloadWindow', windowArgs);		
	    
	    if(isDefined(LogEvent))
	        LogEvent('DownloadedFile');
	    try {
	        _hbLink(FileUrl, 'Agreement');	
        } catch(ex) {}
	}    
    
    function addRolloverBG(control, color) {
        if(is_ie6) return;
        control.onmouseover = function() { this.style.backgroundColor = color; };
        control.onmouseout = function() { this.style.backgroundColor = 'transparent'; };
    }
    
    function toggleSettings() {
        var show;
        if(this.tagName=="SELECT") show = this.selectedIndex > 0;
        else show = this.checked;    
        if(show) restoreObject(this.settings);
        else removeObject(this.settings);
    }    
    
// Article Module Scripting -----------------------------------    
   
    function growIfNeeded(textArea, min) {
     if(textArea.scrollHeight > textArea.offsetHeight) {      
      while (textArea.scrollHeight > textArea.offsetHeight) { textArea.rows++; }
     } else {
      while (textArea.scrollHeight < textArea.offsetHeight && textArea.rows > min) {  textArea.rows--;} 
     }
    }    
    
    function wait(div)
    {
        var container = getObject(div);
        if(container) {
            container.style.cursor = 'wait';
        }
    }
 
 // Content Tabs ---   
 
    var tabs, tabCount;

    function initTabs(tabsName) {
        tabs = getObject(tabsName)
        tabCount = tabs.childNodes.length;
        var firstTab = true;
        for(var x = 0; x < tabCount; x++) {
            if(tabs.childNodes[x].tagName == "LI") {
                tabs.childNodes[x].onclick = selectTab;
                if(firstTab) { 
                    selectTab.call(tabs.childNodes[x]);
                    firstTab = false;
                }
            }
        }
    }
    
    function selectTab() {
        hideTabs();
        this.className = "selected";
        restoreObject(this.id + '_Content');
    }
    
    function hideTabs() {
        for(var x = 0; x < tabCount; x++) {
            if(tabs.childNodes[x].tagName == "LI") {
                tabs.childNodes[x].className = "";
                removeObject(tabs.childNodes[x].id + '_Content');
            }
        }
    }

