function openGoogleAdWords()
{
	window.open('https://www.securepaynet.net/gdshop/jump_pages/reseller_words.asp?se=%2B&prog%5Fid=vtcomputerguy&app%5Fhdr=99&ci=3246', 'display', 'left=20,top=20,scrollbars=yes,resizable=yes,width=620,height=500');
}

function openEulaPopup()
{

	var win=window.open('https://www.securepaynet.net/gdshop/legal_agreements/show_doc.asp?se=%2B&prog%5Fid=vtcomputerguy&app%5Fhdr=&pageid=Dedicated+Hosting+SA&ci=1490', 'display1', 'left=50,top=50,resizable=yes,scrollbars=yes,width=780,height=500');

}
function openPleskPopup()
{
	var win=window.open('https://products.secureserver.net/products/plesk.htm', 'display2', 'left=50,top=50,resizable=yes,scrollbars=yes,width=780,height=500');
}
function openVirtuozzoPopup()
{
	var win=window.open('https://products.secureserver.net/products/virtuozzo.htm', 'display2', 'left=50,top=50,resizable=yes,scrollbars=yes,width=780,height=500');
}
function openDedicatedPopup()
{
	var win=window.open('https://products.secureserver.net/products/hosting/aboutdedicatedhosting.htm', 'display2', 'left=50,top=50,resizable=yes,scrollbars=yes,width=780,height=500');
}
function openVirtualPopup()
{
	var win=window.open('https://products.secureserver.net/products/hosting/aboutvirtualdedicatedhosting.htm', 'display2', 'left=50,top=50,resizable=yes,scrollbars=yes,width=780,height=500');
}
function openSoftwarePopup(anchor)
{	

	var win=window.open('https://products.secureserver.net/products/ded_hosting_value_apps.htm' + anchor, 'software', 'left=10,top=10,resizable=yes,scrollbars=yes,width=300,height=400');

}

function formatPrice(listPrice)
{
	if ('' == '1387')
		return "$X.XX"

	if (listPrice == 0)
		return "FREE";
					
	if (listPrice < 100)
		return listPrice + '¢';

	else
	{
		var strListPrice = listPrice.toString();
		var strCents = strListPrice.substr(strListPrice.length - 2, 2);
		var strListPrice = "$" + strListPrice.substr(0, strListPrice.length - 2) + "." + strCents;
		return strListPrice;
	}
}

function getPrice(pf_id)
{
	var price = 0;
	switch(pf_id)
	{
	case '271211'		: price = 10900; break;
	
	case '271226'	: price = 1900; break;
	case '271218'	: price = 1995; break;
	case '271213'	: price = 1900; break;
	case '271214'				: price = 1900; break;
	
	case '276500'			: price = 500; break;
	case '276501'		: price = 1995; break;
	case '276502'	: price = 2000; break;
	case '271216'		: price = 1995; break;
	case '271217'		: price = 1995; break;
	case '271219'		: price = 1995; break;
	case '271220'		: price = 1995; break;
	case '271221'	: price = 2995; break;
	case '272753'	: price = 995; break;
	case '272754'		: price = 1995; break;
	}
	return price;
}

function selectForm()
{
	var frm = document.forms.frmSelect;
	var plan = frm.elements['chkPlan'];
	var optionVal;
	var formName;
	var months = 1;
	var frmToSubmit;
	
  for(i=0;i<plan.length;i++)
	{
		if(plan[i].checked==true)
		{
			optionVal = plan[i].value;
			formName = optionVal.substring(0, optionVal.indexOf("_"))
			months = optionVal.substring((optionVal.indexOf("_")+1), optionVal.length)
		}
	}

	if (formName == 'economy')
	{
		frmToSubmit = document.forms.frmEconomy;
		if (frm.quickBuy)
		{
			
		frmToSubmit.quickBuy.value = "yes|1892";
			
		}
	}
	else if (formName == 'popular')
	{
		frmToSubmit = document.forms.frmPopular;
		if (frm.quickBuy)
		{
			
		frmToSubmit.quickBuy.value = "yes|1892";
			
		}
	}
	else if (formName == 'premium')
	{
		frmToSubmit = document.forms.frmPremium;
                if (frm.quickBuy)
		{
			
		frmToSubmit.quickBuy.value = "yes|1892";
			
		}
	}

	//Check if FTP Backups were checked and add to form
	if(frm.ftp[1].checked) frmToSubmit.elements['ftp'].value = frm.ftp[1].value;
	if(frm.ftp[2].checked) frmToSubmit.elements['ftp'].value = frm.ftp[2].value;
	if(frm.ftp[3].checked) frmToSubmit.elements['ftp'].value = frm.ftp[3].value;
	
	if(frm.sslOption.checked)
	{
		frmToSubmit.elements['sslOption'].value = "1";
		frmToSubmit.elements['ssl'].value = frm.ssl.options[frm.ssl.options.selectedIndex].value;
	}
	
	if  (frm.agreeVal.checked == false)
	{
		alert('You must agree to the Dedicated Server Agreement.');
		frm.agreeVal.focus();
	}
	else
	{
		frmToSubmit.elements['moQty'].value = months;
		frmToSubmit.submit();		
	}
}

