var   factual=2;

Event.observe(window, 'load', function() {
  inicia_combo();
  ver_total_carrito();
 // cf(factual); 
});

var tiempo_ver_carrito="";
var empresa_eleg="";
var color_elegido;

function ver_productos(){
	ver_cargar();
	new Ajax.Updater('cotenido_carrito_cargado','do.php?controlador=carrito&accion=productos');	
}

function ver_carrito(){
	new	Effect.toggle("dv_carrito", 'slide', { 
					  	duration: 0.5 ,delay: 0.1 ,
						queue: 'front',
						beforeStart :function(){
							if($('dv_carrito').visible()){
								$('ventana_carrit_modal').hide();
								$('ventana_carrit_modal').removeClassName('carrito_modal');
							}else{
								$('imagen_evento_carrito').src='images/agregar_carrito.png';
								$('texto_evento_carrito').update('Agregando al carrito...');
								$('ventana_carrit_modal').show();
								$('ventana_carrit_modal').addClassName('carrito_modal');
							}
						}
						
						
					});
	clearInterval(tiempo_ver_carrito);
}

function quick_carrito(i,ic){
/*	if($('color_'+ic).value==""){
		alert("Debes elegir  un color");
		return false;
	}else if($('talla_'+ic).value==""){
		alert("Debes elegir  una talla");
		return false;
	}
*/	
	new Effect.ScrollTo('bt_vercarrito',{duration:0.5});
	cambiar_imagenes(i,ic);
	$('codigo_carrito_preview').update($('codigo_'+ic).value);
	$('precio_carrito_preview').update($('precio_p_'+ic).value);
	$('cantidad_carrito_preview').update($('cantidad_'+ic).value);
	$('talla_carrito_preview').update($('talla_'+ic).value);
	$('nombre_carrito_preview').update($('nombre_'+ic).value);
	$('color_carrito_preview').update($('color_inicial_'+ic).value);
	
	ver_carrito();
	tiempo_ver_carrito=setInterval("ver_carrito()",1500);
	
	agregar_item(i);
}

function elegir_color(rgb,rgb2,dc,icapa,i,ic,color){
	if(dc=="no"){
		$(icapa).update("");
		$(icapa).setStyle({
			backgroundColor:rgb
		});
	}else{
		$(icapa).setStyle({
			backgroundColor:''
		});
		$(icapa).update("<div onmouseover=\"return false;\" style=\"background-color:"+rgb+";width:9px;height:20px;float:left\" >&nbsp;</div><div onmouseover=\"return false;\" style=\"background-color:"+rgb2+";width:9px;height:20px;float:right\" >&nbsp;</div>");
	}
	
	$('talla_'+i).value="";
	//cambiar_imagenes(i,ic);
	talla_x_color(i,ic);
	$('color_'+i).value=ic;
	$('color_carrito_preview').update(color);
	$('color_inicial_'+i).value

}

function cambiar_imagenes(i,ic){
	$('producto_carrito_preview').src=$('img_chica_'+i+'_'+ic).src;	
	/*$('imagen_chica_front_'+i).src=$('img_mediana_'+i+'_'+ic).src;	
	$('imagen_grande_'+i).src=$('img_grande_'+i+'_'+ic).src;	*/

}

function elegir_talla(t,icapa,i,c,it){
	$(icapa).update(t);
	
	$('talla_'+i).value=t;
	$('id_talla_'+i).value=it;
	$('precio_p_'+i).value=c;
	$('precio_'+i).update(c);	
}


function elegir_tallacaja(t,icapa,i,c,it){
	$(icapa).update(t);
	
	$('talla_'+i).value=t;
	$('id_talla_'+i).value=it;
	$('precio_p_'+i).value=c;
}



function talla_x_color(i,c){
	//$('talla_a_elegir_'+i).update("<img src=\"images/cargando.gif.gif\"  />");
	new Ajax.Request("php/eleccion_producto.php?tallas=yes&ic="+c,{
		parameters:"cp="+i,
		onSuccess:function(e){
			var resultados=e.responseText.evalJSON();
			if(resultados){
				$('paleta_tallas_'+i).update(resultados['data']);
				$('talla_a_elegir_'+i).update("");
			}
		}
	});
	
}

