jQuery(document).ready(function(){	
    jQuery('#LoginButton').click(function (event) {
        event.preventDefault();
        jQuery.ajax({
            type: "POST",
            url: "/services/users.asmx/Login",
            data: "{\"user\": \"" + jQuery('#UserText').val() + "\", \"pass\": \"" + jQuery('#PassText').val() + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                if (msg.d.resultado == "OK")
                {
                    window.location = "/member/home-user.aspx";
                }
                else
                {
                    window.location = "/member/login.aspx";
                }
            }
        });
    });
    
    jQuery('form input, form select').live('keypress', function (e) {
        if (jQuery(this).parents('form').find('button[type=submit].default, input[type=submit].default').length <= 0)
            return true;

        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            jQuery(this).parents('form').find('button[type=submit].default, input[type=submit].default').click();
            return false;
        } else {
            return true;
        };
    }); 
	 		 	
	jQuery.each(jQuery('.subMenAsoc'), function() {														  		 
		jQuery(this).hover(
			function(event){ 
				jQuery(this).find('a:eq(0)').addClass ('MenuSeleccionado');
				jQuery(this).find('div.conSubMenu')								
					.css("display", "block")																																																			
			},
			function(event){ 	
				jQuery(this).find('div.conSubMenu')								
					.css("display", "none")						
				jQuery(this).find('a:eq(0)').removeClass ('MenuSeleccionado');																					
																																																			
			}					
		); 					
	});						
	
	jQuery.each(jQuery('.lnkBul'), function() {		
		jQuery(this).css({width : 9, height : 9})						  		 
		jQuery(this).mouseover(
			function(){ 											
				jQuery(this).attr("src", "img/bullet10.gif");
			}
		); 	
		jQuery(this).mouseout(
			function(){ 						
				jQuery(this).attr("src", "img/bullet9.gif");										
			}
		);			
	});
	
	jQuery.each(jQuery('#cat'), function() {														  		 
		jQuery(this).hover(
			function(event){ 
				jQuery(this).find('ul#optCategorias2')								
					.css("display", "block")																																																			
			},
			function(event){ 	
				jQuery(this).find('ul#optCategorias2')								
					.css("display", "none")																				
																																																			
			}					
		); 							
	});

	jQuery.each(jQuery('.imagesmall'), function() {														  		 
		jQuery(this).mouseover(
			function(event){ 
				jQuery("#imagenficha").attr("src",  jQuery(this).attr("src"));
			}					
		); 							
	});
	
	var idMarcado = "";
	jQuery.each(jQuery('.trConsulta'), function() {														  		 
		jQuery(this).click(
			function(){
				
				var idConsulta = jQuery(this).attr("id");
				var idConsultaTmp;
				var claseLnDot;		
				
				//alert(idConsulta + "---" + idMarcado)
					
				if(idMarcado!="" && idConsulta!=idMarcado){
					idConsulta = idMarcado;
					idConsultaTmp = '.'+idMarcado;
					claseLnDot = jQuery(this).attr("class").indexOf("lnDot") ;
										
					jQuery('#'+idConsulta).removeClass('lnDot');					
					jQuery.each(jQuery(idConsultaTmp), function(index) {							
						jQuery(this).removeClass('datosExtBlock');
						jQuery(this).addClass('datosExt');					
					});					
				}					
				
				idConsulta = jQuery(this).attr("id");
				idConsultaTmp = '.'+jQuery(this).attr("id");
				claseLnDot = jQuery(this).attr("class").indexOf("lnDot") ;
				
				if(claseLnDot!=-1)
					jQuery(this).removeClass('lnDot');
				else
					jQuery(this).addClass('lnDot');
				jQuery.each(jQuery(idConsultaTmp), function(index) {	
					if(claseLnDot!=-1){
						jQuery(this).removeClass('datosExtBlock');
						jQuery(this).addClass('datosExt');
						idMarcado = "";
					}else{
						jQuery(this).removeClass('datosExt');
						jQuery(this).addClass('datosExtBlock');	
						if(jQuery(idConsultaTmp).length != (index+1))					
							jQuery(this).addClass('lnDot');
						idMarcado = idConsulta;
					}
				});
			}
		);
	});
	
	jQuery("#modalPopupTarifas").dialog({
            autoOpen: false,
            height: 410, 
            width: 600,
            title: 'Tarifas de envio',
            modal:true, 
            buttons: {
                'Cancelar':function(){jQuery(this).dialog('close');}
            }
    });
	
	jQuery('#ShowTarifasPopup').click( function(event) {
	    event.preventDefault();
	    jQuery("#modalPopupTarifas").dialog('open');
	});
	
	jQuery('#modalPopupform1 select').change( function(event) {
	    event.preventDefault();
	    ScrollPane(jQuery("#modalPopupContenedorTabla"), this);
	});
	
	jQuery('#tarifasInfoform1 select').change( function(event) {
	    event.preventDefault();
	    var target = this.options[this.selectedIndex].value;
	    jQuery.scrollTo("a[href=" + target + "]", 800);
	});
});

function ScrollPane(scroll, element)
{
    var target = element.options[element.selectedIndex].value;
    jQuery(scroll).scrollTo("a[href=" + target + "]", 800);
}

function togglerow(row)
{
    jQuery(row).toggleClass("GridViewRowSelectStyle");
}
function GotoAnchor(anchor)
{
    document.location.hash = anchor;
}

