// 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 valida(){
	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[]']	
	
	for(i=0; i < name.length; i++){
		if(name[i].value==""){
			alert(" ERROR: Por favor ingrese el nombre del producto ");
			name[i].focus();
			return false
		}
	}
	for(i=0; i < desc.length; i++){
		if(desc[i].value==""){
			alert(" ERROR: Por favor ingrese el nombre de Categoria ");
			desc[i].focus();
			return false
		}
	}
	
	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)"
}

function ver_compromiso(){
  $('#nosotros').hide('slow');
  $('#compromiso').show('slow');
};
function ver_nosotros(){
  $('#compromiso').hide('slow');
  $('#nosotros').show('slow');
};
/*function(flash, ancho, alto){
	
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'">
				 <param name="movie" value="aplication/webroot/flash/'+flash+'.swf" />
				 <param name="quality" value="high" />
				 <embed src="aplication/webroot/flash/'+flash+'.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ancho+'" height="'+alto+'" ></embed>
			</object>');
	}*/