//Javascript

document.observe('dom:loaded',function(){
									   
	
	var userAgent = navigator.userAgent;
	var version = parseFloat(navigator.appVersion);
	var navegadores = new Array();
	navegadores["msie"] = navegadorIE;
	navegadores["firefox"] = navegadorFirefox;
	navegadores["opera"] = navegadorOpera;
	
	
	var funcion = navegadorDesconocido;
	for (var navegador in navegadores) {
		
		if (userAgent.toLowerCase().indexOf(navegador) != -1) {
			
			funcion = navegadores[navegador];
			break;
		}
	}
	
	if(funcion(version))
		redirecciona();

									   
		if($('form1'))
		{
			$('imagenArchivo').observe('change',function(){
						
					var nombreCorto =   $('imagenArchivo').value.match(/[^\/\\]+$/);
					nombreCorto = nombreCorto.toString();
					var nuevoNombre = nombreCorto.substring(0,nombreCorto.indexOf("."));
					$('descripcion').value  = nuevoNombre;

				
			});
			
			$('form1').observe('submit',function(event){
												
				if($('descripcion').value == ""){
					$('validarDescripcion').innerHTML = "El campo de la descripci&oacute;n no puede ir Solo";
					Event.stop(event);
				}
				
				if($("imagenArchivo").value == ""){
					$('validarImagen').innerHTML = "El campo de la imagen no puede ir vac&iacute;o, favor de verificarlo";
					Event.stop(event);
				}
				
			});
		}
		
		if($('form3'))
		{
			$('form3').observe('submit',function(event){
					
					if($F('idQuitarImagen') == ""){
						$('validarId').update('El campo no puede ir vac&iacute;o favor de verificarlo.');
						$('idQuitarImagen').focus();
						Event.stop(event);
					}
					if($F('idQuitarImagen').match(/^\d+$/) == null){
						$('validarId').update('El campo no puede ir vac&iacute;o favor de verificarlo.');
						$('idQuitarImagen').focus();
						Event.stop(event);
					}
			});
		}
		
		if($('nuestraEmpresa')){
		
		$('nuestraEmpresa').observe('click',function(event){
				$('imagenCambia').fade(
				{
					fps:50,
					limit:1,
					afterFinish:function()
					{
						if(!$('imagenLoad').visible())$('imagenLoad').show();	

						new Ajax.Updater('imagenCambia','secciones/nuestraEmpresa.html',
						{
							onLoading:$('imagenLoad').addClassName('loading'),
							method:'get',
							onComplete:function()
							{ 
								$('imagenCambia').setStyle({background:'#FFFFFF'});
								$('imagenLoad').fade(); 
								$('imagenCambia').appear({queue:'end'});
							}
						});
					}
				});
		 event.stop();
		});
		}
		
		if($('nuestrasTiendas')){
		
		$('nuestrasTiendas').observe('click',function(event){
				$('imagenCambia').fade(
						{
							fps:50,
							limit:1,
							afterFinish:function()
							{
								if(!$('imagenLoad').visible())$('imagenLoad').show();	
		
								new Ajax.Updater('imagenCambia','secciones/nuestrasTiendas.html',
								{
									onLoading:$('imagenLoad').addClassName('loading'),
									method:'get',
									onComplete:function()
									{ 
										$('imagenCambia').setStyle({background:'#FFFFFF'});
										$('imagenLoad').fade(); 
										$('imagenCambia').appear({queue:'end'});
									}
								});
							}
						});
				event.stop();
				});	
		}
		
		//Sección del despliege del catálogo
		
		if($('catalogo')){
		
		$('catalogo').observe('click',function(event){
				$('imagenCambia').fade(
						{
							fps:50,
							limit:1,
							afterFinish:function()
							{
								if(!$('imagenLoad').visible())$('imagenLoad').show();	
		
								new Ajax.Updater('imagenCambia','secciones/catalogo.html',
								{
									onLoading:$('imagenLoad').addClassName('loading'),
									method:'get',
									onComplete:function()
									{ 
										$('imagenCambia').setStyle({background:'#FFFFFF'});
										$('imagenLoad').fade(); 
										$('imagenCambia').appear({queue:'end'});

										
										$$('.catalogos').invoke('observe','mouseover',function(event){
							
													var id = this.id;
													$('imagenSeccion').hide();
													$('imagenSeccion').update("<img src='img/catalogo/"+id+".jpg'/>");
													$('imagenSeccion').appear();
										});
										
										$$('.catalogos').invoke('observe','click',function(event){
											
											var id = this.id;
											
											$('imagenCambia').fade(
											{
												fps:50,
												limit:1,
												afterFinish:function()
												{
													if(!$('imagenLoad').visible())$('imagenLoad').show();
											
													new Ajax.Updater('imagenCambia','secciones/galeria.php',
													{
														onLoading:$('imagenLoad').addClassName('loading'),
														method:'get',
														parameters:{
															categoria:id,pag:1,
															sid:Math.random()
														},
														onComplete:function()
														{
															$('imagenLoad').fade();
															//$('imagenCambia').setStyle({backgroundImage:'url(img/catalogo2/'+id+'2.jpg)',backgroundRepeat:'no-repeat'});
															$('imagenCambia').appear({queue:'end'});
															
														}
													});
												}
											});
													
											event.stop();
										});
										
										
									}
								});
							}
						});
				event.stop();
				});	
		
		}
		//Seccion de la parte de contacto
		
		if($('contacto')){
		
		$('contacto').observe('click',function(event){
			$('imagenCambia').fade(
						{
							fps:50,
							limit:1,
							afterFinish:function()
							{
								if(!$('imagenLoad').visible())$('imagenLoad').show();	
		
								new Ajax.Updater('imagenCambia','secciones/contacto.html',
								{
									onLoading:$('imagenLoad').addClassName('loading'),
									method:'get',
									onComplete:function()
									{ 
										$('imagenCambia').setStyle({background:'#FFFFFF'});
										$('imagenLoad').fade(); 
										$('imagenCambia').appear({queue:'end'});
										
										$('form2').observe('submit',function(event){
											
											// empiezo validaciones 
											
											if($F('nombre') == ""){
												$('validarNombreContacto').update('El nombre no puede ir vac&iacute;o, favor de verificarlo');
												Event.stop(event);
												return false;
											}else{
												$('validarNombreContacto').addClassName('correcta');
												$('validarNombreContacto').update('La informaci&oacute;n es correcta,gracias.');
											}
											
											
											if($F('email') == ""){
												$('validarEmailContacto').update('El email no puede ir vac&iacute;o, favor de verificarlo');
												Event.stop(event);
												return false;
											}else{
												if($F('email').match(/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/) == null){
														$('validarEmailContacto').update('El email que proporcionaste no es v&aacute;lido, favor de verificarlo');
														Event.stop(event);
														return false;
												}else{
													$('validarEmailContacto').addClassName('correcta');
													$('validarEmailContacto').update('La informaci&oacute;n es correcta, gracias.');
												}
												
											}
											
											
											if($F('asunto') == ""){
												$('validarAsuntoContacto').update('El asunto no puede ir vac&iacute;o, favor de verificarlo');
												Event.stop(event);
												return false;
											}else{
												$('validarAsuntoContacto').addClassName('correcta');
												$('validarAsuntoContacto').update('La informaci&oacute;n es correcta, gracias.');
											}
											
											
											if($F('mensaje') == ""){
												$('validarMensajeContacto').update('El mensaje no puede ir vac&iacute;o, favor de verificarlo');
												Event.stop(event);
												return false;
											}else{
												$('validarMensajeContacto').addClassName('correcta');
												$('validarMensajeContacto').update('La informaci&oacute;n es correcta, gracias.');
											}
											
											
											Event.stop(event);
											$('imagenCambia').fade(
											{
												fps:50,
												limit:1,
												afterFinish:function()
												{
													if(!$('imagenLoad').visible())$('imagenLoad').show();
													new Ajax.Updater('imagenCambia','secciones/contacto.php',{
														onLoading:$('imagenLoad').addClassName('loading'),
														parameters:
														{
															nombre:$F('nombre'),
															email:$F('email'),
															asunto:$F('asunto'),
															mensaje:$F('mensaje')
														},
														onComplete:function()
														{
															$('imagenLoad').fade();
															$('imagenCambia').appear({queue:'end'});
														}
														
													});
												}
											});
											
										});
										
									}
								});
							}
			});
		});
		
	
		}
		
		
});


