var alto = '';



$(function() {



	//alert($('#lang').val());

	pestana_registro ();

	form_login ();

	formregistro ();

	ajax_radio ();

	submit_car ();

	submit_cita ();

	ajax_elim ();

	verpaso3();

	verpaso2();

	submit_redondos ();



	$('.slite_fotos').cycle({

		fx:   'curtainX',

		speed:    900,

		timeout:  4000

	});

	$('.slite_fotos2').cycle({

		fx:   'curtainY',

		speed:    900,

		timeout:  4000

	});





	$('.slite_fotos3').cycle({

		fx:   'shuffle',

		speed:    900,

		timeout:  4000

	});

	$('.slite_fotos4').cycle({

		fx:   'toss',

		speed:    900,

		timeout:  4000

	});



	$('#slideshow').cycle({

		fx:     'fade',

		speed:    900,

		timeout: 0,

		pager:  '#nav',

		prev:   '#inf_izquierda',

		next:   '#inf_derecha',

		pagerAnchorBuilder: function(idx, slide) {

			return '#nav li:eq(' + (idx) + ') a';

		}

	});



	$(".tultip").tooltip({

		track: true,

		delay: 0,

		showURL: false,

		showBody: " - ",

		fade: 250

	});



	/*$('.cup').click(function () {

	var iframe = '<a name="pdf" id="pdf"></a><iframe src="coupons.pdf" width="690" height="535" scrolling="auto" frameborder="0" transparency> <p>Abrir archivo PDF.</p> </iframe>';

	$('#contenidos').html(iframe);

	});*/



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



		$.ajax({

			type: "post",

			url: "envio_clave.php",

			data: "email="+$('#email').val()+"&lang="+$('#lang').val(),

			beforeSend: function(objeto){

				if($('#email').val() == '' || $('#email').val() == 'e-mail'){

					if($('#lang').val() == 'esp'){

						alert('Ingrese tu email');

					}

					else{

						alert('Enter your e-mail');

					}

					return false;

				}

				else{

					$("#olvidcalve").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

				}

			},

			success: function(responseText){

				$("#olvidcalve").html(responseText);

				botones_redondos ();

				//$("#form_registro").slideDown();

			}

		});

	})



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

		$.nyroModalManual({

			url: 'recorrido_virtual.php',

			width: 860,

			height: 660,

			autoSizable: true

		});

	});



	var time_tiger = 2000;

	var inter_tiger = setInterval("bajar_subir_tiger ()",time_tiger);



	bajar_subir_tiger = function () {

		if ($('#tires').height() == 35) {

			$('#tires').animate({

				height: "245px"

			},700);

			time_tiger = 12000;

			clearInterval(inter_tiger);

			inter_tiger = setInterval("bajar_subir_tiger ()",time_tiger);

		}

		else {

			$('#tires').animate({

				height: "35px"

			},700);

			time_tiger = 2000;

			clearInterval(inter_tiger);

			inter_tiger = setInterval("bajar_subir_tiger ()",time_tiger);

		}

	}



	$('#tires').mouseover(

	function () {

		$(this).animate({

			height: "245px"

		},1000);

		clearInterval(inter_tiger);

	});



	$('#tires').mouseout(

	function () {

		inter_tiger = setInterval("bajar_subir_tiger ()",time_tiger);

	});



	$('#tires').cycle({

		fx:   'fade',

		speed:    900,

		timeout:  13000

	});



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

		baja_registro ();

	});

	botones_redondos();

	esquinas_redondas();

});







function botones_redondos() {

	if($.browser.msie || $.browser.opera) {

		$('.boton').corner('10px');

	}

	else {

		$.jcorners('.boton',{radius:10});

	}

}



function esquinas_redondas() {

	if($.browser.msie || $.browser.opera) {

		$('#menu').corner('10px');

	}

	else {

		$.jcorners('#menu',{radius:10});

	}



	if($.browser.msie || $.browser.opera) {

		//$('#menu li a').corner('10px');

	}

	else {

		$.jcorners('#menu li a',{radius:10});

	}



	if($.browser.msie || $.browser.opera) {

		$('#contenidos, #text_banner, #menu_lat, #payment').corner('10px');

	}

	else {

		$.jcorners('#contenidos, #text_banner, #menu_lat, #payment',{radius:10});

	}



	if($.browser.msie || $.browser.opera) {

		$('#regis_log').corner('10px');

	}

	else {

		$.jcorners('#regis_log',{radius:10});

	}



	if($.browser.msie || $.browser.opera) {

		$('#pestana').corner('bottom 10px');

	}

}



