// alot of shit hardcoded by Derrick - supposedly this whole thing will be replaced
// by qualtiy at some stage.

function dooswin2000()
{
//'.net setup
//	document.pricing.Product48.checked=0;
//	document.pricing.Product48.disabled=true;
//coldfusion
	document.pricing.Product7.disabled=false;
//frontpage
	document.pricing.Product10.disabled=false;
//ms access
//	document.pricing.Product18.disabled=false;
//windows media
//	document.pricing.Product34.disabled=false;
//custom com
	document.pricing.Product19.disabled=false;

// take off net setup if previously selected
	if ( netsetup==true ) 
	{
	document.pricing.setup.value = round(eval(document.pricing.setup.value) - eval(100));
	setupFee = document.pricing.setup.value;
	document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 );
	netsetup= false;
	}
}


function dooslinux()
{
//.net setup
//	document.pricing.Product48.checked=0;
//	document.pricing.Product48.disabled=true;
//coldfusion
	document.pricing.Product7.disabled=true;
//frontpage
	document.pricing.Product10.disabled=true;
//ms access
//	document.pricing.Product18.disabled=true;
//windows media
//	document.pricing.Product34.disabled=true;
//custom com
	document.pricing.Product19.disabled=true;
// take of net setup if previously selected
	if ( netsetup==true ) 
	{
	document.pricing.setup.value = round(eval(document.pricing.setup.value) - eval(100));
	setupFee = document.pricing.setup.value;
	document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 );
	netsetup= false;
	}
	
}

var netsetup= false;

function doosnet()
{
//.net setup
//	document.pricing.Product48.checked=1;
//	document.pricing.Product48.disabled=true;
//coldfusion
	document.pricing.Product7.disabled=true;
//frontpage
	document.pricing.Product10.disabled=false;
//ms access
//	document.pricing.Product18.disabled=false;
//windows media
//	document.pricing.Product34.disabled=false;
//custom com
	document.pricing.Product19.disabled=false;
//add .net setup fee to display price
	if ( netsetup==false ) 
	{
	document.pricing.setup.value = round(eval(document.pricing.setup.value) + eval(100));
	setupFee = document.pricing.setup.value;
	document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 );
	netsetup=true;
	}

}

function init()
{	
	// force .net setup to be non selectable
//	document.pricing.Product48.disabled=true;
	netsetup= false;
	thePricing = new hostOption();
	initialSetup = 49;
	setupFee = initialSetup;
	bTaxFree = false; 
	
	if (document.pricing.setup.value == 0)
	{
		document.pricing.setup.value = round(setupFee);
		document.pricing.setupDisplay.value = format ( (setupFee * 1.1), 2 );
		theCost = eval(document.pricing.space[document.pricing.space.selectedIndex].value);
		document.pricing.cost.value = round(theCost );
		document.pricing.costDisplay.value = format ( (theCost * 1.1 ), 2 );
	}

	document.pricing.setup.defaultValue = ( initialSetup );
	document.pricing.setupDisplay.defaultValue = format ( ( initialSetup * 1.1 ), 2 );
	document.pricing.cost.defaultValue = eval( ( document.pricing.space[0].value ) );
	document.pricing.costDisplay.defaultValue = eval( format ( ( document.pricing.space[0].value ) * 1.1, 2 ) );
	document.pricing.GST.defaultValue = calculateGST();
	calculateGST();
	
	for(j=0; j<document.pricing.length; j++)
	{
		if(document.pricing.elements[j].name.indexOf("Units")== 0)
		{
			if(document.pricing.elements[j-1].checked == false)
			{
				document.pricing.elements[j].disabled = true;
			}
		}
	}

	theChoice = eval(document.pricing.space[document.pricing.space.selectedIndex].value);
	document.pricing.GST.value = round(theGST);
}

function hostOption()
{ }

// Make sure select boxes are enabled if the check box is checked
function enableSelect ( checkbox, selectbox ) {
	alert  (checkbox.checked);
	if ( checkbox.checked=="1" && selectbox.disabled == true )
		{ selectbox.disabled = false }
}

