
// JavaScript Document

//Configs de los banners


var timeBann;
var transparencyBann = 0;

var tiempovista = 7;
var banner_actual = 0;
var cant_banners = 5;

var timeElement;
var transparencyElem = 0;

function fadeInBann(elemento) {
  //incrementamos el valor
  transparencyBann += 2; 
  //si termino la trnsicion borramos el intervalo
  transparencyBann = (transparencyBann == 100) ? clearInterval(timeBann) : transparencyBann;
  //seteamos al div como objeto para poder usarlo
  obj = document.getElementById(elemento);
  //programamos cada navegador por separado
  if (document.all){ 
    //esto es para IE, como siempre hay q programarlo a parte
    obj.style.filter = 'alpha(opacity='+transparencyBann+')';
  }else{
    // Safari 1.2, posterior Firefox y Mozilla, CSS3
    obj.style.opacity = transparencyBann /100;
    
    // anteriores Mozilla y Firefox
    obj.style.MozOpacity = transparencyBann /100;
    
    // Safari anterior a 1.2, Konqueror
    obj.style.KHTMLOpacity = transparencyBann /100;  
  } 
};
function fadeIn(elemento) {
  //incrementamos el valor
  transparencyElem += 5; 
  //si termino la trnsicion borramos el intervalo
  transparencyElem = (transparencyElem == 100) ? clearInterval(timeElement) : transparencyElem;
  //seteamos al div como objeto para poder usarlo
  obj = document.getElementById(elemento);
  //programamos cada navegador por separado
  if (document.all){ 
    //esto es para IE, como siempre hay q programarlo a parte
    obj.style.filter = 'alpha(opacity='+transparencyElem+')';
  }else{
    // Safari 1.2, posterior Firefox y Mozilla, CSS3
    obj.style.opacity = transparencyElem /100;
    
    // anteriores Mozilla y Firefox
    obj.style.MozOpacity = transparencyElem /100;
    
    // Safari anterior a 1.2, Konqueror
    obj.style.KHTMLOpacity = transparencyElem /100;  
  } 
};


function RotarBanner(){
	
	if(banner_actual + 1 >cant_banners){
		banner_actual = 1;	
	}else{
		banner_actual = banner_actual + 1;	
	}
	document.getElementById("ContenidoBanner").style.backgroundImage = "url(imgs/banner/bann"+banner_actual+".jpg)";
	//vuelvo la transparencia a 0
	transparencyBann = 0;
	
	//Lo inicializo todo transparente
	obj = document.getElementById("ContenidoBanner");
	if (document.all){ 
    //esto es para IE, como siempre hay q programarlo a parte
    obj.style.filter = 'alpha(opacity='+transparencyBann+')';
  		}else{
    // Safari 1.2, posterior Firefox y Mozilla, CSS3
    obj.style.opacity = 0;
    
    // anteriores Mozilla y Firefox
    obj.style.MozOpacity = 0;
    
    // Safari anterior a 1.2, Konqueror
    obj.style.KHTMLOpacity = 0;  
  } 
	//creo el timer para comenzar a aclararlo
	timeBann = setInterval("fadeInBann('ContenidoBanner')",50);
}
//---------







//Ajax para enviar datos
function ajaxDatos(){
	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 MostrarFrmConsulta(tipo){
	document.getElementById("popupConsulta").style.display = "block";
	
	CargarFormConsulta(tipo);
	
}
function CerrarFrmConsulta(){
	document.getElementById("popupConsulta").style.display = "none";
	}


function CargarFormConsulta(tipo){
	
	var contenedor;
	
	contenedor = document.getElementById('contenidoConsulta');
	
	ajax=ajaxDatos();
	ajax.open("POST", "FrmConsultarServicio.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(
		"tipo="+tipo
	)
}

function ValidarEmail(valor){
	var s = valor;
	var filtro=/^[A-Za-z_.][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (filtro.test(s)){ return true;}else{return false;}
}
function ValidarCamposConsulta(){
	estado = true;
	
	nombre = document.getElementById("txtConsultaNombre").value;
	email = document.getElementById("txtConsultaEmail").value;
	mensaje = document.getElementById("txtConsultaConsulta").value;
	
	val_email = ValidarEmail(email);
	

	
	if(nombre.length < 2 ){ estado = false;}
	if(val_email==false){ estado = false;}
	if(mensaje.length < 2 ){ estado = false;}
	

	if(estado==false){
		document.getElementById("ErrorConsulta").style.display = "block";
	}else{
		document.getElementById("ErrorConsulta").style.display = "none";
	}
	return estado;
	
}
function EnviarEmail(){
	estado = ValidarCamposConsulta();
	if(estado){
		var nombre, empresanegocio, email, mensaje, tipo_consulta, contenedor;
		resultado = document.getElementById("ConsultaCampos");
		
		nombre = document.getElementById("txtConsultaNombre").value;
		empresanegocio = document.getElementById("txtConsultaEmpresaNegocio").value;
		email = document.getElementById("txtConsultaEmail").value;
		mensaje = document.getElementById("txtConsultaConsulta").value;
		tipo_consulta = document.getElementById("txtConsultaTipo").value;
		telefono = document.getElementById("txtConsultaTelefono").value;
		
		ajax=ajaxDatos();
		ajax.open("POST", "EnviarConsultaServicio.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				
				resultado.innerHTML = ajax.responseText
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(
			"nombre="+nombre
			+"&empresanegocio="+empresanegocio
			+"&email="+email
			+"&mensaje="+mensaje
			+"&tipo_consulta="+tipo_consulta
			+"&telefono="+telefono
		)
	}
}
