/**************************************
*    Funciones generales para Larrain Vial
*    Author: Victor Hugo Saavedra
*    Email: vsaavedra@imagemaker.cl 
 **************************************/

function MostrarbannerMemorias2()
{
	window.open("http://www.larrainvial.com/campanas/memorias/2006/memorias3.asp","Memorias","width=800,height=600,left=25,top=25")
}
function series(link)
{
	window.location=link;
}
 function linkFondo(nemo,familia){
	if (familia.indexOf("dep")==0){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_detalle.aspx?nemo="+nemo;
	}	
	if (familia=="balanceada"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_lv02.aspx?nemo="+nemo;
	}
	if (familia=="balanceado"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_lv02.aspx?nemo="+nemo;
	}
	if (familia=="accionaria"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_lv03.aspx?nemo="+nemo;
	}
	if (familia=="alternativas"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_lv04.aspx?nemo="+nemo;
	}
	if (familia=="alter"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/fondos_mutuos_lv04.aspx?nemo="+nemo;
	}
  }
  function linkFondo_c(nemo,familia){
	//alert ("este es un link a fondo\r\n urlBase->"+dirBase+"\r\nnemo->"+nemo+"\r\nfamilia-->"+familia);
	if (familia=="deposito"){
		
		window.location=dirBase+"productos/fondos_mutuos/fondos_c/fondos_mutuos_lv/fondos_mutuos_detalle.aspx?nemo="+nemo;
	}	
	if (familia=="balanceada"){
		
		window.location=dirBase+"productos/fondos_mutuos/fondos_c/fondos_mutuos_lv/fondos_mutuos_lv02.aspx?nemo="+nemo;
																					
	}
	if (familia=="accionaria"){
		
		window.location=dirBase+"productos/fondos_mutuos/fondos_c/fondos_mutuos_lv/fondos_mutuos_lv03.aspx?nemo="+nemo;
	}
	if (familia=="alter"){
		
		window.location=dirBase+"productos/fondos_mutuos/fondos_c/fondos_mutuos_lv/fondos_mutuos_lv04.aspx?nemo="+nemo;
	}
  }
  function linkFondoComision(nemo,familia){
	//alert ("este es un link a fondo\r\n urlBase->"+dirBase+"\r\nnemo->"+nemo+"\r\nfamilia-->"+familia);
	if (familia=="deposito"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/comision_deposito.aspx?nemo="+nemo;
	}	            
	if (familia=="ahorro"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/comision_ahorro.aspx?nemo="+nemo;
				                        																	
	}
	if (familia=="oportunidad"){
		window.location=dirBase+"productos/fondos_mutuos/fondos_lv/fondos_mutuos_lv/comision_oportunidad.aspx?nemo="+nemo;
	}
 }
 
 
 	function tableScrollUp(tabla, incremento) {
	    var rows = $(tabla).tBodies[0].rows;
	    var buscandoFilasParaMostrar = true;
	    for (var i = 0; i < rows.length; i++) {
		if (buscandoFilasParaMostrar) {
		    if (computedStyle(rows[i], 'display') != "none") { 
 		        if (incremento > i) {
			    incremento = i;
			}
			for (var j = i - 1; j >= i - incremento; j--) {
		             rows[j].style.display = "";
			}
		        buscandoFilasParaMostrar = false;
		    }
		} else { //buscandoFilasParaEsconder
		    if (computedStyle(rows[i], 'display') == "none") {
		        for (var j = i - 1; j >= i - incremento; j--) {
			     rows[j].style.display = "none";
			}
			break;
		    } else if (i == rows.length - 1) {
		        for (var j = rows.length - incremento; j < rows.length; j++) {
			     rows[j].style.display = "none";
			}
		    }
		}
	      
	    }
	}
	
	function tableScrollDown(tabla, incremento) {
	    var rows = $(tabla).tBodies[0].rows;
	    var buscandoFilasParaMostrar = true;
	    for (var i = rows.length - 1; i >= 0; i--) {
		if (buscandoFilasParaMostrar) {
		    if (computedStyle(rows[i], 'display') != "none") { 
 		        if (incremento >= rows.length - 1 - i) {
			    incremento = rows.length - 1 - i;
			}
			for (var j = i + incremento; j > i; j--) {
		             rows[j].style.display = "";
			}
		        buscandoFilasParaMostrar = false;
		    }
		} else { //buscandoFilasParaEsconder
		    if (computedStyle(rows[i], 'display') == "none") {
		        for (var j = i + incremento; j > i; j--) {
			     rows[j].style.display = "none";
			}
			break;
		    } else if (i == 0) {
		        for (var j = 0; j < incremento; j++) {
			    rows[j].style.display = "none";
			}
		    }
		}	
	      
	    }
	}	
 
 
 
function cambiaImagenMenu(obj,imagen){
	obj.src=imagen;
}
 
 function cambiaImagen(obj,imagen){
	obj.style.backgroundImage.src="url("+imagen+")";
}
function isMail(email){
    regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    return regx.test(email);
}
   
function debug(text){
	if (getElement("debug")!=null){
		getElement("debug").innerHTML="___________________________<br>"+text;
	}
}
function onlyTextPress(e){
	debug(e.key().code);
	if ((e.key().code<=46)||(e.key().code==192)||(e.key().code==116)){ return true;}
	if (e.key().code>100){e.stop()}
	if (((e.key().code>=48)&&(e.key().code<=57))||((e.key().code>=96)&&(e.key().code<=105))){
		e.stop();
	}	
}

