/* Load Price XML File
---------------------------------------------- */
function createRequest() {
	return (window.XMLHttpRequest) ? new XMLHttpRequest() : (window.ActiveXObject) ? new ActiveXObject("MSXML2.XMLHTTP") : null
}

function sendRequest(request,path,container,callback) {
	request.open("GET", path, true);
	request.onreadystatechange = function() {
		if(request.readyState == 4) {
			if(request.status == 200) {
				callback(container,request);
			}
		}
	}
	request.send(null);
}

function processPrices(container,request) {
	container.priceXML = request.responseXML;
}

function loadPrices() {
	var langpath = (typeof n_lang != 'undefined') && n_lang != null && n_lang != 'en-us' ? "/"+n_lang : "";
	var xmlPath = langpath+"/products/openworkgroupsuite/pricing_nows.xml";
	var summaryStep = document.getElementById("pricingwizard_step4");
	if(!summaryStep) return;
	
	summaryStep.request = createRequest();
	if(summaryStep.request != null) sendRequest(summaryStep.request,xmlPath,summaryStep,processPrices);
}

/* Steps
---------------------------------------------- */
var currentStep = 0;
var greatestCompleteStep = 0;
var hasNOWS = false;
var hasNOWSMaint = false;
var hasGroupWise = false;
var hasGroupWiseMaint = false;
var hasOES = false;
var hasOESMaint = false;
var hasZENSuite = false;
var hasZENSuiteMaint = false;
var hasZENDesk = false;
var hasZENDeskMaint = false;
var wantsTeaming = true;
var replaceMessaging = false;
var desiredMaint = "none";
var price = null;

function setMaintenance() {
	var duration = null;
	var type = null;
	var maintenanceInpts = document.getElementById("pricingwizard_step3_e").getElementsByTagName("input");
	for(var i = maintenanceInpts.length - 1; i >= 0; i--) {
		if(maintenanceInpts[i].checked) {
			switch(maintenanceInpts[i].value) {
				case '1p' :
					duration = "1";
					type = "Priority";
					break;
				case '3p' :
					duration = "3";
					type = "Priority";
					break;
				case '1s' :
					duration = "1";
					type = "Standard";
					break;
				case '3s' :
					duration = "3";
					type = "Standard";
					break;
				default :
					duration = "0";
					type = "Priority";
			};
			document.getElementById("desiredmaintenance_length").value = duration;
			document.getElementById("desiredmaintenance_type").value = type;
			if(duration == "0") {
				document.getElementById("desiredmaintenance_type").style.display = "none";
			}
			else {
				document.getElementById("desiredmaintenance_type").style.display = "inline";
			}
			return;
		}
	}
}

function getPlatformPriceNode(xml, name) {
	var platformPrices = xml.getElementsByTagName("platform");
	for(var i = 0; i < platformPrices.length; i++) {
		if(platformPrices[i].getAttribute("name") == name) return platformPrices[i];
	}
	return null;
}

function filterOptionsWithAttribute(optionNodes,attrName,attrVal) {
	var optionsWithAttr = new Array();
	for(var i = optionNodes.length-1; i >= 0; i--) {
		if(optionNodes[i].getAttribute(attrName) == attrVal) optionsWithAttr[optionsWithAttr.length] = optionNodes[i];
	}
	return optionsWithAttr;
}

function setPrice(optn,maint) {
	var prices = optn.getElementsByTagName("price");
	var price = "";
	if(document.getElementById("dollars").checked) {
		// dollar price
		price = '$' + (parseInt(prices[0].firstChild.data) + maint);
	}
	else {
		// euro price
		price = '&#8364;' + (parseInt(prices[1].firstChild.data) + maint);
	}
	document.getElementById("finalprice").innerHTML = price + '<sup>*</sup>';
	document.getElementById("pricingform").price.value = price;
}

