helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}

function AddText(NewCode) {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		var caretPos = document.PostTopic.Message.caretPos;
		caretPos.text = NewCode;
	} else {
		document.PostTopic.Message.value+=NewCode;
	}
	document.PostTopic.Message.focus();
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("Bold Tag Makes the enclosed text bold.\n\nUSE: <b>Questo è un testo bold</b>");
	} else if (basic) {
		AddTxt="<b>" + text + "</b>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Text to be made BOLD.",text);
		} else {
			txt=prompt("Text to be made BOLD.","Text");
		}
		if (txt!=null) {
			AddTxt="<b>"+txt+"</b>";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("Italicize Tag Makes the enclosed text italicized.\n\nUSE: <i>This is some italicized text</i>");
	} else if (basic) {
		AddTxt="<i>" + text + "</i>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Text to be italicized",text);
		} else {
			txt=prompt("Text to be italicized","Text");
		}
		if (txt!=null) {
			AddTxt="<i>"+txt+"</i>";
			AddText(AddTxt);
		}
	}
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		return document.PostTopic.Message.caretPos.text;
	} else {
		return '';
	}
}

function Anteprima(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function CheckContatti(f)
{
	var msgErrore = '';
	var nome=f.nome;
	var cognome=f.cognome;
	var azienda=f.azienda;
	var citta=f.citta;
	var email=f.email;
	var testo=f.testo;
	
	if (nome.value=="")
		{ msgErrore+="- Nome è obbligatorio.\r"; }
	else
	{
		if ((nome.value.replace(/\s*/gi,'') == '') || (nome.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Nome è obbligatorio e non può essere vuoto.\r"; }
	}
	
	if (cognome.value=="")
		{ msgErrore+="- Cognome è obbligatorio.\r"; }
	else
	{
		if ((cognome.value.replace(/\s*/gi,'') == '') || (cognome.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Cognome è obbligatorio e non può essere vuoto.\r"; }
	}

	if (azienda.value!="")
	{
		if ((azienda.value.replace(/\s*/gi,'') == '') || (azienda.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Azienda non può essere vuoto.\r"; }
	}

	if (citta.value!="")
	{
		if ((citta.value.replace(/\s*/gi,'') == '') || (citta.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Città non può essere vuoto.\r"; }
	}

	if (email.value == "")
		{ msgErrore+="- E-mail è obbligatorio.\r"; }
	else
		{
		if (!verEmail(email.value))
		{ msgErrore+="- Inserire un indirizzo e-mail corretto.\r"; }
		}

	if (testo.value == "")
		{ msgErrore+="- Testo del messaggio è obbligatorio.\r"; }
	else
		{
		if ((testo.value.replace(/\s*/gi,'') == '') || (testo.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Testo del messaggio è obbligatorio e non può essere vuoto.\r"; }
		}
	
	if (msgErrore != '')
		{
		msgErrore = "Si sono verificati i seguenti errori:\r\r" + msgErrore;
		alert(msgErrore);
		return false;
		}
	return true;
}

function CheckFranchising(f)
{
	var msgErrore = '';
	var err_pers = '';
	var err_st = '';
	var err_str = '';
	var err_resp = '';
	var err_att = '';
	var pers_nome=f.pers_nome;
	var pers_cognome=f.pers_cognome;
	var pers_mail=f.pers_mail;
	var pers_tel=f.pers_tel;
	var st_nome=f.st_nome;
	var st_anno=f.st_anno;
	var st_soci=f.st_soci;
	var str_dip=f.str_dip;
	var str_periti=f.str_periti;
	var str_dotazioni=f.str_dotazioni;
	var resp_nome=f.resp_nome;
	var resp_cognome=f.resp_cognome;
	var resp_titolo=f.resp_titolo;
	var resp_settori=f.resp_settori;
	var resp_iscr=f.resp_iscr;
	var resp_att=f.resp_att;
	var att_terr=f.att_terr;
	var att_comp=f.att_comp;
	var att_sinistri=f.att_sinistri;
	var att_met=f.att_met;
	
	// DATI PERSONALI
	if (pers_nome.value=="")
		{ err_pers+="- nome è obbligatorio\r"; }
	else
	{
		if ((pers_nome.value.replace(/\s*/gi,'') == '') || (pers_nome.value.replace(/\x13\x10*/gi,'') == ''))
		{ err_pers+="- nome è obbligatorio e non può essere vuoto\r"; }
	}

	if (pers_cognome.value=="")
		{ err_pers+="- cognome è obbligatorio\r"; }
	else
	{
		if ((pers_cognome.value.replace(/\s*/gi,'') == '') || (pers_cognome.value.replace(/\x13\x10*/gi,'') == ''))
		{ err_pers+="- cognome è obbligatorio e non può essere vuoto\r"; }
	}

	if (pers_mail.value == "")
		{ err_pers+="- e-mail è obbligatorio\r"; }
	else
	{
		if (!verEmail(pers_mail.value))
		{ err_pers+="- inserire un indirizzo e-mail corretto\r"; }
	}

	if (pers_tel.value=="")
		{ err_pers+="- telefono è obbligatorio\r"; }
	else
	{
		if ((pers_tel.value.replace(/\s*/gi,'') == '') || (pers_tel.value.replace(/\x13\x10*/gi,'') == ''))
		{ err_pers+="- telefono è obbligatorio e non può essere vuoto\r"; }
	}

	// ERRORE DATI PERSONALI
	if (err_pers != '')
		{ msgErrore+="\rDati personali:\r"+err_pers }


	// STUDIO
	if (st_nome.value=="")
		{ err_st+="- nome è obbligatorio\r"; }
	else
	{
		if ((st_nome.value.replace(/\s*/gi,'') == '') || (st_nome.value.replace(/\x13\x10*/gi,'') == ''))
		{ err_st+="- nome è obbligatorio e non può essere vuoto\r"; }
	}
	
	if (st_anno.value=="")
		{ err_st+="- anno apertura è obbligatorio\r"; }
	else
	{
		if ((st_anno.value.replace(/\s*/gi,'') == '') || (st_anno.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_st+="- anno apertura è obbligatorio e non può essere vuoto\r"; }
		if (isNaN(st_anno.value))
			{ err_st+="- anno apertura deve essere numerico\r"; }
	}

	if (st_soci.value=="")
		{ err_st+="- numero soci è obbligatorio\r"; }
	else
	{
		if ((st_soci.value.replace(/\s*/gi,'') == '') || (st_soci.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_st+="- numero soci è obbligatorio e non può essere vuoto\r"; }
		if (isNaN(st_anno.value))
			{ err_st+="- numero soci deve essere numerico\r"; }
	}

	// ERRORE STUDIO
	if (err_st != '')
		{ msgErrore+="\rStudio:\r"+err_st }


	// STRUTTURA
	if (str_dip.value=="")
		{ err_str+="- numero dipendenti è obbligatorio\r"; }
	else
	{
		if ((str_dip.value.replace(/\s*/gi,'') == '') || (str_dip.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_str+="- numero dipendenti è obbligatorio e non può essere vuoto\r"; }
		if (isNaN(str_dip.value))
			{ err_str+="- numero dipendenti deve essere numerico\r"; }
	}

	if (str_periti.value=="")
		{ err_str+="- numero collaboratori esterni è obbligatorio\r"; }
	else
	{
		if ((str_periti.value.replace(/\s*/gi,'') == '') || (str_periti.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_str+="- numero collaboratori esterni è obbligatorio e non può essere vuoto\r"; }
		if (isNaN(str_periti.value))
			{ err_str+="- numero collaboratori esterni deve essere numerico\r"; }
	}

	if (str_dotazioni.value=="")
		{ err_str+="- dotazioni informatiche è obbligatorio\r"; }
	else
	{
		if ((str_dotazioni.value.replace(/\s*/gi,'') == '') || (str_dotazioni.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_str+="- dotazioni informatiche è obbligatorio e non può essere vuoto\r"; }
		if (isNaN(str_periti.value))
			{ err_str+="- numero collaboratori esterni deve essere numerico\r"; }
	}

	// ERRORE STRUTTURA
	if (err_str != '')
		{ msgErrore+="\rStruttura:\r"+err_str }


	// RESPONSABILE
	if (resp_nome.value=="")
		{ err_resp+="- nome è obbligatorio\r"; }
	else
	{
		if ((resp_nome.value.replace(/\s*/gi,'') == '') || (resp_nome.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- nome è obbligatorio e non può essere vuoto\r"; }
	}

	if (resp_cognome.value=="")
		{ err_resp+="- cognome è obbligatorio\r"; }
	else
	{
		if ((resp_cognome.value.replace(/\s*/gi,'') == '') || (resp_cognome.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- cognome è obbligatorio e non può essere vuoto\r"; }
	}

	if (resp_titolo.value=="")
		{ err_resp+="- titolo di studio è obbligatorio\r"; }
	else
	{
		if ((resp_titolo.value.replace(/\s*/gi,'') == '') || (resp_titolo.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- titolo di studio è obbligatorio e non può essere vuoto\r"; }
	}

	if (resp_settori.value=="")
		{ err_resp+="- settori di competenza è obbligatorio\r"; }
	else
	{
		if ((resp_settori.value.replace(/\s*/gi,'') == '') || (resp_settori.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- settori di competenza è obbligatorio e non può essere vuoto\r"; }
	}

	if (resp_iscr.value=="")
		{ err_resp+="- iscrizione a associazioni di categoria è obbligatorio\r"; }
	else
	{
		if ((resp_iscr.value.replace(/\s*/gi,'') == '') || (resp_iscr.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- iscrizione a associazioni di categoria è obbligatorio e non può essere vuoto\r"; }
	}

	if (resp_att.value=="")
		{ err_resp+="- anni di attività è obbligatorio\r"; }
	else
	{
		if ((resp_att.value.replace(/\s*/gi,'') == '') || (resp_att.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_resp+="- anni di attività è obbligatorio e non può essere vuoto.\r"; }
		if (isNaN(resp_att.value))
			{ err_resp+="- anni di attività deve essere numerico\r"; }
	}

	// ERRORE RESPONSABILE
	if (err_resp != '')
		{ msgErrore+="\rResponsabile:\r"+err_resp }


	// ATTIVITA'
	if (att_terr.value=="")
		{ err_att+="- territorio di intervento è obbligatorio\r"; }
	else
	{
		if ((att_terr.value.replace(/\s*/gi,'') == '') || (att_terr.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_att+="- territorio di intervento è obbligatorio e non può essere vuoto\r"; }
	}

	if (att_comp.value=="")
		{ err_att+="- principali compagnie clienti è obbligatorio\r"; }
	else
	{
		if ((att_comp.value.replace(/\s*/gi,'') == '') || (att_comp.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_att+="- principali compagnie clienti è obbligatorio e non può essere vuoto\r"; }
	}

	if (att_sinistri.value=="")
		{ err_att+="- principali sinistri gestiti è obbligatorio\r"; }
	else
	{
		if ((att_sinistri.value.replace(/\s*/gi,'') == '') || (att_sinistri.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_att+="- principali sinistri gestiti è obbligatorio e non può essere vuoto\r"; }
	}

	if (att_met.value=="")
		{ err_att+="- metodologia operativa è obbligatorio\r"; }
	else
	{
		if ((att_met.value.replace(/\s*/gi,'') == '') || (att_met.value.replace(/\x13\x10*/gi,'') == ''))
			{ err_att+="- metodologia operativa è obbligatorio e non può essere vuoto\r"; }
	}

	// ERRORE ATTIVITA'
	if (err_att != '')
		{ msgErrore+="\rAttività:\r"+err_att }


	// GESTIONE ERRORI
	if (msgErrore != '')
		{
		msgErrore = "Si sono verificati i seguenti errori:\r" + msgErrore;
		alert(msgErrore);
		return false;
		}
	return true;
}

function CheckLogin(f)
{
	var errMsg = '';
	var user=f.user;
	var pass=f.pass;
	
	if (user.value=="")
		{ errMsg+="- Username è obbligatorio\r"; }
	else
	{
		if ((user.value.replace(/\s*/gi,'') == '') || (user.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Username è obbligatorio e non può essere vuoto\r"; }
	}
	
	if (pass.value=="")
		{ errMsg+="- Password è obbligatorio\r"; }
	else
	{
		if ((pass.value.replace(/\s*/gi,'') == '') || (pass.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Password è obbligatorio e non può essere vuoto\r"; }
	}
	
	if (errMsg != '')
		{
		errMsg = "Si sono verificati i seguenti errori:\r\r" + errMsg;
		alert(errMsg);
		return false;
		}
	return true;
}

// FUNZIONI AREA AMMINISTRATIVA
function CheckAzienda(f)
{
	var errMsg = '';
	var denominazione=f.denominazione;
	var indirizzo=f.indirizzo;
	var cap=f.cap;
	var citta=f.citta;
	var telefono=f.telefono;
	var fax=f.fax;
	var email=f.email;
	
	if (denominazione.value=="")
		{ errMsg+="- Denominazione è obbligatorio\r"; }
	else
	{
		if ((denominazione.value.replace(/\s*/gi,'') == '') || (denominazione.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Denominazione è obbligatorio e non può essere vuoto\r"; }
	}
	
	if (indirizzo.value=="")
		{ errMsg+="- Indirizzo è obbligatorio\r"; }
	else
	{
		if ((indirizzo.value.replace(/\s*/gi,'') == '') || (indirizzo.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Indirizzo è obbligatorio e non può essere vuoto\r"; }
	}

	if (cap.value=="")
		{ errMsg+="- CAP è obbligatorio\r"; }
	else
	{
		if ((cap.value.replace(/\s*/gi,'') == '') || (cap.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- CAP è obbligatorio e non può essere vuoto\r"; }
	}

	if (citta.value=="")
		{ errMsg+="- Città è obbligatorio\r"; }
	else
	{
		if ((citta.value.replace(/\s*/gi,'') == '') || (citta.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Città è obbligatorio e non può essere vuoto\r"; }
	}

	if (telefono.value=="")
		{ errMsg+="- Telefono è obbligatorio\r"; }
	else
	{
		if ((telefono.value.replace(/\s*/gi,'') == '') || (telefono.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- Telefono è obbligatorio e non può essere vuoto\r"; }
	}

	if (fax.value=="")
		{ errMsg+="- FAX è obbligatorio\r"; }
	else
	{
		if ((fax.value.replace(/\s*/gi,'') == '') || (fax.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- FAX è obbligatorio e non può essere vuoto\r"; }
	}

	if (email.value=="")
		{ errMsg+="- E-mail è obbligatorio\r"; }
	else
	{
		if ((email.value.replace(/\s*/gi,'') == '') || (email.value.replace(/\x13\x10*/gi,'') == ''))
		{ errMsg+="- E-mail è obbligatorio e non può essere vuoto\r"; }
	}
	
	if (errMsg != '')
		{
		errMsg = "Si sono verificati i seguenti errori:\r\r" + errMsg;
		alert(errMsg);
		return false;
		}
	return true;
}

function CheckContenuti(f)
{
	var msgErrore = '';
	var contenuto=f.Message;
	
	if (contenuto.value=="")
		{ msgErrore+="- Il contenuto della pagina è obbligatorio.\r"; }
	else
	{
		if ((contenuto.value.replace(/\s*/gi,'') == '') || (contenuto.value.replace(/\x13\x10*/gi,'') == ''))
		{ msgErrore+="- Il contenuto della pagina è obbligatorio e non può essere vuoto.\r"; }
	}

	if (msgErrore != '')
		{
			msgErrore = "Si sono verificati i seguenti errori:\r\r" + msgErrore;
			alert(msgErrore);
			return false;
		}
		else
		{
		return true;
		}
}
