var percentageIncrement = 6.25;
var zoomRange = 3;
var bannerHeight = "138px";
var bannerWidth = "877px";


function tabpanel_mouseover(node)
{
  var tabHolderId = node.parentNode.id;
  var tabs = document.getElementById(tabHolderId).childNodes;
  for (var x = 0; x < tabs.length; x++) {
    if (!tabs[x].id) continue;
    if (!tabs[x].id == node.id) continue;
    tabs[x].className = "";// De-Activate all other items
  }
  node.className = "tabpanel_default"; // Activate the hovered item
}

var seasonImages = 5;

function setseason() {
 var simgid =Math.floor(Math.random()*seasonImages)+1;
 var season = "";
 switch(new Date().getMonth()) {
   case 11://december
   case 0:
   case 1:
     season = "winter";
     break;
   case 2:
   case 3:
   case 4:
     season = "spring";
     break;
   case 5:
   case 6:
   case 7:
     season = "summer";
     break;
   case 8:
   case 9:
   case 10:
     season = "fall";
     break;
 }
if ((navigator.appName=="Microsoft Internet Explorer")
 && (parseFloat(navigator.appVersion)<7)) {
   var globalcss = document.styleSheets[0];
   var rules = globalcss.cssRules? globalcss.cssRules: globalcss.rules;
   for (var i=0; i<rules.length; i++){
     if(rules[i].selectorText.toLowerCase()=="div.banner"+season+simgid+"#banner"){
	 document.getElementById("banner").style.backgroundColor=rules[i].style.backgroundColor;
       break;
     }
   }
 } else {
   document.getElementById("banner").className = "banner"+season+simgid;

 }
 document.getElementById("bannerimg").src = "images/bnr/seasons/"+season+"/"+season+simgid+".jpg";
 document.getElementById("bannerimg").style.height = bannerHeight;
 document.getElementById("bannerimg").style.width = bannerWidth;
}


function setCss(newCss) {
 var i, a, main;
 for (i=0; i < document.getElementsByTagName("link").length; i++) {
	 a = document.getElementsByTagName("link")[i];
// for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
   if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("title")) {
	 var ieversion = null;
	 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	   ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
       if (ieversion<7)
         return false;
     }
//	 if(a.getAttribute("href") == "css/global.css") continue;
//     alert(a.getAttribute("href"));
//	 alert(a.getAttribute("disabled"));
     a.disabled = true;
     if(a.getAttribute("title") == newCss) a.disabled = false;
   }
 }
}

var currentZoom = 1;
function changeSize(factor) {
 if (factor > 0 && currentZoom == zoomRange) return false;
 if (factor < 0 && currentZoom == 1) return false;
 currentZoom+=factor;
 var bodyelem;
 bodyelem = document.getElementsByTagName('body')[0];
 if (bodyelem == null) {
   bodyelem = document.body;
 }
 var currentSize = bodyelem.style.fontSize;  
 if (currentSize == "") {
   var defaultPercentage;
   var globalcss = document.styleSheets[0];
   var rules = globalcss.cssRules? globalcss.cssRules: globalcss.rules;
   for (var i=0; i<rules.length; i++){
     if(rules[i].selectorText.toLowerCase()=="body"){
       defaultPercentage =rules[i].style.fontSize;
       defaultPercentage = defaultPercentage.substr(0,defaultPercentage.length-1)*1;
       break;
     } 
   }
   currentSize = (defaultPercentage+(factor*percentageIncrement))+"%";
 } else {
   currentSize = currentSize.substr(0,currentSize.length-1)*1;
   currentSize = (currentSize+(factor*percentageIncrement))+"%";
 }
 bodyelem.style.fontSize = currentSize;
 return false;
}

initNavigation = function() {

  if (document.getElementById) { // Does the browser support the getElementById method?
    navRoot = document.getElementById("nav_list"); // Get main list ul

    if (typeof defaultMainList!="undefined")
      var reMainNav = new RegExp("^" + defaultMainList + "<", "i"); // Regex for finding the index of the default main list item

    for (i=0; i<navRoot.childNodes.length; i++) { // Loop over main list items
      node = navRoot.childNodes[i];
      if (node.nodeName == "LI") {
        if ((typeof defaultMainList!="undefined") && node.firstChild.innerHTML.match(reMainNav)) { // Found default main nav item
          defaultMainListIndex = i;
        } else {

          ////// Apply onmouseover and onmouseout event handlers to each main list item //////
          node.onmouseover = function() {
            if (defaultMainListIndex != -1) // Is there a default main list item?
              navRoot.childNodes[defaultMainListIndex].className = "nav_default_off"; // De-activate it
            this.className = "mouse_over"; // Activate the hovered item
          }
          node.onmouseout = function() {
            this.className = ""; // De-activate the hovered item
            if (defaultMainListIndex != -1) // Is there a default main list item?
              navRoot.childNodes[defaultMainListIndex].className = "nav_default_on"; // Activate it
          }
        }
      }
    }

    ////// Activate the default main list item //////
    if (defaultMainListIndex != -1)
      navRoot.childNodes[defaultMainListIndex].className = "nav_default_on";
  }
}

