/*
Copyright © 2005, KEEP. All Rights Reserved.
http://www.uwsp.com/keep
Xai Vang
	
This script may not be used for any purpose without prior consent from KEEP.
Design for Appliance Survey Sheet
*/

window.onload=function(){
this.document.forms[0].onsubmit=function(){

var bool=true, tx='';
with(document.f){

if(uname.value=='')tx='\rname';
if(uemail.value=='')tx='\remail';
if(r1a.value==''||r1b.value==''||r1c.value==''){
if(r1a.value=='')tx+='\r#1 - 1    ';else tx+='#1 -       ';
if(r1b.value=='')tx+='2    ';else tx+='      ';
if(r1c.value=='')tx+='3'}

if(r2a.value==''||r2b.value==''||r2c.value==''){
if(r2a.value=='')tx+='\r#2 - 1    ';else tx+='\r#2 -       ';
if(r2b.value=='')tx+='2    ';else tx+='      ';
if(r2c.value=='')tx+='3'}

if(r3a.value==''||r3b.value==''||r3c.value==''){
if(r3a.value=='')tx+='\r#3 - 1    ';else tx+='\r#3 -       ';
if(r3b.value=='')tx+='2    ';else tx+='      ';
if(r3c.value=='')tx+='3'}

if(!(r3[0].checked||r3[1].checked)||!(r4[0].checked||r4[1].checked)||!(r5[0].checked||r5[1].checked)){
if(r3[0].checked||r3[1].checked)tx+='\r#4 -       ';else tx+='\r#4 - 1    ';
if(r4[0].checked||r4[1].checked)tx+='      ';else tx+='2    ';
if(!(r5[0].checked||r5[1].checked))tx+='3'}

if(!(r8[0].checked||r8[1].checked)||!(r9[0].checked||r9[1].checked)||!(r10[0].checked||r10[1].checked)){
if(r8[0].checked||r8[1].checked)tx+='\r#5 -       ';else tx+='\r#5 - 1    ';
if(r9[0].checked||r9[1].checked)tx+='      ';else tx+='2    ';
if(!(r10[0].checked||r10[1].checked))tx+='3'}

if(r6a.value==''||r6b.value==''||r6c.value==''){
if(r6a.value=='')tx+='\r#6 - 1    ';else tx+='\r#6 -       ';
if(r6b.value=='')tx+='2    ';else tx+='      ';
if(r6c.value=='')tx+='3'}

if(r13a.value==''||r13b.value==''||r13c.value==''){
if(r13a.value=='')tx+='\r#13 - 1    ';else tx+='\r#13 -       ';
if(r13b.value=='')tx+='2    ';else tx+='      ';
if(r13c.value=='')tx+='3'}
}
if(tx){
bool=false;
alert('The following questions are required:\r'+tx+'\r\rPlease, complete them before submitting this survey.\rThank you.');
}else if(!confirm("Are you sure you want to submit this survey?"))bool=false;
return bool;
}

with(document.f){
r3a.onkeyup=function(){
ta=this.value*30;
if(isNaN(ta))ta=0;
r7a.value=ta+' hrs';
r8a.value=720-parseInt(r7a.value)+' hrs';
r2a.onkeyup()
}

r3b.onkeyup=function(){
tb=this.value*30;
if(isNaN(tb))tb=0;
r7b.value=tb+' hrs';
r8b.value=720-parseInt(r7b.value)+' hrs';
r2b.onkeyup()}

r3c.onkeyup=function(){
tc=this.value*30;
if(isNaN(tc))tc=0;
r7c.value=tc+' hrs';
r8c.value=720-parseInt(r7c.value)+' hrs';
r2c.onkeyup()}

r2a.onkeyup=function(){
if(r7a.value!=''){
r9a.value=r2a.value*parseInt(r7a.value)+' watt-hrs';
r6a.onkeyup()}}

r2b.onkeyup=function(){
if(r7b.value!=''){
r9b.value=r2b.value*parseInt(r7b.value)+' watt-hrs';
r6b.onkeyup()}}

r2c.onkeyup=function(){
if(r7c.value!=''){
r9c.value=r2c.value*parseInt(r7c.value)+' watt-hrs';
r6c.onkeyup()}}

r6a.onkeyup=function(){
r10a.value=this.value*parseInt(r8a.value)+' watt-hrs';
r11a.value=parseInt(r9a.value)+parseInt(r10a.value)+' watt-hrs';
r12a.value=parseInt(r11a.value)/1000+' kWh/month';
//rank(r12a.value,r12b.value,r12c.value)
}

r6b.onkeyup=function(){
r10b.value=this.value*parseInt(r8b.value)+' watt-hrs';
r11b.value=parseInt(r9b.value)+parseInt(r10b.value)+' watt-hrs';
r12b.value=parseInt(r11b.value)/1000+' kWh/month';
//rank(r12a.value,r12b.value,r12c.value)
}

r6c.onkeyup=function(){
r10c.value=this.value*parseInt(r8c.value)+' watt-hrs';
r11c.value=parseInt(r9c.value)+parseInt(r10c.value)+' watt-hrs';
r12c.value=parseInt(r11c.value)/1000+' kWh/month';
//rank(r12a.value,r12b.value,r12c.value)
}
}}//end onload

function rank(a,b,c){if(a!=''&b!=''&c!=''){
//have computer rank number 13 automatically
a=a.substr(0,a.indexOf(' '));
a+=','+b.substr(0,b.indexOf(' '));
a+=','+c.substr(0,c.indexOf(' '));
a=a.split(',').sort(s)
with(document.f){
r13a.value=a[2]+' kWh/month'
r13b.value=a[1]+' kWh/month'
r13c.value=a[0]+' kWh/month'}
}else{return(null)}}

function s(a,b){return(a-b)} 
