window.addEvent('domready', function() {
	hoverImg();
});

function hoverImg(){
	$$('.borde-imagenes img').addEvents({
	mouseenter: function(){
		this.fade(0.6);
	},
	mouseleave: function(){
	   this.fade(1);
	}
	});
}

function aunNoDisponible(){
	alert("En construcción.\n\nEn breve estaremos actualizando esta sección. Disculpe las molestias.");
	return false;
}

function get_portfolio_todos(page){
	if (page==""){
		var page = Cookie.read('page_todos');
		if (!page) page = 1;		
	}
	laurl = "portfolio_todos_page_"+page+".html";
	
	new Request({
		url: laurl,
		method: 'get',
		onRequest: function(){
			$('html_portfolio_page').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('html_portfolio_page').set('html', txt);
			hoverImg();
			Cookie.write('page_todos', page, {duration: 1});
		},
		onFailure: function(){
			$('html_portfolio_page').set('text', 'Ha fallado el requerimiento..');
			Cookie.dispose('page_todos');
		}
	}).send();	
}

function get_portfolio(page){
	if (page==""){
		var page = Cookie.read('page');
		if (!page) page = 1;		
	}
	laurl = "portfolio_page_"+page+".html";
	
	new Request({
		url: laurl,
		method: 'get',
		onRequest: function(){
			$('html_portfolio_page').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('html_portfolio_page').set('html', txt);
			hoverImg();
			Cookie.write('page', page, {duration: 1});
		},
		onFailure: function(){
			$('html_portfolio_page').set('text', 'Ha fallado el requerimiento..');
			Cookie.dispose('page');
		}
	}).send();	
}



function get_novedades(){
	new Request({
		url: 'div_novedades.html',
		method: 'get',
		onRequest: function(){
			$('div_casosestudio').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_novedades').set('html', txt);
			new JFeedMoo('div.novedades','btnNovPrev','btnNovNext');
		},
		onFailure: function(){
			$('div_novedades').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_testimonios(){
	new Request({
		url: 'div_testimonios.html',
		method: 'get',
		onRequest: function(){
			$('div_testimonios').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_testimonios').set('html', txt);
			new JFeedMoo('div.testimonios','btnTestiPrev','btnTestiNext').playing(10000,false);	
		},
		onFailure: function(){
			$('div_testimonios').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_etapas_proceso(){
	new Request({
		url: 'div_etapas_proceso.html',
		method: 'get',
		onRequest: function(){
			$('div_etapas').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_etapas').set('html', txt);			
		},
		onFailure: function(){
			$('div_etapas').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_clientes_lista(){
	new Request({
		url: 'div_clientes_lista.html',
		method: 'get',
		onRequest: function(){
			$('div_clientes').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_clientes').set('html', txt);			
		},
		onFailure: function(){
			$('div_clientes').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_casosestudio(){
	new Request({
		url: 'div_casosestudio.html',
		method: 'get',
		onRequest: function(){
			$('div_casosestudio').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_casosestudio').set('html', txt);
			new JFeedMoo('div.casosestudio','btnCasoPrev','btnCasoNext');
		},
		onFailure: function(){
			$('div_casosestudio').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();
}

function get_clientes(){
	new Request({
		url: 'div_clientes.html',
		method: 'get',
		onRequest: function(){
			$('div_clientes').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_clientes').set('html', txt);
			(new JFeedMoo('img.clientes','btnClientesPrev','btnClientesNext')).playing(4000,false);
		},
		onFailure: function(){
			$('div_clientes').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_contacto(){
	var req = new Request({
		url: 'div_contacto.html',
		method: 'get',
		onRequest: function(){
			$('div_contacto').set('text', '');
		},
		onSuccess: function(txt){
			$('div_contacto').set('html', txt);
			$("resultado_div_contacto").fade('hide');
			$("resultado_div_contacto").style.display = "none";
			set_contacto_rapido();
		},
		onFailure: function(){
			$('div_contacto').set('text', 'Ha fallado el requerimiento..');
		}
	});
	req.send();	
}

function set_contacto_rapido(){
	respOk = "<p style='padding:10px;'><br /><img src='imagenes/imgCheck.png'/><br /><br />El mensaje ha sido enviado.<br />En breve le estaremos respondiendo.<br /><br />Muchas Gracias</p>";
	respNotOk1 = "<p style='padding:10px;'><br /><img src='imagenes/imgError.png'/><br /><br />Por favor, complete todos los campos del formulario.</p>";
	respNotOk2 = "<p style='padding:10px;'><br /><img src='imagenes/imgError.png'/><br /><br />Por favor, ingrese un email valido.</p>";	
	$("form_contacto_rapido").addEvent('submit', function(e) {
		e.stop();
		this.set('send', {
			 onRequest: function(){
				$('loading_div_contacto').set('html', '<img src="imagenes/ajax-loader.gif" />');
			},
			onSuccess: function(respuesta) { 
				$('loading_div_contacto').set('html', '');
				
				$("resultado_div_contacto").style.display = "";
				
				if (respuesta=="0"){
					$('resultado_div_contacto').set('html', respOk);
					$("form_contacto_rapido").reset();
				}
				if (respuesta=="1"){
					$('resultado_div_contacto').set('html', respNotOk1);
				}
				if (respuesta=="2"){
					$('resultado_div_contacto').set('html', respNotOk2);
				}				
				
				$("tabla_contacto").style.display = "none";
				$("resultado_div_contacto").fade(1);
				
				setTimeout(function() { $("resultado_div_contacto").fade('hide');$('resultado_div_contacto').style.display = "none";$("tabla_contacto").style.display = "";$("tabla_contacto").fade('hide');$("tabla_contacto").fade(1); },3000);				
			}
		});
		this.send();
	});	
}

function set_contacto(){
	respOk = "<p style='font-size:13pt;'>El mensaje ha sido enviado. En breve le estaremos respondiendo.<br /><br />Muchas Gracias</p>";
	respNotOk1 = "<p style='color:#d40000;'>Por favor, complete los campos requeridos del formulario.</p>";
	respNotOk2 = "<p style='color:#d40000;'>Por favor, ingrese un email valido.</p>";	
	$("form_contacto").addEvent('submit', function(e) {
		e.stop();
		this.set('send', {
			 onRequest: function(){
				$('loading_div_contacto').set('html', '<img src="imagenes/ajax-loader.gif" />');
			},
			onSuccess: function(respuesta) { 
				
				if (respuesta=="0"){
					$('loading_div_contacto').set('html', respOk);
					$("form_contacto").reset();
				}
				if (respuesta=="1"){
					$('loading_div_contacto').set('html', respNotOk1);					
				}
				if (respuesta=="2"){
					$('loading_div_contacto').set('html', respNotOk2);
					$('email').focus();
				}				
				
				setTimeout(function() {$('loading_div_contacto').set('html', ""); },5000);				
			}
		});
		this.send();
	});	
}

