var imageArray = new Array(2)
imageArray[0] = new Image(25,30)
imageArray[0].src = "../../images/blue.gif"
imageArray[1] = new Image(25,30)
imageArray[1].src = "../../images/red.gif"

clockTower = new Object();
clockTower.empty = new Array(" ");
clockTower.myTimes = new Array(25);
clockTower.myValues = new Array(25);

var myNum;

for (i = 0; i < 24; i++) {
	if (i < 10){
		myNum = "0" + i;
	} else  {
		myNum = i;
	};
	clockTower.myTimes[i] = myNum + ":00";
	clockTower.myValues[i] = i;	
}
clockTower.myTimes[24] = "23:59";
clockTower.myValues[24] = "24";

function wdStartMorning_OnChange()
{	
	if (document.PowerConnForm.wdStartMorning.selectedIndex == 24){
		document.PowerConnForm.wdStartMorning.selectedIndex = 0;
	};
	myIndex = document.PowerConnForm.wdStartMorning.selectedIndex;
	myLength = 24 - myIndex;
	mySelected = document.PowerConnForm.wdEndMorning[document.PowerConnForm.wdEndMorning.selectedIndex].value;
	myNewSelected = 1;
  	document.PowerConnForm.wdEndMorning.length = myLength + 1;
  	for(i = 0; i < myLength; i++){
  			myStartTime = myIndex + i + 1;
  			document.PowerConnForm.wdEndMorning.options[i + 1].text = clockTower.myTimes[myStartTime];
  			document.PowerConnForm.wdEndMorning.options[i + 1].value = clockTower.myValues[myStartTime];
  			if (mySelected == clockTower.myValues[myStartTime]){
  				myNewSelected = i + 1;
  			};
  	};
  	document.PowerConnForm.wdEndMorning.selectedIndex = 0;
  	document.PowerConnForm.wdEndMorning.selectedIndex = myNewSelected;
  	wdEndMorning_OnChange();
}

function wdEndMorning_OnChange()
{	
	myIndex = document.PowerConnForm.wdEndMorning.selectedIndex + document.PowerConnForm.wdStartMorning.selectedIndex;
	myLength = 24 - myIndex + 1;
	mySelected = document.PowerConnForm.wdStartEvening[document.PowerConnForm.wdStartEvening.selectedIndex].value;
	myNewSelected = 0;
  	document.PowerConnForm.wdStartEvening.length = myLength + 1;
  	if(myIndex == 0){
  		j = 0;
  	} else {
  		j = 1;
  	};
  	for(i = 0; i < myLength; i++){
  			myStartTime = myIndex + i;
  			if (myStartTime > 0){
  				document.PowerConnForm.wdStartEvening.options[i + j].text = clockTower.myTimes[myStartTime];
  				document.PowerConnForm.wdStartEvening.options[i + j].value = clockTower.myValues[myStartTime];
  			
  				if (mySelected == clockTower.myValues[myStartTime]){
  					myNewSelected = i + 1;
  				};
  			};	
  	};
  	document.PowerConnForm.wdStartEvening.selectedIndex = 0;
  	document.PowerConnForm.wdStartEvening.selectedIndex = myNewSelected;
  	wdStartEvening_OnChange();
}

function wdStartEvening_OnChange()
{	
	if (document.PowerConnForm.wdStartEvening.selectedIndex == (document.PowerConnForm.wdStartEvening.length - 1)){
		document.PowerConnForm.wdStartEvening.selectedIndex = 0;
	};
	if (document.PowerConnForm.wdStartEvening.selectedIndex == 0) {
		document.PowerConnForm.wdEndEvening.length = 1;
		document.PowerConnForm.wdEndEvening.selectedIndex = 0;
	} else {
		if (document.PowerConnForm.wdEndMorning.selectedIndex + document.PowerConnForm.wdStartMorning.selectedIndex == 0){
			myIndex = 1
		} else { 
			myIndex = 0
		};
		myIndex = myIndex + document.PowerConnForm.wdEndMorning.selectedIndex + document.PowerConnForm.wdStartMorning.selectedIndex + document.PowerConnForm.wdStartEvening.selectedIndex;
		myLength = 24 - myIndex + 1;
		mySelected = document.PowerConnForm.wdEndEvening[document.PowerConnForm.wdEndEvening.selectedIndex].value;
		myNewSelected = 1;
  		document.PowerConnForm.wdEndEvening.length = myLength + 1;
  		for(i = 0; i < myLength; i++){
  			myStartTime = myIndex + i;
  			document.PowerConnForm.wdEndEvening.options[i + 1].text = clockTower.myTimes[myStartTime];
  			document.PowerConnForm.wdEndEvening.options[i + 1].value = clockTower.myValues[myStartTime];
  			if (mySelected == clockTower.myValues[myStartTime]){
  				myNewSelected = i + 1;
  			};
  		};
  	};
  	document.PowerConnForm.wdEndEvening.selectedIndex = 0;
  	document.PowerConnForm.wdEndEvening.selectedIndex = myNewSelected;
  	changeImageWD();
}

