function CSSConfig(carpeta,archivo) {

	var urlcss = "/TarjetaMasWEB/css/"+carpeta+"/"+archivo;
	if (carpeta == null || carpeta.lenght == 0) {
		urlcss = "/TarjetaMasWEB/css/"+archivo;
	}
	var heads = document.getElementsByTagName('HEAD');
	
	if (heads || heads.length) {
		oPrintElm = document.createElement('LINK');
		oPrintElm.setAttribute('type', 'text/css');
		oPrintElm.rel = 'stylesheet';
		oPrintElm.media = 'all';
		oPrintElm.href = urlcss;
		oPrintElm.setAttribute('id', 'cssTMAS'+Math.round(Math.random()*10));
		heads[0].appendChild(oPrintElm);
	}
}

function cerrardiv(divid) {
	div = document.getElementById(divid);
	div.style.display='none';
}

function muestradiv2(id) {
	posicionCuadroMensaje();
	document.getElementById(id).style.display = "block";
}

function isNumberKeyRut(evt){
        //list all CTRL + key combinations you want to disable
        var forbiddenKeys = new Array("a","n","c","x","v","j");
        var key;
        var isCtrl;
        var i;
        var charCode = (evt.which) ? evt.which : evt.keyCode
   		if (charCode > 31 && (charCode < 48 || charCode > 57)){
   			return false;
   		}
        if(window.event)
        {
                key = window.event.keyCode;     //IE      
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = evt.which;     //firefox
                if(evt.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        //if ctrl is pressed check if other key is in forbidenKeys array       
        if(isCtrl)
        {
                for(i=0; i<forbiddenKeys.length ; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                return false;
                        }
                }
        return false;
        }
        return true;
}

function EliminarPegar(evt) {
 		var forbiddenKeys = new Array("a","n","c","x","v","j");
        var key;
        var isCtrl;
        var i;
		var charCode = (evt.which) ? evt.which : evt.keyCode;		
		if(window.event)
        {
                key = window.event.keyCode;     //IE      
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = evt.which;     //firefox
                if(evt.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array
        if(isCtrl) {
                for(i=0; i<forbiddenKeys.length ; i++) {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                return false;
                        }
                }
        return false;
        }
}

function isNumberKeyDv(evt){
   var charCode = (evt.which) ? evt.which : evt.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57)){
	   	if (charCode < 107 && charCode > 75)
	   	return false;
   	   	if (charCode < 75) 
	   	return false;
	   	if (charCode > 107)    		
	   	return false;
	}
   return true;
}

function limpialayer(valor){
	if (valor =="rut" || valor =="dv" || valor =="clave")
	document.getElementById('cont_mensaje_error').style.display = "none";
	document.getElementById('cont_mensaje_rut').style.display = "none";
	document.forms.form1.rut.style.background = "#FFFFFF";
	document.forms.form1.dv.style.background = "#FFFFFF";
	document.getElementById('cont_mensaje_clave').style.display = "none";
	document.forms.form1.clave.style.background = "#FFFFFF";
	
	
}

function submitenter(form_name,ssl,e)
{

var keycode;
if( !isNumberKeyPhone(e)){ return false; }
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {

   if(form_name == "formBloqueo"){
//        alert('validabloqueo: ' + form_name);
         validarBloqueo(form_name, ssl);
   //myfield.form.submit();
   } else if(form_name == "FormSolicitante_avance"){
  //      alert('validadisponible/super disponible: ' + form_name);   
	    ValRegUsuVerPublicDisp();
   } else if(form_name == "FormSolicitante_simula"){
    //    alert('simulador: ' + form_name);   
       ValRegUsuVerPublic();
   } else{
      //   alert('validalogin: ' + form_name);
        validalogin(form_name, ssl);
	}

//   return false;
   }
else
  {
   return true;
   }
}

function ValRegUsuVerPublic(){     
    var rutIngreso = document.FormSolicitante_simula.rut_avance_val.value+'-'+document.FormSolicitante_simula.dv_avance_val.value;
    var claveIngreso = document.FormSolicitante_simula.pass_avance.value;
    var rut = document.FormSolicitante_simula.rut_avance_val.value;
    var dv = document.FormSolicitante_simula.dv_avance_val.value
    var validacionOK = true;
    var esRutValido = Valida_RUT(rut, dv);
                
    if ((document.FormSolicitante_simula.rut_avance_val.value == '') || (document.FormSolicitante_simula.dv_avance_val.value == '') ){
            document.getElementById('rut_avance_val').style.textAlign="left";
            document.getElementById('rut_avance_val').style.background = "#fedfdd";
            document.getElementById('dv_avance_val').style.background = "#fedfdd";
            posicionCuadroMensaje();
            document.getElementById('mensaje_error_datos_r').style.display = "block";        
            validacionOK = false;
    }
    else {    
            document.getElementById('rut_avance_val').style.textAlign="right";
            document.getElementById('rut_avance_val').style.background = "#FFFFFF";
            document.getElementById('dv_avance_val').style.background = "#FFFFFF";        

            if ( esRutValido) {
                document.getElementById('rut_avance_val').style.textAlign="right";
                document.getElementById('rut_avance_val').style.background = "#FFFFFF";
                document.getElementById('dv_avance_val').style.background = "#FFFFFF";        
            
            }else{
                    document.getElementById('rut_avance_val').style.textAlign="left";
                    posicionCuadroMensaje();
                    document.getElementById('mensaje_rut_error_super_tarjeta_avance1').style.display = "block";
                    document.getElementById('rut_avance_val').style.background = "#fedfdd";
                    document.getElementById('dv_avance_val').style.background = "#fedfdd";
                    document.getElementById('pass_avance').style.background = "#fedfdd";
                    validacionOK = false;
            }
    }
    if(document.FormSolicitante_simula.pass_avance.value == ''){
        document.getElementById('pass_avance').style.background = "#fedfdd";            
        posicionCuadroMensaje();
        document.getElementById('mensaje_error_datos_r').style.display = "block";
        validacionOK = false;
    }
    
    if( validacionOK )
    {
        document.FormSolicitante_simula.action="simularPublico2.do?accion=logueo";
        formElementsToUpperCase(FormSolicitante_simula);
        document.FormSolicitante_simula.submit();
    }
    
}

