var objToExpH;
var objToExpV;
var tH;
var tV
var h;
var w;
var inc = 5;/*20*/
var minV = 0;/*0*/
var maxV = 290;/*290*/
var minH = 0;/*52*/
var maxH = 380;/*780*/
var elementsVer=new Array();
var elementsHor=new Array();

///////////Move
var xe;
var xe_var;
var _x;
var speed;
var comp_movil;
var menu_actual=0;
var to;

////////cambio de imagenes del fondo en el cuadro de informacion
var banners;
var imgs;
var cont_banner;
var banner_actual=0;
var tbann;
var intervalo_banners=5000;
var alfaBanner=100;

//////////////otras variables
var esIndex = false;
var esQuienes = false;
var esServicios = false;

/*********************************************************************************************************************************************
									funciones para deslizar botones
*********************************************************************************************************************************************/

function getElements(tipos,num){
	for(i=0;i<tipos.length;i++){
		for(j=1;j<=num[i];j++){
			if(i==0)
				elementsVer.push(document.getElementById(tipos[i]+j));
			else
				elementsHor.push(document.getElementById(tipos[i]+j));
		}
	}
	if(elementsHor[0])
		showH(elementsHor[0]);
	if(elementsVer[0])
		showV(elementsVer[0]);		
}
	
function showV(obj){
	objToExpV = obj;
	h = Number(objToExpV.style.height.substr(0,objToExpV.style.height.indexOf("p")));
	if(h==0) h = minV;
	expandV();
}
			
function expandV(){
	if (h <= maxV){
		var n=resizeOthersV();
		h+=(inc*n);
		objToExpV.style.height=h+"px";
		tV=setTimeout("expandV()", 5);
	}
	else
		clearTimeout(tV);
}
			
function resizeOthersV(){
	var n=0;
	for(i=0;i<elementsVer.length;i++){
		if(elementsVer[i].id != objToExpV.id){
			h2=Number(elementsVer[i].style.height.substr(0,elementsVer[i].style.height.indexOf("p")));
			if(h2 > minV){
				h2-=inc;
				elementsVer[i].style.height=h2+"px";
				n++;
			}
		}
	}
	if(n==0)n=1;
	return n;
}

function showH(obj){
	objToExpH = obj;
	w = Number(objToExpH.style.width.substr(0,objToExpH.style.width.indexOf("p")));
	if(w==0) w = minH;
	expandH();
}
			
function expandH(){
	if (w <= maxH){
		var n=resizeOthersH();
		if(n==0)n=1;
		w+=(inc*n);
		objToExpH.style.width=w+"px";
		tH=setTimeout("expandH()", 5);
	}
	else
		clearTimeout(tH);
}
	
function resizeOthersH(){
	var n=0;
	for(i=0;i<elementsHor.length;i++){
		if(elementsHor[i].id != objToExpH.id){
			w2=Number(elementsHor[i].style.width.substr(0,elementsHor[i].style.width.indexOf("p")));
			if(w2 > minH){
				w2-=inc;
				elementsHor[i].style.width=w2+"px";
				n++;
			}
		}
	}
	return n;
}

/*********************************************************************************************************************************************
										funciones para mostrar noticias
*********************************************************************************************************************************************/

function loading () {
	getElements(new Array('ver','hor'), new Array(0,2));
	mostrarNoticia (1);
	cambiaImagenIndex ();
	if (!esIndex)
		document.getElementById('cabeceraPestanaInforme').style.visibility = "visible";
	setTimeout('iniciarDesplazamiento()',500);
	setTimeout('desplazarTipoDeCambio()',500);
}


function mostrarNoticia (id) {
	clearTimeout(to);
	for (x = 1; x <= registros; x++)
		document.getElementById('linkId_not'+x).style.textDecoration="none";
		
	move(document.getElementById('divGrande'),id-1,6);
	
	document.getElementById('linkId_not'+id).style.textDecoration="underline";
	
	//activar boton anterior
	if (id == 1)
		document.getElementById('botonAnterior').innerHTML = '<img src="img/botonAnterior.jpg" />';
	else {
		document.getElementById('botonAnterior').innerHTML = '<img src="img/botonAnterior2.jpg" />';
		document.getElementById('botonAnterior').onclick = function (){ mostrarNoticia (id-1)};
	}
	
	//activar boton siguiente
	if (id == registros)
		document.getElementById('botonSiguiente').innerHTML = '<img src="img/botonSiguiente.jpg" />';
	else {
		document.getElementById('botonSiguiente').innerHTML = '<img src="img/botonSiguiente2.jpg" />';
		document.getElementById('botonSiguiente').onclick = function () {mostrarNoticia (id+1)};
	}
}

