/*****************************************/
// Cascading menus section appears last. //
/*****************************************/


//for use as copyright year
curDate = new Date();
var curYear = curDate.getFullYear();

//TEXT SIZE SELECTION
function makeSmall() {
  var t=document.getElementById("document");
  if (t!=null) {
    t.style.fontSize="85%";    
  }
  setImage(1);
  return false;
}
function makeMedium() {
  var t=document.getElementById("document");
  if (t!=null) {
    t.style.fontSize="100%";
  }
  setImage(2);
  return false;
}
function makeBig() {
  var t=document.getElementById("document");
  if (t!=null) {
    t.style.fontSize="115%";
  }
  setImage(3);
  return false;
}
var isrc = new Array();
for (iTemp=1; iTemp<7; iTemp++) {
isrc[iTemp] = new Image();
}
isrc[1].src = '/de/imgs/topnav/s.gif';
isrc[2].src = '/de/imgs/topnav/m.gif';
isrc[3].src = '/de/imgs/topnav/b.gif';
isrc[4].src = '/de/imgs/topnav/sa.gif';
isrc[5].src = '/de/imgs/topnav/ma.gif';
isrc[6].src = '/de/imgs/topnav/ba.gif';

function setImage(imgIndex) {
  var t1=document.getElementById("ts");
  var t2=document.getElementById("tm");
  var t3=document.getElementById("tb");
    
  if (t1 != null) {
    if (imgIndex==1) {
      t1.src=isrc[4].src;
    }
    else {
      t1.src = isrc[1].src;
    }
  }
  if (t2 != null) {
    if (imgIndex==2) {
      t2.src = isrc[5].src;
    }
    else  {
      t2.src = isrc[2].src;
    }    
  }
  if (t3 != null) {
    if (imgIndex==3) {
      t3.src = isrc[6].src;
    }
    else {
      t3.src = isrc[3].src;
    }
  }
}

// 2 Functions for GE Fast Search
function fnSiteSearch(fm) {
	if (fm.textToSearch.value=="") { return false; }
	return true;
}
function fnSiteSearchLink(fm) {
	if (fm.textToSearch.value != "") { fm.submit(); } 
}

function validate() {
  if(!checkSpaces(document.form.SEARCHTEXT.value)) {
    alert("Please enter your search criteria.");
    document.form.SEARCHTEXT.select();
    document.form.SEARCHTEXT.focus();
    return false;
  }
  //document.form.target="_blank";
  document.form.submit();
  return true;
}


function onMouse(id, newSrc) {
    var theImage = FWFindImage(document, id, 0);
    if (theImage) {
        theImage.src = newSrc;
    }
}

function FWFindImage(doc, name, j) {
    var theImage = false;
    if (doc.images) {
        theImage = doc.images[name];
    }
    if (theImage) {
        return theImage;
    }
    if (doc.layers) {
        for (j = 0; j < doc.layers.length; j++) {
            theImage = FWFindImage(doc.layers[j].document, name, 0);
            if (theImage) {
                return (theImage);
            }
        }
    }
    return (false);
}

function displayStatus(msgStr) {
    window.status = msgStr;
    document.MM_returnValue = true;
}

function checkSpaces(fld)	{
		l_length_of_data = fld.length;
		l_ctr=0;
		while(l_ctr != l_length_of_data)	{
			if(fld.charAt(l_ctr) != " ")	{
				return true;
			}
			l_ctr++
		}
		return false;
}

// global vars
var popupWin;
var largerWin;
var largerWin2;
var largerWin3;
var glossaryWin;
var scrnwidth=screen.width;
var scrnheight=screen.height;


//NN4 window resize fix
if(!window.saveInnerWidth) {
  window.onresize = resizeIt;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}
function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}


// "only 1 open at a time" popup function //
function openPop(url,width,height,addloptions){
	var xspot=Math.round((scrnwidth/2)-(width/2));
	var yspot=Math.round((scrnheight/2)-(height/2)-30);
	features = "height="+height+",width="+width+",top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot;
	if (addloptions && addloptions!="") { features += ","+addloptions; }
	if (!popupWin || popupWin.closed){
		popupWin = window.open(url, '', features);
	}
	else {
		window.popupWin.close();
		popupWin = window.open(url, '', features);
	}
}