function Valida_RUT(fElRut,fElDv){
	var ElRut  = fElRut;
	var ElDv  = fElDv;	
	var largo_rut = ElRut.length;
	var largo_dv = ElDv.length;
	var RutC = ElRut+ElDv;
	var rut00 = "000000000";
	if (rut00.substring(0, largo_rut) == ElRut){
         return (false);
	}
	if (largo_rut==0) {
         return (false);
	}
	if (largo_dv==0) {
         return (false);
    } else if ( largo_dv == 2 ){
         return (false);
    }
	for(i=0;i>largo_rut;i++){
		c=ElRut.charAt(i);
		if (c<"0" || c>"9"){
             return (false);
		}
	}
    c=ElDv.charAt(0);
	if ( (c<"0" || c>"9") && c!="K" && c!="k"){
           return (false);
	}
	var suma=0;
	var mult=2;
	if (ElDv=="K") ElDv="10";
	if (ElDv=="k") ElDv="10";
	for (i=largo_rut-1;i>=0;i--){
		c=ElRut.charAt(i);
		suma+=parseInt(c,10)*mult;
		mult++;
		if (mult>7) mult=2;
	}
	var calculado=11-suma%11;
	if (calculado==11) calculado=0;
	if(parseInt(ElDv)!=calculado){
    	return (false);
    }
	return (true);
}

function ValRegUsuVerPublicDisp(){
	
	var rutIngreso = document.FormSolicitante_avance.rut_avance_val.value+'-'+document.FormSolicitante_avance.dv_avance_val.value;
	var claveIngreso = document.FormSolicitante_avance.pass_avance.value;
		
	var rut = document.FormSolicitante_avance.rut_avance_val.value;
	var dv = document.FormSolicitante_avance.dv_avance_val.value
		
	var validacionOK = true;
	var esRutValido = Valida_RUT(rut, dv);
	
	if ((document.FormSolicitante_avance.rut_avance_val.value == '') || (document.FormSolicitante_avance.dv_avance_val.value == '') ){
		
			document.getElementById('rut_avance_val').style.textAlign="left";
			document.getElementById('rut_avance_val').style.background = "#fedfdd";
			document.getElementById('dv_avance_val').style.background = "#fedfdd";
			posicionCuadroMensaje();
			document.getElementById('faltan_datos_super_tarjeta_avance1').style.display = "block";		
			validacionOK = false;
	}
	else {	
			
			document.getElementById('rut_avance_val').style.textAlign="right";
			document.getElementById('rut_avance_val').style.background = "#FFFFFF";
			document.getElementById('dv_avance_val').style.background = "#FFFFFF";		

			if ( esRutValido) {
				document.getElementById('rut_avance_val').style.textAlign="right";
				document.getElementById('rut_avance_val').style.background = "#FFFFFF";
				document.getElementById('dv_avance_val').style.background = "#FFFFFF";		
			
			}else{
					document.getElementById('rut_avance_val').style.textAlign="left";
					posicionCuadroMensaje();
					document.getElementById('mensaje_rut_error_super_tarjeta_avance1').style.display = "block";
					document.getElementById('rut_avance_val').style.background = "#fedfdd";
					document.getElementById('dv_avance_val').style.background = "#fedfdd";
					document.getElementById('pass_avance').style.background = "#fedfdd";
					validacionOK = false;
			}
			
	}
		
	if(document.FormSolicitante_avance.pass_avance.value == ''){
		document.getElementById('pass_avance').style.background = "#fedfdd";			
		posicionCuadroMensaje();
		document.getElementById('faltan_datos_super_tarjeta_avance1').style.display = "block";
		validacionOK = false;
	}
	
	if( validacionOK )
	{
		document.FormSolicitante_avance.action="avance.do";
		formElementsToUpperCase(FormSolicitante_avance);
		document.FormSolicitante_avance.submit();
	}
	
}

function Trim(cadena) {
 if (cadena==null) return "";
 var s = 0;
 var e = cadena.length - 1;
 if (e < s) return '';
 for (var i=0; i < cadena.length; i++){
   if ((cadena.charAt(i) != " ") && (cadena.charAt(i) != '\t')) {
     s = i;
     break;
   }
 }
 if (s == 0 && ((cadena.charAt(s) == " ") || (cadena.charAt(s) == '\t')))
   return '';
 for (var i = cadena.length - 1; i >= 0; i--) {
   if ((cadena.charAt(i) != " ") && (cadena.charAt(i) != '\t')){
     e = i;
     break;
   }
 }
 return cadena.substring(s,(e+1));
}

function marcaGoogle(Tarjeta) {
	var nombreTarjeta;
try {
var pageTracker = _gat._getTracker("UA-7553944-1");

	
	if(Tarjeta == "000001|001")
		nombreTarjeta = "Paris"
	if(Tarjeta == "615290|902")
		nombreTarjeta = "Jumbo"	
	if(Tarjeta == "615290|942")
		nombreTarjeta = "Easy"
	if(Tarjeta == "615290|962")
		nombreTarjeta = "Tur-Bus"
	
	pageTracker._trackPageview("/Intenta_"+nombreTarjeta);
} catch(err) {}
}

function validalogin(form1, ssl) {

	var ElRut = Trim(document.forms.form1.rut.value.toUpperCase());
	var ElDv = document.forms.form1.dv.value.toUpperCase();
	var LaTarjeta = document.forms.form1.tarjeta.value;
	var LaClave = Trim(document.forms.form1.clave.value.toUpperCase());	

//	var key = Trim(document.getElementById('key').value.toUpperCase());	
//	alert("key =" + key);
	
	var largo_rut = ElRut.length;
	var largo_dv = ElDv.length;
	var largo_clave = LaClave.length;
	var RutC = ElRut+ElDv;
	document.forms.form1.clave.value = LaClave;
	var rut00 = "000000000";
	
	if (largo_rut==0 || largo_dv==0 || largo_clave == 0 || LaTarjeta.value == "") {
           var band = 0;
           posicionCuadroMensaje();
           div = document.getElementById('cont_mensaje_error');
		   div.style.display = 'block';
           document.forms.form1.rut.focus();
	} else {
        if (rut00.substring(0, largo_rut) == ElRut){
            //alert("largorut");
            var band = 0;
            mostrardiv();
        	document.forms.form1.rut.focus();
         
        }
        for(i=0;i<largo_rut;i++){
		c=ElRut.charAt(i);
		if (c<"0" || c>"9"){
	        //alert("largo de rut");
	        var band = 0;
	        mostrardiv();
	        document.forms.form1.rut.focus();
		}
		
	}
		
	var suma=0;
	var mult=2;
	if (ElDv=="K") ElDv="10";
	for (i=largo_rut-1;i>=0;i--){
		c=ElRut.charAt(i);
		suma+=parseInt(c,10)*mult;
		mult++;
		if (mult>7) mult=2;
	}
	var calculado=11-suma%11;
	if (calculado==11) calculado=0;
		if(parseInt(ElDv)!=calculado){
	        var band = 0;
	        mostrardiv();
			document.forms.form1.rut.focus();
	    }
	    if (LaTarjeta == "") {
			var band = 0;
	    	errorTarjeta();
	    	document.forms.form1.tarjeta.focus();
	    }
		if (band != 0) {
			if (ssl) {
				document.getElementById(form1).action=document.getElementById('secureUrl').value;
			} else {
				document.getElementById(form1).action="/TarjetaMasWEB/autenticar.do";
			}
			marcaGoogle(LaTarjeta);
			formElementsToUpperCase(document.getElementById(form1));
			document.getElementById(form1).submit();
		}
	}		
}

