/*
 * toggleClassName
 * this script toggles the CSS class name of an element between two parameters
 */
 
var arrMenu = new Array();
var intPrevLevel;

function MenuLoad(Level) {
    var intBuff;
    var arrSplit;
    var strH = 'h';
    var strI = 'id';
    var strC = 'cbtn';
    var intBuff;
    var strBuff = '';
    var intL = 0;
    var strPre = '';
        
       
    for (intL = 0; intL < Level; intL++)
    {
        strPre = strPre + '../';
    }
    
   /*  
    MM_preloadImages("'" + strPre + "Images/Buttons/bBlueArrow01.gif'","'" + strPre + "'Images/Buttons/bBlueArrow02.gif'","'" + strPre + "'Images/Buttons/bBlueArrow03.gif'","'" + strPre + "'Images/Buttons/bBlueArrowExp01.gif'","'" + strPre + "'Images/Buttons/bBlueArrowExp02.gif'","'" + strPre + "'Images/Buttons/bBlueLeft.gif'","'" + strPre + "'Images/Buttons/bBlueRight.gif'","'" + strPre + "'Images/Buttons/bWhiteArrow01.gif'", "'" + strPre + "'Images/Buttons/bWhiteArrow02.gif'", "'" + strPre + "'Images/Buttons/bWhiteArrow03.gif'", "'" + strPre + "'Images/Buttons/b_more02.gif'");
   */     
    
    if (document.layers) {
        intBuff = document.layers['ctl00$ucMenu01$hidMenu'].value;
    }
    if (document.getElementById) {
        intBuff = document.getElementById('ctl00$ucMenu01$hidMenu').value;
    }
    
    arrSplit = intBuff.split("_");
    
    // Passing paramenters to the hidden object from vb
    if (intBuff != -1)
    {
        
        //intPrevLevel = intBuff - 1;
        for (i = 0; i < arrSplit.length; i++)
        {
           intBuff = i + 1;
           strBuff = intBuff+'';
           strBuff = padLeft(strBuff, '0', 2);
           //alert('strBuff ' + strBuff); 
           intPrevLevel = arrSplit.length - 1;
           
           strH = strH + arrSplit[i];
           strI = strI + arrSplit[i]; 
           strC = 'cbtn' + strBuff;
           
           //alert(strH);
           //alert(strI);
           //alert(strC);
           
           arrMenu[i] = {
	           LevelCount:  0,
	           H:      strH,
	           I:      strI,
	           C:      strC
	       };
	       
	       strH = strH + "_";
	       strI = strI + "_";
        }
    }
}

function padLeft(str, pad, count) {
    while(str.length<count)
    str=pad+str;
    return str;
}


