// JavaScript Document
var oActivoSite = null;
function activarSite(e,b,o){
	if(!!oActivoSite){
		oActivoSite['site'].style.display = 'none';
		oActivoSite['btnOn'].style.display = 'inline';
		oActivoSite['btn'].style.display = 'none';
	}
	oActivoSite = {};
	oActivoSite['site'] = $(e);
	oActivoSite['site'].style.display = 'block';
	oActivoSite['btnOn'] = $(b);
	oActivoSite['btnOn'].style.display = 'none';
	oActivoSite['btn'] = $(o);
	oActivoSite['btn'].style.display = 'inline';
};

var foco = "";
function enfocado(nombre){
	foco = nombre;
}
function desenfocado(){
	foco = "";
}

function WScreen(){ return (Nav.esIE)? document.documentElement.clientWidth : window.innerWidth; }
function HScreen(){ return (Nav.esIE)? document.documentElement.clientHeight : window.innerHeight; }
function YPos(){ return (Nav.esIE)? document.documentElement.scrollTop : window.pageYOffset; }
function XPos(){ return (Nav.esIE)? document.documentElement.scrollLeft : window.pageXOffset; }
function HBody(){ return document.documentElement.scrollHeight; }


/***************************************/
//Funciones de obtencion de datos del navegador
function getScrollPos(){
	if(Nav.esOp) return {y:window.pageYOffset, x:window.pageXOffset};
	else if(Nav.esFf || Nav.esIE) return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
	else return {x:0, y:0};
}
function getWindowDims(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else if(Nav.esFf) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
	else if(Nav.esIE) return {w:document.body.clientWidth, h:document.body.clientHeight};
	else return {w:0, h:0}
}
function getBodyWHAvaible(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
	else if(Nav.esIE || Nav.esFf) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
	else return {w:0, h:0}
}
function getBodyDims(){
	if(Nav.esOp) return {w:document.body.clientWidth, h:document.body.clientHeight};
	else if(Nav.esIE || Nav.esFf) return {w:document.body.offsetWidth, h:document.body.offsetHeight};
	else return {w:0, h:0}
}

//
function mostrarLayer(id){
	var element = id;
	var pos = getScrollPos();
	var dim = getBodyWHAvaible();
	
	element.style.display = 'inline';
	var height = element.childNodes[0].offsetHeight
	var width = element.offsetWidth;
	element.style.visibility = 'visible';
	
	element.style.left = (((dim.w-width)/2)+pos.x)+"px";
	element.style.top = (((dim.h-height)/2)+pos.y)+"px";
}
function mostrarLayer2(id){
	var element = document.getElementById(id);
	var pos = getScrollPos();
	var dim = getWindowDims();
	var height = parseInt(element.style.height);//element.offsetHeight;
	var width = parseInt(element.style.width);//element.offsetWidth;
	element.style.visibility = 'visible';
	element.style.left = (((dim.w-width)/2)+pos.x)+"px";
	element.style.top = (((dim.h-height)/2)+pos.y)+"px";
}
function eliminarNodos(obj){//v2 Gallo
	while(obj.hasChildNodes())
		for(i = 0; i < obj.childNodes.length; i++)
			obj.removeChild(obj.childNodes[i]);
}

