   var http_request = false;
   var targetDiv = '';
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById(targetDiv).innerHTML = result;            
         } else {
            //alert('There was a problem with the request.');
         }
      }
   }
   
	function get_comuni(div) {
		if(div == 'res'){
			targetDiv = 'cittadiv';
			var poststr = "provincia=" + encodeURI( document.getElementById('provincia').value );
		}
		else{
			targetDiv = 'comunediv';
			var poststr = "provincie=" + encodeURI( document.getElementById('provincie').value );
		}
		
		makePOSTRequest( './ajax_get_comuni.php' , poststr);
	}
	function get_country(div) {
		if($('#user_country').val() == 'IT'){
			$.post('ajax.php', { fname: 'jq_get_provincie' } , function(data){ $('#provinciadiv').html(data); });
			$.post('ajax.php', { fname: 'jq_get_italy' } , function(data){ $('#italy').html(data); });
			$.post('ajax.php', { fname: 'jget_comuni' , provincia: 1 }  , function(data){ $('#cittadiv').html(data); });
		}	
		else{
			$('#provinciadiv').html('<input type="text" name="provincia" id="provincia">');	
			$('#cittadiv').html('<input type="text" name="citta" id="citta">');	
			$('#italy').html('');
		}
	}
	function refreshPayments(){
		$.post("ajax.php", { fname: 'lpayment' }  , function(data){
			var returnDataL = data.split("DXPUPLAY");
			$.post("ajax.php", { fname: 'payment' , status: $('#creditocheck').attr('checked'), spedizione: $('[name=spedizione]').val() }  , function(data){
				var returnData = data.split("DXPUPLAY");
				$("#pagamentodiv").html(returnData[0]);
				if(returnData[1] != 'off'){
					$("#creditmsg").html('<br>' + returnDataL[2] + ' ' + returnData[1] + '€<br>' + returnDataL[0] + ' ' + returnData[2] + '€<br>' + returnDataL[3] + ' ' + returnData[3] + '€<br>' + returnDataL[1] + ' ' + returnData[4] + '€');
				}
				else{
					$("#creditmsg").html('');
				}
			});	
		});	
	}
	function refreshShippings(){
		$.post("ajax.php", { fname: 'lpayment' }  , function(data){
			var returnDataL = data.split("DXPUPLAY");
			$.post("ajax.php", { fname: 'shipping' , ship_country: $('#user_country').val() , spedizione: $('[name=spedizione]').val() }  , function(data){
				var returnData = data.split("DXPUPLAY");
				if(returnData[0] == 0){
					$("#spedizionediv").html(returnDataL[4]);	
					$("#submit").attr( 'disabled' , 'disabled' );
				}
				else{
					$("#submit").removeAttr( 'disabled' );
					$("#spedizionediv").html(returnData[0]);
				}
				refreshPayments();
			});
		});	
	}
   function sign_for_email(giocoId) {
      var poststr = "prodotto=" + giocoId;
	  targetDiv = 'emaildiv';
      makePOSTRequest( './ajax_signforemail.php' , poststr);
   }
   
  function update_cart(pid,quant) {
      var poststr = "prodotto=" + pid;
	  if(quant>0)
	  	poststr = poststr + "&quant=" + quant;

	  targetDiv = 'cartcontent';
      makePOSTRequest( './ajax_update_cart.php' , poststr);
   }
  function updatePubblico(giocoId,status,user) {
      var poststr = "prodotto=" + giocoId + "&status=" + status;
	  targetDiv = 'pubblicodiv' + giocoId;
      makePOSTRequest( './ajax_pubblico.php' , poststr);
	   var timestamp = new Date().getTime();
	  $('#foto-wish').attr('src','wi-'+user+'.png?'+timestamp);
   }
  function get_codfis() {
	  if(document.getElementById('nome').value == '') {
		  document.getElementById('nome').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('nome').style.backgroundColor="#e78810";
	  if(document.getElementById('cognome').value == '') {
		  document.getElementById('cognome').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('cognome').style.backgroundColor="#e78810";
	  if(document.getElementById('sesso').value == '') {
		  document.getElementById('sesso').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('sesso').style.backgroundColor="#e78810";
	  if(document.getElementById('gg').value == '') {
		  document.getElementById('gg').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('gg').style.backgroundColor="#e78810";
	  if(document.getElementById('mm').value == '') {
		  document.getElementById('mm').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('mm').style.backgroundColor="#e78810";
	  if(document.getElementById('yy').value == '') {
		  document.getElementById('yy').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('yy').style.backgroundColor="#e78810";
	  if(document.getElementById('comune') == null) {
		  document.getElementById('provincie').style.backgroundColor="#FF0000";
	  }
	  else
		  document.getElementById('provincie').style.backgroundColor="#e78810";
		  
		  
	  if(document.getElementById('nome').value == '' || document.getElementById('cognome').value == '' || document.getElementById('sesso').value == '' || document.getElementById('gg').value == '' || document.getElementById('mm').value == '' || document.getElementById('yy').value == '' || document.getElementById('comune').value == null) {
		 document.getElementById('divmsg').innerHTML = "ATTENZIONE: Per calcolare il codice fiscale devono essere compilati necessariamente tutti i campi che sono stati sgnati in rosso.";
	  }
	  else {
		   var poststr = "nome=" + encodeURI( document.getElementById('nome').value ) + "&cognome=" + encodeURI( document.getElementById('cognome').value ) + "&sesso=" + encodeURI( document.getElementById('sesso').value ) + "&data=" + encodeURI( document.getElementById('yy').value ) + "-" + encodeURI( document.getElementById('mm').value ) + "-" + encodeURI( document.getElementById('gg').value ) + "&comune=" + encodeURI( document.getElementById('comune').value );
	 	 targetDiv = 'codfis_div';   
		 makePOSTRequest( './ajax_get_codfis.php' , poststr);
	  }
	  
   }
function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
    }

