
// Conferma eliminazione
function conferma_elimina() 
{
var is_confirmed = confirm('Confermi l\'eliminazione ?');
return is_confirmed;
}

function conferma_elimina_en() 
{
var is_confirmed = confirm('Confirm deletion?');
return is_confirmed;
}
// Conferma sicura
function conferma_sicura(theform) 
{

 	var email_string =/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	var string_1_60=/^[\.|\s|a-zA-Z_0-9]{1,60}$/;


		check_it=string_1_60.test(theform.cognome.value);
		if (!check_it) 
		{
		   alert('Il cognome non e\' valido');
		   return false;	
		 }

		check_it=string_1_60.test(theform.nome.value);
		if (!check_it) 
		{
		   alert('Il nome non e\' valido');
		   return false;	
		 }

		check_it=string_1_60.test(theform.citta.value);
		if (!check_it) 
		{
		   alert('La citta non e\' valida');
		   return false;	
		 }

		check_it=string_1_60.test(theform.indirizzo.value);
		if (!check_it) 
		{
		   alert('L\'indirizzo non e\' valido');
		   return false;	
		 
		 }
		check_it=string_1_60.test(theform.stato.value);
		if (!check_it) 
		{
		   alert('Stato non valido');
		   return false;	
		 }

		check_it=email_string.test(theform.email.value);
		if (!check_it) 
		{
		   alert('L\'email non ha un formato valido');
		   return false;	
		}

var is_confirmed = confirm('Scegliendo "OK" la connessione verra\' inoltrata al server abilitato alle transazioni finanziarie mediante connessione sicura.\nSi desidera continuare? Se si, non premere il tasto back del browser durante l\'operazione');

return is_confirmed;
}


function conferma_sicura_en(theform) 
{

 	var email_string =/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 

	var string_1_60=/^[\.|\s|a-zA-Z_0-9]{1,60}$/;

		check_it=string_1_60.test(theform.cognome.value);
		if (!check_it) 
		{
		   alert('Insert last name');
		   return false;	
		 }

		check_it=string_1_60.test(theform.nome.value);
		if (!check_it) 
		{
		   alert('Insert first name');
		   return false;	
		 }

		check_it=string_1_60.test(theform.citta.value);
		if (!check_it) 
		{
		   alert('Insert city');
		   return false;	
		 }

		check_it=string_1_60.test(theform.indirizzo.value);
		if (!check_it) 
		{
		   alert('Insert address');
		   return false;	
		 
		 }
		check_it=string_1_60.test(theform.stato.value);
		if (!check_it) 
		{
		   alert('Insert country');
		   return false;	
		 }

		check_it=email_string.test(theform.email.value);
		if (!check_it) 
		{
		   alert('Check email!');
		   return false;	
		}

var is_confirmed = confirm('Proceed to checkout using secure server? If you proceed do NOT press stop button or reload button in your browser');


return is_confirmed;
}









// Controllo input   gioiello
function checkinput(theForm) {

  var prezzo =       /^\d{0,6}(\.\d{0,2})?$/ ;
  var peso =         /^\d{0,5}(\.\d{0,2})?$/ ;
  var descrizione =   /[A-Za-z0-9_\.]/ ;

  var testprezzo =prezzo.test(theForm.prezzo.value);
  var testpeso   =peso.test(theForm.peso.value);
  var testdescrizione= descrizione.test(theForm.descrizione.value)
  
  if (! testdescrizione) {
  alert ("Immettere una descrizione contenente solo caratteri alfanumerici");
  theForm.descrizione.focus();
  return false;
  }
  
  if (! testprezzo) {
    alert ("Immettere un prezzo valido");
    theForm.prezzo.focus();
    return false;
  }
  
  if (! testpeso) {
    alert ("Immettere un peso valido");
    theForm.peso.focus();
    return false;
  }

  return true;
}



// Anteprima
function anteprima(id,form)
  {
    //alert ('Verra\' aperta una nuova finestra con l\'anteprima dell\'immagine');
    contents="";
    contents+="<html>\n";
    contents+="<head>\n";
    contents+="<title>\n";
    contents+="Anteprima gioiello - Codice = " + id;
    contents+="\n</title>\n";
    //contents+="<script type=\"text/javascript\" language=\"javascript\">\n";
    //contents+="</script>\n";
    //contents+="<LINK REL=\"stylesheet\" HREF=\".\\css\farruggio.css\\">\n";
    contents+="</head>\n";
    contents+="<body bgcolor=#dddddd>";
    contents+=   "<center><img border=1 title =\"Anteprima\" alt = \"Non disponibile\"src =\"./img/";
    contents+= id ;
    contents+= ".jpg\"></center>\n<br>\n";
    contents+="<center><H4><a href=\"javascript:self.close();\">chiudi anteprima</a></H4>";
    popup=window.open('', 'Window1', 'scrollbars,resizable,height=600,width=600');
    popup.document.writeln(contents);

return true;
}

