/*****************************************************************************************************************************************************************************************************************************************/
/* Carbon Emission Page */
/*****************************************************************************************************************************************************************************************************************************************/
function redirect()
{
/*if((document.form1.res_txtCFtotOffCost.value==null ||
document.form1.res_txtCFtotOffCost.value==""))
{
alert("Please Submit to calculate your Carbon Emissions");
}
else*/
{
//document.location.href='carbon-offset.asp?val1=' + document.form1.res_txtCarbonNeutral.value+ '&val2=0' + // + document.form1.res_txtCNtotOffCost.value +
//'&val3=0' + '&val4=0';
//'&val3=' + document.form1.res_txtCarbonFriendly.value + '&val4=' + document.form1.res_txtCFtotOffCost.value + '#Order_your_Carbon_Offsets_here';
document.form1.method="post";
document.form1.action="carbon-offset.asp";
document.form1.submit();


//document.location.href='carbon-offset.asp?val1=' + document.form1.res_txtTotDom.value+ '&val2=' + document.form1.res_txtTotCarBusTravel.value +
//'&val3=' + document.form1.res_txtTotTravel.value + '&val4=' + document.form1.res_txtCarbonNeutral.value + '#Order_your_Carbon_Offsets_here';
}
}


function CheckKeyCode()
{
  if ((event.keyCode >= 48 && event.keyCode <= 57)|| (event.keyCode == 8 )|| (event.keyCode == 46 ) || (event.keyCode >= 96 && event.keyCode <= 105)|| (event.keyCode >= 9 && event.keyCode <10 ))
      {
    return true; }
  else {
    return false;}
}

function calculate()
{
if (document.form1.txtNoOfPersons.value ==null || document.form1.txtNoOfPersons.value=="")	
	{ alert("Please enter the No Of Persons");
	document.form1.txtNoOfPersons.focus();
	return false;
	}
document.form1.method="post";
document.form1.action="carbonemission.asp";
document.form1.hidtemp.value="y";
document.form1.submit();
}

function clear()
{
document.form1.hidtemp.value="";
}

function clearAll()
{
document.form1.txtNoOfPersons.value="";
document.form1.txtElectricity.value="";
document.form1.txtGasKwh.value="";
document.form1.txtGasTherms.value="";
document.form1.txtGasCubicmeter.value="";
document.form1.txtLPG.value="";
document.form1.txtHeatingOil.value="";
document.form1.txtCoal.value="";
document.form1.txtWood.value="";
document.form1.txtCarMiles.value="";
document.form1.txtTrainBus.value="";
document.form1.txtShortHaul.value="";
document.form1.txtMedHaul.value="";
document.form1.txtMedLongHaul.value="";
document.form1.txtLongHaul.value="";
document.form1.res_txtElectricity.value="";
document.form1.res_txtGasKwh.value="";
document.form1.res_txtGasTherms.value="";
document.form1.res_txtGasCubicmeter.value="";
document.form1.res_txtLPG.value="";
document.form1.res_txtHeatingOil.value="";
document.form1.res_txtCoal.value="";
document.form1.res_txtWood.value="";
document.form1.res_txtCarMiles.value="";
document.form1.res_txtTrainBus.value="";
document.form1.res_txtShortHaul.value="";
document.form1.res_txtMedHaul.value="";
document.form1.res_txtMedLongHaul.value="";
document.form1.res_txtLongHaul.value="";
document.form1.res_txtTotDom.value="";
document.form1.res_txtTotTravel.value="";
//document.form1.res_txtTotIndustry.value="";
document.form1.res_txtTotCarbon.value="";
document.form1.res_txtTotEmissions.value="";
//document.form1.res_txtTargetUK.value="";
//document.form1.res_txtExPerson.value="";
//document.form1.res_txtExHousehold.value="";
document.form1.res_txtCarbonNeutral.value="";
//document.form1.res_txtCarbonFriendly.value="";
//document.form1.res_txtCNCostPerTon.value="";
//document.form1.res_txtCNtotOffCost.value="";
//document.form1.res_txtCFCostPerTon.value=""; 
//document.form1.res_txtCFtotOffCost.value="";
document.form1.res_txtTotCarBusTravel.value="";
document.form1.btnSubmit.disabled=false;
}

/*****************************************************************************************************************************************************************************************************************************************/
/*carbon-offset Page*/
/*****************************************************************************************************************************************************************************************************************************************/

