function doActionName(form, actionName) {
    form.action.value = actionName;
    form.submit();
}

function doActionNameVal(form, actionName) {
    if (window.fillEmptyLang) fillEmptyLang();
    if (validar()) {
        form.action.value = actionName;
        form.submit();
    }
}

function doActionNameValCustom(form, actionName) {
    if (validar() && customValidation(actionName)) {
        form.action.value = actionName;
        form.submit();
    }
}

function doDelete(form, actionName) {
    if (confirm('Delete selected elements?')) doActionName(actionName);
}

function seleccionarChecks(chk, nameChk){
  var arrChk = document.getElementsByName(nameChk);
  for(var i=0; i<arrChk.length; i++) { arrChk[i].checked =chk.checked; }
}

function seleccionarFilas(chk, nameHidden){
  hiddList = document.getElementsByName(nameHidden);
	if (chk.checked) {
    hiddList[chk.value].value = "S";
  }
  else {
    hiddList[chk.value].value = "N";
  }
}

function seleccionarFilasVal(chk, nameHidden, vv){
  hiddList = document.getElementsByName(nameHidden);
  if (chk.checked) {
    hiddList[chk.value].value = vv;
  }
  else {
    hiddList[chk.value].value = "";
  }
}

function seleccionarFilasEx(chk, nameHidden){
  hiddList = document.getElementsByName(nameHidden);
  chkList = document.getElementsByName(chk.name);
  for(i=0; i<chkList.length; i++) {
      if (chkList[i].value==chk.value) {
          if (chk.checked) {
            hiddList[i].value = "S";
          }
          else {
            hiddList[i].value = "N";
          }
      }
  }

}

function anyChecked(name) {
    arrElem = document.getElementsByName(name);
    if (arrElem==null) return true;
    for(i=0; i<arrElem.length; i++)
        if (arrElem[i].checked) return true;
    return false;
}

function showCalendarRange(nombre, index, dateRange) {
    campos = document.getElementsByName(nombre);
    if (dateRange!=null && dateRange!='')
        gfPop.fPopCalendar(campos[index], dateRange);
    else {
        hoy = new Date();
        bd = [hoy.getFullYear(),hoy.getMonth()+1,hoy.getDate()];
        d = new Date(hoy.getFullYear()+2,hoy.getMonth(),hoy.getDate());
        ed = [d.getFullYear(),d.getMonth()+1,d.getDate()];
        dateRange = [bd, ed];

        gfPop.fPopCalendar(campos[index], dateRange);
    }
    return false;
}

function showCalendar(nombre, index) {
    campos = document.getElementsByName(nombre);
    gfPop.fPopCalendar(campos[index]);
    return false;
}

// Para trabajo con combos
function addComboOption(combo, value, text, sel) {
    oOption = document.createElement("OPTION");
    combo.options.add(oOption);
    oTextNode = document.createTextNode(text);
    oOption.appendChild(oTextNode) ;
    oOption.value = value;
    if (sel) oOption.setAttribute("selected", "true");
}
function addEmptyOption(combo, sel) {
    addComboOption(combo, "","",sel);
}
function clearCombo(combo) {
    while(combo.options.length>0) combo.removeChild(combo.options[0]);
}

// Abre la pagina para seleccionar un producto
    var wndProd = null;
    function findProduct(id,name,index, filter_code, filter_mfgcode, filter_name, filter_manufacter) {
        if (wndProd != null)
            if (!wndProd.closed) wndProd.close();

        var url = "../admin/productlist.do?forward=modal";
        url += "&fieldid=" + id;
        url += "&fieldname=" + name;
        url += "&fieldindex=" + index;
        url += "&rowsInPage=" + 15;
        if (filter_code!=null ) url += "&filter_code=" + filter_code;
        if (filter_mfgcode!=null ) url += "&filter_mfgcode=" + filter_mfgcode;
        if (filter_name!=null ) url += "&filter_name=" + filter_name;
        if (filter_manufacter!=null ) url += "&filter_manufacter=" + filter_manufacter;
        wndProd = window.open(url,'wndProd','toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=800,height=640');
        wndProd.focus();
    }

// Abre la pagina para seleccionar varios usuarios
    var wndUsr = null;
    function findUser(id, name, index, multiple, filter_name, notingroup) {
        if (wndUsr != null)
            if (!wndUsr.closed) wndUsr.close();

        var url = "../admin/userlist.do?forward=modal";
        url += "&fieldid=" + id;
        url += "&fieldname=" + name;
        url += "&fieldindex=" + index;
        url += "&rowsInPage=" + 15;
        if (multiple!=null) url += "&multiple="+multiple
        if(filter_name!=null) url += "&filter_name="+filter_name;
        if(notingroup!=null) url += "&filter_notingroup="+notingroup;
        wndUsr = window.open(url,'wndUsr','toolbar=no,location=0,directories=no,status=yes,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=700,height=640');
        wndUsr.focus();
    }