function agregar_item(i){	
	new Ajax.Request("do.php?controlador=carrito&accion=agregar&item="+i,{
		parameters:$('formulario_producto_'+i).serialize()+'&cant='+$('cantidad_'+i).value,
		onSuccess:function(e){
			var resultados=e.responseText;
			$('cantidad_carrito').update(resultados);
		}
	});	
}

function ver_carrito_completo(i){
	$('cotenido_carrito_cargado').insert("<div class='cargando_ajax textosnumeros' style='position:absolute;left:250px;top:150px'><b>Cargando...</b></div>");
	new Ajax.Updater("cotenido_carrito_cargado","do.php?controlador=carrito&accion=ver_completo");
	
}

function ver_total_carrito(){
	new Ajax.Updater('cantidad_carrito','do.php?controlador=carrito&accion=cantidad');
}

function quitar_producto(i){
	if(confirm("Realmente desea eliminar este item de su carrito de compras?")){
		new Ajax.Request("do.php?controlador=carrito&accion=eliminar&item="+i,{
			onSuccess:function(e){
				//$('fila_dvcarrito_'+i).fade({duration:0.8});
				$('fila_carrito_'+i).remove();
				ver_carrito_completo();
				ver_total_carrito();
				
			}
		
		});
	}
}

function actualiza_carrito_completo(i,c){
	/*$('imagen_evento_carrito').src='images/bolsa.png';
	$('texto_evento_carrito').update('Calculando carrito...');
	$('ventana_carrit_modal').show();
	$('ventana_carrit_modal').addClassName('carrito_modal');
	*/
	lg=$('lugar_de_destino').value;
	new Ajax.Request("do.php?controlador=carrito&accion=actualizar&item="+i,{
		parameters:'c='+c+'&lugar='+lg,
		onSuccess:function(e){
			//ver_carrito_completo();
			var resultados=e.responseText.evalJSON();
			if(resultados){
				
				$('total_item_'+i).update(resultados['total_item'])
				$('sub_total_carrito_completo').update(resultados['subtotal']);	
				$('gasto_envio_carrito_completo').update(resultados['gasto_envio']);	
				$('total_carrito_completo').update(resultados['total']);	
				$('peso_total_carrito').value=resultados['peso'];	
				
				lugar=$('lugares_para_entregar').options[$('lugares_para_entregar').selectedIndex].text;
				new Ajax.Request("do.php?controlador=carrito&accion=calcular",{parameters:'p='+$F('lugares_para_entregar')+'&lugar='+lugar+'&tipo='+$F('tipod_lugar')});
				
				
				
				 ver_carrito_completo();
				
				
				$('ventana_carrit_modal').hide();
				$('ventana_carrit_modal').removeClassName('carrito_modal');
			}
			
			
		}
	});
}

function actualiza_destino(p,t){
	lugar=$('lugares_para_entregar').options[$('lugares_para_entregar').selectedIndex].text;
	new Ajax.Request("do.php?controlador=carrito&accion=calcular",{
		parameters:'p='+p+'&lugar='+lugar+'&tipo='+t,
		onSuccess:function(e){			
			var resultados=e.responseText.evalJSON();
			if(resultados){
				$('sub_total_carrito_completo').update(resultados['subtotal']);	
				$('gasto_envio_carrito_completo').update(resultados['gasto_envio']);	
				$('total_carrito_completo').update(resultados['total']);
				$('lugar_de_destino').value=resultados['lugar_destino'];
				ver_carrito_completo();
			}
		}
	});

}