function setRecommendation(optn) {
	var recommenations = optn.getElementsByTagName('recommendation');
	var recommenationList = document.getElementById("recomendation").getElementsByTagName('ul')[0];
	
	// remove current values
	while(recommenationList.hasChildNodes()) {
		recommenationList.removeChild(recommenationList.firstChild);
	}
	var frm = document.getElementById("pricingform");
	for(var i = 0; i < frm.elements.length; i++) {
		if(frm.elements[i].name == "recommenation") frm.removeChild(frm.elements[i]);	
	}
	
	// add new values
	for(var i = 0; i < recommenations.length; i++) {
		var li = document.createElement('li');
		li.innerHTML = (recommenations.length > 1) ? '<strong>' + (i+1) + '.</strong>' + recommenations[i].firstChild.data : recommenations[i].firstChild.data;
		recommenationList.appendChild(li);
		
		var recommencationInpt = document.createElement("input");
		recommencationInpt.type = "hidden";
		recommencationInpt.name = "recommenation";
		recommencationInpt.value = recommenations[i].firstChild.data;
		document.getElementById("pricingform").appendChild(recommencationInpt);
	}
}

function showBuyLink() {
	document.getElementById("buynow").style.display = "block";
	document.getElementById("pricingform").showbuylink.value = "true";
}

function hideBuyLink() {
	document.getElementById("buynow").style.display = "none";
	document.getElementById("pricingform").showbuylink.value = "false";
}

function getMaintenancePrice(platformPriceNode) {
	var maintOptions = platformPriceNode.getElementsByTagName("defaultmaintenanceoption");
	var maintDuration = desiredMaint.substr(0,1);
	var teaming = (wantsTeaming) ? "yes" : "no";
	var currency = (document.getElementById("dollars").checked) ? "usd" : "eur";
	var prices = null;
	for(var i = 0; i < maintOptions.length; i++) {
		if(maintOptions[i].getAttribute("years") == maintDuration) {
			prices = maintOptions[i].getElementsByTagName("price");
		}
	}
	if(prices != null) {
		var maintType = (desiredMaint.substr(1) == "p") ? "priority" : "standard";
		for(var i = 0; i < prices.length; i++) {
			if(prices[i].getAttribute("type") == maintType && prices[i].getAttribute("teaming") == teaming && prices[i].getAttribute("currency") == currency) return parseInt(prices[i].firstChild.data);
		}
	}
	return 0;
}

function getCustomMaintenancePrice(platformPriceNode,id) {
	var customMaintOptions = platformPriceNode.getElementsByTagName("custommaintenanceoptions");
	var maintDuration = desiredMaint.substr(0,1);
	var currency = (document.getElementById("dollars").checked) ? "usd" : "eur";
	var prices = null;
	for(var i = customMaintOptions.length-1; i >= 0; i--) {
		if(customMaintOptions[i].getAttribute("id") == id) {
			var maintOptions = customMaintOptions[i].getElementsByTagName("custommaintenanceoption");
			for(var j = 0; j < maintOptions.length; j++) {
				if(maintOptions[j].getAttribute("years") == maintDuration) {
					prices = maintOptions[j].getElementsByTagName("price");
				}
			}
		}
	}
	if(prices != null) {
		var maintType = (desiredMaint.substr(1) == "p") ? "priority" : "standard";
		for(var i = 0; i < prices.length; i++) {
			if(prices[i].getAttribute("type") == maintType && prices[i].getAttribute("currency") == currency) return parseInt(prices[i].firstChild.data);
		}
	}
	return 0;
}

function getPriceOptionNode(platformPriceNode) {
	var priceOptions = platformPriceNode.getElementsByTagName("option");
	for(var i = priceOptions.length-1; i >= 0 ; i--) {
		if(priceOptions[i].getAttribute("hasOES") == ((hasOES) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasOESMaint") == ((hasOESMaint) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasGW") == ((hasGroupWise) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasGWMaint") == ((hasGroupWiseMaint) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasZENSuite") == ((hasZENSuite) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasZENSuiteMaint") == ((hasZENSuiteMaint) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasZENDesktop") == ((hasZENDesk) ? "yes" : "no") && 
			priceOptions[i].getAttribute("hasZENDesktopMaint") == ((hasZENDeskMaint) ? "yes" : "no") && 
			priceOptions[i].getAttribute("teaming") == ((wantsTeaming) ? "yes" : "no")
		   ) {
			return priceOptions[i];
		}
	}
	return null;
}

