﻿
if(typeof(searchCar) == "undefined"){
  var searchCar = {};
}

searchCar.start = function (action) {

  var el = fmw.get("div_ricercasel");
  if (el) {
    var seletcs = el.getElementsByTagName("select");
    var values = [];
    for (var i = 0; i < seletcs.length; i++) {
      if (seletcs[i].value != "") {
        values.push(encodeURIComponent(seletcs[i].name) + '=' + encodeURIComponent(seletcs[i].value));
      }
    }
    var check_confrontasel = fmw.get("check_confrontasel");
    if (check_confrontasel) {
      if (check_confrontasel.checked == true) {
        values.push("ca=1");
      }
    }
    window.location.href = action + "&" + values.join("&");
  }
}

searchCar.clear = function() {  
  var d = document.getElementById("div_ricercasel");
  if (d) {    
    var sel = d.getElementsByTagName("select");
    for (var i=0; i < sel.length; i++) {
      sel[i].value = "";
    }

    var inp = d.getElementsByTagName("input");
    for (var i=0; i < inp.length; i++) {
      if (inp[i].type == "text") {
        inp[i].value = "";
      }       
    }
    sel[0].focus();
  }
}

/* confronto articoli */
searchCar.confrontoArticoli = function (action) {

  var el = fmw.get("confronto");
  if (el) {
    var ck = fmw.getNodesByAttributeValue("type", "checkbox", el);
    var values = [];
    for (var i = 0; i < ck.length; i++) {
      if (ck[i].checked == true) {
        values.push(encodeURIComponent(ck[i].name) + '=' + encodeURIComponent(ck[i].value));
      }
    }
    if (values.length == 0) { alert("Selezionare almeno un articolo da confrontare"); return false; }
    //values.push("ca=2");
    window.location.href = action + "&" + values.join("&");
  }
}

searchCar.selezionaArticoli = function () {

  var el = fmw.get("confronto");
  if (el) {
    var ck = fmw.getNodesByAttributeValue("type", "checkbox", el);
    var values = [];
    for (var i = 0; i < ck.length; i++) {
      ck[i].checked = true;
    }
  }
}

