// JavaScript Document
//Funzione per riconoscere IE msie
function isIE(){
  if(jQuery.browser.name=='msie'){
	  if (jQuery.browser.version==8) {
    	return false;
	  } else {
		return true;
	  }
  }else{
    return false;
  }
}
//funzione per cambiare la classe di un oggetto
function changeClass(idElement,myClass){
	if (isIE()) {
		document.getElementById(idElement).setAttribute("className", myClass);
	} else {
		document.getElementById(idElement).setAttribute("class", myClass);
	}
}
//Apertura e chiusura del menu
jQuery(document).ready(function(){
jQuery("#bottone_altre_prop").click(function () {
		 if (jQuery("#tendina_altre_prop").is(":hidden")) {
			jQuery("div:#tendina_altre_prop").slideDown("fast"); 
		 } else { 
			jQuery("div:#tendina_altre_prop").slideUp("fast"); 
		 } 
	 }); 
});
//Centra le miniature in altezza
(function (jQuery) {
    jQuery.fn.vAlign = function(a,b) {
		return this.each(function(i){
			jQuery('#cont'+a).load(function() {
				jQuery('#cont'+a).hide();				
				var altezza = (jQuery('#cont'+a).height());
				var largh = (jQuery('#cont'+a).width());
				//jQuery('#context'+a).html('Dimensioni:<br>'+largh+' - '+altezza);
				var margin = ((b-altezza)/2)+'px';
				jQuery('#cont'+a).css({'margin-top': margin});
				jQuery('#cont'+a).fadeIn('slow');
			});
		});
	}
		})(jQuery);

jQuery('img.userIcon').load(function(){
  if($(this).height() > 100) {
    $(this).addClass('bigImg');
  }
});