function calculatePrice() {
	var summaryStep = document.getElementById("pricingwizard_step4");
	var maintenanceFrm = document.getElementById("maintenanceform");
	var finalOption = null;
	var platformPriceNode = null;
	var maintenancePrice = 0;
	hideBuyLink();
	
	var platform = (document.getElementById("platform_linux").checked) ? "Linux" : "Cross-Platform";
	if(platform == "Linux") {
		if(document.getElementById("rent_yes").checked) {
			// Linux Rented
			maintenanceFrm.style.display = "none";
			platformPriceNode = getPlatformPriceNode(summaryStep.priceXML,"Linux Rent");
			var priceOptions = platformPriceNode.getElementsByTagName("option");
			if(hasNOWS || (hasGroupWise && hasOES && hasZENSuite)) {
				// has nows or all products seperately
				priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWS","yes");
				if(hasNOWSMaint || (hasGroupWiseMaint && hasOESMaint && hasZENSuiteMaint)) {
					// has maintenance
					priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","yes");
				}
				else {
				 	priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","no");
				}
				finalOption = (wantsTeaming) ? filterOptionsWithAttribute(priceOptions,"teaming","yes")[0] : filterOptionsWithAttribute(priceOptions,"teaming","no")[0];
			}
			else {
				// does not have nows or all products seperately
				priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWS","no");
				finalOption = (wantsTeaming) ? filterOptionsWithAttribute(priceOptions,"teaming","yes")[0] : filterOptionsWithAttribute(priceOptions,"teaming","no")[0];
			}
			if(!wantsTeaming) {
				showBuyLink();
			}
		}
		else {
			// Linux Own
			maintenanceFrm.style.display = "block";
			setMaintenance();
			platformPriceNode = getPlatformPriceNode(summaryStep.priceXML,"Linux Own");
			var priceOptions = platformPriceNode.getElementsByTagName("option");
			if(hasNOWS) {
				// has nows or all products seperately
				priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWS","yes");
				if(hasNOWSMaint) {
					// has maintenance
					priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","yes");
					finalOption = (wantsTeaming) ? filterOptionsWithAttribute(priceOptions,"teaming","yes")[0] : filterOptionsWithAttribute(priceOptions,"teaming","no")[0];
				}
				else {
					wantsTeaming = true;  // have to upgrade with teaming
					document.getElementById("teaming_yes").checked = true;
				 	finalOption = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","no")[0];
				}
			}
			else {
				// does not have nows or all products seperately
				finalOption = getPriceOptionNode(platformPriceNode);
			}
			maintenancePrice = getMaintenancePrice(platformPriceNode);
		}
	}
	else {
		// Cross-Platform
		maintenanceFrm.style.display = "block";
		setMaintenance();
		platformPriceNode = getPlatformPriceNode(summaryStep.priceXML,"Cross-Platform");
		var priceOptions = platformPriceNode.getElementsByTagName("option");
		if(hasNOWS) {
			// has nows or all products seperately
			priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWS","yes");
			if(hasNOWSMaint) {
				// has maintenance
				priceOptions = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","yes");
				finalOption = (wantsTeaming) ? filterOptionsWithAttribute(priceOptions,"teaming","yes")[0] : filterOptionsWithAttribute(priceOptions,"teaming","no")[0];
			}
			else {
				document.getElementById("teaming_yes").checked = true;
				wantsTeaming = true;  // have to upgrade with teaming
				finalOption = filterOptionsWithAttribute(priceOptions,"hasNOWSMaint","no")[0];
			}
		}
		else {
			// does not have nows or all products seperately
			finalOption = getPriceOptionNode(platformPriceNode);
		}
		var customMaintenance = finalOption.getAttribute("customMaintenance");
		if(customMaintenance) maintenancePrice = getCustomMaintenancePrice(platformPriceNode,customMaintenance);
		else maintenancePrice = getMaintenancePrice(platformPriceNode);
	}
	if(finalOption != null) {
		setPrice(finalOption,maintenancePrice);
		setRecommendation(finalOption);
	}
	else {
		alert(msg_error);
	}
}

