/******************************************************************************************
*  FUNZIONI PER CANCELLARE MISURE E CODICI
*  Cè un problema e per fare veloce uso due parametri per gestire la riga
*  row arriva da html dinamico e l'oggetto chosenRow dalla tabella html
*  prevale quello dinamico 
*******************************************************************************************/

function eliminaRigaGalleria(chosenRow,table,row)
{
	 
	 //CANCELLA SOLO SU HTML
	 
	 var mainTable = document.getElementById(table);
	 
	 if(row !='')	 		 
	      chosenRow= document.getElementById(row);	      
	 
	 
	 mainTable.deleteRow(chosenRow.rowIndex);
	 
}



/******************************************************************************************
*  FUNZIONI PER PUBBLICARE DIRETTAMENTE UN PRODOTTO.
*******************************************************************************************/

 function	pubblica(table,index,IDSOG,PUBBLICA)
 {
  
		 	  var url = "pubblica.php";
		    var xmlhttp = FactoryXMLHttpRequest();
		     
		    var _IDSOG =IDSOG;
		    var _PUBBLICA=PUBBLICA;
		    var _INV_PUBBLICA = (PUBBLICA==0)?1:0;

        //NON METTIAMO APPOSTO NIENTE
        if(xmlhttp)
        {
            	
       	     try{
            	     	        	
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {                                                
		                         //document.getElementById('debug').innerHTML = xmlhttp.responseText;
		                         if(xmlhttp.responseText!="")
		                         {
		                         	 //index--;
		                         	 //alert(xmlhttp.responseText);
		                         	 //alert(index);
		                         	 //alert(document.getElementById(table).rows[index].cells[5].innerHTML);
		                         	 
                              var str = "<a href=\"javascript:pubblica('table_ricerca',"+index+",'"+ IDSOG+"','"+_INV_PUBBLICA+"')\">"+xmlhttp.responseText+"</a>";
		                         	 
		                           document.getElementById(table).rows[index].cells[5].innerHTML=str;	
		                         }                                                                          
                        }
                   }
                   
                   xmlhttp.send("IDSOG="+_IDSOG+"&PUBBLICA="+_PUBBLICA);

             }catch(E){alert("errore");} 
        } 
 }





/******************************************************************************************
*  FUNZIONI PER SPOSTARE LE RIGHE
*******************************************************************************************/

 function	save(POSIZIONE,IDSOG,IDCAT,IDCATSUB)
 {
  
		 	  var url = "updaterow.php";
		    var xmlhttp = FactoryXMLHttpRequest();
		     
		    var _IDSOG =IDSOG;
		    var _IDCAT=IDCAT;
		    var _IDCATSUB=IDCATSUB;
        var _POSIZIONE="";    

        //NON METTIAMO APPOSTO NIENTE
        if(xmlhttp)
        {
            	
       	     try{
            	     	        	
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {                                                
                         document.getElementById('debug').innerHTML = xmlhttp.responseText;                          
                        }
                   }
                          
                          
                   _POSIZIONE = document.getElementById(POSIZIONE).value;       
                          
                   //RIPASSO GLI HIDDEN FIELD                     
                   
                   xmlhttp.send("IDSOG="+_IDSOG+"&IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&POSIZIONE="+_POSIZIONE);

             }catch(E){alert("errore");} 
        } 
 }


/*****************************************************************************************************
* Setta la nuova posizione dell'elemento sul DB.
* In ogni caso sono sempre 2 gli elementi di cui cambiare la posizione
******************************************************************************************************/

 function	chagePositionDB(IDSOG,IDCAT,IDCATSUB,TYPE)
 {  	
		 	  var url = "updaterow.php";
		    var xmlhttp = FactoryXMLHttpRequest();
		     
		    var _IDSOG =IDSOG;
		    var _IDCAT=IDCAT;
		    var _IDCATSUB=IDCATSUB;
        var _TYPE=TYPE;    

        //NON METTIAMO APPOSTO NIENTE
        if(xmlhttp)
        {
            	
       	     try{
            	     	        	
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {                                                
                         document.getElementById('debug').innerHTML = xmlhttp.responseText;                          
                        }
                   }
                          
                   //RIPASSO GLI HIDDEN FIELD                     
                   xmlhttp.send("IDSOG="+_IDSOG+"&IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&TYPE="+_TYPE);

             }catch(E){} 
        } 
 }



/*******************************************************************************************
*  FUNZIONE PER GESTIRE ORDINAMENTO DELLE RIGHE NELLE TABELLE
*******************************************************************************************/
//SPOSTA SU
function swapRowUp(chosenRow,table,id,IDCAT,IDCATSUB) {
 		if (chosenRow.rowIndex != 0) {

 	    //INCREMENTO E DECREMENTO PRIMA DELLO SCAMBIO
 	 
 	    document.getElementById(table).rows[chosenRow.rowIndex-1].cells[0].childNodes[0].value++; //QUELLA PRECEDENTE   
 	    var id_inc = document.getElementById(table).rows[chosenRow.rowIndex-1].cells[0].childNodes[0].id; //POSIZIONE_key FORMATO
      id_inc = id_inc.substring(10, id_inc.length);
   
      document.getElementById(table).rows[chosenRow.rowIndex].cells[0].childNodes[0].value--; 

   		moveRow(chosenRow, chosenRow.rowIndex-1,table,'DEC');   		   		
   		chagePositionDB(id,IDCAT,IDCATSUB,'DEC');   		
   		chagePositionDB(id_inc,IDCAT,IDCATSUB,'INC');
 		}
}

//SPOSTA GIU
function swapRowDown(chosenRow,table,id,IDCAT,IDCATSUB) {
 var	mainTable = document.getElementById(table);
 if (chosenRow.rowIndex != (mainTable.rows.length-1)) {
 	
 	 //INCREMENTO E DECREMENTO PRIMA DELLO SCAMBIO
 	 document.getElementById(table).rows[chosenRow.rowIndex+1].cells[0].childNodes[0].value--; //QUELLA SUCCESSIVA
 	 var id_dec = document.getElementById(table).rows[chosenRow.rowIndex+1].cells[0].childNodes[0].id; //POSIZIONE_key FORMATO
 	 id_dec = id_dec.substring(10, id_dec.length);
 	 
 	 
   document.getElementById(table).rows[chosenRow.rowIndex].cells[0].childNodes[0].value++; 
                  
   moveRow(chosenRow, chosenRow.rowIndex+1,table,'INC');   
   chagePositionDB(id,IDCAT,IDCATSUB,'INC');
   chagePositionDB(id_dec,IDCAT,IDCATSUB,'DEC');
   
 }
}


//moves the target row object to the input row index
function moveRow(targetRow, newIndex,table,type) 
{
	//since we are not actually swapping
	//but simulating a swap, have to "skip over"
	//the current index
	 if (newIndex > targetRow.rowIndex) {
	   newIndex++;
	 }
	//establish proper reference to the table
	 var mainTable = document.getElementById(table);
	//insert a new row at the new row index
	 var theCopiedRow = mainTable.insertRow(newIndex);
	
	
	//copy all the cells from the row to move
	//into the new row
	 for (var i=0; i<targetRow.cells.length; i++) {
	   var oldCell = targetRow.cells[i];
	   var newCell = document.createElement("TD");
	   newCell.innerHTML = oldCell.innerHTML;
	   
	   theCopiedRow.appendChild(newCell);	   	   
	   
	   
	   copyChildNodeValues(targetRow.cells[i], newCell);
	   
	 }
//delete the old row
 mainTable.deleteRow(targetRow.rowIndex,table);

}


function copyChildNodeValues(sourceNode, targetNode) {
   for (var i=0; i < sourceNode.childNodes.length; i++) {
			   try
			   {   
			       targetNode.childNodes[i].value = sourceNode.childNodes[i].value;     
			   }
			   catch(e){}
   }
}



/*******************************************************************************************
*  FUNZIONE PER GESTIRE IL RITORNO/ASSEGNAMENTO DALLA GALLERIA
*******************************************************************************************/

function getUrl2(path)
{

  try{    
   path = path+'?IDSOG='+ document.getElementById("IDSOG").value;   
  }catch(E){
  	path = path+'IDSOG=';
  }

  try{    
   path = path+'&IDLNG='+ document.getElementById("IDLNG").value;   
  }catch(E){
  	path =path+'&IDLNG=';
  }
  

  try{    
   path = path+'&IDCAT='+ document.getElementById("IDCAT").value;   
  }catch(E){
  	path =path+'&IDCAT=';
  }

 try{    
   path = path+'&IDCATSUB='+ document.getElementById("IDCATSUB").value;   
  }catch(E){
  	path =path+'&IDCATSUB=';
  }

  try{    
   path = path+'&TYPE='+ document.getElementById("TYPE").value;   
  }catch(E){
  	path =path+'&TYPE=';
  }

return path;

}	


function getUrl(FIELD_TARGET){
	
  var path = 'gallery.php?' ;
  
  try{    
   path = path+'IDCATSUB='+ document.getElementById("IDCATSUB").value;   
  }catch(E){
  	path =path+'IDCATSUB=';
  }
  

  try{    
   path = path+'&IDCAT='+ document.getElementById("IDCAT").value;   
  }catch(E){
  	path =path+'&IDCAT=';
  }
  
  
  try{    
   path =path+ '&IDLNG='+ document.getElementById("IDLNG").value;   
  }catch(E){
  	path =path+'&IDLNG=';
  }
  
  try{    
   path = path+'&TYPE='+ document.getElementById("TYPE").value;   
  }catch(E){
  	path =path+'&TYPE=';
  }

  
  
  path=path+ '&FIELD_TARGET='+FIELD_TARGET ;   
  //alert(path);    
  return path;

}



/*******************************************************************************************
*  FUNZIONE PER GESTIRE IL RITORNO/ASSEGNAMENTO DALLA GALLERIA
*******************************************************************************************/