function paginar(numero,categoria)
{
	$('imagenCambia').fade(
	{
		fps:50,
		limit:1,
		afterFinish:function()
		{
			if(!$('imagenLoad').visible())$('imagenLoad').show();
	
			new Ajax.Updater('imagenCambia','secciones/galeria.php',
			{
				onLoading:$('imagenLoad').addClassName('loading'),
				method:'get',
				parameters:{categoria:categoria,pag:numero},
				onComplete:function()
				{
					$('imagenLoad').fade();
					$('imagenCambia').appear({queue:'end'});
				}
			});
		}
	});
}


function regresarCatalogo()
{
	$('imagenCambia').fade(
	{
		fps:50,
		limit:1,
		afterFinish:function()
		{
			if(!$('imagenLoad').visible())$('imagenLoad').show();
	
			new Ajax.Updater('imagenCambia','secciones/catalogo.html',
			{
				onLoading:$('imagenLoad').addClassName('loading'),
				method:'get',
				onComplete:function()
				{
					$('imagenCambia').setStyle({background:'#FFFFFF'});
					$('imagenLoad').fade();
					$('imagenCambia').appear({queue:'end'});
					
					
					$$('.catalogos').invoke('observe','mouseover',function(event){
							
								var id = this.id;
								$('imagenSeccion').hide();
								$('imagenSeccion').update("<img src='img/catalogo/"+id+".jpg'/>");
								$('imagenSeccion').appear();
					});
					
					$$('.catalogos').invoke('observe','click',function(event){
											
						var id = this.id;
						
						$('imagenCambia').fade(
						{
							fps:50,
							limit:1,
							afterFinish:function()
							{
								if(!$('imagenLoad').visible())$('imagenLoad').show();
						
								new Ajax.Updater('imagenCambia','secciones/galeria.php',
								{
									onLoading:$('imagenLoad').addClassName('loading'),
									method:'get',
									parameters:{categoria:id,pag:1},
									onComplete:function()
									{
										$('imagenLoad').fade();
										//$('imagenCambia').setStyle({backgroundImage:'url(img/catalogo2/'+id+'2.jpg)',backgroundRepeat:'no-repeat'});
										$('imagenCambia').appear({queue:'end'});
									}
								});
							}
						});
								
						event.stop();
					});
				}
			});
		}
	});
}

