function getArticle (pcode, target) {
	//alert("ajax.php?mode=get_article&cookie_language=ITA&pos=" + target + "&pCode=" + pcode);
	//lancio il post	
	$.ajax({ type: "POST", 
		 url: "ajax.php", 
		 data: "&mode=get_article&cookie_language=ITA&pos=" + target + "&pCode=" + pcode, 
		 dataType: "xml", 
		 success: function(xmlData)
		 {
			xmlDataSet = xmlData;
			return_ok = browseXMLArticle(xmlDataSet, target);
		 }
	});
}

function browseXMLArticle (inXML, nomet) {
   $(inXML).find('article').each(function(){
		
      //ottengo i dati dall'xml
    	var _titolo = $(this).find('titolo').text();
      var _testo = $(this).find('testo').text();
      var _categoria = $(this).find('categoria').text();
      var _data = $(this).find('data').text();
      var _flag_ifiit = $(this).find('flag_ifiit').text();
      var _img_src = $(this).find('img_src').text();
      
      //resetto altezza e larghezza dell'immagine
      $('#image_' + nomet).removeAttr('width');
      $('#image_' + nomet).removeAttr('height');
      $('#image_' + nomet).css('top', '0px');
      $('#image_' + nomet).css('left', '0px');
      //resetto anche i parametri del crop
      $('#image_' + nomet + '_t').val('0px');
      $('#image_' + nomet + '_le').val('0px');
            
      //switcho la posizione
      if (nomet==1) {
         //switcho il display se ifiit oppure no
         if (_flag_ifiit==1) {
            $('#head_tit2').css('display', 'inline');
            $('#head_numero2').css('display', 'inline');
            $('#head_sottotit2').css('display', 'inline');
            $('#head_testo2').css('display', 'inline');
            //--------------------
            $('#head_tit_art').css('display', 'none');
            $('#head_testo_art').css('display', 'none');
            $('#head_foto').css('display', 'none');
            //sostituisco gli HTML
            $('#' + nomet + '_titolo_ifiit').html(_titolo);
            $('#' + nomet + '_testo_ifiit').html(_testo);
            $('#' + nomet + '_data_ifiit').html(_data);
         } else if (_flag_ifiit==0) {
            $('#head_tit2').css('display', 'none');
            $('#head_numero2').css('display', 'none');
            $('#head_sottotit2').css('display', 'none');
            $('#head_testo2').css('display', 'none');
            //--------------------
            $('#head_tit_art').css('display', 'inline');
            $('#head_testo_art').css('display', 'inline');
            $('#head_foto').css('display', 'inline');
            //sostituisco gli HTML
            $('#' + nomet + '_titolo').html(_titolo);
            $('#' + nomet + '_testo').html(_testo);
            $('#' + nomet + '_data').html(_data);
            $('#' + nomet + '_categoria').html(_categoria);
            $('#' + 'image_' + nomet).attr('src',_img_src);     
         }
      } else if (nomet<=2 && nomet>=7) {
         //sostituisco gli HTML
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         $('#' + nomet + '_data').html(_data);
         $('#' + nomet + '_categoria').html(_categoria);
         $('#' + 'image_' + nomet).attr('src',_img_src);
         $('#' + 'image_' + nomet).attr('width',750);           
      } else {
         //sostituisco gli HTML
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         $('#' + nomet + '_data').html(_data);
         $('#' + 'image_' + nomet).attr('src',_img_src);
         $('#' + nomet + '_categoria').html(_categoria.replace('.', '.<b>') + '</b>');
      }
	
   });
   
}

function getArticleCat (pcode, target) {
	//alert("ajax.php?mode=get_article_cat&cookie_language=ITA&pos=" + target + "&pCode=" + pcode);
	//lancio il post	
	$.ajax({ type: "POST", 
		 url: "ajax.php", 
		 data: "&mode=get_article_cat&cookie_language=ITA&pos=" + target + "&pCode=" + pcode, 
		 dataType: "xml", 
		 success: function(xmlData)
		 {
			xmlDataSet = xmlData;
			return_ok = browseXMLArticleCat(xmlDataSet, target);
		 }
	});
}