function setImage(field,_file)
{

  //SETTO LA FOTO
  
  var img = 'IMG_'+field;
  //alert(img);
  //alert(_file);
 
 
 
  document.getElementById(img).src=_file; 
  document.getElementById(img).style.width='100%';   	  
  document.getElementById(img).style.height='100%';

}	

function setFile(field,_file){	
 
  //SETTO IL FILE    
  
  document.getElementById(field).value=_file;
  
}

/********************************************************************************************
*             FUNZIONE PER TOGLIERE GLI SPAZI
*********************************************************************************************/

function trim(s) {
		var tmp = s.replace(/^[\s\u00A0]*/, '');
		return tmp;
}


/********************************************************************************************
* ALL'INTERNO DEL PANNELLO DI UPLOAD(gallery.php), TI PERMETTE DI NAVIGARE TUTTI I FOLDER E LE IMMAGINI
*********************************************************************************************/

function navigaGalleria(parameter)
{	
            var url = "loaddirectory.php";
            var xmlhttp = FactoryXMLHttpRequest();
             
            var indice_selezionato ="";
            var _IDCAT="";
            var _IDCATSUB="";
            var _FIELD_TARGET=""; 
             
            //NON METTIAMO APPOSTO NIENTE
            if(xmlhttp)
            {
            	
            	     try{
            	     
		                    indice_selezionato = document.getElementById('IDCAT').selectedIndex;
		                    _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;
		   
		   
		                    _FIELD_TARGET = document.getElementById('FIELD_TARGET').value;
		   
		                    if(_IDCAT == '')
		                    {
		                        alert("Selezionare una categoria");	
		                   	    return false;
		                    }   
   
                  }catch(E){alert("Selezionare una categoria");return false;} 


                  try{    
                    indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;                    
                    _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
                  }catch(E){
                    _IDCATSUB = document.getElementById('IDCATSUB').value;	
                  } 
            	
            	
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
                                                
                         document.getElementById('navigator').innerHTML = xmlhttp.responseText;                          
                        }
                   }
       
                   
                   //RIPASSO GLI HIDDEN FIELD 
                    
                   xmlhttp.send("FIELD_TARGET="+_FIELD_TARGET+"&FOLDER="+parameter+"&IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB);

             } 

	
}





/*******************************************************************************
* METODO GENERICO. CHIUDE QUALSIASI POPUP.
********************************************************************************/

function chiudi_popup()
{
  close();	
}


/*******************************************************************************
* Aggiunge una riga vuota alla tabella dei colori
********************************************************************************/

function aggiungiNuovoColore()
{

	var COUNT_PROGRES = document.getElementById('PROGRES').value;
	COUNT_PROGRES++;
	
  var tbl = document.getElementById('tableColori');
  var lastRow = 0;
  
  try{
     lastRow = tbl.rows.length;
  }catch(E)
  {
     lastRow =1; 
     // if there's no header row in the table, then iteration = lastRow + 1
  }  
  
  
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;

  var row = tbl.insertRow(lastRow);
  row.id="r_"+lastRow+"_"+COUNT_PROGRES;


  //CREO LA CELLA N.1
  var cell1 = row.insertCell(0);
  cell1.className = "tabella01";
  cell1.vAlign="top";
  cell1.align="center";  
  cell1.width="100";
  
  var elimg = document.createElement('img');
  elimg.border = '0';
  elimg.height = '18';
  elimg.width = '18';
  elimg.src='images/pulsante_su.gif';  
 
  var ellink_ = document.createElement('a');
  ellink_.href = 'javascript:su()';   
  ellink_.appendChild(elimg);
  cell1.appendChild(ellink_);
   
  var elimg2 = document.createElement('img');
  elimg2.border = '0';
  elimg2.height = '18';
  elimg2.width = '18';
  elimg2.src='images/pulsante_giu.gif';  
 
  var ellink__ = document.createElement('a');
  ellink__.href = 'javascript:giu()';   
  ellink__.appendChild(elimg2);
  cell1.appendChild(ellink__);

  //CREO LA CELLA N.2
  var cell2 = row.insertCell(1);
  cell2.className = "tabella01";
  cell2.vAlign="top";
  cell2.align="center";  
  cell2.width="100";
  
  var elimg2_ = document.createElement('img');
  elimg2_.border = '0';
  elimg2_.height = '18';
  elimg2_.width = '18';
  elimg2_.src='images/pulsante_elimina.gif';  
 

  var ellink___ = document.createElement('a');
  ellink___ .href = "javascript:eliminaRigaGalleria('','tableColori','"+row.id+"')";      
  ellink___.appendChild(elimg2_);
  cell2.appendChild(ellink___);

  //CREO LA CELLA N.3
  var cell3 = row.insertCell(2);
  cell3.className = "tabella01";
  cell3.vAlign="top";
  cell3.align="left";  
  cell3.width="500";

  var textNodef1 = document.createTextNode("Descrizione ");
  cell3.appendChild(textNodef1);

  var desc = document.createElement('input');  
  desc.type = 'text';
  desc.name = 'DESCRIZIONE_COLORENEW' + COUNT_PROGRES;
  desc.id = 'DESCRIZIONE_COLORENEW' + COUNT_PROGRES;  
  desc.value='';  
  desc.className='form';
  desc.size='42';
  cell3.appendChild(desc);

  var hid = document.createElement('input');  
  hid.type = 'hidden';
  hid.name = 'POSIZIONENEW' + COUNT_PROGRES;
  hid.id = 'POSIZIONENEW' + COUNT_PROGRES;  
  hid.value= COUNT_PROGRES;
  cell3.appendChild(hid);
  
  
  var hid2 = document.createElement('input');  
  hid2.type = 'hidden';
  hid2.name = 'IDCOLNEW' + COUNT_PROGRES;
  hid2.id = 'IDCOLNEW' + COUNT_PROGRES;    
  hid2.value= 0;
  cell3.appendChild(hid2);

  //AGGIUNGO LA SECONDA RIGA

  //var row_ = tbl.insertRow(lastRow+1);
  
  //CREO LA CELLA N.1
  //var cell1_ = row_.insertCell(0);
  //cell1_.className = "tabella01";
  //cell1_.vAlign="top";
  //cell1_.align="left";  
 
  cell3.appendChild(document.createElement("BR")); 
  cell3.appendChild(document.createElement("BR")); 

  
  var textNodef1_ = document.createTextNode("Codice ");
  cell3.appendChild(textNodef1_);
  
  var codice = document.createElement('input');  
  codice.type = 'text';
  codice.name = 'CODICE_COLORENEW' + COUNT_PROGRES;
  codice.id = 'CODICE_COLORENEW' + COUNT_PROGRES;  
  codice.value='';  
  codice.className='form';
  codice.size='46';
  cell3.appendChild(codice);

  document.getElementById('PROGRES').value=COUNT_PROGRES;
}



/*******************************************************************************
* Aggiunge una riga vuota alla tabella delle finiture
********************************************************************************/

function aggiungiNuovaFinitura()
{

	var COUNT_PROGRES = document.getElementById('PROGRES').value;
	COUNT_PROGRES++;
	
  var tbl = document.getElementById('tableFiniture');
  var lastRow = 0;
  
  try{
     lastRow = tbl.rows.length;
  }catch(E)
  {
     lastRow =1; 
     // if there's no header row in the table, then iteration = lastRow + 1
  }  
 
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  row.id="r_"+lastRow+"_"+COUNT_PROGRES;

  //CREO LA CELLA N.1
  var cell1 = row.insertCell(0);
  cell1.className = "tabella01";
  cell1.vAlign="top";
  cell1.align="center";  
  cell1.width="100";
  
  var elimg = document.createElement('img');
  elimg.border = '0';
  elimg.height = '18';
  elimg.width = '18';
  elimg.src='images/pulsante_su.gif';  
 
  var ellink_ = document.createElement('a');
  ellink_.href = 'javascript:su()';   
  ellink_.appendChild(elimg);
  cell1.appendChild(ellink_);
 
 
 
   
  var elimg2 = document.createElement('img');
  elimg2.border = '0';
  elimg2.height = '18';
  elimg2.width = '18';
  elimg2.src='images/pulsante_giu.gif';  
 
  var ellink__ = document.createElement('a');
  ellink__.href = 'javascript:giu()';   
  ellink__.appendChild(elimg2);
  cell1.appendChild(ellink__);



  //CREO LA CELLA N.2
  var cell2 = row.insertCell(1);
  cell2.className = "tabella01";
  cell2.vAlign="top";
  cell2.align="center";  
  cell2.width="100";

  var elimg2_ = document.createElement('img');
  elimg2_.border = '0';
  elimg2_.height = '18';
  elimg2_.width = '18';
  elimg2_.src='images/pulsante_elimina.gif';  
 
 
 
 
  var ellink___ = document.createElement('a');
  ellink___ .href = "javascript:eliminaRigaGalleria('','tableFiniture','"+row.id+"')";   
  ellink___.appendChild(elimg2_);
  cell2.appendChild(ellink___);

  //CREO LA CELLA N.3
  var cell3 = row.insertCell(2);
  cell3.className = "tabella01";
  cell3.vAlign="top";
  cell3.align="left";  
  cell3.width="500";

  var textNodef1 = document.createTextNode("Descrizione ");
  cell3.appendChild(textNodef1);

  var desc = document.createElement('input');  
  desc.type = 'text';
  desc.name = 'DESCRIZIONE_FINITURANEW' + COUNT_PROGRES;
  desc.id = 'DESCRIZIONE_FINITURANEW' + COUNT_PROGRES;  
  desc.value='';  
  desc.className='form';
  desc.size='42';
  cell3.appendChild(desc);

  var hid = document.createElement('input');  
  hid.type = 'hidden';
  hid.name = 'POSIZIONENEW' + COUNT_PROGRES;
  hid.id = 'POSIZIONENEW' + COUNT_PROGRES;  
  hid.value= COUNT_PROGRES;
  cell3.appendChild(hid);

  var hid2 = document.createElement('input');  
  hid2.type = 'hidden';
  hid2.name = 'IDFINNEW'+ COUNT_PROGRES;
  hid2.id = 'IDFINNEW'+ COUNT_PROGRES;  
  hid2.value= 0;
  cell3.appendChild(hid2);

  //AGGIUNGO LA SECONDA RIGA

  //var row_ = tbl.insertRow(lastRow+1);
 
 
  //CREO LA CELLA N.1
  //var cell1_ = row_.insertCell(0);
  //cell1_.className = "tabella01";
  //cell1_.vAlign="top";
  //cell1_.align="left";  
  
  cell3.appendChild(document.createElement("BR")); 
  cell3.appendChild(document.createElement("BR")); 
  
  var textNodef1_ = document.createTextNode("Codice ");
  cell3.appendChild(textNodef1_);
  
  var codice = document.createElement('input');  
  codice.type = 'text';
  codice.name = 'CODICE_FINITURANEW' + COUNT_PROGRES;
  codice.id = 'CODICE_FINITURANEW' + COUNT_PROGRES;  
  codice.value='';  
  codice.className='form';
  codice.size='46';
  cell3.appendChild(codice);
 
 document.getElementById('PROGRES').value=COUNT_PROGRES;
}


