// JavaScript Document

// ******************************************
// Inserisce un flash sulla home in funzione 
// della risoluzione del browser
// ******************************************
function flashHomepage(fileflash, xflash, yflash)
{
	// impostare le dimensioni originali del file flash, il file path...
	//fileflash = "images/solene_sito1063x390.swf";
	// xflash = 1064;
	// yflash = 600;
	// ...e oltre non toccare
	larghezza = window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
    lunghezza = larghezza/xflash*yflash;
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + larghezza  + '" height="' + lunghezza  + '">');
	document.write('<param name="movie" value="' + fileflash + '">');
	document.write('<param name=quality value=high>');
	document.write('<embed src="' + fileflash + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + larghezza  + '" height="' + lunghezza  + '"></embed> ');
	document.write('</object>');
}

// ******************************************
// Inserisce un flash sulla home in funzione 
// della risoluzione del browser
// ******************************************
function flashSchermoHomepage(fileflash, xflash, yflash)
{
	/* if (window.screen.width != 1024)
	{
	larghezza = xflash; 
    lunghezza = yflash;
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + larghezza  + '" height="' + lunghezza  + '">');
	document.write('<param name="movie" value="' + fileflash + '">');
	document.write('<param name=quality value=high>');
	document.write('<embed src="' + fileflash + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + larghezza  + '" height="' + lunghezza  + '"></embed> ');
	document.write('</object>');
	}
	else  if (window.screen.width == 1024) */
		altezza = window.screen.width / xflash * yflash
		// altezza = window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
		// altezza = altezza / 1024 * yflash
    //	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="' + altezza + '">');
		document.write('<param name="movie" value="' + fileflash + '">');
		document.write('<param name=quality value=high>');
		document.write('<embed src="' + fileflash + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="' + altezza + '"></embed> ');
		document.write('</object>');
	/* }
	 else if (window.screen.width == 1600)
	 {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="625">');
		document.write('<param name="movie" value="images/solene_sito1024x400.swf">');
		document.write('<param name=quality value=high>');
		document.write('<embed src="images/solene_sito1024x400.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="625"></embed> ');
		document.write('</object>');
	 }
	 */
}


// ******************************************
// Alert per onSubmit del form Richiesta_Di_Preventivo di solene.asp?do=preventivofotovoltaico
// Check if form is filled in correctly before submitting
// ******************************************
function checkForm_fotovoltaico(numeroForm, redirezionaPagina) {
	// Intialise variables
	var errorMsg = "";
	// Check for nominativo
	if (document.forms[numeroForm].elements[0].value == ""){
		errorMsg += "\n\tNominativo \t- Inserisci il tuo nome e cognome";
	}
	// Check for email
	if (document.forms[numeroForm].elements[1].value == ""){
		errorMsg += "\n\tEmail \t\t- Inserisci la tua email";
	}
	// Check for oggetto
	if (document.forms[numeroForm].elements[3].value == ""){
		errorMsg += "\n\tOggetto \t\t- Inserisci l\x27oggetto della tua richiesta";
	}
	// Check for oggetto
	if (document.forms[numeroForm].elements[12].checked == false){
		errorMsg += "\n\tPrivacy \t\t- Acconsenti al trattamento dei tuoi dati personali";
	}
	// Check the Email non valida
	// words = document.forms[numeroForm].elements[1].value;
	// chiocciola = 0;
	// for (var loop = 0; loop <= words.length - 1; ++loop){
	// 	if (words[loop] == '@') {
	//	chiocciola = 1
	//	}
	// }	
	// if (chiocciola == 0)
	// {
	// errorMsg += "\n\tEmail \t\t- Email non valida";
	// }	
	
	// If there is a problem with the form then display an error
	if (errorMsg != "") {
		msg = "___________________________________________________________________\n\n";
		msg += "La tua richiesta di preventivo non è corretta.\n";
		msg += "Correggi gli errori e re-invia il form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "Elenco errori: \n";
		
		errorMsg += alert(msg + errorMsg + "\n");
		return false;
	}
	return self.location = redirezionaPagina; 
	//true;	
}



// ******************************************
// Alert per onSubmit del form Richiesta_Di_Preventivo di solene.asp?do=preventivobioedilizia
// Check if form is filled in correctly before submitting
// ******************************************
function checkForm_bioedilizia(numeroForm, redirezionaPagina) {
	// Intialise variables
	var errorMsg = "";
	// Check for nominativo
	//document.getElementById(nome).value == ""
	if (document.forms[numeroForm].elements[0].value == ""){
		errorMsg += "\n\tNominativo \t- Inserisci il tuo nome e cognome";
	}
	// Check for email
	if (document.forms[numeroForm].elements[1].value == ""){
		errorMsg += "\n\tEmail \t\t- Inserisci la tua email";
	}
	// Check for oggetto
	if (document.forms[numeroForm].elements[3].value == ""){
		errorMsg += "\n\tOggetto \t\t- Inserisci l\x27oggetto della tua richiesta";
	}
	// Check for tipologia di intervento
	if (document.forms[numeroForm].elements[4].value == ""){
		errorMsg += "\n\tTipologia di intervento - Inserisci l\x27intervento richiesto";
	}
	// Check for regione
	if (document.forms[numeroForm].elements[5].value == "" || document.forms[numeroForm].elements[5].value == "NULL"){
		errorMsg += "\n\tRegione \t\t- Identifica il luogo d\x27intervento";
	}
	// Check for provincia
	if (document.forms[numeroForm].elements[6].value == "" || document.forms[numeroForm].elements[6].value == "NULL"){
		errorMsg += "\n\tProvincia \t\t- Identifica il luogo d\x27intervento";
	}
	// Check for comune
	if (document.forms[numeroForm].elements[7].value == "" || document.forms[numeroForm].elements[7].value == "NULL"){
		errorMsg += "\n\tComune \t\t- Identifica il luogo d\x27intervento";
	}
		// Check for Accessibilità all'area  	  	
  	if (document.forms[numeroForm].elements[8].value == ""){
		errorMsg += "\n\tAccessibilità all\x27area - Specificare";
	}
	// Check for Terreno acquistato/di proprietà
	if (document.forms[numeroForm].elements[9].value == ""){
		errorMsg += "\n\tTerreno acquistato/di proprietà - Specificare";
	}
	// Check for Metri quadri desiderati
	if (document.forms[numeroForm].elements[10].value == ""){
		errorMsg += "\n\tMetri quadri desiderati - Specificare";
	}
	// Check for Tempistiche
	if (document.forms[numeroForm].elements[11].value == ""){
		errorMsg += "\n\tTempistiche \t- Indicare la propria richiesta";
	}
	// Check for casa Biohouse
	if (document.forms[numeroForm].elements[17].value == ""){
		errorMsg += "\n\tCasa Biohouse scelta come riferimento - Indicare";
	}
	// Check for Breve descrizione delle necessità
	if (document.forms[numeroForm].elements[18].value == ""){
		errorMsg += "\n\tBreve descrizione delle necessità - Specificare";
	}
	// Check for Interrato
	if (document.forms[numeroForm].elements[19].value == ""){
		errorMsg += "\n\tInterrato \t\t- Indicare la propria richiesta";
	}
	// Check for Box
	if (document.forms[numeroForm].elements[20].value == ""){
		errorMsg += "\n\tBox \t\t- Indicare la propria richiesta";
	}
	// Check for Finiture esterni
	if (document.forms[numeroForm].elements[21].value == ""){
		errorMsg += "\n\tFiniture esterni \t- Indicare il tipo";
	}
	// Check for Finiture esterni
	if (document.forms[numeroForm].elements[22].value == ""){
		errorMsg += "\n\tFiniture esterni \t- Indicare la modalità";
	}
	// Check for Riscaldamento
	if (document.forms[numeroForm].elements[23].value == ""){
		errorMsg += "\n\tRiscaldamento \t- Indicare la propria richiesta";
	}
	// Check for Tipo di risorsa energetica
	if (document.forms[numeroForm].elements[24].value == ""){
		errorMsg += "\n\tTipo di risorsa energetica - Indicare la propria richiesta";
	}
	// Check for Raffrescamento
	if (document.forms[numeroForm].elements[25].value == ""){
		errorMsg += "\n\tRaffrescamento \t- Indicare la propria richiesta";
	}
	// Check for Ventilazione meccanica controllata
	if (document.forms[numeroForm].elements[26].value == ""){
		errorMsg += "\n\tVentilazione meccanica controllata \t- Indicare la propria richiesta";
	}
	// Check for Impianto Elettrico
	if (document.forms[numeroForm].elements[27].value == ""){
		errorMsg += "\n\tImpianto Elettrico \t- Indicare la propria richiesta";
	}
	// Check for Solare termico
	if (document.forms[numeroForm].elements[28].value == ""){
		errorMsg += "\n\tSolare termico \t- Indicare la propria richiesta";
	}
	// Check for Solare fotovoltaico
	if (document.forms[numeroForm].elements[29].value == ""){
		errorMsg += "\n\tSolare fotovoltaico \t- Indicare la propria richiesta";
	}
	// Check for Privacy
	if (document.forms[numeroForm].elements[30].checked == false){
		errorMsg += "\n\tPrivacy \t\t- Acconsenti al trattamento dei tuoi dati personali";
	}
	// Check the Email non valida
	// words = document.forms[numeroForm].elements[1].value;
	// chiocciola = 0;
	// for (var loop = 0; loop <= words.length - 1; ++loop){
	// 	if (words[loop] == '@') {
	//	chiocciola = 1
	//	}
	// }	
	// if (chiocciola == 0)
	// {
	// errorMsg += "\n\tEmail \t\t- Email non valida";
	// }	
	
	// If there is a problem with the form then display an error
	if (errorMsg != "") {
		msg = "___________________________________________________________________\n\n";
		msg += "La tua richiesta di preventivo non è corretta.\n";
		msg += "Correggi gli errori e re-invia il form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "Elenco errori: \n";
		
		errorMsg += alert(msg + errorMsg + "\n");
		return false;
	}
	return self.location = redirezionaPagina; 
	//true;	
}

// ******************************************
// Apre una popup. 
// Dichiarare, nel file prima della function: var popUpWin=0; 
// Per chiamare la function, ad esempio: popUpWindow('nomefilexxx', 10, 10, 600, 500)
// ******************************************
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin.focus();
}


// ******************************************
// Funzione (C) Macromedia Inc.
// rollover, preload....
// ******************************************
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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

/* Functions that swaps images. */
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 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;
}

/* Functions that handle preload. */
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];}}
}


