/* COPYRIGHT INFORMATION All pages within a SITE are the property of DTE Energy or its Affiliate, unless other ownership is 
indicated. All information and content including any software programs available on or through a SITE is protected by copyright. A 
user is permitted to download information from a SITE which, by its nature or context, is to be copied in order to use SITE-related 
services. A user is permitted to download information from a SITE for private personal use. A user is prohibited from modifying, copying, 
distributing, transmitting, displaying, publishing, selling, licensing, creating derivative works or using any Content available on or 
through a SITE for any commercial or public purpose unless the user has the prior written permission of DTE Energy or its Affiliate. 
*/

// reference variables used inside this script
var refDTEu = "http://www.dteenergy.com";

//Find which page the user is on and identify the corresponding unique ID in menu.js 
//winLocation = location.pathname;
winLocation = window.document.URL.toString();

//alert(winLocation);
//Re-write above variable to string so we can compare to items in menu.js (not sure why we must do this, but it only works this way)
var windowLocation = "";
for(var f=0; f < winLocation.length; f++){
	windowLocation = windowLocation+winLocation.charAt(f);
}
//End re-write

//If the document path does not include a document name assume it is index.html
var winLength=winLocation.length-1;
if(windowLocation.charAt(winLength)=="/"){
	windowLocation = windowLocation+"index.html";
}
//End index.html assumption
//alert(windowLocation);
//Locate document in menu.js and identify corresponding unique ID
menuLocation=-1;
//alert(windowLocation);
for(var b=0; b < localNav.length; b++){
	var tmpLocalNav = localNav[b].split('|');
	
  //find row in menu.js table that matches page
  tmpNbr = windowLocation.indexOf(tmpLocalNav[2]);
  //alert(b+" : "+tmpLocalNav[2]+", "+tmpNbr);
	if((windowLocation.indexOf(tmpLocalNav[2])!=-1)){
		windowLocation = tmpLocalNav[0];
		menuLocation = b;
    //alert("found");
		//current locations unique ID is now windowLocation
	}
}
//End document location

//If unique ID is multi-tier, convert to array for future use
var menuStyle = windowLocation.split('_');
var parentMenu = menuStyle[0];
for(var b=1; b < menuStyle.length-1; b++){
	parentMenu += "_" + menuStyle[b];
}
var menuNumber = menuStyle[0];
var menuTier = menuStyle.length;

//Create and display the menu
function makeLeftNav(){
	document.write('<ul id=\"leftNav\">');
	var prevLevel = 1;
  var prevLinkCreated = 0;
  for(var y=0; y < localNav.length; y++){
    var tmpLocalNav = localNav[y].split('|');
    var splitTmpLocalNav = tmpLocalNav[0].split('_');

    //only show first two levels 
    if (splitTmpLocalNav.length < 3) {

      //only create the closing link if the previous Entry was created
      if (prevLinkCreated > 0) {
     		if(splitTmpLocalNav.length == prevLevel){
          document.write("</li>");
          prevLinkCreated = 0;
        }
     		if(splitTmpLocalNav.length < prevLevel){
          document.write("</li></ul></li>");
          prevLinkCreated = 0;
        }
      }
        
      //skip creation if link is hidden from leftNav
      if(tmpLocalNav[3] !='h') {

     		if(splitTmpLocalNav.length > prevLevel){
          document.write("<ul>");
        }
      	document.write('<li>');
      	document.write('<a href="'+tmpLocalNav[2]+'"');
      	
        //open link in new window
        if(tmpLocalNav[3] == 1){
      		document.write('target="_blank"');
      	}
        
      	document.write('>&nbsp;&nbsp;'+tmpLocalNav[1]+'</a>');
    
        prevLevel = splitTmpLocalNav.length;
        prevLinkCreated = 1;
      }
    }
  }	
  if (prevLevel > 1) {
    document.write('</li></ul>');
  }
  document.write('</li></ul><br /><br />');
}
//End Make Menu

//Create and display the menu
function makeBox(){
	document.write('<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">');
	document.write('<tr class=\"color\">');
	document.write('<td height=\"50\" class=\"whiteNoLine\"><b>&nbsp;&nbsp;<a href=\"'+sitePath+'\"  target=\"_top\">'+bcHomeLink+'</a></b></td>');
	document.write('</tr>');
	document.write('</table>');
}
//End Make Menu


//Create and display the bread crumbs
function makeBreadCrumbs(){
  //alert("menuLocation " + menuLocation);
	if(menuLocation!=-1){
  	document.write('<a class="Crumbs" href="',sitePath,'" target="_top">', bcHomeLink,'</a>');
  	var currentPage = localNav[menuLocation].split('|');
  	var tmpCString = menuStyle[0];
  	for(var c=0; c < (menuTier-1); c++){
  		for(var b=0; b < localNav.length; b++){
  			var tmpCrumb = localNav[b].split('|');
  			if(tmpCrumb[0]==tmpCString){
          tmpCrumb[1] = tmpCrumb[1].replace(/&nbsp;/gi,"");	//change		
    			document.write(' > <a class="Crumbs" href="',tmpCrumb[2],'" target="_top">',tmpCrumb[1],'</a>');
  			}
  		}
  		tmpCString = tmpCString+"_"+menuStyle[c+1];
  	}
  	currentPage[1] = currentPage[1].replace(/&nbsp;/gi,"");  //change
    document.write(' > ',currentPage[1]);
	} else {
    document.write(' ');
  }
}
//End bread crumbs creation

/**********************************************************************
   End Make Menu Functions
***********************************************************************/

/**********************************************************************
    Additional Functions
***********************************************************************/


//Read cookie created by CSO
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//End readCookie

//Create and display the footer
function makeFooter(){
  var today = new Date();
  document.write(''+
    '<br />'+
    '<table cellpadding="0" cellspacing="0" border="0" width="1000" summary="Bottom Global Navigation" id="footer">'+
    '  <tr>'+
    '    <td align="center" valign="middle">'+
    '      <a href="'+refDTEu+'/" target="_top">DTE Energy home</a> |'+
    '      <a href="'+refDTEu+'/privacyPolicy.html" target="_top">Privacy Policy</a> |'+
    '      <a href="'+refDTEu+'/termsofuse.html" target="_top">Terms of Use</a><br />'+
    '      All contents &copy; '+
    today.getFullYear()+
    '      DTE Energy Company<br /><br />'+
    '    </td>'+
    '  </tr>'+
    '</table>');
}
//End makeFooter

// added functions for hiding and showing the collapsible sections
function show(id) {
  if (document.getElementById(id).style.display == 'none') {
    document.getElementById(id).style.display = '';
  }
}

function hide(id) {
  document.getElementById(id).style.display = 'none';
}