// To redirect to the billing page with the Tonnes of Carbon to Purchase
function billing(temp)
{
var bool=false;
var Treebool="false";
var TotEmissions=0;
var TotCost=0;

if(document.frmcarbonoffset.C1.checked==1)
{
//alert("True");
TotEmissions=0; //txtTree
TotCost= (parseFloat(TotCost)+ parseFloat(MyReplace(document.frmcarbonoffset.txtTreeCost.value,",",""))).toFixed(2);
bool=true;
if(TotCost!=0)
{
Treebool="true";
}
}

if(document.frmcarbonoffset.C2.checked==1)
{
//alert("True");
TotCost= (parseFloat(TotCost)+ parseFloat(MyReplace(document.frmcarbonoffset.txtLifeStyleCost.value,",",""))).toFixed(2);
TotEmissions= (parseFloat(TotEmissions)+ parseFloat(document.frmcarbonoffset.txtLifeStyleIndustry.value)).toFixed(2);
bool=true;
}
if(document.frmcarbonoffset.C3.checked==1)
{
//alert("rv");
TotCost= (parseFloat(TotCost) + parseFloat(MyReplace(document.frmcarbonoffset.txtUKDomesticCost.value,",",""))).toFixed(2);
TotEmissions= (parseFloat(TotEmissions) + parseFloat(document.frmcarbonoffset.txtUKDomestic.value)).toFixed(2);
bool=true;
}
if(document.frmcarbonoffset.C4.checked==1)
{
//alert("True");
TotCost= (parseFloat(TotCost)+ parseFloat(MyReplace(document.frmcarbonoffset.txtUKRoadCost.value,",",""))).toFixed(2);
TotEmissions= (parseFloat(TotEmissions)+ parseFloat(document.frmcarbonoffset.txtUKRoad.value)).toFixed(2);
bool=true;
}
if(document.frmcarbonoffset.C5.checked==1)
{
//alert("True");
TotCost= (parseFloat(TotCost)+ parseFloat(MyReplace(document.frmcarbonoffset.txtAirTravelCost.value,",",""))).toFixed(2);
TotEmissions= (parseFloat(TotEmissions)+ parseFloat(document.frmcarbonoffset.txtAirTravel.value)).toFixed(2);
bool=true;
}
if(document.frmcarbonoffset.C6.checked==1)
{
//alert("True");
TotEmissions= (parseFloat(TotEmissions) + parseFloat(document.frmcarbonoffset.txtTotEmissions.value)).toFixed(2);
TotCost= (parseFloat(TotCost) + parseFloat(MyReplace(document.frmcarbonoffset.txtTotEmissionsCost.value,",",""))).toFixed(2);
bool=true;

}

if(bool==false)
{
alert("Please Check atleast one check box to proceed further");
//return false;
}
else if(TotCost==0 || TotCost=='NaN')
{
alert("The selection does not include any Cost to proceed further");
document.frmcarbonoffset.txtTree.focus();
}
else
//if(bool==true)
{
//alert("TotEmissions" + TotEmissions);
//alert("TotCost" + TotCost);
document.frmcarbonoffset.hidTotalEmissions.value=TotEmissions;
document.frmcarbonoffset.hidTotalCost.value=TotCost;
document.frmcarbonoffset.hidTreebool.value=Treebool;

document.frmcarbonoffset.method="post";
document.frmcarbonoffset.action="CarbonBilling.asp";
document.frmcarbonoffset.hidtemp.value=temp;
document.frmcarbonoffset.submit();
}
 /*  if(temp==1 && (document.frmcarbonoffset.txtTotEmissions.value<=0))
    {
      alert("Please Enter the Number of Tonnes you would like to buy");
      document.frmcarbonoffset.txtTonnes.focus();
    }
  
   else if(temp==2 && (document.frmcarbonoffset.txtUKExcess.value<=0))
    {
      alert("Please Enter the Number of Tonnes you would like to buy");
      document.frmcarbonoffset.txtTonnes.focus();
    }

    else if(temp==3 && (document.frmcarbonoffset.txtTonnes.value==""))
    {
      alert("Please Enter the Number of Tonnes you would like to buy");
      document.frmcarbonoffset.txtTonnes.focus();
    }
    else if(temp==4 && (document.frmcarbonoffset.txtTree.value==""))
    {
      alert("Please Enter the Number of Tree's you would like to Sponsor");
      document.frmcarbonoffset.txtTree.focus();
    }
    else
    {
      document.frmcarbonoffset.hidtemp.value=temp;
      document.frmcarbonoffset.submit();
    }*/
}

// To calculate the cost for the Tonnes of Carbon entered
function CalCost(tempTonnes)
{
    document.frmcarbonoffset.txtCost.value=(tempTonnes*11.5).toFixed(2);
}
// To calculate the cost for Tree Sponsor
function CalTreeCost(tempTreeTonnes)
{
    document.frmcarbonoffset.txtTreeCost.value=(tempTreeTonnes*9.5).toFixed(2);
}

function CalLSCost(tempLSTonnes)
{
    document.frmcarbonoffset.txtLifeStyleCost.value=(tempLSTonnes*11.5).toFixed(2);
}

