function cleanText(id, text) 
{
	if (document.getElementById(id).value == text) 
	{
		document.getElementById(id).value = '';
	}
}

function refillText(id, text) 
{
	if (document.getElementById(id).value == '') 
	{
		document.getElementById(id).value = text;
	}
}

function removeAllegato(allegato)
{
	if (allegato == 'curriculum')
	{
		document.getElementById('curriculum-inviato').style.display = 'none';
		document.invia_dati.curriculum_file = "";
	}
	if (allegato == 'sommario')
	{
		document.getElementById('sommario-inviato').style.display = 'none';
		document.invia_dati.summary_file = "";
	}
}

function validateForm()
{
	
	var email = document.getElementById('form-email').value;
	var indirizzo = document.getElementById('form-indirizzo').value;
	var name = document.getElementById('form-name').value;
	var professione = document.getElementById('form-professione').value;
	var telefono = document.getElementById('form-telefono').value;
	var titolo = document.getElementById('form-titolo').value;
	var pagine = document.getElementById('form-pagine').value;
	var theme = document.getElementById('form-theme').value;
	var pubblico = document.getElementById('form-pubblico').value;
	var state = document.getElementById('form-state').value;
	var concorrenti = document.getElementById('form-concorrenti').value;
	var pubblicazioni = document.getElementById('form-pubblicazioni').value;
	var note = document.getElementById('form-note').value;
	var curriculum = document.getElementById('curriculum').value;
	var sommario = document.getElementById('sommario_file').value;
	
	var isValid = true;
	
	var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	
	if (!email_re.test(email)) {
		document.getElementById('form-email').style.border="1px solid red";
		isValid = false;
	}

	if ((indirizzo == '') || (indirizzo == 'Indirizzo'))
	{
		document.getElementById('form-indirizzo').style.border="1px solid red";
		isValid = false;
	}
	
	if ((name == '') || (name == 'Nome e cognome'))
	{
		document.getElementById('form-name').style.border="1px solid red";
		isValid = false;
	}
	
	if ((name == '') || (name == 'Nome e cognome'))
	{
		document.getElementById('form-professione').style.border="1px solid red";
		isValid = false;
	}

	if ((telefono == '') || (telefono == 'Telefono'))
	{
		document.getElementById('form-telefono').style.border="1px solid red";
		isValid = false;
	}

	if ((titolo == '') || (titolo == 'Titolo'))
	{
		document.getElementById('form-titolo').style.border="1px solid red";
		isValid = false;
	}

	if ((pagine == '') || (pagine == 'N. Cartelle (o pagine) anche presunte'))
	{
		document.getElementById('form-pagine').style.border="1px solid red";
		isValid = false;
	}

	if ((theme == '') || (theme == 'Ambito tematico'))
	{
		document.getElementById('form-theme').style.border="1px solid red";
		isValid = false;
	}

	if ((pubblico == '') || (pubblico == 'Pubblico specifico a cui si rivolge'))
	{
		document.getElementById('form-pubblico').style.border="1px solid red";
		isValid = false;
	}

	if ((state == '') || (state == 'Stato dell’opera'))
	{
		document.getElementById('form-state').style.border="1px solid red";
		isValid = false;
	}

	if ((concorrenti == '') || (concorrenti == 'Opere concorrenti conosciute (Titolo)'))
	{
		document.getElementById('form-concorrenti').style.border="1px solid red";
		isValid = false;
	}

	if ((pubblicazioni == '') || (pubblicazioni == 'Altre pubblicazioni'))
	{
		document.getElementById('form-pubblicazioni').style.border="1px solid red";
		isValid = false;
	}

	if ((note == '') || (note == 'Note dell’autore'))
	{
		document.getElementById('form-note').style.border="1px solid red";
		isValid = false;
	}
	
	if (sommario == '')
	{
		document.getElementById('send-sommario').style.border="1px solid red";
		isValid = false;
	}

	if (curriculum == '')
	{
		document.getElementById('send-curriculum').style.border="1px solid red";
		isValid = false;
	}

	
	if (isValid)
	{
		return true;
	}
	else
		return false;
}

function removeRedBorder(id)
{
	id.style.border="1px solid #dddddd";
}