function form_login () {



	$('#email').one("click", function(){

		$(this).val('');

	}

	);



	$('#contrasena').bind("click select",

	function (e) {

		$('#contrasena').replaceWith('<input type="password" name="contrasena" id="contrasena" value="" />');

		$('#contrasena').focus();

	}

	);



	$('.submitlogin').click(

	function () {

		$('#formlogin').submit();

	});



	$("#formlogin").ajaxForm({

		type: "POST",

		resetForm: true,

		beforeSend: function(objeto){

			if($('#lang').val() == 'esp'){

				var lang = 'contrase&ntilde;a';

			}

			else{

				var lang = 'password';

			}

			if ($('#formlogin input').val() == '' || $('#email').val() == 'e-mail' || $('#contrasena').val() == lang){

				if($('#lang').val() == 'esp'){

					alert('Ingrese su mail y contrase&ntilde;a');

				}

				else{

					alert('Enter your email and password');

				}

				return false;

			}

			else {

				$("#login").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

			}

		},

		success: function(response) {

			$('#login').html(response);

			botones_redondos();

			form_login ();

			$("#form_registro").slideUp();

			/*$("#form_registro").css('display','none');*/

		}

	});



	$('.ajax_salir').click(

	function () {

		$.ajax({

			type: "post",

			url: "request_login.php",

			data: "logaut=true",

			beforeSend: function(objeto){

				$("#login").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

			},

			success: function(responseText){

				$("#login").html(responseText);

				botones_redondos ();

				form_login ();

				//$("#form_registro").slideDown();

			}

		});

	});

}



function pestana_registro () {

	alto = $("#regis_log").height();

	$("#regis_log").css("top",'-'+(alto+13)+'px');



	$("#pestana").click(

	function () {

		alto = $("#regis_log").height();

		if ($("#regis_log").css("top") == "-"+(alto+13)+"px") {

			baja_registro ();

		}

		else {

			sube_registro ();

		}

	});

}



function sube_registro () {

	$("#regis_log").animate({top:-(alto+13) }, "slow");

	if($('#lang').val() == 'esp'){

		$("#pestana").text('Click para Registrarse');

	}

	else{

		$("#pestana").text('Click to Register');

	}

}

function baja_registro () {

	$("#regis_log").animate({top:-10 }, "slow");

	if($('#lang').val() == 'esp'){

		$("#pestana").text('Click para Ocultar');

	}

	else{

		$("#pestana").text('Click to Hide');

	}

}