function sfHover() {
	var sfEls = document.getElementById("iconContainer").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"), "");
		}
	}
}

function startList() {
  initNavigation();
  blockids.each(function(item, index){
	if (document.getElementById(item) != null)
    document.getElementById(item).style.display="block";
  });
  setseason();
}

function openSearchSelect() {
  var el = document.getElementById("searchOptions");
  var ulobj = document.createElement("ul");
  var liobj;
  var imgobj;
  var alto = document.getElementById("curSearchType").firstChild.firstChild.alt;
  if (alto != "Google") {
    liobj = document.createElement("li");
    liobj.id="googleSearch";
    liobj.onclick = changeSearchSelectGoogle;
    liobj.onmouseover = hoverOnGoogle;
    liobj.onmouseout = hoverOffGoogle;
    imgobj = document.createElement("img");
    imgobj.src="http://www.colorado.gov/cms/coloradogov/images/img_googleSrchUp.gif";
    imgobj.alt="Google";
    liobj.appendChild(imgobj);
    ulobj.appendChild(liobj);
  }
  if (false) {//remove when k2c is ready
  // if (alto != "Contact Compass") {
    liobj = document.createElement("li");
    liobj.id="k2cSearch";
    liobj.onclick = changeSearchSelectK2c;
    liobj.onmouseover = hoverOnK2c;
    liobj.onmouseout = hoverOffK2c;
    imgobj = document.createElement("img");
    imgobj.src="http://www.colorado.gov/cms/coloradogov/images/img_compassSrchUp.gif";
    imgobj.alt="Contact Compass";
    liobj.appendChild(imgobj);
    ulobj.appendChild(liobj);
 }
 if (alto != "State Employee Telephone Directory") {
    liobj = document.createElement("li");
    liobj.id="telephoneSearch";
    liobj.onclick = changeSearchSelectTelephone;
    liobj.onmouseover = hoverOnTelephone;
    liobj.onmouseout = hoverOffTelephone;
    imgobj = document.createElement("img");
    imgobj.src="http://www.colorado.gov/cms/coloradogov/images/img_telephoneSrchUp.gif";
    imgobj.alt="State Employee Telephone Directory";
    liobj.appendChild(imgobj);
    ulobj.appendChild(liobj);
 }



  if (document.getElementById("searchOptions").firstChild != null)
    el.replaceChild(ulobj,document.getElementById("searchOptions").firstChild);
  else
    el.appendChild(ulobj);

  el.style.left = (document.getElementById("curSearchType").offsetLeft+20)+"px";
  el.style.top = (document.getElementById("curSearchType").offsetTop+
    document.getElementById("curSearchType").offsetHeight+1)+"px";
  el.style.display="block";
}
function hoverOnGoogle() {
  document.getElementById("googleSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_googleSrchOvr.gif";
}
function hoverOffGoogle() {
  document.getElementById("googleSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_googleSrchUp.gif";
}
function changeSearchSelectGoogle() {
  if (document.getElementById("searchBar").value =="Search Contact Compass")
    document.getElementById("searchBar").value = "Search Colorado.gov";
  if (document.getElementById("searchBar").value =="Last, First")
    document.getElementById("searchBar").value = "Search Colorado.gov";
  document.getElementById("curSearchType").firstChild.firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_googleSrchUp.gif";
  document.getElementById("curSearchType").firstChild.firstChild.alt="Google";
  document.getElementById("searchBar").onfocus=function onfocus(event){
    if (this.value == "Search Colorado.gov") {this.value = "";}
  };
  document.getElementById("searchBar").onblur=function onblur(event) {
    if (this.value == "") {this.value = "Search Colorado.gov";}
  };
  closeSearchSelect();
}
function hoverOnK2c() {
  document.getElementById("k2cSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_compassSrchOvr.gif";
}
function hoverOffK2c() {
  document.getElementById("k2cSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_compassSrchUp.gif";
}
function changeSearchSelectK2c() {
  if (document.getElementById("searchBar").value =="Search Colorado.gov")
    document.getElementById("searchBar").value = "Search Contact Compass";
  if (document.getElementById("searchBar").value =="Last, First")
    document.getElementById("searchBar").value = "Search Contact Compass";
  document.getElementById("curSearchType").firstChild.firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_compassSrchUp.gif";
  document.getElementById("curSearchType").firstChild.firstChild.alt="Contact Compass";
  document.getElementById("searchBar").onfocus=function onfocus(event){
    if (this.value == "Search Contact Compass") {this.value = "";}
  };
  document.getElementById("searchBar").onblur=function onblur(event) {
    if (this.value == "") {this.value = "Search Contact Compass";}
  };
  closeSearchSelect();
}
function hoverOnTelephone() {
  document.getElementById("telephoneSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_telephoneSrchOvr.gif";
}
function hoverOffTelephone() {
  document.getElementById("telephoneSearch").firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_telephoneSrchUp.gif";
}
function changeSearchSelectTelephone() {
  if (document.getElementById("searchBar").value =="Search Colorado.gov")
    document.getElementById("searchBar").value = "Last, First";
  if (document.getElementById("searchBar").value =="Search Contact Compass")
    document.getElementById("searchBar").value = "Last, First";
  document.getElementById("curSearchType").firstChild.firstChild.src="http://www.colorado.gov/cms/coloradogov/images/img_telephoneSrchUp.gif";
  document.getElementById("curSearchType").firstChild.firstChild.alt="State Employee Telephone Directory";
  document.getElementById("searchBar").onfocus=function onfocus(event){
    if (this.value == "Last, First") {this.value = "";}
  };
  document.getElementById("searchBar").onblur=function onblur(event) {
    if (this.value == "") {this.value = "Last, First";}
  };

  closeSearchSelect();
}
function closeSearchSelect() {
  document.getElementById("searchOptions").style.display="none";
}
function performSearch() {
  switch (document.getElementById("curSearchType").firstChild.firstChild.alt) {
    case "Google":
      //alert ("g");
      return performSearchGoogle();
    case "Contact Compass":
      //alert("k");
      return false;
    case "State Employee Telephone Directory":
      //alert("t");
      performSearchTelephone();
      return false;
  }
  return false;
}
function performSearchGoogle() {
  var forma = document.getElementById("searchform");
  var inp;
  forma.action = "http://www.colorado.gov/search";
  forma.method = "GET";
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="sort";
  inp.value="date:D:L:d1";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="output";
  inp.value="xml_no_dtd";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="oe";
  inp.value="UTF-8";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="ie";
  inp.value="UTF-8";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="client";
  inp.value="CO_Test";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="proxystylesheet";
  inp.value="CO_Test";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="site";
  inp.value="CO-Test";
  forma.appendChild(inp);
  return true;
}
function performSearchK2C() {
  var forma = document.getElementById("searchform");
  var inp;
  forma.action = "http://www.colorado.gov/apps/dpa/k2c/welcome.jsf";
  forma.method = "POST";
  forma.enctype= "application/x-www-form-urlencoded";
  forma.removeChild(document.getElementById("searchBar"));
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="welcome:Keywords";
  inp.value=document.getElementById("searchBar").value;
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="welcome_SUBMIT";
  inp.value="1";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="welcome:_idcl";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="welcome:_idcl";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="welcome:_link_hidden_";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="javax.faces.ViewState";
  inp.value="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAE5cHQADC93ZWxjb21lLmpzcA==";
  forma.appendChild(inp);
  return true;
}
function performSearchTelephone() {
  var forma = document.getElementById("searchform");
  var inp;
  var names = document.getElementById("searchBar").value.split(',');
  var lastname = names[0];
  var firstname = "";
  for (var i=1;i< names.length;i++) {
    firstname += names[i];
  }
 
  forma.action = "http://www.state.co.us/test9/telemp/Telemp_Result.cfm";
  forma.method = "POST";

  //forma.removeChild(document.getElementById("searchBar"));
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit1_Value";
  inp.value=lastname;
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit2_Value";
  inp.value=firstname;
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit1_FieldName";
  inp.value="Telemp.lastname";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit1_FieldType";
  inp.value="CHAR";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit1_Operator";
  inp.value="BEGINS_WITH";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit2_FieldName";
  inp.value="Telemp.firstname";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit2_FieldType";
  inp.value="CHAR";
  forma.appendChild(inp);
  inp = document.createElement("input");
  inp.type="hidden";
  inp.name="Crit2_Operator";
  inp.value="BEGINS_WITH";
  forma.appendChild(inp);
  return true;
}
var defaultMainListIndex = -1; // Integer, index of the default main list item




