//for use as copyright year
curDate = new Date();
var curYear = curDate.getFullYear();

// 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(); } 
}

// 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);
    }
}


/* 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 */

// "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);
	}
}

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();
	}
}

function MM_displayStatusMsg(msgStr) { //v2.0
  msgStr = msgStr.replace(/'/g,"\\'");  //This code takes care of the single quote
  setTimeout("status='" + msgStr + "'", 50);
  document.MM_returnValue = true;
}


/* 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('/eu/');
  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 applPop(url) {
    openPop("/apo/applications/" + url,"650","550","resizable");
  }
  
/*  Edison Awards openPop wrapper function */
  function referPop(url) {
    openPop("/apo/applications/" + url,"600","500","resizable");
  }
  
/*  Edison Awards openPop wrapper function */
  function motors_Pop(url) {
    openPop("/apo/products/industrial/motors_control/" + url,"600","500","resizable");
  }
  

/*  Edison Awards openPop wrapper function */
  function repl_Pop(url) {
    openPop("/apo/resources/cost_of_light/" + url,"480","250","resizable");
  }

/*  Edison Awards openPop wrapper function */
  function colour_Pop(url) {
    openPop("/apo/resources/colour_booth/" + url,"650","400","resizable=1, scrollbars=1");
  }  



  
/*/Edison Awards openPop wrapper function */

/* Learn About Light's Distribution Curves openPop wrapper function */
function openCurve(idx) {
	openPop("/apo/resources/learn_about_light/pop_curves.htm?"+idx,"580","450");
}
/*/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/eu/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/eu/resources/glossary.htm#"+anchr;
	}
}
/*/Glossary opener function */


/**********************************************************************/
// Cascading Menus for Standard GE Corporate Top Navbar
// By Matthew Rasnake and Scott Henderson, GE Consumer & Industrial
// March 2005
/**********************************************************************/

var 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.gelighting.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 */

geMenuArray[0] = [
			  "Refrigeration||"+menuBaseHref+"/apo/products/appliances/refrigeration/index.htm",
			  "Cooking||"+menuBaseHref+"/apo/products/appliances/cooking/index.htm",
			  "Dishwashers||"+menuBaseHref+"/apo/products/appliances/dishwashers/index.htm",
			  "Clothes Care||"+menuBaseHref+"/apo/products/appliances/clothes_care/index.htm",
			  "Water Systems||"+menuBaseHref+"/apo/products/appliances/water_systems/index.htm",
			  "Air Conditioning||"+menuBaseHref+"/apo/products/appliances/air_conditioning/index.htm",
				];
geMenuArray[0]['id']    = "navbarCell_1";
geMenuArray[0]['width'] = "125";
geMenuArray[0]['right']  = "";

geMenuArray[1] = [
				"Office Lighting||"+menuBaseHref+"/apo/products/fixtures/prod_list.htm?prod_ctgy=ofs",
		  	"Indoor Industrial||"+menuBaseHref+"/apo/products/fixtures/prod_list.htm?prod_ctgy=ind",
		  	"Commercial Lighting||"+menuBaseHref+"/apo/products/fixtures/prod_list.htm?prod_ctgy=com",
		  	"Flood Lighting||"+menuBaseHref+"/apo/products/fixtures/prod_list.htm?prod_ctgy=fld",
		  	"Roadway / Tunnel||"+menuBaseHref+"/apo/products/fixtures/prod_list.htm?prod_ctgy=rdt",
				];
geMenuArray[1]['id']    = "navbarCell_2";
geMenuArray[1]['width'] = "125";
geMenuArray[1]['right']  = "";



geMenuArray[2] = [
				"Automotive Lighting||"+menuBaseHref+"/apo/products/lighting/automotive/index.htm",
				"Incandescent Lamps||"+menuBaseHref+"/apo/products/lighting/incandescent/index.htm",
				"Halogen Lamps||"+menuBaseHref+"/apo/products/lighting/halogen/index.htm",
				"Fluorescent Lamps||"+menuBaseHref+"/apo/products/lighting/fluorescent/index.htm",
				"Compact Fluorescent Lamps||"+menuBaseHref+"/apo/products/lighting/compact_fluorescent/index.htm",
				"High Intensity Discharge||"+menuBaseHref+"/apo/products/lighting/hid/index.htm",
				"Fixtures||"+menuBaseHref+"/apo/products/lighting/fixtures/index.htm",
				"Specialty Lamps||"+menuBaseHref+"/apo/products/lighting/specialty/index.htm",
				"LED's||"+menuBaseHref+"/apo/products/lighting/led/index.htm?index_item=0",
				];			 
geMenuArray[2]['id']    = "navbarCell_3"; // id of Parent object for this menu
geMenuArray[2]['width'] = "135";          // width of this menu
geMenuArray[2]['left']  = "";             // left offset (positive or negative)


/* The first menu */
geMenuArray[3] = [
			  "Literature Library||"+menuBaseHref+"/apo/resources/library/prod_search.htm",
			  "Design with Light||"+menuBaseHref+"/apo/resources/virtualdesigner/index.htm",
				"Electronic Newsletters||"+menuBaseHref+"/apo/resources/newsletter/index.htm",
				"Online Tools||"+menuBaseHref+"/apo/resources/online_tools/index.htm",
				"Cost of Light||"+menuBaseHref+"/apo/resources/cost_of_light/index.htm",
				"Energy Optimizer||"+menuBaseHref+"/apo/resources/energy_optimiser/index.htm",
				"Interactive Colour Booth||"+menuBaseHref+"/apo/resources/colour_booth/index.htm",
				"Software||"+menuBaseHref+"/apo/resources/software/index.htm",
				"Industrial Resellers||"+menuBaseHref+"/apo/resources/where_to_buy/index.htm?0&type=Industrial",
				"Lighting Resellers||"+menuBaseHref+"/apo/resources/where_to_buy/index.htm?1&type=Lighting",
				"Seminars & Conferences||"+menuBaseHref+"/apo/resources/seminars/index.htm",
				"Learn About Light||"+menuBaseHref+"/apo/resources/learn_about_light/index.htm",
				"Lighting Glossary||"+menuBaseHref+"/apo/resources/glossary.htm",
];
geMenuArray[3]['id']    = "navbarCell_4";
geMenuArray[3]['width'] = "145";
geMenuArray[3]['left']  = "";

/* The third menu */
geMenuArray[4] = [
				"Information||"+menuBaseHref+"/apo/about/info/index.htm",
				"Careers at GE||"+menuBaseHref+"/apo/about/careers/index.htm",
				"Contact Us||"+menuBaseHref+"/apo/about/feedback/index.htm",
             ];
geMenuArray[4]['id']    = "navbarCell_5";
geMenuArray[4]['width'] = "107";
geMenuArray[4]['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
	menuString =  '<br><div id="menudiv'+mNum+'" class="ddmenu" style="'+mWidth+mLeft+'">'; // 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";

	/* in IE, select boxes overlap everything, no matter what you set
	their z-index to, we create iframes, which somehow *do* overlap
	select boxes, under the menus. */
	if (!menObj.iframe) {
		var iframe = document.createElement("iframe");
		menObj.iframe = iframe;
		var x = menObj.offsetLeft;
		var y = menObj.offsetTop;
		var w = menObj.offsetWidth;
		var h = menObj.offsetHeight;
		iframe.style.position = "absolute";
		iframe.style.top    = y + "px";
		iframe.style.left   = x + "px";
		iframe.style.width  = w + "px";
		iframe.style.height = h + "px";
		menObj.parentNode.insertBefore(iframe, menObj);
	}
	menObj.iframe.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";
	if (menObj.iframe) {
		menObj.iframe.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
}

function init() {	
	if (arguments.callee.done) {return;}
	arguments.callee.done = true;
	var onloadOnly = 0;
	if(typeof(matrix_setup) != "undefined") {matrix_setup();}
} 
	
/* for Mozilla */
if (document.addEventListener) {
   // document.addEventListener("DOMContentLoaded", init, null);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)></script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/