function getBuildTotal()
{
	var frm = document.forms.frmBuild;
	var subTotal = 0;
	var bandwidthPrice = 0;
	var bandwidthAmount = 0;
	var originalPrice = 0;
	var optionVal;
	var has_cpanel = false;

	if (frm.cpanel[1].checked == true){has_cpanel = true;}
	if (frm.cpanel[2].checked == true){has_cpanel = true;}
	if (frm.cpanel[3].checked == true){has_cpanel = true;}

	if (!document.layers)
	{
		if (has_cpanel)
		{
			document.getElementById('software_div').style.display = "";
			document.getElementById('notice_div').style.display = "none";
		}
		else
		{
			document.getElementById('software_div').style.display = "none";
			document.getElementById('notice_div').style.display = "";
			frm.software[0].checked = true;
			frm.software[1].checked = false;
			frm.software[2].checked = false;
		}
	}

	for(i=0;i<frm.length;i++)
	{
		// base server
		if (frm[i].name == 'serverType')
		{
			subTotal = subTotal + getPrice(frm[i].value);
		}
		// operating system
		if (frm[i].name == 'os')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}
		// disk space
		if (frm[i].name == 'diskspace')
		{
			if (frm[i].checked == true)
			{
				optionVal = frm[i].value;
				subTotal = subTotal + (getPrice(optionVal.substring(0, optionVal.indexOf("_"))) * optionVal.substring((optionVal.indexOf("_")+1), optionVal.length));
			}
		}
		// bandwidth 
		if (frm[i].name == 'bandwidth')
		{
			if (frm[i].checked == true)
			{
				optionVal = frm[i].value;
				bandwidthPrice = (getPrice(optionVal.substring(0, optionVal.indexOf("_"))) * optionVal.substring((optionVal.indexOf("_")+1), optionVal.length));
				bandwidthAmount = (500 * optionVal.substring((optionVal.indexOf("_")+1), optionVal.length));
			}
		}
		// processor
		if (frm[i].name == 'processor')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}
		// ram
		if (frm[i].name == 'ram')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}
		// control panel
		if (frm[i].name == 'cpanel')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}
		// software options
		if (frm[i].name == 'software')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}

		// ftp
		if (frm[i].name == 'ftp')
		{
			if (frm[i].checked == true)
			{
				subTotal = subTotal + getPrice(frm[i].value);
			}
		}
	}
	originalPrice = subTotal;
	
	document.getElementById('txtTotalPrice').innerHTML = formatPrice(originalPrice) + "/mo";	
	document.getElementById('txtSalePrice').innerHTML = formatPrice(originalPrice * 1) + "/mo";	
	
	subTotal = subTotal + bandwidthPrice

	if(bandwidthPrice > 0)
	{
		document.getElementById('bandwidthRow').style.display = "";		
		document.getElementById('txtBandwidthDesc').innerHTML = ' >' + bandwidthAmount + 'GB Additional Bandwidth'
		document.getElementById('txtBandwidthPrice').innerHTML = formatPrice(bandwidthPrice) + "/mo";
	}
	else
	{
		document.getElementById('bandwidthRow').style.display = "none";
	}

	document.getElementById('txtMonthlyPrice').innerHTML = formatPrice(subTotal) + "/mo";
}

function submitBuildForm()
{
	var frm = document.frmBuild;
	if  (frm.agreeVal.checked == false)
	{
		alert('You must agree to the Dedicated Server Agreement.');
		frm.agreeVal.focus();
	}
	else
	{
		frm.submit();		
	}
}

function showPleskOptions(os)
{
	
	if (os == "linux")
	{
		if (document.all){
			postgre.style.display = "";
			gamehost.style.display = "";
			mssql.style.display = "none";
		}
		else{
			var ihatenetscape = document.getElementById("postgre");
			ihatenetscape.style.display = "";
			ihatenetscape = document.getElementById("mssql");
			ihatenetscape.style.display = "none";
			ihatenetscape = document.getElementById("gamehost");
			ihatenetscape.style.display = "";
		}
	}
	else
	{
		if (document.all){
			postgre.style.display = "none";
			gamehost.style.display = "none";
			mssql.style.display = "";
		}
		else{
			var ihatenetscape = document.getElementById("postgre");
			ihatenetscape.style.display = "none";
			ihatenetscape = document.getElementById("mssql");
			ihatenetscape.style.display = "";
			ihatenetscape = document.getElementById("gamehost");
			ihatenetscape.style.display = "none";
		}
	}
	
}

// sets up prices in bottom of the page
getBuildTotal();