function Calc(){

var HoursSurf_Weekly;
var EmailsTotal_Weekly;
var EmailsAttach_Weekly;
var MusicTracksDownload_Weekly;
var MinutesVideoWatch_Wekly;
var MoviesDownload_Monthly;
var HoursRadioListen_Daily;
var HoursGameOnline_Weekly;
var HoursCalls_Weekly;

    
 HoursSurf_Weekly=Validate(document.getElementById("HoursSurf_Weekly"));
 
 EmailsTotal_Weekly=Validate(document.getElementById("EmailsTotal_Weekly"));
 EmailsAttach_Weekly=Validate(document.getElementById("EmailsAttach_Weekly"));
 PicsReceive_Weekly=Validate(document.getElementById("PicsReceive_Weekly"));
 MusicTracksDownload_Weekly=Validate(document.getElementById("MusicTracksDownload_Weekly"));
 MinutesVideoWatch_Wekly=Validate(document.getElementById("MinutesVideoWatch_Wekly"));
 MoviesDownload_Monthly=Validate(document.getElementById("MoviesDownload_Monthly"));
 HoursRadioListen_Daily=Validate(document.getElementById("HoursRadioListen_Daily"));
 HoursGameOnline_Weekly=Validate(document.getElementById("HoursGameOnline_Weekly"));
 HoursCalls_Weekly=Validate(document.getElementById("HoursCalls_Weekly"));


//==calculate total usage===
var GB_Usage=0
GB_Usage=GB_Usage+(HoursSurf_Weekly * 0.06);
GB_Usage=GB_Usage+(EmailsTotal_Weekly * 0.0001);
GB_Usage=GB_Usage+(EmailsAttach_Weekly * 0.001);
GB_Usage=GB_Usage+(PicsReceive_Weekly * 0.085);
GB_Usage=GB_Usage+(MusicTracksDownload_Weekly * 0.0169);
GB_Usage=GB_Usage+(MinutesVideoWatch_Wekly * 0.01);
GB_Usage=GB_Usage+(MoviesDownload_Monthly * 1);
GB_Usage=GB_Usage+(HoursRadioListen_Daily * 0.1);
GB_Usage=GB_Usage+(HoursGameOnline_Weekly * 0.13);
GB_Usage=GB_Usage+(HoursCalls_Weekly * 0.3);

document.getElementById("totGB").innerHTML = roundNumber(GB_Usage) + " GB";

/*if(GB_Usage>0){
document.getElementById("TR_totGB").style.display="inline";
}else{
document.getElementById("TR_totGB").style.display="none";
}*/

}


//==vars to set==
var This_ISP_Name="V21"  //==name of ISP;==
var This_ISP_Price="16.99"  //==512kb==

function Validate(obj)
{
	var tmp1;
	tmp1 = parseFloat(obj.value);	
	
	if(isNaN(tmp1)==true) 
	{
		tmp1=0;
	}
	if(tmp1<0) 
	{
		tmp1=0;
	}
	
	//==some specific validations==
	if(obj.name=="HoursSurf_Daily" && tmp1>24){
	tmp1=24;
	obj.value=tmp1;
	}
	if(obj.name=="HoursRadioListen_Daily" && tmp1>24){
	tmp1=24;
	obj.value=tmp1;
	}
	if(obj.name=="MinutesVideoWatch_Wekly" && tmp1>10080){
	tmp1=10080;
	obj.value=tmp1;
	}

	//=============================
return tmp1;
}

function OrganiseValue(obj){
	if (obj) 
	{
	obj.value=Validate(obj);
	}

}

function roundNumber(num1) {
	var rlength = 2; // The number of decimal places to round to
	var newnumber = Math.round(num1*Math.pow(10,rlength))/Math.pow(10,rlength);
return newnumber;
}

function myBubbleSort(arrayName,length) {
    for (var i=0; i<(length-1); i++)
        for (var j=i+1; j<length; j++)
            if (arrayName[j][1] < arrayName[i][1]) {
                var dummy0 = arrayName[i][0];
                var dummy1 = arrayName[i][1];				
                var dummy2 = arrayName[i][2];								
                var dummy3 = arrayName[i][3];												
                arrayName[i][0] = arrayName[j][0];
                arrayName[i][1] = arrayName[j][1];				
                arrayName[i][2] = arrayName[j][2];								
                arrayName[i][3] = arrayName[j][3];												
                arrayName[j][0] = dummy0;
                arrayName[j][1] = dummy1;
                arrayName[j][2] = dummy2;								
                arrayName[j][3] = dummy3;												
            }
}

