/* =================================================== */
/* |                                                 | */
/* |                                                 | */
/* |                Aeronix, Inc.                    | */
/* |         Utility Javascript Codefile             | */
/* |                                                 | */
/* |           Concinnitas Development               | */
/* |         Implemented Feb-March 2006              | */
/* |                                                 | */
/* |                                                 | */
/* =================================================== */





//*****************************************************************************
// Run on page load.

  fontsetting = getCookie('dyn_fontsize');
  fontsmall = "alternate "; fontmedium = "alternate "; fontlarge = "alternate "; fontxlarge = "alternate ";
    
    if (fontsetting == "small") {
        fontsmall = "";
    } else if (fontsetting == "medium") {
        fontmedium = "";
    } else if (fontsetting == "large") {
        fontlarge = "";
    } else if (fontsetting == "xlarge") {
        fontxlarge = "";
	} else {
		fontmedium = "";
	}
    
  document.write('<link rel="'+fontsmall+'stylesheet" type="text/css" href="'+sm_text_css_location+'" title="small" media="all" />');    
  document.write('<link rel="'+fontmedium+'stylesheet" type="text/css" href="'+md_text_css_location+'" title="medium" media="all" />'); 
  document.write('<link rel="'+fontlarge+'stylesheet" type="text/css" href="'+lg_text_css_location+'" title="large" media="all" />'); 
  document.write('<link rel="'+fontxlarge+'stylesheet" type="text/css" href="'+xl_text_css_location+'" title="xlarge" media="all" />'); 




//*****************************************************************************
// Run after page load.

function initialize()
{
  // Add arrows to links within <p class="action">
  insertArrows();
}



//*****************************************************************************
// Insert double arrow glyph after links inside any element classed as "action"

function insertArrows() {
	var ptags = document.getElementsByTagName('p');
	var ptags_2 = document.getElementsByTagName('span');

	
	var action_ptags = [];
	for (var i = 0; i < ptags.length; i++) {
    	if (/\baction\b/.exec(ptags[i].className)) {
    		action_ptags[action_ptags.length] = ptags[i];
    	}
  	}
  
  // Add span elements
  for (var i = 0; i < ptags_2.length; i++) {
    	if (/\baction\b/.exec(ptags_2[i].className)) {
    		action_ptags[action_ptags.length] = ptags_2[i];
    	}
  	}
  	
  	for (var i = 0; i < action_ptags.length; i++) {
    	var arrow = document.createElement('span');
    	arrow.className = 'arrow';
		arrow.innerHTML = "&nbsp;&#187;";
		// var symbol = document.createTextNode(" &#187;");
		// arrow.appendChild(symbol);
    	action_ptags[i].appendChild(arrow);
  	}
	var ultags = document.getElementsByTagName('ul');
	var action_ultags = [];
	for (var i = 0; i < ultags.length; i++) {
    	if (/\baction\b/.exec(ultags[i].className)) {
			for ( var x = 0; x < ultags[i].childNodes.length; x++ ){
				if ( ultags[i].childNodes[x].tagName == 'LI' ) {
    				action_ultags[action_ultags.length] = ultags[i].childNodes[x];
				}
			}
    	}
  	}
  	for (var i = 0; i < action_ultags.length; i++) {
    	var arrow = document.createElement('span');
    	arrow.className = 'arrow';
		arrow.innerHTML = "&nbsp;&#187;";
		// var symbol = document.createTextNode(' »');
		// arrow.appendChild(symbol);
    	action_ultags[i].appendChild(arrow);
  	}
	var spantags = document.getElementsByTagName('span');
	var arrow_spantags = [];
	for (var i = 0; i < spantags.length; i++) {
    	if (/arrow/.exec(spantags[i].className)) {
    		arrow_spantags[arrow_spantags.length] = spantags[i];
    	}
  	}
  	for (var i = 0; i < arrow_spantags.length; i++) {
		if (/\barrowleft\b/.exec(arrow_spantags[i].className)) {
			arrow_spantags[i].innerHTML = "&#171;&nbsp;";
		} else {
    		arrow_spantags[i].innerHTML = "&nbsp;&#187;";
		}
  	}
}




//*****************************************************************************
// Basic javascript cookie save/load/delete functionality.




function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}

function setCookie(myname, myvalue, mypath, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = myname + "=" + escape(myvalue) + ((mypath == null) ? "" : "; path=" + mypath) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

}




//*****************************************************************************
// Dynamic font resizing with support for cookie-based size pref storage.

function setFont(myfontsize) {
    
    var font_i, font_a, font_main;
    for (font_i=0; (font_a = document.getElementsByTagName("link")[font_i]); font_i++) {   
        if(font_a.getAttribute("rel").indexOf("style") > -1 && font_a.getAttribute("title")) {
            font_a.disabled = true;
            if (font_a.getAttribute("title") == myfontsize) {
                font_a.disabled = false;
            }
        }  
    }

    setCookie('dyn_fontsize', myfontsize, '/', 1000)
    fontsetting = myfontsize;
    document.getElementById('fontid_small').className = 'fontsize_small';
    document.getElementById('fontid_medium').className = 'fontsize_medium'; 
    document.getElementById('fontid_large').className = 'fontsize_large'; 
    document.getElementById('fontid_xlarge').className = 'fontsize_xlarge';                     
    document.getElementById('fontid_'+myfontsize).className = 'fontsize_'+fontsetting+'_active';
    
}