function addSingleToCart(idProd) {

         url = "/addtocart.do?action=addsingle";
         url += "&idProduct="+idProd;
         url += "&quantity=1";
         url += "&imageCaract1=";
         url += "&imageCaract2=";
         url += "&imageCaract3=";
         url += "&url="+document.location.href;

         document.location.href = url;
}

// Para el catalogo
    function gotoCategory(cat) {
        if (cat!=null) document.getElementsByName('category')[0].value = cat;
        document.getElementsByName('pmin')[0].value = "";
        document.getElementsByName('pmax')[0].value = "";
        var arrC = document.getElementsByName('count');
        if (arrC!=null && arrC.length>0) arrC[0].value = "9";
        $('#mainform').submit();
        return false;
    }

    function gotoBrand(br) {
        if (br!=null) {
            document.getElementsByName('brand')[0].value = br;
            document.getElementsByName('pmin')[0].value = "";
            document.getElementsByName('pmax')[0].value = "";
        }
        $('#mainform').submit();
        return false;
    }

    function gotoPrices(pmin, pmax) {
        if (pmin!=null) document.getElementsByName('pmin')[0].value = pmin;
        if (pmax!=null) document.getElementsByName('pmax')[0].value = pmax;
        $('#mainform').submit();
        return false;
    }

     function navigatorStart(st) {
        document.getElementsByName('start')[0].value = st;
        $('#mainform').submit();
         return false;
    }

    function goSearch() {
        sq = document.getElementsByName('search_query')[0].value;
        sc = document.getElementsByName('search_category')[0].value;
        url = "search.do?search_query="+sq+"&search_category="+sc;
        document.location.href = url;
    }

var wndTrack = null;
function gotoTracking(tr, ca) {
    if (wndTrack != null)
        if (!wndTrack.closed) wndTrack.close();

    url = "/tracking.do?track="+tr+"&carrier="+ca;
    wndTrack = window.open(url,'wndTrack','toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=700,height=540');
    wndTrack.focus();

}

var wndUser = null;
function showUserDetail(id) {
    if (wndUser != null)
        if (!wndUser.closed) wndUser.close();

    var url = "admin/userdata.do?id="+id;
    url += "&modal=true";
    wndUser = window.open(url,'wndUser','toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=700,height=540');
    wndUser.focus();

}

var wndOrder = null;
function showOrderDetail(id) {
    if (wndOrder != null)
        if (!wndOrder.closed) wndOrder.close();

    alert('Not implemented');
    return;

    var url = "admin/userdata.do?id="+id;
    url += "&modal=true";
    wndOrder = window.open(url,'wndUser','toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=700,height=540');
    wndOrder.focus();

}

var wndLabel = null;
function gotoLabels(id, carr) {
    if (wndLabel != null)
        if (!wndLabel.closed) wndLabel.close();

    var url = "/images/orders/ship/"+id;
    if (carr=='UPS') url += ".gif";
    if (carr=='USPS') url += ".pdf" ;     
    if (carr=='FEDEX') url += ".png";
    wndOrder = window.open(url,'wndUser','toolbar=yes,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=700,height=540');
    wndOrder.focus();
}

var wndLearn = null;
function showLearningCenter() {
    if (wndLearn != null)
        if (!wndLearn.closed) wndLearn.close();

    var url = "/learning/index.html";
    wndLearn = window.open(url,'wndLearn','toolbar=no,location=0,directories=no,status=no,menubar=1,scrollbars=yes,resizable=yes,copyhistory=0,width=600,height=400');
    wndLearn.focus();
}

var wndDialog = null;
function showDialog(url, w, h) {
    if (wndDialog != null)
        if (!wndDialog.closed) wndDialog.close();

    wndDialog = window.open(url,'wndDialog','toolbar=no,location=0,directories=no,status=no,menubar=1,scrollbars=yes,resizable=yes,copyhistory=0,width='+w+',height='+h);
    wndDialog.focus();
    return false;
}


function showHideBlock(elem, divId) {
    divElem = document.getElementById(divId);
    if (divElem!=null) {
        divElem.style.display = (divElem.style.display=='none') ? '' : 'none';
        elem.className = (divElem.style.display=='none') ? 'section-title-coll' : 'section-title-exp';
    }
}

var wndZoom = null;
function showBigImage(id) {
    if (wndZoom != null)
        if (!wndZoom.closed) wndZoom.close();
    url = "/zoomimg.do?id="+id;
    wndZoom = window.open(url,'wndZoom','toolbar=yes,location=0,directories=no,status=no,menubar=0,scrollbars=no,resizable=yes,copyhistory=0,width=445,height=490');
    wndZoom.focus();

}

function showSubMenu(idM) {
    var elem = document.getElementById('subMenu'+idM);
    elem.style.display = (elem.style.display=='none') ? '' : 'none';
}
