/**
*Procedimientos y funciones de uso general
*
*/
var nav4 = window.event ? true : false;

jQuery( document ).ready(function(){
		
	
	/*
	 * Nuestro calendario 
	 */
	Date.firstDayOfWeek = 7;
	Date.format = 'yyyy-mm-dd';
	
	
	$('.calendar').datePicker();
	
	/*
	 * Intervalo de fechas
	 */
	$( '#FechaInicio' ).bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if ( d ) 
			{
				d = new Date(d);
				$('#FechaFin').dpSetStartDate( d.addDays(1).asString() );
			}
		}
	);
	
	$( '#FechaFin' ).bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) 
			{
				d = new Date( d );
				$( '#FechaInicio' ).dpSetEndDate( d.addDays( -1 ).asString() );
			}
		}
	);
	$( '.fecha' ).bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) 
			{
				d = new Date( d );
				$( '.fecha' ).dpSetEndDate( d.addDays( -1 ).asString() );
			}
		}
	);
	
	
	
	/*
	 * Toggle de los shortcuts
	 */
	$( "#hidemenuleft" ).click(function(){
	    $("#shortcuts").toggle();
		$(".shortcuts").width( "10px" );
	});
	/*
	 * denegacion de campos
	 */	 
	 //solo numeros
	$( "input.onlynumber" ).keypress(function( evt ){
		var key = nav4 ? evt.keyCode : evt.which;
		return /[\d]/.test( String.fromCharCode( key ) );
	});
	
	//monetario
	$( "input.money" ).keyup(function(){
		this.value = number_format( this.value );
	});
	
	//solo letras
	$( "input.onlyword" ).keypress(function(){
		var key = nav4 ? evt.keyCode : evt.which;
		return /[\w]/.test( String.fromCharCode( key ) );
	});
	
	$( "form.formvalida" ).submit(function(){ 
		return EvaluaReg( this ) });
	
	$( "#buscarUsuario" ).hide("fast");
	
	$( "#linkBuscarUsuario" ).click(function(){
	    $("#buscarUsuario").toggle("slow");
	});
	
	$( ".linkMenuIzquierda" ).click( function( ){
		$( ".subsubmenu" ).hide( "fast" );	
		$("." + ( $(this).attr( 'rel' ) ) ).toggle("slow");
		return false;
	});
	
	//Para la imágenes del carro
	$( ".cartbuttons" ).hover(function(){
	    this.src = "img/botones/"+this.name+"_hover.gif";
	});
   	
	
	$( ".divOcultar" ).hide( "fast" );
	
	$(".galeria_content").jCarouselLite({
		btnNext: ".galeria_next",
		btnPrev: ".galeria_prev",
		scroll: 1,
		visible: 1,
		speed:2000
	});
	
	peps.rollover.init();
	
});


peps = {};
peps.rollover = {
   init: function() {
      this.preload();
      $(".roll").hover(
         function () { $(this).attr( 'src', peps.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', peps.rollover.oldimage($(this).attr('src')) ); }
      );
   },
preload: function(){
      $(window).bind('load', function() {
         $('.roll').each( function( key, elm ) { $('<img>').attr( 'src', peps.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   newimage: function( src ) {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_hover' + src.match(/(\.[a-z]+)$/)[0];
   },
   oldimage: function( src ){
      return src.replace(/_hover\./, '.');
   }
};
