/*******************************************************************/
// JavaScript Document for NewEnergy.com site redesign
// Global variables: includes asset path & arrays containing image
// names for different rollovers & interactive pieces 
/********************************************************************/

var ASSET_PATH = "/vcmfiles/NewEnergy2/Images/";
var nvItems = new Array('home', 'informu', 'about', 'experience', 'electricity', 'gas');
var prodItems = new Array('descriptions', 'benefits', 'risks');
var whySwitchItems = new Array('reason1', 'reason2', 'reason3');
var innovationItems = new Array('why', 'how', 'choice', 'mirror');

/********************************************************************/
// Used for the Service Area dropdown in the main  header
// Takes user to the specified url in a select statement option
/********************************************************************/
function linkJump(source) {
window.location = source.options[source.selectedIndex].value;
}


/********************************************************************/
// GLOBAL HEADER FUNCTIONS FOR NAVIGATION & DHTML MENUS 
/********************************************************************/

// MAIN NAVIGATION
// Preloads images in the nvItems array 
function rollover_preload(){
for (i=0; i < nvItems.length; i++){
	eval(nvItems[i] + "_rol = new Image();");
	eval(nvItems[i] + " = new Image();");
	
	eval(nvItems[i] + "_rol.src = '" + ASSET_PATH + "nv_" + nvItems[i] + "_rol.gif';");
	eval(nvItems[i] + ".src = '" + ASSET_PATH + "nv_" + nvItems[i] + ".gif';");
	} 
}

// Sets the specified image OFF state to its ON state
function set_restore_curr(currOnItem){
for (i=0; i < nvItems.length; i++){

	if (nvItems[i] == currOnItem) {
		eval(nvItems[i] + ".src = '" + ASSET_PATH + "nv_" + nvItems[i] + "_on.gif';");
	}
}
}

// Shows the ON state of a nav item when user rolls over the image
function rollover(imageName){
if (document.images){
	eval("document." + imageName + ".src=" + imageName + "_rol.src");
}
}

// Shows the OFF state of a nav item when user rolls out of the image
function restore(imageName){
if (document.images){
	eval("document." + imageName + ".src=" + imageName + ".src");
}
}

// Restores all nav item buttons to their OFF state
function restoreall(){
	for (i=0; i < nvItems.length; i++){
		restore(nvItems[i]);
	}
}

//MAIN NAVIGATION DHTML MENUS 
// Hides ALL DHTML menus 
function closeall() {
clearTimeout(timeoff);
if (document.all && !(document.getElementById)){
	document.all['menuinformu'].style.visibility='hidden';
	document.all['menuaboutus'].style.visibility='hidden';
	document.all['menuexperience'].style.visibility='hidden';
	document.all['menuelectricity'].style.visibility='hidden';
	document.all['menugas'].style.visibility='hidden';
	
} else if (document.getElementById) {
	var divslist = document.getElementsByTagName("div"); 
	var i;
	for(i=0;i<divslist.length;i++) { 
 
	  if (divslist[i].id.indexOf("menu") != -1) {
	   document.getElementById(divslist[i].id).style.visibility='hidden';
	   }
	}
} else if (document.layers) {
  document.layers['menuinformu'].visibility='hide';
  document.layers['menuaboutus'].visibility='hide';
  document.layers['menuexperience'].visibility='hide';
  document.layers['menuelectricity'].visibility='hide';
  document.layers['menugas'].visibility='hide';
	}
	
	restoreall();
}

function reDo() {
   if (innerWidth != origWidth || innerHeight != origHeight) 
      location.reload();
}

// Shows specified DHTML menu
function visOn(id) {
var strID = "'" + id + "'";
id = "menu" + id;
closeall();
	if (document.all && !(document.getElementById)){
		document.all[id].style.visibility='visible';
		eval('timeoff=setTimeout("visOff(" + strID + ")", 5000)');
	} else if (document.getElementById) {
		document.getElementById(id).style.visibility='visible';
		eval('timeoff=setTimeout("visOff(" + strID + ")", 5000)');
	} else if (document.layers) {
		document.layers[id].visibility='show';
		eval('timeoff=setTimeout("visOff(" + strID + ")", 5000)');
	}
}

