/*
File: COMMON.JS
---------------
incluso nel file principale
contiene tutte le funzioni COMUNI javascript richiamate
dalle varie pagine nelle varie sezioni
*/
//<SCRIPT language="javascript">

function addparam(nome,valore){

strparam   = document.frmmenu.strparam.value;
strparam   = strparam + "&" +nome +"="+valore;
document.frmmenu.strparam.value = strparam;

}

function convalidaForm(form,language,classevi)
{  
	
  for (var a = 0; a < form.elements.length; a++) 	
  {	
     var campo = form.elements[a];      	
	 var tipo=campo.type;
	 var nome=campo.name;
	 var classe=campo.className;
	 var titolo = campo.title; 
	 var id_ = campo.id; 
	 var param = campo.style.req;
	 var etichetta = id_;
	  

	if(id_.length>0)
	{
	
	    if(tipo=="text" || tipo=="file" || tipo=="password" || tipo=="select-one")
		{
		   var strvalue = campo.value.replace(/ */,"");
		   
		   if ((strvalue == '') || (strvalue == 'undefined'))
	       {
		     	window.alert('Il campo ' + etichetta +' è obbligatorio\n'+etichetta+' is required');
				campo.value = '';
	         	campo.focus();    
				campo.className = classevi;    	
				return false;      		
	       }    	
		}
		
		
		if(tipo=="checkbox")
		{
		   if ((campo.checked == false))
	       {
		     	window.alert('Il campo ' + etichetta +' è obbligatorio\n'+etichetta+' is required');
	         	campo.focus();        	
				return false;      		
	       }    	
		}
	
	
	
	
	}
	
   }
   return true;
}
 
function convalidaForm2(form,language,classevi)
{  
  
	res = true;
	
  for (var a = 0; a < form.elements.length; a++) 	
  {	
     var campo = form.elements[a];      	
	 var tipo=campo.type;
	 var nome=campo.name;
	 var classe=campo.className;
	 var titolo = campo.title; 
	 var id_ = campo.id; 
	 //var param = campo.style.req; non funziona
	 var etichetta = titolo;
	  

	if(titolo.length>0)
	{
	
	
	    if(tipo=="text" || tipo=="textarea" || tipo=="file" || tipo=="password" || tipo=="select-one" || tipo=="hidden")
		{
		   var strvalue = campo.value.replace(/ */,"");
		   
		   if ((strvalue == '') || (strvalue == 'undefined'))
	       {
		     	//window.alert('Il campo ' + etichetta +' è obbligatorio\n'+etichetta+' is required');
		     	window.alert('Il campo ' + etichetta +' è obbligatorio');
				campo.value = '';
	         	campo.focus();    
				campo.className = classevi;    	
				res= false;      		
	       }    	
		}
		
		if(tipo=="radio"){
		
		}
		
	}
	
   }
   return res;
}
 


//------------------------------------------------
function go_(sez){

 //document.frmmenu.target="_self";
  document.frmmenu.sezione.value  = sez;
  //document.frmmenu.npage.value  = 0;
  addparam("search",""); 
 //  addparam("npage","");
  addparam("ord","");
document.frmmenu.submit();

}

//------------------------------------------------

function set_language(lan){
	addparam('language',lan);
	document.frmmenu.submit();
}

function set_lang(lg)
{
 document.frmlanguage.language_.value=lg;
 document.frmlanguage.submit();
}
//------------------------------------------------
//------------------------PAGINAZIONE----------------------------

function pnext(){

	page = document.frmmenu.npage.value;
	//
	if(isNaN(page)) page = 0;
	document.frmmenu.npage.value = page*1+1;
	document.frmmenu.submit();
	
}
function plast(){
	page = document.frmmenu.npage.value;
	document.frmmenu.npage.value = page*1-1;
	document.frmmenu.submit();
	
}
function pstart(){
	document.frmmenu.npage.value = 0;
	document.frmmenu.submit();
	
}
function pend(){
	page = document.frmmenu.ntotpage.value;
	document.frmmenu.npage.value = page*1-1;
	document.frmmenu.submit();
	
}
//------------------------PAGINAZIONE2----------------------------

function pnext_(frm){
    eval("page = "+frm+".npage.value;");
	//
	if(isNaN(page)) page = 0;
	newpage = page*1+1;
	eval(frm+".npage.value = newpage;");
	eval(frm+".submit();");
	
}
function plast_(frm){
    eval("page = "+frm+".npage.value;");
	//
	if(isNaN(page)) page = 0;
	newpage = page*1-1;
	eval(frm+".npage.value = "+newpage+";");
	eval(frm+".submit();");
	
}
function pstart_(frm){
    eval(frm+".npage.value = 0;");
	eval(frm+".submit();");
	
}
function pend_(frm){
    eval("page = "+frm+".ntotpage.value;");
	newpage = page*1-1;
    eval(frm+".npage.value = "+newpage+";"); 
	eval(frm+".submit();");
	
}
//-------------------------------------------------------------------------------
//------------------------PAGINAZIONE3----------------------------