function formregistro () {

	$(".verpaso1").click(function(){

		//alert($("#id_usuario").val());

		if($("#id_usuario").val() == ""){

			$("#form1").slideDown();

		}

		else{

			if($("#lang") == "esp"){

				alert('Ya realizaste este paso');

			}

			else{

				alert("Since this step");

			}

		}

	});



	if($('#lang').val() == 'esp'){

		$('#fecha_nacimiento').datepicker({

			yearRange: '-90:0',

			changeMonth: true,

			changeYear: true,

			dateFormat: 'd M yy',

			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],

			dayNamesMin: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab']

		});

	}

	else{

		$('#fecha_nacimiento').datepicker({

			yearRange: '-90:0',

			changeMonth: true,

			changeYear: true,

			dateFormat: 'd M yy'

		});

	}

	$('.submitregist').click(

	function () {

		var x=0;

		for(var i=0; i<$('.oblig').length; i++){

			if($('.oblig').eq(i).val() == ''){

				x++;

			}

		}

		if(x>0){

			if($('#lang').val() == 'esp'){

				alert('Ingrese los datos requeridos');

			}

			else{

				alert('Enter the required data');

			}



		}

		else{

			$('#formapo').submit();

		}

	});



	$("#formapo").ajaxForm({

		type: "POST",

		resetForm: true,

		beforeSend: function(objeto){

			$("#form_registro").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

		},

		success: function(responseText) {

			$("#form_registro").html(responseText);

		}

	});



	$('.submitregist2').click(

	function () {

		var x=0;

		for(var i=0; i<$('.oblig2').length; i++){

			if($('.oblig2').eq(i).val() == ''){

				x++;

			}

		}

		if(x>0){

			if($('#lang').val() == 'esp'){

				alert('Ingrese los datos requeridos');

			}

			else{

				alert('Enter the required data');

			}



		}

		else{

			$('#formregistro').submit();

		}

	});



	$("#formregistro").ajaxForm({

		type: "POST",

		resetForm: true,

		beforeSend: function(objeto){

			$("#formreg").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

		},

		success: function(msj) {

			//alert(msj);

			if(msj > 0){

				$.ajax({

					type: "POST",

					url: "appointment_request_car.php",

					success: function(msge){

						$("#contenedor_derecho").html(msge);

						formregistro ();

						ajax_radio ();

						submit_car ();

						submit_cita ();

						ajax_elim ();

						verpaso3();

						verpaso2();

						submit_redondos ();

					}



				});

				$("#id_usuario").replaceWith('<input type="hidden" id="id_usuario" value="'+msj+'"/>');

				$("#vp1").replaceWith('<input type="hidden" id="vp1" value="true"/>');

				$("#form1").slideUp();

				$("#form2").slideDown();

			}

		}



	});



	$('.submitregist3').click(

	function () {

		var x=0;

		for(var i=0; i<$('.oblig3').length; i++){

			if($('.oblig3').eq(i).val() == ''){

				x++;

			}

		}

		if(x>0){

			if($('#lang').val() == 'esp'){

				alert('Ingrese los datos requeridos');

			}

			else{

				alert('Enter the required data');

			}



		}

		else{

			$('#formlogeo').submit();

		}

	});



	$("#formlogeo").ajaxForm({

		type: "POST",

		resetForm: true,

		beforeSend: function(objeto){

			$("#cargalogeo").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

		},

		success: function(msj) {

			//alert(msj);

			if(msj > 0){

				$.ajax({

					type: "POST",

					url: "appointment_request_car.php",

					success: function(msge){

						$("#contenedor_derecho").html(msge);

						formregistro ();

						ajax_radio ();

						submit_car ();

						submit_cita ();

						ajax_elim ();

						verpaso3();

						verpaso2();

						submit_redondos ();

					}



				});

				$("#id_usuario").replaceWith('<input type="hidden" id="id_usuario" value="'+msj+'"/>');

				$("#vp1").replaceWith('<input type="hidden" id="vp1" value="true"/>');

				$("#form1").slideUp();

				$("#form2").slideDown();



			}

			else{



				$.ajax({

					type: "POST",

					url: "viewlogin.php",

					success: function(msge){

						//alert("false");

						$("#cargalogeo").html(msge);

						$("#textlogueo").html('Login and Password invalid');

						formregistro ();

						ajax_radio ();

						submit_car ();

						submit_cita ();

						ajax_elim ();

						verpaso3();

						verpaso2();

						submit_redondos();

					}



				});



			}

			/*$("#cargalogeo").html(msj);

			$("#id_usuario").replaceWith('<input type="hidden" id="id_usuario" value="'+msj+'"/>');

			$("#vp1").replaceWith('<input type="hidden" id="vp1" value="true"/>');

			$("#form1").slideUp();

			$("#form2").slideDown();*/



		}



	});

}

function ajax_radio () {

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

		$('#id_car').val($(this).val());

		$.ajax({

			type: "POST",

			url: "appointment_request_car.php",

			data: "idcar="+$(this).val(),

			success: function(responseText){

				$("#contenedor_izquierdo").html(responseText);



				ajax_elim ();

				submit_car ();

				verpaso3();

				submit_redondos ();

			}

		});

	});

}



function ajax_elim () {

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

		$.ajax({

			type: "post",

			url: "appointment_request_car.php",

			data: "idcarelim="+$(this).attr('value')+"&confelim=true",

			success: function(responseText){

				$("#contenedor_derecho").html(responseText);



				ajax_elim ();

				ajax_radio ();

				verpaso3();

				submit_redondos ();

			}

		});

	});

}