function cambiar_lugares_carrito(i){
	peso=$('peso_total_carrito').value;
	switch (i){
		case '0':
			alert ("Por favor seleccione un destino");
			
		break;
		case '1':
			new Ajax.Updater('lugares_carrito_completo','do.php?controlador=carrito&accion=clugar',{
								parameters:"i="+i+"&peso="+peso	
							});			 
		break;
		case '2':									
			new Ajax.Updater('lugares_carrito_completo','do.php?controlador=carrito&accion=clugar',{
								parameters:"i="+i+"&peso="+peso+"&provincia" 
							});					
							
		
		break;
		
		case '3':
			new Ajax.Updater('lugares_carrito_completo','do.php?controlador=carrito&accion=clugar',{
								parameters:"i="+i+"&peso="+peso		
							});			 
		break;
	}
	
	

}

//para las muestras

function cargar_opcion(c,u){
	new Ajax.Updater(c,u,{evalScripts:true});
}

function abrir_ventana(i){
	new Effect.Appear(i,{duration:0.7});
}

function cerrar_ventana(i){
	//$(i).fade({duration:0.7});
	$(i).hide();
}

function cerrar_factura(){
	$('mini_window_factura').hide();
	$('estado_de_factura').update("");
	$('tipo_comprobante_envio_boleta').checked=true;
}

function cerrar_nombre(){
	$('mini_window_nombre').hide();
}

function grabar_factura(){
	var vacio=0;
	var form = $('fomulario_factura'); 
 		var arr = form.getElements(); 
		
	   		arr.each(function(item) {
				if(item.id.value==""){
				  vacio++;
				}
   	   		});
	   
	   
	   if(vacio==0){
		   $('estado_de_factura').update("<a href=\"javascript:;\" onclick=\"ver_factura('do.php?controlador=carrito&accion=ver_factura')\">Editar datos factura</a>");
		   $('tipo_comprobante_envio_factura').checked=true;
		   $('mini_window_factura').hide();
		   
	   }else if(vacio>0){
		   $('estado_de_factura').update("");
		   cerrar_factura();
	   }


}

function ver_descuentos(url){
	abrir_ventana('mini_window_descuento');
	$('form_mini_window_descuento').update("Cargando...");
	cargar_opcion('form_mini_window_descuento',url);
}

function ver_factura(i){
	if(i=='1'){
	   $('fila_ruc_factura').show();
	   $('ruc_factura').focus();
	   $('fila_direccion_factura').show();
	   $('fila_razon_social_factura').show();
	}else{
	   $('fila_ruc_factura').hide();
	   $('ruc_factura').value="";
	   $('fila_direccion_factura').hide();
	   $('direccion_factura').value="";
	   $('fila_razon_social_factura').hide();
	   $('razon_social_factura').value="";
	}
}

function elegir_empresa(i,n,id){
	if(!$(i).hasClassName("empresa_elegida")){
		$(i).addClassName("empresa_elegida");
		$('nombre_empresa_descuento').update("Ingrese C&oacute;digo descuento para : "+n)
		$('ced').value=id;
		$('codigo_descuento').value="";
		$('codigo_descuento').focus();
			if($(empresa_eleg)){
				$(empresa_eleg).removeClassName("empresa_elegida");
			}
		empresa_eleg=i;
	}	
}

function ccdesceunto(){
	if($('ced').value==""){
		alert("Debe elegir una empresa");
	}else if($('codigo_descuento').value==""){
		alert("Debe escribir un c\u00f3digo para el descuento");
	}else{
			new Ajax.Request("do.php?controlador=descuento&accion=comprobar",{
				parameters:"ie="+$('ced').value+"&cd="+$('codigo_descuento').value,
				onSuccess:function(e){
					var resultados=e.responseText.evalJSON();
						if(resultados){
							$('rvdescuento').update(resultados['mensaje']);
								new Ajax.Request("do.php?controlador=carrito&accion=descontar",{
												 parameters:"descuento="+resultados['dscto'],
												 onSuccess:function(e){
													 ver_carrito_completo();
													 $('sub_total_carrito_completo').addClassName("tachado");
												 }
								});
							//alert(resultados['dscto']);
						}
				}
			});
	}
	

}

function comprar(){
	if($('tipo_destino').value==0){
		elegir_destino();
		return false;
	}else{
		
		new Ajax.Request("do.php?controlador=carrito&accion=cerrar_compra",{
					parameters:$('detalle_carrito').serialize(),
					onSuccess:function(e){
							cargar_opcion('cotenido_carrito_cargado','do.php?controlador=carrito&accion=comprar',{evalScripts:true});					
					}
		});
	}

}

