﻿// Archivo JScript



//**********************************************//
	//*funciones de SolicitudeTarxeta.aspx***//
	//**********************************************//


//Valida el DNI
function ValidarDni(strDni)
{
 if (strDni== "")
     return false;
	 
 if (strDni.substring(0,1).toUpperCase()=="X")
 {
 	strDni="0" + strDni.substring(1,strDni.length);
 }
// strExpresion= /^[0-9]([0-9]{0,7})[a-zA-Z]{1}$/;
 strExpresion= /^[0-9]{8}[a-zA-Z]{1}$/;

 if (!strExpresion.test(strDni))
    return false;

 strNumeros=strDni.substring(0,strDni.length-1);
 strPos =  strNumeros % 23;
 strCadena='TRWAGMYFPDXBNJZSQVHLCKE';
 strLetra = strCadena.substring(strPos, strPos+1);
 strLetraDni=strDni.substr(strDni.length-1,1);
 strLetraDni= strLetraDni.toUpperCase();

 if (strLetra != strLetraDni)
    return false;
	
 return true;
}

function ValidacionCliente_Dni(source, args)
{
    var Txtnif = document.getElementById(source.controltovalidate);
	args.IsValid = ValidarDni(Txtnif.value);
}
		
function ValidacionCliente_Combo(source, args)		
{
    var listbox = document.getElementById(source.controltovalidate);
	if (!listbox.disabled) {
	    if (listbox.options.length == 0 || listbox.selectedIndex == 0 ){
		    args.IsValid = false;
		}
	}
	else
	{
	    args.IsValid = true;
	}
}
		
function ValidacionCliente_TextBox(source, args)		
{
    var textBox = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_txtOtroTema');
    if (textBox.value == "" )
	    args.IsValid = false;
	else
	    args.IsValid = true;
}

function ValidacionCliente_Fecha_Doazons(source, args)
{
    var TxtAno = document.getElementById(source.controltovalidate);
    var TxtMes = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_TxtMes');
    var TxtDia = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_TxtDia');
    
    args.IsValid = false;
    if (TxtAno.value != "" && TxtMes.value != "" && TxtDia.value != "")
    {
        args.IsValid = true;
    }
}


function ValidacionCliente_ComboCondicionado(source, args)		
{
    var listbox = null;
    var listbox2 = null;
    var blnProvincia = false;

    listbox = document.getElementById(source.controltovalidate);
    listbox2 = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_CmbProvincias');
	    
    var txtCP = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_TxtCodigoPostal');
	if (trim(txtCP.value) == "" && listbox2.options.length != 0 && listbox2.selectedIndex != 0){
	
	    
	    if (listbox2.options.length == 0 || listbox2.selectedIndex == 0)
        {
            args.IsValid = false;
        }
    	else
    	{
    	    if (listbox.options.length == 0 || listbox.selectedIndex == 0)
    	    {
    	        args.IsValid = false;
    	    }
    	}
	}
	else
	{
	    args.IsValid = true;
	}
}

function ValidacionCliente_TextBoxCondicionado(source, args)
{
    var txtCP = document.getElementById(source.controltovalidate);
    var listbox1 = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_CmbProvincias');
    var listbox2 = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_CmbConcellos');
	if (trim(txtCP.value) == "" && ((listbox1.options.length == 0 || listbox1.selectedIndex == 0) && (listbox2.options.length == 0 || listbox2.selectedIndex == 0))){
	    args.IsValid = false;
	}
	else
	{
	    args.IsValid = true;
	}
}
function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
return cadena;
}



function rellenaProvinciaCombo()
{
    var txtCP = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_TxtCodigoPostal');
    
    if (trim(txtCP.value).length == 5)
    {   
        var codprov = txtCP.value.substring(0,2);
        var i = 0;
        var listbox = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_CmbProvincias');
        for (i = 0; i < listbox.options.length; i++)
        {
            if (listbox.options[i].value == trim(codprov))
            {
                listbox.selectedIndex = i;
                __doPostBack('ctl00_ContentPlaceHolderContenidoCentral_CmbProvincias', '');
            }
            else {
               listbox.selectedIndex = 0;
               listbox = document.getElementById('ctl00_ContentPlaceHolderContenidoCentral_CmbConcellos');
               listbox.selectedIndex = 0;
            }
        }
    }
}

function __doPostBack(eventTarget, eventArgument) 
{
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        theform = document.Form1;
    }
    else {
        theform = document.forms["Form1"];
    }
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
}
