//<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function inizializza(){
  if (document.all) {
    documento="document.all";
    parA="['";
    parB="']";
    visibilita=".style.visibility";
    nascosto="'hidden'";
    visibile="'visible'";
  }
  else if (document.layers){
    documento="document.layers";
    parA="['";
    parB="']";
    visibilita=".visibility";
    nascosto="'hide'";
    visibile="'show'";
  }
  else if (document.getElementById) {
    documento="document.getElementById";
    parA="('";
    parB="')";
    visibilita=".style.visibility";
    nascosto="'hidden'";
    visibile="'visible'";
  }
  visibilitaLivello1=documento+parA+parB+visibilita;
}

function ShowLayer(livello, livello1)
{
	visibilitaLivello1=documento+parA+livello1+parB+visibilita;
	stato1 = eval(nascosto);
	eval(documento+parA+livello1+parB+visibilita+"=''+stato1+'';");
	
	visibilitaLivello=documento+parA+livello+parB+visibilita;
	stato = eval("("+visibilitaLivello+"=="+visibile+")?"+nascosto+":"+visibile+";");
	eval(documento+parA+livello+parB+visibilita+"=''+stato+'';");
}
function controllaemail(campo)
{
  if (campo.value.length != 0)
  {
	errore = 2;
	x = 0;
	stringa = campo.value.length;
			
	 for (y=0 ;y < stringa ; y++)
	 { 	
	 	if (campo.value.charAt(y).valueOf() != "@")
      	{
			errore = 1 ;			
		}
		else
		{	
			errore = 0;
			x = y;
			y = 1000;
		}
	 }
	 	
	if (errore > 0)
 	{
		alert("Indirizzo E-MAIL non valido.");  
		campo.focus();
        return false;
	}
			 
	 for (y=x ;y < stringa ; y++)
	 {
	 	if (campo.value.charAt(y).valueOf() != ".")
      	{
			errore = 1 ;
		}
		else
		{	
            if (y == (stringa - 1))
            { 
                errore = 1 ; 
            }
            else
            {   
                if (campo.value.charAt(y + 1).valueOf() == ".")
                {
                    errore = 1 ; 
                }
                else
                {
                   	errore = 0;
	        	    y = 1000;
                }
            }
		}
	 }
     if (errore > 0)
	{
		alert("Indirizzo E-MAIL non valido.");  
		campo.focus();
	    return false;
	}
	return true;
  }
}
function AddEmail(campo)
{
	var pos;
	var email;
	var id;
	var frm = document.forms[1];
	
	for (var i = 0; i < campo.options.length; i++)
	{
		pos = campo.value.indexOf("|");
		id = campo.value.substr(0,pos);
		email = campo.value.substr(pos+1);
		if ((campo.options[i].index == true) && (campo.options[i].value != '*'))
		{
			if (frm.MailTo.value.length==0)
			{frm.MailTo.value = email;}
			else if (frm.MailCC.value.length==0)
			{frm.MailCC.value = email;}
			else
			{frm.MailCC.value = frm.MailCC.value+';'+email;}
		}
	}
}
function getUrlid(car)
{
	var pos1 = document.URL.indexOf(car, 0);
	var pos2 = document.URL.indexOf("&", 0);
	if (pos2 == -1) pos2 = document.URL.length;
	if (pos1 > 0 && pos2 > 0) campo = document.URL.substring(pos1, pos2);
	return campo.substring(campo.indexOf("=", 0)+1, campo.length);
}

function RemoveSelValue(selname)
{
	var selMName = eval("document.forms[1]."+selname);
	if (selMName.options.selectedIndex > 0)
	{
		if (selMName.options[selMName.options.selectedIndex].value.length > 0)
		{
			for (var i = 0; i < selMName.options.length; i++)
			{
					if (selMName.options[i].selected == true)
					{selMName.options[i] = null;}
			}
		}
	}
	else
	{
	 	alert("Selezionare un valore da eliminare!")
		selMName.focus();
	 }
}
function controllanum(campo)
{
	if (isNaN(parseFloat(campo.value)))
	{
		alert("Inserire un valore numerico!");
		campo.value = '';
		campo.focus();
        return false;
	}
}

