// GESTIONE MENU
var proSelect = 'MO';

function trim(text) {
   // Tolgo gli spazi dalla variabile passata
   return text.replace(/^\s*|\s*$/g,"");
}

function globalCampoCheckSeVuoto(id, mex) {
   // Verifico se il campo indicato è vuoto
   if(trim(id.value) == '') {
   	alert(mex);
   	id.select();
   	return false;
   }
   return true;
}

function checkInfo(ele)
{
	if(!globalCampoCheckSeVuoto(ele.nome, TRADSUPERSEC_js_campo_vuoto)) return false;
	if(!globalCampoCheckSeVuoto(ele.cognome, TRADSUPERSEC_js_campo_vuoto)) return false;
	if (ele.ufficio.selectedIndex != 3)
	{
		if(!globalCampoCheckSeVuoto(ele.azienda, TRADSUPERSEC_js_campo_vuoto)) return false;
		if(!globalCampoCheckSeVuoto(ele.attivita, TRADSUPERSEC_js_campo_vuoto)) return false;
	}
	if(!globalCampoCheckSeVuoto(ele.indirizzo, TRADSUPERSEC_js_campo_vuoto)) return false;
	if(!globalCampoCheckSeVuoto(ele.email, TRADSUPERSEC_js_campo_vuoto)) return false;
	if(!globalCampoCheckSeVuoto(ele.cap, TRADSUPERSEC_js_campo_vuoto)) return false;
	if(!globalCampoCheckSeVuoto(ele.paese, TRADSUPERSEC_js_campo_vuoto)) return false;
	if (ele.ufficio.selectedIndex == 3 && trim(ele.doc.value) != '')
	{
		var ext = ele.doc.value.split('.');
		switch (trim(ext.pop().toLowerCase()))
		{
			case 'doc':
			case 'docx':
			case 'rtf':
			case 'pdf':
			case 'txt':
				break;
			default:
				alert(TRADSUPERSEC_js_doc_non_valido);
				return false;
		}
	}
	
	if(!globalCampoCheckSeVuoto(ele.info, TRADSUPERSEC_js_campo_vuoto)) return false;

   if(!ele.autorizzazione.checked) {
      alert(TRADSUPERSEC_js_non_accettato); return false;
   }
   return true;
}

function changeScrivici(ele)
{
	document.getElementById('info1').style.display = (ele.selectedIndex == 3 ? 'none' : '');
	document.getElementById('info2').style.display = (ele.selectedIndex != 3 ? 'none' : '');
}

function openOptionalIMAGE(id) {
	window.open(URL_TEMA_REMOTO+"/_modules/accessorioFoto.php?id="+id, "Foto", "width=100,height=100,status=no,toolbar=no,scrollbars=no,menubar=no,location=no");
	return false;
}

function openOPTIONAL(id) {
	window.open(URL_OPTIONAL+"?id="+id, "Optional", "width=620,height=440,status=no,resize=no,toolbar=no,scrollbars=yes,menubar=no,location=no");
	return false;
}

function openPDF(nome) {
	window.open(URL_DOWNLOAD_PDF+nome+".pdf", "PDF", "width=700,height=500,status=no,toolbar=no,menubar=no,location=no,resize=yes");
	return false;
}

function cambiaProd(ele, nome) {
	ele.blur();
	document.getElementById(proSelect+'td').className = 'voce';
	proSelect = nome;
	document.getElementById(proSelect+'td').className = 'voce sel';
	switch(nome) {
		case 'MO': var id = 0; break;
		case 'MT': var id = 1; break;
		case 'HS': var id = 2; break;
		case 'HV': var id = 3; break;
	}
	document.getElementById('imgProd').src = picProd[id].src;
	document.getElementById('imgProd').useMap = '#'+nome;
	return false;
}

function loadFlash(file, height, width, noscale) {
	// Cerco di superare i problemi tecnici con i flash in IE!!!
	document.write("<OBJECT CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' WIDTH='"+width+"' HEIGHT='"+height+"' ");
	document.write("CODEBASE='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'> ");
	document.write("<PARAM NAME='MOVIE'  VALUE='/_flash/"+file+"'> ");
	document.write("<PARAM NAME='QUALITY' VALUE='high'> ");
	if(noscale === true)
		document.write("<PARAM NAME='SCALE' VALUE='noscale'> ");
	document.write("<param name='menu' value='false' /> ");
	document.write("<EMBED SRC='/_flash/"+file+"' ");
	if(noscale === true)
		document.write(" scale='noscale'");
	document.write("WIDTH='"+width+"' HEIGHT='"+height+"' QUALITY='high' menu='false' "); 
	document.write("PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> ");
	document.write("</EMBED> </OBJECT> ");
}

function loadFlashShared(file, height, width, noscale) {
	// Cerco di superare i problemi tecnici con i flash in IE!!!
	document.write("<OBJECT CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' WIDTH='"+width+"' HEIGHT='"+height+"' ");
	document.write("CODEBASE='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'> ");
	document.write("<PARAM NAME='MOVIE'  VALUE='/_shared/"+file+"'> ");
	document.write("<PARAM NAME='QUALITY' VALUE='high'> ");
	if(noscale === true)
		document.write("<PARAM NAME='SCALE' VALUE='noscale'> ");
	document.write("<param name='menu' value='false' /> ");
	document.write("<EMBED SRC='/_shared/"+file+"' ");
	if(noscale === true)
		document.write(" scale='noscale'");
	document.write("WIDTH='"+width+"' HEIGHT='"+height+"' QUALITY='high' menu='false' "); 
	document.write("PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> ");
	document.write("</EMBED> </OBJECT> ");
}

function mouseProdottiHome(ele) {
	ele.src = (ele.src.slice(-9) == '.over.jpg' ? ele.src.substring(0, (ele.src.length - 9))+'.jpg' : ele.src.substring(0, (ele.src.length - 4))+'.over.jpg');
}

function faresINside(lang) {
	window.open('/faresINside/popup.php?l='+lang, "faresINside", "scrollbars=no,resizable=no,width=490,height=590,status=no,location=no,toolbar=no");
	return false;
}

function showAll()
{
	$('#schedaAccessori .moreLink').hide();
	$('#schedaAccessori .more').show();
}

function homeImages()
{
	if ($('#homeRandBox img.top').next().length)
		var ref = $('#homeRandBox img.top').next();
	else
		var ref = $('#homeRandBox img:first');
	ref.show().css('z-index', '25');
	
	$('#homeRandBox img.top').fadeOut('slow', function() {
		$('#homeRandBox img.top').removeClass('top');
		ref.addClass('top').css('z-index', '30');
	});
}

$(function()
{
	$('.mainMenu a').attr('title', '');
	$('.menuLat a').attr('title', '');
	if (!$.browser.msie)
		$('.ieMenu table').appendTo('td.head .widthbox');
	if ($('#homeRandBox').length == 1)
		setInterval(homeImages, 4000);
	if ($('#schedaAccessori .preview a').length > 0)
		$('#schedaAccessori .preview a').lightBox();
	$('.mainMenu li:has(ul)').hover(function(e)
	{
		$(this).children('ul').css('display', 'none');
		$(this).children('ul').show();
	},
	function(e)
	{
		$(this).children('ul').hide();
	});

});