function controlAdmin(tipo){
	// datos personales
	var nombre = document.ingreso.Nombre.value;
	var email = document.ingreso.Email.value;
	// login
	var usuario = document.ingreso.Usuario.value;
	var clave = document.ingreso.Clave.value;
	// resticciones 
	var strError = "Ocurrieron Errores:\n";

	// datos personales
	if(nombre==""){
		strError+="- Ingrese su nombre.\n";
	}
	if(email==""){
		strError+="- Ingrese su email.\n";
	}else{
		var p=email.indexOf('@');
		if(p<1){
			strError+="- El email debe ser una dirección correcta.\n";
		}
	}
	// login
	if(usuario==""){
		strError+="- Ingrese un nombre de usuario.\n";
	}else{
		if (usuario.length<6) {
			strError+="- El nombre de usuario debe contener como mínimo 6 caractéres.\n";
		}
	}
	if(tipo!=2){
		if(clave==""){
			strError+="- Ingrese una clave.\n";
		}else{
			if (clave.length<6) {
				strError+="- La clave debe contener como mínimo 6 caractéres.\n";
			}
		}
	}else{
		if(clave!=""){
			if (clave.length<6) {
				strError+="- La clave debe contener como mínimo 6 caractéres.\n";
			}
		}
	}
	if(strError!="Ocurrieron Errores:\n"){
		alert(strError);
		return false;
	}else{
		return true;
	}
}
function marcarContenido(){
	var check = false;
	for (i=0;i<document.listado.c.length;i++){
		if(document.listado.c[i].checked){
			check = true;
		}
	}
	if(!check){
		alert("Por favor marque un contenido");
		return false;
	}else{
		return true;
	}
}
if (document.getElementById){ 
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}
function SwitchMenu(id){
	var tb = document.getElementById(id);
	var img = 'img_'+id;
	var rutaAmpliar = 'imagenes/item_menos.gif';
	var rutaContraer = 'imagenes/item_mas.gif';
	
	if(tb.style.display == "block"){
		tb.style.display = "none";
		document.images[img].src = rutaAmpliar;
		document.images[img].setAttribute('alt','Maximizar');
	}else{
		tb.style.display = "block";
		document.images[img].src = rutaContraer;
		document.images[img].setAttribute('alt','Minimizar');

	}
}
function openWindow(url,frame){
	window.open(url,frame,'');
}

function openPopUp(url, name){
	window.open(url,'name','width=350, height=350, scrollbars=yes, left=410, top=180');
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// validacion de formularios
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección de mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe contener un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es necesario.\n'; }
  } if (errors) alert('Los siguientes errores han ocurrido:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function controlArchivo(CampoArchivo){
	
	var campo = this.document.getElementById(CampoArchivo).value;
	var ar = this.document.getElementById('archivo');
	if(campo){
	var miString = campo.split('\\');
	var largo = miString.length;
	var archivo = miString[largo-1];
	ar.value=archivo;
	var punto = 0;
	var error=0;
	var especiales = 0;
	
	//nos fijamos si hay archivo
	
	if (miString[largo-1] == '') {
		alert("Debe especificar un archivo.");
		return false
	}
	// nos fijamos si las barras no son invertidas
	for(i=0;i<campo.length;i++){
		var chr = campo.charAt(i);
		if(chr=="/"){
			error=error+1;
		}else{
			error = error;
		}
	}
	if(error>0){
		alert("El separador de directorios debe ser \\");
		return false;
	}
	
	// nos fijamos si hay punto
	for(a=0;a<archivo.length;a++){
		var chr = archivo.charAt(a);
		if(chr=="."){
			punto=punto+1;
		}
	}
	
	if(punto==0 || punto>1){
		alert("Debe especificar un archivo");
		return false;
	}
	// controlamos caracteres especiales
	
	for(i=0;i<campo.length;i++){
		var chr = campo.charAt(i);
		if(chr=="/"){
			especiales=especiales+1;
		}
		if(chr=="?"){
			especiales=especiales+1;
		}
		if(chr=="*"){
			especiales=especiales+1;
		}
		if(chr=="<"){
			especiales=especiales+1;
		}
		if(chr==">"){
			especiales=especiales+1;
		}
		if(chr=="\""){
			especiales=especiales+1;
		}
		if(chr=="|"){
			especiales=especiales+1;
		}
		if(chr=="'"){
			especiales=especiales+1;
		}
	}
	if(especiales>0){
		alert("No debe usar caractéres especiales");
		return false;
	}
	// nos fijamos en la extensión
	arrayArchivo = archivo.split('.');
	largoArchivo = arrayArchivo.length;
	extension =  arrayArchivo[largoArchivo-1];
	extensionl = extension.length;
	
	if(extensionl>4 || extensionl<2){
		alert("Debe especificar un archivo.");
		return false;
	}
	}
}
function controlNombreArchivo(CampoArchivo){
	
	var archivo = this.document.getElementById(CampoArchivo).value;
	var punto = 0;
	var error=0;
	var especiales = 0;

	// nos fijamos si hay punto
	for(a=0;a<archivo.length;a++){
		var chr = archivo.charAt(a);
		if(chr=="."){
			punto=punto+1;
		}
	}
	
	if(punto==0 || punto>1){
		alert("Debe especificar un nombre de archivo correcto.");
		return false;
	}
	// controlamos caracteres especiales
	
	for(i=0;i<archivo.length;i++){
		var chr = archivo.charAt(i);
		if(chr=="/"){
			especiales=especiales+1;
		}
		if(chr=="?"){
			especiales=especiales+1;
		}
		if(chr=="*"){
			especiales=especiales+1;
		}
		if(chr=="<"){
			especiales=especiales+1;
		}
		if(chr==">"){
			especiales=especiales+1;
		}
		if(chr=="\""){
			especiales=especiales+1;
		}
		if(chr=="|"){
			especiales=especiales+1;
		}
		if(chr=="'"){
			especiales=especiales+1;
		}
	}
	if(especiales>0){
		alert("No debe usar caractéres especiales");
		return false;
	}
	// nos fijamos en la extensión
	arrayArchivo = archivo.split('.');
	largoArchivo = arrayArchivo.length;
	extension =  arrayArchivo[largoArchivo-1];
	extensionl = extension.length;
	
	if(extensionl>4 || extensionl<2){
		alert("Debe especificar un nombre de archivo correcto.");
		return false;
	}
}