function setAllProductStatus(nows,gw,oes,suite,desk) {
	hasNOWS = nows;
	if(!nows) {
		hasNOWSMaint = false
		document.getElementById("maintenance_nows_no").checked = true;
	}
	hasGroupWise = gw;
	if(!gw) {
		hasGroupWiseMaint = false;
		document.getElementById("maintenance_groupwise_no").checked = true;
	}
	hasOES = oes;
	if(!oes) {
		hasOESMaint = false;
		document.getElementById("maintenance_oes_no").checked = true;
	}
	hasZENSuite = suite;
	if(!suite) {
		hasZENSuiteMaint = false;
		document.getElementById("maintenance_zensuite_no").checked = true;
	}
	hasZENDesk = desk;
	if(!desk) {
		hasZENDeskMaint = false;
		document.getElementById("maintenance_zendesk_no").checked = true;
	}
}

function selectProduct(inpt) {
	if(greatestCompleteStep > 1) {
		resetStep(4);
		resetStep(3);
	}
	var productInpts = inpt.parentNode.parentNode.getElementsByTagName("input");
	if(inpt == productInpts[0]) {
		// has none option selected
		if(inpt.checked == true) {
			document.getElementById("btn_2a_prev").style.display = "block";
			document.getElementById("btn_2a_next").style.display = "block";
			document.getElementById("pricingwizard_step2_b").style.display = "none";
			productInpts[0].parentNode.className = productInpts[0].parentNode.className.replace("disabled","");
			for(var i = productInpts.length-1; i > 0; i--) {
				productInpts[i].checked = false;
				if(productInpts[i].parentNode.className.indexOf("disabled") < 0) productInpts[i].parentNode.className += " disabled";
				document.getElementById("productmaintenance_"+productInpts[i].value).style.display = "none";
			}
			setAllProductStatus(false,false,false,false,false);
		}
		else {
			for(var i = productInpts.length-1; i >= 0; i--) {
				productInpts[i].parentNode.className = productInpts[i].parentNode.className.replace("disabled","");
			}
		}
	}
	else if(inpt == productInpts[1]) {
		// has NOWS selected
		if(inpt.checked == true) {
			document.getElementById("productmaintenance_"+inpt.value).style.display = "block";
			inpt.parentNode.className = inpt.parentNode.className.replace("disabled","");
			for(var i = productInpts.length-1; i >= 0; i--) {
				if(i != 1) {
					productInpts[i].checked = false;
					if(productInpts[i].parentNode.className.indexOf("disabled") < 0) productInpts[i].parentNode.className += " disabled";
					if(i > 1) document.getElementById("productmaintenance_"+productInpts[i].value).style.display = "none";
				}
			}
			setAllProductStatus(true,false,false,false,false);
		}
		else {
			for(var i = productInpts.length-1; i >= 0; i--) {
				productInpts[i].parentNode.className = productInpts[i].parentNode.className.replace("disabled","");
			}
			document.getElementById("btn_2a_prev").style.display = "block";
			document.getElementById("btn_2a_next").style.display = "block";
			document.getElementById("pricingwizard_step2_b").style.display = "none";
			document.getElementById("productmaintenance_"+inpt.value).style.display = "none";
			setAllProductStatus(false,false,false,false,false);
		}
	}
	else {
		switch(inpt.value) {
			case "groupwise" :
				hasGroupWise = (inpt.checked) ? true : false;
				hasGroupWiseMaint = false;
				document.getElementById("maintenance_groupwise_no").checked = true;
				break;
			case "oes" :
				hasOES = (inpt.checked) ? true : false;
				hasOESMaint = false;
				document.getElementById("maintenance_groupwise_no").checked = true;
				break;
			case "zensuite" :
				hasZENSuite = (inpt.checked) ? true : false;
				hasZENSuiteMaint = false;
				document.getElementById("maintenance_zensuite_no").checked = true;
				break;
			case "zendesk" :
				hasZENDesk = (inpt.checked) ? true : false;
				hasZENDeskMaint = false;
				document.getElementById("maintenance_zendesk_no").checked = true;
				break;
		}
		hasNOWS = false;
		if(inpt.checked) {
			if(productInpts[1].parentNode.className.indexOf("disabled") < 0) productInpts[1].parentNode.className += " disabled";
			if(productInpts[0].parentNode.className.indexOf("disabled") < 0) productInpts[0].parentNode.className += " disabled";
			for(var i = productInpts.length-1; i > 1; i--) {
				productInpts[i].parentNode.className = productInpts[i].parentNode.className.replace("disabled","");
			}
		}
		else if(hasGroupWise == false && hasOES == false && hasZENSuite == false && hasZENDesk == false) {
			productInpts[1].parentNode.className = productInpts[1].parentNode.className.replace("disabled","");
			productInpts[0].parentNode.className = productInpts[0].parentNode.className.replace("disabled","");
		}
		document.getElementById("productmaintenance_"+productInpts[1].value).style.display = "none";
		document.getElementById("productmaintenance_"+inpt.value).style.display = (inpt.checked) ? "block" : "none";
		productInpts[0].checked = false;
		productInpts[1].checked = false;
	}
}