function onlyNumberPress(e){
	debug(e.key().code);
	if ((e.key().code<=46)||(e.key().code==195)||((e.key().code>=96)&&(e.key().code<=105)))
	{ return true;}
	
	
       if (e.key().code>100){e.stop()}
	if (e.key().code>57){
		e.stop();
	}	
}

function LCase(s){
	// Devuelve la familia convertida en minúsculas
	return s.toLowerCase();
}

function cortarNumero(ctl, ddv)
	{
		var t;
		var caracter;
		var i;
		var sts;
        sts = ctl; 
		
		rutCompleto=ctl+ '-' +ddv;
		
		dv=IsRut(rutCompleto);
		
		//if (LCase(dv)!= LCase(ddv))   
		if (dv == "malo") 
		{          
			alert("EL d\u00edgito no corresponde al RUT ingresado.Debe ingresar el d\u00edgito correspondiente");
			return false
		}	
		  
		p= OnlyNumber(ctl);
		if (p==true)
		{      
			if (sts.length == 0 )
			{	
				alert(" Debe ingresar su Rut");
				document.formClave.rut.focus();
				return false;
			}    
			t = "";
    
			for (i=0;i< sts.length;i++)
			{
				caracter = sts.substring(i, i + 1);
       		 
				if (caracter != "-")
				{	
					t = t + caracter;
				}
				else
				{   
					i=i +1; 
		       
				}	        		
			}
                if (getElement("psw_Clave").value=="")
		{
			alert("Ingrese su Clave\r\n");
			document.formClave.psw_Clave.focus();
		         
		}
                else
                {		
			document.formClave.txt_Rut.value=t;
			document.formClave.txt_Dv.value=dv;
		 
			document.formClave.submit();
		}	
     }
 }
  
	function OnlyNumber(ctl)
	{
   
		if (isNaN(parseInt(ctl)))
		{ 	 
			alert("Debe Ingresar dato Numerico");
			document.formClave.rut.value= "";
			document.formClave.rut.focus();
			return false; 
		}
                return true; 
	}

        function IsRut(valor)
	{
		var rut = valor; 
		var tmpstr = "";
		var malo = "malo";
		largo = rut.length;
		guiones = 0;
	
		for ( i=0; i < largo; i++ ){
		if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' ){ 
		tmpstr = tmpstr + rut.charAt(i);
		}
		else if (rut.charAt(i) != '-') {
		//return false
		return malo
		}    
		else if (rut.charAt(i) == '-') {
		guiones++;
		if (i != largo - 2)
			//return false;
			return malo;
		}
    }
    if (guiones == 0)
        //return false;
		return malo;
	rut = tmpstr;
	largo = rut.length;
	if ( largo < 2 )
        { 
        //return false
		return malo;
        }

    for (i=0; i < largo ; i++ )
        {
        if ( rut.charAt(i) !="0" && rut.charAt(i) != "1" && rut.charAt(i) !="2" && rut.charAt(i) != "3" && rut.charAt(i) != "4" && rut.charAt(i) !="5" && rut.charAt(i) != "6" && rut.charAt(i) != "7" && rut.charAt(i) !="8" && rut.charAt(i) != "9" && rut.charAt(i) !="k" && rut.charAt(i) != "K" )
            {
            //return false;
			return malo;
            }
        }
    var dtexto = ""; 
    cnt = 0;
    for ( i=largo-1, j=largo-1+3; i>=0; i--, j-- )
        {
        if ( cnt == 3 )
            {
            dtexto = rut.charAt(i) + dtexto;
            dtexto = '.' + dtexto;
            cnt = 1; 
            }
        else
            {
            dtexto = rut.charAt(i) + dtexto;
            if( cnt == 0 )
                {
                dtexto = '-' + dtexto;
                }
            cnt++; 
            }
        }
    return checkDV(rut);
    }


	function checkDV( crut )
	{
		largo = crut.length;
		if ( largo > 2 )
		{
		rut = crut.substring(0, largo - 1); 
		}
		else
		{
			rut = crut.charAt(0);
		}

		dv = crut.charAt(largo-1);
		if ( rut == null || dv == null )
		{
			return 0;
		}

		var dvr = '0'; 
		suma = 0;
		mul  = 2;
		for (i = rut.length - 1 ; i >= 0; i--)
		{
			suma += rut.charAt(i) * mul;
			if (mul == 7)
			{
				mul = 2;
			}
			else
			{
				mul++;
			}
		}
		res = suma % 11;
		if (res == 1)
		{
			dvr = 'k';
		}
		else if (res == 0)
		{
			dvr = '0'; 
		}
		else
		{
			dvi = 11-res;
			dvr = dvi + "";
		}

		if ( dvr != dv.toLowerCase() )
		{
			//return false;
			return "malo";
		}

	return dvr; 
}
		function MM_openBrWindow(theURL,winName,features)
		{ 
		  window.open(theURL,winName,features);
		}
		function Permut (flag,img) {
						   if (document.images) {
						        if (document.images[img].permloaded) {
						            if (flag==1) document.images[img].src = document.images[img].perm.src
						            else document.images[img].src = document.images[img].perm.oldsrc
						        }
						   }
		}
		function preloadPermut (img,adresse) {
		   if (document.images) {
		       img.onload = null;
		       img.perm = new Image ();
		       img.perm.oldsrc = img.src;
		       img.perm.src = adresse;
		       img.permloaded = true;
		   }
		}