function validaMailOfertas(){
	if(valida_email(document.getElementById("mail_ofertas").value)){						
		document.getElementById('mail_ofertas').style.background = "#FFFFFF";		
		formElementsToUpperCase(document.getElementById('form-email-footer'));
		document.getElementById('form-email-footer').submit();				
	}else{
		document.getElementById('mail_ofertas').style.background = "#fedfdd";		
		muestraError("", "error_mail_ofertas");
	}
}

function on_focus(){
	if(document.forms.length > 0) {
		for(var i=0; i < document.forms[0].elements.length; i++) {
			document.forms[0].elements[i].style.background = "#FFFFFF";
		}
	}
}

function on_focus(){
	
	if(document.forms.length > 0)
		{
		for(var i=0; i < document.forms[0].elements.length; i++)
			{    
			document.forms[0].elements[i].style.background = "#FFFFFF";
			}
		}
	
	try {
		document.getElementById('faltan_solicitud_error2').style.display = "none";
		document.getElementById('rut_solicitud_error2').style.display = "none";
		document.getElementById('rut_solicitud_error3').style.display = "none";
		document.getElementById('rut_solicitud_error4').style.display = "none";
		document.getElementById('mail_solicitud_error2').style.display = "none";
	} catch (e) {
	
	}

	try {
		document.getElementById('error_dato_incorrecto').style.display = "none";
		document.getElementById('faltan_datos_contacto').style.display = "none";
		document.getElementById('error_mail_contacto').style.display = "none";
		document.getElementById('error_mail2_contacto').style.display = "none";
		document.getElementById('error_fono_contacto_remision').style.display = "none";
	} catch (e) {
	
	}

}

function isNumberKeyPhone(evt){
   var charCode = (evt.which) ? evt.which : evt.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
	   return false;     
   return true;
}