function selectMaintenance(inpt) {
	switch(inpt.id) {
		case "maintenance_nows_yes" :
			hasNOWSMaint = true;
			break;
		case "maintenance_nows_no" :
			hasNOWSMaint = false;
			break;
		case "maintenance_groupwise_yes" :
			hasGroupWiseMaint = true;
			break;
		case "maintenance_groupwise_no" :
			hasGroupWiseMaint = false;
			break;
		case "maintenance_oes_yes" :
			hasOESMaint = true;
			break;
		case "maintenance_oes_no" :
			hasOESMaint = false;
			break;
		case "maintenance_zensuite_yes" :
			hasZENSuiteMaint = true;
			break;
		case "maintenance_zensuite_no" :
			hasZENSuiteMaint = false;
			break;
		case "maintenance_zendesk_yes" :
			hasZENDeskMaint = true;
			break;
		case "maintenance_zendesk_no" :
			hasZENDeskMaint = false;
			break;
	}
}

function setForceLinuxPlatform() {
	document.getElementById("platform_linux").checked = true;
	document.getElementById("pricingwizard_step3_b").style.display = "none";
	//document.getElementById("pricingwizard_step3_c").style.display = "block";
	//document.getElementById("pricingwizard_step3_c").className += " nobg";
}

function setForceCrossPlatform() {
	wantsTeaming = true;  // alternate messaging option only comes with teaming
	document.getElementById("teaming_yes").checked = true;
	document.getElementById("platform_crossplatform").checked = true;
	document.getElementById("pricingwizard_step3_a").style.display = "none";
	document.getElementById("pricingwizard_step3_b").style.display = "none";
	document.getElementById("pricingwizard_step3_c").style.display = "none";
	document.getElementById("pricingwizard_step3_d").style.display = "none";
	document.getElementById("pricingwizard_step3_e").style.display = "block";
	document.getElementById("pricingwizard_step3_e").className += " nobg";
}

function selectMessaging(value) {
	replaceMessaging = value;
}

function selectPlatform(inpt) {
	var platformInpts = inpt.parentNode.parentNode.getElementsByTagName("input");
	if(inpt == platformInpts[0]) {
		if(document.getElementById("pricingwizard_step3_d").style.display == "block") {
			document.getElementById("pricingwizard_step3_c").style.display = "block";
			document.getElementById("btn_3c_prev").style.display = "none";
			document.getElementById("btn_3c_next").style.display = "none";
		}
	}
	else {
		document.getElementById("pricingwizard_step3_c").style.display = "none";
		if(document.getElementById("pricingwizard_step3_d").style.display != "block") {
			document.getElementById("btn_3b_prev").style.display = "block";
			document.getElementById("btn_3b_next").style.display = "block";
		}
	}
}

function selectRent(inpt) {
	if(inpt.id == "rent_yes") {
		if(document.getElementById("pricingwizard_step3_e").style.display == "block") {
			document.getElementById("pricingwizard_step3_e").style.display = "none";
			document.getElementById("btn_3c_prev").style.display = "block";
			document.getElementById("btn_3c_next").style.display = "block";
		}
	}
}

function selectTeaming(value) {
	wantsTeaming = value;
}

function selectDesiredMaintenance(value) {
	desiredMaint = value;
}