/*******************************************************************************
* Aggiunge una riga vuota alla tabella misura e codici
********************************************************************************/

function aggiungiNuovoMisura(){

	var COUNT_PROGRES = document.getElementById('PROGRES').value;
	COUNT_PROGRES++;
	
  var tbl = document.getElementById('misureCodice');
  var lastRow = 0;
  
  try{
     lastRow = tbl.rows.length;
  }catch(E)
  {
     lastRow =1; 
     // if there's no header row in the table, then iteration = lastRow + 1
  }   
  
  
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  row.id="r_"+lastRow+"_"+COUNT_PROGRES;
    
  //CREO LA CELLA N.1
  var cell1 = row.insertCell(0);
  cell1.className = "tabella02";
  cell1.vAlign="top";
  cell1.align="left";  
  
  //CREO UN ELEMENTO HIDDEN PER TUTTI GLI IDGAL DELLA GALLERIA
  
  var hid = document.createElement('input');  
  hid.type = 'hidden';
  hid.name = 'IDMISNEW' + COUNT_PROGRES;
  hid.id = 'IDMISNEW' + COUNT_PROGRES;  
  hid.value="0"
  cell1.appendChild(hid);
  
  
  var hid2 = document.createElement('input');  
  hid2.type = 'hidden';
  hid2.name = 'POSIZIONENEW' + COUNT_PROGRES;
  hid2.id = 'POSIZIONENEW' + COUNT_PROGRES;  
  hid2.value= COUNT_PROGRES;
  cell1.appendChild(hid2);
  
  
  var foto = document.createElement('img');
  foto.border=0;
  foto.id='IMG_FOTONEW' + COUNT_PROGRES;
  foto.name='IMG_FOTONEW' + COUNT_PROGRES;
  foto.src='images/trasparente.gif';  
  foto.alt="Galleria";
  
  cell1.appendChild(foto);
  
  //CREO LA CELLA N.2
  var cell2 = row.insertCell(1);
  cell2.className = "tabella01";  
  cell2.vAlign="top";
  cell2.align="center";  
   
  var elimg = document.createElement('img');
  elimg.border = '0';
  elimg.height = '18';
  elimg.width = '18';
  elimg.src='images/pulsante_su.gif';  
 
 
  var ellink_ = document.createElement('a');
  ellink_.href = 'javascript:su()';   
  ellink_.appendChild(elimg);
  cell2.appendChild(ellink_);
 
  
  var elimg2 = document.createElement('img');
  elimg2.border = '0';
  elimg2.height = '18';
  elimg2.width = '18';
  elimg2.src='images/pulsante_giu.gif';  
 
 
  var ellink__ = document.createElement('a');
  ellink__.href = 'javascript:giu()';   
  ellink__.appendChild(elimg2);
  cell2.appendChild(ellink__);
  
  
  
  
   
  //CREO LA CELLA N.3
  var cell3 = row.insertCell(2);
  cell3.className = "tabella01";  
  cell3.vAlign="top";
  cell3.align="center";  
  
  
  var elimg1 = document.createElement('img');
  elimg1.border = '0';
  elimg1.height = '18';
  elimg1.width = '18';
  elimg1.src='images/pulsante_elimina.gif';    
  
  
  var ellink = document.createElement('a');
  ellink.href = "javascript:eliminaRigaGalleria('','misureCodice','"+row.id+"')";  
  ellink.appendChild(elimg1);
  cell3.appendChild(ellink);
  
 
  
  //CREO LA CELLA N.4
  var cell4 = row.insertCell(3);
  cell4.className = "tabella01";  
  var textNodef1 = document.createTextNode("File");  
  cell4.appendChild(textNodef1);
  cell4.align="left";  
  
  cell4.appendChild(document.createElement("BR")); 
  
  var el = document.createElement('input');
  el.type = 'text';
  el.className = "form";  
  el.name = 'FOTONEW' + COUNT_PROGRES;
  el.id = 'FOTONEW' + COUNT_PROGRES;
  el.size = 48;
  cell4.appendChild(el);
    
  var textNode4 = document.createTextNode(" ");
  cell4.appendChild(textNode4);  
  
  var el2 = document.createElement('input');  
  el2.type = 'button';
  el2.value = "GALLERIA FOTO";
  el2.onclick=_openpopup;
   
  el2.id = 'FOTONEW' + COUNT_PROGRES;
  el2.className = 'form';
  el2.name = 'FOTONEW' + COUNT_PROGRES;  
  cell4.appendChild(el2);
	  
  cell4.appendChild(document.createElement("BR"));
  cell4.appendChild(document.createElement("BR"));  
    
  var textNodef1_ = document.createTextNode("Codice");
  cell4.appendChild(textNodef1_);
    
  var codice = document.createElement('input');  
  codice.type = 'text';
  codice.name = 'CODISOGGNEW' + COUNT_PROGRES;
  codice.id = 'CODISOGGNEW' + COUNT_PROGRES;  
  codice.value='';  
  codice.className='form';
  codice.size='48';
  cell4.appendChild(codice);
	
	cell4.appendChild(document.createElement("BR")); 
	
	document.getElementById('PROGRES').value=COUNT_PROGRES;
	
}



//NON USARE DEPRECAT0
/*******************************************************************************
* Eliminaa una riga dalla tabella della galleria
********************************************************************************/


/*
function eliminaRigaGalleria(row){
	var tbl = document.getElementById('tblSample');
	var lastRow = row;
	tbl.deleteRow(row);
	
}
*/

/*******************************************************************************
* Aggiunge una riga vuota alla tabella della galleria
********************************************************************************/


function aggiungiNuovoGalleria()
{
		
		
	var COUNT_PROGRES = document.getElementById('PROGRES').value;
	COUNT_PROGRES++;
	
  var tbl = document.getElementById('altreFoto');
  var lastRow = 0;
  // if there's no header row in the table, then iteration = lastRow + 1
 
   try{
     lastRow = tbl.rows.length;
  }catch(E)
  {
     lastRow =1; 
     // if there's no header row in the table, then iteration = lastRow + 1
  }   
 
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  row.id="r_"+lastRow+"_"+COUNT_PROGRES;
     
  //CREO LA CELLA N.1
  var cell1 = row.insertCell(0);
  cell1.className = "tabella02";
  cell1.vAlign="top";
  cell1.align="left";  
  
  //CREO UN ELEMENTO HIDDEN PER TUTTI GLI IDGAL DELLA GALLERIA
  
  var hid = document.createElement('input');  
  hid.type = 'hidden';
  hid.name = 'IDGALNEW' + COUNT_PROGRES;
  hid.id = 'IDGALNEW' + COUNT_PROGRES;  
  hid.value="0"
  cell1.appendChild(hid);
  
  
  var hid2 = document.createElement('input');  
  hid2.type = 'hidden';
  hid2.name = 'POSIZIONENEW' + COUNT_PROGRES;
  hid2.id = 'POSIZIONENEW' + COUNT_PROGRES;  
  hid2.value= COUNT_PROGRES;
  cell1.appendChild(hid2);
  
  
  var foto = document.createElement('img');
  foto.border=0;
  foto.id='IMG_FOTONEW' + COUNT_PROGRES;
  foto.name='IMG_FOTONEW' + COUNT_PROGRES;
  foto.src='images/trasparente.gif';  
  foto.alt="Galleria";
  
  cell1.appendChild(foto);
  
  //CREO LA CELLA N.2
  var cell2 = row.insertCell(1);
  cell2.className = "tabella01";  
  cell2.vAlign="top";
  cell2.align="center";  
   
  var elimg = document.createElement('img');
  elimg.border = '0';
  elimg.height = '18';
  elimg.width = '18';
  elimg.src='images/pulsante_su.gif';  
 
 
  var ellink_ = document.createElement('a');
  ellink_.href = 'javascript:su()';   
  ellink_.appendChild(elimg);
  cell2.appendChild(ellink_);
 
  
  var elimg2 = document.createElement('img');
  elimg2.border = '0';
  elimg2.height = '18';
  elimg2.width = '18';
  elimg2.src='images/pulsante_giu.gif';  
 
 
  var ellink__ = document.createElement('a');
  ellink__.href = 'javascript:giu()';   
  ellink__.appendChild(elimg2);
  cell2.appendChild(ellink__);
  
  
  
  
   
  //CREO LA CELLA N.3
  var cell3 = row.insertCell(2);
  cell3.className = "tabella01";  
  cell3.vAlign="top";
  cell3.align="center";  
  
  var elimg1 = document.createElement('img');
  elimg1.border = '0';
  elimg1.height = '18';
  elimg1.width = '18';
  elimg1.src='images/pulsante_elimina.gif';    
  
  var ellink = document.createElement('a');
  ellink.href = "javascript:eliminaRigaGalleria('','altreFoto','"+row.id+"')";   
  ellink.appendChild(elimg1);   
  cell3.appendChild(ellink);
  
  //CREO LA CELLA N.4
  var cell4 = row.insertCell(3);
  cell4.className = "tabella01";  
  var textNodef1 = document.createTextNode("File");
  cell4.appendChild(textNodef1);
  cell4.align="left";  
  
  var el = document.createElement('input');
  el.type = 'text';
  el.className = "form";  
  el.name = 'FOTONEW' + COUNT_PROGRES;
  el.id = 'FOTONEW' + COUNT_PROGRES;
  el.size = 48;
  cell4.appendChild(el);
    
  var textNode4 = document.createTextNode(" ");
  cell4.appendChild(textNode4);  
  
  var el2 = document.createElement('input');  
  el2.type = 'button';
  el2.value = "GALLERIA FOTO";
  el2.onclick=_openpopup;
   
  el2.id = 'FOTONEW' + COUNT_PROGRES;
  el2.className = 'form';
  el2.name = 'FOTONEW' + COUNT_PROGRES;  
  cell4.appendChild(el2);
	
	
	//AGGIUNGO LA SECONDA RIGA DI ZOOM

  //var row_ = tbl.insertRow(lastRow+1);
 
  //CREO LA CELLA N.1
  //var cell1_ = row_.insertCell(0);
  //cell1_.className = "tabella01";
  //cell1_.vAlign="top";
  //cell1_.align="left";  
  
  cell4.appendChild(document.createElement("BR")); 
  cell4.appendChild(document.createElement("BR")); 
  
  var textNodef1_ = document.createTextNode("Zoom");
  cell4.appendChild(textNodef1_);
    
  var codice = document.createElement('input');  
  codice.type = 'text';
  codice.name = 'ZOOMNEW' + COUNT_PROGRES;
  codice.id = 'ZOOMNEW' + COUNT_PROGRES;  
  codice.value='';  
  codice.className='form';
  codice.size='48';
  cell4.appendChild(codice);


  var textNode44 = document.createTextNode(" ");
  cell4.appendChild(textNode44);
  
  var el22 = document.createElement('input');
  el22.type = 'button';
  el22.value = "GALLERIA ZOOM";
  el22.onclick=_openpopup;
   
  el22.id = 'ZOOMNEW' + COUNT_PROGRES;
  el22.className = 'form';
  el22.name = 'ZOOMNEW' + COUNT_PROGRES;
  cell4.appendChild(el22);

	
	document.getElementById('PROGRES').value=COUNT_PROGRES;
	
}


