//// *********************************** ////
//// State of California master template ////
////             Version 1.20            ////
////       Last Updated 03/23/2007       ////
////                                     ////
//// Add your own Department-specific    ////
//// scripts here.                       ////
//// *********************************** ////

// selectSearch - If you are not using DTS site search you may delete lines 10-to-25
// Choose between the statewide search and your own local site search.
//

var ca_agency="ca_cccco";

function getGoogleSearch() {
	var url='http://search.ca.gov/search?q='+  document.getElementById("search").value +'&output=xml_no_dtd&site=ca_calohi&client=ca_calohi&proxystylesheet='+ca_agency;
	window.location.href=url;
}

function selectSearch() { 
	if (document.getElementById("control").which[0].checked) {
	  document.getElementById("ca_form").q.value = document.getElementById("search").value;
	  document.getElementById("ca_form").submit();
	} else {
		// Change the 'q' to the parameter your search engine uses for its text field
	  document.getElementById("local_form").q.value = document.getElementById("search").value;
	  document.getElementById("local_form").submit();
	}
  return false;
}
var defaultMainList = "Home";

function setNavLoaded(txt){
	defaultMainList = txt;
		if (typeof defaultMainList!="undefined")
			var reMainNav = new RegExp("^" + txt + "<", "i"); // Regex for finding the index of the default main list item

	var navRoot = document.getElementById("nav_list"); // Get main list ul
		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;
					navRoot.childNodes[defaultMainListIndex].className = "nav_default_on"; // Activate it
					try {
						var _li =node.getElementsByTagName("li")
						for (x=0; x<_li.length; x++){
							if (! _li[x].id.match("mssg"))
								_li[x].style.display="none";
							else
								_li[x].style.display="block";
						}
					} catch (err) { ; }
					
				} else {
					try {
						var _li =node.getElementsByTagName("li")
						for (x=0; x<_li.length; x++){
							if (_li[x].id.match("mssg"))
								_li[x].style.display="none";
							else
								_li[x].style.display="block";
						}
					} catch (err) { ; }
				}
			}
		}
}

dnnSearchLabel = function () {
	var DNNSearch = document.getElementById("dnn_dnnSEARCH_txtSearch");
	var text = ' Internal Search';
	var ApplianceSearch = document.getElementById("search");

	if (DNNSearch != undefined){
		DNNSearch.value = text;

		DNNSearch.onmouseover = function () {
			if(this.value==text)this.value='';
		};

		DNNSearch.onmouseout= function () {
			if(this.value=='')this.value=text;
		};
	} else if (ApplianceSearch != undefined){
		text = ' Google Search';

		ApplianceSearch.value = text;

		ApplianceSearch.onmouseover = function () {
			if(this.value==text)this.value='';
		};

		ApplianceSearch.onmouseout= function () {
			if(this.value=='')this.value=text;
		};
	}

}

