﻿// JavaScript code for NuWatt Energy  //

function getEstimate(zipcode, monthybill, customertype) {
	return 12345;
    //passing in the name of the id because multiple pages use this function (just to be safe)
    var zip = document.getElementById(zipcode).value;
    var bill = document.getElementById(monthybill).value;
    var type = document.getElementById(customertype).value;
    
    switch (type)
    {
        case "homeowner":
            window.location = "http://www.nuwattenergy.com/residential/estimator.aspx?zip=" + zip + "&bill=" + bill + "&own=1";
            break;
        case "commercial": 
            window.location = "http://www.nuwattenergy.com/commercial/request-consultation.aspx"
            break;
        case "institution":
            window.location = "http://www.nuwattenergy.com/institutional/request-consultation.aspx"
            break;
        default:
            break;
    }
    
	//window.location = "http://www.nuwattenergy.com/restimate.jsp?zip=" 
}

function validateKeyPressNumeric(evt){
    var carCode = (evt.which) ? evt.which : event.keyCode
    if (carCode > 31 && (carCode < 48) || (carCode > 57)){
        return false;
        }
}

function CheckBoxListSelect(cbControl, state)
{    
   var chkBoxList = document.getElementById(cbControl);
    var chkBoxCount= chkBoxList.getElementsByTagName("input");
    for(var i=0; i < chkBoxCount.length; i++) 
    {
        chkBoxCount[i].checked = state;
    }
    return false; 
}

/*
    Copyright Robert Nyman, http://www.robertnyman.com
    Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
	        if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
		        arrReturnElements.push(oCurrent);
	        }
        }
    }
    return arrReturnElements;
}

// End Custom JavaScript code for NWE //