function ingresar_nombre(i,t){
	abrir_ventana('mini_window_nombre');
	$('form_mini_window_nombre').update("Cargando...");
	cargar_opcion('form_mini_window_nombre','do.php?controlador=carrito&accion=agregar_nombre&i='+i+'&t='+t.strip(),{evalScripts:true});
}

function ver_representante(i){
	c=$(i);
	/*if(c.checked){
	   $('fila_nombre_representante').show();
	}else{
		$('fila_nombre_representante').hide();
	}*/
	if(c.value=="si"){
	   $('fila_nombre_representante').show();
	}else{
		$('fila_nombre_representante').hide();
	}
	

}

/*function iniciar_sesion(){
//	alert("Para poder realizar compras necesita iniciar sesión \n o de lo contrario registarrse para poder acceder a nuestros productos.")
	iniciar_sesion();
	//new Effect.Highlight('iniciarsesion', { startcolor: '#ffff99',endcolor: '#ffffff' }); 
}*/

function es_regalo(i){
	c=$(i);
	if(c.checked){
	   $('fila_regalo_de').show();
	   $('fila_regalo_para').show();
	   $('fila_regalo_mensaje').show();
	   $('regalo_de').focus();
	}else{
	   $('fila_regalo_de').hide();
	   $('regalo_de').value="";
	   $('fila_regalo_para').hide();
	   $('regalo_para').value="";
	   $('fila_regalo_mensaje').hide();
	   $('mensaje_regalo').value="";
	}

}

function finalizar_compra(){
	var ap = Spry.Widget.Form.validate($('fomulario_compra'));
	if(ap){
		new Ajax.Request("do.php?controlador=carrito&accion=datos_compra",{
				parameters:$('fomulario_compra').serialize(),
				onSuccess:function(e){
						cargar_opcion('cotenido_carrito_cargado','do.php?controlador=carrito&accion=finalizar_compra',{evalScripts:true});					
				}
		});
	}else{
		return false;
	}
}

function iniciar_sesion(){
	options={
		url:"promptSesion.php",
		width:460,
		height:122
	}
  	jQuery.loadWindow(options);   
}

function elegir_destino(){
 /*   Dialog.alert("Debes elegir un destino", 
                   {width:250, className: "alphacube", okLabel: "Cerrar ",buttonClass:'btn_carrito'})*/
	options={
		url:"",
		width:250,
		height:100,
		html:"<div class='contenWindowAuxiliar' align='center' style='padding:15px'><strong>Debes elegir un distrito</strong><br><br>"+
			 "<input style='width:50px' type='buttom' value='Aceptar' onclick='jQuery.closeWindow()'/></div>"
	}
  	jQuery.loadWindow(options);   
}

function agregar_nombre(){
	nombre=$('nombre_bordado').value;
	if(nombre!==""){
			new Ajax.Request("do.php?controlador=carrito&accion=grabar_nombre",{
						parameters:'nombre='+nombre+"&i="+$('id_item').value,
						onSuccess:function(e){
								ver_carrito_completo();
						}
			});
	}else{
		alert("Debes escribir un nombre para el bordado");
	}

}

function quitar_bordado(i){
	new Ajax.Request("do.php?controlador=carrito&accion=quitar_bordado",{
						parameters:'i='+i,
						onSuccess:function(e){
								ver_carrito_completo();
						}
	});
}

/*function ver_compras(){
	new Ajax.Request("do.php?controlador=compras&accion=ver",{
						onSuccess:function(e){
								ver_carrito_completo();
						}
	});
}*/

function cerrar_sesion(){
	optionsSesion={
		url:"promptSesionLogout.php",
		width:460,
		height:150
	}
	jQuery.loadWindow(optionsSesion);
}

function cargar_pagina(url){
	ver_cargar();
	$getHTML("cotenido_carrito_cargado",url);
}