// Hides specified DHTML menu
function visOff(id) {
restore(id);
id = "menu" + id;
	if (document.all && !(document.getElementById)){
		document.all[id].style.visibility='hidden';
	} else if (document.getElementById) {
		document.getElementById(id).style.visibility='hidden';
	} else if (document.layers) {
	    document.layers[id].visibility='hide';
	}
}
				
// Highlights DHTML menu subitem background color when user rolls over it				
function classOver(td, atd){
if(document.getElementById||(document.all && !(document.getElementById))){
td.className='subnvhover';
	if (document.all) {
	   document.all[atd].className ='subnvhover';
	} else if (document.getElementById) {
	   document.getElementById(atd).className='subnvhover';
	}
	}
}

// Restores DHTML menu subitem background color when user rolls out
function classOut(td, atd){
if(document.getElementById||(document.all && !(document.getElementById))){
td.className='subnvbg';
if (document.all) {
   document.all[atd].className ='subnvbg';
} else if (document.getElementById) {
   document.getElementById(atd).className='subnvbg';
   }
}
}
		
var origWidth, origHeight;
//if (NS4) onresize = reDo;

if (document.layers) {
  origWidth = innerWidth;
  origHeight = innerHeight;
  onresize = reDo;
  //alert('redo');
} 

var timeoff=0;


/********************************************************************/
// HOMEPAGE KNOWLEDGE INTERACTIVE PIECE
/********************************************************************/

// Restores all buttons (why switch, how to switch & energy choice)
// to their OFF states
function closeallrollovers() {
	visOff('whyswitch');
	visOff('howswitch');
	visOff('echoiceswitch');
}

function rolloverOn(id) {
closeallrollovers();
if (document.all && !(document.getElementById)){
	document.all[id].style.visibility='visible';
} else if (document.getElementById) {
	document.getElementById(id).style.visibility='visible';
} else if (document.layers) {
	document.layers[id].visibility='show';
}
}


/********************************************************************/
// TIMESTAMP FUNCTION ON GLOBAL HEADER
/********************************************************************/
function showtimestamp(){
//Displays DD-MM-YYYY: HH:MM PM
var now = new Date();

//Get Date information
var day = now.getDate().toString();
var month = now.getMonth() + 1;
month = month.toString();
var year = now.getYear().toString();

if (year.length >=3) {
	year = year.charAt(year.length -2) + year.charAt(year.length-1)
}

var dateValue = month + "-" +day + "-" + year;
//Get Time information
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += (hours >= 12) ? " PM" : " AM";
//Display time information
document.write(dateValue + " : " + timeValue);
}



/********************************************************************/
// FORM FUNCTIONS
/********************************************************************/

//Request a quote
function submitRequestAQuote () {
var customerCutOff = 10000; //in dollars
var rangedropdown = document.requestaquoteform.range;
//Determine which one is the redirect page
if (rangedropdown.options[rangedropdown.selectedIndex].value >= customerCutOff) {
//Large customer
	document.requestaquoteform.h_c.value = "16fc4f03c73eec2f18a805e4da6176a0";
} else {
	document.requestaquoteform.h_c.value = "42508cbdf1005e2f18a805e4da6176a0";
};
if (validatepage()) {
		document.requestaquoteform.State.value  = document.requestaquoteform.h_t[document.requestaquoteform.h_t.selectedIndex].text;
		document.requestaquoteform.submit();
	}
/*************************************************/
}

function submitContactUs() {

if (validatepage()) {
	document.contactusform.h_c.value = "de9ed02ec646e92f18a805e4da6176a0";
	document.contactusform.State.value  = document.contactusform.h_t[document.contactusform.h_t.selectedIndex].text;
	document.contactusform.submit();
	}
}


/********************************************************************/
// INTERACTIVE PIECES: 
// WHY SWITCH, KNOWLEDGE HOMEPAGE, PRODUCTS, SERVICE AREA MENU
/********************************************************************/
// General Functions 

