//--------------------------------------------------------------------------------
//FUNCIONES DE MENU IZQUIERDO
//--------------------------------------------------------------------------------
 function mostrar_link_activos(){
	ocultar_link_vencimientos();
	contenido="<table border='0' cellpadding='0' cellspacing='0'>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/activos/productos.asp?page=productos'>Por Producto</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/activos/mercado_emisor.asp?page=mercado_emisor'>Por Mercado Emisor</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/activos/merc_activos_productos.asp?page=merc_activos_productos&amp;moneda=CLP&amp;texto=Activos%20Por%20Moneda%20Pesos&amp;init=S'>Por Moneda Pesos</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='l/gest_inv/contenido/activos/merc_activos_productos.asp?page=merc_activos_productos&amp;moneda=USD&texto=Activos%20Por%20Moneda%20Dolar&amp;init=S'>Por Moneda Dólar</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/activos/merc_activos_productos.asp?page=merc_activos_productos&amp;moneda=CLF&amp;texto=Activos%20Por%20Moneda%20UF&amp;init=S'>Por Moneda UF</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"</table>";
	document.getElementById('link_activos').innerHTML = contenido;
	document.getElementById('href_activos').onclick = new Function("ocultar_link_activos()");
	document.getElementById('Image3').onmouseout = new Function("");
}

function mostrar_link_vencimientos(){
	ocultar_link_activos();
	contenido="<table border='0' cellpadding='0' cellspacing='0'>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/vencimiento/renta_fija.asp?page=renta_fija'>Renta Fija</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"<tr>";
	contenido=contenido+"<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href='/gest_inv/contenido/vencimiento/cupon_dividendo.asp?page=cupon_dividendo'>Cortes de Cup&oacute;n <br/>";
	contenido=contenido+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y Dividendos</a></td>";
	contenido=contenido+"</tr>";
	contenido=contenido+"</table>";
	document.getElementById('link_vencimientos').innerHTML = contenido;
	document.getElementById('href_vencimientos').onclick = new Function("ocultar_link_vencimientos()");
	document.getElementById('Image6').onmouseout = new Function("");
}

function ocultar_link_activos(){
	MM_swapImage('Image3','','/gest_inv/imagenes/menu_activos.gif',1);
	document.getElementById('Image3').onmouseout = new Function("MM_swapImgRestore()");
	document.getElementById('link_activos').outerHTML = "<div id='link_activos' align='center'></div>";	
	document.getElementById('href_activos').onclick = new Function("mostrar_link_activos()");
}

function ocultar_link_vencimientos(){
	MM_swapImage('Image6','','/gest_inv/imagenes/menu_vencimientos.gif',1);
	document.getElementById('Image6').onmouseout = new Function("MM_swapImgRestore()");
	document.getElementById('link_vencimientos').outerHTML = "<div id='link_vencimientos' align='center'></div>";	
	document.getElementById('href_vencimientos').onclick = new Function("mostrar_link_vencimientos()");
}


function cambiarContenidoDiv(id){
	glosas=document.getElementsByName('glosa');
	for (var i = 0; i < glosas.length; i++ )
		if (id == i){
				if (glosas[i].innerHTML.length <= 110)
					glosas[i].innerHTML = contenidos[id];
				else glosas[i].innerHTML = glosas[i].innerHTML.substring(0,100)+'...';
		}
		else {
			glosas[i].innerHTML = glosas[i].innerHTML.substring(0,100)+'...';
		}

}


function camposObligatoriosCorreo(form1){
	var auxiliar;
	
	if (isEmpty(form1.nombre.value)) {
		alert("Por favor ingrese su nombre");
		form1.nombre.focus();
		return;
	}
	
	if(!isEmpty(form1.rut.value)){
		auxiliar = form1.rut.value;		
		if(!validateinput(form1.rut, 'RUT incorrecto', true)){
			form1.rut.value = auxiliar;
			form1.rut.focus();
			return;
		}	
	}
	
	if (form1.medio_contacto.value == '0' ){
		alert("Por favor seleccione un medio de contacto");
		form1.medio_contacto.focus();
		return;
	}else{
		if (form1.medio_contacto.value == '1' || form1.medio_contacto.value == '2') {
			if(form1.contacto.value == '') {
				alert("Por favor ingrese el numero correspondiente");
				form1.contacto.focus();
				return;
			}else{
				if(!isInteger(form1.contacto.value)){
					alert("Ingrese un numero correcto");
					form1.contacto.focus();
					return;					
				}
			}
		}
		
		if (form1.medio_contacto.value == '3') {
			if(form1.contacto.value == ''){
				alert("Por favor ingrese la dirección \n de correo correspondiente");
				form1.contacto.focus();
				return;
			}else{
				if(!Validate_Email_Address(form1.contacto.value)){
					alert("Ingrese una dirección \n de correo correcta");
					form1.contacto.focus();
					return;					
				}
			}
		}
	}
	if (isEmpty(form1.comentario.value)) {
		alert("Por favor ingrese su comentario");
		form1.comentario.focus();
		return;
	}	
	form1.submit();
}


