﻿var $j = jQuery.noConflict();

jQuery().ready(function () {
  jQuery('#navigation').accordion({
    active: ".current",
    header: '.head',
    navigation: true,
    navigationFilter: function () {
      return this.href.toLowerCase() == location.href.toLowerCase();
    },
    event: "mousedown",
    alwaysOpen: false,
    autoheight: false
  });
});
function sel_sede(chi) {
  val = $j("#cmb_sede").val();

  if (val.substring(0, 4) == "http") {
    document.location = val;
  } else {
    document.location = "http://www.inlingua.it/" + $j("#cmb_sede").val() + "/it/";
  }

}
function activa(chi) {
  $j("#navigation").activate(-1);
  //jQuery('#navigation').accordion("activate", 0);
  //window.event.cancelBubble = true;
  //}
}
function loadda(cosa) {
  if (cosa.indexOf("http") == 0) {
    window.open(cosa)
  } else {
    document.location = "http://www.inlingua.it/" + cosa
  }
}
function ch_lng(chi) {

  $j.ajax({
    type: "POST",
    url: "index.htm"/*tpa=/it/change_lingua.php*/,
    data: "id_lingua=" + chi,
    success: function (msg) {
      document.location.reload();
    }
  });
}

function slideFocus(id) {
  $j('#corpo_' + id).slideToggle('normal');
  var bg = $j("#titFocus_" + id).css("background-image")
  if (bg.indexOf("plus") > 0) {
    $j("#titFocus_" + id).css("background-image", "url(/_server/img/focus_minus.gif)")
  } else {
    $j("#titFocus_" + id).css("background-image", "url(/_server/img/focus_plus.gif)")
  }
}

function dauna(e) {
  if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

}

var old_li = "";
var old_id = "";
function ch_ana(id) {
  if (old_id != "") {
    $j("#dati_" + old_id).hide();
    $j("#li_" + old_id).html(old_li)

  }
  $j("#dati_" + id).show();
  old_id = id;
  old_li = $j("#li_" + id).html();
  $j("#li_" + id).html($j("#a_" + id).text());
}

// GESTIONE CONTATTO
$j(document).ready(function () {
  $j("form#contatto-home input#invia").click(function () {
    var nome = $j("form#contatto-home input[name=nome]").val();
    if (nome === "") {
      alert("Il campo Nome è obbligatorio.");
      return;
    }
    var cognome = $j("form#contatto-home input[name=cognome]").val();
    if (nome === "") {
      alert("Il campo Cognome è obbligatorio.");
      return;
    }
    var telefono = $j("form#contatto-home input[name=telefono]").val();
    var email = $j("form#contatto-home input[name=email]").val();
    if (nome === "") {
      alert("Il campo Email è obbligatorio.");
      return;
    }
    var messaggio = $j("form#contatto-home textarea[name=testo]").val();
    if (nome === "") {
      alert("Il campo Messaggio è obbligatorio.");
      return;
    }

    $j.ajax({
      type: "POST",
      url: '/Contatto.asmx/Contattaci',
      data: "nome=" + nome + "&cognome=" + cognome + "&telefono=" + telefono + "&email=" + email + "&messaggio=" + messaggio,
      success: function (data) {
        alert("Grazie per averci contattato!");
      },
      error: function (e) {
        alert(e);
      }
    });
  }); 
  $j("form#forma input#invia").click(function () {
    var nome = $j("form#forma input[name=nome]").val();
    if (nome === "") {
      alert("Il campo Nome è obbligatorio.");
      return;
    }
    var cognome = $j("form#forma input[name=cognome]").val();
    if (nome === "") {
      alert("Il campo Cognome è obbligatorio.");
      return;
    }
    var telefono = $j("form#forma input[name=telefono]").val();
    var email = $j("form#forma input[name=email]").val();
    if (nome === "") {
      alert("Il campo Email è obbligatorio.");
      return;
    }
    var messaggio = $j("form#forma textarea[name=testo]").val();
    if (nome === "") {
      alert("Il campo Messaggio è obbligatorio.");
      return;
    }

    $j.ajax({
      type: "POST",
      url: '/Contatto.asmx/Contattaci',
      data: "nome=" + nome + "&cognome=" + cognome + "&telefono=" + telefono + "&email=" + email + "&messaggio=" + messaggio,
      success: function (data) {
        alert("Grazie per averci contattato!");
      },
      error: function (e) {
        alert(e);
      }
    });
  });
});
