// ************************************
// CUSTOM REBATE 
// ************************************	
	

	function ValidateCustomRebate_Form() {
		
		var theForm = document.EEP_CustRebate_Form;
		
		/* --------------------------------- */
		/*		   PROJECT INFORMATION       */
		/* --------------------------------- */
		
		// ACCOUNT NUMBER
		if (theForm.cust_accountnum.value == "") {
			alert("Please fill in the 'Account Number' field to continue.");
			theForm.cust_accountnum.focus();
			return false;
		} else {
			if (isNaN(theForm.cust_accountnum.value) == true) {
				alert("Your 'Account Number' must be all numbers.");
				theForm.cust_accountnum.focus();
				theForm.cust_accountnum.select();
				return false;
			} else {
				if (theForm.cust_accountnum.value.length < 10) {
					alert("The value in the 'Account Number' field must be 10 numbers long.");
					theForm.cust_accountnum.focus();
					return false;
				}
			}
		}
		
		// TAX ID NUMBER
		if (theForm.cust_tax_id.value == "") {
			alert("Please fill in the 'Federal Tax ID Number' field to continue.");
			theForm.cust_tax_id.focus();
			return false;
		} else {
			//11-111111111
			var str = theForm.cust_tax_id.value;
			var regxx = new RegExp("\\d{2}-\\d{7}","g");
			if (regxx.test(str)) {
				// DO NOTHING
			} else {
				alert("The 'Federal Tax ID' field must be in the correct format to continue. (Ex: xx-xxxxxxx)");
				return false;
			}
		}
		
		// COMPANY NAME
		if (theForm.company_name.value == "") {
			alert("Please fill in the 'Company Name' field to continue.");
			theForm.company_name.focus();
			return false;
		}
		
		// CONTACT PERSON NAME
		if (theForm.contact_name.value == "") {
			alert("Please fill in the 'Contact Person' field to continue.");
			theForm.contact_name.focus();
			return false;
		}
		
		// CONTACT PHONE (PART 1/3)
		if (theForm.contact_ph1.value == "") {
			alert("Please insert a numeric value into the 'Phone (Area Code)' field.");
			theForm.contact_ph1.focus();
			return false;
		} else {
			if (isNaN(theForm.contact_ph1.value) == true) {
				alert("Please insert a numeric value into the 'Phone (Area Code)' field.");
				theForm.contact_ph1.focus();
				theForm.contact_ph1.select();
				return false;
			} else {
				if (theForm.contact_ph1.value.length < 3) {
					alert("The value in the 'Phone (Area Code)' field must be 3 characters long.");
					theForm.contact_ph1.focus();
					return false;
				}
			}
		}
		
		// CONTACT PHONE (PART 2/3)
		if (theForm.contact_ph2.value == "") {
			alert("Please insert a numeric value into the 'Phone' field.");
			theForm.contact_ph2.focus();
			return false;
		} else {
			if (isNaN(theForm.contact_ph2.value) == true) {
				alert("Please insert a numeric value into the 'Phone' field.");
				theForm.contact_ph2.focus();
				theForm.contact_ph2.select();
				return false;
			} else {
				if (theForm.contact_ph2.value.length < 3) {
					alert("The value in the 'Phone' field must be 3 characters long.");
					theForm.contact_ph2.focus();
					return false;
				}
			}
		}
		
		// CONTACT PHONE (PART 3/3)
		if (theForm.contact_ph3.value == "") {
			alert("Please insert a numeric value into the 'Phone' field.");
			theForm.contact_ph3.focus();
			return false;
		} else {
			if (isNaN(theForm.contact_ph3.value) == true) {
				alert("Please insert a numeric value into the 'Phone' field.");
				theForm.contact_ph3.focus();
				theForm.contact_ph3.select();
				return false;
			} else {
				if (theForm.contact_ph3.value.length < 3) {
					alert("The value in the 'Phone' field must be 3 characters long.");
					theForm.contact_ph3.focus();
					return false;
				}
			}
		}
		
		// CONTACT EMAIL
		if (theForm.contact_email.value == "") {
			alert("You must insert a value into the 'E-Mail' field to continue.");
			theForm.contact_email.focus();
			return false;
		} else {
			if ((theForm.contact_email.value==null) || (theForm.contact_email.value=="")) {
				alert(alertEmailString);
				theForm.contact_email.focus();
				return false;
			}
			if (EmailCheck(theForm.contact_email.value) == false){
				theForm.contact_email.focus();
				theForm.contact_email.select();
				return false;
			}
		}
		
		var InstallDate_mm = theForm.install_mm[theForm.install_mm.selectedIndex].value;
		var InstallDate_dd = theForm.install_dd[theForm.install_dd.selectedIndex].value;
		var InstallDate_yy = theForm.install_yy[theForm.install_yy.selectedIndex].value;
		var InstallDate = InstallDate_mm + "/" + InstallDate_dd + "/" + InstallDate_yy;
				
		if (isDate(InstallDate) == false) {
			return false
		}
		
		// PROPERTY TYPE
		if (!isChecked("pt_Type",document.EEP_CustRebate_Form)) {
			alert("Please select a 'Property Type' to continue.");
			return valid=false;
		 }
		 
		 /* --------------------------------- */
		
		// Mailing ADDRESS LINE 1
		if (theForm.mailing_add1.value == "") {
			alert("Please fill in the 'Mailing Address: Address Line 1' field to continue.");
			theForm.mailing_add1.focus();
			return false;
		}
		
		// Mailing ADDRESS CITY
		if (theForm.mailing_city.value == "") {
			alert("Please fill in the 'Mailing Address: City' field to continue.");
			theForm.mailing_city.focus();
			return false;
		}
		
		// Mailing ADDRESS ZIP
		if (theForm.mailing_zip.value == "") {
			alert("Please insert a numeric value into the 'Mailing Address: Zip Code' field.");
			theForm.mailing_zip.focus();
			return false;
		} else {
			if (isNaN(theForm.mailing_zip.value) == true) {
				alert("Please insert a numeric value into the 'Mailing Address: Zip Code' field.");
				theForm.mailing_zip.focus();
				theForm.mailing_zip.select();
				return false;
			} else {
				if (theForm.mailing_zip.value.length < 5) {
					alert("The value in the 'Mailing Address: Zip Code' field must be 5 characters long.");
					theForm.mailing_zip.focus();
					return false;
				}
			}
		}
			
		
		/* --------------------------------- */
		
		// INSTALL ADDRESS LINE 1
		if (theForm.install_add1.value == "") {
			alert("Please fill in the 'Install Address: Address Line 1' field to continue.");
			theForm.install_add1.focus();
			return false;
		}
		
		// INSTALL ADDRESS CITY
		if (theForm.install_city.value == "") {
			alert("Please fill in the 'Install Address: City' field to continue.");
			theForm.install_city.focus();
			return false;
		}
		
		// INSTALL ADDRESS ZIP
		if (theForm.install_zip.value == "") {
			alert("Please insert a numeric value into the 'Install Address: Zip Code' field.");
			theForm.install_zip.focus();
			return false;
		} else {
			if (isNaN(theForm.install_zip.value) == true) {
				alert("Please insert a numeric value into the 'Install Address: Zip Code' field.");
				theForm.install_zip.focus();
				theForm.install_zip.select();
				return false;
			} else {
				if (theForm.install_zip.value.length < 5) {
					alert("The value in the 'Install Address: Zip Code' field must be 5 characters long.");
					theForm.install_zip.focus();
					return false;
				}
			}
		}
		
		// FACILITY HOURS
		var p = 0;
		var a = new Array();
		a = document.getElementsByName("facility_hours[]");
		for(i=0;i<a.length;i++){
			if(a[i].checked){
				p=1;
			}
		}
		if (p==0){
			alert("You must choose a day in the 'Facility Days and Hours or Operation' field to continue.");
			return false;
		}
		
		
		if (theForm.terms_conditions.checked == false) {
			alert("You must agree to the Terms and Conditions to continue.");
			return false;
		}
		
		
		allowExit = true;
		return true;
		//return true;		
/*		if (!isChecked("facility_hours",document.EEP_CustRebate_Form)) {
			alert("You must choose a day in the 'Facility Days and Hours or Operation' field to continue.");
			return false;
		}
		
		
		*/
		//return true;
	}
	
	function Pres_FacilityDays() {
		var theForm = document.EEP_CustRebate_Form;

		// FACILITY HOURS
		var a = new Array();
		a = document.getElementsByName("facility_hours[]");
		for(i=0;i<a.length;i++){
			if(a[i].checked){
				switch(a[i].value) {
					case "Monday":
						theForm.mon_open.disabled = false;
						theForm.mon_close.disabled = false;
						break;
					case "Tuesday":
						theForm.tue_open.disabled = false;
						theForm.tue_close.disabled = false;
						break;
					case "Wednesday":
						theForm.wed_open.disabled = false;
						theForm.wed_close.disabled = false;
						break;
					case "Thursday":
						theForm.thu_open.disabled = false;
						theForm.thu_close.disabled = false;
						break;
					case "Friday":
						theForm.fri_open.disabled = false;
						theForm.fri_close.disabled = false;
						break;
					case "Saturday":
						theForm.sat_open.disabled = false;
						theForm.sat_close.disabled = false;
						break;
					case "Sunday":
						theForm.sun_open.disabled = false;
						theForm.sun_close.disabled = false;
						break;
				}
			}
			if(!a[i].checked){
				switch(a[i].value) {
					case "Monday":
						theForm.mon_open.disabled = true;
						theForm.mon_close.disabled = true;
						break;
					case "Tuesday":
						theForm.tue_open.disabled = true;
						theForm.tue_close.disabled = true;
						break;
					case "Wednesday":
						theForm.wed_open.disabled = true;
						theForm.wed_close.disabled = true;
						break;
					case "Thursday":
						theForm.thu_open.disabled = true;
						theForm.thu_close.disabled = true;
						break;
					case "Friday":
						theForm.fri_open.disabled = true;
						theForm.fri_close.disabled = true;
						break;
					case "Saturday":
						theForm.sat_open.disabled = true;
						theForm.sat_close.disabled = true;
						break;
					case "Sunday":
						theForm.sun_open.disabled = true;
						theForm.sun_close.disabled = true;
						break;
				}
			}
		}
	}
			

