//	var httpserver="http://achille:8080/lastOli/manage";
	var httpserver="http://www.olivazzofineprints.com/manage/";
	function insertArtist() {
		if ( $('#luogo').val() && $('#nascita').val() && $('#nome').val() && $('#cognome').val() ) { 
			//alert( "LUOGO VUOTO");
			params = "?cognome="+$('#cognome').val()+"&nome="+$('#nome').val()+
			"&luogo="+$('#luogo').val()+"&nascita="+$('#nascita').val()+"&morte="+$('#morte').val()+"&luogoMorte="+$('#luogoMorte').val();
			//alert( params);
			$.ajax({
				url: httpserver+'insertArtist.php'+params,
				type: 'GET',
				timeout: 1000,
				error: function(){ alert('Error loading XML document'); },
				success: function(dosome){
				
					eval(dosome);
					// In caso di errore, 
					if (pippo.errore) { 
						$('#insertMsg').html( pippo.errore);
						document.imgArtista.src="../images/chiudi.jpg";
						$("#artistaOK").show();
						}
					// In caso tutto OK
					if (!pippo.errore) {
						$('#insertMsg').html( "ID : "+pippo.artista);
						var cognome = $('#cognome').val();
						var nome    = $('#nome').val();
						//var uCognome = cognome.substring(0,1);//.toUpperCase();;
						//var uNome    = nome.substring(0,1);//.toUpperCase();
						//cognome[0] = uCognome.toUpperCase();//.toUpperCase( cognome.substring(0,1));
						//nome[0]    = uNome.toUpperCase();//.toUpperCase( nome.substring(0,1));
						$('#artista').val( cognome+" "+nome );
						//$('#artista').val( $('#cognome').val()+" "+$('#nome').val() );
						$('#Log').append( "<li> New Artist : " + $('#cognome').val()+" "+$('#nome').val()+"</li>" );
						$("#artistaOK").show();
						//$("#artistaDiv").hide();
					}

				}
			});
		} else { alert("I Campi Cognome,Nome,Luogo di Nascita,Data di Nascita sono VUOTI. Inserisci dei valori"); }
		}
		
		
	function insertTipologia() {
		
		if ( $('#nuovatipologia').val() ) { 
			//alert( "LUOGO VUOTO"+$('#nuovatipologia').val());
			params = "?tipologia="+$('#nuovatipologia').val();

			//alert( params);
			$.ajax({
				url: httpserver+'insertTipologia.php'+params,
				type: 'GET',
				timeout: 1000,
				error: function(){ alert('Error loading XML document'); },
				success: function(dosome){
				
					eval(dosome);
					// In caso di errore, 
					if (pippo.errore) {
						$('#tipologiaMsg').show().html( pippo.errore);
						document.imgTipologia.src="../images/chiudi.jpg";
						$("#tipologiaOK").show();
						}
					// In caso tutto OK
					if (!pippo.errore) {
						$('#tipologiaMsg').hide();
						$("#tipologia").addOption($('#nuovatipologia').val(), $('#nuovatipologia').val());
						$('#Log').append( "<li> New Collection : " + $('#nuovatipologia').val()+"</li>" );
						document.imgTipologia.src="../images/checkFoto.jpg";
						$("#tipologiaOK").show();
					}

				}
			});
		} else { alert("Il Campo Nuova Tipologia e` VUOTo. Inserisci un valore"); }
		}		
		
	function insertTecnica() {
		alert( "SONO QUI");
		if ( $('#nuovatecnica').val() ) { 
			//alert( "LUOGO VUOTO");
			params = "?tecnica="+$('#nuovatecnica').val();

			//alert( params);
			$.ajax({
				url: httpserver+'insertTecnica.php'+params,
				type: 'GET',
				timeout: 1000,
				error: function(){ alert('Error loading XML document'); },
				success: function(dosome){
				
					eval(dosome);
					// In caso di errore, 
					if (pippo.errore) {
						
						$('#tecnicaMsg').show().html( pippo.errore);
						document.imgTecnica.src="../images/chiudi.jpg";
						$("#tecnicaOK").show();
						}
					// In caso tutto OK
					if (!pippo.errore) {
						$('#tecnicaMsg').hide();
						document.imgTecnica.src="../images/checkFoto.jpg";
						$("#tecnica").addOption($('#nuovatecnica').val(), $('#nuovatecnica').val());
						//$('#tecnica').val( $('#nuovatecnica').val() );
						$('#Log').append( "<li> New ?????? : " + $('#nuovatecnica').val()+"</li>" );
						$("#tecnicaOK").show();
					}

				}
			});
		} else { alert("Il Campo Nuova Tecnica e` VUOTO. Inserisci un valore"); }
		}		
		
	function insertPeriodo() {
		if ( $('#nuovoperiodo').val() ) { 
			//alert( "LUOGO VUOTO");
			params = "?periodo="+$('#nuovoperiodo').val()+"&anno="+$('#annoPeriodo').val();

			//alert( params);
			$.ajax({
				url: httpserver+'insertPeriodo.php'+params,
				type: 'GET',
				timeout: 1000,
				error: function(){ alert('Error loading XML document'); },
				success: function(dosome){
				
					eval(dosome);
					// In caso di errore, 
					if (pippo.errore) {
						$('#periodoMsg').show().html( pippo.errore);
						//$('#periodoOK').append( pippo.errore);
						document.imgPeriodo.src="../images/chiudi.jpg";
						$("#periodoOK").show();
						}
					// In caso tutto OK
					if (!pippo.errore) {
						//$('#edit-role-changer option:selected').val();
						//$('#tecnica').selected.val($('#nuovatecnica').val())
						$('#periodoMsg').hide();
						$("#periodo").addOption($('#nuovoperiodo').val(), $('#nuovoperiodo').val());
						//$('#tecnica').val( $('#nuovatecnica').val() );
						$('#Log').append( "<li> New ?????? : " + $('#nuovoperiodo').val()+"</li>" );
						document.imgPeriodo.src="../images/checkFoto.jpg";
						$("#periodoOK").show();
					}

				}
			});
		} else { alert("Il Campo Nuovo Periodo, Anno Periodo e` VUOTO. Inserisci dei valori"); }
		}		
	function insertOpera() {
		// Parametri da passare per l'inserimento della nuova opera
		// titolo , codice , prezzo, descrizione ,artista ,artistaid,tipologia , tecnica , periodo , annoPeriodo,info ,url,
		// fotoscheda , fotosmall1 , fotobig1 , fotosmall2 , fotobig2, fotosmall3 , fotobig3 [, pubblico , venduta]
		
		var params =  "?titolo="+$('#titolo').val()+
					  "&codice="+$('#codice').val()+
					  "&prezzo="+$('#prezzo').val()+
					  "&codice="+$('#codice').val()+	  
					  "&descrizione="+$('#descrizione').val()+	  
					  "&artista="+$('#artista').val()+	  
					  "&artistaid="+$('#artistaid').val()+	
					  "&tipologia="+$('#tipologia').val()+	  
					  "&tecnica="+$('#tecnica').val()+	  
					  "&periodo="+$('#periodo').val()+
					  "&anno="+$('#annoPeriodo').val()+	  
					  "&info="+$('#info').val()+	  
					  "&url="+$('#url').val()+	  
					  "&fotoscheda="+$('#fotoscheda').val()+	  
					  "&fotosmall1="+$('#fotosmall1').val()+	  
					  "&fotobig1="+$('#fotobig1').val()+	  
					  "&fotosmall2="+$('#fotosmall2').val()+	  
					  "&fotobig2="+$('#fotobig2').val()+	  
					  "&fotosmall3="+$('#fotosmall3').val()+	  
					  "&fotobig3="+$('#fotobig3').val() +
					  "&pubblico="+"1" +
					  "&venduta="+"NO";
					  
					$('#DEBUG').html(params);
		$.ajax({
			url: httpserver+'testtOpera.php'+params,
			type: 'POST',
			//data: params,
			timeout: 1000,
			error: function(){ alert('Error loading XML document'); },
			success: function(dosome){
				
				
				alert(dosome);
					//eval(dosome);
					// In caso di errore, 
					/*
					if (pippo.errore) {
						$('#periodoMsg').show().html( pippo.errore);
						//$('#periodoOK').append( pippo.errore);
						document.imgPeriodo.src="../images/chiudi.jpg";
						$("#periodoOK").show();
						}
					// In caso tutto OK
					if (!pippo.errore) {
						//$('#edit-role-changer option:selected').val();
						//$('#tecnica').selected.val($('#nuovatecnica').val())
						$('#periodoMsg').hide();
						$("#periodo").addOption($('#nuovoperiodo').val(), $('#nuovoperiodo').val());
						//$('#tecnica').val( $('#nuovatecnica').val() );
						$('#Log').append( "<li> New ?????? : " + $('#nuovoperiodo').val()+"</li>" );
						document.imgPeriodo.src="../images/checkFoto.jpg";
						$("#periodoOK").show();
					}
					*/
				} //end success
					    
		}); // $.ajax 
		
		
		$("#artistaOK").hide();
		$("#tipologiaOK").hide();
		$("#tecnicaOK").hide();
		$("#periodoOK").hide();
		$("#artistaDiv").hide();
		$("#tipologiaDiv").hide();
		$("#tecnicaDiv").hide();
		$("#periodoDiv").hide();
		$('#periodoMsg').hide();
		$('#tecnicaMsg').hide();
		$('#tipologiaMsg').hide();
		resetFields(document.form1);
	}
	function resetFields(f) {
		
		for (var i=0; i < f.elements.length; i++) {
			
			var element = f.elements[i];
			element.value = '';
		}

	}

		
	function checkForUpLoad() {
		
		if ( ( $('#artista').val() ) && ( $('#codice').val() ) ) showUpLoadFrame();
		//if ( ( $('#artista').val() )  ) showUpLoadFrame();
	}	
	function showUpLoadFrame() {
		 
		$('#iframeid').attr( { href : "loadImages.php?artista="+$('#artista').val()+"&codice="+$('#codice').val() } );
		//alert("loadImages.php?artista="+$('#artista').val());
		$('#DEBUG').html("You are loading an opera of "+$('#artista').val()+" with code ID "+$('#codice').val()+", <br> select the images and click \"Load Images\" button.");
        $('a.iframe').iframe();
   // });
		
	}
	function sendMail4Info(){
		var caller = window.location;
		//Chiamata da page=contactus

		//Chiamata da page=info
		
			if ($('#name').val() && $('#subject').val() && $('#email').val()) {
			
				$.get(httpserver + 'sendMail.php', {
					name: $('#name').val(),
					email: $('#email').val(),
					subject: $('#subject').val(),	
					icodice: $('#icodice').val(),				
					message: $('#message').val()
				}, function(data){
					$('#msg').html(" E-mail sent successfully, Thanks ")
					//alert("Data Loaded: " + data);
				});
			}
		}
		

	function sendMail4Contact() {	
			if ($('#name').val() && $('#surname').val() && $('#telephone').val() && $('#email').val()) {
			
				$.get(httpserver + 'sendMail.php', {
					name: $('#name').val(),
					surname: $('#surname').val(),
					telephone: $('#telephone').val(),
					email: $('#email').val(),
					company: $('#company').val(),
					address: $('#address').val(),
					message: $('#message').val()
				}, function(data){
					$('#msg').html(" E-mail sent successfully, Thanks ")
				});
			}
		}
		
	
	
	