function validarLogin(formRut){


	alert('ADENTRO');
	
	if (isEmpty(formRut.textfield2.value)) {
		alert("Por favor ingrese su nombre");
		formRut.textfield2.focus();
	}else 	
	 if (formRut.rut_num.value == 'RUT...') {
		alert("Por favor ingrese su Rut");
		formRut.rut_num.focus();
	}else	
	if (isEmpty(formRut.pass.value)) {
		alert("Por favor ingrese su Clave");
		formRut.pass.focus();
	}else 	
	 if (formRut.pass.value == 'CLAVE...') {
		alert("Por favor ingrese su Clave");
		formRut.pass.focus();
	}else 
	//alert('bien')
	formRut.submit();

}

function updateVariations(indicador, clase, estilo, valor, claseFlecha){
	if(indicador=="IPSA"){
		//class
		document.getElementById("celIPSA").className = clase;
		//style
		document.getElementById("celIPSA").style.color = estilo;
		//valor
		document.getElementById("celIPSA").innerHTML = valor;
		//flecha
		document.getElementById("celFlechaIPSA").className = claseFlecha;
	}
	if(indicador=="IGPA"){
		//class
		document.getElementById("celIGPA").className = clase;
		//style
		document.getElementById("celIGPA").style.color = estilo;
		//valor
		document.getElementById("celIGPA").innerHTML = valor;
		//flecha
		document.getElementById("celFlechaIGPA").className = claseFlecha;		
		
	}
}
function boton(valor){
	document.grafico.boton.value = valor;
	document.getElementById("titulo_grafico").innerHTML=valor;

	if(lastLink != ""){
		//if (lastLink == "IPSA") document.getElementById(lastLink).className = "ipsa";
		//if (lastLink == "IGPA") document.getElementById(lastLink).className = "igpa";
		if (lastLink == "INTER10") document.getElementById(lastLink).className = "inter";        
  }
  //if (valor == "IPSA") document.getElementById(valor).className = "ipsaselected";
  //if (valor == "IGPA") document.getElementById(valor).className = "igpaselected";
  if (valor == "INTER10") document.getElementById(valor).className = "interselected";    

	lastLink = valor;
}

function boton_fecha(valor){
	document.grafico.perio.value = valor;
	
	if(lastLinkFecha != ""){
		if (lastLinkFecha == "A")  document.getElementById("aleta_ano").src = "/gest_inv/imagenes/btn_ano_off.gif";
 		if (lastLinkFecha == "M")  document.getElementById("aleta_mes").src = "/gest_inv/imagenes/btn_mes_off.gif";
		if (lastLinkFecha == "D")  document.getElementById("aleta_dia").src = "/gest_inv/imagenes/btn_dia_off.gif";    
  }
	if (valor == "A") document.getElementById("aleta_ano").src = "/gest_inv/imagenes/btn_ano.gif";
	if (valor == "M") document.getElementById("aleta_mes").src = "/gest_inv/imagenes/btn_mes.gif";
	if (valor == "D") document.getElementById("aleta_dia").src = "/gest_inv/imagenes/btn_dia.gif";        
	lastLinkFecha = valor;
}

function perio(valor){
	document.grafico.perio.value = valor;
}

function cargaGrafico(){
	var tipo = document.grafico.boton.value;
	var periodo = document.grafico.perio.value;
    
  //alert("graficos/Graficos.asp?Id=" + tipo + "&Periodo=" + periodo);
  window.frames["GRAFICO"].location = "/gest_inv/asp/graficos/Graficos.asp?Id=" + tipo + "&Periodo=" + periodo;
}

//--------------------------------------------------------------------------------
//
//	FUNCIONES PARA VALIDAR CASILLA DE CORREO
//	http://scripts.franciscocharrua.com/validate-email-address.php
//
//--------------------------------------------------------------------------------
function Validate_String(string, return_invalid_chars) {
	valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	invalid_chars = '';

	if(string == null || string == '')
		return(true);

	//For every character on the string.   
	for(index = 0; index < string.length; index++) {
		char = string.substr(index, 1);                        

		//Is it a valid character?
		if(valid_chars.indexOf(char) == -1) {
			//If not, is it already on the list of invalid characters?
			if(invalid_chars.indexOf(char) == -1) {
				//If it's not, add it.
				if(invalid_chars == '')
					invalid_chars += char;
				else
					invalid_chars += ', ' + char;
				}
			}
		}                     

		//If the string does not contain invalid characters, the function will return true.
		//If it does, it will either return false or a list of the invalid characters used
		//in the string, depending on the value of the second parameter.
		if(return_invalid_chars == true && invalid_chars != '') {
			last_comma = invalid_chars.lastIndexOf(',');

			if(last_comma != -1)
				invalid_chars = invalid_chars.substr(0, $last_comma) + ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
			return(invalid_chars);
		}
		else
			return(invalid_chars == ''); 
}


function Validate_Email_Address(email_address) {
	//Assumes that valid email addresses consist of user_name@domain.tld
	at = email_address.indexOf('@');
	dot = email_address.indexOf('.');

	if(at == -1 || dot == -1 || dot <= at + 1 || dot == 0 || dot == email_address.length - 1)
		return(false);

	user_name = email_address.substr(0, at);
	domain_name = email_address.substr(at + 1, email_address.length);                  

	if(Validate_String(user_name) === false || Validate_String(domain_name) === false)
		return(false);                     

	return(true);
}
//--------------------------------------------------------------------------------