function renderReadability() {
    document.write('<div id="dyn_fontsize">');
    document.write('<ul>');
    document.write('<li id="fontid_small" class="fontsize_small"><a href="#" onclick="setFont(\'small\'); return false;"><img border=0 src="'+dotimg+'" class="txtimg" alt="Small"/></a></li>');
    document.write('<li id="fontid_medium" class="fontsize_medium"><a href="#" onclick="setFont(\'medium\'); return false;"><img border=0 src="'+dotimg+'" class="txtimg" alt="Medium"/></a></li>');
    document.write('<li id="fontid_large" class="fontsize_large"><a href="#" onclick="setFont(\'large\'); return false;"><img border=0 src="'+dotimg+'" class="txtimg" alt="Large"/></a></li>');
    document.write('<li id="fontid_xlarge" class="fontsize_xlarge"><a href="#" onclick="setFont(\'xlarge\'); return false;"><img border=0 src="'+dotimg+'" class="txtimg" alt="Extra Large"/></a></li>');
    document.write('</ul>');
    document.write('</div>');
    if (fontsetting) { 
    document.getElementById('fontid_'+fontsetting).className = 'fontsize_'+fontsetting+'_active'; 
    } else {
    document.getElementById('fontid_'+'medium').className = 'fontsize_medium_active';       
    }      
}




//*****************************************************************************
// Search support.

function searchsubmit() 
{
	// Our regex
  var tregex=/<search>/gi;

  // Test the val
  var inputstr=document.forms['searchform'].searchquery.value;

  // do the comparison, if we have a match
  if (tregex.test(inputstr))
    {
	  alert('Please enter one or more words to search for.');
	  return false;	
	  }
	return true;
}




//*****************************************************************************
// JS code required for cross-browser Son Of Suckerfish dropdown support in IE6.