function resetWizard() {
	resetStep(4);
	resetStep(3);
	resetStep(2);
	resetStep(1);
	goToStep(document.getElementById("startbtn"),1);
}

function changeMaintenanceLength(inpt) {
	var typeInpt = document.getElementById("desiredmaintenance_type");
	switch(inpt.options[inpt.selectedIndex].value) {
		case "0" :
			desiredMaint = "none";
			break;
		case "1" :
			desiredMaint = "1"+typeInpt.options[typeInpt.selectedIndex].value.substring(0,1).toLowerCase();
			break;
		case "3" :
			desiredMaint = "3"+typeInpt.options[typeInpt.selectedIndex].value.substring(0,1).toLowerCase()
			break;
	}
	document.getElementById("desiredmaintenance_"+desiredMaint).checked = true;
	calculatePrice();
}

function changeMaintenanceType(inpt) {
	var durationInpt = document.getElementById("desiredmaintenance_length");
	switch(inpt.options[inpt.selectedIndex].value) {
		case "Priority" :
			desiredMaint = durationInpt.options[durationInpt.selectedIndex].value+"p";
			break;
		case "Standard" :
			desiredMaint = durationInpt.options[durationInpt.selectedIndex].value+"s";
			break;
	}
	document.getElementById("desiredmaintenance_"+desiredMaint).checked = true;
	calculatePrice();
}

function resetStep(step) {
	document.getElementById("pricingwizard_step" + step).style.display = "none";
	document.getElementById("pricingwizard_tab_step" + step).className = "incomplete";
	switch(step) {
		case 2 :
			hasNOWS = false;
			hasNOWSMaint = false;
			hasGroupWise = false;
			hasGroupWiseMaint = false;
			hasOES = false;
			hasOESMaint = false;
			hasZENSuite = false;
			hasZENSuiteMaint = false;
			hasZENDesk = false;
			hasZENDeskMaint = false;
			var productOptions = document.getElementById("pricingwizard_step2_a").getElementsByTagName("input");
			for(var i = productOptions.length-1; i >= 0; i--) {
				productOptions[i].checked = false;
				productOptions[i].parentNode.className = productOptions[1].parentNode.className.replace("disabled","");
			}
			document.getElementById("maintenance_nows_no").checked = true;
			document.getElementById("maintenance_groupwise_no").checked = true;
			document.getElementById("maintenance_oes_no").checked = true;
			document.getElementById("maintenance_zensuite_no").checked = true;
			document.getElementById("maintenance_zendesk_no").checked = true;
			document.getElementById("productmaintenance_nows").style.display = "none";
			document.getElementById("productmaintenance_oes").style.display = "none";
			document.getElementById("productmaintenance_groupwise").style.display = "none";
			document.getElementById("productmaintenance_zensuite").style.display = "none";
			document.getElementById("productmaintenance_zendesk").style.display = "none";
			document.getElementById("pricingwizard_step2_b").style.display = "none";
			document.getElementById("btn_2a_prev").style.display = "block";
			document.getElementById("btn_2a_next").style.display = "block";
			break;
		case 3 :
			wantsTeaming = true;
			desiredMaint = "none";
			replaceMessaging = false;
			document.getElementById("replacemessaging_no").checked = true;
			document.getElementById("platform_linux").checked = true;
			document.getElementById("rent_no").checked = true;
			document.getElementById("teaming_yes").checked = true;
			document.getElementById("desiredmaintenance_none").checked = true;
			document.getElementById("pricingwizard_step3_a").style.display = "block";
			document.getElementById("btn_3a_prev").style.display = "block";
			document.getElementById("btn_3a_next").style.display = "block";
			document.getElementById("pricingwizard_step3_b").style.display = "none";
			document.getElementById("btn_3b_prev").style.display = "block";
			document.getElementById("btn_3b_next").style.display = "block";
			document.getElementById("pricingwizard_step3_c").style.display = "none";
			document.getElementById("btn_3c_prev").style.display = "block";
			document.getElementById("btn_3c_next").style.display = "block";
			document.getElementById("pricingwizard_step3_d").style.display = "none";
			document.getElementById("btn_3d_prev").style.display = "block";
			document.getElementById("btn_3d_next").style.display = "block";
			document.getElementById("pricingwizard_step3_e").style.display = "none";
			document.getElementById("pricingwizard_step3_b").className = document.getElementById("pricingwizard_step3_b").className.replace("nobg","");
			document.getElementById("pricingwizard_step3_c").className = document.getElementById("pricingwizard_step3_c").className.replace("nobg","");
			document.getElementById("pricingwizard_step3_d").className = document.getElementById("pricingwizard_step3_d").className.replace("nobg","");
			document.getElementById("pricingwizard_step3_e").className = document.getElementById("pricingwizard_step3_e").className.replace("nobg","");
			break;
		case 4 :
			document.getElementById("emailquote_input").style.display = "none";
			break;
	}
	greatestCompleteStep = step-2;
}