function p_next(frm,page){

	newpage = page*1+1;
	eval(frm+".npage.value = newpage;");
	eval(frm+".submit();");
	
}
function p_back(frm,page){
    //eval("page = "+frm+".npage.value;");
	//
	if(isNaN(page)) page = 0;
	newpage = page*1-1;
	eval(frm+".npage.value = "+newpage+";");
	eval(frm+".submit();");
	
}
function p_start(frm){
    eval(frm+".npage.value = 0;");
	eval(frm+".submit();");
	
}
function p_end(frm,page){
    
	newpage = page*1-1;
    eval(frm+".npage.value = "+newpage+";"); 
	eval(frm+".submit();");
	
}
//-------------------------------------------------------------------------------

function open_img(img,w,h)
//---------------------------
// apre l'immagine in una finestra popup l'immagine alle sue dimensioni originali
 {
   var new_win;
   prop = "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_media(img,w,h,tipo)
//---------------------------
// apre l'immagine in una finestra popup l'immagine alle sue dimensioni originali
 {
   var new_win;
   var open = false;
   prop = "location=no,width=" + w + ",height=" + h;
  
   var content;
   if(tipo=='img') { content = "<img src='"+img+"'>";open=true;}
   if(tipo=='swf') {
   	content = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\"";
   	content += " width=\""+w+"\" height=\""+h+"\"><param name=\"width\" value=\""+w+"\" /><param name=\"height\" value=\""+h+"\" /><param name=\"src\" value=\""+img+"\" />";
   	content += " <embed type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\" src=\""+img+"\">";
   	content += " </embed></object>\n";
   	open = true;
   }
  if(open) {
  	 new_win = window.open('','',prop);
  	new_win.document.write("<html><head><title>Immagine</title></head><body leftmargin=0 topmargin=0>"+content+"</body></html>");
  }
  else alert('Anteprima non disponibile');
 }
//------------------------------------------------- 
 function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
   
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function setStatusBar(msgStr) { self.status = msgStr; }
//--------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------
function logout(){
strparam   = document.frmmenu.strparam.value;
mysessionid = document.frmmenu.MSID.value;
strparam   = strparam + "&logout=1&username=&password=&MSID="+mysessionid;
document.frmmenu.strparam.value = strparam;
document.frmmenu.sezione.value = '100';
document.frmmenu.submit();
}


function showhidelayer(id_){
	
	
	//eval("disp=document.all."+id_+".style.display;"); inline
	disp=document.getElementById(id_).style.display;
	if(disp=='') {
		//eval("document.all."+id_+".style.display='none';");
		document.getElementById(id_).style.display= 'none';
		}
	else {
		//eval("document.all."+id_+".style.display='inline';");inline
		document.getElementById(id_).style.display='';
		
	}

	
}
function hidelayer(id_){
	
		document.getElementById(id_).style.display='none';

}
function showlayer(id_){
	
		document.getElementById(id_).style.display='';

}

function on_focus(el){
	//el.value='';
	//el.style.background= '#FDEFE5';
	el.className="evi";
	 
}
function on_outfocus(el){
	 
	el.className="fe";	
	 
}
function setTextinDiv(div,txt){
	div_ = document.getElementById(div);
	div_.innerHTML = txt;

	}
function setClass(id_,clas){
    el = document.getElementById(id_);
    el.className = clas;
}
function set_class(idel,clas){//,idlnk
	el = document.getElementById(idel);
	el.className = clas;
	//el = document.getElementById(idlnk);
	//el.className = 'black';
}


//-----------------------------------------------------------
function isDate(dateStr) {
// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.

// The function returns true if a valid date, false if not.
// ******************************************************************
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	var esito = true;
	
	if (matchArray == null) {
		//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		alert("Inserire la data nel formato gg/mm/aaaa or gg-mm-aaaa.");
		esito = false;
  }
	
	//nel formato mm/dd/yyyy:
		//month = matchArray[1]; // p@rse date into variables
		//day = matchArray[3];
	
	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		alert("Il mese deve essere compreso tra 1 e 12");
		esito = false;
	}
	
	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		alert("Il giorno deve essere compreso tra 1 e 31.");
		esito = false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn`t have 31 days!")
		alert("Il mese "+month+" non ha 31 giorni!")
		esito = false;
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			//alert("February " + year + " doesn`t have " + day + " days!");
			alert("Febbraio " + year + " non ha " + day + " giorni!");
			esito = false;
		}
	}
	
	return esito; // date is valid
}

	
	function selectAll()
	{
	  with (document.frm_rec) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox')
			   elements[i].checked = true;
		}
	  }
	}
	//-------------------------------------------------
	function deselectAll()
	{
	  with (document.frm_rec) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox')
			   elements[i].checked = 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];}
}

