// JavaScript Document
//iniciia el efecto dedesapareecer el logo...
var funcionEjecutar=null;
var parametrosEjecutar=null;
var fuenteTamao = 12;
var contenidoMensaje="";


var detener,defecto,limiteAncho;
var desplazamiento=0;
var paso; //px
var velocidad; //ms
var direccionGaleria="izquierda";

//variable agregada para redes...
var slider="";
var cf=null;

function iniciar(idiomaParametro)
{
	enviarSolicitud("secciones/inicio",idiomaParametro,cargarExitosa,'contenido');
}

function cargarPopUp(modulo,parametro,id,_width,_height,_x,_y)
{
	
	mostrarPupUp(id,_width,_height,_x,_y);
	enviarSolicitud(modulo,parametro,null,id);
	//document.write("sdaskjdklasjdkl");
}

function accionPanel(panel)
{
	if (document.getElementById(panel.id+"l").style.display=="none")
	{
		document.getElementById(panel.id+"l").style.display="block";
	}else
	{
		document.getElementById(panel.id+"l").style.display="none";
	}
}

function cargarPagina(url,parametros,funcion,parametrosFuncion)
{
	fuente('restore','contenido');
	funcionEjecutar=funcion;
	parametrosEjecutar=parametrosFuncion;
	enviarSolicitud(url,parametros,cargarCompleta,'contenido');
}

function mostrarPupUp(id,_width,_height,_x,_y)
{
	document.getElementById(id).style.display="block";
	document.getElementById(id).style.position="absolute";
	document.getElementById(id).style.zIndex=10;
	document.getElementById(id).width=_width;
	document.getElementById(id).height=_height;
	document.getElementById(id).style.top=_y;
	document.getElementById(id).style.left=_x;
	//document.write("sdaskjdklasjdkl");
	//efectoTransparencia(100,id,1,pararEjecucionInicial);

}

function quitarPopUp(id)
{
	document.getElementById(id).style.display="none";
	document.getElementById(id).style.position="static";
	document.getElementById(id).style.top=0;
	document.getElementById(id).style.left=0;
	document.getElementById(id).width=0;
	document.getElementById(id).height=0;
	document.getElementById(id).innerHTML="";
}

function cargarExitosa(){
	funcionEjecutar=sliderNoticias;
	parametrosEjecutar=null;
	
	clearInterval( nID1 );
	clearInterval( nID2 );
	detenerIntervalo();
	_disabledFader();
	cf=null;
	

	if (funcionEjecutar!=null)
	{
		funcionEjecutar(parametrosEjecutar);
	}
	
}

function cargarCompleta(){
	
	clearInterval( nID1 );
	clearInterval( nID2 );
	detenerIntervalo();
	_disabledFader();
	cf=null;	
	//ejecuta las funciones indicadas arriba...
	if (funcionEjecutar!=null)
	{
		funcionEjecutar(parametrosEjecutar);
		funcionEjecutar=null;
		parametrosEjecutar=null;
	}
	
}

//para la aejecucion del javscript
function pararEjecucionInicial()
{
	if (window.XMLHttpRequest) 
	{
		if(document.all)
		{			
			document.execCommand("Stop");			
		}else
		{			
			window.stop();			
		}
	} else 
	{		
		document.execCommand("Stop");		
	} 
}

function pararEjecucion()
{
	if (window.XMLHttpRequest) 
	{
		if(document.all)
		{
			document.execCommand("Stop");
		}else
		{
			window.stop();
		}
	} else 
	{
		document.execCommand("Stop");
	} 
}

//cambio de imagenes de los menu
function cambiarImagen(imagen)
{
	var cadena=document.getElementById(imagen.id+"Imagen").src.substring(document.getElementById(imagen.id+"Imagen").src.lastIndexOf("/")+1 );
	if(cadena == imagen.id+"1.jpg") 
	{
        document.getElementById(imagen.id+"Imagen").src = "imagenes/"+imagen.id+"2.jpg";
    }
    else 
	{
        document.getElementById(imagen.id+"Imagen").src = "imagenes/"+imagen.id+"1.jpg";
    }

}