function iniciarDesplazamiento(){
	if (!esIndex) { 
		if (esQuienes) {
			animarHorizontal(1);
			document.getElementById('barrasDes').style.visibility="visible";
		}
		if (esServicios) {
			animarHorizontal(6);
			document.getElementById('barrasDes').style.visibility="visible";
		}
	}
}

var distanciaCinto;

function desplazarTipoDeCambio () {
	if (distanciaCinto == null)
		distanciaCinto = 0;
	if (distanciaCinto == -854)
		distanciaCinto = 854;
	distanciaCinto--;
	document.getElementById('frameNoticiaPieDePagina2').style.left = distanciaCinto+"px";
	setTimeout('desplazarTipoDeCambio()',10);
}

/*********************************************************************************************************************************************
							funciones de login, para ocultar o mostrarlo
*********************************************************************************************************************************************/

var tout;

function animarHorizontal(opcId){
	showH(document.getElementById('hor1'));
	tout=setTimeout('cambiarInfo('+opcId+')',1000);
}


/*********************************************************************************************************************************************
									funcones para realizar cambios en las botones animados
*********************************************************************************************************************************************/

function cambiarInfo(opcId){
	clearTimeout(tout);
	document.getElementById('hor1').style.width="380px";
	var borde = document.getElementById('BORDE');
	if (borde) {
		borde.style.width = "386px";
		borde.style.height = '63px';
		borde.style.background = 'url(img/bg_titulo.jpg) no-repeat';
	}
	
	switch (opcId) {
		case 1 : document.getElementById('TITULO').innerHTML = "PERFIL";
				 document.getElementById('CUERPO').innerHTML = "Desde nuestra fundaci&oacute;n en 1998 en la ciudad de Aguascalientes nos hemos caracterizado por ser una empresa especializada y comprometida en proporcionar servicios de comercio exterior de la m&aacute;s alta calidad, participando activamente con la comunidad de negocios tanto en M&eacute;xico como en el extranjero, con una red de oficinas localizadas estrat&eacute;gicamente en puertos del Golfo de M&eacute;xico y del pac&iacute;fico, aduanas interiores franja fronteriza y en Estados Unidos.<br /><br />Hemos establecido y fortalecido alianzas estrat&eacute;gicas con empresas l&iacute;deres en servicios integrales de comercio exterior, para garantizar la excelencia en las operaciones de nuestros clientes.<br /><br />En Jorge Rivera Agencias Aduanales, trabajamos diariamente para construir seguridad, valor y confianza.<br /><br /><br />";
				 break;
		case 2 : document.getElementById('TITULO').innerHTML = "FILOSOF&Iacute;A";
				 document.getElementById('CUERPO').innerHTML = "Tenemos una Misi&oacute;n bastante clara la cual es prestar servicios de comercio exterior con calidad, oportunidad y eficiencia.<br />Nuestra filosof&iacute;a es garantizar la satisfacci&oacute;n de nuestros clientes.<br /><br />";
				 break;
		case 3 : document.getElementById('TITULO').innerHTML = "VALORES";
				 document.getElementById('CUERPO').innerHTML = "Nuestros valores son:<br /><br />Integridad, honestidad, desarrollo, capacitaci&oacute;n, compromiso, lealtad, dinamismo, respeto y unidad.<br /><br />";
				 break;
		case 4 : document.getElementById('TITULO').innerHTML = "POL&Iacute;TICA DE CALIDAD";
				 document.getElementById('CUERPO').innerHTML = "Tenemos como Politica de Calidad el proporcionar servicios que garanticen la satisfacci&oacute;n de las necesidades de nuestros clientes, a trav&eacute;s de la mejora continua del Sistema de Gesti&oacute;n de la Calidad, para lograr el liderazgo en el Comercio Exterior.<br /><br />";
				 break;
		case 5 : document.getElementById('TITULO').innerHTML = "&iquest;D&Oacute;NDE ESTAMOS?";
				 document.getElementById('CUERPO').innerHTML = "Sucursales y oficinas de representaci&oacute;n:<br><ul><li>Aguascalientes, Ags.</li><li>Guadalajara, Jalisco.</li><li>Manzanillo, Colima</li><li>San Luis Potos&iacute;</li><li>Altamira, Tamps.</li><li>Nuevo Laredo, Tamps.</li><li>Tampico, Tamps.</li><li>Laredo, Texas. USA.</li><li>Monterrey, Nuevo Le&oacute;n</li><li>Colombia, Nuevo Le&oacute;n</li></ul><br />";
				 break;
		case 6 : document.getElementById('TITULO').innerHTML = "OFICINA ADUANAL";
				 document.getElementById('CUERPO').innerHTML = "Despachos a&eacute;reos, terrestres, mar&iacute;timos, intermodal y multimodal en importaci&oacute;n y Exportaci&oacute;n.<br /><br />Tambi&eacute;n despachamos sus operaciones administrativas como pedimientos complementarios. virtuales, cambios de r&eacute;gimen.<div style='position:relative; width:190px; height:100px; margin-left:30px; top:20px;'><img src='img/rivera2.jpg' style='float:right; border:none;' /><span style='font-family:arial; font-size:14px; color:#5b5b5b; float:right; margin-right:10px; margin-top:6px;'>www.aajr.com.mx</span></div><br /><br />";
				 break;
		case 7 : document.getElementById('TITULO').innerHTML = "MONITOREO";
				 document.getElementById('CUERPO').innerHTML = "Contamos con ejecutivos para mantenerlo informado del status de su mercanc&iacute;a.<div style='position:relative; width:190px; height:100px; margin-left:30px; top:20px;'><img src='img/rivera2.jpg' style='float:right; border:none;' /><span style='font-family:arial; font-size:14px; color:#5b5b5b; float:right; margin-right:10px; margin-top:6px;'>www.aajr.com.mx</span></div><br /><br />";
				 break;
		case 8 : document.getElementById('TITULO').innerHTML = "SERVICIO PERSONALIZADO";
				 document.getElementById('CUERPO').innerHTML = "Proporcionamos servicio personalizado de tiempo completo en planta para facilitar sus operaciones en comercio exterior.<div style='position:relative; width:190px; height:100px; margin-left:30px; top:20px;'><img src='img/rivera2.jpg' style='float:right; border:none;' /><span style='font-family:arial; font-size:14px; color:#5b5b5b; float:right; margin-right:10px; margin-top:6px;'>www.aajr.com.mx</span></div><br /><br />";
				 break;
		case 9 : document.getElementById('TITULO').innerHTML = "SOLUCIONES";
				 document.getElementById('CUERPO').innerHTML = "A trav&eacute;s de nuestra alianza estrat&eacute;gicas con empresas l&iacute;deres en servicios de Comercio Exterior, podemos ofrecerle soluciones en:<br><ul><li>Servicio personalizado en planta</li><li>Soluciones en log&iacute;stica y transporte</li><li>Servicio de bodega y distribuci&iacute;n</li><li>Consultor&iacute;a y asesor&iacute;a</li><li>Tramitaci&oacute;n de padrones y programas de fomento</li><li>Auditor&iacute;as preventivas</li><li>Asesor&iacute;a legal y defensa fiscal</li><li>Soluciones Inform&aacute;ticas</li></ul><div style='position:relative; width:190px; height:100px; margin-left:30px; top:20px;'><img src='img/rivera2.jpg' style='float:right; border:none;' /><span style='font-family:arial; font-size:14px; color:#5b5b5b; float:right; margin-right:10px; margin-top:6px;'>www.aajr.com.mx</span></div><br /><br /><br />";
				 break;
	}
	
	showH(document.getElementById('hor2'));
}