// Shows a specified block (div) 
function showBlock(id){
if (document.all && !(document.getElementById)){
		document.all[id].style.visibility='visible';
	} else if (document.getElementById) {
		document.getElementById(id).style.visibility='visible';
	} else if (document.layers) {
		document.layers[id].visibility='show';
	}
}

// Hides a specified block (div) 
function hideBlock(id){
if (document.all && !(document.getElementById)){
		document.all[id].style.visibility='hidden';
	} else if (document.getElementById) {
		document.getElementById(id).style.visibility='hidden';
	} else if (document.layers) {
	    document.layers[id].visibility='hide';
	}
}

// Preloads specified array of images
function imagePreloader(arrayname, imgId){
//preloads images in a specific array
for (i=0; i < arrayname.length; i++){
	eval(imgId + arrayname[i] + "_on = new Image();");
	eval(imgId + arrayname[i] + " = new Image();");
	
	eval(imgId + arrayname[i] + "_on.src = '" + ASSET_PATH + imgId + arrayname[i] + "_on.gif';");
	eval(imgId + arrayname[i] + ".src = '" + ASSET_PATH + imgId + arrayname[i] + ".gif';");
	} 
}

// Closes all existing blocks given an div id
function closeAllBlocks(blockname, divid) {

if (document.all && !(document.getElementById)){
	for(i=0;i<blockname.length;i++) {
		eval("document.all['" + blockname[i] + "'].style.visibility='hidden';");
	}
} else if (document.getElementById) {
	var divslist = document.getElementsByTagName("div"); 
	var i;
	for(i=0;i<divslist.length;i++) { 
 
	  if (divslist[i].id.indexOf(divid) != -1) {
	   document.getElementById(divslist[i].id).style.visibility='hidden';
	   }
	}
} else if (document.layers) {
	for(i=0;i<blockname.length;i++) {
		eval(" document.layers['" + blockname[i] + "'].visibility='hide';");
	}
}
	
}

// Restores all images to its OFF state
function restoreAllImages(arrayname, imgId) {
for (i=0; i < arrayname.length; i++){
	if (document.images){
		eval("document." + imgId + arrayname[i] + ".src=" + imgId + arrayname[i] + ".src");
	}
}
}

// Sets a specified image to its ON state
function setImageOn(imageName){

if (document.images){
	eval("document." + imageName + ".src=" + imageName + "_on.src");
}
}


//Products page
function showProductInfo(id) {
	prodId = 'prod' + id;
	//Clear all current visible blocks 
	closeAllBlocks (prodId, 'prod');
	
	//Show the clicked block
	showBlock(prodId);
	
	//Clear all tabs
	restoreAllImages(prodItems, 'tab_');
	
	//Set the current tab
	var imgId = "tab_" + id;
	setImageOn(imgId);	
}

//Why Switch page
function showReasonInfo(id) {
	var reasonId = 'whyswitch' + id;
	//Clear all current visible blocks 
	closeAllBlocks (reasonId, 'whyswitch');
	
	//Show the clicked block
	showBlock(reasonId);
	
	//Clear all tabs
	restoreAllImages(whySwitchItems, 'tab_');
	
	//Set the current tab
	var imgId = "tab_" + id;
	setImageOn(imgId);	
}


//Home page
function showInnovationInfo(id) {
	//Clear all buttons
	restoreAllImages(innovationItems, 'btn_hm_');
	//Set the current tab
	var imgId = "btn_hm_" + id;
	setImageOn(imgId);	
	
	//Show the correct image
	eval("document.block.src=" + "hm_boxorng_" + id + "_on.src");
	if (id == 'choice') {
		document.btn_hm_mirror.src= btn_hm_mirror_on.src;
	}
}

/********************************************************************/
// POPUP WINDOWS - USED IN TOOLS PAGES TO VIEW LARGER IMAGE
/********************************************************************/
function openNewWindow(url, width, height) {
	eval("window.open('" + url + "','mywindow','width=" + width + ",height=" + height + ", menubar=no, toolbar=no, scrollbars=no')");
}