/* =========================================================================

JavaScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT (TM)

NAME: hostplan_cost.js

AUTHOR: Rustom Rawat , Access Web Solutions
DATE  : 9/13/03
COPYRIGHT: (c) 2003 Access Web Solutions.
COMMENT: AWS grants you a royalty free license to use or modify this 
		 software provided that this copyright notice appears on all copies.
 		 This software is provided "AS IS," without a warranty of any kind.

============================================================================ */



// check for empty fields before proceeding for costing
function costplan()
{
var form = window.document.frmPlaceOrder;
if (form.HostPlan.value == "")
  {
  alert("Please opt for plan from the \"Hosting Plan\" field.");
  form.HostPlan.focus();
  return false;
  }
if (form.Quantity.value == "")
  {
  alert("Please enter quantity from the \"How many Plans\" field.");
  form.Quantity.focus();
  return false;
  }
if (form.Quantity.value)
  {
  if (!isNum(form.Quantity.value))
	{
	alert("Please enter only valid numbers.");
	form.Quantity.focus();
	return false;
	}
  }
calcost();
}


// Check for numerical data only
function isNum(passedVal) 
{
	if (passedVal == "") 
	{
	   return false;
	}
	for (i=0; i<passedVal.length; i++) {
	    if (passedVal.charAt(i) <"0") {
/*			if (passedVal.charAt(i)!=".")
			{
				return false;
			} */
			return false;
	    }
	    if (passedVal.charAt(i) > "9") {
/*			if (passedVal.charAt(i)!=".")
			{
				return false;
			} */
		return false;
	    }
	}
	return true;
}

// calculate price for hosting plans
function calcost()
{
var form = window.document.frmPlaceOrder;

// Linux quarterly prices
var Uq10 = "5.25";
var Uq25 = "9.25";
var Uq50 = "14.25";
var Uq100 = "19.25";
var Uq200 = "33.25";
// Linux annually prices
var Ua10 = "19.00";
var Ua25 = "29.00";
var Ua50 = "49.00";
var Ua100 = "69.00";
var Ua200 = "119.00";
// Windows quarterly prices
var Wq10 = "8.25";
var Wq25 = "14.25";
var Wq50 = "21.25";
var Wq100 = "40.25";
var Wq200 = "67.25";
// Windows annually prices
var Wa10 = "29.00";
var Wa25 = "49.00";
var Wa50 = "79.00";
var Wa100 = "149.00";
var Wa200 = "249.00";


// Assign value to a os varriable
switch(form.OS.value) {
  case "Linux":
	var os = "U";
	break;
  case "Windows":
	var os = "W";
  }


// Assign value to cycle varriable
switch(form.BillingCycle.value) {
  case "Quarterly":
	var cycle = "q";
	break;
  case "Annually":
	var cycle = "a";
  }


// Assign value to a plan varriable
switch(form.HostPlan.value) {
  case "Plan 10":
	var plan = "10";
	break;
  case "Plan 25":
	var plan = "25";
	break;
  case "Plan 50":
	var plan = "50";
	break;
  case "Plan 100":
	var plan = "100";
	break;
  case "Plan 200":
	var plan = "200";
  }

// concatinate all the opted values
var netcal = os + cycle + plan ;


// Assign value to a price varriable
switch(netcal) {
  case "Uq10":
	var price = Uq10;
	break;
  case "Uq25":
	var price = Uq25;
	break;
  case "Uq50":
	var price = Uq50;
	break;
  case "Uq100":
	var price = Uq100;
	break;
  case "Uq200":
	var price = Uq200;
	break;
  case "Ua10":
	var price = Ua10;
	break;
  case "Ua25":
	var price = Ua25;
	break;
  case "Ua50":
	var price = Ua50;
	break;
  case "Ua100":
	var price = Ua100;
	break;
  case "Ua200":
	var price = Ua200;
	break;
  case "Wq10":
	var price = Wq10;
	break;
  case "Wq25":
	var price = Wq25;
	break;
  case "Wq50":
	var price = Wq50;
	break;
  case "Wq100":
	var price = Wq100;
	break;
  case "Wq200":
	var price = Wq200;
	break;
  case "Wa10":
	var price = Wa10;
	break;
  case "Wa25":
	var price = Wa25;
	break;
  case "Wa50":
	var price = Wa50;
	break;
  case "Wa100":
	var price = Wa100;
	break;
  case "Wa200":
	var price = Wa200;
  }

var qty = form.Quantity.value ;
var tcost = price * qty ;

tcost= (tcost == Math.floor(tcost)) ? tcost + '.00' : ((tcost*10 == Math.floor(tcost*10)) ? tcost + '0' : tcost);
form.Cost.value = tcost ;

return true;
}
