

var authOk = function(o){ 

if (o.responseText !== undefined) { 
var risJson = parseJsonStr(o.responseText);
switch(risJson.act) {
	case 'error':
	var ris = document.getElementById('sysPrint');
    ris.innerHTML = "<strong>Errore:</strong> "+risJson.str;
	break;
	
	case 'goto':
	location.href=getUrl(risJson.url);
	break;
	
	case 'preventivo1':
		var nf=risJson.nameForm;
		for (var i=0; i<=2; i++) {
			document.forms[risJson.nameForm].elements[i].setAttribute('Readonly',true);
			document.forms[risJson.nameForm].elements[i].className='readonly tV14 lwhite w280'; 
		}
		document.forms[risJson.nameForm].reset.style.display='none';
		document.forms[risJson.nameForm].check1.style.display='none';
		document.forms[risJson.nameForm].check2.style.display='block';
		document.getElementById("block-richiesta").style.display='block';
		document.forms[risJson.nameForm].mac.value=risJson.mac;
	break;
	
	case 'preventivo2':
		document.getElementById("blocco-preventivo").style.display='none';
		document.getElementById("blocco-preventivo-ris").style.display='block';
	break;
	
	case 'promo1':
		var nf=risJson.nameForm;
		for (var i=0; i<=2; i++) {
			document.forms[risJson.nameForm].elements[i].setAttribute('Readonly',true);
			document.forms[risJson.nameForm].elements[i].className='readonly tV14 lwhite w280'; 
		}
		document.forms[risJson.nameForm].reset.style.display='none';
		document.forms[risJson.nameForm].check1.style.display='none';
		document.forms[risJson.nameForm].check2.style.display='block';
		document.getElementById("block-richiesta").style.display='block';
		document.forms[risJson.nameForm].mac.value=risJson.mac;
	break;
	
	case 'promo2':
		document.getElementById("blocco-promo").style.display='none';
		document.getElementById("blocco-promo-ris").style.display='block';
	break;
	}
}
else  {
	  var ris = document.getElementById('sysPrint');
	  ris.innerHTML = "<strong>Errore:</strong> "+o.responseText;
	}
};

var authKo = function(o){
	if(o.responseText !== undefined){
		var ris = document.getElementById('sysPrint');
		ris.innerHTML = "<strong>Errore:</strong> "+o.statusText;
	}
};


var out =
{
  success:authOk,
  failure:authKo
};


function check_preventivo_1(){
	resetSysResponse('sysPrint');
	
	var errorScript=''
	var dl=document.preventivo
	var authpath = "../i/aj/check-preventivo.php";
	var dCheck = 'nome='+escape(dl.nome.value)+'&posut='+escape(dl.pos.value)+'&email='+escape(dl.email.value);
	
	if (!dl.nome.value) errorScript+="Inserire il vostro nome/cognome.\n";
	if (!dl.pos.value) errorScript+="Inserire la vostra posizione aziendale.\nSe siete un privato inserite: 'Privato'\n";
	if (!dl.email.value) errorScript+="Inserire il vostro indirizzo e-mail.\n";
	else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(dl.email.value)) errorScript += 'Indirizzo e-mail non valido.\n'
	
	if (errorScript) alert("Attenzione! Ci sono errori nel modulo. Prima di continuare:\n\n"+errorScript+"\n\n"+firmaMiura);
	else sReq('POST', authpath, out, dCheck, 'check preventivo');
}


function check_preventivo_2(){
	resetSysResponse('sysPrint');
	
	var errorScript=''
	var dl=document.preventivo
	var authpath = "../i/aj/send-preventivo.php";
	var dCheck = 'nome='+escape(dl.nome.value)+'&posut='+escape(dl.pos.value)+'&email='+escape(dl.email.value)+'&text='+escape(dl.richiesta.value)+'&mac='+escape(dl.mac.value);
		
	if (!dl.richiesta.value) errorScript+="Inserire il testo della vostra richiesta.\n";
	if (!dl.nome.value) errorScript+="Inserire il vostro nome/cognome.\n";
	if (!dl.pos.value) errorScript+="Inserire la vostra posizione aziendale.\nSe siete un privato inserite: 'Privato'\n";
	if (!dl.email.value) errorScript+="Inserire il vostro indirizzo e-mail.\n";
	else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(dl.email.value)) errorScript += 'Indirizzo e-mail non valido.\n'
	
	if (errorScript) alert("Attenzione! Ci sono errori nel modulo. Prima di continuare:\n\n"+errorScript+"\n\n"+firmaMiura);
	else sReq('POST', authpath, out, dCheck, 'check preventivo 2');
}



function check_promo_inbook_1(){
	resetSysResponse('sysPrint');
	
	var errorScript=''
	var dl=document.promoinbook
	var authpath = "../i/aj/check-promo-inbook.php";
	var dCheck = 'nome='+escape(dl.nome.value)+'&posut='+escape(dl.pos.value)+'&email='+escape(dl.email.value);
	
	if (!dl.nome.value) errorScript+="Inserire il vostro nome/cognome.\n";
	if (!dl.pos.value) errorScript+="Inserire la vostra posizione aziendale.\nSe siete un privato inserite: 'Privato'\n";
	if (!dl.email.value) errorScript+="Inserire il vostro indirizzo e-mail.\n";
	else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(dl.email.value)) errorScript += 'Indirizzo e-mail non valido.\n'
	
	if (errorScript) alert("Attenzione! Ci sono errori nel modulo. Prima di continuare:\n\n"+errorScript+"\n\n"+firmaMiura);
	else sReq('POST', authpath, out, dCheck, 'check promo');
}


function check_promo_inbook_2(){
	resetSysResponse('sysPrint');
	
	var errorScript=''
	var dl=document.promoinbook
	var authpath = "../i/aj/send-promo-inbook.php";
	var dCheck = 'nome='+escape(dl.nome.value)+'&posut='+escape(dl.pos.value)+'&email='+escape(dl.email.value)+'&text='+escape(dl.richiesta.value)+'&mac='+escape(dl.mac.value);
		
	if (!dl.richiesta.value) errorScript+="Inserire il testo della vostra richiesta.\n";
	if (!dl.nome.value) errorScript+="Inserire il vostro nome/cognome.\n";
	if (!dl.pos.value) errorScript+="Inserire la vostra posizione aziendale.\nSe siete un privato inserite: 'Privato'\n";
	if (!dl.email.value) errorScript+="Inserire il vostro indirizzo e-mail.\n";
	else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(dl.email.value)) errorScript += 'Indirizzo e-mail non valido.\n'
	
	if (errorScript) alert("Attenzione! Ci sono errori nel modulo. Prima di continuare:\n\n"+errorScript+"\n\n"+firmaMiura);
	else sReq('POST', authpath, out, dCheck, 'check promo 2');
}



function resetFormPreventivo() {
	for (var i=0; i<=2; i++) {
		document.forms[0].elements[i].removeAttribute('Readonly');
		document.forms[0].elements[i].className='modulo tV14 black w280';
	}	 
}

function resetFormPromoInbook() {
	for (var i=0; i<=2; i++) {
		document.forms[0].elements[i].removeAttribute('Readonly');
		document.forms[0].elements[i].className='modulo tV14 black w280';
	}	 
}



function clearElem(el) {
	if (!el || el.value=='-- inserite qui il testo della vostra richiesta --') el.value='';
}




