
$(document).ready(function(){

/*
$("#info_contactenos table tr td").css('border','none');
$("#info_contactenos table tr").css('border','none');
$("#info_contactenos table").css('border','none');

$("#info_contactenos table tr td").css('border-style','none');
$("#info_contactenos table tr").css('border-style','none');
$("#info_contactenos table").css('border-style','none');
*/



$('#marquita').vAlign();
$("a[id='delete_productoppo']").one("click", function() {
$(this).next().val(1);
$('#pedido').submit();
});



      trigger_function ();

$('.slidetabs').append('<input type="hidden" name="cantidad_rom" />')



$('.preverX').click(function() {
var valor=Number($('.slidetabs span label').html());
var total=Number ($('#cantidad_rom').val());
valor=valor-1;

if (valor<1) { valor=total; }

$('.slidetabs span label').html(valor)

});


$('.nexterX').click(function() {
var valor=Number($('.slidetabs span label').html());
var total=Number ($('#cantidad_rom').val());
valor=valor+1;
if (valor>total)  { valor=1; }
$('.slidetabs span label').html(valor)

});


$('.prevv').click(function() {
 trigger_function ();

});



$('.nextt').click(function() {

 trigger_function ();
});




$('#enviar_pedidop').click(function() {

	if ($("#nombre").val() == '') {
		alert("Por favor, escriba su Nombre");
		$("#nombre").focus ();
        return false;
	}
   else	 if  ($("#email").val() == '') {
		alert("Por favor, escriba su email");
		$("#email").email.focus ();
             return false;
	}
   else	 if (!isEmail($("#email").val())) {
		alert("Verifique que su correo esté bien escrito, gracias");
		$("#email").focus ();
             return false;
	}
   else   if ($("#telefono").val() == '') {
		alert("Por favor, ingrese su numero telefonico");
		$("#telefono").focus ();
             return false;
	}
   else  if ($("#direccion").val() == '') {
		alert("Por favor, ingrese su direccion");
		$("#direccion").focus ();
             return false;
	}

  else  if ($("#mensaje").val() == '') {
		alert("Por favor, un mensaje o comentario acerca de su necesidad con respecto al producto");
		$("#mensaje").focus ();
             return false;
	}


 else  {

$(this).parent().append('<form name="ajax_former" id="ajax_former" method="post" action="validar_pedido_dir.php"><input name="id_producto" type="hidden" value="'+$('#id_producto').val()+'" /><input name="nombre" type="hidden" value="'+$('#nombre').val()+'" /><input name="email" type="hidden" value="'+$('#email').val()+'" /><input name="telefono" type="hidden" value="'+$('#telefono').val()+'" /><input name="celular" type="hidden" value="'+$('#celular').val()+'" /><input name="direccion" type="hidden" value="'+$('#direccion').val()+'" /><input name="mensaje" type="hidden" value="'+$('#mensaje').val()+'" /></form>');

 $('form[name="ajax_former"]').submit()
}





});

/*
$(".slidetabs").tabs(".slideshow > div", {
effect: 'fade',
fadeOutSpeed: "slow",
rotate: true
}).slideshow();
*/


 $('.slideshow').cycle({
    fx:     'fade',
    speed:  'slow',
  delay:  -4000,
    next:   '.nexterX',
    prev:   '.preverX'
	});








$(".newstoggle").jCarouselLite({
    btnNext: ".vertical .next",
    btnPrev: ".vertical .prev",
    vertical: true,
     auto: 5000,
    speed: 800
});



    $(".logoz").jCarouselLite({
        btnNext: ".nextt",
        btnPrev: ".prevv",
        visible: 5,
        auto: 5000,
        speed: 800
    });

trigger_function ();



});



function trigger_function (){

$(".logoz ul li table tr td a div")
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 -60px)"},
			{duration:1})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 0)"},
			{duration:1})
		})

}


function change_captcha()
	 {
	 	document.getElementById('siimage').src="MYcaptcha/get_captcha.php?rnd=" + Math.random();
	 }


function isEmail(email) {
	// validar el formato de correo que sea del tipo "a@b.cd"
	invalidChars = " /;,:*";
	if (email == "")
		return false;

	for (i=0; i< invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1)
		{
			return false;
		}
	}

	atPos = email.indexOf("@",1)
	// no puede comenzar con "@"
	if (atPos == -1)
		return false;

	// no puede tener mas de un caracter "@"
	if (email.indexOf("@", atPos+1) != -1)
		return false;

	// and at least one "." after the "@"
	periodPos = email.indexOf(".",atPos)
	if(periodPos == -1)
		return false;

	// and at least one character between "@" and "."
	if ( atPos +2 > periodPos)
		return false;

	if ( periodPos +3 > email.length)
		return false;

	return true;
}


//border-style: dashed


(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = Math.ceil((ph-ah) / 2);
	$(this).css('margin-top', mh);
	});
};
})(jQuery);