function regresarContacto()
{
	$('imagenCambia').fade(
	{
		fps:50,
		limit:1,
		afterFinish:function()
		{
			if(!$('imagenLoad').visible())$('imagenLoad').show();
	
			new Ajax.Updater('imagenCambia','secciones/contacto.html',
			{
				onLoading:$('imagenLoad').addClassName('loading'),
				method:'get',
				onComplete:function()
				{
					$('imagenLoad').fade();
					$('imagenCambia').appear({queue:'end'});
					
					$('form2').observe('submit',function(event){
											
						// empiezo validaciones 
						
						if($F('nombre') == ""){
							$('validarNombreContacto').update('El nombre no puede ir vac&iacute;o, favor de verificarlo');
							Event.stop(event);
							return false;
						}else{
							$('validarNombreContacto').addClassName('correcta');
							$('validarNombreContacto').update('La informaci&oacute;n es correcta,gracias.');
						}
						
						
						if($F('email') == ""){
							$('validarEmailContacto').update('El email no puede ir vac&iacute;o, favor de verificarlo');
							Event.stop(event);
							return false;
						}else{
							if($F('email').match(/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/) == null){
									$('validarEmailContacto').update('El email que proporcionaste no es v&aacute;lido, favor de verificarlo');
									Event.stop(event);
									return false;
							}else{
								$('validarEmailContacto').addClassName('correcta');
								$('validarEmailContacto').update('La informaci&oacute;n es correcta, gracias.');
							}
							
						}
						
						
						if($F('asunto') == ""){
							$('validarAsuntoContacto').update('El asunto no puede ir vac&iacute;o, favor de verificarlo');
							Event.stop(event);
							return false;
						}else{
							$('validarAsuntoContacto').addClassName('correcta');
							$('validarAsuntoContacto').update('La informaci&oacute;n es correcta, gracias.');
						}
						
						
						if($F('mensaje') == ""){
							$('validarMensajeContacto').update('El mensaje no puede ir vac&iacute;o, favor de verificarlo');
							Event.stop(event);
							return false;
						}else{
							$('validarMensajeContacto').addClassName('correcta');
							$('validarMensajeContacto').update('La informaci&oacute;n es correcta, gracias.');
						}
						
						
						Event.stop(event);
						$('imagenCambia').fade(
						{
							fps:50,
							limit:1,
							afterFinish:function()
							{
								if(!$('imagenLoad').visible())$('imagenLoad').show();
								new Ajax.Updater('imagenCambia','secciones/contacto.php',{
									onLoading:$('imagenLoad').addClassName('loading'),
									parameters:
									{
										nombre:$F('nombre'),
										email:$F('email'),
										asunto:$F('asunto'),
										mensaje:$F('mensaje')
									},
									onComplete:function()
									{
										$('imagenLoad').fade();
										$('imagenCambia').appear({queue:'end'});
									}
									
								});
							}
						});
						
					});
					
				}
			});
		}
	});
}