var semaforoD = 0;
var actualD = 0;
var reqactor;
var objDet = new Array();
var zInd = 1;
function HijoDetalles(){
	var texto,contenedor;
	if (reqactor.readyState == 4) {
    	if (reqactor.status == 200) {
			texto = reqactor.responseText;
			var contenedor = objDet[actualD].principal;
			if(contenedor.childNodes[0].hasChildNodes()) eliminarNodos(contenedor.childNodes[0]);
			contenedor.childNodes[0].innerHTML = texto;
			contenedor.childNodes[1].style.width = contenedor.childNodes[0].offsetWidth+"px";
			contenedor.childNodes[1].style.height = contenedor.childNodes[0].offsetHeight+"px";
			if(contenedor.childNodes[0].offsetWidth > 350)contenedor.style.width = contenedor.childNodes[0].offsetWidth+"px";
			contenedor.style.height = contenedor.childNodes[0].offsetHeight+"px";
			contenedor.style.display = 'inline';
			if(!Nav.esIE){
				contenedor.childNodes[1].style.width = (contenedor.childNodes[0].offsetWidth-4)+"px";
				contenedor.childNodes[1].style.height = (contenedor.childNodes[0].offsetHeight-4)+"px";
			}
			else{
				contenedor.childNodes[1].style.width = (contenedor.childNodes[0].offsetWidth)+"px";
				contenedor.childNodes[1].style.height = contenedor.childNodes[0].offsetHeight+"px";
			}
			if(objDet[actualD].xInicial == '' && objDet[actualD].yInicial == '') mostrarLayer(objDet[actualD].principal);	
			semaforoD = 0;
		}
		else alert("HijoDetalles Ocurrio un problema:\n" + reqactor.statusText);
    }	
}
function ocultar(id){
	objDet[id].principal.style.display = "none";
	document.body.removeChild(objDet[id].principal); 	   		
	objDet[id] = null;
}

ventana2 = function(links){
	var y = Math.round(document.body.clientHeight/2); 
	var x = Math.round(document.body.clientWidth/2); 
	links_socios=window.open(links,'imprimir','width='+x+',height='+y+',scrollbars=yes,status=yes,menubar=yes,resizable=yes,titlebar=yes,toolbar=yes,location=yes',true);
}
ventana = function(links){
	var y = Math.round(document.body.clientHeight/2); 
	var x = Math.round(document.body.clientWidth/2); 
	links_socios=window.open(links,'socios','width='+x+',height='+y+',scrollbars=yes,status=yes,menubar=yes,resizable=yes,titlebar=yes,toolbar=yes,location=yes',true);
}

function detalles(id,ancho,alto,xInicial,yInicial,limiteX){
	this.id = id;
	this.ancho = ancho;
	this.alto = alto;
	this.xInicial = xInicial;
	this.yInicial = yInicial;
	this.intervalo = 0;
	this.principal = "";
	this.limiteX = limiteX;
}
detalles.prototype.estructura = function(id){
	var principal = document.createElement('div');
	principal.style.position = "absolute";
	principal.style.display = "none";
	principal.style.width = objDet[id].ancho+"px";
	principal.style.height = objDet[id].alto+"px";
	principal.style.left = objDet[id].xInicial+"px";
	principal.style.top = objDet[id].yInicial+"px";
	principal.style.zIndex = zInd;
	var contenedor = document.createElement('div');
	contenedor.style.position = "absolute";
	contenedor.style.zIndex = zInd+2;
	contenedor.className = "contenido";
	contenedor.style.display = "inline";
	principal.appendChild(contenedor);
	var iframe = document.createElement('iframe');
	iframe.scrolling = "no";
	iframe.frameborder = 0;
	iframe.style.zIndex = zInd+1;
	iframe.style.position = "absolute";
	iframe.style.overflow = "visible";
	principal.appendChild(iframe);
	objDet[id].principal = principal;
	document.body.appendChild(principal);
	zInd++;
}
detalles.prototype.manejador = function(id){
	if(semaforoD == 0){
		semaforoD = 1;
		if(objDet[id].intervalo != 0){
			clearInterval(objDet[id].intervalo);
			objDet[id].intervalo = 0;
		}
		objDet[id].padreDetalles(id);
	}
	else objDet[id].intervalo = setInterval(function(){objDet[id].manejador(id);},5);	
	
}
detalles.prototype.padreDetalles = function(id){
	var ids = "";
	valores="id|=|"+id+"&limiteX|=|"+objDet[id].limiteX;
	actualD = id;
	reqactor=crearXHR();
	reqactor.onreadystatechange = HijoDetalles;
	reqactor.open('POST', "xmlHttpRequest/empresa_detalle.php", true);
	reqactor.send(valores);
}
sobreponer = function(id){
	var temporal = objDet[id].principal.childNodes[0].innerHTML;
	var xTemporal = objDet[id].principal.offsetLeft+"px";
	var yTemporal = objDet[id].principal.offsetTop+"px";
	document.body.removeChild(objDet[id].principal);
	objDet[id].estructura(id);
	objDet[id].principal.childNodes[0].innerHTML = temporal;
	objDet[id].principal.style.left = xTemporal;
	objDet[id].principal.style.top = yTemporal;
	if(objDet[id].principal.childNodes[0].offsetWidth > 350)objDet[id].principal.style.width = objDet[id].principal.childNodes[0].offsetWidth+"px";
	objDet[id].principal.style.height = objDet[id].principal.childNodes[0].offsetHeight+"px";
	objDet[id].principal.style.display = "inline";
	objDet[id].principal.childNodes[1].style.width = objDet[id].principal.childNodes[0].offsetWidth+"px";
	objDet[id].principal.childNodes[1].style.height = objDet[id].principal.childNodes[0].offsetHeight+"px";	
}

