window.onload = function () {

/*	document.getElementById('resZip').onfocus = function () {
		if (this.value=='Enter Your Zip Code') {
			this.value='';
		}
	}
	
	document.getElementById('resZip').onblur = function () {
		if (this.value=='') {
			this.value='Enter Your Zip Code';
		}
	}
	
	
	document.getElementById('comZip').onfocus = function () {
		if (this.value=='Enter Your Zip Code') {
			this.value='';
		}
	}
	
	document.getElementById('comZip').onblur = function () {
		if (this.value=='') {
			this.value='Enter Your Zip Code';
		}
	}*/

}
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(type,ref) {
	if(ref=="") { ref = 34; }
	if(type == "residential") {
		var zip = document.getElementById('resZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			window.location = "http://www.electricchoice.com/Zip_Table.php?ftZip=" + zip + "&type=residential&s2=2&ref=" + ref + "&tableType=2";
		} else {
			alert('Please enter a valid zip code.');
		}
	} else if (type == "commercial") {
		var zip = document.getElementById('comZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			var link = "http://www.utilitychoice.com/commercial/orderForm/?ftZip=" + zip + "&ref=" + ref + "&refUrl=www.electricchoice.com";
			$.fancybox({
			'href'				: link,
			'type'				: 'iframe',
        	'width'				: 750,
			'height'			: 700,
			'hideOnOverlayClick': false,
			'enableEscapeButton': false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
			});
/*			Shadowbox.open({
				content:    link,
				player:     'iframe',
				title:      'Commercial Pricing',
				handleOversize: 'resize',
				height:     700,
        		width:      760
			});*/
		} else {
			alert('Please enter a valid zip code.');
		}
	} else if (type == "commercialSupplier") {
		window.location = "../business/index.php";
	} else {
		window.location = "business/index.php";
	}
}



function submitFormvi(type,ref) {
	if(ref=="") { ref = 34; }
	if(type == "residential") {
		var zip = document.getElementById('comZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			window.location = "http://www.electricchoice.com/Zip_Table.php?ftZip=" + zip + "&type=residential&s2=2&ref=" + ref + "&tableType=2";
		} else {
			alert('Please enter a valid zip code.');
		}
	} else if (type == "commercial") {
		var zip = document.getElementById('comZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			var link = "http://www.utilitychoice.com/commercial/orderForm/?ftZip=" + zip + "&ref=" + ref + "&refUrl=www.electricchoice.com";
			$.fancybox({
			'href'				: link,
			'type'				: 'iframe',
        	'width'				: 750,
			'height'			: 700,
			'hideOnOverlayClick': false,
			'enableEscapeButton': false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
			});
/*			Shadowbox.open({
				content:    link,
				player:     'iframe',
				title:      'Commercial Pricing',
				handleOversize: 'resize',
				height:     700,
        		width:      760
			});*/
		} else {
			alert('Please enter a valid zip code.');
		}
	} else if (type == "commercialSupplier") {
		window.location = "../business/index.php";
	} else {
		window.location = "business/index.php";
	}
}



/*function submitFormC(type,ref) {
	alert('here1');
	if(ref=="") { ref = 34; }
	if(type == "residential") {
		var zip = document.getElementById('resZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			window.location = "http://www.electricchoice.com/Zip_Table.php?ftZip=" + zip + "&type=residential&s2=2&ref=" + ref + "&tableType=2";
		} else {
			alert('Please enter a valid zip code.');
		}
	} else if (type == "commercialtest") {
		var zip = document.getElementById('comZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			var link = "http://www.utilitychoice.com/commercial/orderFormJN/?ftZip=" + zip + "&ref=" + ref + "&refUrl=www.electricchoice.com";
			Shadowbox.open({
				content:    link,
				player:     'iframe',
				title:      'Commercial Pricing',
				handleOversize: 'resize',
				height:     700,
        		width:      760
			});
		} else {
			alert('Please enter a valid zip code.');
		}
	} else {
		window.location = "../business/index.php";
	}
}*/
function submitMatrix1(type,ref) {
	if(ref=="") { ref = 34; }
	if(type == "residential") {
		var zip = document.getElementById('resZip').value;	
		if (zip != "" && IsNumeric(zip) == true && isZip(zip) == true) {
			window.location = "http://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 = "business/index.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,ref){ //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,ref);
		return false 
	} else{
		return true 
	}

}