/* Styles Tabbed content - Will only handle one per page */
styleTabbed = function () {
	var tabbedContainers = document.getElementById("tabbed_container");
	var _tab_list;
	var is_netscape = false;
	if (navigator.appName == "Netscape")
		is_netscape = true;


	if (tabbedContainers != null){
		var tabCont = tabbedContainers;
		//alert(tabCont.innerHTML);
		//alert(tabCont.getElementsByTagName('div').length);
		var DIVs = tabCont.getElementsByTagName('div');
		DIVs[1].id = "tabpanel";
		var tabpanelDIV = DIVs[1];
		var max_height = 50;
		a=3;
		DIVs[a].className = "";
		DIVs[a].id = "tab_list";
		var divCont=DIVs[a];
		var ULs=divCont.getElementsByTagName('ul');
		ULs[0].id = "tab_ul";
		_tab_list = ULs[0].id;
		var list = ULs[0].childNodes;
		var aa=1;
		for (l=0; l < list.length; l++){
			if (list[l].tagName != undefined && list[l].tagName.toLowerCase() == "li" ){
				var this_o = list[l];
				var anch;
				if (this_o.childNodes[0].nodeType == 3 ) {
					// Creating the node when no link is provided
					var child = this_o.childNodes[0];
					var node_content = "" + this_o.innerHTML;
					var reg_exp = new RegExp(child.nodeValue, '');
					this_o.innerHTML = node_content.replace(reg_exp,"<a href='#' class='tab_link'>"+child.nodeValue+"</a>");
				} else if (this_o.getElementsByTagName('a').length > 0){
					anch = this_o.getElementsByTagName('a')[0];
					anch.className="tab_link";
				}
				// Adding runtime actions
				list[l].onmouseover = function () {
					tabpanel_mouseover(this);
				};
				list[l].onmouseout = function () {
					tabpanel_mouseout(this);
				};

				var _li_list = this_o.getElementsByTagName('li');
				var _ul_ = this_o.getElementsByTagName('ul')[0];

				_ul_.className="list_decorative_dark";
				_ul_.id="tabpanel_"+aa+"_sublist";
				list[l].id = "tabpanel_"+aa;
				if (aa == 1 && list[l].tagName.toLowerCase() == "li")
					list[l].className = "tabpanel_default";

				var As = _li_list[_li_list.length-1].getElementsByTagName('a');
				if (As.length == 0 ){
					_li_list[_li_list.length-1].style.background="none";
					_li_list[_li_list.length-1].style.margin="6px";
					_li_list[_li_list.length-1].style.width="98%";
					_li_list[_li_list.length-1].style.padding="0px";
					_li_list[_li_list.length-1].style.border="none";
				}
/*
				if (_li_list[_li_list.length-1].childNodes[0].nodeType == 3){
					_li_list[_li_list.length-1].className="special_p";
				}
*/


				_li_list[_li_list.length-1].innerHTML = _li_list[_li_list.length-1].innerHTML + "<span class='bottom_right'></span><span class='bottom_left'></span>";

				if(_ul_.offsetHeight > max_height){
					max_height = _ul_.offsetHeight;
				}
				for (ll=0; ll < _li_list.length; ll++){
					if(_li_list[ll].offsetHeight > max_height){
						max_height = _li_list[ll].offsetHeight;
					}
				}

				aa=aa+1;
			}
		}

		// Processing image container
		var image_cont = document.getElementById("image_container");

		var IMG_width = 0;
		try {
		var IMGs=divCont.getElementsByTagName('img');
		if (IMGs != null && IMGs.length == 0){
			if (image_cont != null)
				image_cont.style.visibility = "hidden";
		} else if (image_cont == null ){
			var pappa = IMGs[0].parentNode;
			for (i=0; i < IMGs.length; i++){
				IMGs[i].style.visibility="hidden";
				pappa.removeChild(IMGs[i]);
			}
		} else {
			if (IMGs.length == 0 ) {
				image_cont.style.visibility = "hidden";
			} else {
				var src = IMGs[0].src;
				var alt = IMGs[0].alt;
				var w = IMGs[0].width;
				var h = IMGs[0].height;
				var pappa = IMGs[0].parentNode;
				for (i=0; i < IMGs.length; i++){
					IMGs[i].style.visibility="hidden";
					pappa.removeChild(IMGs[i]);
				}
				image_cont.innerHTML = "<img src='"+src+"' height='"+h+"' width='"+w+"' alt='"+alt+"' id='tbbd_image'>";
				if (!is_netscape)
					image_cont.style.width=(w+16)+"px";
				else
					image_cont.style.width=(w)+"px";
				image_cont.style.height=(h+20)+"px";
				var tbbd_image = document.getElementById("tbbd_image");
				if (tbbd_image != undefined){
					tbbd_image.style.width = w;
					tbbd_image.style.height = h;
				}
				IMG_width = w;
				if(h > max_height){
					max_height = h;
				}
			}

			image_cont.height=(max_height*2+60)+"px";
		}
		} catch (e) {; }

		// Setting height and width properties for tabbed environment
		tabbedContainers.style.height=((max_height*1.15)+60)+"px";
		
		var panel_1_width = 0;
		if (document.getElementById("tabbed_container").offsetWidth){
			if (IMG_width != 0)
				panel_1_width =document.getElementById("tabbed_container").offsetWidth - IMG_width-30; 
			else
				panel_1_width = document.getElementById("tabbed_container").offsetWidth; 
		}

		tabpanelDIV.style.width=(panel_1_width+10)+"px"; 

		var mult = 1.1;
		if (is_netscape)
			mult=1;
		var ULs=tabbedContainers.getElementsByTagName('ul');
		if (ULs != null)
		for (u=0;u < ULs.length; u++){
			var _ULs_=ULs[u].getElementsByTagName('ul');
			for (uu=0;uu < _ULs_.length; uu++){
					_ULs_[uu].style.height=""+(max_height*mult)+"px";
			}
		}
		if (document.getElementById("tabpanel_1_sublist"))
 		document.getElementById("tabpanel_1_sublist").style.width = (document.getElementById("tabbed_container").offsetWidth -IMG_width-46) + "px"; // Needed for IE
		if (is_netscape)
			document.getElementById("tab_list").style.left= (IMG_width+18)+"px";

/*
	var pappa = document.getElementById("tab_list").parentNode;
	var tabList_html = pappa.innerHTML;
	pappa.parentNode.innerHTML=tabList_html;*/
	/* Copy to clipboard to check dynamic generated content*/
/*
	if (window.clipboardData)
		window.clipboardData.setData("Text",tabCont.innerHTML);

	if (window.clipboardData)
		window.clipboardData.setData("Text",tabCont.innerHTML);
*/

	window.onresize = function () {
 		document.getElementById("tabpanel_1_sublist").style.width = (document.getElementById("tabbed_container").offsetWidth -IMG_width-46) + "px"; // Needed for IE
		if (is_netscape)
			document.getElementById("tab_list").style.left= (IMG_width+18)+"px";
		
	};

	}
}