function toggleClassName(menu_ref, mClass_state1, mClass_state2, element_ref, class_state1, class_state2) {
	var i = 0;
	var strLevel;
	var intLevel;
	var strHiding;
	var intTo;
	

	// Code is for controlling the menu that will expand
	if (document.layers) { //IS NETSCAPE 4 or below
		mState = document.layers[menu_ref].className;
	}
	if (document.getElementById) {
		mHza = document.getElementById(menu_ref);
		mState = mHza.className;
	}
	//swap state
	if (mState == mClass_state1 || mState == '') {
		mState = mClass_state2;
	}
	else {
		mState = mClass_state1;
	}
	
	//update new state
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[element_ref].className = mState;
	}
	if (document.getElementById) {
		mHza = document.getElementById(menu_ref);
		mHza.className = mState;
	}
	//reset state
	mState = mClass_state1;
	
	

	// check current state - Code is for controlling the expanding part
	if (document.layers) { //IS NETSCAPE 4 or below
		state = document.layers[element_ref].className;
		strHiding = state;
	}
	if (document.getElementById) {
		hza = document.getElementById(element_ref);
		state = hza.className;
		strHiding = state;
	}
	//swap state
	if (state == class_state1 || state == '') {
		state = class_state2;
	}
	else {
		state = class_state1;
	}
	
	//update new state
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[element_ref].className = state;
	}
	if (document.getElementById) {
		hza = document.getElementById(element_ref);
		hza.className = state;
	}
	//reset state
	state = class_state1;
		
		
		
    // This code will store the current menu level values.
    // When another menu item is clicked at the same level, use these values to close the one expanded.
    // Level is determined by the length of the menu_ref
    intLevel = menu_ref.length / 3;    
    

	if (!arrMenu[intLevel - 1])
	{
	    arrMenu[intLevel - 1] = {
	        LevelCount:  0,
	        H:      menu_ref,
	        I:      element_ref,
	        C:      mClass_state1
	    };
	}
	else
	{
        arrMenu[intLevel - 1].LevelCount = arrMenu[intLevel - 1].LevelCount + 1;        
	}
	
	
	if (intLevel < intPrevLevel)
	{
	    //alert("1");
	    // Item clicked a lower level
	    // Remove all sub levels
	    	    
	    // If menu level click is the parent, don't close because it already did
	    if (arrMenu[intLevel - 1].I != element_ref)
	    {
	        intTo = intLevel;
	    }
	    else
	    {
	        intTo = intLevel + 1;
	    }

	    for (i = intPrevLevel; i >= intTo; i--)
	    {
	        // Close Sub Level
	        hza = document.getElementById(arrMenu[i - 1].I);
		    
		    hza.className = 'hideMenu';
		
		    mhza = document.getElementById(arrMenu[i - 1].H);
		    mhza.className = arrMenu[i - 1].C;
	        
	        arrMenu[i - 1].LevelCount = -1;
	    }
	    
	    
	        
		// Assign new
		arrMenu[intLevel - 1] = {
	        LevelCount:  0,
	        H:      menu_ref,
	        I:      element_ref,
	        C:      mClass_state1
	    };
	    
	}
	
	else if (intLevel > intPrevLevel)
	{
	    //alert("2");
	    arrMenu[intLevel - 1] = {
	        LevelCount:  0,
	        H:      menu_ref,
	        I:      element_ref,
	        C:      mClass_state1
	    };
	}
	
	else if (arrMenu[intLevel - 1].LevelCount > 0 && strHiding == 'hideMenu' && arrMenu[intLevel - 1].I == element_ref)
	{
	    // Dummy one to catch
	    //alert("3");
	    //alert(arrMenu[intLevel - 1].LevelCount);
	}

	else if (arrMenu[intLevel - 1].LevelCount > 0 && strHiding == 'hideMenu')
	{	
	    //alert("4");
	    // Another menu item clicked at same level, close the current level 
	    hza = document.getElementById(arrMenu[intLevel - 1].I);
		hza.className = 'hideMenu';
		
		mhza = document.getElementById(arrMenu[intLevel - 1].H);
		mhza.className = arrMenu[intLevel - 1].C;
		
		arrMenu[intLevel - 1] = {
	        LevelCount:  0,
	        H:      menu_ref,
	        I:      element_ref,
	        C:      mClass_state1
	    };
	    
	}
	else if (arrMenu[intLevel - 1].LevelCount > 0 && strHiding == 'showMenu')
	{
	    //alert("5");
	    // this code resets if someone closes a level
	    arrMenu[intLevel - 1].LevelCount = -1;
	}
	else
	{
	    arrMenu[intLevel - 1] = {
	        LevelCount:  0,
	        H:      menu_ref,
	        I:      element_ref,
	        C:      mClass_state1
	    };
	}
	
    intPrevLevel = intLevel;
    
    //alert(arrMenu[intLevel - 1].LevelCount);
    //alert(arrMenu[intLevel - 1].H);
    //alert(arrMenu[intLevel - 1].I);
    //alert(arrMenu[intLevel - 1].C);
}