// ************************************
// CUSTOM REBATE (CONTINUED FORM)
// ************************************

function Custom_Rebate_MeasureType() {
			
				var span_kwh_saved = document.getElementById('span_kwh_saved');
				var span_kw_saved = document.getElementById('span_kw_saved');
			
				if (document.getElementById('measure_type') != undefined) {
					var theForm = document.EEP_CustomRebate_Cont;
					var measureType = document.getElementById('measure_type');
					var selectedIndex = measureType.selectedIndex;
					var selectedType = measureType.options[selectedIndex].value;
					
				
					switch(selectedType) {
						case "11":
							kWh_subtotal = 0.05;
							kW_subtotal = 50.00;
							break;
							
						case "12":
							kWh_subtotal = 0.10;
							kWh_subtotal = kWh_subtotal.toFixed(2);
							kW_subtotal = 100.00;
							break;
							
						case "13":
							kWh_subtotal = 0.08;
							kW_subtotal = 100.00;
							break;
					}
					
				} else {
					kWh_subtotal = 0.05;
					kW_subtotal = 50.00;
				}
				
				span_kwh_saved.innerHTML = kWh_subtotal;
				span_kw_saved.innerHTML = kW_subtotal;
				
				//alert("KWH: "+Get_KWH_Total());
				//alert("KW: "+Get_KW_Total());
				Update_Rebate();
			}
			
			function Get_KWH_Total() {
				var span_kwh_saved = document.getElementById('span_kwh_saved').innerHTML;
				
				return span_kwh_saved;
			}
			
			function Get_KW_Total() {
				var span_kw_saved = document.getElementById('span_kw_saved').innerHTML;
				
				return span_kw_saved;
			}

	

	function Update_Rebate() {
		var theForm = document.EEP_CustomRebate_Cont;
		
		// VALUE INPUT BOXES
		var Annual_Baseline_KWH = theForm.baseline_annual_kwh;
		var NEW_Annual_KWH = theForm.new_annualkwh;
		
		var Baseline_KW = theForm.baseline_kw;
		var NEW_KW = theForm.new_kw;
		
		// VIEWABLE TOTALS
		var Annual_Savings_KWH = document.getElementById("kwh_annual_savings");
		var Subtotal_KWH = document.getElementById("subtotal_kwh");
		
		var KW_Savings = document.getElementById("kw_savings");
		var Subtotal_KW = document.getElementById("subtotal_kw");
		
		// HIDDEN TOTALS
		var Hidden_Annual_Savings_KWH = theForm.hide_kwh_annual_savings;
		var Hidden_Subtotal_KWH = theForm.hide_subtotal_kwh;
		
		var Hidden_KW_Savings = theForm.hide_kw_savings;
		var Hidden_Subtotal_KW = theForm.hide_subtotal_kw;
		
		// ************************************
		// 	KILOWATTS / HOUR
		// ************************************
		
		if ((Annual_Baseline_KWH.value != "") && (NEW_Annual_KWH.value != "")) {
			
			// CHECK TO SEE IF ITS A NUMBER
			if (isNaN(Annual_Baseline_KWH.value) == true) {
				alert("The 'Annual Baseline kWh' field must be a number.");
				return false;	
			}
			
			// CHECK TO SEE IF ITS A NUMBER
			if (isNaN(NEW_Annual_KWH.value) == true) {
				alert("The 'New Annual kWh' field must be a number.");
				return false;	
			}
			
			// CHECK TO SEE IF THE ANNUAL BASELINE KWH IS SMALLER THAN THE NEW ANNUAL KWH
			/*
			if (parseInt(Annual_Baseline_KWH.value) <= parseInt(NEW_Annual_KWH.value)) {
				
				// CLEAR ALL INFO
				Annual_Baseline_KWH.value = "";
				NEW_Annual_KWH.value = "";
				Annual_Savings_KWH.innerHTML = "( Calculated Automatically ) ";
				Hidden_Annual_Savings_KWH.value = "";
				Hidden_Subtotal_KWH.value = "";
				Subtotal_KWH.innerHTML = "( Calculated Automatically )";
				
				Annual_Baseline_KWH.focus();
				alert("This measure is not saving you any money, please contact DP&L for further instructions.\n\nPlease review the following fields: 'Baseline Annual kWh' & 'New Annual kWh'.");
				return false;
			}
			*/
			
			// SET TOTAL (AB_KWH-NA_KWH)
			var KWH_Total = (Annual_Baseline_KWH.value - NEW_Annual_KWH.value);
			
			Annual_Savings_KWH.innerHTML = KWH_Total;
			Hidden_Annual_Savings_KWH.value = KWH_Total;
			
			calc_KWH_value = Get_KWH_Total();
			//alert(parseInt(KWH_Total)+" * "+calc_KWH_value+" = "+(parseInt(KWH_Total) * calc_KWH_value));
			
			Subtotal_KWH_Value = (parseInt(KWH_Total) * calc_KWH_value);
			Hidden_Subtotal_KWH.value = Subtotal_KWH_Value.toFixed(2);
			
			Subtotal_KWH.innerHTML = formatCurrency(Subtotal_KWH_Value.toFixed(2));
		}
		
		if ((Annual_Baseline_KWH.value == "") && (NEW_Annual_KWH.value == "")) {
			Annual_Savings_KWH.innerHTML = "( Calculated Automatically ) ";
			Hidden_Annual_Savings_KWH.value = "";
			Hidden_Subtotal_KWH.value = "";
			Subtotal_KWH.innerHTML = "( Calculated Automatically )";
			return false;
		}
		
		// ************************************
		// 	KILOWATTS
		// ************************************
		
		if ((Baseline_KW.value != "") && (NEW_KW.value != "")) {
			
			// CHECK TO SEE IF ITS A NUMBER
			if (isNaN(Baseline_KW.value) == true) {
				alert("The 'Baseline kW' field must be a number.");
				return false;	
			}
			
			// CHECK TO SEE IF ITS A NUMBER
			if (isNaN(NEW_KW.value) == true) {
				alert("The 'New kW' field must be a number.");
				return false;	
			}
			
			// CHECK TO SEE IF THE BASELINE KW IS LARGER THAN NEW KW
			/*
			if (parseInt(Baseline_KW.value) <= parseInt(NEW_KW.value)) {
				
				// CLEAR ALL INFO
				Baseline_KW.value = "";
				NEW_KW.value = "";
				KW_Savings.innerHTML = "( Calculated Automatically ) ";
				Hidden_KW_Savings.value = "";
				Hidden_Subtotal_KW.value = "";
				Subtotal_KW.innerHTML = "( Calculated Automatically )";
				
				Baseline_KW.focus();
				alert("This measure is not saving you any money, please contact DP&L for further instructions.\n\nPlease review the following fields to make sure everything was entered correctly: 'Baseline kW' & 'New kW'");

				return false;
			}
			*/
			
			var KW_Total = (Baseline_KW.value - NEW_KW.value);
			
			KW_Savings.innerHTML = KW_Total.toFixed(2);
			Hidden_KW_Savings.value = KW_Total;
			
			//alert(KW_Total * 50.00);
			
			calc_KW_value = Get_KW_Total();
			//alert(parseInt(KW_Total)+" * "+calc_KW_value+" = "+(parseInt(KW_Total) * calc_KW_value));
			
			Subtotal_KW_Value = (KW_Total * calc_KW_value);
			
			Hidden_Subtotal_KW.value = Subtotal_KW_Value.toFixed(2);
			
			Subtotal_KW.innerHTML = formatCurrency(Subtotal_KW_Value.toFixed(2));
			
			if ((Baseline_KW.value == "") && (NEW_KW.value == "")) {
				KW_Savings.innerHTML = "( Calculated Automatically ) ";
				Hidden_KW_Savings.value = "";
				Hidden_Subtotal_KW.value = "";
				Subtotal_KW.innerHTML = "( Calculated Automatically )";
				return false;
			}

		}
		
		var allowExit = true;
		
	}
	
	function Validate_CustomRebate_Cont() {
		var theForm = document.EEP_CustomRebate_Cont	
	
		/* --------------------------------- */
		/*		   PROJECT INFORMATION       */
		/* --------------------------------- */
		
		// MEASURE TYPE, MANUFACTURER, AND DESCRIPTION
		if (theForm.measure_desc.value == "") {
			alert("Please fill in the 'Measure Type, Manufacturer, and Description' field to continue.");
			theForm.measure_desc.focus();
			return false;
		}
		
		// MEASURE EQUIPMENT COST
		if (theForm.measure_equipcost.value == "") {
			alert("Please fill in the 'Measure Equipment Cost' field to continue.");
			theForm.measure_equipcost.focus();
			return false;
		} else {
			if (isNaN(theForm.measure_equipcost.value) == true) {
				alert("The 'Measure Equipment Cost' field must be a numeric field to continue.");
				theForm.measure_equipcost.focus();
				theForm.measure_equipcost.select();
				return false;
			}
				
		}
		
		// MEASURE INSTALLED COST
		if (theForm.measure_installcost.value == "") {
			alert("Please fill in the 'Measure Installation Cost' field to continue.");
			theForm.measure_installcost.focus();
			return false;
		} else {
			if (isNaN(theForm.measure_installcost.value) == true) {
				alert("The 'Measure Equipment Cost' field must be a numeric field to continue.");
				theForm.measure_installcost.focus();
				theForm.measure_installcost.select();
				return false;
			}
				
		}
		
		// Measure Life Expectancy (years)
		if (theForm.measure_lifeexpect.value == "") {
			alert("Please fill in the 'Measure Life Expectancy (years)' field to continue.");
			theForm.measure_lifeexpect.focus();
			return false;
		} else {
			if (isNaN(theForm.measure_lifeexpect.value) == true) {
				alert("The 'Measure Life Expectancy (years)' field must be a numeric field to continue.");
				theForm.measure_lifeexpect.focus();
				theForm.measure_lifeexpect.select();
				return false;
			}
				
		}
		
		// Useful life (years)
		/*
		if (theForm.measure_usefullife.value == "") {
			alert("Please fill in the 'Useful life (years)' field to continue.");
			theForm.measure_usefullife.focus();
			return false;
		} else {
			if (isNaN(theForm.measure_usefullife.value) == true) {
				alert("The 'Useful life (years)' field must be a numeric field to continue.");
				theForm.measure_usefullife.focus();
				theForm.measure_usefullife.select();
				return false;
			}
				
		}
		*/
		
		// OPERATING PERIOD (MONTHS, DAYS, TIMES)
		if (theForm.oper_period.value == "") {
			alert("Please fill in the 'Operating Period (months, days, times)' field to continue.");
			theForm.oper_period.focus();
			return false;
		}
		
		// BASELINE ANNUAL KWH
		if (theForm.baseline_annual_kwh.value == "") {
			alert("Please fill in the 'Baseline Annual kWh' field to continue.");
			theForm.baseline_annual_kwh.focus();
			return false;
		}
		
		// NEW ANNUAL KWH
		if (theForm.new_annualkwh.value == "") {
			alert("Please fill in the 'New Annual kWh' field to continue.");
			theForm.new_annualkwh.focus();
			return false;
		}
		
		// BASELINE KW
		if (theForm.baseline_kw.value == "") {
			alert("Please fill in the 'Baseline kW' field to continue.");
			theForm.baseline_kw.focus();
			return false;
		}
		
		// NEW ANNUAL KWH
		if (theForm.new_kw.value == "") {
			alert("Please fill in the 'New kW' field to continue.");
			theForm.new_kw.focus();
			return false;
		}
		
		if ( (parseInt(theForm.hide_subtotal_kwh.value) < 0) && (parseInt(theForm.hide_subtotal_kw.value) < 0) ) {
			alert("Either the Kilowatts or Kilowatts / Hour must be a positive number to continue.");
			return false;	
		}
		
		return true;
	}
	
	function Cust_InstallAddressChecked() {
				
		var theForm = document.EEP_CustRebate_Form;
	
		if (theForm.install_sameasabove.checked) {
			if (theForm.mailing_state[theForm.mailing_state.selectedIndex].value != "OH") {
				alert("The installation address must be in Ohio.");
				theForm.install_sameasabove.checked = false;
				return false;
			} else {
				theForm.install_add1.value = theForm.mailing_add1.value;
				theForm.install_add2.value = theForm.mailing_add2.value;
				theForm.install_city.value = theForm.mailing_city.value;
				theForm.install_zip.value = theForm.mailing_zip.value;
			}
		} else {
			theForm.install_add1.value = "";
			theForm.install_add2.value = "";
			theForm.install_city.value = "";
			theForm.install_zip.value = "";
		}
	}
	
	function Cust_FacilityDays() {
		var theForm = document.EEP_CustRebate_Form;

		// FACILITY HOURS
		var a = new Array();
		a = document.getElementsByName("facility_hours[]");
		for(i=0;i<a.length;i++){
			if(a[i].checked){
				switch(a[i].value) {
					case "Monday":
						theForm.mon_open.disabled = false;
						theForm.mon_close.disabled = false;
						break;
					case "Tuesday":
						theForm.tue_open.disabled = false;
						theForm.tue_close.disabled = false;
						break;
					case "Wednesday":
						theForm.wed_open.disabled = false;
						theForm.wed_close.disabled = false;
						break;
					case "Thursday":
						theForm.thu_open.disabled = false;
						theForm.thu_close.disabled = false;
						break;
					case "Friday":
						theForm.fri_open.disabled = false;
						theForm.fri_close.disabled = false;
						break;
					case "Saturday":
						theForm.sat_open.disabled = false;
						theForm.sat_close.disabled = false;
						break;
					case "Sunday":
						theForm.sun_open.disabled = false;
						theForm.sun_close.disabled = false;
						break;
				}
			}
			if(!a[i].checked){
				switch(a[i].value) {
					case "Monday":
						theForm.mon_open.disabled = true;
						theForm.mon_close.disabled = true;
						break;
					case "Tuesday":
						theForm.tue_open.disabled = true;
						theForm.tue_close.disabled = true;
						break;
					case "Wednesday":
						theForm.wed_open.disabled = true;
						theForm.wed_close.disabled = true;
						break;
					case "Thursday":
						theForm.thu_open.disabled = true;
						theForm.thu_close.disabled = true;
						break;
					case "Friday":
						theForm.fri_open.disabled = true;
						theForm.fri_close.disabled = true;
						break;
					case "Saturday":
						theForm.sat_open.disabled = true;
						theForm.sat_close.disabled = true;
						break;
					case "Sunday":
						theForm.sun_open.disabled = true;
						theForm.sun_close.disabled = true;
						break;
				}
			}
		}
	}