function isAlfanumerico(evt){ 
        var forbiddenKeys = new Array("a","n","c","x","v","j");
        var key;
        var isCtrl;
        var i;
		var tecla = (evt.which) ? evt.which : evt.keyCode;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
	
	
    	if(window.event)
        {
                key = window.event.keyCode;     //IE      
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = evt.which;     //firefox
                if(evt.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array
        if(isCtrl)
        {
                for(i=0; i<forbiddenKeys.length ; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                return false;
                        }
                }
        return false;
        }
        
        if(65<=tecla && tecla<=90 || 97<=tecla && tecla<=122 || tecla == 32 || tecla == 8 || tecla == 9 || tecla == 241){
	 		return true;
		} else {
     		return false; 
    	}
    	return true;
}

function isCaracterEmail(evt) {
	var tecla = (evt.which) ? evt.which : evt.keyCode;
	var isCtrl = false;
	var isShift = false;
	var teclasPermitidas = new Array("a","n","c","x","v","j", "~", "¬");
	var codigosNoPermitidos = new Array('!', '"', '#', '$', '%', '&', '/', '(', ')', '=', '\'', '¿', '¡', '?', '-', ':', ';', ',', '°', '|', '¬', '´', '+', '{', '}', '[', ']', '<', '>', '/', '*', '´', '¨', '~');
	var noPermitidosSinShift = new Array("|", "/", "*", "-", "+", "<", "´", "{", "}", ",", "'", "¿");
	if (window.event) {
		key = window.event.keyCode;     //IE      
		isCtrl = false;
		if (window.event.ctrlKey) { isCtrl = true; }
		if (window.event.shiftKey) { isShift = true; }
	} else {			
		key = evt.which;     //firefox
		isCtrl = false;
		if (evt.ctrlKey) { isCtrl = true; }
		if (evt.shiftKey) { isShift = true; }
	}
	if (isCtrl) {
		for (i = 0; i < teclasPermitidas.length; i++) {
			if (teclasPermitidas[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) {
				return false;
				break;
			}
		}
	}
	if (isShift) {
		for (j = 0; j < codigosNoPermitidos.length; j++) {
			if (codigosNoPermitidos[j] == String.fromCharCode(key).toLowerCase()) {
				return false;
				break;
			}
		} 		
	} else {
		for (k = 0; k < noPermitidosSinShift.length; k++) {
			if (noPermitidosSinShift[k] == String.fromCharCode(key).toLowerCase()) {
				return false;
				break;
			}
		} 
	}		
}

function isCadenaValidaCaptcha(evt){
	var tecla = (evt.which) ? evt.which : evt.keyCode	
	if( ( isAlfanumerico(evt) || isNumberKey(evt) || tecla == 45) && tecla != 37 ){
	  return true;
	} else {
      return false; 
    }	
}

function validaLargoTextArea(campo, largo, evt) {
	var key = null;
	var isShift = false;
	if (window.event) {
		key = window.event.keyCode;     //IE      
		if (window.event.shiftKey) { isShift = true; }
	} else {			
		key = evt.which;     //firefox
		if (evt.ctrlKey) { isCtrl = true; }
	}
	
	if (campo.value.length > largo) {
		if (key == 8 || key == 0) return true;
		alert("Solo se permiten "+largo+" caracteres ");
		campo.value.substring(0, largo); 		
		return false;
	}		
	return true;
}

function CerrarLayer(divid) {
	div = document.getElementById(divid);
	div.style.display='none';
}

function CerrarLayer(parametro){

document.getElementById(parametro).style.display = "none";
	
}

function cambiaEstilo(variable){
	document.getElementById(variable).style.textAlign="right";	
}

function validarCirculomas(){
	if ((document.FormCirculomas.rut_circulo.value == '') && (document.FormCirculomas.dv_circulo.value == '')){
		document.getElementById('cont_mensaje_rut_circulo').style.display = "block";
		document.getElementById('rut_circulo').style.textAlign="left";	
		document.getElementById('rut_circulo').style.background = "#fedfdd";
		document.getElementById('dv_circulo').style.background = "#fedfdd";
	} else {
		document.getElementById('rut_circulo').style.textAlign="right";
		document.getElementById('rut_circulo').style.background = "#FFFFFF";
		document.getElementById('dv_circulo').style.background = "#FFFFFF";
		if(!Valida_RUT(document.FormCirculomas.rut_circulo.value,document.FormCirculomas.dv_circulo.value))
		{
			document.getElementById('rut_circulo').style.background = "#fedfdd";
			document.getElementById('dv_circulo').style.background = "#fedfdd";
			document.getElementById('rut_circulo').style.textAlign="left";
			document.getElementById('cont_mensaje_rut_circulo').style.display = "block";
		} else {
			document.getElementById('rut_circulo').style.background = "#FFFFFF";
			document.getElementById('dv_circulo').style.background = "#FFFFFF";
			document.getElementById('rut_circulo').style.textAlign="right";
			document.getElementById('cont_mensaje_rut_circulo').style.display = "none";
		}
	}
	if ((document.FormCirculomas.rut_circulo.value != '') && (document.FormCirculomas.dv_circulo.value != '') &&  (!Valida_RUT(document.FormCirculomas.rut_circulo.value,document.FormCirculomas.dv_circulo.value) == false) ){
		document.getElementById('FormCirculomas').action="/TarjetaMasWEB/consultarPuntos.do?action=puntosCalculo";
		formElementsToUpperCase(document.getElementById('FormCirculomas'));
		document.getElementById('FormCirculomas').submit();	 
	}
}

function validarCirculomas(){
	
	if ((document.FormCirculomas.rut_circulo.value == '') && (document.FormCirculomas.dv_circulo.value == '')){
		
		
		document.getElementById('cont_mensaje_rut_circulo').style.display = "block";
		document.getElementById('rut_circulo').style.textAlign="left";
		
			
		document.getElementById('rut_circulo').style.background = "#fedfdd";
		document.getElementById('dv_circulo').style.background = "#fedfdd";
		
		
	}
	else {
		
		document.getElementById('rut_circulo').style.textAlign="right";
		document.getElementById('rut_circulo').style.background = "#FFFFFF";
		document.getElementById('dv_circulo').style.background = "#FFFFFF";
		
		if(!Valida_RUT(document.FormCirculomas.rut_circulo.value,document.FormCirculomas.dv_circulo.value))
		{
			document.getElementById('rut_circulo').style.background = "#fedfdd";
			document.getElementById('dv_circulo').style.background = "#fedfdd";
			document.getElementById('rut_circulo').style.textAlign="left";
			document.getElementById('cont_mensaje_rut_circulo').style.display = "block";
			
		}
		else {
			document.getElementById('rut_circulo').style.background = "#FFFFFF";
		document.getElementById('dv_circulo').style.background = "#FFFFFF";
			document.getElementById('rut_circulo').style.textAlign="right";
			document.getElementById('cont_mensaje_rut_circulo').style.display = "none";
		}
	}
	
	if ((document.FormCirculomas.rut_circulo.value != '') && (document.FormCirculomas.dv_circulo.value != '') &&  (!Valida_RUT(document.FormCirculomas.rut_circulo.value,document.FormCirculomas.dv_circulo.value) == false) ){
		
		formElementsToUpperCase(document.FormCirculomas);
		document.FormCirculomas.submit();
		//	location.href = "?page=columna_circulo_mas_puntos";
		
		}
	
}

function validarBloqueo(form1, ssl){	

	var rutIngreso = Trim(document.getElementById('rut_bloqueo').value.toUpperCase())+'-'+document.getElementById('dv_bloqueo').value.toUpperCase(); //document.formBloqueo.rut_bloqueo.value+'-'+document.formBloqueo.dv_bloqueo.value;
	var claveIngreso = Trim(document.getElementById('clave_bloqueo').value.toUpperCase()); //document.formBloqueo.clave_bloqueo.value;
	
	//document.getElementById('error_tarjeta_bloqueo').style.display = "none";
	if (document.formBloqueo.rut_bloqueo.value == '') {
		document.getElementById('rut_bloqueo').style.textAlign="left";
		document.getElementById('rut_bloqueo').style.background = "#fedfdd";
		document.getElementById('dv_bloqueo').style.background = "#fedfdd";	
		muestraError("Por favor, ingresa los datos requeridos.", "error_login_bloqueo");
		if (document.formBloqueo.tarjeta.value == '') {
			document.formBloqueo.tarjeta.style.background = "#fedfdd";
		} else {
			document.formBloqueo.tarjeta.style.background = "#ffffff";
		}
		if (document.formBloqueo.clave_bloqueo.value == ''){
			document.getElementById('clave_bloqueo').style.background = "#fedfdd";
		}
	} else {
		if(!Valida_RUT(document.getElementById('rut_bloqueo').value.toUpperCase(),document.getElementById('dv_bloqueo').value.toUpperCase())) {
			document.getElementById('rut_bloqueo').style.textAlign="left";
			document.getElementById('rut_bloqueo').style.background = "#fedfdd";
			document.getElementById('dv_bloqueo').style.background = "#fedfdd";	
			muestraError("El RUT ingresado no es v&aacute;lido,<br/>por favor int&eacute;ntalo nuevamente.", "error_login_bloqueo");
			if (document.formBloqueo.tarjeta.value == '') {
				document.formBloqueo.tarjeta.style.background = "#fedfdd";
			} else {
				document.formBloqueo.tarjeta.style.background = "#ffffff";
			}
			if (document.formBloqueo.clave_bloqueo.value == ''){
				document.getElementById('clave_bloqueo').style.background = "#fedfdd";
			} 
		} else {
			document.getElementById('rut_bloqueo').style.textAlign="right";
			document.getElementById('rut_bloqueo').style.background = "#FFFFFF";
			document.getElementById('dv_bloqueo').style.background = "#FFFFFF";
			if (document.formBloqueo.tarjeta.value == '') {
				document.formBloqueo.tarjeta.style.background = "#fedfdd";
				muestraError("Debe seleccionar su tarjeta,<br/>	por favor int&eacute;ntalo nuevamente.", "error_login_bloqueo");
			} else {
				document.formBloqueo.tarjeta.style.background = "#ffffff";
				if (document.formBloqueo.clave_bloqueo.value == '') {
					document.getElementById('clave_bloqueo').style.background = "#fedfdd";
					muestraError("Por favor, ingresa los datos requeridos.", "error_login_bloqueo");
				} else {
					document.getElementById('clave_bloqueo').style.background = "#ffffff";
					document.formBloqueo.tarjeta.style.background = "#ffffff";
					if (ssl) {
						document.getElementById(form1).action="https://www.tarjetamas.cl/TarjetaMasWEB/bloquearLogin.do";
					} else {
						document.getElementById(form1).action="/TarjetaMasWEB/bloquearLogin.do";
					}
					formElementsToUpperCase(document.getElementById(form1));
					document.getElementById(form1).submit();
				}
			}
		}
	}  
}

function isDvRut(evt) {
	var digitosPermitidos = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "k");
	var tecla = (evt.which) ? evt.which : evt.keyCode;
	if (window.event) {
		key = window.event.keyCode;     //IE      
	} else {			
		key = evt.which;     //firefox
	}
	var TeclaString = String.fromCharCode(key).toLowerCase();
	for (i = 0; i < digitosPermitidos.length; i++) {
		if (digitosPermitidos[i] == TeclaString) {
			return true;
		}
	}
	if (key == 8 || key == 0) {
		return true;
	}
	return false;
}

function mostrardiv() {
	div = document.getElementById('cont_mensaje_rut');
	div.style.display = 'block';
	if ($.browser.msie && $.browser.version == 6.0) {
		var newTop = ($(window).scrollTop() + 100)+'px';
		$(".cuadro_mensaje_error").css('top', newTop);
		$(".fondo_mensaje").css('width', document.body.offsetWidth);
		$(".fondo_mensaje").css('height', document.body.offsetHeight);
	}
}

function errorTarjeta() {
	div = document.getElementById('cont_mensaje_tarjeta');
	div.style.display = 'block';
}
function validarSolicitante(){
	
	var formIngresoSolicitante = document.getElementById('formIngresoSolicitante');
	if ((formIngresoSolicitante.rut_solicitante.value == '') && (formIngresoSolicitante.dv_solicitante.value == '')){
		document.getElementById('rut_solicitante').style.textAlign="left";
		document.getElementById('rut_solicitante').style.background = "#fedfdd";
		document.getElementById('dv_solicitante').style.background = "#fedfdd";
		muestraError("Por favor, ingresa los datos requeridos.", "error_solicitud_tarjeta");
	} else {
		document.getElementById('rut_solicitante').style.textAlign="right";
		document.getElementById('rut_solicitante').style.background = "#FFFFFF";
		document.getElementById('dv_solicitante').style.background = "#FFFFFF";	
		
		if(!Valida_RUT(formIngresoSolicitante.rut_solicitante.value, formIngresoSolicitante.dv_solicitante.value)) {
			document.getElementById('rut_solicitante').style.textAlign="left";
			document.getElementById('rut_solicitante').style.background = "#fedfdd";
			document.getElementById('dv_solicitante').style.background = "#fedfdd";
			muestraError("El R.U.T. ingresado no es v&aacute;lido,<br/>por favor int&eacute;ntalo nuevamente.", "error_solicitud_tarjeta");
		}
	}
 	if	(formIngresoSolicitante.rut_solicitante.value != '') {
 		if(!Valida_RUT(formIngresoSolicitante.rut_solicitante.value, formIngresoSolicitante.dv_solicitante.value)) {
			document.getElementById('rut_solicitante').style.textAlign="left";
			document.getElementById('rut_solicitante').style.background = "#fedfdd";
			document.getElementById('dv_solicitante').style.background = "#fedfdd";
			muestraError("El R.U.T. ingresado no es v&aacute;lido,<br/>por favor int&eacute;ntalo nuevamente.", "error_solicitud_tarjeta");
		} else {
			if(formIngresoSolicitante.tarjeta_solicitante.options[formIngresoSolicitante.tarjeta_solicitante.selectedIndex].value == 0){
				document.getElementById('tarjeta_solicitante').style.background = "#fedfdd";
				muestraError("Por favor, ingresa los datos requeridos.", "error_solicitud_tarjeta");
		    }else {
		    	document.getElementById('tarjeta_solicitante').style.background = "#ffffff";
	 			document.getElementById('rut_solicitante').style.textAlign="right";
	 			formElementsToUpperCase(formIngresoSolicitante);
	 			formIngresoSolicitante.submit();
	 	    }
		}
 	}
}

function on_focus_Preaprobado(){	
	document.getElementById('nombre').style.background = "#FFFFFF";
	document.getElementById('nombre1').style.background = "#FFFFFF";
	document.getElementById('nombre2').style.background = "#FFFFFF";
	document.getElementById('nacionalidad').style.background = "#FFFFFF";	
	document.getElementById('codTelefono1').style.background = "#FFFFFF";		
	document.getElementById('numTelefono1').style.background = "#FFFFFF";			
	document.getElementById('codTelefono2').style.background = "#FFFFFF";		
	document.getElementById('numTelefono2').style.background = "#FFFFFF";				
	document.getElementById('region').style.background = "#FFFFFF";
	document.getElementById('comuna').style.background = "#FFFFFF";
	document.getElementById('nomCalle').style.background = "#FFFFFF";
	document.getElementById('numCalle').style.background = "#FFFFFF";
	document.getElementById('email1').style.background = "#FFFFFF";
	document.getElementById('email2').style.background = "#FFFFFF";
//	document.getElementById('faltan_datos_super_solicita').style.display = "none";
}

function isCadenaValidaCalle(evt){
	 	var forbiddenKeys = new Array("a","n","c","x","v","j");
        var key;
        var isCtrl;
        var i;
		var tecla = (evt.which) ? evt.which : evt.keyCode;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
	
    	if(window.event)
        {
                key = window.event.keyCode;     //IE      
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = evt.which;     //firefox
                if(evt.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array
        if(isCtrl)
        {
                for(i=0; i<forbiddenKeys.length ; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                return false;
                        }
                }
        return false;
        }
		

	if( ( isAlfanumerico(evt) || isNumberKey(evt) || tecla == 35 || tecla == 45) && tecla != 37 ){
	  return true;
	} else {
      return false; 
    }	
}

function validarPreaprobado() {
	var ejecutar = true;
	//Nacionalidad
	if (document.preaprobadoForm.nacionalidad.options[document.preaprobadoForm.nacionalidad.selectedIndex].value == 0) {
		document.getElementById('nacionalidad').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
	} else {
		document.getElementById('nacionalidad').style.background = "#FFFFFF";
		document.getElementById('faltan_datos_super_solicita').style.display = "none";
	}

	//Fono
	if	((document.preaprobadoForm.codTelefono1.options[document.preaprobadoForm.codTelefono1.selectedIndex].value == 0 ) || (document.preaprobadoForm.numTelefono1.value == '') ){
		document.getElementById('codTelefono1').style.background = "#fedfdd";
		document.getElementById('numTelefono1').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		document.getElementById('codTelefono1').style.background = "#FFFFFF";
		document.getElementById('faltan_datos_super_solicita').style.display = "none";	
		if(!verificaNumero(document.preaprobadoForm.numTelefono1.value) || document.preaprobadoForm.numTelefono1.value.length < 6 ) { 
			document.getElementById('numTelefono1').style.background = "#fedfdd";
			document.getElementById('mensaje_error_fono').style.display = "block";
			ejecutar = false;
		} else {
			document.getElementById('numTelefono1').style.background = "#FFFFFF";
			document.getElementById('mensaje_error_fono').style.display = "none";	
		}
	}
	
	//Fono 2
	  if(document.getElementById('numTelefono2').value != "")	{
	  	if(document.getElementById('numTelefono2').value.length < 7 ){
	  		document.getElementById('numTelefono2').style.background = "#fedfdd";  
		  	document.getElementById('mensaje_error_fono').style.display = "block";	  			
	        ejecutar = false;
	  	} else {
		  	document.getElementById('numTelefono2').style.background = "#FFFFFF";   
		    document.getElementById('mensaje_error_fono').style.display = "none";
	  	}
	  }	  
	
	
	//Mail
	if (document.preaprobadoForm.email1.value == '') {
		document.getElementById('email1').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		if (valida_email(document.preaprobadoForm.email1.value)) {
			document.getElementById('email1').style.background = "#FFFFFF";
			document.getElementById('mensaje_error_mail_formato').style.display = "none";				
		} else {
			document.getElementById('email1').style.background = "#fedfdd";
			document.getElementById('mensaje_error_mail_formato').style.display = "block";
			//document.getElementById('mensaje_error_mail').style.display = "none";
			ejecutar = false;
		}
	}
	//Mail2
	if (document.preaprobadoForm.email2.value == '') {
		document.getElementById('email2').style.background = "#fedfdd";	
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		if (valida_email(document.preaprobadoForm.email2.value)) {
			document.getElementById('email2').style.background = "#FFFFFF";
			document.getElementById('mensaje_error_mail1_formato').style.display = "none";
		} else {
			document.getElementById('email2').style.background = "#fedfdd";
			document.getElementById('mensaje_error_mail1_formato').style.display = "block";
			document.getElementById('mensaje_error_mail').style.display = "none";
			ejecutar = false;
		}
		if ((document.preaprobadoForm.email1.value !=  document.preaprobadoForm.email2.value) && (valida_email(document.preaprobadoForm.email1.value) == true) && (valida_email(document.preaprobadoForm.email2.value) == true) ){
			document.getElementById('email1').style.background = "#fedfdd";
			document.getElementById('email2').style.background = "#fedfdd";
			//document.getElementById('mensaje_error_mail').style.display = "block";
			ejecutar = false;
		} else {
			document.getElementById('email1').style.background = "#FFFFFF";
			document.getElementById('email2').style.background = "#FFFFFF";
			document.getElementById('mensaje_error_mail').style.display = "none";
		}
		if (document.preaprobadoForm.email1.value != document.preaprobadoForm.email2.value){
			document.getElementById('email1').style.background = "#fedfdd";
			document.getElementById('email2').style.background = "#fedfdd";
			document.getElementById('mensaje_error_mail1_formato').style.display = "block";				
			ejecutar = false;
		} else {
			if ((document.preaprobadoForm.email1.value != '') && (document.preaprobadoForm.email2.value != '')){
				document.getElementById('mensaje_error_mail1_formato').style.display = "none";
				document.getElementById('email1').style.background = "#FFFFFF";
				document.getElementById('email2').style.background = "#FFFFFF";			
			}
		}		
	}
	//Nombre Calle
	if (document.preaprobadoForm.nomCalle.value == '') {
		document.getElementById('nomCalle').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		document.getElementById('nomCalle').style.background = "#FFFFFF";
		document.getElementById('faltan_datos_super_solicita').style.display = "none";
	}
	//Nro. Calle
	if (document.preaprobadoForm.numCalle.value == '') {
		document.getElementById('numCalle').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		document.getElementById('numCalle').style.background = "#FFFFFF";
		document.getElementById('faltan_datos_super_solicita').style.display = "none";
	}	
	//Comuna
	if (document.preaprobadoForm.comuna.value == '') {
		document.getElementById('comuna').style.background = "#fedfdd";
		document.getElementById('faltan_datos_super_solicita').style.display = "block";
		ejecutar = false;
	} else {
		document.getElementById('comuna').style.background = "#FFFFFF";
		//document.getElementById('faltan_datos_super_solicita').style.display = "none";		
	}
	if(ejecutar != false){
		formElementsToUpperCase(document.preaprobadoForm);
		document.preaprobadoForm.submit();
	}
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("La dirección de correo parece inválida (comprobar @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("El usuario no parece ser válido.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("IP de destino incorrecta.")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("El dominio no parece ser válido.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("La dirección debe terminar con un dominio de 3 letras, o un nombre de país de dos letras.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="¡A esta dirección le falta un nombre de host!"
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function enviar(donde){ 
	var formSeleccionado = document.getElementById('formSeleccionado');
	var existeError=0;
	var dondeTemp = donde;
	var tieneCaptcha = 0;
	var validarCamposRut = false;
	
	// Variables para Mensajes;
	var noTarjeta = 0;
	
	var _public = "_public";
	
	var divErrorRut = "error_rut_contacto_public"; // Solo público	
	var divFaltanDatos = "faltan_datos_contacto";
	var divErrorMail = "error_mail_contacto2";
	var divErrorMail2 = "error_mail2_contacto2";
	var divErrorFono = "error_fono_contacto";
	var divErrorFono1 = "error_fono_contacto_1";
	var divErrorFono2 = "error_fono_contacto_2";
	var divErrorCaptcha = "error_captcha_incorrecto";
	var divErrorTipoArchivo = "error_upload_archivo";
	var divErrorArchivoTam = "error_upload_archivo_tam";
		
	
	if (donde == 1) {
		validarCamposRut = true;
		divFaltanDatos += _public;
		divErrorMail += _public;
		divErrorMail2 += _public;
		divErrorFono += _public;
		divErrorFono1 += _public;
		divErrorFono2 += _public;
		divErrorCaptcha += _public;
		divErrorTipoArchivo += _public;
		divErrorArchivoTam += _public;
	}
		
	layerFaltanDatos = document.getElementById(divFaltanDatos);
	layerFaltanDatos.style.display="none";
	
	document.getElementById(divErrorCaptcha).style.display = "none";
	document.getElementById(divErrorTipoArchivo).style.display = "none";
	document.getElementById(divErrorArchivoTam).style.display = "none";
	
	if (validarCamposRut) {
		objRut = document.getElementById('rut_contacto');
		objDvRut = document.getElementById('dv_contacto');
		layerErrorRut = document.getElementById(divErrorRut);
		if (objRut.value == "") {
			objRut.style.background = "#fedfdd";
			layerFaltanDatos.style.display="block";	
			existeError=1;
	  	} else {
	    	objRut.style.background = "#FFFFFF";
	    	layerFaltanDatos.style.display="none";
	  	}
		if (objDvRut.value == "") {
			objDvRut.style.background = "#fedfdd";
			layerFaltanDatos.style.display="block";
			existeError = 1;
		} else {
			objDvRut.style.background = "#FFFFFF";
			if (existeError == 0) layerFaltanDatos.style.display="none";
		}
		if (existeError == 0) {
			if (!Valida_RUT(objRut.value,objDvRut.value)) {
				objRut.style.background = "#fedfdd";
				objDvRut.style.background = "#fedfdd";
		  	  	layerFaltanDatos.style.display="block";
		  	  	layerErrorRut.style.display="block";
		   	 	existeError = 1;
	    	} else {
				objRut.style.background = "#FFFFFF";
				layerErrorRut.style.display="none";
				layerFaltanDatos.style.display="none";
	    	}
	    }
		donde = "0";
	}	
	
	// Nombre Contacto	
	var NombreContacto = document.getElementById('nombre_contacto');
	if (NombreContacto.value == ""){	
		NombreContacto.style.background = "#fedfdd";
		layerFaltanDatos.style.display="block";	
	} else {
	    NombreContacto.style.background = "#FFFFFF";
	    if (existeError == 0) layerFaltanDatos.style.display="none";
	}
	
	var ApellidoContacto = document.getElementById('apellido_contacto');
	// Apellido Contacto
	if (ApellidoContacto.value == ''){	    
	    ApellidoContacto.style.background = "#fedfdd";
	    layerFaltanDatos.style.display="block";		       
	} else {
		ApellidoContacto.style.background = "#FFFFFF";  
		if (existeError == 0) layerFaltanDatos.style.display="none";
	}

	// E-Mail 1
	var EmailContacto = document.getElementById('email_contacto');
	var layerErrorMail = document.getElementById(divErrorMail);
	if (EmailContacto.value == '') {
	    EmailContacto.style.background = "#fedfdd";   
	    layerFaltanDatos.style.display="block";
	} else {
	    EmailContacto.style.background = "#FFFFFF"; 
	    if (existeError == 0) layerFaltanDatos.style.display="none";
	  	if (valida_email(EmailContacto.value)) {	      
	    	EmailContacto.style.background = "#FFFFFF";  
	    	layerErrorMail.style.display = "none";
	  	} else {
	    	EmailContacto.style.background = "#fedfdd";  
	    	layerErrorMail.style.display = "block"; 
	    	return;	    	
	  	}
	}
	
	// E-Mail 2  
	var EmailContacto2 = document.getElementById('email2_contacto');
	var layerErrorMail2 = document.getElementById(divErrorMail2);
	if (EmailContacto2.value == '') {
		EmailContacto2.style.background = "#fedfdd";  
		layerFaltanDatos.style.display="block";
	} else {
		EmailContacto2.style.background = "#FFFFFF";
	    if (existeError == 0)
			layerFaltanDatos.style.display="none";
		if (valida_email(EmailContacto2.value)) {
			EmailContacto2.style.background = "#FFFFFF";
			layerErrorMail2.style.display = "none";
	    } else {
			EmailContacto2.style.background = "#fedfdd";
			layerErrorMail2.style.display = "block";
			return;
	    }
	}
	  
	// Código de Contacto
	
	var CodigoContacto = document.getElementById('codigo_contacto');
	var FonoContacto = document.getElementById('fono_contacto');
	var layerErrorFono = document.getElementById(divErrorFono);
	if ((CodigoContacto.options[CodigoContacto.selectedIndex].value == 0) &&
	  	(CodigoContacto.value == 0)) {	   
		CodigoContacto.style.background = "#fedfdd"; 
	    FonoContacto.style.background = "#fedfdd"; 	  
	    layerFaltanDatos.style.display="block";	   
	} else {	   
	    CodigoContacto.style.background = "#FFFFFF"; 
	    FonoContacto.style.background = "#FFFFFF"; 
	    if((!verificaNumero(FonoContacto.value) || 
	     	(FonoContacto.value.length == 7 ) ) &&  (FonoContacto.value != '' )) {
		   FonoContacto.style.background = "#fedfdd"; 
	    } else {	
		   FonoContacto.style.background = "#FFFFFF";  
		   layerErrorFono.style.display = "none"; 
		   if(existeError==0) layerFaltanDatos.style.display = "none"; 
	    }
	}	  
	  
	// Fono Contacto
	
	layerErrorFonoConacto2 = document.getElementById(divErrorFono);
	if (FonoContacto.value == "" ){
	  	FonoContacto.style.background = "#fedfdd"; 
	    layerFaltanDatos.style.display="block";	
	} else {
	  	if (FonoContacto.value.length < 7) {
			FonoContacto.style.background = "#fedfdd"; 
			layerErrorFonoConacto2.style.display = "block";
			existeError=1;	
	  	} else {	  		
		  	FonoContacto.style.background = "#FFFFFF"; 
		  	if (existeError == 0) layerFaltanDatos.style.display="none";
		    layerErrorFonoConacto2.style.display = "none";
		}	  	
	}
	
	// Fono Contacto 2
	var FonoContacto2 = document.getElementById('fono_contacto2');
	var layerErrorFonoContacto3 = document.getElementById(divErrorFono2);
	if (FonoContacto2.value != "")	{
		if (FonoContacto2.value.length < 7 ){
			FonoContacto2.style.background = "#fedfdd";  
	  		layerErrorFonoContacto3.style.display = "block";
   	        existeError=1;
	  	} else {
		  	FonoContacto2.style.background = "#FFFFFF";   
	  		layerErrorFonoContacto3.style.display = "none";
	  	}
	}	  

	var TarjetaContacto = document.getElementById('tarjeta_contacto');
	if ((TarjetaContacto.value == 0)) {	
	    TarjetaContacto.style.background = "#fedfdd";    
	    layerFaltanDatos.style.display="block";
	    noTarjeta = 0;
	} else {	
		TarjetaContacto.style.background = "#FFFFFF";    
		layerFaltanDatos.style.display="none";
		noTarjeta = 1;
	}
	
	if(noTarjeta == 0) {
		layerFaltanDatos.style.display="block";
	}

	var OrdenContacto = document.getElementById('orden_contacto');
	var layerErrorOrden = document.getElementById('error_orden_contacto_1P');
	var layerErrorOrden7 = document.getElementById("error_orden_contacto_2P");
	var layerErrorOrden8 = document.getElementById("error_orden_contacto_3P");
	if (OrdenContacto != null) {
		if (OrdenContacto.value == '' ){
		    OrdenContacto.style.background = "#fedfdd";
		    layerFaltanDatos.style.display="block";		       
			existeError=1;
		} else { 
			if (formSeleccionado.value == 9 || formSeleccionado.value == 11) {
				if (OrdenContacto.value.length < 16 ) {
					OrdenContacto.style.background = "#fedfdd";
					layerErrorOrden.style.display="block";		       
					existeError = 1;
					return;
				} else {
				    OrdenContacto.style.background = "#FFFFFF";       
				    if (existeError == 0) {
						layerFaltanDatos.style.display="none";	    
						layerErrorOrden.style.display="none";	    
					}
				}
			} else if (formSeleccionado.value == 7) {
				// error_orden_contacto_2P
				if (OrdenContacto.value.length < 10) {
					OrdenContacto.style.background = "#fedfdd";
					layerErrorOrden7.style.display="block";		       
					existeError = 1;
					return;
				} else {
				    OrdenContacto.style.background = "#FFFFFF";
				    if (existeError == 0) {
						layerFaltanDatos.style.display="none";
						layerErrorOrden7.style.display="none";	    
					}
				}
			} else if (formSeleccionado.value == 8) {
				// error_orden_contacto_2P
				if (OrdenContacto.value.length < 10) {
					OrdenContacto.style.background = "#fedfdd";
					layerErrorOrden8.style.display="block";		       
					existeError = 1;
					return;
				} else {
				    OrdenContacto.style.background = "#FFFFFF";       
				    if (existeError == 0) {
						layerFaltanDatos.style.display="none";
						layerErrorOrden8.style.display="none";
					}
				}
			}
		}
	}
	  
	  
	var ComentarioContacto = document.getElementById('comentario_contacto');
	if (ComentarioContacto.value == '' ){	    
		ComentarioContacto.style.background = "#fedfdd";
		layerFaltanDatos.style.display="block";
	} else {
		ComentarioContacto.style.background = "#FFFFFF";       
		if(existeError==0) layerFaltanDatos.style.display="none";	    
	}
	
	var Captcha = document.getElementById('captcha');
	var ValorCaptcha = document.getElementById('valorCaptcha');
	if (Captcha.value == '' ){	    
		Captcha.style.background = "#fedfdd";
		layerFaltanDatos.style.display="block";	
	} else {
	  	//Validacion captcha
		if (Captcha.value.toUpperCase() != trim(ValorCaptcha.value)){
			tieneCaptcha = 1;
  		}
	}
	  
	  
	if (EmailContacto.value != EmailContacto2.value) {
		layerErrorMail2.style.display = "block";
	}

	var theFile = document.getElementById('theFile');
	var layerErrorTipoArchivo = document.getElementById(divErrorTipoArchivo);
	if (theFile.value != '') {
		if(!esExtensionFormularioContacto(theFile.value)){
		//El formato del archivo subido no es válido
			theFile.style.background = "#fedfdd";
			layerErrorTipoArchivo.style.display = "block";
			existeError = 1;
		}
	} else {
		theFile.style.background = "#FFFFFF";
		layerErrorTipoArchivo.style.display = "none";
	}
	  
	 // alert("Error->"+existeError);
	  if ((donde == "0" ) &&
			(NombreContacto.value != '') && (ApellidoContacto.value != '')&&
			(EmailContacto.value != '') && (EmailContacto2.value != '')  &&
			(CodigoContacto.options[CodigoContacto.selectedIndex].value != 0) &&
			(FonoContacto.value != '')  && 
			(TarjetaContacto.options[TarjetaContacto.selectedIndex].value != 0)&&
			(ComentarioContacto.value != '') && Captcha.value != '' && tieneCaptcha==1 && existeError==0 ) {
			if (EmailContacto.value == EmailContacto2.value){	 
				formElementsToUpperCase(document.formContacto);  
			    document.formContacto.submit(); 	 			    
			}   	
	  }
}

function verificaNumero(campoFormularioValidar) {
		
		//formato de parametro de entrada: document.campoFormularioValidar.pnum.value o con prototype $F('campoFormularioValidar')
		// es decir, llega value.
		
		var valido = false;
		
		var anum=/(^\d+$)|(^\d+\.\d+$)/;
		if (anum.test(campoFormularioValidar))
			valido=true;
		else{
			valido=false;
		}
		return (valido);
	}

function clearForms() {
	var i;
	for (i = 0; (i < document.forms.length); i++) {
		document.forms[i].reset();
	}
}

$(document).ready(function() {
	try {
		posicionCuadroMensaje();
	} catch (e) {}
	if (isTACWEB()) {
		$(".input_mensaje_ingresar").css('left', '241px');
		$(".input_mensaje_ingresar").css('top', '243px');
		$(".punta_mensaje_ingresar").css('left', '232px');
		$(".punta_mensaje_ingresar").css('top', '258px');
		
		$(".punta_mensaje_ingresar_clave").css('left', '232px');
		$(".punta_mensaje_ingresar_clave").css('top', '312px');
		$(".input_mensaje_ingresar2").css('left', '241px');
		$(".input_mensaje_ingresar2").css('top', '300px');
	}
});