//	NORMAL Function to View Larger Image.
//	Opens window which contains only a 500 x 500 image
function openLarger(imgurl,imgalt) {
	var xspot=Math.round((scrnwidth/2)-(250));
	var yspot=Math.round((scrnheight/2)-(280));
	if (!largerWin || largerWin.closed) {
		largerWin = window.open("","","width=500,height=500,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	else {
		window.largerWin.close();
		largerWin = window.open("","","width=500,height=500,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	drawstr =  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
	drawstr += '<html><head><title>'+imgalt+'</title></head>';
	drawstr += '<body bgcolor="white" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">';
	drawstr += '<img src="';
	drawstr += imgurl;
	drawstr += '" width="500" height="500" border="0" alt="';
	drawstr += imgalt;
	drawstr += '">';
	drawstr += '</body></html>';
	largerWin.document.open();
	largerWin.document.write(drawstr);
	largerWin.document.close();
}


//	Function to View Larger Fluorescent (HORIZONTAL) Image.
//	Opens window which contains only a ????? x 128 image
function openLarger2(imgurl,imgalt) {
	var xspot=Math.round((scrnwidth/2)-(250));
	var yspot=Math.round((scrnheight/2)-(100));
	if (!largerWin2 || largerWin2.closed) {
		largerWin2 = window.open("","","scrollbars,width=500,height=150,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	else {
		window.largerWin2.close();
		largerWin2 = window.open("","","scrollbars,width=500,height=150,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	drawstr =  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
	drawstr += '<html><head><title>'+imgalt+'</title></head>';
	drawstr += '<body bgcolor="white" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">';
	drawstr += '<img src="';
	drawstr += imgurl;
	drawstr += '" height="128" border="0" alt="';
	drawstr += imgalt;
	drawstr += '">';
	drawstr += '</body></html>';
	largerWin2.document.open();
	largerWin2.document.write(drawstr);
	largerWin2.document.close();
}

//	Function to View Larger Fluorescent (VERTICAL) Image.
//	Opens window which contains only a 303 x ?????? image
function openLarger3(imgurl,imgalt) {
	var xspot=Math.round((scrnwidth/2)-(160));
	var yspot=Math.round((scrnheight/2)-(280));
	if (!largerWin3 || largerWin3.closed) {
		largerWin3 = window.open("","","scrollbars,width=323,height=500,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	else {
		window.largerWin3.close();
		largerWin3 = window.open("","","scrollbars,width=323,height=500,top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot);
	}
	drawstr =  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
	drawstr += '<html><head><title>'+imgalt+'</title></head>';
	drawstr += '<body bgcolor="white" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">';
	drawstr += '<img src="';
	drawstr += imgurl;
	drawstr += '" width="303" border="0" alt="';
	drawstr += imgalt;
	drawstr += '">';
	drawstr += '</body></html>';
	largerWin3.document.open();
	largerWin3.document.write(drawstr);
	largerWin3.document.close();
}


function closepopups(){
	if (popupWin && popupWin.open){
		window.popupWin.close();
	}
	if (largerWin && largerWin.open){
		window.largerWin.close();
	}
	if (largerWin2 && largerWin2.open){
		window.largerWin2.close();
	}
	if (largerWin3 && largerWin3.open){
		window.largerWin3.close();
	}
	if (glossaryWin && glossaryWin.open){
		window.glossaryWin.close();
	}
}

// function linktoOpener(url) is called from popups. Places url in opener, and closes popup. 
function linktoOpener(url) {
	if(self.opener) {
		self.opener.top.document.location=url;
		self.opener.focus();
		self.close();
	} else {
		self.top.document.location=url;
		self.focus();
	}
}

// turnonTab() sniffs the document location and turns on the appropriate tab in the navbar.
// Used on HOME LIGHTING site
function turnonTab() {
	var currurl=document.location+"";
	var locindex="0";
	if(currurl.indexOf("/product_portfolio/") != -1) { locindex="1"; }
	if(currurl.indexOf("/products/") != -1) { locindex="2"; }
	if(currurl.indexOf("/market_segments/") != -1) { locindex="3"; }
	if(currurl.indexOf("/resources/") != -1) { locindex="4"; }
	if(currurl.indexOf("/after_sales/") != -1) { locindex="5"; }	
	if(locindex!="0" && document.getElementById) {
		document.getElementById("navimgcell"+locindex).className="navbarLinkOn";
		document.getElementById("navimg"+locindex).src="/de/imgs/shim.gif";
		document.getElementById("navlinkcell"+locindex).className="navbarLinkOn";
		document.getElementById("navlink"+locindex).className="navbarLinkOn";
	}
}

// turnonTab2() sniffs the document location and turns on the appropriate tab in the navbar.
// Used on COMMERCIAL LIGHTING site -- all except its home page where navbar is hard coded to have "home" selected.
function turnonTab2() {
	var currurl=document.location+"";
	var locindex="0";
	if(currurl.indexOf("/product_portfolio/") != -1) { locindex="1"; }
	if(currurl.indexOf("/products/") != -1) { locindex="2"; }
	if(currurl.indexOf("/market_segments/") != -1) { locindex="3"; }
	if(currurl.indexOf("/after_sales/") != -1) { locindex="4"; }
	if(currurl.indexOf("/resources/") != -1) { locindex="5"; }	
	if(locindex!="0" && document.getElementById) {
		document.getElementById("navbarCell_"+locindex).className="selected";
		document.getElementById("navbarImg_"+locindex).src="/de/imgs/topnav/nav1Link_selected.gif";
	}
}

// needforSubmit() builds INFM URL from two select elements and redirects user to INFM page
function needforSubmit() {
	var infm_url = "/na/home_lighting/infm/";
	var form = document.needforForm;
	var Ineed = form.needSel.options[form.needSel.selectedIndex].value;
	var ForMy = form.forSel.options[form.forSel.selectedIndex].value;
	infm_url = infm_url + Ineed + "_" + ForMy + ".htm";
	document.location = infm_url;
}

// setINFMform() reads URL and sets select elements of INFM form to reflect the current page
function setINFMform() {
	var curl = unescape(document.location);
	if (curl.indexOf("/infm/")!=-1) {
		var infm = curl.slice((curl.indexOf('/infm/')+6),curl.indexOf('.htm'));
		var infm_arr = infm.split("_");
		var form = document.needforForm;
		form.needSel.selectedIndex = (infm_arr[0]=="light")?0:(infm_arr[0]=="life")?1:2;
		for(i=0;i<6;i++) {
			if (form.forSel.options[i].value == infm_arr[1]) {
				form.forSel.selectedIndex = i;
			}
		}
	}
}

/* SELECT ELEMENT NAVIGATION */
/* selectNav function -- a select (dropdown) element navigation function
   called from onChange event of select element,
   i.e. onChange="selectNav('formName','archive');"
   where 'formName' is the id/name of the containing form, and
   where 'archive' is the id/name of the specific select element to be tested.
   the value of the option elements should be the target URLs.
*/
function selectNav(form,fName) {
  fRef = eval('top.document.'+form);
  var selIdx = fRef[fName].selectedIndex 
  var selURL = fRef[fName].options[selIdx].value 
  document.location = selURL;
}

/* setSelected function -- sets select element navigation dropdown to reflect the current page
   called inline after the code for the select element navigation,
   i.e. within a javascript code block
      setSelected(top.document.formName,'archive');
   where 'archive' is the name of the specific select element to be effected
   the value of the option elements will be compared to the current URL and, if an option matches, it will be set as selected.
*/
function setSelected(form,fName) {
  fRef = eval('top.document.'+form);
	var curl = unescape(document.location);
  i = curl.indexOf('/na/');
  curl = curl.slice(i);
  for(i=0;i<fRef[fName].options.length;i++) {
    if (fRef[fName].options[i].value.indexOf(curl)>=0) {
      fRef[fName].options[i].selected = true;
      break;
    }
  }
}
/* END SELECT ELEMENT NAVIGATION */


/*  Edison Awards openPop wrapper function */
  function eaPop(url) {
    openPop("/de/" + url,"750","650","resizable,scrollbars");
  }
/*/Edison Awards openPop wrapper function */


/* Learn About Light's Distribution Curves openPop wrapper function */
function openCurve(idx) {
	openPop("/na/business_lighting/education_resources/learn_about_light/pop_curves.htm?"+idx,"710","520","resizable,scrollbars");
}
/*/Learn About Light Distribution Curves openPop wrapper function */


/* COMMERCIAL Glossary opener function */
/* Calls absolutely so it can be used within ecatalog also */
/* Cannot use generic openPop because of feature override behavior */
function openGlossary(anchr) {
	if (!glossaryWin || glossaryWin.closed){
		glossaryWin = window.open("http://www.gelighting.com/na/business_lighting/education_resources/glossary.htm#"+anchr,"","width=770,height=300,resizable,scrollbars,toolbar,location,status,top=1,screenY=1,left=1,screenX=1");
	}
	else {
		glossaryWin.focus();
		glossaryWin.document.location = "http://www.gelighting.com/na/business_lighting/education_resources/glossary.htm#"+anchr;
	}
}
/*/Glossary opener function */

/* image switcher function for Edison Awards Winners pop-up pages */
/* does show/hide on divs rather than a src swap, because images can be different sizes */
/* assumes first image is visible by default */
visible="1";
function switchImage(num) {
  if (num!=visible) {
    document.getElementById('switchBox'+visible).style.display = 'none';
    document.getElementById('switchBox'+num).style.display = 'block';
    visible = num;
  }
}
/* image switcher */



/**********************************************************************/
// Cascading Menus for Standard GE Corporate Top Navbar
// By Matthew Rasnake and Scott Henderson, GE Consumer & Industrial
// March 2005
/**********************************************************************/

var menuBaseHref = "";
if (document.URL.indexOf("gealnx34.appl.ge.com")>0) menuBaseHref = "http://www.gepowercontrols.com" ;
else menuBaseHref = "" ;

//if NOT teamsite AND NOT gelighting, make menuBaseHref absolute
hoststring=window.location.host.toLowerCase();
if(hoststring.indexOf('teamsite') == -1 && hoststring.indexOf('gelighting') == -1) {

//	menuBaseHref = "http://www.gepowercontrols.com";

//	menuBaseHref = "http://test.gepowercontrols.com";
}

//Create the only array we'll need.
geMenuArray = new Array();

/* All calls are absolute b/c it must be used within ecatalog & search results also */
/* The first menu */
geMenuArray[0] = [
				"Installationsger&auml;te||"+menuBaseHref+"/de/product_portfolio/residential/index.htm",
				"Leistungsschalter||"+menuBaseHref+"/de/product_portfolio/industrial_components/index.htm",
				"Steuerungskomponenten||"+menuBaseHref+"/de/product_portfolio/control_automation/index.htm",
				"Industrielle Geh&auml;usesysteme||"+menuBaseHref+"/de/product_portfolio/industrial_enclosures/index.htm",
				"Schaltanlagen und Systemschr&auml;nke||"+menuBaseHref+"/de/product_portfolio/system_equipment/index.htm",
				"Softwareunterst&uuml;tzung||"+menuBaseHref+"/de/product_portfolio/software/index.htm",
				"Dienstleistungen||"+menuBaseHref+"/de/after_sales/index.htm",
				"RoHS-Richtlinie||"+menuBaseHref+"/de/resources/rohs/index.htm",
				"A-Z||"+menuBaseHref+"/de/product_portfolio/keywords.html"
				];
geMenuArray[0]['id']    = "navbarCell_1"; // id of Parent object for this menu
geMenuArray[0]['width'] = "125";          // width of this menu
geMenuArray[0]['left']  = "";             // left offset (positive or negative)
geMenuArray[0]['align'] = "left";

/* The second menu */
/*geMenuArray[1] = [
             ];
geMenuArray[1]['id']    = "navbarCell_2";
geMenuArray[1]['width'] = "115";
geMenuArray[1]['left']  = "";
geMenuArray[1]['align'] = "left";*/

/* The third menu */
geMenuArray[2] = [
				"Anwendungen f&uuml;r Wohngeb&auml;ude||"+menuBaseHref+"/de/market_segments/residential_applications/index.htm",
				"Gewerbliche Anwendungen||"+menuBaseHref+"/de/market_segments/commercial_applications/index.htm",
				"Industrieanwendungen||"+menuBaseHref+"/de/market_segments/industrial_applications/index.htm",
				"Referenzen & L&ouml;sungen||"+menuBaseHref+"/de/market_segments/vertical_markets/index.htm"
		 ];
geMenuArray[2]['id']    = "navbarCell_3";
geMenuArray[2]['width'] = "110";
geMenuArray[2]['left']  = "";
geMenuArray[2]['align'] = "left";

/* The fourth menu */
geMenuArray[3] = [
				];
geMenuArray[3]['id']    = "navbarCell_4";
geMenuArray[3]['width'] = "111";
geMenuArray[3]['left']  = "";
geMenuArray[3]['align'] = "left";

/* The fifth menu */
geMenuArray[4] = [
				
				]; 

geMenuArray[4]['id']    = "navbarCell_5";
geMenuArray[4]['width'] = "105";
geMenuArray[4]['left']  = "-36";
geMenuArray[4]['align'] = "left";

//Write additional styles required for menus.
ourStyles = '<style type="text/css">';
ourStyles += 'div.ddmenu {position:absolute; margin-top:7px; visibility:hidden; text-transform:none; border-top:1px solid #CCCCCC;}';
ourStyles += 'a.ddcell       {background-color:#F7F7F7; border:1px solid #CCCCCC; border-top:0px; padding: 6px 7px 6px 8px; text-transform:none; display:block;}';
ourStyles += 'a.ddcell:hover {background-color: #FFFFFF;}';
ourStyles += '</style>';
document.write(ourStyles);


//fnBuildMenu(mNum) returns the html for a single menu.
function fnBuildMenu(mNum) {
	mArr = geMenuArray[mNum];
	mWidth = "width:"+mArr.width+"px;";                      // a CSS style width statement string
	mLeft = (mArr.left)?"margin-left:"+mArr.left+"px;":"";   // a CSS style left-margin statement string
	if (mArr.align) {
	  mAlign = "text-align:" + mArr.align + ";";
	}
	else {
	  mAlign = "text-align:left;";
	}
	menuString =  '<div id="menudiv'+mNum+'" class="ddmenu" style="'+mWidth+mLeft+mAlign+'">'; // start menuString with opening DIV
	for (mItem in mArr) {                           // loop through this sub-array
		if (parseInt(mItem)||(parseInt(mItem)==0)) {  // if array item name is a number (i.e. it's not "id" or "width")
			linky = mArr[mItem].split('||');            // split the contents of this array item to get Link Text and Link URL
			menuString += '<a href="'+linky[1]+'" class="ddcell" id="m'+mNum+'-'+mItem+'" style="'+mWidth+'">'+linky[0]+'</a>'; // add this menu item to HTML DIV string
		}
	}
	menuString += '</div>';                         // close HTML DIV string
	return menuString;                              // return the constructed Menu HTML 
}

//fnDefineMenus() uses fnBuildMenu to create the HTML, insert it into the page, and attach event listeners to the Parent Objects  
function fnDefineMenus() {
	if(!document.getElementById(geMenuArray[geMenuArray.length-1].id)) { //a test for final Parent object that's supposed to spawn a menu
		fred = setTimeout("fnDefineMenus()",500);  //if it doesn't exist yet, wait a bit longer
	} else {
		for (men in geMenuArray) {                      // loop through main menu Array
	  		tempObj = document.getElementById(geMenuArray[men].id); //get obj ref. to this menu's Parent Object
	  		tempObj.innerHTML  += fnBuildMenu(men);     //build menu HTML string and add it to Parent Object's HTML
	  		tempObj.onmouseover = fnOpenMen;          //define Parent Object's mouseover event to call fnOpenMen
	  		tempObj.onmouseout  = fnCloseMen;         //define Parent Object's mouseout event to call fnCloseMen
    	}
	}
}

function fnOpenMen() {
  menObj = this.getElementsByTagName('div')[0];  // Our menu is the first div within the Parent Object (this)
  menObj.style.visibility = "visible";           
}
function fnCloseMen() {
  menObj = this.getElementsByTagName('div')[0];  // Our menu is the first div within the Parent Object (this)
  menObj.style.visibility = "hidden";
}

//Let's get things started!!
//We're NOT using document.onload -- It could conflict with an onload already in the BODY tag.
if (document.getElementsByTagName) { // if we're DOM capable
	fnDefineMenus();  //start _trying_ to define menus
}

/*********************************************/
// Cascading Menus Section Ended
/*********************************************/

/**********************************************************/
// This should be the end.
// Place any/all new stuff ABOVE the menus section please.
/**********************************************************/