function showISP(ISP){
hideAllISP();										
//document.all[ISP].style.display="inline";
document.getElementById("ISP").style.display="inline";
document.getElementById("ISP_Package").style.display="inline";
//document.all["ISP_Package"].style.display="inline";	//==parent table==		
}

function hideAllISP(){

	document.getElementById("ThisISPinfo").style.display="none";
	document.getElementById("BT").style.display="none";
	document.getElementById("PlusNet_Lite").style.display="none";
	document.getElementById("PlusNet_Premier").style.display="none";
	document.getElementById("Tiscali").style.display="none";
	document.getElementById("Demon").style.display="none";
	document.getElementById("Wanadoo_Std").style.display="none";
	document.getElementById("Wanadoo_Active").style.display="none";
	document.getElementById("Wanadoo_Heavy").style.display="none";
	document.getElementById("ISP_Package").style.display="none";				
	
}

//===members for ISP prices========
function getV21(speed,usage){  //==This_ISP==
	var FinalBill=0;
switch (speed) { 
   case "512kb" : 
	  FinalBill=This_ISP_Price;   //==512kb monthly price==
      break; 
   case "1mb" : 
      break; 
   case "2mb" : 
      break; 
} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getBT(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=17.99;  //==512kb monthly price==
			  FinalBill=FinalBill+Price;
			  if(usage >= 6){
				  FinalBill=FinalBill+12;	  
			  }else if(usage >= 3){
				  FinalBill=FinalBill+8;	  	  
			  } else if(usage >= 1){
				  FinalBill=FinalBill+4;	  	  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getPlusNet_Lite(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=14.99; //==512kb monthly price==
			  var usageLimit=1  //==in GB==
			  FinalBill=FinalBill+Price;
			  
			  //==charging £1.75 for each extra 1GB==
			  if(usage > usageLimit){  
				  FinalBill=FinalBill+((usage-usageLimit)*1.75);	  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getPlusNet_Premier(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=21.99; //==512kb monthly price==
			  var usageLimit=10  //==GB==
			  FinalBill=FinalBill+Price;
			  //==charging £1.75 for each extra 1GB==
			  if(usage > usageLimit){  
				  FinalBill=FinalBill+((usage-usageLimit)*1.75);	  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getDemon(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=19.99; //==512kb monthly price==
			  //==no cap==
			  FinalBill=FinalBill+Price;
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getWanadoo_Std(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=17.99; //==512kb monthly price==
			  var usageLimit=2  //==GB==
			  FinalBill=FinalBill+Price;
			  //==moving user automatically to Active type from Std if he exceeds usageLimit==
			  if(usage > usageLimit){  
				  FinalBill=22.99;  //==22.99 is 512bb price of Active User option==  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getWanadoo_Active(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=22.99; //==512kb monthly price==
			  var usageLimit=6  //==GB==
			  FinalBill=FinalBill+Price;
			  //==moving user automatically to Heavy type from Active if he exceeds usageLimit==
			  if(usage > usageLimit){  
				  FinalBill=27.99;  //==22.99 is 512bb price of Heavy User option==  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
function getWanadoo_Heavy(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=27.99; //==512kb monthly price==
			  var usageLimit=30  //==GB==
			  FinalBill=FinalBill+Price;
			  //==user acc is terminated if he exceeds usageLimit==
			  if(usage > usageLimit){  
				  FinalBill="Account Terminated";  //==22.99 is 512bb price of Heavy User option==  
				  return FinalBill;
			  }else{
				  return roundNumber(FinalBill);	
			  }			  
			  
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
}
//++++++++++++++++++++++++++++
function getTiscali(speed,usage){
	var FinalBill=0;
	switch (speed) {
	   case "512kb" : 
		   	  var Price=17.99; //==512kb monthly price==
			  var usageLimit=30  //==GB==
			  FinalBill=FinalBill+Price;
			  //==charging £1.50 for each extra 1GB==
			  if(usage > usageLimit){  
				  FinalBill=FinalBill+((usage-usageLimit)*1.50);	  
			  }
	      break; 
	   case "1mb" : 
	      break; 
	   case "2mb" : 
	      break; 
	} 
return roundNumber(FinalBill);	
}
//++++++++++++++++++++++++++++