/*
function browseXMLArticleCat (inXML, nomet) {
   if (nomet==1 || nomet==2 || nomet==3 || nomet==4) {
      $(inXML).find('article').each(function(){
   		//ottengo i dati dall'xml
       	var _titolo = $(this).find('titolo').text();
         var _testo = $(this).find('testo').text();
         var _img_src = $(this).find('img_src').text();
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         $('#' + nomet + '_img_src').attr('src',_img_src);   					
   	});  
   } else if (nomet==5 || nomet==6) {
      $(inXML).find('article').each(function(){
   		//ottengo i dati dall'xml
       	var _titolo = $(this).find('titolo').text();
         var _testo = $(this).find('testo').text();
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
   	});
   } else if (nomet==7 || nomet==8 || nomet==9 || nomet==10 || nomet==11 || nomet==12 || nomet==13 || nomet==14) {
      $(inXML).find('article').each(function(){
   		//ottengo i dati dall'xml
       	var _titolo = $(this).find('titolo').text();
         var _testo = $(this).find('testo').text();
         var _img_src = $(this).find('img_src').text();
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         if (_img_src!='') {
            $('#' + nomet + '_img').html('<img id="' + nomet + '_img_src" src="' + _img_src + '" class="bordo_grigio" width="35" alt="" title="" border="0" />');
         } else {
            $('#' + nomet + '_img').html('');
         }
   	});
   }
}
*/

function browseXMLArticleCat (inXML, nomet) {
   $(inXML).find('article').each(function(){
		
      //ottengo i dati dall'xml
    	var _titolo = $(this).find('titolo').text();
      var _testo = $(this).find('testo').text();
      var _categoria = $(this).find('categoria').text();
      var _data = $(this).find('data').text();
      var _flag_ifiit = $(this).find('flag_ifiit').text();
      var _img_src = $(this).find('img_src').text();
      
      //resetto altezza e larghezza dell'immagine
      $('#image_' + nomet).removeAttr('width');
      $('#image_' + nomet).removeAttr('height');
      $('#image_' + nomet).css('top', '0px');
      $('#image_' + nomet).css('left', '0px');
      //resetto anche i parametri del crop
      $('#image_' + nomet + '_t').val('0px');
      $('#image_' + nomet + '_le').val('0px');
            
      //switcho la posizione
      /*if (nomet==1) {
         //switcho il display se ifiit oppure no
         if (_flag_ifiit==1) {
            $('#head_tit2').css('display', 'inline');
            $('#head_numero2').css('display', 'inline');
            $('#head_sottotit2').css('display', 'inline');
            $('#head_testo2').css('display', 'inline');
            //--------------------
            $('#head_tit_art').css('display', 'none');
            $('#head_testo_art').css('display', 'none');
            $('#head_foto').css('display', 'none');
            //sostituisco gli HTML
            $('#' + nomet + '_titolo_ifiit').html(_titolo);
            $('#' + nomet + '_testo_ifiit').html(_testo);
            $('#' + nomet + '_data_ifiit').html(_data);
         } else if (_flag_ifiit==0) {
            $('#head_tit2').css('display', 'none');
            $('#head_numero2').css('display', 'none');
            $('#head_sottotit2').css('display', 'none');
            $('#head_testo2').css('display', 'none');
            //--------------------
            $('#head_tit_art').css('display', 'inline');
            $('#head_testo_art').css('display', 'inline');
            $('#head_foto').css('display', 'inline');
            //sostituisco gli HTML
            $('#' + nomet + '_titolo').html(_titolo);
            $('#' + nomet + '_testo').html(_testo);
            $('#' + nomet + '_data').html(_data);
            $('#' + nomet + '_categoria').html(_categoria);
            $('#' + 'image_' + nomet).attr('src',_img_src);     
         }
      } else if (nomet<=2 && nomet>=7) {*/
         //sostituisco gli HTML
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         $('#' + nomet + '_data').html(_data);
         $('#' + nomet + '_categoria').html(_categoria);
         $('#' + 'image_' + nomet).attr('src',_img_src);
         $('#' + 'image_' + nomet).attr('width',750);           
      /*} else {
         //sostituisco gli HTML
         $('#' + nomet + '_titolo').html(_titolo);
         $('#' + nomet + '_testo').html(_testo);
         $('#' + nomet + '_data').html(_data);
         $('#' + 'image_' + nomet).attr('src',_img_src);
         $('#' + nomet + '_categoria').html(_categoria.replace('.', '.<b>') + '</b>');
      }*/
	
   });
   
}

function sendComment () {
   pcode = $('#pcode').get(0).value;
   userid = $('#userid').get(0).value;
   nomecognome = $('#nomecognome').get(0).value;
   txt_comment = $('#txt_comment').get(0).value;
   txt_comment_ok = txt_comment.replace('|', ' ');
   txt_comment_ok = txt_comment_ok.replace('&', 'e');
   if (txt_comment_ok=='') {
      alert('Compilare il campo di testo prima di inviare un commento')
   } else {
   	//alert("ajax.php?mode=send_comments&pCode=" + pcode + "&userid=" + userid + "&nomecognome=" + nomecognome + "&txt_comment=" + txt_comment);
   	//lancio il post	
   	$.ajax({ type: "POST", 
   		 url: "ajax.php", 
   		 data: "&mode=send_comments&pCode=" + pcode + "&userid=" + userid + "&nomecognome=" + nomecognome + "&txt_comment=" + txt_comment, 
   		 dataType: "xml", 
   		 success: function(xmlData)
   		 {
   			xmlDataSet = xmlData;
   			return_ok = AddHTMLComment(xmlDataSet);
   		 }
   	});      
   }
}