function OpenWin(page,windowWidth,windowHeight)
{
	var win;
	var menu = 'no';
	//var windowWidth = 500;
	//var windowHeight = 250;
	var locX = ( screen.width - windowWidth ) / 2;
	var locY = ( screen.height - windowHeight ) / 2;

	var windowFeatures = "width=" + windowWidth
	                   + ",height=" + windowHeight
	                   + ",screenX=" + locX
	                   + ",screenY=" + locY
	                   + ",left=" + locX
	                   + ",top=" + locY
					   + ",toolbar=no"
					   + ",location=no"
					   + ",directories=no"
					   + ",status=yes"
					   + ",menubar=" + menu
					   + ",scrollbars=yes"
					   + ",resizable=yes";

	win = open(page, "SoluzioneOro", windowFeatures);
}
function Vai(url,id,flag)
{
	var frm = document.forms[id];
	var trovato = 0;
	var checkfrm = false;
	var countradio = 0;
	var countradiof = 0;
	var countradiot = 0;
	var countradio1 = 0;
	var counttext = 0;
	var counttext1 = 0;
	var countselect = 0;
	var countselect1 = 0;
	var countselectM = 0;
	var countselectM1 = 0;
	var n;
	var v;
	var mess;
	
	for(var i=0; i <= frm.elements.length-1; i++) 
	{
		n = frm.elements[i].name;
		v = frm.elements[i].value;
		if (frm.elements[i].type == "select-one")
		{
			countselect += 1;
			if (frm.elements[i].value.length == 0)
			{
				alert("Il campo "+n+" è obbligatorio!");
				frm.elements[i].focus();
				return false;
			}
			else
			{
				checkfrm = true;
				countselect1 += 1;
			}
		}
		else if (frm.elements[i].type == "text")
		{
			if ((n.toLowerCase() == "ragione") && (v.length == 0))
			{
				if ((frm.nome.value.length == 0) || (frm.cognome.value.length == 0))
				{
					mess = "";
					trovato = 1;
				}
			}
			else if ((n.toLowerCase() == "ragione") && (v.length > 0))
			{
				if ((frm.nome.value.length > 0) || (frm.cognome.value.length > 0))
				{
					mess = "";
					trovato = 1;
				}
			}
			else if ((n.toLowerCase() != "ragione") && (n.toLowerCase() != "nome") && (n.toLowerCase() != "cognome"))
			{
				counttext += 1;
				if (frm.elements[i].value.length == 0)
				{
					alert("Il campo "+n+" è obbligatorio!");
					frm.elements[i].focus();
					return false;
				}
				else
				{
					checkfrm = true;
					counttext1 += 1;
				}
			}
			if (trovato ==1)
			{
				alert(mess);
				frm.elements[i].focus();
				return false;
			}
		}
	}
	
	if ((checkfrm == true) && (countselect == countselect1) && (counttext == counttext1))
	{
		frm.action = url;
		frm.submit();
		return true;
	}
}
function Elimina(url,id)
{
	var frm = document.forms[id];
	if (confirm("Sei sicuro di voler continuare?")) 
		{
			//frm.action=url;	
			//alert(frm.action);		
			//frm.submit();
			window.location=url;
		}
}
function trim(a)
{	
  return a.replace(/^\s+/,'').replace(/\s+$/,'')
}
function ShowModulo()
{	
	if (navigator.appName == "Netscape")
	{
		if (document.layers['infoSpan'].visibility == 'hide')
		{
			document.layers['infoSpan'].visibility = 'visible';
		}
		else
		{
			document.layers['infoSpan'].visibility = 'hide';
		}
	}
	else
	{
		if (document.all['infoSpan'].style.visibility == 'hidden')
		{
			document.all['infoSpan'].style.visibility = 'visible';
		}
		else
		{
			document.all['infoSpan'].style.visibility = 'hidden';
		}
	}	
}