addLoadEvent(dnnSearchLabel);
addLoadEvent(styleTabbed);

/////////////////////////
//// tabpanel_module ////
/////////////////////////


//// tabpanel_mouseover
//// This function is called when a tabpanel tab is hovered

function tabpanel_mouseover(node)
{
  var panel_1_width = document.getElementById("tabpanel_1_sublist").offsetWidth; // Needed for IE
  document.getElementById("tabpanel_1").className = ""; // De-activate default item
  node.className = "tabpanel_default"; // Activate the hovered item
  if (panel_1_width) {
    if (document.getElementById("tabpanel_2_sublist"))
      document.getElementById("tabpanel_2_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_3_sublist"))
      document.getElementById("tabpanel_3_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_4_sublist"))
      document.getElementById("tabpanel_4_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_5_sublist"))
      document.getElementById("tabpanel_5_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_6_sublist"))
      document.getElementById("tabpanel_6_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_7_sublist"))
      document.getElementById("tabpanel_7_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_8_sublist"))
      document.getElementById("tabpanel_8_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_9_sublist"))
      document.getElementById("tabpanel_9_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_10_sublist"))
      document.getElementById("tabpanel_10_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_11_sublist"))
      document.getElementById("tabpanel_11_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_12_sublist"))
      document.getElementById("tabpanel_12_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
    if (document.getElementById("tabpanel_13_sublist"))
      document.getElementById("tabpanel_13_sublist").style.width = (panel_1_width - 2) + "px"; // Needed for IE
  }
}

//// tabpanel_mouseout
//// This function is called on mouseout

function tabpanel_mouseout(node)
{
  node.className = ""; // De-activate this item
  document.getElementById("tabpanel_1").className = "tabpanel_default"; // Activate default item
}

// End of tabpanel_module javascript
