//-----------------------------------------------------------------------------
// 	G3W - Sistema de Franquias
// 	http://g3w.com.br
// 	2008-Jul
//	Charset ISO-8859-1
//-----------------------------------------------------------------------------
var xmlHttp;

//-----------------------------------------------------------------------------
// Init
//-----------------------------------------------------------------------------
window.onload = function()
{
	// hosting plan
	orderAltered();
}

//-----------------------------------------------------------------------------
// Append prices
//-----------------------------------------------------------------------------
//	priceDomain
//	priceHost
//	priceTotal
// 	return string
//-----------------------------------------------------------------------------
function appendPrices(priceTerm, priceInstall, priceTotal)
{
	//	plan price
	tmpObj = document.getElementById("ljvPlanPrice");
	tmpObj.innerHTML = priceTerm;

	//	install price
	tmpObj = document.getElementById("ljvInstallPrice");
	tmpObj.innerHTML = priceInstall;

	//	total price
	tmpObj = document.getElementById("ljvTotal");
	tmpObj.innerHTML = priceTotal+'&nbsp;'; // to fix a bug of IE6 (O'RLY?)
}

//-----------------------------------------------------------------------------
// Get URL
//-----------------------------------------------------------------------------
// return string
//-----------------------------------------------------------------------------
function getURL()
{
	//	members
	var buffer 	= "formulario.xml.php?plan=";
	var tmpObj 	= "";

	//	selected plan
	tmpObj		= document.getElementById('ljvPlan');
	selIndex	= tmpObj.selectedIndex;
	buffer	   += tmpObj[selIndex].value;

	//	selected term
	tmpObj		= document.getElementById('ljvTerm');

	//	required for the "concept hack"
	try {
		selIndex	= tmpObj.selectedIndex;
		buffer	   += "&term="+tmpObj[selIndex].value;
	}
	catch(e) {
		buffer	   += "&term="+tmpObj.value;
	}

	//	selected payment
	tmpObj		= document.getElementById('ljvPayment');
	if (tmpObj)
		buffer	   += "&payment="+tmpObj.value;

	return buffer;
}

//-----------------------------------------------------------------------------
// Dropdowns or checkbox for order was altered
//-----------------------------------------------------------------------------
function orderAltered()
{
	// members
	var url = getURL();

	// set request to append new prices
	xmlHttp = getXMLHttpRequest();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = orderAlteredCallback;
	xmlHttp.send(null);
}

//-----------------------------------------------------------------------------
// Selected Plan Option callback function
//-----------------------------------------------------------------------------
function orderAlteredCallback()
{
	if(xmlHttp.readyState != 4)
		return;

	if(xmlHttp.status != 200)
		return;

	//	append results
	xmlDoc	= xmlHttp.responseXML;

	var priceTerm = xmlDoc.getElementsByTagName("termPrice")[0].childNodes[0].nodeValue;
	var priceInstall = xmlDoc.getElementsByTagName("installPrice")[0].childNodes[0].nodeValue;
	var priceTotal = xmlDoc.getElementsByTagName("totalPrice")[0].childNodes[0].nodeValue;

	appendPrices(priceTerm, priceInstall, priceTotal);
}