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

jQuery( document ).ready(function(){

	/*
	 * 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 ) });


	$(".banner ul").cycle({
        timeout: 5000,
        speed:   100,
		prev: ".btnPrev",
		next: ".btnNext",
		pager: ".pag_banner"
    });
	
	$(".bannervideo ul").cycle({
        timeout: 5000,
        speed:   100,
		prev: ".btnPrev",
		next: ".btnNext",
		pager: ".pag_banner"
    });

	
	$( "#btnPause" ).click(function(){
		$(this).addClass("current");
		$('#primaryimage ul').cycle('pause');
		$('#primaryimage2 ul').cycle('pause');
		$("#btnPlay").removeClass("current");
		return false;
	});
	
	$( "#btnPlay" ).click(function(){
		$(this).addClass("current");
		$("#btnPause").removeClass("current");
		$('#primaryimage ul').cycle('resume');
		$('#primaryimage2 ul').cycle('resume');
		
		return false;
	});
	
	
	$('.boxmenu').tinycarousel({ 
		display: 3
	});
	


	$('.contentVallas').tinycarousel({ 
		display: 1,
		callback: function(element, index){
			//element, index, 
			$(".pagerValla").html(index + 1);
			get_mapa( $(element).attr("title") ) ;
		}
	});
	
	
	
	$('.btnCorporativo').click(function(){
		$(".boxconten div").hide();
		$(".boxconten div").html( $("div#" + $(this).attr("rel") ).html() );
		$(".boxconten div").fadeIn();
		
		$('.btnCorporativo').removeClass("active");
		$(this).addClass("active");
		
		return false;
	});
	
	$('#innova .box').hover(						
		function(){		
			$('.OffCaso' + $(this).attr( 'rel' ) ).slideDown();						
		},
		function(){
			$('.OffCaso' + $(this).attr( 'rel' ) ).slideUp()						
	});

	$( ".btnInnovacion" ).click(function(){
		$('#imgInnovacion').show();
		$(".videoInnovacion").hide();
		$('#imgInnovacion').attr( 'src',$(this).attr("href") );
		return false;
	});
	
	$( ".btnVideoInnovacion" ).click(function(){
		$('#imgInnovacion').hide();
		$(".videoInnovacion").show();
		$(".videoInnovacion").html('<iframe style="float:left; height:293px; overflow-x:hidden; overflow-y:hidden; padding:0; widows:530px" src="https://www.youtube.com/embed/' + $(this).attr("rel") + '" width="530" frameborder="0" allowfullscreen="" >	</iframe>');
		return false;
	});

	
	
	$(".example7").colorbox({width:"850px", height:"700px", iframe:true});
	$("a[rel='example2']").colorbox();
	
	
	
	$("#frmBusqueda #IDCiudad").change(function(){
		$('#frmBusqueda').submit();
		//alert("si");
		return false;
	});
	
});


function addNotify( element )
{
	element.html( "<img src='img/ajax-loader.gif' />" );
}




function checkall( obj , selector )
{
	var checked_status = obj.checked;
	$( selector ).each(function(){
		this.checked = checked_status;
	});
}

function acceptNum(evt){ 
	var key = !nav4 ? evt.which : evt.keyCode; 
	return (key <= 13 || (key >= 46 && key <= 57));
}

function getNum(strNum)
{
	//console.log(strNum);
	num = strNum.toString().replace(/\$|\,/g,'');
	return isNaN( num ) ? 0 : num;
}


function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function get_mapa(idproducto)
{
	jQuery.ajax( {
		"type" : "POST",
		"data" : { "IDProducto" : idproducto },
		"url" : "includes/async/mapa.async.php" ,
		
		"beforeSend" : function(){
			
			$(".mapa").html();
		},
		 
		"success" : function( data ){
			
			$(".mapa").html(data);
		}
	});
	
	return false;
}//end function