function MyReplace(sOrgVal,sSearchVal,sReplaceVal)
{
   var sVal;
   try
   {
      sVal = new String(sOrgVal);
      if (sVal.length < 1) { return sVal; }
      var sRegExp = eval("/" + sSearchVal + "/g");
      sVal = sVal.replace(sRegExp,sReplaceVal);
   }
   catch (exception)  { }
   return sVal;

 }

/*****************************************************************************************************************************************************************************************************************************************/
/* Carbon Billing Page */
/*****************************************************************************************************************************************************************************************************************************************/

//Total page validation script for saving the new customer details entered
function validateData()
{
//document.frmBilling.hidCBtemp.value="";
//alert(document.frmBilling.hidCBtemp.value);
if(document.frmBilling.txtEmail.value=='')
{
alert("Please enter Email ID");
document.frmBilling.txtEmail.focus();
return false;
}
if(emailcheck(document.frmBilling.txtEmail.value)==true)
{
if(document.frmBilling.txtName.value=='')
{
alert("Please enter your First Name");
document.frmBilling.txtName.focus();
return false;
}
else
if(document.frmBilling.txtLastName.value=='')
{
alert("Please enter your Last Name");
document.frmBilling.txtLastName.focus();
return false;
}
else
if(document.frmBilling.txtAdd1.value=='')
{
alert("Please enter your Address");
document.frmBilling.txtAdd1.focus();
return false;
}
else
if(document.frmBilling.txtAdd3.value=='')
{
alert("Please enter your City");
document.frmBilling.txtAdd3.focus();
return false;
}
else
if(document.frmBilling.txtCounty.value=='')
{
alert("Please enter your County");
document.frmBilling.txtCounty.focus();
return false;
}
else
if(document.frmBilling.txtPostCode.value=='')
{
alert("Please enter your Post Code");
document.frmBilling.txtPostCode.focus();
return false;
}
else
if(document.frmBilling.txtHomePhone.value=='' && document.frmBilling.txtMobile.value=='')
{
alert("Please enter your Phone Number");
document.frmBilling.txtHomePhone.focus();
return false;
}
if(document.frmBilling.hidCBtemp.value=="")
{
document.frmBilling.hidCBtemp.value="y";
}

if(document.frmBilling.hidCBtemp.value=="s")
{
document.frmBilling.hidCBupdate.value="i";
}

document.frmBilling.method="post";
//commented on 03/10/2007
document.frmBilling.action="CarbonBilling.asp";
//document.frmBilling.hidCBtemp.value="y";
//alert(document.frmBilling.hidCBtemp.value);
document.frmBilling.submit();
}
}

//Email validation script for saving the new customer details entered
function emailcheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
           document.frmBilling.txtEmail.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
           document.frmBilling.txtEmail.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }
		 return true
	}
//Email validation script for fetching the details wrt the entered Email
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
           document.frmBilling.txtEmail.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
           document.frmBilling.txtEmail.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
            document.frmBilling.txtEmail.focus();
		    return false
		 }
		document.frmBilling.method="post";
		document.frmBilling.action="CarbonBilling.asp";
		document.frmBilling.hidCBtemp.value="s";
		document.frmBilling.submit();
		 return true
	}
	
//To enable the Update button wrt Checkbox toggle
function enableUpdate()
{
	if(document.frmBilling.checkboxUpdate.checked==true)
	{
		document.frmBilling.btnSubmit.disabled=true;
		document.frmBilling.btnUpdate.disabled=false;
	}
	else
	{
		document.frmBilling.btnSubmit.disabled=false;
		document.frmBilling.btnUpdate.disabled=true;
	}
}

//To update the Customer Details 
function updateDetails()
{
  document.frmBilling.hidCBupdate.value="u";
  //alert(document.frmBilling.hidCBupdate.value);
  document.frmBilling.method="post";
  document.frmBilling.action="CarbonBilling.asp";
  document.frmBilling.submit();
}

//for all the pages to go to the previous page	
function goBack()
{
//alert(document.frmBilling.hidBack.value);

if(document.frmBilling.hidBack.value=="c")
{
document.frmBilling.hidCBtemp.value="";
document.frmBilling.hidCBupdate.value="";
javascript:history.go(-3);
document.frmBilling.hidBack.value="a";
}
if(document.frmBilling.hidBack.value=="b")
{
document.frmBilling.hidCBtemp.value="";
document.frmBilling.hidCBupdate.value="";
javascript:history.go(-3);
document.frmBilling.hidBack.value="a";
}
else
{
javascript:history.go(-1);}
}

/*****************************************************************************************************************************************************************************************************************************************/
/* Confirm.asp Page */
/*****************************************************************************************************************************************************************************************************************************************/