function isFunction(a) {
    return typeof a == 'function';
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

sfHover = function() {
  // In case we don't have the top_navlist element on a given page
  if (document.getElementById("top_navlist"))
	{
	
  var sfEls = document.getElementById("top_navlist").getElementsByTagName("LI");  
	for (var i=0; i<sfEls.length; i++) {		
		
		// Define the onmouseover function
		sfEls[i].onmouseover=function() {
			
		  // IE form select kludge.
	    if (document.getElementById("nav_go_form"))
	      {
	      var zselects=document.getElementById("nav_go_form").getElementsByTagName("SELECT");
	      for (var j=0; j<zselects.length; j++)
	        {
	        zselects[j].style.visibility="hidden";	
	        }
	      }
		
     if (this.className=="separator")
        {
        this.className+=" sfsephover";	
        }
     else if (this.className=="ancestor") 
        {
      	this.className+=" sfhover sfahover";
			  myhref=this.getElementsByTagName("A");
		    if (isObject(myhref[0])) myhref[0].className+=" sfhover";
        }
     else if (this.className=="locked") 
        {
      	this.className+=" sfhover sflhover";
			  myhref=this.getElementsByTagName("A");
		    if (isObject(myhref[0])) myhref[0].className+=" sfhover";
        }
      else 
        {
			  this.className+=" sfhover";
			  myhref=this.getElementsByTagName("A");
		    if (isObject(myhref[0])) myhref[0].className+=" sfhover";
			  }
		}
		sfEls[i].onmouseout=function() {
		  
	    // IE form select kludge.
	    if (document.getElementById("nav_go_form"))
	      {
	      var zselects=document.getElementById("nav_go_form").getElementsByTagName("SELECT");
	      for (var j=0; j<zselects.length; j++)
	        {
	        zselects[j].style.visibility="visible";	
	        }
	      }
	  
			this.className=this.className.replace(new RegExp(" sfsephover\\b"), "");	
			this.className=this.className.replace(new RegExp(" sfhover sflhover\\b"), "");		
			this.className=this.className.replace(new RegExp(" sfhover sfahover\\b"), "");
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			myhref=this.getElementsByTagName("A");
		  if (isObject(myhref[0])) myhref[0].className=myhref[0].className.replace(new RegExp(" sfhover\\b"), "");
		  }
		}
	}
}

var sfClickFired=false;
sfClick = function() {
  // In case we don't have the top_navlist element on a given page
  if (document.getElementById("top_navlist"))
	{
  var sfEls = document.getElementById("top_navlist").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {	  
		
		// Handle another IE issue that also applies to Moz.
		// We pull the HREF from the first contained A
		// and attach it as a location.href to all LI elements onclick.
		// Because all nested LIs fire their onclicks from innermost out,
		// we flip sfClickFired to true after our desired event. 
		sfEls[i].onclick=function()
		  {
		  mychref=this.getElementsByTagName("A");
		  if (mychref[0].href && (sfClickFired==false)) 
		    {
		    sfClickFired=true;
		    
		    /* handle the case where we spawn a new window with target="blah" */
		    if (mychref[0].target=='') 
		      {
		      document.location.href=mychref[0].href;
		      }
		    }	
		  }
	  }
	}
}

// IE
if (window.attachEvent) 
  {
  window.attachEvent("onload", sfHover);
  window.attachEvent("onload", sfClick);  
  }
// Mozilla
if (window.addEventListener) 
  {
  window.addEventListener("load", sfClick, false);
  }




//*****************************************************************************
// JS code to complete mouseover highlighting of on-page navtabs

ptHover = function() {
	
	// In case we don't have the page_navlist element on a given page
	if (document.getElementById("page_navlist"))
	{
	var ptEls = document.getElementById("page_navlist").getElementsByTagName("A");
	for (var i=0; i<ptEls.length; i++) {
		
		// Add code to handle ancestor-type nav menu item mouseover-background-switch
		
		ptEls[i].onmouseover=function() 
		  {
			  this.parentNode.className+=" pthover";
			}
			
		ptEls[i].onmouseout=function() {
			this.parentNode.className=this.parentNode.className.replace(new RegExp(" pthover\\b"), ""); //IE
		  this.parentNode.className=this.parentNode.className.replace(new RegExp("pthover\\b"), "");  //Moz
		  }
	  }
  }
}

// Mozilla
if (window.addEventListener) 
  {
  window.addEventListener("load", ptHover, false);
  }
// IE
else if (window.attachEvent) 
  {
  window.attachEvent("onload", ptHover);
  }
  
  
  

//*****************************************************************************
// Show/hide DOM elements - used for page tabsheets
  
function activateTabsheet(searchin_id, oftype_class, boxid)
{ 
	 var tsEls = document.getElementById(searchin_id).getElementsByTagName("DIV");
   for (var i=0; i<tsEls.length; i++) 
     {
     if (tsEls[i].className==oftype_class)
       {
       tsEls[i].style.visibility="hidden";
       tsEls[i].style.display="none";       
       }
     }
   document.getElementById(boxid).style.visibility="visible";
   document.getElementById(boxid).style.display="block";
} 

function activateTab(tab, searchin_id)
{
  var Els = document.getElementById(searchin_id).getElementsByTagName("LI");
	for (var i=0; i<Els.length; i++) 
	  {
		Els[i].className=Els[i].className.replace(new RegExp(" current\\b"), ""); //IE
		Els[i].className=Els[i].className.replace(new RegExp("current\\b"), "");  //Moz
		}
	tab.parentNode.className +=" current";
}




//*****************************************************************************
// Simple popup generator for popup full-size images, etc.

var mypwin=null;
function execNewWindow(mypage,myname,w,h,scroll,pos)
  {
  if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
  if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
  else if((pos!="center" && pos!="random") || pos==null){LeftPosition=20;TopPosition=20}
  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
  mypwin=window.open(mypage,myname,settings);
  }
  
  
  

//*****************************************************************************
// Hide/show elements by id.

function Toggle( secid,minuspath,pluspath)
{
	var sectionId = document.getElementById(secid);
	if (sectionId == null) return;
	if (sectionId.style.display == '') 
	{
		sectionId.style.display = 'none';
		var ImgSrc = document.getElementById("i" + secid);
		ImgSrc.src = pluspath;
	}
	else
	{
		sectionId.style.display = '';
		var ImgSrc = document.getElementById("i" + secid);
		ImgSrc.src = minuspath;
	}
}

function toggleMultiple(secid_array,toggle_bulkstate,minuspath,pluspath)
{
   var preload_minus = new Image(11,11); 
   preload_minus.src=minuspath;
   var preload_plus = new Image(11,11); 
   preload_plus.src=pluspath;

  if (toggle_bulkstate=='hidden')
  {
    for (var i=0; i<secid_array.length; i++)
    {
    Show(secid_array[i],preload_minus);
    }
    return 'shown';
  }
  else
  {
    for (var i=0; i<secid_array.length; i++)
    {
    Hide(secid_array[i],preload_plus);	
    }
    return 'hidden';
  }
}

function Hide( secid, preload_plus)
{
	var oDiv = document.getElementById(secid);
	if(oDiv != null) 
	{
	  oDiv.style.display = "none";
    var ImgSrc = document.getElementById("i" + secid);
    ImgSrc.src = preload_plus.src;
    ImgSrc.style.display = "";
  }
}

function Show( secid, preload_minus)
{
	var oDiv = document.getElementById(secid);
	if(oDiv != null) 
	{
	  oDiv.style.display = "";
    var ImgSrc = document.getElementById("i" + secid);
    ImgSrc.src = preload_minus.src;
    ImgSrc.style.display = "";

  }
}




//*****************************************************************************
// Switch the browser cursor style




function cursor_tohand(myelement)
{
  if(document.all)
    curPoint = "hand";
  else
    curPoint = "pointer";
  myelement.style.cursor=curPoint;
}

function cursor_tonormal(myelement)
{
  myelement.style.cursor="auto";
}