// JavaScript Skate
function activar_boton(boton_retirar,id_select){
	//alert(boton_retirar);
	var valor_select=document.getElementById(id_select).options[document.getElementById(id_select).selectedIndex].value;
	switch(valor_select){
	case "":
	document.getElementById(boton_retirar).disabled=true;
	break;
	case "0":
	document.getElementById(boton_retirar).disabled=false;
	break;
	case "1":
	document.getElementById(boton_retirar).disabled=false;
	break;	
	case "2":
	document.getElementById(boton_retirar).disabled=false;
	break;	
	case "3":
	document.getElementById(boton_retirar).disabled=false;
	break;	
	case "4":
	document.getElementById(boton_retirar).disabled=false;
	break;
	}
	
}
function prepara_ocultar(id,tienda){
	//alert(id+' '+tienda);
	setTimeout("ocultar_direccion('"+id+"',"+tienda+")",4000);
}
function cambia_stock_en_tienda(id_admin,id_tienda){
	if(id_admin==1){
	switch(id_tienda){
	case 1:	
	document.location.href='tienda_la_molina.php?id_admin=2';	
	break;
	case 2:	
	document.location.href='tienda_san_miguel.php?id_admin=2';	
	break;	
	case 3:	
	document.location.href='tienda_miraflores.php?id_admin=2';	
	break;	
	case 4:	
	document.location.href='tienda_higuereta.php?id_admin=2';	
	break;	
                      }

}else{

switch(id_tienda){
	case 1:	
	document.location.href='tienda_la_molina.php?id_admin=1';	
	break;
	case 2:	
	document.location.href='tienda_san_miguel.php?id_admin=1';	
	break;	
	case 3:	
	document.location.href='tienda_miraflores.php?id_admin=1';	
	break;	
	case 4:	
	document.location.href='tienda_higuereta.php?id_admin=1';	
	break;	
                      }
					  
}
}
function consultar_venta_por_fecha(eleme){
	var dat=document.getElementById(eleme).options[document.getElementById(eleme).selectedIndex].value;
document.location.href='consulta_ventas.php?dat='+dat;	
}
function cambia_admin(id_admin){
if(id_admin==1){
document.location.href='ingreso_stock.php?id_admin=2';	
}else{
document.location.href='ingreso_stock.php?id_admin=1';		
}
}
function calcular(id,linea,tienda){
//document.getElementById(id).select();
//var foco=document.getElementById(id);
//var linea='';
//var tienda='';
/*document.getElementById(id).onkeypress=function(e){
var esIE=(document.all);
var esNS=(document.layers);
tecla=(esIE) ? event.keyCode : e.which;
if(tecla==13){
	//alert("Ud. ha presionado la tecla Enter con el foco puesto en: "+foco+" "+linea +" " +tienda); return false;*/
	recalcular_cesta_stock(id,linea,tienda);
 // }
//}
}
function calcular_cantidad_venta(id,linea){
document.getElementById(id).select();
//var foco=document.getElementById(id);
//var linea='';
//var tienda='';
document.getElementById(id).onkeypress=function(e){
var esIE=(document.all);
var esNS=(document.layers);
tecla=(esIE) ? event.keyCode : e.which;
if(tecla==13){
	//alert("Ud. ha presionado la tecla Enter con el foco puesto en: "+foco+" "+linea +" " +tienda); return false;
	recalcular_cesta_venta(id,linea);
  }
}
}
function calcular_descuento_venta(id,linea){
document.getElementById(id).select();
//var foco=document.getElementById(id);
//var linea='';
//var tienda='';
document.getElementById(id).onkeypress=function(e){
var esIE=(document.all);
var esNS=(document.layers);
tecla=(esIE) ? event.keyCode : e.which;
if(tecla==13){
	//alert("Ud. ha presionado la tecla Enter con el foco puesto en: "+foco+" "+linea +" " +tienda); return false;
	recalcular_cesta_venta(id,linea);
  }
}
}
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
 
         return true;
      }
var estado=0;	  
function mostrar_direccion(id,conten,x,y){
	//alert(estado);
	if(estado==0){
	document.getElementById(id).style.display='block';
	mapa_google(conten,x,y);
	estado=1;
	}
}
function ocultar_direccion(id){
	//alert(estado);
	document.getElementById(id).style.display='none';
	estado=0;
	GUnload();
}
function mantener_visible(id){
document.getElementById(id).style.display='block';	
}
function mapa_google(conten,x,y){
//<![CDATA[
    function loaded() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(conten));
        map.setCenter(new GLatLng(x,y), 15);
		//map.addControl(new GMapTypeControl());
		map.addOverlay(new GMarker(new GLatLng(x,y)));
        map.addControl(new GSmallMapControl()); 
 //       map.addControl(new GScaleControl()); 
        map.addControl(new GOverviewMapControl()); 
        map.setMapType(G_NORMAL_MAP); 
        function addtag(point, address) { 
        var marker = new GMarker(point); 
         
        GEvent.addListener(marker, "click", function() { 
    marker.openInfoWindowHtml(address); } ); 
        return marker; 
        } 
		//map.openInfoWindow(map.getCenter(), '<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="2"><tr><td><div id="letra28">FRUTTETO <br />F.LLI DI<br />BUDUO<br /><br /></div><div id="letra27">Viale Monza 114-1<br /> Milano</div></td><td width="2"></td><td><table border="0" cellpadding="0" cellspacing="2" style="border-color:#004E32; border-width:1px; border-style:solid"><tr><td><img src="images/mapa2.jpg" width="90" height="65" /></td></tr></table></td></tr></table>');
		//map.addControl(new GMapTypeControl());
		//map.addControl(new GLargeMapControl());
		}
	}
