// JavaScript Document

var delayTime = 9000;
var start = null;
var colorCounter = 4;

var colors = new Array("#7e9698","#749a9c","#5d9cad","#5e99b0","#5e92b5","#5e8bb7","#5b82b6","#7e8db1","#878aa1","#8b8a9e");

var quotes = new Array (
	new Array ("Fantastic service (NEM-Watch) - love it!","David Craddock<br>Business Solution Analyst<br>Ergon Energy Corporation Ltd","12 March 2007"),
	new Array ("We have installed the new version of NEM-Watch with no problems and we are now monitoring the NEM with great interest.","Corinne Denny<br>Aurora Energy","2001"),
	new Array ("Thanks alot for your prompt reply - that is good customer service!","Indunil Jayatissa<br>Principal Research Engineer<br>Office of the Tasmanian Energy Regulator","2 October 2006"),
	new Array ("Quite intuitive, so you don't need to pull the manual out, which is a good thing.","General Manager at a major OEM while he was trialling the software (he is now a client)","20 August 2006"),
	new Array ("NEM-Watch we have up on the flat screen (fascinating stuff...!)","Glenn Johnstone<br>Department of Industry Tourism & Resources<br>Canberra","26 February 2007"),
	new Array ("...excellent, just what we planned to do ourselves...","(on NEM-Watch)<br>Peter Bushing<br>CS Energy<br>","2002"),
	new Array ("...your products have helped us immensely!","energy consultant at one of the \"Big 4\" accountancy firms","26 June 2006"),
	new Array ("Your responses are always very prompt - far better than most others!!","National Sales Manager from Major Energy Retailer","19 February 2007"),
	new Array ("We find the playback function very useful for illustrating issues surrounding price spikes, when they occur in the market.","(on NEM-Watch)<br>Matthew Halpin<br>Senior Systems Analyst - Market & Trading<br>Tarong Energy","2007"),
	new Array ("We have definitely found NEM-watch to be advantageous in looking at the market and trying to understand more about it.","Laurie Korn<br>Mt Stuart","2002"),
	new Array ("...the best value for money product in the NEM...","(on NEM-Watch)<br>Warwick Forster<br>Ergon Energy","2001"),
	new Array ("Fixed - and, as usual, a lightning quick response","Angelo Russo<br>Business Development Manager, AGL Energy","15 January 2008"),
	new Array ("You have clearly got the best product in the market, by a country mile (about NEM-Watch)","Julian Turecek<BR>Investment Manager<BR>Cleantech Ventures<BR><BR>formerly GM climate change and energy policy<BR>Origin Energy","6 March 2008"),
	new Array ("Thank you very much for your excellent service. We, at the Department, highly value both of your products (NEM-Watch and NEM-Review), which we use on a regular basis and find them extremely useful in the provision of any NEM related data analysis","Dr T S Prasad<BR>Manager Analysis & Modelling<BR>Department of Water & Energy","7th April 2008"),
	new Array ("... I found the NEM-Watch tips very helpful for understanding this tool and its capability ... well done on a great product","Sandra Fitzpatrick<BR>Communications Specialist<BR>NEMMCO","22 February 2008"),
	new Array ("...you guys do a great job.","Tony Van de Vusse<br>Director<br>Department of Infrastructure Energy and Resources","July 2007"),
	new Array("(NEM-Watch) is absolutely awesome - sensational to visualise what's happening in the world of electricity.","Senior Analyst<br>Corporate Finance Generation Development Company","12 June 2007"),
	new Array("We have NEM-Watch on a big tv screen in our division and it looks pretty good. Now the whole division can see what is happening.","Earth & Energy Resources Policy<br>Department of Primary Industries<br>Victoria", "27 November 2008")
	);

var counter = Math.round(Math.random()*quotes.length);
	