//cambio de color menu..
function cambiarColor(elemento, estado)
{
	
	if(estado== true) 
	{
		document.getElementById(elemento.id+"Td").bgColor = "#CAE3F9";
    }
    else 
	{
        document.getElementById(elemento.id+"Td").bgColor = "#EDF4F9";
    }

}

function validarFormulario(parametroIdioma)
{	
	var cadenaParametro="nombre="+document.getElementById("nombre").value+"&correo="+document.getElementById("correo").value+"&pais="+document.getElementById("pais").value+"&mensaje="+document.getElementById("mensaje").value;
	enviarSolicitud("php/enviarContacto",cadenaParametro+"&idiomaSeleccion="+parametroIdioma,verificarContacto,'errorRegistro');
}

function verificarContacto()
{
	
	if (document.getElementById("errorRegistro").innerHTML=="exito mensaje")
	{
		document.getElementById("errorRegistro").innerHTML="<font color='#0099FF' size='4'>Mensaje Enviado con Exito</font>";
		
		document.getElementById('formContact').reset();
	}
}

function validarEmail(emailValor)
{	
	
	var filtro=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

	if ( filtro.test(emailValor) )
	{
		return true;
	}else
	{
		return false;
	}
	
}

function trim(cadena)
{
	var vacio=false;
	
	if (cadena!="" && cadena!=" ")
	{
		for(i=0; i<cadena.length;i++ )
		{
			if(cadena.charAt(i)!=" " && cadena.charAt(i)!="")
			{
				vacio=true;
			}
		}
	}
	
	return vacio;
}

//agregadas para redes institucionales...
function sliderNoticias()
{	
	cf = new Crossfader( new Array('cf1','cf2','cf3'), 1500, 8000 );	
//	var Accordion1 = new Spry.Widget.Accodion("Accordion1");	
}	

function fuente(estado,id)
{
	if (estado=="true")
	{
		if (fuenteTamao<24)
			fuenteTamao=fuenteTamao+1;
	}else
	{
		if (estado=="false")
		{
			if (fuenteTamao>12)
				fuenteTamao=fuenteTamao-1;
		}else
		{
			fuenteTamao=12;
		}
	}
	document.getElementById(id).style.fontSize=fuenteTamao+"px";
}

function imprimir(contenido,tipo,correo,nombre1a,nombre2a,parametroIdioma)
{
	var destino="";
	if (document.getElementById(nombre1a).value=="")
	{
		document.getElementById("error").innerHTML="Debes Llenar el Nombre del destinatario";
	}else
	{
		
		if (validarEmail(document.getElementById(correo).value)==false)
		{
			document.getElementById("error").innerHTML="Debes Llenar el Campo de Correo Electr&oacute;nico Correctamente.";
		}else
		{
			
			if (document.getElementById(nombre2a).value=="")
			{
				document.getElementById("error").innerHTML="Debes Indicar tu nombre";
			}else
			{
				var parametro="";
				if (tipo=="Noticia")
				{
					document.getElementById("error").innerHTML="";
					parametro="contenido="+contenido+"&correo="+document.getElementById(correo).value+"&asunto="+tipo+" de Red Indh enviado(a) por "+document.getElementById(nombre2a).value+" a "+document.getElementById(nombre1a).value+"&tipo="+tipo;
					destino="correo";
				}else
				{
					if (tipo=="programa_de_trabajo")
					{
						parametro="contenido="+contenido+"&correo="+document.getElementById(correo).value+"&asunto=Programa de Trabajo enviado(a) por "+document.getElementById(nombre2a).value+" a "+document.getElementById(nombre1a).value+"&tipo="+tipo;						
					}else
					{
						if (tipo=="red")
						{
						parametro="contenido="+contenido+"&correo="+document.getElementById(correo).value+"&asunto=Red de INDH America enviado(a) por "+document.getElementById(nombre2a).value+" a "+document.getElementById(nombre1a).value+"&tipo="+tipo;
						}else
						{
							if (tipo=="articulo")
							{
							parametro="contenido="+contenido+"&correo="+document.getElementById(correo).value+"&asunto=Articulo enviado(a) por "+document.getElementById(nombre2a).value+" a "+document.getElementById(nombre1a).value+"&tipo="+tipo;
							}else
							{
								if (tipo=="entrevista")
								{
								parametro="contenido="+contenido+"&correo="+document.getElementById(correo).value+"&asunto=Entrevista enviado(a) por "+document.getElementById(nombre2a).value+" a "+document.getElementById(nombre1a).value+"&tipo="+tipo;
								}
							}
						}
					}
				}
				enviarSolicitud("php/correo",parametro+"&"+parametroIdioma,null,'error');
				document.getElementById('envioFormulario').style.display='none';
			}
		}		
	}	
}

