// JavaScript Document
jQuery(document).ready(function($) {
	
	$("#lbxVerNumero").attr('href','/boleta/?TB_iframe=1&keepThis=1&width=700&height=535').click(function(){
		TB_show('Ver numero', this.href, false);	
		return false;
	});
	
	
	$(".ampliar").click(function(){
		var titulo = $(this).attr("title");
		var vinculo =  $(this).attr("href");
	
		TB_show(titulo, vinculo, true);
		return false;
	});
	
		
	$("#chained").scrollable({circular: true}).navigator();
	$("#vendidos").scrollable({circular: true}).navigator();
	$("#browsable").scrollable({circular: true}).navigator().autoscroll(6500);
	$("#paginacion").scrollable().navigator();
	
	$(".navi a").html("&bull;");


	


	$("ul.tabs").tabs("div.panes > div");
	
	//Agregamos clase al primer banner
	$(".banners a:first").addClass("first");
	
	//formulario login
    var optionslogin = {
        beforeSubmit:  showRequestLogin,  // pre-submit callback 
        success:       showResponseLogin  // post-submit callback 
    }; 
    $('#formlogin').submit(function() { 
        $(this).ajaxSubmit(optionslogin); 
        return false; 
    });

	$("#user_rut").focus(function(){
		$("#nombrerut").hide();
	}).blur(function(){
		if ($(this).val()==''){
			$("#nombrerut").show();
		}
	});
	
	$("#nombrerut").click(function(){
		$(this).hide();
		$("#user_rut").focus();
	});
	
	
	$("#user_pass").focus(function(){
		$("#contra").hide();
	}).blur(function(){
		if ($(this).val()==''){
			$("#contra").show();
			
		}
	});
	
	$("#contra").click(function(){
		$(this).hide();
		$("#user_pass").focus();
	});
	
	$(".cat-item a").each(function(){
		var nombre = $(this).html();
		$(this).attr('title',nombre);
	});
	
	
  	$("#formbusqueda").submit(function(){
		s1 = $("#s").val();
		s2 = $("#s2").val();
		if (s1 == '' && s2 !=''){
			$("#s").val(' ');
		}
	});
	$("#cotizarProducto").submit(function(){


		$.ajax({
			url: "/wp-content/themes/wpStore/ajax-cotizar.php",
			async:true,
			type: "POST",
			data: $("#cotizarProducto").serialize(),
			success: function(datos){
				if (datos=='ok'){
					$(".form_detalles").hide().html('<p>Cotización enviada correctamente.</p><p>Muchas Gracias.</p>').fadeIn();
				}else{
					alert(datos);
				}
			}
		});
		 
		 
		return false;
	});
  });

function showRequestLogin(formData, jqForm, options){ 
    //accion a ejecutar 
    return true; 
} 

function showResponseLogin(responseText, statusText, xhr, jQueryform){ 
	if(responseText == 'ok'){
		window.location.href = '/';
	} else {
		if ( jQuery("#alerta_login").length==0 || jQuery("#TB_window").css('display')!='block' ){
			
			jQuery('#user_rut').val('');
			jQuery('#user_pass').val('');
			var alerta = jQuery(document.createElement('div'));
			jQuery('body').append(alerta);
			alerta.attr('id', 'alerta_login');
			alerta.css('display', 'none');
			alerta.html('<p class="p_titulo"><span class="alert_titulo">&iexcl;Atenci&oacute;n!</span><br /><br />Los datos de acceso ingresados son incorrectos. Intenta nuevamente.</p>');
			jQuery('.alert_titulo').css('font-weight', 'bold');
			jQuery('.alert_titulo').css('font-size', '16px');
			jQuery('.p_titulo').css('text-align', 'center');
			TB_show('', '#TB_inline?height=100&width=400&inlineId=alerta_login&modal=true', null);
		}
	}
} 

