/*
File: JSCODE.JS
---------------
incluso nel file principale
contiene tutte le funzioni javascript richiamate
dalle varie pagine
*/
 
function open_scheda(id)
//----------------------------
// apre in pop-up la pagina page con le caratteristiche definite in prop
{
   var left;
   left = (window.screen.availwidth - 770)/2 +120;
   n = window.open('popup.php?content=contents/scheda_ristrutturazione.php&id='+id,'',"top=160,left="+left+",location=no,scrollbars=no,toolbar=no,width=600,height=500");

}

function open_swf(page)
//---------------------------
// apre l'immagine in una finestra popup l'immagine alle sue dimensioni originali
 {
   
   new_win = window.open(page,'',"top=50,left=50,location=no,scrollbars=yes,resizable=yes");
   new_win.document.write("<html><head><title> EMP </title></head><body leftmargin=0 topmargin=0>");
   new_win.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='100%'><br />");
   new_win.document.write("<param name='movie' value='"+page+"'><br />");
   new_win.document.write("<param name='quality' value='high'><br />");
   new_win.document.write("<embed src='"+page+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='100%' height='100%'></embed></object>");
   new_win.document.write("</body></html>");
  }

  
function open_img(img,w,h)
//---------------------------
// apre l'immagine in una finestra popup l'immagine alle sue dimensioni originali
 {
   var new_win;
   prop = "top=50,left=50,resizable=yes, location=no,width=" + w + ",height=" + h;
   new_win = window.open('','',prop);
   new_win.document.write("<html><head><title>Immagine</title></head><body leftmargin=0 topmargin=0><img src='"+img+"'></body></html>");
 }


function open_page(page,prop)
//----------------------------
// apre in pop-up la pagina page con le caratteristiche definite in prop
{
   var left;
   left = (window.screen.availwidth - 770)/2 +120;
   n = window.open(page,'',"top=160,left="+left+","+prop);

}

//---------------------------------------------------------------------------------------------
	function Check_Fields()
	{
		//Controlla che tutti i campi siano stati compilati correttamente
		var testo;
		testo = document.frm.stAlert.value;	//testo alert in lingua
		
		if (document.frm.testimone.value == "" )	
		{
			document.frm.testimone.focus();
			return false;
		}

		if (document.frm.resina.value == "" )	
		{
			document.frm.resina.focus();
			return false;
		}
		
		if (document.frm.qta.value == "" || document.frm.qta.value <=0 || isNaN(document.frm.qta.value))
		{
			alert(testo);
			document.frm.qta.focus();
			return false;
		}		
		
		if (!document.frm.CC[0].checked && !document.frm.CC[1].checked)
		{
			alert(testo);
			document.frm.CC[0].focus();
			return false;
		}
		
		if (!document.frm.CI[0].checked && !document.frm.CI[1].checked)
		{
			alert(testo);
			document.frm.CI[0].focus();
			return false;
		}
		
		if (!document.frm.CA[0].checked && !document.frm.CA[1].checked)
		{
			alert(testo);
			document.frm.CA[0].focus();
			return false;
		}
		
		return true;
	}

//---------------------------------------------------------------------------------------------
//  limite al numero di caratteri
	
function cownter(nome_form,max_chars){
	   
		if (eval(nome_form).value.length > 159) {
		    
			eval(nome_form).value = eval(nome_form).value.substr(0, max_chars);
		}
}


//----------------------------------- USERNAME E PASSWORD -----------------------------
function Check_pwd(nomeform)
{
 // controlla la validità di username e password
    	if (eval(nomeform).username.value == "" || (eval(nomeform).username.value.length < 4))
    	{
    		alert ("Inserire uno username di almeno 4 caratteri.");
    		eval(nomeform).username.focus();
    		return false;
    	}
    	
    	if (eval(nomeform).password.value == "" || (eval(nomeform).password.value.length < 4))
    	{
    		alert ("Inserire una password di almeno 4 caratteri.");
    		eval(nomeform).password.focus();
    		return false;
    	}

}





function MM_displayStatusMsg(msgStr) { 
// Imposta il testo nella barra di stato
  status=msgStr;
  document.MM_returnValue = true;
  }
 

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];}
}
