
function MandaRichiesta()
{
	oVerifica = VerificaDatiCompleti();
	if (oVerifica == '') {
    	oCorpo = BuildCorpo();  
		oFunction = 'Function=MailRichiesta&' + oCorpo;
		oSenderMail = document.getElementById('EMAIL').value;
		oFunction = oFunction + "&Mittente=" + oSenderMail;
		oFunction = oFunction + "&Ricevente=<eva.melodia@gmail.com>,<adsoft@adsoft.it>,<assistenza@adsoft.it>";
		oFunction = oFunction + ",<" + oSenderMail + ">";
		oPath = "../Logic/Telin_Logic.php?" + oFunction;
		window.document.location.href = oPath;
		
		//(oPath,'Invia Richiesta','width=400,height=400, status=yes, directories=yes, toolbar=yes, location=no, menubar=no,scrollbars=no, resizable=yes');
    } else {
        alert('Verifica Fallita: ' + oVerifica);
    }
}

function BuildCorpo()
{
        oResult = "";
		oRagSoc = "Richiedente=" + document.getElementById('RAGSOC').value;
        oResult = oResult + "&" + oRagSoc;
        oTel = "Telefono=" + document.getElementById('TELEFONO').value;
        oResult = oResult + "&" + oTel;
        oMail = "Mail=" + document.getElementById('EMAIL').value;
        oResult = oResult + "&" + oMail;
        oServer = "NUMERO_SERVER=" + document.getElementById('QuantiServer').value;
        oResult = oResult + "&" + oServer;
        oClient = "NUMERO_CLIENT=" + document.getElementById('QuantiClient').value;
        oResult = oResult + "&" + oClient;
        oRinnovi = document.getElementsByName('Rinnovo');
        for (i = 0; i < oRinnovi.length; i++)
        {
				oRinnovo = "Rinnovo" + i + "=" + oRinnovi.item(i).value; 
                oResult = oResult + "&" + oRinnovo;
        }
        oClienteSette = "CLIENTE_DELTA_7=" + document.getElementById('ClienteDel7').checked;
        oResult = oResult + "&" + oClienteSette;
        oClienteSei = "CLIENTE_DELTA_6=" + document.getElementById('ClienteDel6').checked;;
        oResult = oResult + "&" + oClienteSei;
        oPagamento = "TIPO_PAGAMENTO=" + getTipoPagamentoSTR();
        oResult = oResult + "&" + oPagamento;
        oTipoConsegna = "TIPO_CONSEGNA=" + getTipoConsegnaSTR();
        oResult = oResult + "&" + oTipoConsegna;
        return oResult;
        
}

function VerificaDatiCompleti()
{
		oResult = "";
        oServer = document.getElementById('QuantiServer');
        oClient = document.getElementById('QuantiClient');
        oRinnovo1 = document.getElementById('Rinnovo1');
        if ((oServer.value == 0) && (oClient.value == 0) && ((oRinnovo1.value == "inserire il codice da rinnovare") || (oRinnovo1.value == "")))
        {
                oResult = "Specificare almeno un tipo di richiesta!"
        }
        oRagSoc = document.getElementById('RAGSOC');
        if (oRagSoc.value == "") 
        {
                oResult = "Il campo RAGIONE SOCIALE è OBBLIGATORIO!";
        }       
		oTel = document.getElementById('TELEFONO');
		if (oTel.value == "") 
        {
                oResult = "Il campo TELEFONO è OBBLIGATORIO!";
        }    
        oMail = document.getElementById('EMAIL');
		if (oMail.value == "") 
        {
                oResult = "Il campo E-MAIL è OBBLIGATORIO!";
        }		
        oPagamento = getTipoPagamento();
        if (oPagamento == -1) {
                oResult = "Specificare un tipo di pagamento!";
        }
        oTipoConsegna = getTipoConsegna();
        if (oTipoConsegna == -1) {
                oResult = "Specificare un tipo di consegna!";
        }
        return oResult;
}
function getTipoPagamentoSTR()
{
        PAG_BON = 'BONIFICO';
        PAG_CON = 'CONTRASSEGNO';
        PAG_NONE = 'NON_SPECIFICATO';
        if (document.getElementById('PagamentoBonifico').checked){
                
                return PAG_BON;
        } else { 
                if (document.getElementById('PagamentoContrassegno').checked){
                        
                        return PAG_CON;
                } else { 
                
                        return PAG_NONE;
                }
        }
}
function getTipoPagamento()
{
        PAG_BON = 0;
        PAG_CON = 1;
        PAG_NONE = -1;
        if (document.getElementById('PagamentoBonifico').checked){
                
                return PAG_BON;
        } else { 
                if (document.getElementById('PagamentoContrassegno').checked){
                        
                        return PAG_CON;
                } else { 
                
                        return PAG_NONE;
                }
        }
}

function getTipoConsegnaSTR()
{
        CON_MAIL = 'MAIL';
        CON_CORR = 'CORRIERE';
        CON_POSTA = 'POSTA';
        CON_NONE = 'NON_SPECIFICATO';
        if (document.getElementById('SpedizioneCorriere').checked){

                return CON_CORR;
        } else 
        { 
                if (document.getElementById('SpedizionePosta').checked)
                {
                        return CON_POSTA;
                } else 
                {
                        if (document.getElementById('SpedizioneMail').checked)
                        { 
                                return CON_MAIL;
                        } else 
                        {
                                return CON_NONE;
                        }
                }
        }
}

function getTipoConsegna()
{
        CON_MAIL = 0;
        CON_CORR = 1;
        CON_POSTA = 2;
        CON_NONE = -1;
        if (document.getElementById('SpedizioneCorriere').checked){

                return CON_CORR;
        } else 
        { 
                if (document.getElementById('SpedizionePosta').checked)
                {
                        return CON_POSTA;
                } else 
                {
                        if (document.getElementById('SpedizioneMail').checked)
                        { 
                                return CON_MAIL;
                        } else 
                        {
                                return CON_NONE;
                        }
                }
        }
}



function Scrivi(testo){
        document.getElementsByTagName("BODY").item(0).appendChild(document.createTextNode(testo));
        document.getElementsByTagName("BODY").item(0).appendChild(document.createElement("BR"));
}

function AggiungiCodice(vTableName)
{
                oTable = document.getElementById(vTableName);
                oHeads = oTable.getElementsByTagName('THead');
                oHead = oHeads.item(0);
                oTrArray = oHead.getElementsByTagName('Tr');
                i = oTrArray.length;
                oTr = oTrArray.item(oTrArray.length - 1 );
                if (!VerificaUsatoUltimo(oTr))
                {
                        alert('Inserire il codice nello spazio disponibile');
                
                } else {
                        oCloneTr = oTr.cloneNode(true);
                        oHead.appendChild(oCloneTr);
                        i = i++;
                        oCloneTr.getElementsByTagName('Input').item(0).id = 'Rinnovo' + Str(i);
                        oCloneTr.getElementsByTagName('Input').item(0).name = 'Rinnovo'; 
                }
                                                
}
function VerificaUsatoUltimo(vTr)
{
                oCelle = vTr.getElementsByTagName('td');
                oTd = oCelle.item(0);
                oInputs = oTd.getElementsByTagName('Input');
                oInp = oInputs.item(0);
                if (oInp.value != 'inserire il codice da rinnovare') 
                {
                                return true;
                }else{
                                return false;
                }       

}
function EliminaCodice(vButton)
{
                oTr = vButton.parent.parent;
                alert(oTr.innerHtml);

}


