// Arthur Wang  09/25/07 /water/js/rates.js for /water/rates/calculator.pl 

function validate(frm) {
var themessage = "You are required to complete the following fields: ";
if (frm.customertype.value=="") {
themessage = themessage + "\n - Customer Type";
}
if (frm.metersize.value=="") {
themessage = themessage + "\n -  Meter Size";
}
if (frm.usage.value=="") {
themessage = themessage + "\n -  Water Usage";
}
if (frm.usage.value!="" && isInteger('usage')== false) {
	if (themessage != "You are required to complete the following fields: "){
	themessage = themessage + "\n\nWater Usage must be numbers";}
	else{
	themessage = "Water Usage must be numbers";
	}
}

//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
	//if (event.keyCode == 13) {document.forms[0].submit();}
	return true;
}
else {
alert(themessage);
return false;
   }
}

function Jump(URL){
var NURL = new String(this.location.href + "#" + URL);
window.location.href = NURL;
}

function loadForm(type, size, use, ison){

//document.forms['calculateform'].customertype.selectedIndex = type;
var theType = document.getElementById("customertype");
var theSize = document.getElementById("metersize");
var theUsage = document.getElementById("usage");
//var theTooltip = document.getElementById("tooltipscontrol");
//var themessage ="In the load form\ntype is "+ type +"\n size is " +size +"\n use is " +use;
//alert(themessage);
//var typeOption = document.getElementById("customertype[type]");
//var sizeOption = document.getElementById("metersize[parseInt(size)]");
theType.selectedIndex = type;
theSize.selectedIndex = size;
theUsage.value = use;
if (ison =="") 
{
	//theTooltip.checked = false;
//alert("theTooltip checked is false");
}
else{
	//theTooltip.checked = true;	
//alert("theTooltip checked is true");
	tooltipObj.tooltipDisabled = true;
//alert("tooltipObj tooltipDisabled is " + tooltipObj.tooltipDisabled);
}
}

function isInteger(theName)
{   var i;
	var s = document.getElementById(theName).value
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) {
		return false;
		}
    }
    // All characters are numbers.
    return true;
}


//function controltooltip()
//{   
//alert("IN the controltooltip");
//var thecheckbox = document.getElementById("tooltipscontrol")
//	if (thecheckbox.checked == true){
//		tooltipObj.tooltipDisabled = true;	
//alert("thecheckbox checked is true");
//	} else{
//		tooltipObj.initFormFieldTooltip();	
//alert("thecheckbox checked is false");
//	}

//}