/********************************************************
*  Compatibilita Cinzia
*********************************************************/
function MM_openBrWindow(theURL,winName,features) {
	
  mypopup = window.open(theURL,winName,features);
  mypopup.opener = this;
}


function _openpopup()
{
	
  var name= this.id;
	//var IDCAT = document.getElementById('IDCAT').value;	
	//var IDLNG = document.getElementById('IDLNG').value;

	var theURL = getUrl(name);
	//alert(theURL);
	var winName='Galleriafotografica';
	var features= 'scrollbars=yes,resizable=yes,width=780,height=500';
	
	MM_openBrWindow(theURL,winName,features);
	
}

/******************************************************************************
* Cancella un prodotto del tool con IDSOG uguale a parameter
*******************************************************************************/


   function modifica(parameter){
      
      var url = "dettaglio.php";
      var xmlhttp = FactoryXMLHttpRequest();
             
       if(xmlhttp)
       {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {

                         
                         document.getElementById('header').style.display='none';   
                         document.getElementById('header').innerHTML="";
                         
                         document.getElementById('result').style.display='none';                            
                         document.getElementById('result').innerHTML="";
                  	       
                         document.getElementById('footer').style.display='none';                            
                         document.getElementById('footer').innerHTML="";
                  	       
                  	       
                  	     document.getElementById('detail').style.display="block";
                         document.getElementById('detail').innerHTML = xmlhttp.responseText;                          
                    }
             }
                          
             var indice_selezionato = document.getElementById('IDCAT').selectedIndex;
             var _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;

             indice_selezionato = document.getElementById('IDLNG').selectedIndex;
             var _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;

             //IDCATSUB potrebbe essere una combo oppure un text field hidden
             var _IDCATSUB="";

             try{ 
      
                    if(document.getElementById('IDCATSUB').selectedIndex == undefined)
                    {
                      //NON ESISTE LA SOTTO CATEGORIA
                      _IDCATSUB = document.getElementById('IDCATSUB').value;     
                    }
                    else
                    {
                      //ESISTE LA SOTTO CATEGORIA

                      indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;
                      _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
   
                    }

            }catch(e){}

            var _CODISOGG= document.getElementById('CODISOGG').value;

            var _TEXT= document.getElementById('TEXT').value;
                          
            var _NOMSOG= document.getElementById('NOMSOG').value;

            xmlhttp.send("IDLNG="+_IDLNG+"&IDSOG="+parameter+"&R_IDCAT="+_IDCAT+"&R_IDCATSUB="+_IDCATSUB+"&R_IDLNG="+_IDLNG+"&R_CODISOGG="+_CODISOGG+"&R_TEXT="+_TEXT+"&R_NOMSOG="+_NOMSOG);
              

        }

    }

/******************************************************************************
* Inserisce un nuovo prodotto
*******************************************************************************/

    function nuovo(){
       var url = "dettaglio.php";
       var xmlhttp = FactoryXMLHttpRequest();
       
       if(xmlhttp)
       {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {

                         document.getElementById('header').innerHTML="";
                         document.getElementById('header').style.display='none';   
                         
                         document.getElementById('result').innerHTML="";
                         document.getElementById('result').style.display='none';   
                         
                         document.getElementById('footer').style.display='none';                            
                         document.getElementById('footer').innerHTML="";
                         
                         document.getElementById('detail').style.display="block";
                         document.getElementById('detail').innerHTML = xmlhttp.responseText;                          
                    }
             }
                          
             var indice_selezionato = document.getElementById('IDCAT').selectedIndex;
             var _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;

             indice_selezionato = document.getElementById('IDLNG').selectedIndex;
             var _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;

             //IDCATSUB potrebbe essere una combo oppure un text field hidden
             var _IDCATSUB="";

             try{ 
      
                    if(document.getElementById('IDCATSUB').selectedIndex == undefined)
                    {
                      //NON ESISTE LA SOTTO CATEGORIA
                      _IDCATSUB = document.getElementById('IDCATSUB').value;     
                    }
                    else
                    {
                      //ESISTE LA SOTTO CATEGORIA

                      indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;
                      _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
   
                    }

            }catch(e){}

            var _CODISOGG= document.getElementById('CODISOGG').value;

            var _TEXT= document.getElementById('TEXT').value;
                          
            var _NOMSOG= document.getElementById('NOMSOG').value;

            xmlhttp.send("IDSOG=&R_IDCAT="+_IDCAT+"&R_IDCATSUB="+_IDCATSUB+"&R_IDLNG="+_IDLNG+"&R_CODISOGG="+_CODISOGG+"&R_TEXT="+_TEXT+"&R_NOMSOG="+_NOMSOG);              

        }

    }


/******************************************************************************
* Ricerca Sito
*******************************************************************************/