function abrirDetalles(id,ancho,alto,xInicial,yInicial,limiteX){
	if(!objDet[id]){
		var det = new detalles(id,ancho,alto,xInicial,yInicial,limiteX);
		objDet[id] = det;
		objDet[id].estructura(id);
		objDet[id].manejador(id);
	}
	else sobreponer(id);
}
padreSuscribir = function(nombre,email){
	valores="nombre|=|"+nombre+"&email|=|"+email;
	reqactor=crearXHR();
	reqactor.onreadystatechange = HijoSuscribir;
	reqactor.open('POST', "xmlHttpRequest/suscribirse.php", true);
	reqactor.send(valores);
}
function HijoSuscribir(){
	var texto,contenedor;
	if (reqactor.readyState == 4) {
    	if (reqactor.status == 200) {
			texto = reqactor.responseText;
			var confirmacion = document.getElementById("confirmacion");
			var formulario = document.getElementById("formSuscribirLateral");
			var boton = document.getElementById("boton");
			if(texto != "si"){
				var mostrar = document.getElementById('errores');
				mostrar.innerHTML = texto;
				mostrar.style.display = "block";
			}
			else{
				var nombre = document.getElementById("nombre");
				var email = document.getElementById("emailsuscr");
				nombre.value = "Nombre y Apellido";
				email.value = "E-mail";
				formulario.style.display = "none";
				confirmacion.style.display = "block";
				boton.style.display = "block";
			}
		}
		else alert("HijoSuscribir Ocurrio un problema:\n" + reqactor.statusText);
    }	
}
function corroborarContacto(){
	var mensaje = "";
	var Error = "^[a-z0-9_/.]+@[a-z0-9/-]+\.[a-z]{2,4}\.{0,1}[a-z]{0,4}$";
	var fantasia = document.getElementById("fantasia");
	var direccion = document.getElementById("direccion");
	var ciudad = document.getElementById("ciudad");
	var web = document.getElementById("web");
	var email = document.getElementById("email");
	var tel1 = document.getElementById("tel1");
	if(fantasia.value == "")mensaje += "El campo nombre est&aacute; vac&iacute;o.<br>";
	if(direccion.value == "")mensaje += "El campo direcci&oacute;n est&aacute; vac&iacute;o.<br>";
	if(ciudad.value == "")mensaje += "El campo ciudad est&aacute; vac&iacute;o.<br>";
	if(web.value == "")mensaje += "El campo web est&aacute; vac&iacute;o.<br>";
	if(tel1.value == "")mensaje += "El campo telefono est&aacute; vac&iacute;o.<br>";
//if(email.value.search(Error)==-1) mensaje += "Email Incorrecto.<br>";
	if(mensaje != ""){
		var informe = document.getElementById("principal");	
		var segundo = document.createElement('div');
		segundo.style.paddingLeft = "15px";
		segundo.innerHTML = mensaje;
		var ob = informe.childNodes[0];
		if(informe.childNodes[0].childNodes[1].hasChildNodes()) eliminarNodos(informe.childNodes[0].childNodes[1]);
		informe.childNodes[0].childNodes[1].appendChild(segundo);
		//informe.childNodes[0].style.display = "inline";
		//informe.style.display = "inline";
		mostrarLayer2('principal');
	}
	else document.contacto.submit();
}
function cerrarContacto(){
	var principal = document.getElementById("principal");
	principal.style.display = "none";
}
corroborarEmail = function(email){
	valores="email|=|"+email;
	reqactor=crearXHR();
	reqactor.onreadystatechange = HijoEmail;
	reqactor.open('POST', "xmlHttpRequest/corrEmail.php", true);
	reqactor.send(valores);
}
function HijoEmail(){
	var texto,contenedor;
	if (reqactor.readyState == 4) {
    	if (reqactor.status == 200) {
			texto = reqactor.responseText;
			var confirmacion = document.getElementById("confirmacion");
			var formulario = document.getElementById("formSuscribirLateral");
			var boton = document.getElementById("boton");
			if(texto != "si"){
				var mostrar = document.getElementById('errores');
				mostrar.innerHTML = texto;
				mostrar.style.display = "block";
			}
			else{
				var nombre = document.getElementById("nombre");
				var email = document.getElementById("emailsuscr");
				nombre.value = "Nombre y Apellido";
				email.value = "E-mail";
				formulario.style.display = "none";
				confirmacion.style.display = "block";
				boton.style.display = "block";
			}
		}
		else alert("HijoEmail Ocurrio un problema:\n" + reqactor.statusText);
    }	
}