function weStartMorning_OnChange()
{	
	if (document.PowerConnForm.weStartMorning.selectedIndex == 24){
		document.PowerConnForm.weStartMorning.selectedIndex = 0;
	};
	myIndex = document.PowerConnForm.weStartMorning.selectedIndex;
	myLength = 24 - myIndex;
	mySelected = document.PowerConnForm.weEndMorning[document.PowerConnForm.weEndMorning.selectedIndex].value;
	myNewSelected = 1;
  	document.PowerConnForm.weEndMorning.length = myLength + 1;
  	for(i = 0; i < myLength; i++){
  			myStartTime = myIndex + i + 1;
  			document.PowerConnForm.weEndMorning.options[i + 1].text = clockTower.myTimes[myStartTime];
  			document.PowerConnForm.weEndMorning.options[i + 1].value = clockTower.myValues[myStartTime];
  			if (mySelected == clockTower.myValues[myStartTime]){
  				myNewSelected = i + 1;
  			};
  	};
  	document.PowerConnForm.weEndMorning.selectedIndex = 0;
  	document.PowerConnForm.weEndMorning.selectedIndex = myNewSelected;
  	weEndMorning_OnChange();
}

function weEndMorning_OnChange()
{	
	myIndex = document.PowerConnForm.weEndMorning.selectedIndex + document.PowerConnForm.weStartMorning.selectedIndex;
	myLength = 24 - myIndex + 1;
	mySelected = document.PowerConnForm.weStartEvening[document.PowerConnForm.weStartEvening.selectedIndex].value;
	myNewSelected = 0;
  	document.PowerConnForm.weStartEvening.length = myLength + 1;
  	if(myIndex == 0){
  		j = 0;
  		//alert("hello");
  	} else {
  		j = 1;
  	};
  	for(i = 0; i < myLength; i++){
  		myStartTime = myIndex + i;
  		
  			document.PowerConnForm.weStartEvening.options[i + j].text = clockTower.myTimes[myStartTime];
  			document.PowerConnForm.weStartEvening.options[i + j].value = clockTower.myValues[myStartTime];
  			if (mySelected == clockTower.myValues[myStartTime]){
  				myNewSelected = i + 1;
  			};
  				
  	};
  	document.PowerConnForm.weStartEvening.selectedIndex = 0;
  	document.PowerConnForm.weStartEvening.selectedIndex = myNewSelected;
  	weStartEvening_OnChange();
}

function weStartEvening_OnChange()
{	
	if (document.PowerConnForm.weStartEvening.selectedIndex == (document.PowerConnForm.weStartEvening.length - 1)){
		document.PowerConnForm.weStartEvening.selectedIndex = 0;
	};
	if (document.PowerConnForm.weStartEvening.selectedIndex == 0) {
		document.PowerConnForm.weEndEvening.length = 1;
		document.PowerConnForm.weEndEvening.selectedIndex = 0;
	} else {
		if (document.PowerConnForm.weEndMorning.selectedIndex + document.PowerConnForm.weStartMorning.selectedIndex == 0){
			myIndex = 1
		} else { 
			myIndex = 0
		};
		myIndex = myIndex + document.PowerConnForm.weEndMorning.selectedIndex + document.PowerConnForm.weStartMorning.selectedIndex + document.PowerConnForm.weStartEvening.selectedIndex;
		myLength = 24 - myIndex + 1;
		mySelected = document.PowerConnForm.weEndEvening[document.PowerConnForm.weEndEvening.selectedIndex].value;
		myNewSelected = 1;
  		document.PowerConnForm.weEndEvening.length = myLength + 1;
  		for(i = 0; i < myLength; i++){
  			myStartTime = myIndex + i;
  			document.PowerConnForm.weEndEvening.options[i + 1].text = clockTower.myTimes[myStartTime];
  			document.PowerConnForm.weEndEvening.options[i + 1].value = clockTower.myValues[myStartTime];
  			if (mySelected == clockTower.myValues[myStartTime]){
  				myNewSelected = i + 1;
  			};
  		};
  	};
  	document.PowerConnForm.weEndEvening.selectedIndex = 0;
  	document.PowerConnForm.weEndEvening.selectedIndex = myNewSelected;
  	changeImageWE();
}

function changeImageWD(){
	myMorningStart = document.PowerConnForm.wdStartMorning.selectedIndex;
	myMorningStop = document.PowerConnForm.wdEndMorning.selectedIndex + myMorningStart
	myEveningStart = document.PowerConnForm.wdStartEvening.selectedIndex + myMorningStop;
	myEveningStop = document.PowerConnForm.wdEndEvening.selectedIndex + myEveningStart;
	for (i = 0; i < document.PowerConnForm.wd.length; i ++) {
		if (((i >= myMorningStart) && (i <=  myMorningStop - 1)) || ((i >= myEveningStart - 1) && (i <= myEveningStop - 2))){
			document.PowerConnForm.wd[i].src = imageArray[1].src;
		} else {
		document.PowerConnForm.wd[i].src = imageArray[0].src;
		};
	};
}

function changeImageWE(){
	myMorningStart = document.PowerConnForm.weStartMorning.selectedIndex;
	myMorningStop = document.PowerConnForm.weEndMorning.selectedIndex + myMorningStart
	myEveningStart = document.PowerConnForm.weStartEvening.selectedIndex + myMorningStop;
	myEveningStop = document.PowerConnForm.weEndEvening.selectedIndex + myEveningStart;
	for (i = 0; i < document.PowerConnForm.we.length; i ++) {
		if (((i >= myMorningStart) && (i <=  myMorningStop - 1)) || ((i >= myEveningStart - 1) && (i <= myEveningStop - 2))){
			document.PowerConnForm.we[i].src = imageArray[1].src;
		} else {
		document.PowerConnForm.we[i].src = imageArray[0].src;
		};
	};
}