/**********************************************************************************************************************************************
											funciones para mostrar el div de contactos
*********************************************************************************************************************************************/
function contactoMostrar (opcId) {
	switch (opcId) {
		case 1: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '214px';
				document.getElementById('contact').innerHTML = "01 (449) 9781300<br /><b>Lucila Y&aacute;&ntilde;ez</b><br />lucilayanez@aajr.com.mx y<br/><b>Pedro de Luna</b><br />pedro@aajr.com.mx";
				break;
		case 2: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '249px';
				document.getElementById('contact').innerHTML = "01 (314) 3364375<br /><b>Alejandro Cavazos</b><br />acavazos@aajr.com.mx y<br/><b>Edsi Fabi&aacute;n P&eacute;rez</b><br />edsi.perez@aajr.com.mx";
				break;
		case 3: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '284px';
				document.getElementById('contact').innerHTML = "01 (833) 1261947<br /><b>Miriam Tejeda</b><br />miriamtejeda@aajr.com.mx y<br/><b>Homero Mart&iacute;nez</b><br />traficotampico@aajr.com.mx";
				break;
		case 4: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '319px';
				document.getElementById('contact').innerHTML = "01 (444) 8162782<br /><b>Victor Ram&iacute;rez</b><br />victorr@aajr.com.mx y<br/><b>Mayra M&eacute;ndez</b><br />mayra.mendez@aajr.com.mx";
				break;
		case 5: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '354px';
				document.getElementById('contact').innerHTML = "01 (867) 7159881<br /><b>Victor Rivera</b><br />victor.rivera@aajr.com.mx y<br/><b>Alfonzo L&oacute;pez</b><br />Alfonzo.lopez@aajr.com.mx";
				break;
		case 6: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '389px';
				document.getElementById('contact').innerHTML = "01 (33) 36885970<br />01 (33) 36885946<br /><b>H&eacute;ctor Garc&iacute;a</b><br />hector.garcia@aajr.com.mx y<br/><b>Miguel Zazueta</b><br />miguel.zazueta@aajr.com.mx";
				break;
		case 7: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '424px';
				document.getElementById('contact').innerHTML = "01 (33) 38175388<br /><b>Ivan Cossio</b><br />ivanc@aajr.com.mx";
				break;
		case 8: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '494px';
				document.getElementById('contact').innerHTML = "(956) 7182451<br /><b>Pablo Vazquez</b><br />pablo.vazquez@aajr.com.mx";
				break;
		case 9: document.getElementById('contact').style.display = 'block';
				document.getElementById('contact').style.top = '530px';
				document.getElementById('contact').innerHTML = "(956) 7182451<br /><b>Pablo Vazquez</b><br />pablo.vazquez@aajr.com.mx y<br/><b>Luis T&eacute;llez</b><br />luis.tellez@aajr.com.mx";
				break;
	}
}