function eliminar(text,url) { 
	var text = unescape(text);
	var txt = "";
	for(i=0;i<text.length;i++){
		var chr = text.charAt(i);
		if(chr=="+"){
			chr=" ";
		}
	txt = txt+chr;
	}
	var re = /\\/g;
	txt = txt.replace(re,"");
	var x=window.confirm(txt);
	if (x) {
		window.open(url,'_top','');
	}
}
function refresh(url){
    window.location.href = url;
}

function uno(src,color_entrada) { 
    src.bgColor=color_entrada;src.style.cursor="hand"; 
} 
function dos(src,color_default) { 
    src.bgColor=color_default;src.style.cursor="default"; 
} 

function validarFechas(){
	// inico
	var fechaInicio = document.historial.fecha1.value;
	var fechaFinalizacion = document.historial.fecha2.value;
	
	var arrayInicio = fechaInicio.split('-');
	var diaI = arrayInicio[0];
	var mesI = arrayInicio[1];
	var anioI = arrayInicio[2];
	var dateI = new Date(anioI,mesI,diaI);
	
	var arrayFin = fechaFinalizacion.split('-');
	var diaF = arrayFin[0];
	var mesF = arrayFin[1];
	var anioF = arrayFin[2];
	var dateF = new Date(anioF,mesF,diaF);
	
	var fecha = new Date();
	var fechaActual = new Date(fecha.getYear(),parseInt(fecha.getMonth()+1),fecha.getDate());
	
	var mensajeError ="";
	var error = false;
	
	if(dateI>dateF){
		mensajeError="La fecha desde debe ser menor a la fecha hasta";
		error=true;
	}
	if(dateI>fechaActual || dateF > fechaActual){
		mensajeError="Las fechas deben ser mayor a la fecha actual";
		error=true;
	}
	if(error){
		alert(mensajeError);
		return false;
	}
	
}

function seleccionMultiple(){
	var selec = document.historial.monedas.options;

	var string = "";
	var error = false;
	var b=0;
	for(i=0;i<selec.length;i++){
		if(selec[i].selected == true){
			string+=selec[i].value+'_';
			b++;
		}
 	}
	if(b==0){
		alert("Debe seleccionar por lo menos una moneda");
		return false;
	}else{
		document.historial.moneda.value = string;
		return true;
	}
}


function desplegarArchivo(){
	
	var tr2 = document.getElementById("ar2");
	var oculto = document.ingreso.modifica;
	if(tr2.style.display == 'block'){
		tr2.style.display = 'none'
		oculto.value="0";
	}else{
		tr2.style.display = 'block'
		oculto.value="1";
	}
}

function accionMultiple(){
	var selec = document.listado.ac.options;
	var accion = document.listado.accion.value;
	
	var string = "";
	var error = false;
	var b=0;
	for(i=0;i<document.listado.ac.length;i++){
		if(document.listado.ac[i].checked == true){
			string+=document.listado.ac[i].value+'_';
			b++;
		}
 	}
	if(accion ==""){
		alert("Debe seleccionar una acción.");
		return false;
	}else if(b==0){
		alert("Debe seleccionar por lo menos un registro.");
		return false;
	}else{
		document.listado.acciones.value = string;
		if(accion=="papelera"){
			var x=window.confirm("Está seguro que quiere enviar " + b +" registros a la papelera de reciclaje?");
			if (x) {
				return true;
			}else{
				return false;
			}
		}
		else if (accion=="eliminar"){
			var x=window.confirm("La eliminación será definitiva.\nEstá seguro que quiere eliminar " + b +" registros?");
			if (x) {
				return true;
			}else{
				return false;
			}
		}else{
			return true;
		}
		
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function ejecutarBuscadorProductos(){
	var palabra = document.productos.p.value;
	if(palabra==""){
		alert("Por favor ingrese una palabra clave");
	}else if(palabra.length<=2){
		alert("La palabra clave debe poseer por lo menos 2 caractéres");
	}else{
		document.productos.ca.value=0;
		document.productos.submit();
	}
}