//// *********************************** ////
//// State of California master template ////
////             Version 1.20            ////
////       Last Updated 03/23/2007       ////
//// *********************************** ////


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
              var reMainNav = defaultMainList;
		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;
				if (node.id == reMainNav){
				    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";

		////// If the search form has radio buttons, make them visible //////
		radioContainer = document.getElementById("radio_container");
		if (radioContainer) {
			//Comment the following line to always hide the radio buttons
			radioContainer.style.display = "inline";
		}
	}
}
// addLoadEvent by Simon Willison
// Adds a handler to an event without over-riding other handlers

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

var defaultMainListIndex = -1; // Initialize the index of the default main list item

addLoadEvent(initNavigation); // Add initNavigation to the page onload event handler
addLoadEvent(set800pxStyle); // Add initNavigation to the page onload event handler
window.onresize = set800pxStyle;

   /*Justin added, testing show/hide subnav*/
addLoadEvent(subNavDisplay);
///////////////////////////////////
//////// OPA scripts //////////////
///////////////////////////////////

function set800pxStyle()
{

    //if screen size is 800px, set width of #content to 53% 
    //set height of buckets to the max height of the three buckets 
    //set width of bottom_homepage_box_container_header to width of bucket
    var elContent = document.getElementById("content")
    var rightCol = document.getElementById("rightcol")
    var col1 = document.getElementById("col1")
    var col2 = document.getElementById("col2")
    var col3 = document.getElementById("col3");
    var col1Header= document.getElementById("col1Header");;
    var col2Header= document.getElementById("col2Header");;
    var col3Header= document.getElementById("col3Header");;
    var resolution = screen.width;
    var bucketWrapper = document.getElementById("bucketWrapper");
    var navMainFillin = document.getElementById("navMainFillin");
    
    if(navigator.appName.toLowerCase().indexOf('microsoft')==-1)
        if(navMainFillin!=null)
            navMainFillin.style.height="67px";
    
        
    if(resolution<=800 || getWindowWidth()<800)
    {
        if(elContent !=null)
        {
           // elContent.style.width="48%"; 
        }
    }
    else
    {   var contentW =0;
        if(elContent!=null)
        {     
        
            contentW = parseInt(((getWindowWidth()-367)/getWindowWidth())*100-.5) ;
            
            //contentW = parseInt((getWindowWidth()-367)/12) ;
           // alert(contentW + " " + getWindowWidth())
           // elContent.style.width=contentW+"%";    
             
        }
        
    } 
    
       
        if( col1 != null && col2!=null && col3 !=null && bucketWrapper!=null && rightCol!=null)
        {
            var maxHeight=0;
            var divOneEm = document.getElementById("divOneEm");
            var emToPx = 12.8;
            if(divOneEm !=null)
                emToPx = divOneEm.offsetHeight;
   
            if(col1Header!=null &&col2Header!=null && col3Header!=null )
            {
                

               
                //set bucket yellow header to match longest height  
                col1Header.style.height="";
                col2Header.style.height="";
                col3Header.style.height="";
                
                maxHeight=col1Header.offsetHeight;                
                if(maxHeight < col2Header.offsetHeight)
                    maxHeight = col2Header.offsetHeight;
                if(maxHeight < col3Header.offsetHeight)
                    maxHeight = col3Header.offsetHeight;
                    
               //alert(col1Header.offsetHeight + " " +col2Header.offsetHeight + " " +col3Header.offsetHeight + " "+ maxHeight)
                maxHeight = (maxHeight-1)/emToPx;
                    col1Header.style.height=  maxHeight+"em";
                    col2Header.style.height=  maxHeight+"em";
                    col3Header.style.height=  maxHeight+"em";
                //    alert(maxHeight+"em")
           }   
           
           
            col1.style.height = "100%";
            col2.style.height = "100%";
            col3.style.height = "100%";
            bucketWrapper.style.height = "100%";
            
                        
            //set bucket's height to match the longest one
            maxHeight = col1.offsetHeight; 
            if(maxHeight < col2.offsetHeight)
                maxHeight = col2.offsetHeight;
            if(maxHeight < col3.offsetHeight)
                maxHeight = col3.offsetHeight;
                
            // alert(maxHeight+"px" + " " +col1.offsetHeight + " " + col2.offsetHeight + " " + col3.offsetHeight);
            maxHeight=Math.ceil((maxHeight-2)/emToPx);
               
            if(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
               maxHeight+=2;
            col1.style.height = maxHeight +"em";
            col2.style.height = maxHeight +"em";
            col3.style.height = maxHeight +"em";
            bucketWrapper.style.height = maxHeight +2 +"em";
           
            //alert(rightCol.offsetHeight + " "+elContent.offsetHeight);

           // alert(col3.style.height + " "+col2.style.height + " "+col1.style.height +" " +maxHeight + " "+emToPx + " " +((maxHeight+2)*emToPx));
            if(rightCol.offsetHeight>elContent.offsetHeight)
            {
                var col_height=Math.ceil((rightCol.offsetHeight-2)/emToPx);
                var diff = col_height +1.5 - Math.ceil((elContent.offsetHeight-2)/emToPx); 

               var bucketHeight = Math.ceil((bucketWrapper.offsetHeight-2)/emToPx);
                //elContent.style.height = Math.ceil(col_height)+1.5 +"em";
                col1.style.height = bucketHeight+ diff-1 +"em";
                col2.style.height = bucketHeight+ diff-1 +"em";
                col3.style.height = bucketHeight+diff-1 +"em";
                bucketWrapper.style.height = bucketHeight+ diff  +"em";
            }
        }
     
    
}

function getWindowWidth()
{
    var winW=0;
    if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE
    winW = window.innerWidth;

    } 
    else if( document.documentElement.clientWidth ) {

    //IE 6+ in 'standards compliant mode'
    winW = document.documentElement.clientWidth;

    } 
    else if( document.body.clientWidth) {

    //IE 4 compatible
    winW = document.body.clientWidth;

    }
    return winW;   
}