function anteprima_web(id,form)
  {
    //alert ('Verra\' aperta una nuova finestra con l\'anteprima dell\'immagine');
    contents="";
    contents+="<html>\n";
    contents+="<head>\n";
    contents+="<title>\n";
    contents+="Anteprima gioiello - Codice = " + id;
    contents+="\n</title>\n";
    //contents+="<script type=\"text/javascript\" language=\"javascript\">\n";
    //contents+="</script>\n";
    //contents+="<LINK REL=\"stylesheet\" HREF=\".\\css\farruggio.css\\">\n";
    contents+="</head>\n";
    contents+="<body bgcolor=#000000 link=#cccccc>";

    contents+=   "<br><br><br><br>";
    contents+=   "<center><img border=1 title =\"Anteprima\" alt = \"Non disponibile\"src =\"./img/";
    contents+= id ;
    contents+= ".jpg\"></center>\n<br>\n";
    contents+="<center><H4><a href=\"javascript:self.close();\">chiudi anteprima</a></H4>";
    //popup=window.open('', 'Window1', 'scrollbars,resizable,height=800,width=800');
    popup=window.open('', 'Window1', 'scrollbars,resizable,fullscreen=yes');
    popup.document.writeln(contents);

return true;
}

 
function status_bar() {
  this.status="Farruggio Design";
  return true;
}
 

function check_input(theForm) 
// FUNZIONE GENERALE PER CHECK INPUT
{
	// Espressioni regolari comunemente usate
	var string_1_30=/^[\.|\s|a-zA-Z_0-9]{1,30}$/;
	var string_0_30=/^[\.|\s|a-zA-Z_0-9]{0,30}$/;
	var string_0_5=/^[\.|\s|a-zA-Z_0-9]{0,5}$/;
	var string_1_5=/^[\.|\s|a-zA-Z_0-9]{1,5}$/;
	var string_4_10=/^[\.|\s|a-zA-Z_0-9]{4,10}$/;
	var string_6_10=/^[\.|\s|a-zA-Z_0-9]{6,10}$/;
	var dec_6_2 = /^\d{0,6}(\.\d{0,2})?$/ ;
	var dec_5_2 = /^\d{0,5}(\.\d{0,2})?$/ ;
	var check_it;
 	var email_string =/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 

	// Quale form sto controllando ?
	input_form=theForm.form_name.value;	

	//alert("Form name is : " + input_form);

	switch (input_form) 
	{

		// Edit rivenditore 
	   case 'riv_edit':
   	nome=theForm.nome.value;
   	cognome=theForm.cognome.value;
   	email=theForm.email.value;

		check_it=string_1_30.test(cognome);
		if (!check_it) 
		{
		   alert('Il cognome non e\' valido');
		   return false;	
		 }

		check_it=string_1_30.test(nome);
		if (!check_it) 
		{
		   alert('Il nome non e\' valido');
		   return false;	
		 }


		check_it=email_string.test(email);
		if (!check_it) 
		{
		   alert('L\'email non ha un formato valido');
		   return false;	
		}

		return true;
		break;



		// Nuovo rivenditore 
	   case 'riv_new':
   	nome=theForm.nome.value;
   	cognome=theForm.cognome.value;
   	login=theForm.login.value;
   	password=theForm.password.value;
   	email=theForm.email.value;

		check_it=string_1_30.test(cognome);
		if (!check_it) 
		{
		   alert('Il cognome non e\' valido');
		   return false;	
		 }

		check_it=string_1_30.test(nome);
		if (!check_it) 
		{
		   alert('Il nome non e\' valido');
		   return false;	
		 }

		check_it=string_4_10.test(login);
		if (!check_it) 
		{
		   alert('L\'user-id deve essere almeno 4 caratteri');
		   return false;	
		 }
 
		check_it=string_4_10.test(password);
		if (!check_it) 
		{
		   alert('La password  deve essere almeno 4 caratteri');
		   return false;	
		}


		check_it=email_string.test(email);
		if (!check_it) 
		{
		   alert('L\'email non ha un formato valido');
		   return false;	
		}

		return true;
		break;

		// Nuova categoria 
		case 'insertcategoria':
   	categoria=theForm.categoria.value;


		check_it=string_1_30.test(categoria);
		if (!check_it) 
		{
		   alert('Inserire un nome valido per la categoria');
		   return false;	
		}

		return true;
		break;


		// Nuovo componente per un gioiello
		case 'select_componente':
   	idmateria=theForm.idmateria.value;

		
		if (idmateria==-1)	{
	   alert('Scegliere un componente valido');
	   return false;	
		}
		

		return true;
		break;


		//Nuova sottocategoria
		case 'new_sub':
   	subcat=theForm.subcat.value;

		check_it=string_1_30.test(subcat);
		if (!check_it) 
		{
		   alert('Inserire un nome valido per la sottocategoria');
		   return false;	
		}

		return true;
		break;





		default:
		break;

	}
		
}


// ----------------------------------------------------------------------------------------------- //

// Funzioni importate da PHP ADMIN 



var marked_row = new Array;

//----------------------------------------------------//
// Funzioni per i colori delle righe
//----------------------------------------------------//

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()'