function openSchedaDettaglio(key,IDLNG, IDCAT, IDCATSUB)
{
	
    	 var _file ='';
	
	     if(IDLNG == '2'){	
				       if(IDCAT == 'DIVANI' && IDCATSUB == 'HERITAGE' ) _file= 'http://www.verim-homecollection.com/prodotti/divani/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'DIVANI' && IDCATSUB == 'DESIGN' ) _file= 'http://www.verim-homecollection.com/prodotti/divani/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       
				       if(IDCAT == 'POLTRONE' && IDCATSUB == 'HERITAGE' ) _file= 'http://www.verim-homecollection.com/prodotti/poltrone/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'POLTRONE' && IDCATSUB == 'DESIGN' ) _file= 'http://www.verim-homecollection.com/prodotti/poltrone/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				  
				       if(IDCAT == 'TAVOLI' && IDCATSUB == 'HERITAGE' ) _file= 'http://www.verim-homecollection.com/prodotti/tavoli/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TAVOLI' && IDCATSUB == 'DESIGN' ) _file= 'http://www.verim-homecollection.com/prodotti/tavoli/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       
				       if(IDCAT == 'SEDIE' && IDCATSUB == 'HERITAGE' ) _file= 'http://www.verim-homecollection.com/prodotti/sedie/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'SEDIE' && IDCATSUB == 'DESIGN' ) _file= 'http://www.verim-homecollection.com/prodotti/sedie/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				
				       if(IDCAT == 'COMPLEMENTI' && IDCATSUB == 'HERITAGE' ) _file= 'http://www.verim-homecollection.com/prodotti/complementi/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'COMPLEMENTI' && IDCATSUB == 'DESIGN' ) _file= 'http://www.verim-homecollection.com/prodotti/complementi/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       				     				       
				       if(IDCAT == 'LAMPADE' && IDCATSUB == 'TAVOLO' ) _file= 'http://www.verim-homecollection.com/prodotti/lampade/tavolo_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'LAMPADE' && IDCATSUB == 'TERRA' ) _file= 'http://www.verim-homecollection.com/prodotti/lampade/terra_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;				
				       if(IDCAT == 'LAMPADE' && IDCATSUB == 'PARETE' ) _file= 'http://www.verim-homecollection.com/prodotti/lampade/parete_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'LAMPADE' && IDCATSUB == 'SOSPENSIONE' ) _file= 'http://www.verim-homecollection.com/prodotti/lampade/sospensione_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				
		   	       if(IDCAT == 'LETTI' && IDCATSUB == 'HERITAGE')          _file= 'http://www.verim-homecollection.com/prodotti/letti/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
               if(IDCAT == 'LETTI' && IDCATSUB == 'DESIGN')            _file= 'http://www.verim-homecollection.com/prodotti/letti/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;      	       
						
				       if(IDCAT == 'TAPPETI') _file= 'http://www.verim-homecollection.com/prodotti/tappeti/tappeti_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'CUSCINI')        _file= 'http://www.verim-homecollection.com/prodotti/tessile/cuscini_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'LENZUOLA')       _file= 'http://www.verim-homecollection.com/prodotti/tessile/lenzuola_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'PIUMONI')        _file= 'http://www.verim-homecollection.com/prodotti/tessile/piumoni_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'PLAID')          _file= 'http://www.verim-homecollection.com/prodotti/tessile/plaid_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'SPUGNE')         _file= 'http://www.verim-homecollection.com/prodotti/tessile/spugne_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;				       
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'TOVAGLIE')       _file= 'http://www.verim-homecollection.com/prodotti/tessile/tovaglie_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;				       
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'TRAPUNTE')       _file= 'http://www.verim-homecollection.com/prodotti/tessile/trapunte_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       if(IDCAT == 'TESSILE' && IDCATSUB == 'HERITAGE LINEN') _file= 'http://www.verim-homecollection.com/prodotti/tessile/homediffusion_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				       
       }
       else if(IDLNG == '1')
       {
       
              if(IDCAT == 'ARMCHAIRS' && IDCATSUB == 'HERITAGE')     _file= 'http://www.verim-homecollection.com/en/prodotti/poltrone/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
              if(IDCAT == 'ARMCHAIRS' && IDCATSUB == 'DESIGN')       _file= 'http://www.verim-homecollection.com/en/prodotti/poltrone/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
       	      if(IDCAT == 'BEDS' && IDCATSUB == 'HERITAGE')          _file= 'http://www.verim-homecollection.com/en/prodotti/letti/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
              if(IDCAT == 'BEDS' && IDCATSUB == 'DESIGN')            _file= 'http://www.verim-homecollection.com/en/prodotti/letti/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;      	       
			       	if(IDCAT == 'CHAIRS' && IDCATSUB == 'HERITAGE')        _file= 'http://www.verim-homecollection.com/en/prodotti/sedie/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'CHAIRS' && IDCATSUB == 'DESIGN')          _file= 'http://www.verim-homecollection.com/en/prodotti/sedie/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;			       	
			       	if(IDCAT == 'COMPLEMENTS' && IDCATSUB == 'HERITAGE')   _file= 'http://www.verim-homecollection.com/en/prodotti/complementi/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'COMPLEMENTS' && IDCATSUB == 'DESIGN')		 _file= 'http://www.verim-homecollection.com/en/prodotti/complementi/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;	       	
			       	if(IDCAT == 'LIGHTING' && IDCATSUB == 'CHANDELIERS')   _file= 'http://www.verim-homecollection.com/en/prodotti/lampade/sospensione_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'LIGHTING' && IDCATSUB == 'FLOOR LAMPS')   _file= 'http://www.verim-homecollection.com/en/prodotti/lampade/terra_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'LIGHTING' && IDCATSUB == 'TABLE LAMPS')   _file= 'http://www.verim-homecollection.com/en/prodotti/lampade/tavolo_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'LIGHTING' && IDCATSUB == 'WALL LAMPS')    _file= 'http://www.verim-homecollection.com/en/prodotti/lampade/parete_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
	            if(IDCAT == 'RUGS')                                    _file= 'http://www.verim-homecollection.com/en/prodotti/tappeti/tappeti_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			       	if(IDCAT == 'SOFAS' && IDCATSUB == 'HERITAGE')         _file= 'http://www.verim-homecollection.com/en/prodotti/divani/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
			        if(IDCAT == 'SOFAS' && IDCATSUB == 'DESIGN')           _file= 'http://www.verim-homecollection.com/en/prodotti/divani/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;	
		          if(IDCAT == 'TABLES' && IDCATSUB == 'HERITAGE')        _file= 'http://www.verim-homecollection.com/en/prodotti/tavoli/heritage_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TABLES' && IDCATSUB == 'DESIGN')          _file= 'http://www.verim-homecollection.com/en/prodotti/tavoli/design_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
					       	
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'CUSHIONS')         _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/cuscini_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'BED SHEET SETS')   _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/lenzuola_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'DUVETS')           _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/piumoni_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'THROWS')           _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/plaid_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'BATH LINENS')         _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/spugne_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;				       
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'TABLE CLOTHS')       _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/tovaglie_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;				       
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'COMFORTERS')       _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/trapunte_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
				      if(IDCAT == 'TEXTILE ACCESSORIES' && IDCATSUB == 'HERITAGE LINEN') _file= 'http://www.verim-homecollection.com/en/prodotti/tessile/homediffusion_scheda.php?IDLNG='+IDLNG+'&IDSOG='+key;
       
             	
       }
              
      location.href= _file;
}


/******************************************************************************
* Ricerca Sito
*******************************************************************************/

function cercaAncoraSito(){

      //document.getElementById('header').innerHTML = "";
      document.getElementById('header').style.display="block";
      
      document.getElementById('result').innerHTML = "";
	    document.getElementById('result').style.display="none";
	
	    document.getElementById('footer').style.display='none';                            
      document.getElementById('footer').innerHTML="";
	
}

    function ricercaSito(parameter){

       var url = "/Tool/ricercaSito.php";
       var xmlhttp = FactoryXMLHttpRequest();
       if(xmlhttp)
       {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
 
                         //document.getElementById('header').innerHTML = "";                          
                         document.getElementById('header').style.display="none";
                         
                         //document.getElementById('footer').style.display='none';                            
                         //document.getElementById('footer').innerHTML="";
                         
                         document.getElementById('result').style.display="block";
                         document.getElementById('result').innerHTML = xmlhttp.responseText;
                    }
             }

             //NON SEMPRE ESISTONO LE COMBO, POTREBBERO ESSERE DEGLI HIDDEN

             //if(parameter == null || parameter=='' )
             //{ 
             
      		             var indice_selezionato="";
		             var _IDCAT="";
		             var _IDLNG="";
		             var _IDCATSUB="";
		             var _CODISOGG="";
		             var _TEXT="";
		             var _NOMSOG="";
		
		
		
		             try{ 
		
		                    if(document.getElementById('IDCAT').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDCAT = document.getElementById('IDCAT').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                      indice_selezionato = document.getElementById('IDCAT').selectedIndex;
		                      _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;
		   
		                    }
		
		             }catch(e){}   
		
		
		             //IDLNG potrebbe essere una combo oppure un text field hidden
		
		             try{ 
		
		                    if(document.getElementById('IDLNG').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDLNG = document.getElementById('IDLNG').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                       indice_selezionato = document.getElementById('IDLNG').selectedIndex;
		                       _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;
		   
		                    }
		
		             }catch(e){}   
		
		
		             //IDCATSUB potrebbe essere una combo oppure un text field hidden
		
		
		             try{ 
		      
		                    if(document.getElementById('IDCATSUB').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDCATSUB = document.getElementById('IDCATSUB').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                      indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;
		                      _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
		   
		                    }
		
		            }catch(e){}
		
		             _CODISOGG= document.getElementById('CODISOGG').value;
		
		             _TEXT= document.getElementById('TEXT').value;
		                          
		             _NOMSOG= document.getElementById('NOMSOG').value;
		                            
		                           
		             xmlhttp.send("pag="+parameter+"&IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&IDLNG="+_IDLNG+"&CODISOGG="+_CODISOGG+"&TEXT="+_TEXT+"&NOMSOG="+_NOMSOG);
          //        }
          //        else
          //        {
          //                   xmlhttp.send(parameter);
          //
          //        } 
 
        }
    }    

/******************************************************************************
* Ricerca 
*******************************************************************************/

    function ricerca(parameter){

       var url = "ricerca.php";
       var xmlhttp = FactoryXMLHttpRequest();
       if(xmlhttp)
       {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
 
                         document.getElementById('result').style.display="block";  
                         document.getElementById('result').innerHTML="";
                         
                         document.getElementById('result').innerHTML = xmlhttp.responseText;                          
                    }
             }

             //NON SEMPRE ESISTONO LE COMBO, POTREBBERO ESSERE DEGLI HIDDEN

             if(parameter == null || parameter=='' )
             { 
             
      		             var indice_selezionato="";
		             var _IDCAT="";
		             var _IDLNG="";
		             var _IDCATSUB="";
		             var _CODISOGG="";
		             var _TEXT="";
		             var _NOMSOG="";
		
		
		
		             try{ 
		
		                    if(document.getElementById('IDCAT').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDCAT = document.getElementById('IDCAT').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                      indice_selezionato = document.getElementById('IDCAT').selectedIndex;
		                      _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;
		   
		                    }
		
		             }catch(e){}   
		
		
		             //IDLNG potrebbe essere una combo oppure un text field hidden
		
		             try{ 
		
		                    if(document.getElementById('IDLNG').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDLNG = document.getElementById('IDLNG').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                       indice_selezionato = document.getElementById('IDLNG').selectedIndex;
		                       _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;
		   
		                    }
		
		             }catch(e){}   
		
		
		             //IDCATSUB potrebbe essere una combo oppure un text field hidden
		
		
		             try{ 
		      
		                    if(document.getElementById('IDCATSUB').selectedIndex == undefined)
		                    {
		                      //NON ESISTE LA SOTTO CATEGORIA
		                      _IDCATSUB = document.getElementById('IDCATSUB').value;     
		                    }
		                    else
		                    {
		                      //ESISTE LA SOTTO CATEGORIA
		
		                      indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;
		                      _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
		   
		                    }
		
		            }catch(e){}
		
		             _CODISOGG= document.getElementById('CODISOGG').value;
		
		             _TEXT= document.getElementById('TEXT').value;
		                          
		             _NOMSOG= document.getElementById('NOMSOG').value;
		                            
		             xmlhttp.send("IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&IDLNG="+_IDLNG+"&CODISOGG="+_CODISOGG+"&TEXT="+_TEXT+"&NOMSOG="+_NOMSOG);
                  }
                  else
                  {
                             xmlhttp.send(parameter);

                  } 
 
        }
    }    