function submit_car () {

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

		$('#formcar').submit();

	});



	/*boton enviar registro carro nuevo*/

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

		$('#id_car').val('');

		$('#formcar').submit();

	});

	/*fin boton enviar registro carro nuevo*/



	$("#formcar").ajaxForm({

		target: '#contenedor_derecho',

		type: "POST",

		resetForm: true,

		beforeSend: function(objeto){

			if ($('#formcar :input').val() == ''){

				if($('#lang').val() == 'esp'){

					alert('Ingrese los datos requeridos');

				}

				else{

					alert('Enter the required data');

				}

				return false;

			}

			else{

				$("#contenedor_derecho").html('<div align="center"><img src="img/ajaxLoader2.gif" align="absmiddle" /></div>');

			}

		},

		success: function(responseText) {

			$("#contenedor_derecho").html(responseText);

			ajax_radio ();

			ajax_elim ();

			verpaso3();

			submit_redondos ();

			$('#formcar :text').val('');

			$('#id_car').val('');

			$('#formcar :radio').attr('checked','');



		}

	});

}



function submit_cita () {

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

		if($('#fecha1').val() != '' && $('#hora1').val() != ''){

			if($('#fecha2').val() == '' && $('#hora2').val() == ''){

				if($('#fecha2').val() != '' && $('#hora2').val() != ''){

					$('#formcita').submit();

				}

				else{

					if($('#fecha2').val() != '' && $('#hora2').val() == ''){

						if($('#lang').val() == 'esp'){

							alert('Ingrese la hora de la cita de la opcion 2');

						}

						else{

							alert('Enter the time of the appointment of Option 2');

						}

					}

					else{

						if($('#fecha3').val() == '' && $('#hora3').val() == ''){

							$('#formcita').submit();

						}

						else{

							if($('#fecha3').val() != '' && $('#hora3').val() == ''){

								if($('#lang').val() == 'esp'){

									alert('Antes de ingresar la opcion 3, ingresa la opcion 2');

								}

								else{

									alert('Before entering the option 3, enter option 2');

								}

							}

							else{

								$('#formcita').submit();

							}



						}



					}

				}

			}

			else{

				if($('#fecha2').val() != '' && $('#hora2').val() == ''){

					if($('#lang').val() == 'esp'){

						alert('Ingrese la hora de la cita de la opcion 2');

					}

					else{

						alert('Enter the time of the appointment of Option 2');

					}

				}

				else{

					if($('#fecha3').val() == '' && $('#hora3').val() == ''){

						$('#formcita').submit();

					}

					else{

						if($('#fecha3').val() != '' && $('#hora3').val() == ''){

							if($('#lang').val() == 'esp'){

								alert('Ingrese la hora de la cita de la opcion 3');

							}

							else{

								alert('Enter the time of the appointment of Option 3');

							}

						}

						else{

							$('#formcita').submit();

						}



					}



				}

			}

		}

		else{

			if($('#fecha1').val() != '' && $('#hora1').val() == ''){

				if($('#lang').val() == 'esp'){

					alert('Ingrese la hora de la cita de la opcion 1');

				}

				else{

					alert('Enter the time of the appointment of Option 1');

				}

			}

			else{

				if($('#lang').val() == 'esp'){

					alert('Ingrese al menos una opcion de cita Nota: si seleccionas una opcion, ingresa la opcion 1');

				}

				else{

					alert('Enter the time of the appointment Note: If you select an item, enter option 1');

				}

			}

		}



	});





	if($('#lang').val() == 'esp'){

		$('#fecha1').datepicker({



			changeMonth: true,

			dateFormat: 'd M yy',

			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],

			dayNamesMin: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab']



		});

		$('#fecha2').datepicker({

			changeMonth: true,

			dateFormat: 'd M yy',

			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],

			dayNamesMin: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab']



		});

		$('#fecha3').datepicker({

			changeMonth: true,

			dateFormat: 'd M yy',

			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],

			dayNamesMin: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab']



		});

	}

	else{

		$('#fecha1').datepicker({

			changeMonth: true,

			dateFormat: 'd M yy'

		});

		$('#fecha2').datepicker({

			changeMonth: true,

			dateFormat: 'd M yy'

		});

		$('#fecha3').datepicker({

			changeMonth: true,

			dateFormat: 'd M yy'

		});



	}

}

