function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
function isZip(s) {
	// Check for correct zip code
	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
	
	if (!reZip.test(s)) {
	  //alert("Zip Code Is Not Valid");
	  return false;
	}
	return true;
}
function submitForm(ref) {
	if(ref=="") { ref = 46; }
	var type = document.getElementById('type').value;	
	switch(type) {
		case "residential":
			var zip = document.getElementById('resZip').value;	
			if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
				window.location = "http://www.pennsylvania-electric-company.com/news/zip_tables.php?ftZip=" + zip + "&type=residential&s2=2&ref=" + ref + "&tableType=2";
			} else {
				alert('Please enter a valid zip code.');
			}
			break;
		case "commercial":
			window.location = "http://www.pennsylvania-electric-company.com/commercial_form.php";
			break;
		default:
			alert('Please select plan type.');
	}
}
function submitMatrix1(type,ref) {
	if(ref=="") { ref = 46; }
	if(type == "residential") {
		var zip = document.getElementById('resZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			window.location = "https://www.electricchoice.com/affiliateTable.php?ftZip=" + zip + "&type=residential&s2=2&ref=" + ref + "&tableType=1";
		} else {
			alert('Please enter a valid zip code.');
		}
	} else {
		window.location = "signup.php";
	}
}
function supplierSearch() {
	var q = document.getElementById('supplierSearch').value;
	var param = "q=" + q;
	$.ajax({   
		type: "GET",   
		url: "inc/supplierSearch.php",   
		data: param,   
		dataType: "text/html",   
		success: function(html){ 
			$("#scroll-pane").html(html);  
		}
	});
}
function checkEnter(e,fm){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	} else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		submitForm(fm);
		return false 
	} else{
		return true 
	}

}
