﻿function statusbar() {
    window.status = "Banco Financiero";
    setTimeout("statusbar()", 100);
}
function redirect(URL){
    document.location = URL;
    return false;
}
/*Validaciones en general*/
function validarNumeros(ctl){
    var bOk = /^ *[0-9]+ *$/.test(ctl.value);
    if(!bOk){
        alert("Ingresa sólo números para el teléfono por favor");
        ctl.selected = true;
    }
    return bOk;
}
/*Para realizar la búsqueda con el buscador de Google*/
function buscarCSE(id){
    if(window.event.keyCode == 13){
        for(i = 0; i < document.forms(0).elements.length; i++){
            elm = document.forms(0).elements(i);
            if (elm.id.indexOf(id) != -1){
                elm.click();
                if (document.all && window.event) event.returnValue = false;
                return false;
            }
        }
    }
}
/*Para la validación del límite de caracteres para los mensajes de contáctenos*/
function contarCaracteres(ctl) {
    document.forms[0].contador.value = ctl.value.length;
}

function validarMensaje(ctl) {
    cantMax = document.forms[0].total.value;
    if (ctl.value.length > cantMax)
        ctl.value = ctl.value.substring(0, cantMax);
    contarCaracteres(ctl);
}
/*Pre-validaciones de banca por Internet*/
function redireccionarBancaPorInternet(){
    //parent.location.href="Transaccional.aspx";
    window.open("Transaccional.aspx", "", "status=0,location=0,width=1014px,height=768px,top=0,left=0");
}

function redireccionarSolicitud(){
    parent.location.href="Solicitud.aspx";
}

function agregarNumero(value){
    var ctl = document.forms[0].pwdCodigo;
    if(ctl.value.length < 6)
        ctl.value = ctl.value + value;
}

function limpiarCodigo(){
    document.forms[0].pwdCodigo.value = '';
}
/*Validaciones de número de documento de identidad*/
function ingresoSoloNumerosEnLinea(){
	var iAscii, Ok; 
	if (window.event.keyCode){iAscii = window.event.keyCode;}
	else if (window.event.which){iAscii = window.event.which;}
	else {iAscii = 13;}
	if (iAscii != 13){
		Ok = (47 < iAscii && iAscii < 58);
		if (!Ok){ window.event.keyCode=0; }
	}
}
function ingresoSoloNumeros(ctl){
	if(isNaN(ctl.value)){
	    alert("Ingresa sólo números para los teléfonos. Intenta nuevamente por favor.");
	    ctl.value = '';
	    return false;
	}
}
/*Validación de control de espacio*/
function trim(s) {
	var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null) ? "" : m[1];
}
/*Validación para el control en el formato del e-mail*/
function validarEmail(ctl){
    if(trim(ctl.value) == '') return;
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(!pattern.test(ctl.value)){
		alert("El correo electrónico ingresado es incorrecto. Debe tener el siguiente formato [cuenta]@[dominio]\nPor ejemplo: juanperez@hotmail.com");
		//ctl.focus();
		//ctl.select();
		ctl.value = '';
		if (document.all && window.event) event.returnValue = false;
        return false;
    }
}
/*Validaciones de entrada de datos*/
function validarEntradaDatos(){
    var elem;
    for(var i = 0; i < document.forms[0].elements.length; i++ ){
        elem = document.forms[0].elements[i];
        if(elem.id.indexOf("txtNombre") >-1 ){
            if(trim(elem.value) == ''){
                alert("Debes ingresar tu nombre. Intenta nuevamente por favor.");
                if (document.all && window.event) event.returnValue = false;
                return false;
            }
        }
		if(elem.id.indexOf("txtApellidos") >-1 ){
            if(trim(elem.value) == ''){
                alert("Debes ingresar tu apellido. Intenta nuevamente por favor.");
                if (document.all && window.event) event.returnValue = false;
                return false;
            }
        }
		if(elem.id.indexOf("txtDocumento") >-1 ){
            if(trim(elem.value) == ''){
                alert("Debes ingresar tu documento de identidad. Intenta nuevamente por favor.");
                if (document.all && window.event) event.returnValue = false;
                return false;
            }	
        }
		if(elem.id.indexOf("txtCorreoElectronico") >-1 ){
            if(trim(elem.value) == ''){
                alert("Debes ingresar tu correo electrónico para comunicarnos con usted a la brevedad posible. Intenta nuevamente por favor.");
                if (document.all && window.event) event.returnValue = false;
                return false;
            }			
        }
        if(elem.id.indexOf("txtMensaje") >-1 ){
            if(trim(elem.value) == ''){
                alert("Debes ingresar tu consulta o mensaje. Intenta nuevamente por favor.");
                if (document.all && window.event) event.returnValue = false;
                return false;
            }        
		}
		if(elem.id.indexOf("ddlTipoSolicitud") >-1 ){
            if(indicarCamposObligatorios(elem)){
                if(subValidacionSolicitud() == false){
                    if (document.all && window.event) event.returnValue = false;
                    return false;
                }
            }
		}
    }
}
/*Validación de campos obligatorios*/
function indicarCamposObligatorios(ctl){
    var seltxt = ctl.options[ctl.selectedIndex].text;
    /****************************************************/
    if(seltxt.indexOf('producto')!=-1 || seltxt.indexOf('representante')!=-1)
    {
        document.forms[0].imgco6.style.visibility = 'visible';
        document.forms[0].imgco7.style.visibility = 'visible';
        return true;
    }
    else
    {
        document.forms[0].imgco6.style.visibility = 'hidden';
        document.forms[0].imgco7.style.visibility = 'hidden';
        return false;
    }
}
function preVerificarCamposObligatorios(){
    var elem;
    for(var i = 0; i < document.forms[0].elements.length; i++ ){
        elem = document.forms[0].elements[i];
        if(elem.id.indexOf("ddlTipoSolicitud") >-1 )
            indicarCamposObligatorios(elem);
    }
}
/*Verificación de la banca y productos*/
function subValidacionSolicitud(){
    var elem;
    for(var i = 0; i < document.forms[0].elements.length; i++ ){
        elem = document.forms[0].elements[i];
        if(elem.id.indexOf("ddlTipoSolicitud") >-1 ){
            if(elem.value == 0){
                alert("Debes seleccionar un motivo para registrar tu solicitud. Intenta nuevamente por favor.");
                return false;
            }
        }        
        if(elem.id.indexOf("ddlTipoBanca") >-1 ){
            if(elem.value == 0){
                alert("Debes seleccionar una banca para registrar tu solicitud. Intenta nuevamente por favor.");
                return false;
            }
        }
        if(elem.id.indexOf("ddlProductos") >-1 ){
            if(elem.value == 0){
                alert("Debes seleccionar un producto para registrar tu solicitud. Intenta nuevamente por favor.");
                return false;
            }
        }        
    }
    return true;
}