function verpaso3(){

	$(".verpaso3").click(function(){

		//alert("id usuario "+$("#id_usuario").val()+" id carro "+$("#id_car").val());

		var idcar=$("#id_car").val();

		if($("#id_usuario").val() != "" && $("#id_car").val() != ""){

			$("#vp1").replaceWith('<input type="hidden" name="vp1" id="vp1" value="false"/>');

			$("#id_car_envio").replaceWith('<input type="hidden" name="id_carro" id="id_car" value="'+idcar+'"/>');

			$("#form2").slideUp();

			$("#form3").slideDown();

		}

		else{

			if($("#lang").val() == "esp"){

				alert("Debes realizar los pasos segun el orden");

			}

			else{

				alert("You must perform the steps in the order");

			}



		}

	});

}

function verpaso2(){

	$(".verpaso2").click(function(){

		//alert("id usuario ="+$("#id_usuario").val()+" vp1="+$("#vp1").val());

		if($("#id_usuario").val() != "" && $("#vp1").val() != "false"){

			$("#form2").slideDown();

			/*var vacio='';

			$("#form2").slideDown();

			$.ajax({

			type: "POST",

			url: "appointment_request_car.php",

			data: "idcar="+vacio,

			success: function(responseText){

			$("#contenedor_izquierdo").html(responseText);



			ajax_elim ();

			submit_car ();

			verpaso3();

			submit_redondos ();

			}

			});*/



		}

		else{

			if($("#lang").val() == "esp"){

				alert('Debes realizar los pasos segun el orden');

			}

			else{

				alert("You must perform the steps in the order");

			}

		}

	});

}



function validar_atencion(){

	if($("#fecha1").val() != ""){

		$.ajax({

			type: "POST",

			url: "validar_fecha.php",

			data: "fecha="+$("#fecha1").val()+"&lang="+$("#lang").val()+"&opt=1",

			success: function(msge){

				var result = msge.split("|");

				if(result[0] == "false"){

					if($("#lang").val() == "esp"){

						alert("En este dia no atendemos");

					}

					else{

						alert("On this day we do not attend");

					}

					

					$("#fecha1").val("");

				}

				else{

					if(result[1] != "0"){

						//alert(result[1]);

						$("#combo1").html(result[1]);

					}

				}

			}



		});

	}

	if($("#fecha2").val() != ""){

		$.ajax({

			type: "POST",

			url: "validar_fecha.php",

			data: "fecha="+$("#fecha2").val()+"&lang="+$("#lang").val()+"&opt=2",

			success: function(msge){

				var result2 = msge.split("|");

				if(result2[0] == "false"){

					if($("#lang").val() == "esp"){

						alert("En este dia no atendemos");

					}

					else{

						alert("On this day we do not attend");

					}

					

					$("#fecha2").val("");

				}

				else{

					if(result2[1] != "0"){

						//alert(result[1]);

						$("#combo2").html(result2[1]);

					}

				}

			}



		});

	}

	if($("#fecha3").val() != ""){

		$.ajax({

			type: "POST",

			url: "validar_fecha.php",

			data: "fecha="+$("#fecha3").val()+"&lang="+$("#lang").val()+"&opt=3",

			success: function(msge){

				var result3 = msge.split("|");

				if(result3[0] == "false"){

					if($("#lang").val() == "esp"){

						alert("En este dia no atendemos");

					}

					else{

						alert("On this day we do not attend");

					}

					

					$("#fecha3").val("");

				}

				else{

					if(result3[1] != "0"){

						//alert(result[1]);

						$("#combo3").html(result3[1]);

					}

				}

			}



		});

	}

}





function submit_redondos(){

	if($.browser.msie || $.browser.opera) {

		$('.boton2').corner('10px');

	}

	else {

		$.jcorners('.boton2',{radius:10});

	}

}