function anim()
{
	var quote1 = document.getElementById("quote1");
	
	quote1.style.color = colors[colorCounter];
	colorCounter = (colorCounter+1)%colors.length;
	
	quote1.innerHTML = '"' + quotes[counter][0] + '"';
	document.getElementById("quote2").innerHTML = quotes[counter][1] + "<br><br>" + quotes[counter][2];	
	counter = (counter + 1) % quotes.length;
}

function slide()
{
	anim();
	start =	setInterval("anim()", delayTime);
}

function ChangeClient(aForm)
{	
	if (aForm.client[aForm.client.selectedIndex].value == "other")
	{
		aForm.otherclient.style.visibility = "visible";
	}
	else
	{
		aForm.otherclient.style.visibility = "hidden";
	}
}

function ChangeLoc(aForm)
{
	locationMenu = aForm.location;
	marketMenu = aForm.market;
	
	with (locationMenu)
	{
		switch (selectedIndex) {
			case 0:
				nullOptions(marketMenu);
				marketMenu.options[0] = new Option('Choose Location', 'none');
				marketMenu.options[0].selected = true;
				break;
			case 1:
				nullOptions(marketMenu);
				marketMenu.options[0] = new Option("National Electricity Market on the East Coast", "NEM");
				marketMenu.options[1] = new Option("SWIS Electricity Market on the West Coast", "WEM");
				marketMenu.options[2] = new Option("Elsewhere in Australia", "Elsewhere");
				marketMenu.options[0].selected = true;
				break;
			case 2:
				nullOptions(marketMenu);
				marketMenu.options[0] = new Option("Ontario", "Ontario");
				marketMenu.options[1] = new Option("New England", "Elsewhere");
				marketMenu.options[2] = new Option("New York", "Elsewhere");
				marketMenu.options[3] = new Option("PJM", "Elsewhere");
				marketMenu.options[4] = new Option("MISO", "Elsewhere");
				marketMenu.options[5] = new Option("Texas", "Elsewhere");
				marketMenu.options[6] = new Option("Southwest Power Pool", "Elsewhere");
				marketMenu.options[7] = new Option("California", "Elsewhere");
				marketMenu.options[8] = new Option("Alberta", "Elsewhere");
				marketMenu.options[9] = new Option("Elsewhere in North America", "Elsewhere");
				marketMenu.options[0].selected = true;
				break;
			case 3:
				nullOptions(marketMenu);
				marketMenu.options[0] = new Option("Ireland", "Elsewhere");
				marketMenu.options[1] = new Option("UK", "Elsewhere");
				marketMenu.options[2] = new Option("France", "Elsewhere");
				marketMenu.options[3] = new Option("Belgium", "Elsewhere");
				marketMenu.options[4] = new Option("Netherlands", "Elsewhere");
				marketMenu.options[5] = new Option("Spain and Portugal", "Elsewhere");
				marketMenu.options[6] = new Option("Germany", "Elsewhere");
				marketMenu.options[7] = new Option("Austria", "Elsewhere");
				marketMenu.options[8] = new Option("Norway-Swedan-Finland-Denmark", "Elsewhere");
				marketMenu.options[9] = new Option("Switzerland", "Elsewhere");
				marketMenu.options[10] = new Option("Poland", "Elsewhere");
				marketMenu.options[11] = new Option("Czech Republic", "Elsewhere");
				marketMenu.options[12] = new Option("Slovenia", "Elsewhere");
				marketMenu.options[13] = new Option("Italy", "Elsewhere");
				marketMenu.options[14] = new Option("Greece", "Elsewhere");
				marketMenu.options[15] = new Option("Romania", "Elsewhere");
				marketMenu.options[0].selected = true;
				break;
			case 4:
				nullOptions(marketMenu);
				marketMenu.options[0] = new Option("Elsewhere", "Elsewhere");
				marketMenu.options[0].selected = true;
				break;
		}
	}
}