/******************************************************************************
* Visualizza il secondo campo di codice
*******************************************************************************/
function aggingiCodice(){
	 
	 if(document.getElementById("codice2").className == "hide")
	 {	 
	    eval('document.getElementById("codice2").className="show"');
	    
	 }   
	 else if(document.getElementById("codice3").className == "hide")
	 {	 
	    eval('document.getElementById("codice3").className="show"');
   }
	 else if(document.getElementById("codice4").className == "hide")
	 {	 
	    eval('document.getElementById("codice4").className="show"');
   }
	else if(document.getElementById("codice5").className == "hide")
	{	 
	    eval('document.getElementById("codice5").className="show"');
	} 
	else if(document.getElementById("codice6").className == "hide")
	{	 
	    eval('document.getElementById("codice6").className="show"');
	} 
	 
	 
	  
}

function eliminaCodice(fieldname)
{
	
  	if(fieldname == "codice2")
	  {	 
	     eval('document.getElementById("codice2").className="hide"');
	     eval('document.getElementById("CODISOGG2").value=""');
	    	    
	  }   
	 else if(fieldname == "codice3")
	 {	 
	    eval('document.getElementById("codice3").className="hide"');
	    eval('document.getElementById("CODISOGG3").value=""');
   }
	 else if(fieldname == "codice4")
	 {	 
	    eval('document.getElementById("codice4").className="hide"');
	    eval('document.getElementById("CODISOGG4").value=""');
   }
	else if(fieldname == "codice5")
	{	 
	    eval('document.getElementById("codice5").className="hide"');
	    eval('document.getElementById("CODISOGG5").value=""');
	}
	else if(fieldname == "codice6")
	{	 
	    eval('document.getElementById("codice6").className="hide"');
	    eval('document.getElementById("CODISOGG6").value=""');
	}

}

/******************************************************************************
* Inserisce la data di pubblicazione
*******************************************************************************/

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}

function insertDate(fieldCheck,fieldText){

       if(!document.getElementById(fieldCheck).checked)
       {
          document.getElementById(fieldText).value = ''; 
          return;
       }  
 
       var today = new Date();
       var Year = takeYear(today);
       var Month = leadingZero(today.getMonth()+1);
       var Day = leadingZero(today.getDate());
       var Hours = leadingZero(today.getHours());
       var Minutes = leadingZero(today.getMinutes());
       var Seconds = leadingZero(today.getSeconds());

       document.getElementById(fieldText).value = Year +'-' + Month + '-' +Day+ ' '+ Hours + ':' + Minutes + ':' + Seconds ; 
 
       return; 
}

/******************************************************************************
* Inserisce l'immagine nel campo foto del dettaglio
*******************************************************************************/

  function  cambiaLinguaRicerca(){

            var url = "categorie.php";
            var xmlhttp = FactoryXMLHttpRequest();
             
            //NON METTIAMO APPOSTO NIENTE
            if(xmlhttp)
            {
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {

                         
                         

                         document.getElementById('categorie').innerHTML = xmlhttp.responseText;                          
                        }
                   }
       
                   var indice_selezionato = document.getElementById('IDCAT').selectedIndex;
                   var _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;

                   var _IDSOG = "";

                   indice_selezionato = document.getElementById('IDLNG').selectedIndex;
                   var _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;

                   //RIPASSO GLI HIDDEN FIELD 
                    




                   xmlhttp.send("IDSOG="+_IDSOG+"&IDCAT="+_IDCAT+"&IDLNG="+_IDLNG);

             } 

  }

function categorieSito(parameter,_IDLNG){
                                       
            var url = "/Tool/categorieSito.php";
            var xmlhttp = FactoryXMLHttpRequest();
             
            if(xmlhttp)
            {
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
                                                 
                            document.getElementById('categorie').innerHTML = xmlhttp.responseText;                          
                        }
                   }
       
                  if(parameter == '')
                  {                    
                    xmlhttp.send("&IDLNG="+_IDLNG);
                  }
                  else
                  {
                    xmlhttp.send(parameter+"&IDLNG="+_IDLNG);
                  } 

            }        
  }


function categorie(parameter){
                                       
            var url = "categorie.php";
            var xmlhttp = FactoryXMLHttpRequest();
             
            if(xmlhttp)
            {
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
                           try{                      
                            document.getElementById('categorie').innerHTML = xmlhttp.responseText;                          
                           }catch(E){} 
                        }
                   }
       
                  if(parameter == '')
                  {                    
                    xmlhttp.send(null);
                  }
                  else
                  {
                    xmlhttp.send(parameter);
                  } 

            }        
  }

function  cambiaLingua(){
     var agree = confirm("Attenzione! I dati non ancora salvati verranno persi");

     if (agree)
     {

            var url = "dettaglio.php";
            var xmlhttp = FactoryXMLHttpRequest();
             
            if(xmlhttp)
            {
                   xmlhttp.open("POST", url);
                   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                   xmlhttp.onreadystatechange = function()
                   {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {

                        
                         document.getElementById('header').style.display='none';   
                         document.getElementById('header').innerHTML='';   
                         
                         document.getElementById('result').style.display='none';   
                         document.getElementById('result').innerHTML=''; 
                                                                          
                         document.getElementById('detail').style.display = "block";
                         document.getElementById('detail').innerHTML = xmlhttp.responseText;
                         
                         document.getElementById('footer').style.display='none';                            
                         document.getElementById('footer').innerHTML="";
                         
                         
                        }
                   }
       
                   var indice_selezionato = document.getElementById('IDCAT').selectedIndex;
                   var _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;

                   var _IDSOG = document.getElementById('IDSOG').value;

                   indice_selezionato = document.getElementById('IDLNG').selectedIndex;
                   var _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;

                   var _R_IDCAT = document.getElementById('R_IDCAT').value;
                   var _R_IDCATSUB = document.getElementById('R_IDCATSUB').value;
                   var _R_IDLNG = document.getElementById('R_IDLNG').value;
                   var _R_CODISOGG = document.getElementById('R_CODISOGG').value;
                   var _R_TEXT = document.getElementById('R_TEXT').value;
                   var _R_NOMSOG = document.getElementById('R_NOMSOG').value;

                   xmlhttp.send("IDSOG="+_IDSOG+"&IDCAT="+_IDCAT+"&IDLNG="+_IDLNG+"&R_IDCAT="+_R_IDCAT+"&R_IDCATSUB="+_R_IDCATSUB+"&R_IDLNG="+_R_IDLNG+"&R_CODISOGG="+_R_CODISOGG+"&R_TEXT="+_R_TEXT+"&R_NOMSOG="+_R_NOMSOG);
            }        
 
     }	 
     else
     {

	
      //RIMETTO TUTTO APPOSTO 
       if(document.getElementById("IDLNG").options[document.getElementById("IDLNG").selectedIndex].value == 1){
        //RIMETTO L'INGLESE 
        document.getElementById("IDLNG").options[1].selected = true;
       }
       else
       {
         //RIMETTO L'ITALIANO
         document.getElementById("IDLNG").options[0].selected = true;
       }
     }    
  }


/******************************************************************************
* chiude la finestra di dettaglio e ritorna alla finestra di ricerca 
*******************************************************************************/
 function openGallery(parameter){
             
     mypopup = window.open('gallery.php?type='+parameter,'upload','width=800,height=600');    
     mypopup.opener = this;
}

/******************************************************************************
* Ordna le colonne della tabella di ricerca in base al parameter: nome della 
* colonne
*******************************************************************************/
   function ordina(parameter){return true;}


/******************************************************************************
* Cancella un prodotto del tool con IDSOG uguale a parameter
*******************************************************************************/

   function _delete(parameter){
    
        var agree = confirm("Attenzione! Vuoi veramente cancellare la scheda prodotto?");

        if (agree)
        {

             var url = "deleteProdotto.php";
             var xmlhttp = FactoryXMLHttpRequest();
       
             if(xmlhttp)
             {
                xmlhttp.open("POST", url);
                xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                       ricerca(''); 
                    }
                }

                xmlhttp.send("IDSOG="+parameter);
             }
       }
       else
       {
          return false;  
       }
      
  }
  
/******************************************************************************
* Alimenta la combo sotto categorie
*******************************************************************************/

   function sottoCategoriaSito()
   {
      var url = "/Tool/sottoCategoria.php";
      var xmlhttp = FactoryXMLHttpRequest();
      var _IDCAT="";
      var _IDLNG="";
      
      if(xmlhttp)
      {
      
         xmlhttp.open("POST", url);
         xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');       

          
         xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {
                         document.getElementById('livello2').innerHTML="";
                         document.getElementById('livello2').innerHTML = xmlhttp.responseText;
                 }
          }



           _IDCAT= document.getElementById('IDCAT').value;           
           _IDLNG= document.getElementById('IDLNG').value;           
         
         xmlhttp.send('IDCAT='+_IDCAT+'&IDLNG='+_IDLNG);
 
      }
      
    }



   function sottoCategoria(parameter)
   {
      var url = "sottoCategoria.php";
      var xmlhttp = FactoryXMLHttpRequest();
      var _IDCAT="";
      var _IDCATSUB="";
      var _IDLNG="";
      
      if(xmlhttp)
      {
      
         xmlhttp.open("POST", url);
         xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');       

          
         xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {
                         try{
                         document.getElementById('livello2').innerHTML="";
                         document.getElementById('livello2').innerHTML = xmlhttp.responseText;
                         }catch(E){}  
                 }
          }

         if(parameter=='')
         {
		         try
		         {
           _IDCAT= document.getElementById('IDCAT').value;           
           _IDLNG= document.getElementById('IDLNG').value;           
		         	 _IDCATSUB= document.getElementById('IDCATSUB').value;
		         }
		         catch(E)
		         {           
		           _IDCATSUB="";                      
		         }
		         xmlhttp.send('IDCAT='+_IDCAT+'&IDLNG='+_IDLNG+'&IDCATSUB='+_IDCATSUB);
        }         
        else
        {
           xmlhttp.send(parameter);
        }
      }
      
    }