function AddHTMLComment (inXML) {
   $('#no_comment').css({'display': 'none'});
   $(inXML).find('comment').each(function(){
		//ottengo i dati dall'xml
    	var _nomecognome = $(this).find('nomecognome').text();
      var _dataora = $(this).find('dataora').text();
      var _commento = $(this).find('commento').text();
      var html_append = '<div id="commento_display_off" style="display: none;"><div class="col_570"><div><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="left"><span class="no_bullet_grigio2"><strong>' + _nomecognome + '</strong></span></td><td align="right"><span class="no_bullet_grigio">' + _dataora + '</span></td></tr></table></div><p class="no_bullet_grigio">' + _commento + '</p><!-- col_570> --></div><div class="spazio"><img src="images/spacer.gif" width="1" height="10" alt="" title="" border="0"/><!-- spazio --></div><div class="riga_590_grigio"><img src="images/spacer.gif" width="590" height="1" alt="" title="" border="0"/><!-- riga_590_grigio --></div><div class="spazio"><img src="images/spacer.gif" width="1" height="10" alt="" title="" border="0"/><!-- spazio --></div><!-- fine riga COMMENTI da ripetere --></div>';
      $('#nuovi_commenti').html(html_append);
      $('#commento_display_off').slideToggle(500);
	});
   comme = parseInt($('#num_commenti').html()) + 1;
   $('#txt_comment').val('');
   $('#num_commenti').html(comme);
   location.href = '#anchor_commenti';
}

function getJSONSearch () {
	keysearch = $('#ajax_key_search').val();
   //stilo i div
   $('#loader').css('display', 'inline');
   $('#search_table').css('display', 'none');
   //alert("get_gsearch_json.php?keysearch=" + keysearch); 
   //lancio il post	
	$.ajax({ type: "POST", 
		 url: "get_gsearch_json.php", 
		 data: "&keysearch=" + keysearch, 
		 dataType: "json", 
		 success: function(jsonData)
		 {
			jsonDataSet = jsonData;
			return_ok = browseJSONsearch(jsonDataSet);
		 }
	});
}

function browseJSONsearch (inJSON) {
   z = 1;
   htmlAdd = '';
   $.each(inJSON.responseData.results, function(i,item){
      alert("item " + i + " -> " + item["titleNoFormatting"]);
      //$.each(item, function(key,value){
         /*if (key=="results") {
            $.each(value, function(id,obj){
               //alert("item " + id + " -> " + obj["titleNoFormatting"]);*/
               htmlAdd = '<!-- inizio riga da ripetere -->'
                      +  '<div>'
                      +     '<div class="float">'
                      +     '<div class="foto_articolo_small"><a href="' + item["titleNoFormatting"] + '" title="" onfocus="this.blur()">' + item["titleNoFormatting"] + '</a><!-- foto_articolo_small --></div>'
                      +     '</div>'
                      +     '<div class="float"><div class="spazio"><img src="images/spacer.gif" alt="" title="" border="0" height="1" width="20"><!-- sspazio --></div></div>'
                      +     '<div class="float">'
                      +     '<div class="contenuto_articolo">'
                      //+     '<p class="data_articolo_small">' + obj["titleNoFormatting"] + '</p>'
                      +     '<h1 class="tit_articolo_small"><a href="' + item["titleNoFormatting"] + '" class="lnk_tit_articolo_small" title="" onfocus="this.blur()">' + item["titleNoFormatting"] + '</a></h1>'
                      +     '<p class="testo_articolo_small"><a href="' + item["titleNoFormatting"] + '" class="lnk_testo_articolo_small" title="" onfocus="this.blur()">' + item["content"] + '</a></p>'
	                   +     '</div>'
                      +     '</div>'
                      +     '<div class="clear"></div>';
						    +  '</div>';
                      +  '<!-- fine riga da ripetere -->';
               $(htmlAdd).appendTo('#search_table');
               /*z = z + 1;
            });
         }*/
      //});
      
    });
   //$('#search_table').html('htmlAdd');
   //stilo i div
   $('#loader').css('display', 'none');
   $('#search_table').css('display', 'inline');
}
