//<SCRIPT language="javascript">

function addparam(nome,valore){

strparam   = document.frmmenu.strparam.value;
strparam   = strparam + "&" +nome +"="+valore;
document.frmmenu.strparam.value = strparam;

}

function setparam(nome,valore){

eval("document.frmmenu."+nome+".value = '"+valore+"';");

}
//s alert('common loaded');

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")
		{
		   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;      		
	       }    	
		}
		
		
	}
	
   }
   return res;
}
 

function write_email(testo,classe,stile){
  
  document.writeln('<a href=\"mailto:'+email+'\" class=\"'+classe+'\"  style=\"'+stile+'\" >'+testo+'</a>');
  }


//------------------------------------------------
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 go_ordini(id){
 
  document.frmmenu.sezione.value  = '200';
  addparam("search","1"); 
  addparam("searchstr",id);
 
document.frmmenu.submit();

}
//------------------------------------------------
function go2_(sez,mode){
 
  if(mode=='1') document.frmmenu.target="_blank";
  document.frmmenu.sezione.value  = sez;
  addparam("search",""); 
  addparam("npage","0");
  addparam("ord","");
document.frmmenu.submit();

}
//------------------------------------------------
function goextp_(sez,name){
 action = document.frmmenu.action;
 msid = document.frmmenu.MSID.value;
 open_page(action+'?frame=2&MSID='+msid+'&sz='+sez,name,700,480);

}
//------------------------------------------------
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 open_page(url,name,w,h)
//---------------------------
// apre l'immagine in una finestra popup l'immagine alle sue dimensioni originali
 {
   
   prop = "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h;
   MM_openBrWindow(url,name,prop);
 }



 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 login(){
wsusername = document.frmlogin.username.value;
wspassword = document.frmlogin.password.value;
strparam   = document.frmmenu.strparam.value;
strparam   = strparam + "&login=1&logsz=900&username="+wsusername+"&password="+wspassword;
document.frmmenu.strparam.value = strparam;
document.frmmenu.submit();
}

//-------------------------------------------------------------------------------
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 addbookmark(){
var bookmarkurl="http://wm"
var bookmarktitle=""

bookmark(bookmarkurl,bookmarktitle);
}

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
}