function RicaricaFrm(frm,page)
{
	document.forms[frm].action = page;
	document.forms[frm].submit();
}
function NonAbilitata()
{
	alert('Area in costruzione!');
	return false;
}
function Vai2(url)
{
	var frm = document.forms[1];
	var checkfrm = false;
	var counttext = 0;
	var counttext1 = 0;
	var countselect = 0;
	var countselect1 = 0;
	var n;
	var v;
	
	for(var i=0; i <= frm.elements.length-1; i++) 
	{
		n = frm.elements[i].name;
		v = frm.elements[i].value;
		if (frm.elements[i].type == "select-one")
		{
			countselect += 1;
			if (v.length == 0)
			{
				alert("Il campo "+n+" è obbligatorio!");
				frm.elements[i].focus();
				return false;
			}
			else
			{
				checkfrm = true;
				countselect1 += 1;
			}
		}
		else if (frm.elements[i].type == "text")
		{
			counttext += 1;
			if (v.length == 0)
			{
					alert("Il campo "+n+" è obbligatorio!");
					frm.elements[i].focus();
					return false;
			}
			else
			{
					checkfrm = true;
					counttext1 += 1;
			}
		}
	}

	if ((checkfrm == true) && (countselect == countselect1) && (counttext == counttext1))
	{
		alert(url);
		frm.action = url;
		frm.submit();
		return true;
	}
}

function CalculatePrice(radice)
{
	var selMName = eval("document.forms[0].carati"+radice+"");
	var texMName = eval("document.forms[0].grammi"+radice+"");
	var resMName = eval("document.forms[0].risultato"+radice+"");
	var res=0;
	if (texMName.value.indexOf(',')){
		txtMN = texMName.value.replace(',','.');
	}
	if (texMName.value == ""){
		alert('Il campo grammi è vuoto!');
		resMName.value = '';
		return false;
	}
	else{
		res = (parseFloat(txtMN) * parseFloat(selMName.options[selMName.options.selectedIndex].value));
		resMName.value = parseFloat(res);
		return true;
	}
}
function ControllaPrezzo(flag, campo)
{
	var texMName = eval("document.forms[0].grammi"+flag+"");
	var selMName = eval("document.forms[0].carati"+flag+"");
	var selNegozio = eval("document.forms[0].negozio"+flag+"");
	if (texMName.value == ""){
		alert('Il campo grammi è vuoto!');
		texMName.focus();
		return false;
	}
	else if (controllanum(texMName)==false){return false;}
	
	if(campo.name=='oro'){
		var gr = texMName.value;
		var car = selMName.options[selMName.options.selectedIndex].value;
		var neg = selNegozio.options[selNegozio.options.selectedIndex].value;
		OpenWin('quotazioneoro.php?gr='+gr+'&car='+car+'&neg='+neg, 500, 400);
	}
	else{
		var gr = texMName.value;
		var car = selMName.options[selMName.options.selectedIndex].value;
		var neg = selNegozio.options[selNegozio.options.selectedIndex].value;
		OpenWin('quotazioneargento.php?gr='+gr+'&car='+car+'&neg='+neg, 500, 400);
	}
}

function InviaContatto(){
	var frm = eval("document.forms[0]");
	if((frm.email_da.value == "") && (frm.telefono_da.value == "")){
		alert('Inserire l\'indirizzo email o il telefono per essere contattati!');
		return false;
	}
	else if(controllaemail(frm.email_da)==false){return false;}
	
	else if(frm.txa_corpo.value == ""){
		alert('Inserire il testo del messaggio!');
		return false;
	}
	else{
		frm.submit();
		return true;
	}
}

function getValue(varname)
{
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length == 0)
  {
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname)
    {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
}

function controllarisoluzione()
{
	var Wide = screen.width;

	/*if (Wide <= 1024){
	  document.write('<div id="flashcontentchi">');
	  var myFlashObject = new FlashObject("Galleria/gallery.swf", "gallery", "360", "100%", 6, "#ffffff");
	  myFlashObject.addParam("scale", "noscale");
	  myFlashObject.addVariable("request", getQueryParamValue("image1024"));
	  myFlashObject.addVariable("photosXmlFile", "photos1024.xml");
	  myFlashObject.addVariable("configXmlFile", "galleryconfig.xml");
	  myFlashObject.write();
	  document.write('</div>');
	}
	
	else {*/
	  document.write('<div id="flashcontentchi">');
	  var myFlashObject = new FlashObject("Galleria/gallery.swf", "gallery", "500", "100%", 6, "#ffffff");
	  myFlashObject.addParam("scale", "noscale");
	  myFlashObject.addVariable("request", getQueryParamValue("image"));
	  myFlashObject.addVariable("photosXmlFile", "photos.xml");
	  myFlashObject.addVariable("configXmlFile", "galleryconfig.xml");
	  myFlashObject.write();
	  document.write('</div>');
	//}
}

//-->