function hideStep(step) {
	document.getElementById("pricingwizard_step" + step).style.display = "none";
	document.getElementById("pricingwizard_tab_step" + step).className = "completed";
}

function showStep(step) {
	document.getElementById("pricingwizard_step" + step).style.display = "block";
	document.getElementById("pricingwizard_tab_step" + step).className = "active";
}

function showSubStep(step,oldSub,newSub) {
	document.getElementById("btn_"+step+oldSub+"_prev").style.display = "none";
	document.getElementById("btn_"+step+oldSub+"_next").style.display = "none";
	document.getElementById("pricingwizard_step"+step+"_"+newSub).style.display = "block";
}

function completeStep(step) {
	for(var i = 1; i <= step; i++) {
		hideStep(i);
	}
	if(step > greatestCompleteStep) greatestCompleteStep = step;
}

function goToStep(trigger,step,substep) {
	if(trigger.parentNode.className != "btn_pricing" && trigger.parentNode.className.indexOf("completed") < 0) return;
	if(step <= greatestCompleteStep && step != currentStep) {
		hideStep(currentStep);
	}

	switch(step) {
		case 1 : 
			currentStep = 1;
			document.getElementById("pricewizard_start").style.display = "none";
			document.getElementById("pricingwizard_steps").style.display = "block";
			showStep(1);
			loadPrices();
			break;
		case 2 :
			currentStep = 2;
			if(substep == "b") {
				// first verify completed before letting user proceed
				var products = trigger.parentNode.parentNode.getElementsByTagName("input");
				var noProductsSelected = true;
				for(var i = products.length-1; i >= 0; i--) {
					if(products[i].checked) {
						noProductsSelected = false;
						break;
					}
				}
				if(noProductsSelected) {
					alert(msg_selectproduct);
					return;
				}
				// if selected none then move to step 3
				if(products[0].checked) {
					goToStep(trigger,3);
					return;
				}
				// products selected so ask about maintenance
				showSubStep(2,'a','b');
			}
			else {
				completeStep(1);
				showStep(2);
			}
			break;
		case 3 :
			currentStep = 3;
			switch(substep) {
				case 'b' :
					// go to platform question
					if(hasNOWS == false && hasGroupWise == false && hasOES == false && hasZENSuite == false && hasZENDesk == false) {
						if(replaceMessaging) {
							// user owns no products and wants to replace messaging platform
							setForceLinuxPlatform();
							showSubStep(3,'a','c');
						}
						else {
							// user owns no products and does not want to replace messaging platform
							wantsTeaming = true;  // alternate messaging option only comes with teaming
							document.getElementById("teaming_yes").checked = true;
							document.getElementById("platform_crossplatform").checked = true;
							showSubStep(3,'a','e');
						}
					}
					else {
						showSubStep(3,'a','b');
					}
					break;
				case 'c' :
					// go to rent/own question
					if(document.getElementById("platform_linux").checked) showSubStep(3,'b','c');
					else showSubStep(3,'b','d');
					break;
				case 'd' :
					// go to teaming question
					if(hasNOWS == false && hasGroupWise == false && hasOES == false && hasZENSuite == false && hasZENDesk == false) {
						// user does not own any products already so don't show them teaming option, just force them to product with teaming
						wantsTeaming = true;
						document.getElementById("teaming_yes").checked = true;
						if(document.getElementById("rent_yes").checked && document.getElementById("platform_linux").checked) {
							goToStep(trigger,4);
						}
						else {
							goToStep(trigger,3,'e');
						}
					}
					else {
						showSubStep('3','c','d');				
					}
					break;
				case 'e':
					// go to maintenance question
					if(document.getElementById("rent_yes").checked && document.getElementById("platform_linux").checked) {
						goToStep(trigger,4);
					}
					else {
						if(document.getElementById("platform_linux").checked && document.getElementById("rent_no").checked && hasNOWS == false && hasGroupWise == false && hasOES == false && hasZENSuite == false && hasZENDesk == false) {
							showSubStep(3,'c','e');
						}
						else {
							showSubStep(3,'d','e');
						}
					}
					break;
				default :
					completeStep(2);
					if(hasNOWS == false && hasGroupWise == false && hasOES == false && hasZENSuite == false && hasZENDesk == false) {
						// user has selected no products so ask them if they want to replace messaging platform
						document.getElementById("pricingwizard_step3_a").style.display = "block";
					}
					else if(hasNOWS == false && hasGroupWise == false) {
						// user doesn't have groupwise so default to cross-platform for alternate messaging systems
						setForceCrossPlatform();
					}
					else {
						document.getElementById("pricingwizard_step3_a").style.display = "none";
						document.getElementById("pricingwizard_step3_b").style.display = "block";
						document.getElementById("pricingwizard_step3_b").className = document.getElementById("pricingwizard_step3_b").className.replace("nobg","");
						document.getElementById("pricingwizard_step3_c").className = document.getElementById("pricingwizard_step3_c").className.replace("nobg","");
					}
					showStep(3);
			};
			break;
		case 4 :
			currentStep = 4;
			completeStep(3);
			calculatePrice();
			showStep(4);
	}
}