function contactoOcultar () {
	document.getElementById('contact').style.display = 'none';
}

function limpiarCampo (campo) {
	campo.value = campo.value.trim ();
}

function validarCampos () {
	if (document.getElementById('contNombre').value != '') {
		if (document.getElementById('contEmail').value != '') {
			if (document.getElementById('contMensaje').value != '') {
				document.emailContacto.submit ();
			}
			else
				alert ('El campo "Mensaje" es necesario para enviar el mensaje.');
		}
		else
			alert ('El campo "Correo Electr\u00f3nico" es necesario para enviar el mensaje.');
	}
	else
		alert ('El campo "Nombre" es necesario para enviar el mensaje.');
}

/********************************************************************************************************************************************
															funciones para el index
*********************************************************************************************************************************************/
function cambiaImagenIndex () {
	if (esIndex) {
		getBanners();
	}
}

function getBanners(){
	//banners=new Array("../img/index_img1.jpg","../img/index_img2.jpg","../img/index_img3.jpg","../img/index_img4.jpg","../img/index_img5.jpg","../img/index_img6.jpg");/*previo/*/
	banners=new Array("img/index_img1.jpg","img/index_img2.jpg","img/index_img3.jpg","img/index_img4.jpg","img/index_img5.jpg","img/index_img6.jpg");/*previo/*/
	imgs=new Array();
	for(i=0;i<banners.length;i++){
		img_tmp=new Image();
		img_tmp.style.width="717px";
		img_tmp.style.height="471px";
		img_tmp.src=banners[i];
		imgs.push(img_tmp);
	}
	document.getElementById("frameInformacionInfo").appendChild(imgs[banner_actual]);
	cont_banner=1;
	tbann=setTimeout("changeBanner()",intervalo_banners);
}
	