function addCheck(checkBox, isSetup) { //v2.0
	document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1.1));
	document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1.1));

	if(isSetup)
	{
		if (checkBox.checked=="1")
  		{
    		document.pricing.setup.value = round(eval(document.pricing.setup.value) + eval(checkBox.value));
		}
		else
		{
			document.pricing.setup.value = round(eval(document.pricing.setup.value) - eval(checkBox.value));
		}
		setupFee = document.pricing.setup.value;
		document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 );
	}
	else
	{
		if (checkBox.checked=="1")
  		{
    		document.pricing.cost.value = round(eval(document.pricing.cost.value) + eval(checkBox.value));
		}
		else
		{
			document.pricing.cost.value = round(eval(document.pricing.cost.value) - eval(checkBox.value));
		}
		theCost = document.pricing.cost.value;
		document.pricing.costDisplay.value = format ( theCost * 1.1, 2 );
	}
	calculateGST();
}
function format ( expr, decPlaces ) {
	var str= "" + Math.round ( eval ( expr ) * Math.pow ( 10, decPlaces ) )
	while ( str.length <= decPlaces ) {
		str = "0" + str }
	var decpoint = str.length - decPlaces
	var value=str.substring ( 0, decpoint ) + "." + str.substring ( decpoint, str.length )
	return value.toString();
}
function calcdomain(fieldname){
  var pricearray = new Array ('0','53.90','69.00','103.50','138.00','172.50','207.00','241.50','276.00','310.50','345.00');
  var newprice;
  var years;
  eval("years=document.domaincalc."+fieldname+"Years.options[document.domaincalc."+fieldname+"Years.selectedIndex].text" );
  newprice=pricearray[years];
  eval("document.domaincalc."+fieldname+"Price.value = '"+newprice+"'"); 
}

function addChoice(choiceValue){
  document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1.1));
  document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1.1));

  document.pricing.cost.value = round((eval(document.pricing.cost.value) + eval(choiceValue[choiceValue.selectedIndex].value) - eval(theChoice)));
  theChoice = eval(choiceValue[choiceValue.selectedIndex].value);
  theCost = document.pricing.cost.value;
  setupFee = document.pricing.setup.value;
  document.pricing.costDisplay.value = format ( ( theCost * 1.1 ), 2 )
  document.pricing.setupDisplay.value = format ( ( setupFee * 1.1 ), 2 )
  calculateGST();
}

// Hokey replacement for above so value can come from hidden field
function addChoice2(choiceValue){
  choiceValue.selectedIndex = 0
  document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1.1));
  document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1.1));

  document.pricing.cost.value = round((eval(document.pricing.cost.value) + eval(choiceValue[choiceValue.selectedIndex].value) - eval(theChoice)));
  theChoice = eval(choiceValue[choiceValue.selectedIndex].value);
  theCost = document.pricing.cost.value;
  setupFee = document.pricing.setup.value;
  document.pricing.costDisplay.value = format ( ( theCost * 1.1 ), 2 )
  document.pricing.setupDisplay.value = format ( ( setupFee * 1.1 ), 2 )
  calculateGST();
}
function changeChoice(checkBox, isSetup, theID, units) {

	document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1.1));
	document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1.1));

	if (checkBox.checked=="1")
	{
		if(isSetup)
		{		
    		document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricing[theID] + (eval(checkBox.value) * units));
			setupFee = document.pricing.setup.value;
			document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 )
		}
		else
		{
    		document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricing[theID] + (eval(checkBox.value) * units));
			theCost = document.pricing.cost.value;
			document.pricing.costDisplay.value = format ( theCost * 1.1, 2 )
		}	
	}
	calculateGST();
	thePricing[theID] = checkBox.value * units;
}


function mrChoice(checkBox, isSetup, theID, units, unable) { //v2.0
	document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1.1));
	document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1.1));

	if(thePricing[theID] == null)
	{
		thePricing[theID] = "0";
	}

	if(isSetup)
	{
		if (checkBox.checked=="1")
  		{
			unable.disabled = false;
    		document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricing[theID] + (eval(checkBox.value) * units));
			thePricing[theID] = checkBox.value * units;
		}
		else
		{
			unable.disabled = true;
			document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricing[theID]);
			thePricing[theID] = 0;
		}
		setupFee = document.pricing.setup.value;
		document.pricing.setupDisplay.value = format ( setupFee * 1.1, 2 )
	}
	else
	{
		if (checkBox.checked=="1")
  		{
			unable.disabled = false;
    		document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricing[theID] + (eval(checkBox.value) * units));
			thePricing[theID] = checkBox.value * units;
		}
		else
		{
			unable.disabled = true;
			document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricing[theID]);
			thePricing[theID] = 0;
		}
		theCost = document.pricing.cost.value;
		document.pricing.costDisplay.value = format ( theCost * 1.1, 2 )
	}
	calculateGST();	
}

function doFocus(checkBox, theID, units, zap)
{
	thePricing[theID] = checkBox.value * units;
}

function calculateGST()
{
	theGST = round((eval(document.pricing.cost.value) + eval(document.pricing.setup.value)) / 11);
	if (bTaxFree) 
		document.pricing.GST.value = "0";
	else 
		document.pricing.GST.value = round(theGST);
}

function round(price)
{
	newPrice = Math.round(price*Math.pow(10,2))/Math.pow(10,2);
	string = "" + newPrice;
	number = string.length - string.indexOf('.');

	if (number == 2)
      return newPrice + '0';
	else
	  return newPrice;
}

function taxFree(strGst) {
	if (strGst == "No") {
		bTaxFree = false;
		document.pricing.GST.value = round(theGST);
	}
	else {
		bTaxFree = true;
		document.pricing.GST.value = "0";
	}
}

function newWin(url) {
	window.open(url);
	window.close();
}