function efectoMenu(estado,elemento)
{
	if (estado==true)
	{
		document.getElementById(elemento+"s").style.display="block";
		document.getElementById(elemento+"s").style.position="absolute";
	}else
	{
		document.getElementById(elemento+"s").style.display="none";
	}
}

function busqueda(buscar,busqueda,idioma)
{
	if (document.getElementById(busqueda).value!="" && document.getElementById(buscar).value!="")
	cargarPagina('secciones/'+document.getElementById(busqueda).value,'normal=true&'+idioma+'&buscar='+document.getElementById(buscar).value,null,'');
}

//galeria
function inicioGaleria(){
	mostrarImagen(document.getElementById("imagen0"));
	desplazamiento=0;
	paso=4; 
	velocidad=50;
	defecto=document.getElementById("texto").offsetWidth-(document.getElementById("texto").offsetWidth/4);
	limiteAncho=document.getElementById("texto").offsetWidth;
	rM();
}

function moverIzquierda(){
document.getElementById("linea").style.left=desplazamiento+"px";
desplazamiento-=paso;
	if(desplazamiento<=(-limiteAncho) )
	{
		document.getElementById("linea").style.left=defecto+"px";
		desplazamiento=defecto;
	}
}

function moverDerecha(){
document.getElementById("linea").style.left=desplazamiento+"px";
desplazamiento+=paso;
	if(desplazamiento>=(limiteAncho/1.2) )
	{
		desplazamiento=-1*(limiteAncho);
		document.getElementById("linea").style.left=desplazamiento+"px";
		
	}
}

function rM()
{
	if (direccionGaleria=="derecha")
	{
		detener=setInterval("moverDerecha()", velocidad);
		document.getElementById("marquesina").scrollAmount=4;
	}else
	{
		if (direccionGaleria=="izquierda")
		{
			detener=setInterval("moverIzquierda()", velocidad);
			document.getElementById("marquesina").scrollAmount=4;
		}
	}
}

function detenerGaleria()
{
	detenerIntervalo();
	document.getElementById("marquesina").scrollAmount=0;
}

function detenerIntervalo()
{
	clearInterval(detener);	
}

function derecha()
{
	direccionGaleria="derecha";
	paso=16;
	document.getElementById("marquesina").direction="right";	
	detenerGaleria();
	rM();
	document.getElementById("marquesina").scrollAmount=16;
	
}

function restablecerMovimiento()
{
	paso=4;
	document.getElementById("marquesina").scrollAmount=4;
}

function izquierda()
{
	direccionGaleria="izquierda";
	paso=16;
	document.getElementById("marquesina").direction="left";
	detenerGaleria();
	rM();
	document.getElementById("marquesina").scrollAmount=16;
}   

function mostrarImagen(idOrigen)
{
	var nombreTemporal=idOrigen.src;
	nombreTemporal= nombreTemporal.substring(0, nombreTemporal.length-5);
	document.getElementById("imagenGrandeEnlace").href=nombreTemporal+".jpg";
	document.getElementById("imagenGrandeEnlace").title=idOrigen.title;
	document.getElementById("imagenGrande").src=nombreTemporal+".jpg";
	document.getElementById("imagenGrande").title=idOrigen.title;
	document.getElementById("explicacion").innerHTML=idOrigen.title;
}
