// JavaScript for opening external links in XHTML document
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var isMSIE=/*@cc_on!@*/false; //http://dean.edwards.name/weblog/2007/03/sniff/
  if(!isMSIE){
    var newElm=document.createElement('input');
    newElm.type=iType;
  } else {
    var newElm=document.createElement('span');
    newElm.innerHTML='<input type="'+iType+'" name="'+oldElm.name+'">';
    newElm=newElm.firstChild;
  }
  var props=['name','id','className','size','tabIndex','accessKey'];
  for(var i=0,l=props.length;i<l;i++){
    if(oldElm[props[i]]) newElm[props[i]]=oldElm[props[i]];
  }
  newElm.onfocus=function(){return function(){
    if(this.hasFocus) return;
    var newElm=changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur=function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  // some browsers need the value set before the element is added to the page
  // while others need it set after
  if(!blankValue) newElm.value=iValue;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!isMSIE && !blankValue) newElm.value=iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm=newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

/*
LoadHandler.add(function(){
  var ua=navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && /khtml\/3\.[0-4]/.test(ua)) && 
    !(((ua.indexOf('safari')!=-1) && !window.print))) {

      // Set the third value to the text you want to appear in the field.
      changeInputType(document.forms[0].field2,'text','password',false,true);
  }
});*/

function showHideProgramLocal(itemID, thisItem){
	var itemContainer = document.getElementById(itemID);
	var itemBkg = thisItem;
	
	if(itemContainer.style.display == 'none'){
		itemContainer.style.display = 'block';
		itemBkg.style.backgroundImage = 'url(/images/bkg-CollapseItem.png)';
	}
	else {
		itemContainer.style.display = 'none';
		itemBkg.style.backgroundImage = 'url(/images/bkg-ExpandItem.png)';
	}
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function zebraStripListItems() {
 if (!document.getElementsByTagName) return;
 var listItems = document.getElementsByTagName("span");
 for (var i=0; i<listItems.length; i++) {
   var thislistItem = listItems[i];
   if (thislistItem.className == "zebraOn"){
     //alert(thislistItem.innerHTML)
	 var oContent = thislistItem.innerHTML;	
	 thislistItem.innerHTML = "<span class='top'><span class='bottom'>"+oContent+"</span></span>";
   }
 }
}


// JavaScript for suckerfish drop-downs <http://www.htmldog.com/articles/suckerfish/>
sfHover = function() {
	var sfEls = document.getElementById("navMain").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("sfhover\\b"), "");
		}
	}
}

// JavaScript for loading above functions into the page
var PageInitializer = {
    start : function(){
        PageInitializer.addLoadEvent(function(){
            //Add Functions Here
			externalLinks();
			sfHover();
			zebraStripListItems();
			
			
			var ua=navigator.userAgent.toLowerCase();
		  if(!((ua.indexOf('konqueror')!=-1) && /khtml\/3\.[0-4]/.test(ua)) && 
			!(((ua.indexOf('safari')!=-1) && !window.print))) {
		
			  // Set the third value to the text you want to appear in the field.
			  changeInputType(document.getElementById('siteLoginPass'),'text','Password',false,true);
		  }
        });
    },
    addLoadEvent:function(f){var w=window;var o=w.onload;if(typeof w.onload!='function'){w.onload=f;}else{w.onload=function(){o();f();}}}
}
PageInitializer.start();
