function Espacios (InputVal)
{
	var espacios = false;

  	if (InputVal.charAt(0) == " ")
    	espacios = true;
	return espacios;
}

function validarEmail(valor) {
	var Email = true;
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
    	Email = false;

    return Email;
}

function ireset(OBJ_R)
{
	if(OBJ_R.value == "¡REQUERIDO!" || OBJ_R.value == "¡INVALIDO!" || OBJ_R.className == "invalido")
	{
		OBJ_R.className = null;
		OBJ_R.value = "";
	}
}

function maxtext(textarea) {
		var intLimit = 400;
		var varValue = textarea.value;

		if (varValue.length > intLimit) {
			alert ("Máximo " + intLimit + " caracteres.");
			textarea.value = varValue.substring(0, intLimit);
		}
}

var nav4 = window.Event ? true : false;
function acceptNum(evt){	
	var key = nav4 ? evt.which : evt.keyCode;
	
	if(key <= 13 || key == 46 || (key >= 48 && key <= 57))
		return key;
	else{
		/*alert("Ingrese un valor numérico.");*/
		return false;
	}
}

function acceptNum2(evt){	
	var key = nav4 ? evt.which : evt.keyCode;
	
	if(key <= 13 || (key >= 48 && key <= 57))
		return key;
	else{
		/*alert("Ingrese un valor numérico.");*/
		return false;
	}
}

function acceptText(evt){	
	var key = nav4 ? evt.which : evt.keyCode;
	
	if(key <= 13 || key == 209 || key == 241 || (key >= 65 && key <= 122) || (key >= 48 && key <= 57))
		return key;
	else{
		alert("Ingrese solo letras o números.");
		return false;
	}
}

function FormatNumber(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}
function irpag(ir, queryS, pag, criterios)
{	
	var tot_pag		= parseInt(pag);
	var num_pag		= document.getElementById('irnav').value;
	if(tot_pag>=num_pag)
	{
		Pag = document.getElementById(ir).value - 1;
		if(Pag >= 0)
		{
			if(criterios != null)
				document.location = "index.php?paginaN="+Pag+queryS+criterios;
			else
				document.location = "index.php?paginaN="+Pag+queryS;
		}
	}
}

function validarinpt(input)
{
	//alert(input)
	if(document.getElementById(input).value== '')
	{
		document.getElementById(input).value= '¡REQUERIDO!';
		return 1;
	}
	if(document.getElementById(input).value== '¡REQUERIDO!' || document.getElementById(input).value== '¡INVALIDO!')
	{
		document.getElementById(input).value= '¡INVALIDO!';
		return 1;
	}
	else
	{
		return 0;
	}
}

function ischecked(a)
{
	var num 		= '';
	var num 		= a;
	var del			= 1;
	var aux_sup 	= 1;
	var dim_array	= '';
	var dim_array 	= document.getElementById("selectform").seleccion.length;
	var sel		  	= '';
	var i='';
	if(dim_array>0)
	{
		for(i=0;i<dim_array;i++)
		{
			if(document.selectform.seleccion[i].checked==true)
			{
				sel=sel+i+',';
			}
		}
	}
	else
	{
		dim_array = 1;
		obj_est	  = document.selectform.seleccion.checked;
		if(obj_est==true)
		{
			sel = 0+',';
			document.getElementById("checkeds").value = sel;
		}
	}
	if(num==2)
	{
		if(sel=='')
		{	
			alert('Debe selecionar uno para continuar');
			aux_sup = 0;
			del 	= 0;
		}
		if(aux_sup == 1)
		{
			if(!confirm('¿Está seguro que desea ELIMINAR el(los) item(s) seleccionado(s)?'))
			{
				del = 0;
			}
		 	else
		 	{
				del = 1; 
			 	document.getElementById("Sup").value="Del";
			}
		}
		
	}
	if(num==4)
	{
		document.selectform.action = "?m=ZHFuZ3ZrcGd1MWNmb2Rxbmd2a3BndQ==&Env=S";
		//document.getElementById("Upd_bol").value="S";
	}
	if(num == 5)
	{
		alert('Cambiar Clave')
		document.getElementById("Pass").value="Clave";
	}
	
	if(sel=='' && aux_sup!=0)
	{
		alert('Debe selecionar uno para continuar');
	}
	else
	{
		document.getElementById("checkeds").value = sel;
		if(del!=0)
		{
			
			document.getElementById("selectform").submit();
		}
	}
	
	//alert(sel);
}
function backgr(a)
{
	
//	alert('COLOR'+a);
	a.className="td_fondo";
	//alert(a.className)	
}
function backgr2(a)
{
	a.className="datatd";
}

function Mostrar_Ocultar(id,accion)
{
	if(accion == 1)
		document.getElementById(id).style.display = "block";
	if(accion == 0)
	{
		if(id == 'g2' || id == 'g3' || id == 'g4')
		{
			limpiar = id.substring(1);
			document.getElementById('gem_col_'+limpiar).value='';
			document.getElementById('gem_imp_'+limpiar).value='';
			document.getElementById('gem_peso_'+limpiar).value='';
			document.getElementById('gem_tam_'+limpiar).value='';
			document.getElementById('gem_num_'+limpiar).value='';
		}
		document.getElementById(id).style.display = "none";
	}	
}

function show_hide(id1,id2,id3)
{
	if(id3 == '')
	{
		if(id1 == 'single_tipo' || id1 == 'multi_prom_tipo' || id1 == 'multi_nov_tipo' || id1 == 'multi_ofe_tipo')
		{
			if(document.getElementById(id1).value == "1")
				document.getElementById(id2).style.display = "block";
			else
				document.getElementById(id2).style.display = "none";
		}
		
	}
	else
	{
		if(id1 == 'front_tipo')
		{
			//alert(document.getElementById(id1).value);
			if(document.getElementById(id1).value == "1")
			{
				document.getElementById(id2).style.display = "block";
				document.getElementById(id3).style.display = "none";
			}
			
			if(document.getElementById(id1).value == "2")
			{
				document.getElementById(id2).style.display = "none";
				document.getElementById(id3).style.display = "block";
			}
		}
		if(id1 == 'front_promociones')
		{
			document.getElementById(id1).style.display = "block";
			document.getElementById(id2).style.display = "none";
			document.getElementById(id3).style.display = "none";
		}
		if(id1 == 'front_novedades')
		{
			document.getElementById(id1).style.display = "block";
			document.getElementById(id2).style.display = "none";
			document.getElementById(id3).style.display = "none";
		}
		if(id1 == 'front_ofertas')
		{
			document.getElementById(id1).style.display = "block";
			document.getElementById(id2).style.display = "none";
			document.getElementById(id3).style.display = "none";
		}
	}
}

function imgRedim(imagen,size)
{
	var ANCHO = imagen.width;
	var ALTO = imagen.height;
	var VALOR = 1.25;
	var ANCHO_MAX = size;
	
	var RESULT = ANCHO/ALTO;
		
	if(RESULT!=VALOR)
	{
		if(ANCHO>ANCHO_MAX)
			imagen.width = ANCHO_MAX;
		//alert(imagen.width);
	}  
}