function eliminar_estados(i){
	$(i).removeClassName("estado_ok");
	$(i).removeClassName("estado_mal");
	$(i).removeClassName("estado_cargando");
	$(i).removeClassName("estado_alerta");
}

function cargar_paginacion(url,capa){
	ver_cargar();
	$getHTML("cotenido_carrito_cargado",url);
}

//para el combo-list

function inicia_combo(){
	if (document.addEventListener) {
			document.addEventListener("mousedown", ocultar_combo,false );
			
		}
		else if (document.attachEvent) {
			document.attachEvent("onmousedown", function () { ocultar_combo(window.event); } );
		}
}

function ver_combo(){
	if($('body_select').visible()){
		return false;
	}else{
		//$('body_select').removeClassName("select_busqueda");
		$('select_busca').addClassName("select_busqueda_abierta");
		new	Effect.BlindDown("body_select",{duration:0.5}); 
	}
}

function ocultar_combo(){
	if($('body_select').visible()){
		$('select_busca').removeClassName("select_busqueda_abierta");
		new	Effect.BlindUp("body_select", {duration:0.5}); 
		
	}
}

function seleccionar_talla(t,i){
	$('txttalla').update("Edad de : " + t);
	$('valtalla').value=i;
}

function buscarxtalla(){
	if($('valtalla').value==""){
		alert("Debes elegir un rango de tallas");
		return false;
	}else{
		t=$('valtalla').value;
		ver_cargar();
		$getHTML('cotenido_carrito_cargado','php/vistas/resultados/productos.php?t='+t);
	}
}

/// fin del combo list

function abrirpop(){
	hs.htmlExpand(null, { src: "envia_visita.php", objectType: 'iframe',width:340,height:385});
}

function abrirpop2(){
	hs.htmlExpand(null, { src: "envia_mailing.php", objectType: 'iframe',objectWidth:390,objectHeight:410,width:390,height:390});
}


function fpago(i){
	new Ajax.Request("do.php?controlador=carrito&accion=pagoEfectivo&ic="+i,{
		onSuccess:function(){
			hs.close();	
		}
	});
		
}


function ver_categorias(i){
	$getHTML('cotenido_carrito_cargado','php/vistas/categorias/productos.php?c='+i);	
}

function ver_factura_venta(i){
	if(i=='1'){
		$('fila_datos_factura_venta_1').show();
		$('fila_datos_factura_venta_2').show();
		$('ruc').focus();
	}else{
		$('fila_datos_factura_venta_1').hide();
		$('fila_datos_factura_venta_2').hide();
	}
}

function grabar_venta_vendedor(){
	var ap = Spry.Widget.Form.validate($('datos_de_venta'));
	if(ap){
		new Ajax.Request("do.php?controlador=ventas&accion=grabar",{
			evalsScripts:true,
			parameters:$('datos_de_venta').serialize(),
			onSuccess:function(){
				$('btn_grabar_venta').hide();
				$('detalles_de_venta').appear({duration:0.8});
				$('btn_nueva_venta').appear({duration:0.8});
				$('fila_cerrar_venta').show();
			}
		});
	}
	return false;
	
		
}

function buscar_producto_venta(){
	$('resultados_busqueda_ventas').appear({duration:0.5});
	new Ajax.Updater("resultados_busqueda_ventas","do.php?controlador=ventas&accion=buscar",{
			parameters:'cp='+$F('codigo_producto'),evalScripts:true
	});
	
	return false; 	
}

/**para calcular  que no s epase del stock**/

var ces=0;

function vtpv(c,ip){
	new Ajax.Updater('tallas_por_colores_ventas','do.php?controlador=ventas&accion=tallasxcolor',{
		parameters:'ic='+c+'&ip='+ip			 
	});
	ces=0;
	$('cifra_en_stock').update(ces);
}

function qds(c,p){
	ces=c;
	$('cifra_en_stock').update(c);
	$('precio_producto_venta').update(p);
	$('p_producto_venta').value=p;
	$('cantidad_de_producto').focus();
	$('cantidad_de_producto').value=0;
	$('cantidad_de_producto').select();
}

