
var special_NonComplyMessage = special_NonComplyMessage_1 + specialProductName + special_NonComplyMessage_2;
var special_promoText = special_promoText_1; // + specialProductName + special_promoText_2;
var special_conditionsHeader = special_conditionsHeader_1 +specialProductName+special_conditionsHeader_2;
var special_condition1 = special_condition1_1; // + special_cscPercentage + special_condition1_2;
var special_condition2 = special_condition2_1; // + special_maxDealSize + special_condition2_2;
var special_condition4 = special_condition4_1;
var special_condition5 = special_condition5_1;

var special_conditionsDesc = special_condition1 + "\n" + special_condition2 + "\n" + special_condition3;

var disclaimerAdditionalHTML;
var PBX6MonthRemarkHTML;

function composeAdditionalDisclaimer(){

	var ltv = sessionController.getValue("leaseProduct").val;
	var is_spec_leaseProduct;

	if ( isSpecialLeaseType() ) {
		is_spec_leaseProduct = true;
	} else {
		is_spec_leaseProduct = false;
	}
	
	if (ltv == null) {
		var lt = document.getElementById("leaseProduct");
		var ltv = lt.options[lt.selectedIndex].text;
		PBX6MonthRemarkHTML = "";
	}
	else {
		PBX6MonthRemarkHTML = "";
	}
	
	disclaimerAdditionalHTML="";
	
	if (disclaimerMode=="table"){
		var width_perc;
		
		if (document.getElementById("thisiscalc")!=null) {
			width_perc=width_perc_1;
		} else {
			width_perc=width_perc_2;
		}

		if (ltv.indexOf("Voice")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title_voice + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (ltv.indexOf("Network")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title_port + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (ltv.indexOf("FIPP")!=-1) {
				disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title_fipp + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (ltv.indexOf("PartnerPlus")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title_partnerplus + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (ltv.indexOf("A2C")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title_a2c + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (is_spec_leaseProduct) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditional_title + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}
		else if (ltv.indexOf("PBX")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr height=1><td width='" + width_perc + "%' ></td><td width='" + (100 - width_perc) + "%' class='formcontent'><b>" + disclaimerAdditionalPBX_title + ltv + "</b></td></tr><tr><td height='5' colspan='2'></td></tr>";
		}

		if (ltv.indexOf("6")!=-1) {
			for (var i=0;i<disclaimerAdditionalPBX_6_months.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditionalPBX_6_months[i]+"</td></tr>";
			}
			for (var i=0;i<PBX6MonthRemark.length;i++){
				PBX6MonthRemarkHTML = "* "
				PBX6MonthRemarkHTML = PBX6MonthRemarkHTML + PBX6MonthRemark[i]+"<br>";
			}
		}
		else if (ltv.indexOf("Knockout 0")!=-1) {
			for (var i=0;i<disclaimerAdditionalPBX_0_percent.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditionalPBX_0_percent[i]+"</td></tr>";
			}
		}
		else if (ltv.indexOf("Voice")!=-1) {
			for (var i=0;i<disclaimerAdditional_voice_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional_voice_txt[i]+"</td></tr>";
			}
		}
		else if (ltv.indexOf("Network")!=-1) {
			for (var i=0;i<disclaimerAdditional_port_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional_port_txt[i]+"</td></tr>";
			}
		}
		else if (ltv.indexOf("FIPP")!=-1) {
			for (var i=0;i<disclaimerAdditional_fipp_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional_fipp_txt[i]+"</td></tr>";
			}
		}
		else if (ltv.indexOf("PartnerPlus")!=-1) {
			for (var i=0;i<disclaimerAdditional_partnerplus_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional_partnerplus_txt[i]+"</td></tr>";
			}
		}
		else if (ltv.indexOf("A2C")!=-1) {
			for (var i=0;i<disclaimerAdditional_a2c_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional_a2c_txt[i]+"</td></tr>";
			}
		}
		else if (is_spec_leaseProduct) {
			for (var i=0;i<disclaimerAdditional.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<tr height=1><td></td><td>"+disclaimerAdditional[i]+"</td></tr>";
			}
		}

		disclaimerAdditionalHTML = disclaimerAdditionalHTML + "</table>";
	} else if (disclaimerMode=="ul"){
		
		if (ltv.indexOf("Voice")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+ disclaimerAdditional_title_voice + "</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (ltv.indexOf("Network")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+ disclaimerAdditional_title_port +"</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (ltv.indexOf("FIPP")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+ disclaimerAdditional_title_fipp +"</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (ltv.indexOf("PartnerPlus")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+ disclaimerAdditional_title_partnerplus +"</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (ltv.indexOf("A2C")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+ disclaimerAdditional_title_a2c +"</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (is_spec_leaseProduct) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+disclaimerAdditional_title + "</b></td></tr><tr valign='top'><td><ul>";
		}
		else if (ltv.indexOf("PBX")!=-1) {
			disclaimerAdditionalHTML = "<table border=0 class='DisclaimerText' ><tr><td class='formcontent'><b>"+disclaimerAdditionalPBX_title + ltv +"</b></td></tr><tr valign='top'><td><ul>";
		}
		
		if (ltv.indexOf("6")!=-1) {
			for (var i=0;i<disclaimerAdditionalPBX_6_months.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditionalPBX_6_months[i]+"</li>";
			}
			PBX6MonthRemarkHTML = "* "
			for (var i=0;i<PBX6MonthRemark.length;i++){
				PBX6MonthRemarkHTML = PBX6MonthRemarkHTML + PBX6MonthRemark[i]+"<br>";
			}
		}
		else if (ltv.indexOf("Knockout 0")!=-1) {
			for (var i=0;i<disclaimerAdditionalPBX_0_percent.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditionalPBX_0_percent[i]+"</li>";
			}
		}
		else if (ltv.indexOf("Voice")!=-1) {
			for (var i=0;i<disclaimerAdditional_voice_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional_voice_txt[i]+"</li>";
			}
		}
		else if (ltv.indexOf("Network")!=-1) {
			for (var i=0;i<disclaimerAdditional_port_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional_port_txt[i]+"</li>";
			}
		}
		else if (ltv.indexOf("FIPP")!=-1) {
			for (var i=0;i<disclaimerAdditional_fipp_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional_fipp_txt[i]+"</li>";
			}
		}
		else if (ltv.indexOf("PartnerPlus")!=-1) {
			for (var i=0;i<disclaimerAdditional_partnerplus_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional_partnerplus_txt[i]+"</li>";
			}
		}
		else if (ltv.indexOf("A2C")!=-1) {
			for (var i=0;i<disclaimerAdditional_a2c_txt.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional_a2c_txt[i]+"</li>";
			}
		}
		else if (is_spec_leaseProduct) {
			for (var i=0;i<disclaimerAdditional.length;i++){
				disclaimerAdditionalHTML = disclaimerAdditionalHTML + "<li>"+disclaimerAdditional[i]+"</li>";
			}
		}

		disclaimerAdditionalHTML = disclaimerAdditionalHTML + "</ul></td></tr></table>";
	}
}

function cctl_AddItemUK(doNotCalculate) {
	// lease type must be selected if it exists on the page
	var lt = document.getElementById("leaseProduct");
	if (lt != null) {
		var ltv = lt.options[lt.selectedIndex].text;
		if (ltv == null || ltv.indexOf("----") != -1) {
		//	alert(g_selectValidLeaseMsg);
			return;
		}
		else
		{
			//first keep selected value for reference in print page
			var lpv = document.getElementById("leaseProductValue");
			if (lpv != null)
			{
				lpv.value = ltv;
			}
		}
	}
	
// type must be selected
	var et = document.getElementById("equipmentType");
	if (et == null) { alert("Required element 'equipmentType' missing!"); return; }

	var etv = et.options[et.selectedIndex].text;
	if (etv == null || etv.indexOf("----") != -1) {
		alert(g_selectValidTypeMsg);
		return;
	}

	var modelNr="dummyModel";
/** validations no longer needed for UK
	// Model must be selected for promotions
	if (promotion.isPromotion(et.options[et.selectedIndex].value))
	{
		var em = sessionController.getValue("equipmentModel").val;

		if (em == null || em.indexOf("----") != -1) {
			alert(g_selectValidModelMsg);
			return;
		}
		modelNr=em;
	}
	else
	{
		var em = document.getElementById("equipmentModel");
		if (em == null) { alert("Required element 'equipmentModel' missing!"); return; }

		if (em.value == "") {
			alert(g_selectValidModelMsg);
			return;
		}
		modelNr=em.value;
	}
	// equipment description cannot be empty
	var ed = sessionController.getValue("equipmentDescription").val;
	if (ed == null || ed == "") {
		alert(g_validDescriptionMsg);
		return;
	}
	// quantity must be equal to or greater than 1
	var eq = parseInt(sessionController.getValue("equipmentQuantity").val);
	if (isNaN(eq) || eq <= 0) {
		alert(g_minQuantityMsg);
		return;
	}
*/
	var ed="dummyDescription";
	var eq=1;

	// Sales prices must be a float
	var es = nf_parseFloat(sessionController.getValue("equipmentAmount").val);
	if (isNaN(es)) {
		alert(g_validSalespriceMsg);
		return;
	}

	var np = parseInt(sessionController.getValue("numberOfPorts").val);
  if ( isPricePerPort() )	
  {
  	// Get number of ports
  	if (isNaN(np) || np<=0) {
  		alert(g_minQuantityMsg);
  		return;
  	}
  }
  else if ( isPricePerUser() )	
  {
  	// Get number of ports
  	if (isNaN(np) || np<=0) {
  		alert(g_minQuantityMsg);
  		return;
  	}
  }
  else
  {
    np=1;
  }  
  
  // es = es / np;
  es = es;

	// add the items to the equipmentlist
//	it_AddItem("equipmentList", etv, modelNr, ed, eq, nf_formatNumeric(es), nf_formatNumeric(eq * es));
	it_AddItem("equipmentList", etv, nf_formatNumeric(es), np);

	// fixate the lease product selector

	if (lt != null)
		sessionController.setValue("leaseProduct", null, true);
	var npitm = document.getElementById("numberOfPorts");
	if (npitm != null)
		sessionController.setValue("numberOfPorts", null, true);

	if (doNotCalculate != true) cctl_specialCalculate();
	cctl_Clear();

	try {
		onLocalAddItem(doNotCalculate);
	}
	catch (E) {}

}

function cctl_specialCalculate() {
	var fr = document.getElementById("frequency");
	if (fr == null) { alert("Required element 'frequency' missing!"); return; }
	var pr = document.getElementById("period");
	if (pr == null) { alert("Required element 'period' missing!"); return; }
	var ta = document.getElementById("totalAmounts");
	if (ta == null) { alert("Required element 'totalAmounts' missing!"); return; }
	var tp = document.getElementById("totalPayments");
	if (tp == null) { alert("Required element 'totalPayments' missing!"); return; }
	var tf = document.getElementById("totalFirstPayments");
	if (tf == null) { alert("Required element 'totalFirstPayments' missing!"); return; }
	var pt = document.getElementById("totalPromosAddedToList");
	if (pt == null) { alert("Required element 'totalPromosAddedToList' missing!"); return; }
	var ts = document.getElementById("totalsStatus");
	if (ts == null) { alert("Required element 'totalsStatus' missing!"); return; }
	var np = document.getElementById("numberOfPorts");
	if (np == null) { alert("Required element 'number of ports' missing!"); return; }

  // get number of ports
  //var npval = parseInt(sessionController.getValue("numberOfPorts").val);
  var npval = parseInt(np.value);
  if ( isNaN(npval) || npval <= 0 )
  {
    npval=1;
  }
  
	var equipmentTable = itemTable("equipmentList");
	var type = "";
	var promotionId="";
	var amount = 0;
	var totalAmount = 0;
	var totalPayment = 0;
	var totalFirstPayment = 0;
	var rate;
	var typeColumn = 1;


	var totalAmountColumn = equipmentTable.getColumn(2);
	var numberOfPortsColumn = equipmentTable.getColumn(3);
	var firstPaymentColumn = equipmentTable.getColumn(4);
	var pauseColumn = equipmentTable.getColumn(5);
	var furtherPaymentsColumn = equipmentTable.getColumn(6);
	var paymentAmountColumn = equipmentTable.getColumn(7);
	var endPaymentColumn = equipmentTable.getColumn(8);

	var promoCount = 0;
//	var frequency = fr.options(fr.selectedIndex).value;
	var frequency = sessionController.getValue("frequencyValue").val;
	var period = pr.options(pr.selectedIndex).value;
	var firstPayment;
	var payment;
	var endPayment;

	// If the global variables g_vendor and g_nonVendor are assigned,
	// then subtotals will be calculated for vendor and nonVendor equipment
	var typeOfEquipment;
	var totalNonVendor = 0;
	var totalVendor = 0;
	var totalSettlementAmount = 0;

	ta.innerHTML = "";
	sessionController.setValue("unformatted_totalAmounts", 0, false)
	tp.innerHTML = "";
	sessionController.setValue("unformatted_totalPayments", 0, false)
	tf.innerHTML = "";
	sessionController.setValue("unformatted_totalFirstPayments", 0, false)
	ts.innerHTML = "";

	if (equipmentTable.getNrOfItems()>0) {
		// Calculate the total amount for all equipment. The getRate method requires the total amount to determine
		// the payment profile for each line item
		for (var q=0; q<equipmentTable.getNrOfItems(); q++) {
			var qc = equipmentTable.getRowNr(q); // get the real row nr for getEntry
			amount = nf_parseFloat(equipmentTable.getEntry(qc, totalAmountColumn));

			// Determine the amount allocated to vendor specific equipment
			typeOfEquipment = equipmentTable.getEntry(qc, typeColumn);
			if (cctl_isVendorEquipment(typeOfEquipment))
				totalVendor += amount;
			else
				totalNonVendor += amount;
				
			if (cctl_isSettlement(typeOfEquipment))	
				totalSettlementAmount += amount;
					
			totalAmount += amount;
		}
		ta.innerHTML = nf_formatNumeric(totalAmount);

		if (document.getElementById("unformatted_totalNonVendorAmount") != null) sessionController.setValue("unformatted_totalNonVendorAmount", totalNonVendor, false );
		if (document.getElementById("unformatted_totalVendorAmount") != null) sessionController.setValue("unformatted_totalVendorAmount", totalVendor, false );
		if (document.getElementById("unformatted_totalSettlementAmount") != null) sessionController.setValue("unformatted_totalSettlementAmount", totalSettlementAmount, false );
		sessionController.setValue("unformatted_totalAmounts", totalAmount, false);

		for (var q=0; q<equipmentTable.getNrOfItems(); q++) {
			var qc = equipmentTable.getRowNr(q); // get the real row nr for getEntry
			
			// determine amount for the equipment and the promotion type
			type = equipmentTable.getEntry(qc, typeColumn);
			amount = nf_parseFloat(equipmentTable.getEntry(qc, totalAmountColumn));
			promotionId = promotion.getPromotionId(type);
			if (promotion.isPromotion(promotionId)) {
				// Promotion:
				promoCount++;

				rate = promotion.getFirstPaymentRate(promotionId);
				firstPayment = rateCalculator.calculate(amount, 0, rate);
				rate = promotion.getPromotionRate(promotionId);
				payment = rateCalculator.calculate(amount, 0, rate);
				rate = promotion.getEndPaymentRate(promotionId);
				endPayment = rateCalculator.calculate(amount, 0, rate);

				equipmentTable.setEntry(qc, firstPaymentColumn, nf_formatNumeric(firstPayment/npval), false, true);
				equipmentTable.setEntry(qc, furtherPaymentsColumn,  promotion.getPromotionFurtherPayments(promotionId), false, true);
				equipmentTable.setEntry(qc, paymentAmountColumn, nf_formatNumeric(payment/npval), false, true);
				equipmentTable.setEntry(qc, pauseColumn, promotion.getPromotionPause(promotionId), false, true);
				if (endPayment>0) {
					equipmentTable.setEntry(qc, endPaymentColumn, nf_formatNumeric(endPayment/npval), false, true);
				}
				else {
					equipmentTable.setEntry(qc, endPaymentColumn, "", false, true);
				}
			}
			else {
				// Regular:	get the rate for this type of asset
				rate = rateCalculator.getRate(totalAmount, frequency, period , g_countryAbbreviation , cctl_determineExtension(type))
				payment = rateCalculator.calculate(amount, 0, rate);
				firstPayment = payment;
				
				equipmentTable.setEntry(qc, firstPaymentColumn, nf_formatNumeric(firstPayment/npval), false, true);
				equipmentTable.setEntry(qc, furtherPaymentsColumn, cctl_DetermineNrOfFurtherPaymentsForRegular(period, frequency), false, true);
				equipmentTable.setEntry(qc, paymentAmountColumn, nf_formatNumeric(payment/npval), false, true);
				equipmentTable.setEntry(qc, pauseColumn, 0, false, true);
				equipmentTable.setEntry(qc, endPaymentColumn, "", false, true);
				
				var nocomm_payment = rateCalculator.calculate(amount, 0, rate);
			}
			// use the displayed values to update the totals to prevent rounding errors
			totalFirstPayment+=nf_parseFloat(equipmentTable.getEntry(qc, firstPaymentColumn));
			totalPayment+=nf_parseFloat(equipmentTable.getEntry(qc, paymentAmountColumn));
		}

		tp.innerHTML = nf_formatNumeric(totalPayment);
		sessionController.setValue("unformatted_totalPayments", totalPayment, false);

		tf.innerHTML = nf_formatNumeric(totalFirstPayment);
		sessionController.setValue("unformatted_totalFirstPayments", totalFirstPayment, false);

		var blankPaymentColumns = false;
		
		if(window.getNewTransactionAmounts) {
			NTA = getNewTransactionAmounts();
			g_minTransaction = NTA['g_minTransaction'];
			g_maxTransaction = NTA['g_maxTransaction'];
			g_maxTransactionNorm = NTA['g_maxTransactionNorm'];
			g_maxTransaction_0Perc = NTA['g_maxTransaction_0Perc'];
			g_minTransactionMsg = NTA['g_minTransactionMsg'];
			g_maxTransactionMsg = NTA['g_maxTransactionMsg'];
		}
		
		if (isSpecialLeaseType()) {
			
			if (exceedMaxDealSize()) {
				blankPaymentColumns = g_blankPaymentAtMin;
				disableButtonContinue(true);
			} else {
				if (typeof g_maxTransaction != "undefined" && !isNaN(g_maxTransaction) && totalAmount>(g_maxTransaction)) {
					ts.innerHTML = g_maxTransactionMsg;
					blankPaymentColumns = g_blankPaymentAtMax;
					disableButtonContinue(true);
				} else if (typeof g_minTransaction != "undefined" && !isNaN(g_minTransaction) && totalAmount<(g_minTransaction)) {
					ts.innerHTML = g_minTransactionMsg;
					blankPaymentColumns = g_blankPaymentAtMin;
					disableButtonContinue(true);
				}
			}
		} else {
			if (typeof g_minTransaction != "undefined" && !isNaN(g_minTransaction) && totalAmount<(g_minTransaction)) {
				ts.innerHTML = g_minTransactionMsg;
				blankPaymentColumns = g_blankPaymentAtMin;
				disableButtonContinue(true);
			}
			else if (typeof g_maxTransaction != "undefined" && !isNaN(g_maxTransaction) && totalAmount>(g_maxTransaction)) {
				ts.innerHTML = g_maxTransactionMsg;
				blankPaymentColumns = g_blankPaymentAtMax;
				disableButtonContinue(true);
			} else if(typeof g_minPercFormVendor != "undefined" && (g_minPercFormVendor * totalAmount > totalVendor)) {
				ts.innerHTML = g_minPercFormVendorMsg;
				disableButtonContinue(true);
			} else if (isPBXPromotion() && totalSettlementAmount > (special_settlementAmountPerc/100*totalAmount) ) {
				ts.innerHTML = special_condition4;
				disableButtonContinue(true);
			
			} else {
				disableButtonContinue(false);
			}
		}
		if (blankPaymentColumns) {
			// blank the payment related columns
			equipmentTable.blankColumn(firstPaymentColumn);
			equipmentTable.blankColumn(pauseColumn);
			equipmentTable.blankColumn(furtherPaymentsColumn);
			equipmentTable.blankColumn(paymentAmountColumn);
			equipmentTable.blankColumn(endPaymentColumn);
			// blank the payment totals
			tp.innerHTML = "";
			sessionController.setValue("unformatted_totalPayments", 0, false)
			tf.innerHTML = "";
			sessionController.setValue("unformatted_totalFirstPayments", 0, false)
		}
	}

	// Allow country specific local calculations if the method onLocalCalculate is defined
	try {
		onLocalCalculate(equipmentTable);
	}
	catch (E) {}

	// if the list has no more promotions unfreeze the period and frequency and refill the equipment type combo with all promotions
	pt.value = promoCount;
	if (promoCount==0) {
		// unfreeze the period and frequency
		sessionController.setValue("period", sessionController.getValue("period"), false);
		sessionController.setValue("frequency", sessionController.getValue("frequency"), false);

		if (!typeSelectionChanging)	{
			cctl_FillEquipmentTypes();
		}
	}
	else {
		// freeze the period and frequency to the promotion's period and frequency
		sessionController.setValue("period", sessionController.getValue("period"), true);
		sessionController.setValue("frequency", sessionController.getValue("frequency"), true);

		// refill the equipment type combo with just the promotions having the same frequency and period
		if (!typeSelectionChanging)	{
			cctl_FillEquipmentTypesForPeriodAndFrequency();
		}
	}
}

function special_onLoad(automaticSessionHandling) {

	debugWindow.writeln("CalculatorController onLoad");
	if (automaticSessionHandling == null) automaticSessionHandling = true;

	// The automatic session handling is turned of by the request page which also uses the calculator controller to
	// manage the equipment list. The request page manages its own asset, product and commission boxes.
	if (automaticSessionHandling) {
		cctl_fillAssets();
		special_fillProducts();
		cctl_fillCommissionBox();
	}


	// Prefill the equipment types with the global values specified in the page
	cctl_prefillEquipmentTypes();
	g_defaultEquipmentTypeOptions = cctl_BackupOptions(document.getElementById("equipmentType"), g_defaultEquipmentTypeOptions);
//	g_defaultEquipmentModelOptions = cctl_BackupOptions(document.getElementById("equipmentModel"), g_defaultEquipmentModelOptions);


	// If automatic session handling is turned on, the fields on the calculator page are automatically stored in the session cookie when
	// changed or restored by pressing the back button.
	if (automaticSessionHandling) {
		var dt = document.getElementById("date");
		if (dt == null) { alert("Required element 'date' missing!"); return; }
		
		
		// store the values for those elements that need to show that value after a postback
		// the validator fields are automatically marked as storage fields
		sessionController.addField("unformatted_totalAmounts");
		if (document.getElementById("unformatted_totalNonVendorAmount") != null) sessionController.addField("unformatted_totalNonVendorAmount");
		if (document.getElementById("unformatted_totalVendorAmount") != null) sessionController.addField("unformatted_totalVendorAmount");
		if (document.getElementById("unformatted_totalSettlementAmount") != null) sessionController.addField("unformatted_totalSettlementAmount");
		sessionController.addField("unformatted_totalPayments");
		sessionController.addField("unformatted_totalFirstPayments");
		sessionController.addField("periodValue");
		sessionController.addField("frequencyValue");
		if (document.getElementById("leaseProductValue") != null)
			sessionController.addField("leaseProductValue");
		sessionController.addField("provision");
		
		sessionController.addField("quoteTo");
		sessionController.addField("quoteFrom");
		sessionController.addField("repID");
		sessionController.addField("phoneNr");
		sessionController.addField("reseller");
		sessionController.addField("comment");
		sessionController.addField("date");
		
		sessionController.addField("period");
		sessionController.addField("frequency");
		sessionController.addField("disclaimer");
		
		if (document.getElementById("leaseProduct") != null) sessionController.addField("leaseProduct");
		if (document.getElementById("numberOfPorts") != null) sessionController.addField("numberOfPorts");
		
		// check the page integrity and set the defaults
		sessionController.restore();
		var eqlistcol3 = document.getElementById("equipmentList.col3");
		if (eqlistcol3 == null) { alert("Required element 'equipmentList.col3' missing!"); return; }
		if ( isPricePerPort() || isPricePerUser()) {
			eqlistcol3.style["visibility"] = "";
		} else {
			eqlistcol3.style["visibility"] = "hidden";
		}  		
		cctl_FillEquipmentTypes();
		d = new Date();
		dt.value = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getYear();
		// update the equipment table

		it_restoreFromSessionState("equipmentList");
		cctl_specialCalculate();
			
		cctl_onLeaseProductSelectionChanged();	
	}

	special_DisablePeriods();

	var ltv = sessionController.getValue("leaseProduct").val;
	if (ltv == null) {
		var lt = document.getElementById("leaseProduct");
		var ltv = lt.options[lt.selectedIndex].text;
	}
//	if (isSpecialLeaseType() || (ltv.indexOf("Easy")!=-1) || ltv.indexOf("PBX")!=-1) {
	if (isSpecialLeaseType() || ltv.indexOf("PBX")!=-1) {
		setAdditionalDisclaimer(true);
	}
}

function special_fillProducts(elementName) {

	var optionIndex;

	if (elementName==null) elementName="leaseProduct";
	var et = document.getElementById(elementName);
	if (et == null) { alert("Required element '" + elementName + "' missing!"); return; }
	var products = null;
	try { products=cc_getProducts(g_countryAbbreviation); } catch(E) {}
	if (products && et.options) {
		// make options.length equal to amount of products
		et.options.length = 1; //products.length + 1;
		et.options[0] = new Option("------", "", true, true);
		var i;
		for (i = 1; i < products.length + 1; i++) {
			var product = products[i-1];
			
			// perform a locale dependant translation if defined
			try { product = onLocalTranslateLeaseProduct(product, true); } catch(E) {}

			try{
				if (product==specialProductName){
					if (!isSpecialProductPeriod()) {
						continue;
					}
					else {
						displaySpecialAvailable();
					}
				}
			} catch(E) {}
			et.options.length = et.options.length + 1;
			optionIndex = et.options.length - 1;
		    	et.options[optionIndex] = new Option(product, 1);
		}

	}
}

function isSpecialProductPeriod(){
	var today, month, day;
	var todayString;
	if ((specialProductStart!=null)&&(specialProductEnd!=null)){
		if (specialProductEnd>=specialProductStart){
			today=new Date();
			month = (today.getMonth()+1).toString();
			if (month.length==1) month="0"+month;
			day = today.getDate().toString();
			if (day.length==1) day="0"+day;

			todayString=today.getYear().toString()+month+day;

			if ((todayString>=specialProductStart)&&(todayString<=specialProductEnd)){
				return true;
			}
		}
	}
	return false;
}

function isSpecialLeaseType(){
	var lt = document.getElementById("leaseProduct");
	
	if (lt != null) {
		if (lt.type == 'select-one') {
			var ltv = lt.options[lt.selectedIndex].text;
		} else {
			var ltv = lt.value;
		}
		
		try{
			if (
					(ltv == specialProductName) || 
					(ltv.indexOf("0% Financ")!=-1) || 
					(ltv.indexOf("Network")!=-1) || 
					(ltv.indexOf("Voice")!=-1)
			) {
				return true;
			}
		} catch(E) {}
	}
	return false;
}

function isSpecialLeaseType_0perc(){
	var lt = document.getElementById("leaseProduct");
	if (lt != null) {
		var ltv = lt.options[lt.selectedIndex].text;
		try{
			if (ltv.indexOf("0% Financ")!=-1){
				return true;
			}
		} catch(E) {}
	}
	return false;
}

function isPBXPromotion(){
	var lt = document.getElementById("leaseProduct");
	if (lt != null) {
		var ltv = lt.options[lt.selectedIndex].text;
		try{
//			if ((ltv==special_PBX_Promotion_1)||(ltv==special_PBX_Promotion_2)){
			if (lt.selectedIndex==4 || lt.selectedIndex==5)
			{
				return true;
			}
		} catch(E) {}
	}
	return false;
}

function isPricePerPort(){
	var lt = document.getElementById("leaseProduct");
	if (lt != null) 
	{
		var ltv = lt.options[lt.selectedIndex].text;
		try{
			if ( (ltv.indexOf("ports")!=-1) || (ltv.indexOf("Ports")!=-1)){
				return true;
			}
		} catch(E) {}
/*		  
		try{
			if (lt.selectedIndex==6){
				return true;
			}
		} catch(E) {}
*/		
	}
	return false;
}

function isPricePerUser(){
	var lt = document.getElementById("leaseProduct");
	if (lt != null) 
	{
		var ltv = lt.options[lt.selectedIndex].text;
		try{
			if ( (ltv.indexOf("users")!=-1) || (ltv.indexOf("Users")!=-1)){
				return true;
			}
		} catch(E) {}
/*		  
		try{
			if (lt.selectedIndex==6){
				return true;
			}
		} catch(E) {}
*/		
	}
	return false;
}

function special_AddItem(doNotCalculate){
	//calculatorController.AddItem(doNotCalculate);
	// bypass calculatorcontroller, and use UK specific
	cctl_AddItemUK(doNotCalculate);
	var ltv = document.getElementById("leaseProduct").options[document.getElementById("leaseProduct").selectedIndex].text;

	if (isSpecialLeaseType()){
		special_ValidateCriteria();
	}

	if(ltv.indexOf("FIPP")!=-1) {
		FIPP_validateCriteria();
	}
	
	if(ltv.indexOf("PartnerPlus")!=-1) {
		PP_validateCriteria();
	}
	
	displaySpecialAvailable();
}

function special_RemoveItem(doNotCalculate){
	calculatorController.onRemoveItem(doNotCalculate);

	var ltv = document.getElementById("leaseProduct").options[document.getElementById("leaseProduct").selectedIndex].text;
	
	if (isSpecialLeaseType()){
		special_ValidateCriteria();
	}
	
	if(ltv.indexOf("FIPP")!=-1) {
		FIPP_validateCriteria();
	}
	
	if(ltv.indexOf("PartnerPlus")!=-1) {
		PP_validateCriteria();
	}
	
	displaySpecialAvailable();
}

// FIPP
function FIPP_validateCriteria() {
	var comply;
	var blankPaymentColumns = false;
	var totalAmount = sessionController.getValue("unformatted_totalAmounts").val;

	comply = CheckNormalConditions();

	if (comply) {
		if (percentageNotReached()) {	
			comply = false;
			special_NonComplyMessage = special_condition1;
			special_BlankColumns();
		} else if(totalAmount > g_maxTransaction) {
			comply = false;
			special_NonComplyMessage = g_maxTransactionMsg;
		}
		special_ComplyActions(comply);
		displaySpecialAvailable();
	}
}

// PartnerPlus
function PP_validateCriteria() {
	var comply;
	var blankPaymentColumns = false;
	var totalAmount = sessionController.getValue("unformatted_totalAmounts").val;

	comply = CheckNormalConditions();

	if (comply) {
		if (PP_percentageNotReached()) {
			comply = false;
			special_NonComplyMessage = special_condition5;
			special_BlankColumns();
		} else if(totalAmount > g_maxTransaction) {
			comply = false;
			special_NonComplyMessage = g_maxTransactionMsg;
		}
		special_ComplyActions(comply);
		displaySpecialAvailable();
	}
}

// Special Products
function special_ValidateCriteria(){
	var comply;
	var blankPaymentColumns = false;
	var ltv = document.getElementById("leaseProduct").options[document.getElementById("leaseProduct").selectedIndex].text;

	comply = CheckNormalConditions();

	if (comply) {
		if (exceedMaxDealSize()){
			comply = false;
		//	special_NonComplyMessage = special_condition2;
			special_NonComplyMessage = g_maxTransactionMsg
		} else {
			if (percentageNotReached()) {	
				comply = false;
				special_NonComplyMessage = special_condition1;
				special_BlankColumns();
			} else {
				if (!durationAllowed()) {
					comply = false;
				} else {
					if (exceedSettlementAmount()) {
						comply = false;
						special_NonComplyMessage = special_condition4;
					} else {
						comply = true;
					}
				}
			}
		} 
		special_ComplyActions(comply);
		displaySpecialAvailable();
	}
}

function CheckNormalConditions() {
	var ts = document.getElementById("totalsStatus");
	if (ts == null) { 
		alert("Required element 'totalsStatus' missing!"); 
		return; 
	}
	if (ts.innerHTML == g_minTransactionMsg) {
		return false;
	} else {
		return true;
	}
}

function special_BlankColumns() {
	var equipmentTable = itemTable("equipmentList");
	var totalAmountColumn = equipmentTable.getColumn(2);
	var numberOfPortsColumn = equipmentTable.getColumn(3);
	var firstPaymentColumn = equipmentTable.getColumn(4);
	var pauseColumn = equipmentTable.getColumn(5);
	var furtherPaymentsColumn = equipmentTable.getColumn(6);
	var paymentAmountColumn = equipmentTable.getColumn(7);
	var endPaymentColumn = equipmentTable.getColumn(8);

	// blank the payment related columns
	equipmentTable.blankColumn(firstPaymentColumn);
	equipmentTable.blankColumn(pauseColumn);
	equipmentTable.blankColumn(furtherPaymentsColumn);
	equipmentTable.blankColumn(paymentAmountColumn);
	equipmentTable.blankColumn(endPaymentColumn);
	equipmentTable.blankColumn(numberOfPortsColumn);

	// blank the payment totals
	var tp = document.getElementById("totalPayments");
	if (tp == null) { alert("Required element 'totalPayments' missing!"); return; }
	var tf = document.getElementById("totalFirstPayments");
	if (tf == null) { alert("Required element 'totalFirstPayments' missing!"); return; }
	tp.innerHTML = "";
	sessionController.setValue("unformatted_totalPayments", 0, false)
	tf.innerHTML = "";
	sessionController.setValue("unformatted_totalFirstPayments", 0, false)
}

function percentageNotReached(){
	var special_nonVendorAmt = document.getElementById("unformatted_totalNonVendorAmount");
	var special_VendorAmt = document.getElementById("unformatted_totalVendorAmount");
	var perc;

	if (special_nonVendorAmt!=null){
		special_nonVendorAmt = parseFloat(special_nonVendorAmt.value);
	}else{
		special_nonVendorAmt=0
	}

	if (special_VendorAmt!=null){
		special_VendorAmt = parseFloat(special_VendorAmt.value);
	}else{
		special_VendorAmt=0
	}

	if (special_VendorAmt>0){
		perc = 100*special_VendorAmt/(special_VendorAmt+special_nonVendorAmt);
		if (perc<special_cscPercentage) return true;
	}else{
		return true;
	}

	return false;

}

function PP_percentageNotReached(){
	
	var special_nonVendorAmt = document.getElementById("unformatted_totalNonVendorAmount");
	var special_VendorAmt = document.getElementById("unformatted_totalVendorAmount");
	var perc;

	if (special_nonVendorAmt!=null){
		special_nonVendorAmt = parseFloat(special_nonVendorAmt.value);
	}else{
		special_nonVendorAmt=0
	}

	if (special_VendorAmt!=null){
		special_VendorAmt = parseFloat(special_VendorAmt.value);
	}else{
		special_VendorAmt=0
	}

	if (special_VendorAmt>0){
		perc = 100*special_VendorAmt/(special_VendorAmt+special_nonVendorAmt);
		if (perc<special_cscPP_Percentage) {
			return true;
		}
	}else{
		return true;
	}

	return false;

}

function exceedMaxDealSize(){
	var totalDeal = document.getElementById("unformatted_totalAmounts");
	var total = "0";
	
	// get numeber of ports
	var npval = parseInt(sessionController.getValue("numberOfPorts").val);
	if ( isNaN(npval) || npval <= 0 ) {
		npval=1;
	}
	
	if (totalDeal!=null){
		total = totalDeal.value;
	}else{
		return false;
	}
	
//	if (total>(special_maxDealSize/npval)){
	if (total>(special_maxDealSize)){
		return true;
	}

	return false;
}

function exceedSettlementAmount(){
	var totalDeal = document.getElementById("unformatted_totalAmounts");
	var total20 = "0";
	var totalSettlement = document.getElementById("unformatted_totalSettlementAmount");
	var totalS = "0";

	if (totalDeal!=null){
		total20 = totalDeal.value/100*20;
	}else{
		return false;
	}	
	
	if (totalSettlement!=null){
		totalS = totalSettlement.value;
		
	}else{
		return false;
	}	

	if (totalS>total20){
		return true;
	}

	return false;
}

function special_ComplyActions(comply){
	var showMessage = false;
	var bottomMessageBar = document.getElementById("totalsStatus");

	if (bottomMessageBar!=null) showMessage=true;

	if (comply){
		if (showMessage){
			bottomMessageBar.innerText="";
		}
		disableButtonContinue(false);
	}else{
		if (showMessage){
			bottomMessageBar.innerText=special_NonComplyMessage;
		}
		disableButtonContinue(true);
	}
}

function special_DisablePeriods(){
	var pe = document.getElementById("period");
	if ((pe!=null)&&(isSpecialLeaseType())){
		for (var i=0;i<pe.options.length;i++){
			if (!isInDurationSet(pe.options[i].value)){
				pe.options[i].disabled=true;
			}
		}
		emulate(pe);
	}
}

function special_enablePeriods(){
	var pe = document.getElementById("period");
	if (pe!=null){
		for (var i=0;i<pe.options.length;i++){
			pe.options[i].disabled=false;
		}
		emulate(pe);
	}
}

function isInDurationSet(periodValue){
	for (var i=0;i<special_durationSet.length;i++){
		if (special_durationSet[i] == periodValue) {
			return true;
		}
	}
	return false;
}

function durationAllowed(){
	var pe = document.getElementById("period");
	if (pe!=null){
		if (isInDurationSet(pe.value)){
			return true;
		}
	}

	return false;
}

function special_PeriodChange(){
	var pv = document.getElementById("periodValue");
	if (pv == null) { alert("Required element 'periodValue' missing!"); return; }
	var pe = document.getElementById("period");
	if (pe == null) { alert("Required element 'period' missing!"); return; }

	pv.value = pe.options[pe.selectedIndex].value;
	cctl_specialCalculate();

	if (isSpecialLeaseType()){
		special_ValidateCriteria();
	}
}

function special_LeaseTypeChange(){
	calculatorController.onLeaseProductSelectionChanged();

	var ltv = sessionController.getValue("leaseProduct").val;
	if (ltv == null) {
		var lt = document.getElementById("leaseProduct");
		var ltv = lt.options[lt.selectedIndex].text;
	}

	if (isSpecialLeaseType()){
		special_DisablePeriods();
		enable1YearPeriod();
		setAdditionalDisclaimer(true);
	}
	else if ((ltv.indexOf("Voice")!=-1) 
			|| (ltv.indexOf("Network")!=-1) 
			|| (ltv.indexOf("FIPP")!=-1)
			|| (ltv.indexOf("PartnerPlus")!=-1)
			|| (ltv.indexOf("A2C")!=-1)
		) {
		special_enablePeriods();
		disable1YearPeriod();
		setAdditionalDisclaimer(true);
	}
	else if (ltv.indexOf("PBX")!=-1) {
		special_enablePeriods();
		disableYearPeriod(5);
		setAdditionalDisclaimer(true);
	}
	else{
		special_enablePeriods();
		/**
		 * disables 2 years if leaseProduct is "Locazione Finanziaria"
		 */
		if(
			document.getElementById("leaseProduct").selectedIndex == 1 && 
			document.location.href.indexOf("calcCSCit.htm") != -1
		) {
			periods_array = new Array(1,2,3,4);
			disablexYearPeriod(periods_array);
		} else {
			disable1YearPeriod();
		}
		
		setAdditionalDisclaimer(false);
	}
	displaySpecialAvailable();
}

function displaySpecialAvailable(){
	var descBox=document.getElementById("promoDescription");
	var conditionBox = document.getElementById("promoConditions");

	if (descBox!=null){
		try{
			if (isSpecialProductPeriod()){
				var plaatje = new Image();
				plaatje.src= bannerName;

				descBox.innerHTML="<div id='promoPlaatje'><img src='" + bannerName + "'></div><div id='promoTekst'></div>";
				document.getElementById("promoPlaatje").style.position="relative";
				document.getElementById("promoPlaatje").style.zIndex="0";
				document.getElementById("promoPlaatje").style.left=0;
				document.getElementById("promoPlaatje").style.top=0;

				document.getElementById("promoTekst").style.position="relative";
				document.getElementById("promoTekst").style.zIndex="3";
				document.getElementById("promoTekst").style.left=leftOutline;
				document.getElementById("promoTekst").style.top=-1*plaatje.height;
				document.getElementById("promoTekst").innerText = special_promoText;

			}
		} catch(e) {}
	}
	if (conditionBox!=null){
		conditionBox.innerHTML="";
	}

}

function displaySpecialConditions(){
	var descBox=document.getElementById("promoDescription");
	var conditionBox = document.getElementById("promoConditions");

	if (descBox!=null){
		descBox.innerHTML="<center>"+special_conditionsHeader+"</center>";
	}

	if (conditionBox!=null){
		conditionBox.innerText=special_conditionsDesc;
	}
}

//window.onload = function() {
	//setHandlerForPeriodSelect();
	//setHandlerForLeaseTypeSelect();
	//setHandlerForAddItemButton();
	//setHandlerForRemoveItemButton();
	//setHandlerForEquipmentTypeSelect();
	//setHandlerForContinueButton();
//}

function special_setHandlers()
{
	setHandlerForPeriodSelect();
	setHandlerForLeaseTypeSelect();
	setHandlerForAddItemButton();
	// here no handler, because it overwrites the handler set bij session mechanism when
	// returning back to calc page; handler is set in page instead.
//	setHandlerForRemoveItemButton();
	setHandlerForEquipmentTypeSelect();
	setHandlerForContinueButton();
}

function setHandlerForPeriodSelect(){
	var s = document.getElementById("period");

	if (s!=null){
		s.onfocus = function(){ window.select_current = this.selectedIndex;}
		s.onchange = function(){ restorePeriod(this); }
		emulate(s);
	}
}

function setHandlerForLeaseTypeSelect(){
	var lt = document.getElementById("leaseProduct");

	if (lt != null) {
		lt.onfocus = function(){ window.current_leasetype = this.selectedIndex; }
		lt.onchange = function(){ restoreLeasetype(this); localCheckDisclaimer(); } //special_LeaseTypeChange;

		emulate(lt);
	}
}

function setHandlerForAddItemButton(){
	var lt = document.getElementById("Button3");
	if (lt != null) {
		lt.onclick = special_AddItem;
	}
}

function setHandlerForRemoveItemButton(){
	var lt = document.getElementById("removeButton");
	if (lt != null) {
		lt.onclick = special_RemoveItem;
	}
}

function setHandlerForEquipmentTypeSelect(){
	var lt = document.getElementById("equipmentType");
	if (lt != null) {
		lt.onchange = special_EquipTypeChange;
	}
}

function setHandlerForContinueButton(){
	var lt = document.getElementById("continue");
	if (lt != null) {
		lt.onclick = special_ContinueToPrint;
	}
}

function special_ContinueToPrint(){
	sessionController.save();

	var URL = unescape(document.location.href);
	var printPageURL= URL.replace(".htm", "print.htm");

	printPageURL=printPageURL+"?specialProduct="+isSpecialLeaseType();
	printPageURL = printPageURL.replace("/calcCSC", "/calc");
	window.navigate(printPageURL);
}

function special_EquipTypeChange(){
	calculatorController.onEquipmentTypeSelectionChanged();

	if (promotion.isPromotion(this.options[this.selectedIndex].value)){
		enableSpecialProduct(false);
	}else{
		enableSpecialProduct(true);
	}

	displaySpecialAvailable();
}

function enableSpecialProduct(enable){
	var lt = document.getElementById("leaseProduct");
	if (lt != null) {
		for (var i=0;i<lt.options.length;i++){
			if (lt.options[i].text==specialProductName){
				lt.options[i].disabled=!enable;
				if ((enable==false)&&(lt.selectedIndex==i)){
					lt.selectedIndex=0;
				}
			}
		}
		emulate(lt);
	}
}

function special_displayStuff(){
	if (isSpecialLeaseType()){
		//displaySpecialConditions();
	}else{
		displaySpecialAvailable();
	}
}

function restorePeriod(e) {
	if (e.options[e.selectedIndex].disabled) {
		if (!e.options[window.select_current].disabled){
			e.selectedIndex = window.select_current;
		}else{
			setFirstNonDisabled();
		}
	}else{
		special_PeriodChange();
	}
}

function restoreLeasetype(e) {
	if (e.options[e.selectedIndex].disabled) {
		e.selectedIndex = window.current_leasetype;
	}else{
		special_LeaseTypeChange();
	}
}

function emulate(e) {
	for (var i=0; i<e.options.length; i++) {
		if (e.options[i].disabled) {
			e.options[i].style.color = "graytext";
		}
		else {
			e.options[i].style.color = "menutext";
		}
	}
}

function disable1YearPeriod()
{
	if (isSpecialLeaseType()== false)
	{
		var pe = document.getElementById("period");
		for (var i=0; i<pe.options.length; i++)
		{
			if (pe.options[i].value == "1")
			{
				pe.options[i].disabled = true;

				if (pe.selectedIndex==i){
					setFirstNonDisabled(pe);
				}
			}
		}
	}
	emulate(pe);
}

function disable2YearPeriod()
{
	if (isSpecialLeaseType()== false)
	{
		var pe = document.getElementById("period");
		for (var i=0; i<pe.options.length; i++)
		{
			if (pe.options[i].value == "1" || pe.options[i].value == "2")
			{
				pe.options[i].disabled = true;

				if (pe.selectedIndex==i){
					setFirstNonDisabled(pe);
				}
			}
		}
	}
	emulate(pe);
}

function disablexYearPeriod(periods_array)
{
	if (isSpecialLeaseType()== false)
	{
		var pe = document.getElementById("period");
		for (var i=0; i<periods_array.length; i++)
		{
			pe.options[i].disabled = true;
			if (pe.selectedIndex==i){
				setFirstNonDisabled(pe);
			}
		}
	}
	emulate(pe);
}

function disableYearPeriod(lyear)
{
	if (isSpecialLeaseType()== false)
	{
		var pe = document.getElementById("period");
		for (var i=0; i<pe.options.length; i++)
		{
			if (pe.options[i].value == lyear)
			{
				pe.options[i].disabled = true;

				if (pe.selectedIndex==i){
					setFirstNonDisabled(pe);
				}
			}
		}
	}
	emulate(pe);

}

function setFirstNonDisabled(e){
	for (var i=0; i<e.options.length;i++){
		if (e.options[i].disabled==false){
			e.selectedIndex=i;
			break;
		}
	}
}

function enable1YearPeriod()
{
//	if (isSpecialLeaseType()== true)
//	{
		var pe = document.getElementById("period");
		for (var i=0; i<pe.options.length; i++)
		{
			
			if (pe.options[i].value == "1")
			{
				if (isInDurationSet("1"))
				{
					pe.options[i].disabled = false;
				}
			}
		}
//	}
	emulate(pe);
}

function setAdditionalDisclaimer(applicable){
	var disAdd = document.getElementById("disclaimerAddition");
	var pbxAdd = document.getElementById("PBX6MonthRemark");

	composeAdditionalDisclaimer();

	if (disAdd!=null){
		if (applicable){
			disAdd.innerHTML=disclaimerAdditionalHTML;
		} else {
			disAdd.innerHTML="";
		}
	}

	if (pbxAdd!=null){
		if (applicable){
			pbxAdd.innerHTML=PBX6MonthRemarkHTML;
		} else {
			pbxAdd.innerHTML="";
		}
	}

}

function fillDisclaimerAdditionFromSearchString(){

	var ltv = sessionController.getValue("leaseProduct").val;
	if (ltv == null) {
		var lt = document.getElementById("leaseProduct");
		var ltv = lt.options[lt.selectedIndex].text;
	}

	if (findInSearchString("specialProduct") 
			|| (ltv.indexOf("Voice")!=-1) 
			|| (ltv.indexOf("Network")!=-1) 
			|| (ltv.indexOf("PBX")!=-1) 
			|| (ltv.indexOf("FIPP")!=-1)
			|| (ltv.indexOf("PartnerPlus")!=-1)
			|| (ltv.indexOf("A2C")!=-1)
		) {
		setAdditionalDisclaimer(true);
	}
}

function findInSearchString(name){
	var searchString = name+"=";
	if (location.search!=null){
		var start = location.search.indexOf(searchString);
		if (start!=-1){

			var end = location.search.indexOf("&",start);
			if (end==-1) end=location.search.length;

			if (location.search.substr(start+searchString.length,end)=="true"){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
}

function localCheckDisclaimer() {
	var v = document.getElementById("leaseProduct");
	if (v == null) { alert("element leaseProduct missing"); return; }

	v = v.options[v.selectedIndex].text; // the value of the selected lease product, e.g. 'financial' or 'operational'
	if (v.indexOf("Finan")!=-1 || v.indexOf("finan")!=-1) {
		//	document.getElementById("extraDisclaimer").style["visibility"] = "visible";
	} else {
		//    document.getElementById("extraDisclaimer").style["visibility"] = "hidden";
	}
}