// Application  : Bandwidth Usage Estimator
// Created      : 09/01/2006 KS
// Last Updated : 03/09/2008 IB

function isKeyEnter(e) {
	var key = window.event ? e.keyCode : e.which;
	if (key==13) {
		calculateUsage();
		return false;
	}
}

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 getStringyRecService(bwUse) {
	if(bwUse >= 50) {
		bwExtra = Math.ceil(bwUse - 50);
		return "<h2>Your Results</h2><p>Based on the information submitted, you will require approximately <strong>" + bwUse + "GB</strong> of download bandwidth per month.</p><p><strong><a href='BroadbandPlus.aspx?page=10035'>Zen Pro+</a></strong> will be best suited to your needs, however you will need to purchase " + bwExtra + "GB additional bandwidth if your true usage reflects these figures.</p>";
	} else if(bwUse >= 25) {
		return "<h2>Your Results</h2><p>Based on the information submitted, you will require approximately <strong>" + bwUse + "GB</strong> of download bandwidth per month.</p><p><strong><a href='BroadbandPlus.aspx?page=10035'>Zen Pro+</a></strong> will provide you with the capacity to suit your estimated usage.</p>";
	} else if(bwUse >= 15) {
		return "<h2>Your Results</h2><p>Based on the information submitted, you will require approximately <strong>" + bwUse + "GB</strong> of download bandwidth per month.</p><p><strong><a href='BroadbandPlus.aspx?page=10034'>Zen Active+</a></strong> will provide you with the capacity for your estimated usage, with enough spare to accommodate a considerable rise in your Internet usage.</p>";
	} else if(bwUse >= 5) {
		return "<h2>Your Results</h2><p>Based on the information submitted, you will require approximately <strong>" + bwUse + "GB</strong> of download bandwidth per month.</p><p><strong><a href='BroadbandPlus.aspx?page=10034'>Zen Active+</a></strong> will provide you with the capacity for your estimated usage, with enough spare to accommodate a considerable rise in your Internet usage.</p>";
	} else {
		return "<h2>Your Results</h2><p>Based on the information submitted, you will require approximately <strong>" + bwUse + "GB</strong> of download bandwidth per month.</p><p><strong><a href='BroadbandPlus.aspx?page=10033'>Zen Lite+</a></strong> will provide you with the capacity for your estimated usage, with enough spare to accommodate a slight rise in your Internet usage.</p>";
	}
}

function calcUnit(a,b,c,d) {
// a = Kb per unit (1Kb = 1, 1Mb = 1000, 1Gb = 1000000)
// b = number of "units" (eg. number of... hours/emails/mp3s)
// c = maximum possible number of units (0 = unlimited)
// d = frequency. Accepts w,m (per week/month)

	if(!c==0 && b>c) {
	  units = c;
	} else {
	  units = b;
	}

	if(d=='w') {
        freq = 4.25;
	  } else {
	    freq = 1;
	  }
    return a*units*freq;
}

function calculateUsage() {

theTotal = 0;

if (!isNaN(document.forms.frmZenCMSWeb.hours.value)) {
theTotal += calcUnit(5000,document.forms.frmZenCMSWeb.hours.value, 168, 'w');
// Based on average per hour over a range of sites of varying graphical intensity.
}
if (!isNaN(document.forms.frmZenCMSWeb.email.value)) {
theTotal += calcUnit(500,document.forms.frmZenCMSWeb.email.value, 0, 'w');
// average based on combination of plain text and HTML, Re: and Fwd: emails.
}
if (!isNaN(document.forms.frmZenCMSWeb.photos.value)) {
theTotal += calcUnit(850,document.forms.frmZenCMSWeb.photos.value, 0, 'w');
// average jpg photo across different resolutions
}
if (!isNaN(document.forms.frmZenCMSWeb.mp3.value)) {
theTotal += calcUnit(4000,document.forms.frmZenCMSWeb.mp3.value, 0, 'w');
// average mp3 song at 128kbps
}
if (!isNaN(document.forms.frmZenCMSWeb.films.value)) {
theTotal += calcUnit(2000000,document.forms.frmZenCMSWeb.films.value, 0, 'm');
// average film of 2GB - takes into account differing formats
}
if (!isNaN(document.forms.frmZenCMSWeb.radio.value)) {
theTotal += calcUnit(60000,document.forms.frmZenCMSWeb.radio.value, 168, 'w');
// average stream at 128kbps
}
if (!isNaN(document.forms.frmZenCMSWeb.games.value)) {
theTotal += calcUnit(15000,document.forms.frmZenCMSWeb.games.value, 168, 'w');
// average download bandwidth usage of 15MB per hour. Uploads not counted in quota
}

// all calculations and stats based on internal research and should be used as an estimate only!

if (theTotal > 0) {
	theTotal = (theTotal + 100000) / 1000000;
	stringyRecVal = theTotal.toFixed(1);
	stringyRec = getStringyRecService(stringyRecVal);
} else {
	stringyRec = "<div class='errormsg'><h2>! Error</h2><p>In order for us to calculate your estimated bandwidth please enter <strong>numeric values only</strong>.</p><div class='clear'></div></div>";
}

document.getElementById("TotalUsage").innerHTML = stringyRec;
}