//]]>
loaded();
	}	  
function listado_por_marca(elem,destino){
var id_marca = document.getElementById(elem).options[document.getElementById(elem).selectedIndex].value;	
document.location.href=destino+'?id_m='+id_marca;
}
function listado_por_tienda(elem,destino){
var id_tienda = document.getElementById(elem).options[document.getElementById(elem).selectedIndex].value;	
document.location.href=destino+'?id_t='+id_tienda;
}
function cambiar_tienda(cambia_tienda){
var tienda = document.getElementById(cambia_tienda).options[document.getElementById(cambia_tienda).selectedIndex].value;	
document.location.href="ingreso_stock.php?tienda="+tienda;
}
function listar(pagina, variable, variable2){
	if(variable2=='no'){
document.location.href=pagina+'?v='+variable;
	}else{
	document.location.href=pagina+'?v='+variable+'&id_m='+variable2;
	}
}
function mostrar_foto(x){
	document.getElementById(x).style.display="block";
	}
function oculta(x){
document.getElementById(x).style.display="none";	
}
	
function ocultar_foto(x){
setTimeout("oculta('"+x+"')",100);	
}
function nuevo_producto(foto,form,progreso) { 
//alert(document.getElementById('marca_nuevo').options[document.getElementById('marca_nuevo').selectedIndex].value=="");
   //extensiones_permitidas = new Array(".gif", ".jpg", ".doc", ".pdf"); 
 var codigo_nuevo = document.getElementById('codigo_nuevo').value 
 var marca_nuevo = document.getElementById('marca_nuevo').options[document.getElementById('marca_nuevo').selectedIndex].value
 var nombre_nuevo = document.getElementById('nombre_nuevo').value
 var descripcion_nuevo = document.getElementById('descripcion_nuevo').value
 var precio_reg_nuevo = document.getElementById('precio_reg_nuevo').value
 var precio_nuevo = document.getElementById('precio_nuevo').value
 if(codigo_nuevo == "" || marca_nuevo == "" || nombre_nuevo == "" || descripcion_nuevo == "" || precio_reg_nuevo == "" || precio_nuevo == "" ){
	   
	alert('Todos los campos son obligatorios.');   
	
   }else{
   
   if(document.getElementById(foto).value==""){
	alert('Seleccione una foto');	
	return	
	}
   var archivo=document.getElementById(foto).value;
   extensiones_permitidas = new Array(".jpg"); 
   mierror = ""; 
  if (document.getElementById(foto).value!="") { 
      //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario 
       //mierror = "No has seleccionado ningún archivo"; 
   //}else{ 
      //recupero la extensión de este nombre de archivo 
      extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
      //alert (extension); 
      //compruebo si la extensión está entre las permitidas 
      permitida = false; 
      for (var i = 0; i < extensiones_permitidas.length; i++) { 
         if (extensiones_permitidas[i] == extension) { 
         permitida = true; 
         break;
         } 
      } 
      if (!permitida) {
		// mierror = "Comprueba la extensión de la imagen a subir. \nSólo se puede subir una imagen con extensión: " + extensiones_permitidas.join(); 
		mierror = "Seleccione una foto JPG"; 
	       }else{ 
	   //window.parent.alert("1");
          //submito! 
        // alert ("Todo correcto. Voy a submitir el formulario.");
	document.getElementById(progreso).innerHTML="<img src='../images/ajax_mail.gif' width='16' height='16' />";	
    document.getElementById(form).submit();
		//formulario.submit(); 
         return 1; 
       } 
   } 
   //si estoy aqui es que no se ha podido submitir 
   if(mierror){
   alert (mierror);
   }
   return 0; 
}

}
function admin_go(){
document.location.href='admin.php';	
}
function upload_foto_producto2(foto,form,progreso) { 
   //extensiones_permitidas = new Array(".gif", ".jpg", ".doc", ".pdf"); 
   if(document.getElementById(foto).value==""){
	alert('Seleccione una foto');	
	return	
	}
   var archivo=document.getElementById(foto).value;
   extensiones_permitidas = new Array(".jpg"); 
   mierror = ""; 
  if (document.getElementById(foto).value!="") { 
      //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario 
       //mierror = "No has seleccionado ningún archivo"; 
   //}else{ 
      //recupero la extensión de este nombre de archivo 
      extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
      //alert (extension); 
      //compruebo si la extensión está entre las permitidas 
      permitida = false; 
      for (var i = 0; i < extensiones_permitidas.length; i++) { 
         if (extensiones_permitidas[i] == extension) { 
         permitida = true; 
         break; 
         } 
      } 
      if (!permitida) {
		// mierror = "Comprueba la extensión de la imagen a subir. \nSólo se puede subir una imagen con extensión: " + extensiones_permitidas.join(); 
		mierror = "Seleccione una foto JPG"; 
	       }else{ 
	   //window.parent.alert("1");
          //submito! 
        // alert ("Todo correcto. Voy a submitir el formulario.");
	document.getElementById(progreso).innerHTML="<img src='../images/ajax_mail.gif' width='16' height='16' />";	
    document.getElementById(form).submit();
		//formulario.submit(); 
         return 1; 
       } 
   } 
   //si estoy aqui es que no se ha podido submitir 
   if(mierror){
   alert (mierror);
   }
   return 0; 
} 
function mostrar_foto_producto(contenedor,foto){
document.getElementById(contenedor).src='../images/productos_chico/' + 	foto + '.jpg';
}