function subNavDisplay()
{
var subNavArr = new Array(); //for subNav urls
var leftColumn = document.getElementById ("left_column_nav_1_ul")
var curURL = document.URL.toLowerCase();
var curDiv = ""

if (curURL.indexOf("health-plan")>0){
   
    subNavArr[0] = "plan-types.aspx";
    subNavArr[1] = "what-is-hmo.aspx";
    subNavArr[2] = "what-is-ppo.aspx";
    subNavArr[3] = "group-coverage.aspx";
    subNavArr[4] = "individual-coverage.aspx";

    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {    
          curDiv = document.getElementById ("divPlanTypes")
          curDiv.style.display = "block";
        }
    }    
    subNavArr.length = 0;
    
    subNavArr[0] = "pay-for-health-care.aspx";
    subNavArr[1] = "hmo-costs.aspx";
    subNavArr[2] = "ppo-costs.aspx";
    subNavArr[3] = "what-services-cost.aspx";
    subNavArr[4] = "prescription-costs.aspx";
    subNavArr[5] = "national-costs.aspx";
    subNavArr[6] = "spend-wisely.aspx";
    subNavArr[7] = "health-care-costs.aspx";

    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {
          curDiv = document.getElementById ("divHCCosts")
          curDiv.style.display = "block";
        }
    }    
    subNavArr.length = 0;
    
    subNavArr[0] = "check-choices.aspx";
    subNavArr[1] = "compare-costs.aspx";
    subNavArr[2] = "compare-benefits.aspx";
    subNavArr[3] = "compare-quality.aspx";
    subNavArr[4] = "select-a-plan.aspx";
    subNavArr[5] = "right-plan.aspx";
                   
    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {
          curDiv = document.getElementById ("divRightPlan")
          curDiv.style.display = "block";
        }
    }    
    subNavArr.length = 0;
         
}
else if (curURL.indexOf("use-plan")>0){
    subNavArr[0] = "choosing-pcp.aspx";
    subNavArr[1] = "communicating-doctor.aspx";
    subNavArr[2] = "choosing-treatments.aspx";
    subNavArr[3] = "referrals.aspx";
    subNavArr[4] = "second-opinion.aspx";
    subNavArr[5] = "language-assistance.aspx";
    subNavArr[6] = "disability-assistance.aspx";
    subNavArr[7] = "doctor.aspx";
    

    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {    
          curDiv = document.getElementById ("divYouDoctor")
          curDiv.style.display = "block";
        }
    }    
    subNavArr.length = 0;
    
    subNavArr[0] = "preventive-care.aspx";
    subNavArr[1] = "prescription-drugs.aspx";
    subNavArr[2] = "medicine-safety.aspx";
    subNavArr[3] = "see-specialist.aspx";
    subNavArr[4] = "get-emergency-care.aspx";
    subNavArr[5] = "going-to-hospital.aspx";
    subNavArr[6] = "get-supplies.aspx";
    subNavArr[7] = "find-mental-care.aspx";
    subNavArr[8] = "home-care.aspx";
    subNavArr[9] = "hospice-care.aspx";
    subNavArr[10] = "using-services.aspx";    

    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {    
          curDiv = document.getElementById ("divUsingService")
          curDiv.style.display = "block";
        }
    }  
      
    subNavArr.length = 0;
    
    subNavArr[0] = "what-is-a-phr.aspx";
    subNavArr[1] = "why-get-a-phr.aspx";
    subNavArr[2] = "phr-setup.aspx";
    subNavArr[3] = "phrs-for-me.aspx";
    
     for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {    
        
          curDiv = document.getElementById ("divWhatIsPHR")
          curDiv.style.display = "block";
        }
      } 
    
    subNavArr.length = 0; 
    
    } 
    else if (curURL.indexOf("problems")>0){
        subNavArr[0] = "file-complaint.aspx";
        subNavArr[1] = "hmo-complaints.aspx";
        subNavArr[2] = "ppo-complaints.aspx";
        subNavArr[3] = "medi-cal-complaints.aspx";
        subNavArr[4] = "medicare-complaints.aspx";
        
        for(var i =0;i<subNavArr.length;i++){
            if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
            {   
                curDiv = document.getElementById ("divComplaints")
                curDiv.style.display = "block";
            }
        }
        subNavArr.length = 0;
    } 
    else if (curURL.indexOf("people-like-you")>0){
        subNavArr[0] = "making-decisions.aspx";
        subNavArr[1] = "choosing-treatments.aspx";
        subNavArr[2] = "choosing-a-plan.aspx";
        subNavArr[3] = "keeping-coverage.aspx";
        subNavArr[4] = "changing-plans.aspx";
        
        for(var i =0;i<subNavArr.length;i++){
            if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
            {   
                curDiv = document.getElementById ("divDecisions")
                curDiv.style.display = "block";
            }
        }
    
    subNavArr.length = 0;
    
    subNavArr[0] = "choosing-providers.aspx";
    subNavArr[1] = "choosing-pcp.aspx";
    
    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {   
            curDiv = document.getElementById ("divProviders")
            curDiv.style.display = "block";
        }
    }
    
    subNavArr.length = 0;
    
    subNavArr[0] = "getting-care.aspx";
    subNavArr[1] = "speaking-up.aspx";
    subNavArr[2] = "changing-medicine.aspx";
    subNavArr[3] = "getting-care-away.aspx";
    subNavArr[4] = "getting-supplies.aspx";
    subNavArr[5] = "getting-equipment.aspx";
    subNavArr[6] = "discharge-planning.aspx";
    subNavArr[7] = "hospice-care.aspx";
    subNavArr[8] = "filing-complaint.aspx";
    
    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {   
            curDiv = document.getElementById ("divGetCare")
            curDiv.style.display = "block";
        }
    }
    
    subNavArr.length = 0;
    
    subNavArr[0] = "managing-costs.aspx";
    subNavArr[1] = "flex-spend.aspx";
    subNavArr[2] = "yearly-deductible.aspx";
    
    for(var i =0;i<subNavArr.length;i++){
        if(curURL.lastIndexOf(subNavArr[i].toString())>=0)
        {   
            curDiv = document.getElementById ("divManageCost")
            curDiv.style.display = "block";
        }
    }
    
    subNavArr.length = 0;
} 
else if (curURL.indexOf("resources")>0){
curDiv = document.getElementById ("divPlanTypes")
} 


}
  