function navegadorIE(version) {
	if (typeof document.body.style.maxHeight == "undefined") {
		alert("Tu navegador no soporta la página, favor de actualizar a internet explorer 7, safari, opera 9 o FireFox 2.0 en adelante");
		return true;
	} else {
			
			return false;
		}
}

function redirecciona()
{
	setTimeout(window.location = "http://www.mozilla-europe.org/es/firefox/",3000);
}

function navegadorFirefox(){ return false;}
function navegadorOpera(){ return false;}
function navegadorDesconocido(){ return false;}

















/*afterFinish: function()
	{
		if(!$('imagenLoad').visible())$('imagenLoad').show();	

		new Ajax.Updater('imagenCambia', 'secciones/nuestraEmpresa.html',
		 {
			onLoading:$('imagenLoad').addClassName('loading'),
			method:'get',
			//onLoaded:$('imagenLoad').fade(),
			onSuccess:function()
			{
				$('imagenLoad').fade();
				$('imagenCambia').appear({fps:50,queue:'end'});
			
			},

		});
	}
*/
					
					

/*PRACTICA JQUERY*/

/*$("#imagenLoad").ajaxStart(function(){
					$(this).addClass('loading');
					$(this).show();
				});
				$("#imagenLoad").ajaxStop(function(){
					$(this).hide();
					$(this).removeClass('loading');
				});
				
$("#imagenLoad").bind("ajaxSend", function(){
						$(this).addClass('loading');
						$(this).show();
					 }).bind("ajaxComplete", function(){
						$(this).hide();
					 });

				$.ajax({
					url: "secciones/nuestraEmpresa.html",
					cache:false,
					success:function(html)
					{
						$('#imagenCambia').fadeIn(1000);
						$('#imagenCambia').html(html);
					}
				});
				
				*/
				
/*$(document).ready(function(){
		
		/*$('#nuestraEmpresa').click(function()
		{
			$('#imagenCambia').fadeOut(1000,function()
			{
				if(!$('#imagenLoad:visible')) $('#imagenLoad').show();
				
				//$('#imagenLoad').addClass('loading');
				//$('#imagenLoad').fadeIn(1000);
				$('#imagenLoad').hide();
				
				$("#imagenLoad").bind("ajaxSend", function(){
						alert($(this).length+"stoy la de arribita del this class que no junciona");
						$(this).addClass('loading');
						$(this).show();
					 }).bind("ajaxComplete", function(){
						$(this).hide();
					 });
			
				
				$('#imagenCambia').load("secciones/nuestraEmpresa.html",function(){
											
				alert($('#imagenLoad').size()+"Soy la de abajo del ajax load");
					//$('#imagenLoad').fadeOut(1000);	
					$('#imagenCambia').fadeIn(1000);
					
				});

			});
			return false;
		});  Aqui va otro!!
		
		
		$('#nuestraEmpresa').click(function() {
			$('#imagenCambia').fadeOut(1000,function() {

				$("#imagenLoad").addClass('loading');
				$('#imagenCambia').load("secciones/nuestraEmpresa.html",function(){

					$("#imagenLoad").hide();
					$('#imagenCambia').fadeIn(1000);
				});

			});
				return false;
		});
});	*/