//Stripslashes
function stripslashes (str) {
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

//Submit FORM con jQuery
//funzione per aggiornare ordine in settori
function FormAjaxStuffOrdine(ordine,id,nome){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_settore_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineSettore(stripslashes(nome),ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine settori in ecom
function OrdineSettEcom(ordine,id,nome){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=AG_ecom_settore_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineSettore(stripslashes(nome),ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione carrello in ecom
function Carrello(id,nome,prezzo,az){
	//alert (az);
	if (typeof(id) != 'undefined') {
		aid = id;
	} else {
		aid = "";
	}
	if (typeof(nome) != 'undefined') {
		anome = nome;
	} else {
		anome = "";
	}
	if (typeof(prezzo) != 'undefined') {
		aprezzo = prezzo;
	} else {
		aprezzo = "";
	}
 jQuery.ajax({
  type: "POST",
  url: "pages/ajax.php?page=AG_ecom_carrello",
  dataType: "html",
  data: "id=" + aid + "&nome=" + anome + "&prezzo=" + aprezzo + "&az=" + az,
  success: function(response){
   jQuery("#carrello").html(response);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//-----------------------------------
//funzione per aggiornare ordine in scheda
function SchedaModOrdine(ordine,id,sett){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  //url: "www.google.it",
  url: "ajax.php?page=SU_scheda_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal + "&filtro_settore=" + sett,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineScheda(ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in ecom
function SchedaModEcom(ordine,id,sett){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  //url: "www.google.it",
  url: "ajax.php?page=AG_ecom_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal + "&filtro_settore=" + sett,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineScheda(ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in photogallery
function SchedaModPhotogallery(ordine,id,nome){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_photogallery_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#cont_elenco").html(response);
   messaggioOrdinePhotogallery(ordineVal,nome);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in Gallery di photogallery
function SchedaModPhotogalleryGallery(ordine,id,gal){
 //alert (ordine+" - "+id+" - "+gal);
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_photogallery_mod_ordine_gallery",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal + "&GAL=" + gal,
  success: function(response){
   jQuery("#cont_elenco").html(response);
   messaggioOrdinePhotogalleryGallery(ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare didascalie in Gallery di photogallery
function dida_photogallery(id){
 var didaVal = jQuery("#testo_"+id).val();
 var idVal = jQuery("#ID_"+id).attr("value");
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_photogallery_mod_dida",
  dataType: "html",
  data: "dida=" + didaVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#testo_"+id).val(response);
   jQuery("#feedback_"+id).html("Didascalia aggiornata.");
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in link_settore
function SchedaModLinkSettore(ordine,id,sett){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_link_settore_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal + "&filtro_settore=" + sett,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineLinkSettore(ordineVal);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in link
function SchedaModLink(ordine,id,nome){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_link_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineLink(ordineVal,stripslashes(nome));
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per aggiornare ordine in chisiamo
function SchedaModChisiamo(ordine,id,nome){
 var ordineVal = jQuery("#"+ordine).attr("value");
 var idVal = jQuery("#"+id).attr("value");
 //alert(ordineVal+' - '+idVal);
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_chisiamo_mod_ordine",
  dataType: "html",
  data: "ordine=" + ordineVal + "&ID=" + idVal,
  success: function(response){
   jQuery("#serverMsg").html(response);
   messaggioOrdineChisiamo(ordineVal,stripslashes(nome));
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//funzione per visualizzare/modificare link in sez banner
function SchedaGetLink(id_div,az){
	if (az=="insert") {
		val=jQuery("#input_"+id_div).val();
	} else {
		val="";
	}
 jQuery.ajax({
  type: "POST",
  url: "ajax.php?page=SU_banner_link",
  dataType: "html",
  data: "nome=" + id_div + "&az=" + az + "&val=" + val,
  success: function(response){
   jQuery("#cont_"+id_div).html(response);
  },
  error: function(){
   alert("Error occured during Ajax request...");
  }
 });
}
//-----------------------------------
function messaggioOrdineSettore(nome,ordineVal) {
	jQuery("#messaggio").html('AGGIORNATO! | <b>'+nome+'</b> adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdineScheda(ordineVal) {
	jQuery("#messaggio").html('AGGIORNATO! | adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdineLinkSettore(ordineVal) {
	jQuery("#messaggio").html('AGGIORNATO! | adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdineLink(ordineVal,nome) {
	jQuery("#messaggio").html('AGGIORNATO! | <b>'+nome+'</b> adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdineChisiamo(ordineVal,nome) {
	jQuery("#messaggio").html('AGGIORNATO! | <b>'+nome+'</b> adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdinePhotogallery(ordineVal,nome) {
	jQuery("#messaggio").html('AGGIORNATO! | <b>'+nome+'</b> adesso in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function messaggioOrdinePhotogalleryGallery(ordineVal) {
	jQuery("#messaggio").html('AGGIORNATO! | Spostato in posizione: <b>'+ordineVal+'</b>');
	jQuery("#messaggio").slideDown("fast"); 
}
function get_element_height (id_el) {
	if (document.getElementById(id_el)) {
	return document.getElementById(id_el).offsetHeight;
	}
}
jQuery(document).ready(function() {
	var box_height_dep = get_element_height ('news_home');
	var box_height_imm = get_element_height ('imm_home');
	box_height_dep = box_height_dep + 20;
	if (box_height_dep>box_height_imm) {
	jQuery('#cont_totale').css('height',box_height_dep);
	}
	});
/*SOTTOMENU TENDINA*/
/*jQuery(document).ready(function() {
		$('#menu_1,#sottomenu_1,#subtendina_1_hidden,#subtendina_1sub2_hidden').hover(
				function() {
					jQuery('#header div.voce_tendina').removeClass('colore_3, colore_2').addClass('colore_1');
					//$('#header div.voce_tendina').addClass('colore');
					h = get_element_height ('sottomenu_1');
					var p = $("#menu_1");
					var position = p.position();
					var pos_val = position.left+'px';
					jQuery('#sottomenu_1_hidden').css('left', pos_val);
					jQuery('#sottomenu_1_hidden').stop().animate({height:h},{queue:false, duration:600, easing: 'easeOutCirc'}); 
				},
				function() {
					jQuery('#sottomenu_1_hidden').stop().animate({height:'0px'},{queue:false, duration:50, easing: 'easeOutCirc'});
					jQuery('#header div.voce_tendina').removeClass('colore_1');
				}
		);
});*/
jQuery(document).ready(function() {
			jQuery('#progetti, #progetti_sottomenu').hover(	
					function() {
						h = get_element_height ('progetti_sottomenu_height');
						jQuery('#progetti_sottomenu').stop().animate({height:h},{queue:false, duration:600, easing: 'easeOutCirc'});	
					},
					function() {
						jQuery('#progetti_sottomenu').stop().animate({height:'0px'},{queue:false, duration:50, easing: 'easeOutCirc'});
					}
			)
			jQuery('#chisiamo, #chisiamo_sottomenu').hover(	
					function() {
						h = get_element_height ('chisiamo_sottomenu_height');
						jQuery('#chisiamo_sottomenu').stop().animate({height:h},{queue:false, duration:600, easing: 'easeOutCirc'});	
					},
					function() {
						jQuery('#chisiamo_sottomenu').stop().animate({height:'0px'},{queue:false, duration:50, easing: 'easeOutCirc'});
					}
			)
});