function goToPage(aForm)
{	
	locationMenu = aForm.location;
	marketMenu = aForm.market;
	clientMenu = aForm.client;
	
	if (locationMenu.options[locationMenu.selectedIndex].value == 'none') alert('Please Select a Location');
	else if (marketMenu.options[marketMenu.selectedIndex].value == 'none') alert('Please Select a Market');
	else if (clientMenu.options[clientMenu.selectedIndex].value == 'none') alert('Please Select a Client Type');
	else if (marketMenu.options[marketMenu.selectedIndex].value == 'other' || clientMenu.options[clientMenu.selectedIndex].value == 'other')
	{
		destination = "Other.html";
	}
	else
	{
		destination = "helptrack.aspx";
		destination = destination + "?loc=" + locationMenu.options[locationMenu.selectedIndex].value;
		destination = destination + "&mark=" + marketMenu.options[marketMenu.selectedIndex].value;
		destination = destination + "&client=" + clientMenu.options[clientMenu.selectedIndex].value;
	}
	
	createCookie('HY_Client', aForm.client[aForm.client.selectedIndex].value, 7);
	createCookie('HY_Location', aForm.location[aForm.location.selectedIndex].value, 7);
	createCookie('HY_Market', aForm.market[aForm.market.selectedIndex].value, 7);
	
	if (destination) location.href = destination;
}

function nullOptions(menu)
{
	for (var i = menu.length-1; i >= 0; i--)
	{
		menu.options[i] = null;
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function helpingYouSubmit(aForm, bForm)
{
	if (Validate(aForm) && Validate(bForm))
	{
		if (bForm)
		{
			createCookie('HY_Client', bForm.client[bForm.client.selectedIndex].value, 7);
			createCookie('HY_Location', bForm.location[bForm.location.selectedIndex].value, 7);
			createCookie('HY_Market', bForm.market[bForm.market.selectedIndex].value, 7);
		}
		createCookie("HY_Name", aForm.name.value, 7);
		createCookie("HY_Organisation", aForm.organisation.value, 7);
		createCookie("HY_Email", aForm.email.value, 7);
		createCookie("HY_Phone", aForm.phone.value, 7);
		
		location.href = "helpemail.aspx";
	}
}

function helpingYouLoad(aForm)
{
	if (readCookie("HY_Name"))
		aForm.name.value = readCookie("HY_Name");
	if (readCookie("HY_Organisation"))
		aForm.organisation.value = readCookie("HY_Organisation");
	if (readCookie("HY_Email"))
		aForm.email.value = readCookie("HY_Email");
	if (readCookie("HY_Phone"))
		aForm.phone.value = readCookie("HY_Phone");
}

function wopen(url, name, w, h)
{
	w += 32;
	h += 96;
	var win = window.open(url, name, 'width='+w+',height='+h+',location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
	win.focus();

}


function Validate(theForm)
{
	if (theForm)
	{
		if (theForm.location)
		{
			if (theForm.location.options[theForm.location.selectedIndex].value == 'none')
			{
				alert('Please Select a Location');
				theForm.location.focus();
				return (false);
			}
			if (theForm.market.options[theForm.market.selectedIndex].value == 'none')
			{
				alert('Please Select a Market');
				theForm.market.focus();
				return (false);
			}
			if (theForm.client.options[theForm.client.selectedIndex].value == 'none')
			{
				alert('Please Select a Client Type');
				theForm.client.focus();
				return (false);
			}
		}
		else
		{
			if (theForm.gotcha.value != "")
			{
				location.href = "spam.html";
			}
			if (theForm.name.value == "")
			{
				alert("Please enter your name.");
				theForm.name.focus();
				return (false);
			}
			if (theForm.organisation.value == "")
			{
				alert("Please enter your organisation.");
				theForm.organisation.focus();
				return (false);
			}
			if (theForm.phone.value == "")
			{
				alert("Please enter your phone number.");
				theForm.phone.focus();
				return (false);
			}	  
			if (theForm.email.value == "")
			{
				alert("Please enter your e-mail address.");
				theForm.email.focus();
				return (false);
			}
			if (theForm.email.value.length < 5)
			{
				alert("Please enter a valid e-mail address.");
				theForm.email.focus();
				return (false);
			}
		}
	}
	
	return true;
}
