// JavaScript Document


function recuperar_acceso(){
		location.replace('index.php?action=recuperar');
}
function eliminar_sesion(){
	location.replace('salir.php');
}

function mantenimiento_categoria(url,opcion,id1,id){
	
	if(opcion!="deletep" && opcion!="deletec"){ 
			location.replace(url+'?id='+id+'&action='+opcion+'&id1='+id1);
	}else if(opcion=="delete"){
		if(!confirm("Esta Seguro que desea Eliminar el Registro")){
			return false;	
		}else{
			location.replace(url+'?id='+id+'&action='+opcion+'&id1='+id1);			
		}		
	}
}
function validar(){
	if(document.f1.nombre.value==""){
		alert("ERROR: Por favor ingrese su Nombre");
		document.f1.nombre.focus();
		return false;
	}else if(document.f1.apellidos.value==""){
		alert("ERROR: Por favor ingrese sus Apellidos");
		document.f1.apellidos.focus();
		return false;
	}else if(document.f1.email.value==""){
		alert("ERROR: Por favor ingrese su Email");
		document.f1.email.focus();
		return false;
	}else{
		return true;	
	}
	
	}
	

function mantenimiento(url,id,opcion){
	if(opcion!="delete"){ 
		location.replace(url+'?id='+id+'&action='+opcion);
	}else if(opcion=="delete"){
		if(!confirm("Esta Seguro que desea Eliminar el Registro")){
			return false;	
		}else{
			location.replace(url+'?id='+id+'&action='+opcion);			
		}		
	}
}

/*function validar_delete(url){	
	if(!confirm("Esta Seguro que desea Eliminar el Registro")){
		return false;	
	}
}*/
function validar_categorias(opcion, id1, id){
	var name=document.f1.elements['nombre[]']
	for(i=0; i < name.length; i++){
		if(name[i].value==""){
			alert(" ERROR: Por favor ingrese el nombre de Categoria ");
			name[i].focus();
			return false
		}
	}
	
	if(document.f1.imagen.value=="" && opcion == "addc"){
		alert(" ERROR: Por favor ingrese la imagen de categoria ");
		document.f1.imagen.focus();
		return false	
	}else{
		document.f1.action='productos.php?action='+opcion+'&id1='+id1+'&id='+id
		document.f1.submit();
	}
}

function validar_productos(opcion, id1, id){
	
	var name=document.f1.elements['nombre[]']	
	var desc=document.f1.elements['descripcion[]']	
	
	if(name.value==""){
		alert(" ERROR: Por favor ingrese el nombre del producto ");
		name.focus();
		return false
	}else if(desc.value==""){
		alert(" ERROR: Por favor ingrese la descripcion del producto ");
		desc.focus();
		return false
	}else if(document.f1.imagen.value=="" && opcion == "addp"){
		alert(" ERROR: Por favor ingrese la imagen del producto ");
		document.f1.imagen.focus();
		return false	
	
	}else{
		document.f1.action='productos.php?action='+opcion+'&id1='+id1+'&id='+id
		document.f1.submit();
	}
}

function validar_delete(){
	if(!confirm("Esta Seguro que desea Eliminar el Registro")){
		return false;	
	}else{
		return true;	
	}	
}

function pasa_precio(Obj, receptor, oferta){
	if(Obj.value!=""){
		var indice= Obj.selectedIndex;
		var texto=Obj.options[indice].text;
		var precio=texto.split("€");
		receptor.value=precio[1];
		oferta.readOnly="";
		oferta.focus();
	}else{
		receptor.value="";
		oferta.readOnly="true";
	}
}
	
function compara_monto(precio, oferta){
	if(precio.value!=""){
		if(parseFloat(oferta.value)>=parseFloat(precio.value)){
			alert("El precio de la oferta tiene que ser menor al precio del producto: "+precio.value )		
		}	
	}		
}	
function mantenimiento_det(url, id1){	
			location.replace(url+'?id1='+id1);			
}

function buscar(url,texto){
	document.f2.action=url+'&q='+ texto.value;
	document.f2.submit();
}

function checkTheKey(keyCode){
	if(event.keyCode==13){	
		valida();
		return true ;
	}
	return false ;
}
function validnum(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la línea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    patron = /\d/; // Solo acepta números
    //patron = /\w/; // Acepta números y letras 
    //patron = /\D/; // No acepta números 
    // patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
	// uso  onKeyPress="return validnum(event)"
}