function changeBanner(){
	if(alfaBanner>20){
		tbann=setTimeout("changeBanner()",75);
		alfaBanner=alfaBanner-20;
		changeAlpha(imgs[banner_actual],alfaBanner);
	}
	else{
		changeAlpha(imgs[banner_actual],100);
		document.getElementById("frameInformacionInfo").removeChild(imgs[banner_actual]);
		if(cont_banner==imgs.length) cont_banner=0;
		document.getElementById("frameInformacionInfo").appendChild(imgs[cont_banner]);
		banner_actual=cont_banner;
		cont_banner++;
		alfaBanner=100;
		tbann=setTimeout("changeBanner()",intervalo_banners);
	}
}
	
function changeAlpha(elem,alfa){
	try{
		elem.style.opacity=alfa*0.01;
		elem.filters.alpha.opacity=alfa;
	}catch(err){}
}

function cambiaColorBlanco (e) {
	e.style.color = '#fff';
}
				  
function cambiaColorGris (e) {
	e.style.color = '#5c5c5c';
}

function cambiaColorNegro (e) {
	e.style.color = '#000';
}


/*********************************************************************************************************************************************
														funcion de movimiento de noticias
*********************************************************************************************************************************************/
function move(elem,psf,sp){
	comp_movil=elem;
	menu_actual=psf;
	xe=posit[psf];
	//xe=psf;
	speed=sp;
	if(xe<elem.offsetLeft) xe_var=xe-5;
	else  xe_var=xe+5;
	setTimeout("moveComponent()",120);
}

function moveComponent(){
	_x=comp_movil.offsetLeft;
	if(xe!=_x){
		comp_movil.style.left=(_x+Math.ceil((xe_var-_x)/speed))+"px";
		setTimeout("moveComponent()",60);
	}
	else{
		menu_sig=menu_actual+2;
		if(menu_sig>=registros+1) menu_sig=1;
		to=setTimeout("mostrarNoticia(menu_sig)","5000");
	}
}

/*
	funciones para todas las paginas
*/
function mostrarVentanaPiePagina (posit) {
	var ventanaPiePagina = document.getElementById('ventanaPiePagina');
	var infoVentanaPieDePagina = document.getElementById('infoVentanaPieDePagina');
	var flechita = document.getElementById('flechita');
	ventanaPiePagina.style.visibility = "visible";
	switch (posit) {
		case 1: flechita.style.left = "7px";
				infoVentanaPieDePagina.innerHTML = "Ofrece log&iacute;stica integral puerta a  puerta, manejando transporte a&eacute;reo, terrestre, mar&iacute;timo y ferroviario.";
				break;
		case 2: flechita.style.left = "115px";
				infoVentanaPieDePagina.innerHTML = "Despacho de abogados y consultores especializados en materia de Derecho Tributario y Comercio Exterior.";
				break;
		case 3: flechita.style.left = "230px";
				infoVentanaPieDePagina.innerHTML = "Desarrollo de software personalizado, soporte inform&aacute;tico a Agentes Aduanales y empresas con programa IMMEX.";
				break;
		case 4: flechita.style.left = "355px";
				infoVentanaPieDePagina.innerHTML = "Empresa localizada en Laredo Texas, ofrece servicios de bodega, administraci&oacute;n y control de inventarios, empaquetado, etiquetado y distribuci&oacute;n, despacho de mercanc&iacute;a el mismo d&iacute;a.";
				break;
	}
}

function ocultarVentanaPiePagina () {
	document.getElementById('ventanaPiePagina').style.visibility = "hidden";
}

function mostrarFormularioAcceso() {
	var formularioAcceso = document.getElementById('formularioAcceso');
	if (esIndex) {
		formularioAcceso.style.marginLeft = "273px";
		formularioAcceso.style.marginTop = "164px";
	}
	formularioAcceso.style.visibility = "visible";
}

function enviarFormularioAcceso () {
	var valores = "textos="+document.getElementById('formEmpresa').value+"$$$"+document.getElementById('formNombre').value+"$$$"+document.getElementById('formCorreo').value+"$$$"+document.getElementById('formCiudad').value;
	enviar (objX, 'emailAcceso.php', valores);
	ocultarFormularioAcceso ();
	document.getElementById('formEmpresa').value = '';
	document.getElementById('formNombre').value = '';
	document.getElementById('formCorreo').value = '';
	document.getElementById('formCiudad').value = '';
}

function ocultarFormularioAcceso () {
	document.getElementById('formularioAcceso').style.visibility = "hidden";
}

function stateChanged(){
	if(objX.readyState==4) {
		alert (objX.responseText);
		objX=GetXmlHttpObject();
	}
}
