function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

var conv = {
  'stringToArray' : function (sValue,delim){
    if(sValue==null || sValue=='' || sValue==0)return [];
    
  },
  'arrayToString' : function (aValue){
    
  }
};

var valid = {
  errors : ['es obligatorio','no es un email válido','no es un objeto','es numérico'],
  noEmpty : function (value){
    return ( (value!='' && value!=null && value!=undefined)?true:0 );
  },
  email : function (value){
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
      return true;
    }else{
      return 1;
    }
  },
  obj : function (obj){
    if(obj==null || obj==undefined)return false;
    return ( (typeof(obj)=='object')?true:2 );
  },
  arr : function(obj){
    return true;
  },
  numbers : function(value){
    return ( (value==Number(value)) ? true:3 );
  },
  pwdigual : function(val){
    if( val == $('pwdbis').value ){
      return true;
    }else{
      return 'Las contrasenas no son iguales.'
    }
  }
};

function hideSubCat(idCat){
  var ob = $('subcat'+idCat);
  if(valid.obj(ob))ob.style.display='none';
  if(valid.obj(ob))ob.style.display='hidden';
}

function showSubCat(idCat){
  var ob = $('subcat'+idCat);
  if(valid.obj(ob))ob.style.display='block';
  if(valid.obj(ob))ob.style.visibility='visible';
}

function updateCart(){
  $('cntContent').innerHTML = resAjx.cnt;
  $('totalContent').innerHTML = resAjx.total;
  //$('productAdded').innerHTML = 'Producto a&ntilde;adido';
  var obj = $('productAdded'+resAjx.id);
  if(valid.obj(obj))obj.innerHTML = 'Producto a&ntilde;adido';
  obj = $('productAdded');
  if(valid.obj(obj))obj.innerHTML = 'Producto a&ntilde;adido';
  return false;
}

function loginUser(){
  if( valid.noEmpty(resAjx.msg) ){
    $('msgErrorLogin').innerHTML = resAjx.msg;
  }else{
    $('usernameLogin').innerHTML = resAjx.username;
    $('partLogin').style.display = 'none';
    $('loginTitle').style.display = 'none';
    $('partLogout').style.display = 'block';
    window.location.reload();
  }
}

function logoutUser(){
  $('partLogin').style.display = 'block';
  $('loginTitle').style.display = 'block';
  $('partLogout').style.display = 'none';
  window.location.href = '/site/inicio';
}