//En lateral
function hacerFoco(objeto,campo){
	if(objeto.value == campo)objeto.value = "";
}
function sacarFoco(objeto,campo){
	if(objeto.value == "")objeto.value = campo;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var oventana = null;
function abrirNuevaVentana(pagina, titulo, estilo){
	if(oventana!= null && oventana!=undefined) oventana.close();
	oventana = window.open(pagina, titulo, estilo);
	oventana.focus();
}

/***************************************/
//Funcion: centrar un oPopup en la ventana
var globalZIndex = 9;
function popupAbrir(obj){
	//
	obj.l.style.display = "block";
	obj.f.style.display = "block";
	//
	obj.l.style.position = 'absolute';
	obj.c.style.position = 'absolute';
	obj.f.style.position = 'absolute';
	obj.l.style.zIndex = globalZIndex;
	obj.c.style.zIndex = globalZIndex-1;
	obj.f.style.zIndex = globalZIndex-2;
	obj.c.style.display  = 'block';
	//
	globalZIndex = globalZIndex+3;
	//
	var pos = getScrollPos();
	var scrn = getBodyWHAvaible();
	var dim = getBodyDims();

	//
	if(scrn.h - obj.c.offsetHeight <= 0) obj.l.style.top = pos.y + "px";
	else obj.l.style.top = (pos.y + ((scrn.h - obj.c.offsetHeight)/2)) + "px";
	obj.l.style.left = ((scrn.w - obj.c.offsetWidth) / 2) + "px";
	//
	obj.f.style.top 		= 0;
	obj.f.style.left 		= 0;
	obj.f.style.width 		= scrn.w + 'px';
	//
	obj.l.style.visibility 	= "visible";
	obj.f.style.visibility 	= "visible";
	//

	if((parseInt(obj.l.style.top) + obj.c.offsetHeight) < dim.h) obj.f.style.height = (dim.h + ((Nav.esIE)? 18:0)) + "px";
	else obj.f.style.height = (obj.c.offsetHeight + parseInt(obj.l.style.top) + 10) + "px";
	if(obj.f.offsetHeight < scrn.h)obj.f.style.height = scrn.h+'px';
}
function popupCerrar(obj){
	obj.f.style.visibility 	= "hidden";
	obj.l.style.visibility 	= "hidden";
	obj.f.style.display 	= "none";
	obj.l.style.display 	= "none";
}