/* Information note popups
---------------------------------------------- */
function showNote(trigger, msg) {
	var noteDiv = document.getElementById("infonote");
	if(!noteDiv) {
		noteDiv = document.createElement("div");
		noteDiv.id = "infonote";
		document.getElementsByTagName("body")[0].appendChild(noteDiv);
	}
	noteDiv.innerHTML = '<div id="infonote_msg">'+msg+'</div>';

	// position and show popup in correct location
	var pos = getXY(trigger);
	var scrollL = document.body.scrollLeft;
	var scrollT = document.body.scrollTop;
	with(noteDiv.style) {
		visibility = 'hidden';
		display = "block";
		left = (pos[0] + scrollL + 14)+'px';
		top  = (pos[1] + scrollT - 26)+'px';
		visibility = 'visible';
	}
}

function hideNode() {
	var noteDiv = document.getElementById("infonote");
	noteDiv.style.display = "none";
	noteDiv.innerHTML = "";
}

/* Functions for sending the price quote email
---------------------------------------------- */
function getPageCharset() {
	var mt = document.getElementsByTagName('meta');
	for(var i=0; i<mt.length; i++) {
		var ct = mt[i].getAttribute('content');
		if(ct != null && ct.toLowerCase().indexOf('charset=') != -1) return ct.substring(ct.toLowerCase().indexOf('charset=')+8);
	}
	return "";
}

function setCharset() {
	document.getElementById("pricingform").charset.value = getPageCharset();
}

function setEmail(email_address) {
	var email_to = document.getElementById('email_to');
	if (!email_to) {
		var email_to = document.createElement("input");
		email_to.setAttribute("type", "hidden");
		email_to.name = "email_to";
		email_to.id = "email_to";
		document.getElementById('hiddenvaluesforemail').appendChild(email_to);
	}
	email_to.value = email_address;
}

function trim(s) {
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function sendEmail() {
	var email = document.getElementById('email_me').value;
	if (trim(email).length == 0) {
		alert(msg_enteremail);
		document.getElementById('email_me').focus();
	} else {
		// go ahead and send the email
		setCharset(); // First set the charset in the form, so the processing jsps will know how to decode this form's data
		setEmail(email);// Then create an "email_to" hidden input in the form for send_email.jsp, with the value they provided
		document.getElementById('pricingform').submit();
	}
}
