﻿<!--
function AddCheckedToCoupon(){
	try {
		//Verifico le checkbox
		var elencoIDQuota = "";
		var objFrmQuote, aChkQuote, i, j;

		var ElencoIFrame;
		var hidValue = document.getElementById("hidElencoFrame");
		if (hidValue != null) ElencoIFrame = hidValue.value.split("|");

		// Verifico le combo
		for (i = 0; i < ElencoIFrame.length; i++) {
			if (document.getElementById(ElencoIFrame[i]).contentWindow)
				objFrmQuote = document.getElementById(ElencoIFrame[i]).contentWindow;
			else
				objFrmQuote = window.frames[ElencoIFrame[i]];

			aChkQuote = objFrmQuote.document.getElementsByName("cboQuote");
			if (!aChkQuote) continue;

			if (aChkQuote.length > 0) {
				for (j = 0; j < aChkQuote.length; j++) {
					if (!aChkQuote[j].childNodes) continue;
					
					if (aChkQuote[j].childNodes[0].selectedIndex > 0) {
						if (elencoIDQuota.length > 0) elencoIDQuota += "§";
						elencoIDQuota += aChkQuote[j].childNodes[0].options[aChkQuote[j].childNodes[0].selectedIndex].value;									
						
						aChkQuote[j].childNodes[0].selectedIndex = 0;
					}
				}
			} else {
				if (!aChkQuote.childNodes) continue;
				
				if (aChkQuote.childNodes[0].selectedIndex > 0) {
					if (elencoIDQuota.length > 0) elencoIDQuota += "§";
					elencoIDQuota += aChkQuote.childNodes[0].options[aChkQuote.childNodes[0].selectedIndex].value;
					aChkQuote.childNodes[0].selectedIndex = 0;
				}
			}
		}

		if (elencoIDQuota == "") return false;
		
		// Imposto l'elenco degli IDQuota alla hidden nel coupon
		var frm;
		if (document.getElementById("frmCoupon").contentWindow)
			frm = document.getElementById("frmCoupon").contentWindow;
		else
			frm = window.frames["frmCoupon"];

		frm.document.getElementById("hidIDQuota").value = elencoIDQuota;
		frm.document.getElementById("btnHide").click();

		return false;
	} catch(e) {
		return false;
	}
}

function AddIDQuotaCombo(nomeIFrame, comboEvento, comboSottoEvento, comboSottoEvento2){
	var elencoIDQuota = "";
	var frm;				
	if (document.getElementById(nomeIFrame).contentWindow)
		frm = document.getElementById(nomeIFrame).contentWindow;
	else
		frm = window.frames[nomeIFrame];
	if (frm == null) return false;

	var cboEvento = frm.document.getElementById(comboEvento);
	if (cboEvento == null) return false;
	elencoIDQuota = cboEvento.value.split("|")[0];
	if (elencoIDQuota == ""){
		frm.document.getElementById("imgCautionEvento").style.visibility='visible';
		return false;
	}else{
		frm.document.getElementById("imgCautionEvento").style.visibility='hidden';
	}
 
	if (comboSottoEvento != ""){
		var cboSottoEvento = frm.document.getElementById(comboSottoEvento);
		if (cboSottoEvento != null){
			if (cboSottoEvento.value == ""){
				frm.document.getElementById("imgCautionSottoEvento").style.visibility='visible';					
				return false;
			}else{
				frm.document.getElementById("imgCautionSottoEvento").style.visibility='hidden';
			}
			if (elencoIDQuota.length > 0) elencoIDQuota += "§";
			elencoIDQuota += cboSottoEvento.value.split("|")[0];
		}
	}

	if (comboSottoEvento2 != ""){
		var cboSottoEvento2 = frm.document.getElementById(comboSottoEvento2);
		if (cboSottoEvento2 != null){
			if (cboSottoEvento2.value != ""){
				if (elencoIDQuota.length > 0) elencoIDQuota += "§";
				elencoIDQuota += cboSottoEvento2.value.split("|")[0];
			}
		}
	}

	if (elencoIDQuota == "") return false;
	
	//Aggiungo l'importo
	var importo = frm.document.getElementById("txtImporto").value;

	// Imposto l'elenco degli IDQuota alla hidden nel coupon
	if (document.getElementById("frmCoupon").contentWindow)
		frm = document.getElementById("frmCoupon").contentWindow;
	else
		frm = window.frames["frmCoupon"];

	frm.document.getElementById("hidIDQuotaCombo").value = importo + "§" + elencoIDQuota;
	frm.document.getElementById("btnHideCombo").click();
}