/******************************************************************************
* Procedura di caricamento dell' login 
*******************************************************************************/

   function displayLogin(parameter)
   {
   	   	  
      var xmlhttp = FactoryXMLHttpRequest();
      if(xmlhttp)
      {                
          xmlhttp.open('POST','login.php');
          xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');       
          
          xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {                 	                 	       
                 	       document.getElementById('login').style.display = "block";                 	       
                         document.getElementById('login').innerHTML = xmlhttp.responseText;
                         
                 }
          }
        
         xmlhttp.send(parameter);
      }
    }


/******************************************************************************
* Procedura di caricamento dell' header 
*******************************************************************************/

   function header(parameter)
   {
   	   	  
      var xmlhttp = FactoryXMLHttpRequest();
      if(xmlhttp)
      {
                
          xmlhttp.open('POST','header.php');
          xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
          
          xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {
                 	
                 	       //alert(document.getElementById('header'));
                 	       document.getElementById('header').style.display = "block";
                 	       
                         document.getElementById('header').innerHTML = xmlhttp.responseText;
                         categorie(parameter);
                         sottoCategoria(parameter);
                 }
          }
        
         xmlhttp.send(parameter);
      }
    }


/******************************************************************************
* Procedura di caricamento del footer
*******************************************************************************/

   function footer(parameter)
   {
   	   	  
      var xmlhttp = FactoryXMLHttpRequest();
      if(xmlhttp)
      {
                
          xmlhttp.open('POST','footer.php',true);
          
          xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {
                 	
                 	       //alert(document.getElementById('header'));
                 	       document.getElementById('footer').style.display = "block";
                 	       
                         document.getElementById('footer').innerHTML = xmlhttp.responseText;
                         
                 }
          }
        
         xmlhttp.send(parameter);
      }
    }


/******************************************************************************
* Chiude il dettaglio ripristinando i parametri di ricerca e spingendo la
* pagina a rifare la ricerca posizionandosi sull'oggetto selezionato in
* precedenza
*******************************************************************************/
   function chiudi_dettaglio(){


      var xmlhttp = FactoryXMLHttpRequest();
      if(xmlhttp)
      {
          //PULISCO LA SESSIONE DEL DETTAGLIO      
          xmlhttp.open('POST','closedettaglio.php',true);
          
          xmlhttp.onreadystatechange = function()
          {
                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                 {                 	       
                         //document.getElementById('header').innerHTML = xmlhttp.responseText;                
                 }
          }
        
         xmlhttp.send(null);
     }
 
     var _CODISOGG= document.getElementById('R_CODISOGG').value;
     var _TEXT= document.getElementById('R_TEXT').value;                          
     var _NOMSOG= document.getElementById('R_NOMSOG').value;
     var _IDLNG = document.getElementById('R_IDLNG').value;     
     var _IDCAT = document.getElementById('R_IDCAT').value;     
     var _IDCATSUB = document.getElementById('R_IDCATSUB').value;     

     var parameter= "IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&IDLNG="+_IDLNG+"&CODISOGG="+_CODISOGG+"&TEXT="+_TEXT+"&NOMSOG="+_NOMSOG;

     //INIT TEMPLATE
     document.getElementById('result').innerHTML = "";
     document.getElementById('result').style.display = "block";
    
     document.getElementById('detail').style.display = "none";
     document.getElementById('detail').innerHTML = "";

     header(parameter); 
     ricerca(parameter);
     footer(parameter); 

   }

/******************************************************************************
* salva i dati nella maschera di popup di altre foto
* raccolgo i dati e li mando al file php il quale se esiste IDSOG
* lo salva sul db altrimenti lo mette in sessione
*******************************************************************************/


function salva_altrefoto(){
	
     var url = "update_altrefoto.php";
     var xmlhttp = FactoryXMLHttpRequest();
     var _IDSOG="";

     if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                           //NON RESTITUISCE NIENTE E FA INSERT UPDATE                          
                           // document.getElementById('debug').innerHTML = xmlhttp.responseText;
						   chiudi_popup();
                    }
             }

           _IDSOG=document.getElementById('IDSOG').value;
 
 
 
          var items = document.getElementsByTagName("input");             
          var fields = "";
          var cont=0;
          
          for(var x=0; x< items.length; x++)
          {          	          	
          	if((items[x].name).indexOf('FOTO')!= -1 && trim(items[x].value) != '' && items[x].value != 'GALLERIA FOTO')
          	{          		
          		fields+="&"+items[x].name+"="+items[x].value;
          	
          		cont++;          		          		
          	}
           	else if((items[x].name).indexOf('POSIZIONE')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}

          	else if((items[x].name).indexOf('ZOOM')!= -1 && trim(items[x].value) != '' && items[x].value != 'GALLERIA ZOOM')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}         


          	else if((items[x].name).indexOf('IDGAL')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}         
          }

            //alert("IDSOG="+_IDSOG+fields);
          	xmlhttp.send("IDSOG="+_IDSOG+fields);
         	       
     }
     //chiudi_popup(); 
	
}

/******************************************************************************
* salva i dati nella maschera di dettaglio
*******************************************************************************/

function salva_dettaglio(){

     var url = "update.php";
     var xmlhttp = FactoryXMLHttpRequest();

     var indice_selezionato="";
     var _IDCAT="";
     var _IDLNG="";     
     var _IDCATSUB="";
     var _CODISOGG="";
     var _CODISOGG2="";
     var _CODISOGG3="";
     var _CODISOGG4="";
     var _CODISOGG5="";
     var _CODISOGG6="";
     
     var _DESCRIZIONE="";
     var _NOMSOG="";
     var _IDSOG="";

     var _PUBBLICA="";
     var _DATAPUBBLICAZIONE="";

     var _SCHEDAPDF="";
     var _FOTO="";
     var _FOTOZOOM="";
     var _AMBIENTATA="";
     var _FOTOABBINARE="";
     var _FOTOHOMESEZIONE="";
     
     if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                           //NON RESTITUISCE NIENTE E FA INSERT UPDATE
                          //document.getElementById('debug').innerHTML = xmlhttp.responseText;
                    }
             }

             try{

                indice_selezionato = document.getElementById('IDCAT').selectedIndex;
                _IDCAT = document.getElementById('IDCAT').options[indice_selezionato].value;
		
             }catch(e){alert("Attenzione! Campo Categoria Obbligatorio.");return false;} 


                indice_selezionato = document.getElementById('IDLNG').selectedIndex;
                _IDLNG = document.getElementById('IDLNG').options[indice_selezionato].value;
	
             try{	
                indice_selezionato = document.getElementById('IDCATSUB').selectedIndex;
                _IDCATSUB = document.getElementById('IDCATSUB').options[indice_selezionato].value;
             }catch(e){_IDCATSUB=""; } 

             try{	
	             _CODISOGG= document.getElementById('CODISOGG').value;
             }catch(e){alert("Attenzione! Campo Codice prodotto Obbligatorio.");return false;} 

             try{	
	              _CODISOGG2= document.getElementById('CODISOGG2').value;
             }catch(e){} 

             try{	
	              _CODISOGG3= document.getElementById('CODISOGG3').value;
             }catch(e){} 

             try{	
	              _CODISOGG4= document.getElementById('CODISOGG4').value;
             }catch(e){} 

             try{	
	              _CODISOGG5= document.getElementById('CODISOGG5').value;
             }catch(e){} 

             try{	
	              _CODISOGG6= document.getElementById('CODISOGG6').value;
             }catch(e){} 


             _DESCRIZIONE= document.getElementById('DESCRIZIONE').value;
             
             try{
               _NOMSOG= document.getElementById('NOMSOG').value;
             }catch(e){alert("Attenzione! Campo Nome prodotto Obbligatorio.");return false;}                 

             _IDSOG=document.getElementById('IDSOG').value;

             
             if(document.getElementById('PUBBLICA').checked)
             {
               _PUBBLICA = 1;
               _DATAPUBBLICAZIONE=   document.getElementById('DATAPUBBLICAZIONE').value;
             }
                      

             try{	
			            _SCHEDAPDF       = document.getElementById('SCHEDAPDF').value;
						      _FOTO            = document.getElementById('FOTO').value;
						      _FOTOZOOM        = document.getElementById('FOTOZOOM').value;
						      _AMBIENTATA      = document.getElementById('AMBIENTATA').value;
						      _FOTOABBINARE    = document.getElementById('FOTOABBINARE').value;
						      _FOTOHOMESEZIONE = document.getElementById('FOTOHOMESEZIONE').value;
            }catch(E){}  
                                                                                                               
            xmlhttp.send("DATAPUBBLICAZIONE="+_DATAPUBBLICAZIONE+"&PUBBLICA="+_PUBBLICA+"&IDSOG="+_IDSOG+"&IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&IDLNG="+_IDLNG+"&CODISOGG="+_CODISOGG+"&CODISOGG2="+_CODISOGG2+"&CODISOGG3="+_CODISOGG3+"&CODISOGG4="+_CODISOGG4+"&CODISOGG5="+_CODISOGG5+"&CODISOGG6="+_CODISOGG6+"&DESCRIZIONE="+_DESCRIZIONE+"&NOMSOG="+_NOMSOG+"&SCHEDAPDF="+_SCHEDAPDF+"&FOTO="+_FOTO+"&FOTOZOOM="+_FOTOZOOM+"&AMBIENTATA="+_AMBIENTATA+"&FOTOABBINARE="+_FOTOABBINARE+"&FOTOHOMESEZIONE="+_FOTOHOMESEZIONE);
     } 




     var _CODISOGG= document.getElementById('R_CODISOGG').value;
     var _TEXT= document.getElementById('R_TEXT').value;                          
     var _NOMSOG= document.getElementById('R_NOMSOG').value;
     var _IDLNG = document.getElementById('R_IDLNG').value;     
     var _IDCAT = document.getElementById('R_IDCAT').value;     
     var _IDCATSUB = document.getElementById('R_IDCATSUB').value;     

     var parameter= "IDCAT="+_IDCAT+"&IDCATSUB="+_IDCATSUB+"&IDLNG="+_IDLNG+"&CODISOGG="+_CODISOGG+"&TEXT="+_TEXT+"&NOMSOG="+_NOMSOG;

     //INIT TEMPLATE
     document.getElementById('result').innerHTML = "";
     document.getElementById('result').style.display = "block";
     
     document.getElementById('detail').style.display = "none";
     document.getElementById('detail').innerHTML = "";
     
     
     

     header(parameter);
     ricerca(parameter);  
     footer(parameter);  

}