function validarStatusBar(){
    var elem;
    //alert(document.forms[0].elements.length);
    //alert(document.anchors.length);
    elem = document.getElementsByTagName('a');
    for(var i=0; i < elem.length; i++){
        elem[i].onmousemove = function(){ window.status = "Banco Financiero" };
    }
}

function validarPreConsulta(){
    var elem;
    var nAreaMinima;
    var nAreaMaxima;
    var nPrecioMinimo;
    var nPrecioMaximo;

    for(var i = 0; i < document.forms[0].elements.length; i++ ){
        elem = document.forms[0].elements[i];
        if(elem.id.indexOf("txtAreaMinima") >-1 ){
            if(trim(elem.value) != ''){
                if(isNaN(trim(elem.value))){
                    alert("Ingresa solamente valores números para área mínima.Intenta nuevamente por favor.");
                    if (document.all && window.event) event.returnValue = false;
                    return false;                
                }else{
                    nAreaMinima = parseFloat(trim(elem.value));    

                    if(nAreaMinima > 999999){
                        alert("El área mínima no debe ser mayor a 1 000 000.00");
                        if (document.all && window.event) event.returnValue = false;
                        return false;
                    }                    
                }
            }
        }
        if(elem.id.indexOf("txtAreaMaxima") >-1 ){
            if(trim(elem.value) != ''){
                if(isNaN(trim(elem.value))){
                    alert("Ingresa solamente valores números para área máxima.Intenta nuevamente por favor.");
                    if (document.all && window.event) event.returnValue = false;
                    return false;                
                }else{
                    nAreaMaxima = parseFloat(trim(elem.value));    

                    if(nAreaMaxima > 999999){
                        alert("El área maxima no debe ser mayor a 1 000 000.00");
                        if (document.all && window.event) event.returnValue = false;
                        return false;
                    }                    
                }
            }        
		}
		if(elem.id.indexOf("txtPrecioMinimo") >-1 ){
            if(trim(elem.value) != ''){
                if(isNaN(trim(elem.value))){
                    alert("Ingresa solamente valores números para el precio mínimo.Intenta nuevamente por favor.");
                    if (document.all && window.event) event.returnValue = false;
                    return false;                
                }else{
                    nPrecioMinimo = parseFloat(trim(elem.value));    

                    if(nPrecioMinimo > 99999999){
                        alert("El precio mínimo no debe ser mayor a 100 000 000.00");
                        if (document.all && window.event) event.returnValue = false;
                        return false;
                    }                   
                }
            }		
        }
        if(elem.id.indexOf("txtPrecioMaximo") >-1 ){
            if(trim(elem.value) != ''){
                if(isNaN(trim(elem.value))){
                    alert("Ingresa solamente valores números para el precio máximo.Intenta nuevamente por favor.");
                    if (document.all && window.event) event.returnValue = false;
                    return false;                
                }else{
                    nPrecioMaximo = parseFloat(trim(elem.value));  

                    if(nPrecioMaximo > 99999999){
                        alert("El precio máximo no debe ser mayor a 100 000 000.00");
                        if (document.all && window.event) event.returnValue = false;
                        return false;
                    }
                }
            }
        }
    
        if(nAreaMaxima < nAreaMinima){
            alert("El área máxima debe ser mayor que el área mínima");
            if (document.all && window.event) event.returnValue = false;
            return false;
        }

        if(nPrecioMaximo < nPrecioMinimo){
            alert("El precio máximo debe ser mayor que el precio mínimo");
            if (document.all && window.event) event.returnValue = false;
            return false;
        }        
    }   
}

function MarcarEnlaceProducto(valor){
    var elem;
    elem = document.getElementsByTagName('a');
    for(var i=0; i < elem.length; i++){
        if(document.all){
            if(elem[i].innerText == valor){
                elem[i].style.color = "#ffffff";
                elem[i].style.textDecoration = "none";
            }
        } else{
            if(elem[i].textContent == valor){
                elem[i].style.color = "#ffffff";
                elem[i].style.textDecoration = "none";
            }
        }
    }
}

 function DoFlash(){
			window.open('../../Flash/CatCar.html',"",'scrollbars=no,width=912,height=583,TOP=50,LEFT=50');
			                        			            			
	}

function MouseTabs(ctl){
    document.getElementById(ctl.getAttribute("rel")).className="";
    document.getElementById(ctl.getAttribute("rel")).style.display="block";
    document.getElementById(ctl.getAttribute("rel")).style.visibility="visible";
}