function AddIDQuotaToCoupon(IDQuota){
	if (IDQuota == "") return;
	if (isNaN(IDQuota)) return;

	var frm;
	if (document.getElementById("frmCoupon").contentWindow)
		frm = document.getElementById("frmCoupon").contentWindow;
	else
		frm = window.frames["frmCoupon"];

	frm.document.getElementById("hidIDQuota").value = IDQuota;
	frm.document.getElementById("btnHide").click();
}
function AddIDQuotaBFToCoupon(IDQuota){
	if (IDQuota == "") return;
	if (isNaN(IDQuota)) return;

	var frm;
	if (document.getElementById("frmCoupon").contentWindow)
		frm = document.getElementById("frmCoupon").contentWindow;
	else
		frm = window.frames["frmCoupon"];

	frm.document.getElementById("hidIDQuota").value = IDQuota;
	frm.document.getElementById("btnHideBF").click();
}
// Se la variabile showMsg = 0 non visualizzo il panel, se diventa = 1 (per una chiamata dall'iFrame) allora lo visualizzo
var showMsg = 1;

function showPanelMsg(Msg){
	var panelMsg = document.getElementById("PanelMsg1_panel_response");
	if (panelMsg == null) return

	if (Msg == 0) showMsg = 0

	if (showMsg == 1 ) 
		panelMsg.style.display="inline";
	else
		panelMsg.style.display="none";
}

function math_round(precisione)
{
	var rounder = Math.pow(10, precisione);
	return Math.round(this * rounder) / rounder;
}
Number.prototype.round = math_round;

function mcd(s1, s2)
{
	//Algoritmo di Euclide per calcolare l'MCD di 2 numeri.
	var d = 0.0;
	
	s = s1 % s2;
	if (s == 0)
		return s2;
	else
		return mcd(s2, s);
}

function formattaQuota(euOdds, tipoFormattazione)
{
	var returnValue = "";

	switch (tipoFormattazione.toLowerCase()) {
		case "uk":
			var valy = 0.0, valz = 0.0;
			var dive = 0.0;
			valy = ((euOdds - 1) * 100).round(2);
			valz = mcd(valy, 100);
			valy = valy / valz;
			valz = 100 / valz;

			returnValue = valy + "/" + valz;
			break;
		
		case "eu":
			returnValue = euOdds.toFixed(2);
			break;
	}
	
	return returnValue;
}

function CalcolaQuota(nomeIFrame, sDecimalSeparator, sTipoFormattazione){
	var frm;
	if (document.getElementById(nomeIFrame).contentWindow)
		frm = document.getElementById(nomeIFrame).contentWindow;
	else
		frm = window.frames[nomeIFrame];
	if (frm == null) return false;

	var quota1, quota2 , quota3;
	var cboEvento = frm.document.getElementById("cboEventoCombo");
	if (cboEvento == null) return false;
	elencoIDQuota = cboEvento.options[cboEvento.selectedIndex].value;
	if (elencoIDQuota == ""){
		quota1 = "0";
	}else{
		quota1 = elencoIDQuota.split("|")[1]; //elencoIDQuota.split(":")[1];
	}

	quota2 = "1";
	var cboSottoEvento = frm.document.getElementById("cboSottoEventoCombo");
	if (cboSottoEvento != null){
		if (cboSottoEvento.value != ""){
			quota2 = cboSottoEvento.options[cboSottoEvento.selectedIndex].value.split("|")[1]; //.split(":")[1];
		}
	}

	quota3 = "1";
	var cboSottoEvento2 = frm.document.getElementById("cboSottoEventoCombo2");
	if (cboSottoEvento2 != null){
		if (cboSottoEvento2.value != ""){
			quota3 = cboSottoEvento2.options[cboSottoEvento2.selectedIndex].value.split("|")[1]; //.split(":")[1];
		}
	}

	var quotaTotaleDec = parseFloat(parseFloat(quota1.replace(",",".")) * parseFloat(quota2.replace(",",".")) * parseFloat(quota3.replace(",","."))).toString();
	var importoDec = parseFloat(frm.document.getElementById("txtImporto").value.replace(",","."));
	var vincitaPotDec = parseFloat(quotaTotaleDec * importoDec).round(2).toString();

	if (quotaTotaleDec == 0) {
		frm.document.getElementById("lblQuotaTotale").innerHTML = "&nbsp;"
		frm.document.getElementById("lblVincitaPot").innerHTML = "&nbsp;"
	}else{
		frm.document.getElementById("lblQuotaTotale").innerHTML = formattaQuota(parseFloat(quotaTotaleDec).round(2), sTipoFormattazione).replace(".", sDecimalSeparator);
		if (isNaN(importoDec)){
			frm.document.getElementById("lblVincitaPot").innerHTML = "&nbsp;"
		}else{
			frm.document.getElementById("lblVincitaPot").innerHTML = vincitaPotDec.replace(".", sDecimalSeparator);
		}
	}
}

function reloadEventi()
{
	var objFrmQuote, i, j;
	var ElencoIFrame;
	var hidValue = document.getElementById("ctl00_PageContent_hidElencoFrame");
	if ((hidValue == null) || (hidValue.value == "")) return
	ElencoIFrame = hidValue.value.split("|");

	// Verifico le combo
	for (i = 0; i < ElencoIFrame.length; i++) {
		if (document.getElementById(ElencoIFrame[i]).contentWindow)
			objFrmQuote = document.getElementById(ElencoIFrame[i]).contentWindow;
		else
			objFrmQuote = window.frames[ElencoIFrame[i]];
		
		objFrmQuote.location.reload();
	}
}
//-->