function rs(i){
	ts=ces-i;

	if(ts<0){
		alert("No debes sobrepasar la cantidad limite de stock \n para este producto");
		$('cifra_en_stock').update(ces);
		$('cantidad_de_producto').value=0;
		$('cantidad_de_producto').select();
	}else{
		$('cifra_en_stock').update(ts);
	}
}

/**para la cantidad de items en la lista**/
var il=0;
var cpel="";

function apv(){
	if($F('cantidad_de_producto')>0){	
		codigo=$F('codigo_producto')+"_"+$$('input:checked[type="radio"][name="color"]').pluck('value') + "_"+$$('input:checked[type="radio"][name="talla"]').pluck('value');
		if(codigo!=cpel){	
			new Ajax.Request('do.php?controlador=ventas&accion=agregarProducto',{
				parameters:$('datos_productos_venta').serialize()	,
				onSuccess:function(e){
					il++;
					$('cantidad_items_venta').update(il);
					alert("producto agregado");
					cpel=codigo;
				}
			});
		}
	}else{
		alert("Debes ingresar  cantidad  para este producto");
	}
}


function vldv(){
	hs.htmlExpand(null, { src: "do.php?controlador=ventas&accion=verLista", objectType: 'iframe',width:500,height:500});
}


function cerrar_venta(){
	if(il==0){
		alert("Debes tener cuando menos un producto \n en tu lista de venta");
	}else{
		$('datos_de_venta').reset();
		$('datos_productos_venta').reset();
		$('resultados_busqueda_ventas').update("");
		$('detalles_de_venta').fade({duration:0.5});
		$('btn_nueva_venta').fade({duration:0.8});
		$('btn_grabar_venta').show();
	}
	
}

function editar_datos(){
	new Ajax.Updater('cotenido_carrito_cargado','do.php?controlador=sesion&accion=actualizarDatos',{evalScripts:true});	
}


var ielegida;
var pos=0;

function vfg(i,n,nu){
	$('img_chica_pro_1_'+i).removeClassName("foto_elegida");
	if(!$('img_chica_pro_'+nu+'_'+i).hasClassName("foto_elegida")){
		$('img_chica_pro_'+nu+'_'+i).addClassName("foto_elegida");
		if($(ielegida)){
				$(ielegida).removeClassName("foto_elegida");
			}
		ielegida='img_chica_pro_'+nu+'_'+i;
		
	}
	$('imagen_grande_'+i).fade({duration:0.5,
			afterFinish:function(){
				$('imagen_grande_'+i).src="images/productos/"+n;
				$('imagen_grande_'+i).appear({duration:0.8});			
	}});

		

	
}

function cf(){
	 new PeriodicalExecuter(carga_flash,12)
}

function carga_flash(){	
	new Ajax.Updater('banner' , "pub.php?nt="+factual, {
		evalScripts:true,
		onSuccess:function(e){
			factual++;
		}
		
	});
}

function ver_cargar(){
	//new Effect.ScrollTo('telefono',{duration:0.5});
	$('cotenido_carrito_cargado').insert("<div class='cargando_ajax textosnumeros' style='position:absolute;left:250px;top:150px'><b>Cargando...</b></div>");
}

function cerrar_carrito(){
	new Ajax.Request("do.php?controlador=carrito&accion=cerrarCarrito",{
		parameters : { ema:$('contenido_email_carrito').innerHTML},
		onSuccess:function(){
			ver_total_carrito();
		}
	});
}



/**para paises,disitrtos etc**/
function depas(i){
	$('provincia').options.length=1;
	$('distrito').options.length=1;
	if(i==9){
		$('fila_pro_dep').show();
		$('fila_distrito').show();
		
		new Ajax.Request("do.php?controlador=paises&accion=getDepartamentos",{
			evalScripts:true,
			onSuccess:function(e){
			 var json=e.responseText.evalJSON();
				 n=0;
				 json.each(function(){	
					$('departamento').insert({
							bottom:new Element('option', {value: json[n].cdepartamento}).update(json[n].descripcion)							 
			     	});
					 n++;
				 }); 
			}
		});	
		
	}else{
		$('fila_pro_dep').hide();
		$('fila_distrito').hide();
		$('direccion').focus();
		
	}
}


