// JavaScript Document
function totalUpdate()
{
	var id = prendiElementoDaId('total'),
		strict = prendiElementoDaId('strict'),
		pages = prendiElementoDaId('pages'),
		fluid = prendiElementoDaId('fluid'),
		comments = prendiElementoDaId('comments'),
		menu2 = prendiElementoDaId('menu2'),
		rollover = prendiElementoDaId('rollover'),
		wemail = prendiElementoDaId('wemail'),
		form = prendiElementoDaId('form'),
		total = 90;
		
	if(wemail.checked == false)
	{
		if(strict.checked == true)
		{
			total += 10;
			total += (10 * (pages.value - 1)) / 2;
		}
		if(fluid.checked == true)
		{
			total += 20;
			total += (20 * (pages.value - 1)) / 2;
		}
		if(comments.checked == true)
		{
			total += 20;
			total += (20 * (pages.value - 1)) / 2;
		}
		if(menu2.checked == true)
		{
			total += 16;
			total += (16 * (pages.value - 1)) / 2;
		}
		if(rollover.checked == true)
		{
			total += 10;
			total += (10 * (pages.value - 1)) / 2;
		}
	}
	
	if(pages.value > 1)
	{
		
		total += (pages.value - 1) * 45;
	}
	
	if(isNaN(pages.value) || pages.value == '')
	{
		return false;
	}
		
	id.innerHTML = "&euro; "+total+",00";
	form.hiddentot.value = total;
	
	//moneyConverter(total)
}

function pageChecker()
{
	var pages = prendiElementoDaId('pages');
	
	if(pages.value < 1 || isNaN(pages.value))
	{
		pages.value = 1;
	}
	totalUpdate();
}

function switchTempEmail()
{
	var template = prendiElementoDaId('webtemplate'),
		wemail = prendiElementoDaId('wemail'),
		woptions = prendiElementoDaId('woptions'),
		e_mail = prendiElementoDaId('e_mail'),
		totalId = prendiElementoDaId('total');
	
	
	if(template.checked == true)
	{
		e_mail.style.display = "none";
		woptions.style.display = "";
		totalUpdate();
	}
	
	if(wemail.checked == true)
	{
		woptions.style.display = "none";
		e_mail.style.display = "";
		totalUpdate();
	}
}

function formChecker(lang)
{
	var form = prendiElementoDaId('form');
	
	var wrong_email = new Array(),
		no_file_link = new Array();
	
	wrong_email['it'] = 'Inserisci un indirizzo email valido';
	wrong_email['en'] = 'Insert a valid email';
	
	no_file_link['it'] = 'Inserisci il file o un link dove scaricarlo';
	no_file_link['en'] = 'Insert file or link for download';
	
	if(form.email.value == '' || form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert(wrong_email[lang]);
		return false;
	}
	if(form.link.value == '' && form.file.value == '')
	{
		alert(no_file_link[lang]);
		return false;
	}
	
	
	
}

function Plus()
{
	var pages = prendiElementoDaId('pages');
	
	if(pages.value < 999)
	{
		a = pages.value;
		pages.value = a * 1 + 1;
	}
	
	totalUpdate();
	return false;
}

function Minus()
{
	var pages = prendiElementoDaId('pages');
	
	if(pages.value > 1)
	{
		pages.value -= 1;
	}
	
	totalUpdate();
	return false;
}

function requestChecker(lang)
{
	var form = prendiElementoDaId('request');
	
	var wrong_email = new Array();
	
	wrong_email['it'] = 'Inserisci un indirizzo email valido';
	wrong_email['en'] = 'Insert a valid email';
	
	
	if(form.email.value == '' || form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert(wrong_email[lang]);
		return false;
	}
	
}

function moneyConverter(money)
{

	caricaText('../currency.php?total=' + money + '&currency=GBP', 'currency1');
	caricaText('../currency.php?total=' + money + '&currency=USD', 'currency2');
}