/******************************************************************************
* salva i dati nella maschera misure
*******************************************************************************/


function salva_misura(){

		 var url = "update_misure.php";
     var xmlhttp = FactoryXMLHttpRequest();

	   if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                           //NON RESTITUISCE NIENTE E FA INSERT UPDATE
                          //document.getElementById('debug').innerHTML = xmlhttp.responseText;
						  chiudi_popup();
                    }
             }


          var _IDSOG = document.getElementById('IDSOG').value;           
          var _IDLNG = document.getElementById('IDLNG').value; 


          var items = document.getElementsByTagName("input");             
          var fields = "";
          var cont=0;
          
          for(var x=0; x< items.length; x++)
          {          	          	
          	
		          	if((items[x].name).indexOf('FOTO')!= -1 && trim(items[x].value) != '' && items[x].value != 'GALLERIA FOTO')
		          	{          		
		          		fields+="&"+items[x].name+"="+items[x].value;
		          	
		          		cont++;          		          		
		          	}
		
		          	if((items[x].name).indexOf('CODISOGG')!= -1 && trim(items[x].value) != '')
		          	{          		
		          		fields+="&"+items[x].name+"="+items[x].value;
		          		cont++;          		          		
		          	}
		          	
		          	else if((items[x].name).indexOf('POSIZIONE')!= -1 && trim(items[x].value) != '')
		          	{
		          		fields+="&"+items[x].name+"="+items[x].value;
		          		cont++;          		          		          	
		          	}
		          	else if((items[x].name).indexOf('IDMIS')!= -1 && trim(items[x].value) != '')
		          	{
		          		fields+="&"+items[x].name+"="+items[x].value;
		          		cont++;          		          		          	
		          	}                    	         
          }
                           
 
          	xmlhttp.send("IDLNG="+_IDLNG+"&IDSOG="+_IDSOG+fields);

     } 
     
     

	
}


/******************************************************************************
* salva i dati nella maschera delle finiture
*******************************************************************************/

function salva_finiture(){
	
		 var url = "update_finiture.php";
     var xmlhttp = FactoryXMLHttpRequest();

	   if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                           //NON RESTITUISCE NIENTE E FA INSERT UPDATE
                          //document.getElementById('debug').innerHTML = xmlhttp.responseText;
                          chiudi_popup();
                    }
             }


          var _IDSOG = document.getElementById('IDSOG').value;           
          var _IDLNG = document.getElementById('IDLNG').value; 


          var items = document.getElementsByTagName("input");             
          var fields = "";
          var cont=0;
          
          for(var x=0; x< items.length; x++)
          {          	          	
          	if((items[x].name).indexOf('DESCRIZIONE_FINITURA')!= -1 && trim(items[x].value) != '')
          	{          		
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		
          	}
          	else if((items[x].name).indexOf('CODICE_FINITURA')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}
          	else if((items[x].name).indexOf('POSIZIONE')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}
          	else if((items[x].name).indexOf('IDFIN')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}
          	
          	         
          }
                           
 
          	xmlhttp.send("IDLNG="+_IDLNG+"&IDSOG="+_IDSOG+fields);

     } 
     
     
	
}



/******************************************************************************
* salva i dati nella maschera dei colori
*******************************************************************************/

function salva_colori(){
	
		 var url = "update_colori.php";
     var xmlhttp = FactoryXMLHttpRequest();

	   if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                           //NON RESTITUISCE NIENTE E FA INSERT UPDATE
                           document.getElementById('debug').innerHTML = xmlhttp.responseText;
						   chiudi_popup();
                    }
             }


          var _IDSOG = document.getElementById('IDSOG').value;           
          var _IDLNG = document.getElementById('IDLNG').value; 
                               
          //alert(_IDSOG+" "+_IDLNG);                     
	        var items = document.getElementsByTagName("input");             
          var fields = "";
          var cont=0;
          
          for(var x=0; x< items.length; x++)
          {          	          	
          	if((items[x].name).indexOf('DESCRIZIONE_COLORE')!= -1 && trim(items[x].value) != '')
          	{          		
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		
          	}
          	else if((items[x].name).indexOf('CODICE_COLORE')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}         
          	else if((items[x].name).indexOf('POSIZIONE')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}          	

          	else if((items[x].name).indexOf('IDCOL')!= -1 && trim(items[x].value) != '')
          	{
          		fields+="&"+items[x].name+"="+items[x].value;
          		cont++;          		          		          	
          	}

          }
                           
          //if(cont > 0)
          //{
 
          	xmlhttp.send("IDLNG="+_IDLNG+"&IDSOG="+_IDSOG+fields);
          //}
          //else
          //{
          //  xmlhttp.send(null); 	
          //}

     } 
     
    // chiudi_popup();
	
}




function chiudi_abbinamenti()
{
	chiudi_popup();
}

/******************************************************************************
* salva i dati nella maschera degli abbinamenti
*******************************************************************************/

function salva_abbinamenti()
{
	
	
	   var url = "update_abbinamenti.php";
     var xmlhttp = FactoryXMLHttpRequest();

	   if(xmlhttp)
     {
             xmlhttp.open("POST", url);
             xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                          //NON RESTITUISCE NIENTE E FA INSERT UPDATE
                          //document.getElementById('debug').innerHTML = xmlhttp.responseText;
                    }
             }


            var _IDSOG = document.getElementById('IDSOG').value;           
            var _IDABB1 = document.getElementById('IDABB1').value;
            var _IDABB2 = document.getElementById('IDABB2').value;
            var _IDABB3 = document.getElementById('IDABB3').value;
            
            var _POSIZIONE_IDABB1 = document.getElementById('POSIZIONE_IDABB1').value;
            var _POSIZIONE_IDABB2 = document.getElementById('POSIZIONE_IDABB2').value;
            var _POSIZIONE_IDABB3 = document.getElementById('POSIZIONE_IDABB3').value;
           
           
           

	          xmlhttp.send("IDSOG="+_IDSOG+"&IDABB1="+_IDABB1+"&IDABB2="+_IDABB2+"&IDABB3="+_IDABB3+"&POSIZIONE_IDABB3="+_POSIZIONE_IDABB3+"&POSIZIONE_IDABB2="+_POSIZIONE_IDABB2+"&POSIZIONE_IDABB1="+_POSIZIONE_IDABB1);
     } 
     //chiudi_abbinamenti();
}	


function logIn()
{
	   
     var xmlhttp = FactoryXMLHttpRequest();

     var url = "testLogin.php";
     var _USER = document.getElementById('USER').value;           
     var _PASSWORD = document.getElementById('PASSWORD').value;
     var _IDLNG = document.getElementById('IDLNG').value;
     var parameter = "IDLNG="+_IDLNG;   

	   if(xmlhttp)
     {
              xmlhttp.open("POST", url);
              xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
             
             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                          //NON RESTITUISCE NIENTE E FA TEST SE ESISTE L'UTENTE IN SESSIONE
                        
                        var risp =xmlhttp.responseText;                                                
                        var myArray = risp.split("/\n/");
                        
                        for ( i = 0 ; i < myArray.length ; i ++ )
                        {
                        				if ( myArray[i].match('OK'))
                        				{               
                        					              					
                                  	     header(parameter);     
		                                     footer('');
                                  
                                  return true;
                                  	
                        				}					
                        }                                                         
                    }
             }

	          xmlhttp.send("USER="+_USER+"&PASSWORD="+_PASSWORD+"&IDLNG="+_IDLNG);
     } 

}

/******************************************************************************
* Esce dall'area riservata chiudendo la sessione
*******************************************************************************/


function esci()
{
     
     var xmlhttp = FactoryXMLHttpRequest();

     var url = "esci.php";

	   if(xmlhttp)
     {
              xmlhttp.open("POST", url);
              xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
             
             xmlhttp.onreadystatechange = function()
             {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                          //NON RESTITUISCE NIENTE E FA TEST SE ESISTE L'UTENTE IN SESSIONE
                                  
                                  
                         document.getElementById('result').style.display='none';                            
                         document.getElementById('result').innerHTML="";
                  	                         	                         	       
                  	     document.getElementById('detail').style.display="none";
                         document.getElementById('detail').innerHTML = xmlhttp.responseText;      
                                                                                                          			
                         header('');     
		                     footer('');
                                 
                    }
             }

	          xmlhttp.send(null);
     }          
}


/******************************************************************************
* Procedura di inizializzazione della pagina di default
*******************************************************************************/

   function init(){
   	
   	     //testLogin();   	    	
		     header('');     
		     footer('');
		 	    
   }