function provincias(i){
	$('provincia').options.length=1;
		new Ajax.Request("do.php?controlador=paises&accion=getProvincias",{
			evalScripts:true,
			parameters: 'id='+i,
			onSuccess:function(e){
			 var json=e.responseText.evalJSON();
				 n=0;
				 json.each(function(){	
					$('provincia').insert({
							bottom:new Element('option', {value: json[n].cprovincia}).update(json[n].descripcion)							 
			     	});
					 n++;
				 }); 
			}
		});	
}



function distritos(i){
	$('distrito').options.length=1;
		new Ajax.Request("do.php?controlador=paises&accion=getDistritos",{
			evalScripts:true,
			parameters: 'ip='+i,
			onSuccess:function(e){
			 var json=e.responseText.evalJSON();
				 n=0;
				 json.each(function(){	
					$('distrito').insert({
							bottom:new Element('option', {value: json[n].cdistrito}).update(json[n].descripcion)							 
			     	});
					 n++;
				 }); 
			}
		});	
}
/****/


function edg(){
Event.observe('from_edicion_datos','submit',function(){
var ret = Spry.Widget.Form.validate($('from_edicion_datos'));
			if(ret){
				$('button_act').value="Grabando datos por favor espere.... ";
				new Ajax.Request("do.php?controlador=sesion&accion=grabarDatos",{
						parameters:$('from_edicion_datos').serialize(),
						onSuccess:function(){
							$('button_act').value="Datos grabados correctamente";
							setTimeout(function(){$('button_act').value="Grabar Datos";},2000)
							return false;
						}
				});
				
			}
		
		return false;
});

}



function  mailing(){
  var ret = Spry.Widget.Form.validate($('form_lista_mail'));
	if(ret){
		$('msgmail').update("Grabando sus datos....");
				new Ajax.Request("mailing.php",{
						parameters:$('form_lista_mail').serialize(),
						onSuccess:function(e){
							$('msgmail').update(e.responseText);
							setTimeout(function(){
									parent.hs.close();
							},3000)
							return false;
						}
				});
	}
	return false;
}



function cambiaSexo(i,c,ic){
	sexo=$('sexo_caja_separadas_'+c).options[$('sexo_caja_separadas_'+c).selectedIndex].text;
	
	$('sexo_caja_'+c).value=sexo;
	new Ajax.Request("tallassexo.php?icaja="+ic+"&is="+i,{
			evalScripts:true,
			onSuccess:function(e){
			 var json=e.responseText.evalJSON();
				$('paleta_tallas_'+c).update(json.tallas);
				$('tallas_acambiar_'+c).update(json.cantidades);
				$('talla_a_elegir_'+c).update(json.tallauno)
				$('id_caja_link_'+c).setAttribute('href',"pop_caja.php?ic="+json.ccaja+"&is="+json.ctalla);
			}
		});	

//	$('tallas_acambiar_'+c)
}


function elegir_tallacajan(t,icapa,i,c,it){
	new Ajax.Request("tallas.php?icaja="+c+"&it="+it,{
			evalScripts:true,
			onSuccess:function(e){
			 var json=e.responseText.evalJSON();
				$(icapa).update(t);
				$('talla_'+i).value=t;
				$('id_talla_'+i).value=it;	
				$('id_caja_link_'+i).setAttribute('href',"pop_caja.php?ic="+c+"&is="+it);
				$('tallas_acambiar_'+c).update(json.cantidades);
			}
		});	
}

function checkPromo(){
	new Ajax.Request("php/checkPromo.php",{
		parameters :'permission=yes',
		onSuccess:function(e){
			if(e.responseText!=""){
				return hs.expand(null,{ src: "images/promociones/"+e.responseText});
			}
		}
	});
}


function changeFormRegister(type){
	switch(type){
		case "1":
			window.location.href="registrate.php";
			return false;
		break;
		case "2":
			window.location.href="registraEmpresa.php";
			return false;
		break;
	}
	
}

