/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////EFECTOS/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function ponEfecto(id)
{
    document.getElementById(id).className = 'TRIluminado';
}

function quitaEfecto(id)
{
    document.getElementById(id).className = 'TRNormal';
}

function ponEfectoTd(id)
{
    document.getElementById(id).className = 'TDIluminado';
}

function quitaEfectoTd(id)
{
    document.getElementById(id).className = 'FumadoresOpcionesCentro';
}

function muestraAviso(id)
{
    document.getElementById(id).style.display = 'block';
        
}

function ocultaAviso(id)
{
    document.getElementById(id).style.display = 'none';
}








/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////ACCIONES DYG////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function selecciona(linea, opc)
{
    var id = '' + linea + opc;
    for(var i = 1; i < 7; i++)
    {
        var modulo = '' + linea + i;
        if(modulo != id)
            document.getElementById(modulo).checked = false;
    } 
}

function determina(linea)
{
    var i = 1;
    var encontrado = false;
    while(i < 7 && !encontrado)
    {
        var modulo = '' + linea + i;
        if(document.getElementById(modulo).checked)
        {
            encontrado = true;
        }        
        i++;
    }
    
    i--;
    
    var res = (i != 6) ? ("" + i) : "NS/NC";
    
    return res;
}

function muestraOcultaCigarrillos(opcion)
{
    if(opcion == '4' || opcion == '5' || opcion == '6')
    {
        document.getElementById('TrSoloFuma').style.display = 'block';
        document.getElementById('Tr16').style.display = 'block';
        document.getElementById('Tr17').style.display = 'block';
        document.getElementById('Tr18').style.display = 'block';
        document.getElementById('TrUltimaLinea').style.display = 'block';
        if(opcion == '6')
            document.getElementById('Tr10').style.display = 'block';
        else
            document.getElementById('Tr10').style.display = 'none';
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_tbxCigarrosDia').value = '';
        document.getElementById('Tr10').style.display = 'none';
        document.getElementById('TrSoloFuma').style.display = 'none';
        document.getElementById('Tr16').style.display = 'none';
        document.getElementById('Tr17').style.display = 'none';
        document.getElementById('Tr18').style.display = 'none';
        document.getElementById('TrUltimaLinea').style.display = 'none';
    }
}

function muestraOcultaOtrosApoyos()
{
    if(document.getElementById('ctl00_CPHCentro_cbxOtros').checked)
        document.getElementById('Tr14').style.display = 'block';
    else
    {
        document.getElementById('ctl00_CPHCentro_tbxApoyos').value = '';
        document.getElementById('Tr14').style.display = 'none';
    }
}

function muestraOcultaApoyos(opcion)
{
    if(opcion == "No" || opcion == "NS/NC")
    {
        document.getElementById('Tr13').style.display = 'none';
        document.getElementById('Tr14').style.display = 'none';
    }
    else
    {
        document.getElementById('Tr13').style.display = 'block';
        if(document.getElementById('ctl00_CPHCentro_cbxOtros').checked)
            document.getElementById('Tr14').style.display = 'block';
        else
        {
            document.getElementById('ctl00_CPHCentro_tbxApoyos').value = '';
            document.getElementById('Tr14').style.display = 'none';
        }
    }
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////VARIOS CON DDL//////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function quitaPonOtro(opcion)
{
    if(opcion == '88400000' || opcion == '88110000' || opcion == '88140000' || opcion == '88180000' || opcion == '88210000' || opcion == '88230000' || opcion == '88290000' || opcion == '88410000') 
    {
        document.getElementById('ctl00_CPHCentro_tbxOtro').style.display = 'block';
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_tbxOtro').style.display = 'none';
    }
}
function rellenaDDLCentroCCE(provincia)
{
    var res = ClaseConExito.datosDDLCentros(provincia);
    rellenaDDL(res, 'ctl00_CPHCentro_ddlCentro', false);
}
function rellenaDDLCursoCCE(centro)
{
    var res = ClaseConExito.rellenaDDLCurso(centro);
    rellenaDDL(res, 'ctl00_CPHCentro_ddlCurso', false);
    var ddl = document.getElementById('ctl00_CPHCentro_ddlCurso');
    rellenaDDLClaseCCE(centro, ddl.options[ddl.selectedIndex].value);
}
function rellenaDDLClaseCCE(centro, curso)
{
    var res = ClaseConExito.rellenaDDLClase(centro, curso);
    rellenaDDL(res, 'ctl00_CPHCentro_ddlClase', false);
}

function rellenaDDLCentro(provincia)
{
    //var idProvincia = document.getElementById('ctl00_CPHCentro_ddlCentro').value;    
    document.getElementById('ctl00_CPHCentro_tbxOtro').style.display = 'none';
    var res = ClaseSinHumo.datosDDLCentros(provincia);
    rellenaDDL(res, 'ctl00_CPHCentro_ddlCentro', true);
}

function rellenaDDL(res, elemento, conBlanco)
{
	var dt = res.value;
	var html = new Array();
	var oSelect = document.getElementById(elemento);
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
	    if (conBlanco) {
	        agregaBlanco(oSelect);
	    }
		for(var i = 0; i < dt.Rows.length; i++)
		{
	        var oOption = document.createElement("OPTION");
		    oOption.value = dt.Rows[i].c_codigo;
		    oOption.text = dt.Rows[i].s_denomina + " " + dt.Rows[i].d_especifica;
			
		    try {
			    oSelect.add(oOption, null); // Para cumplir con el estándar
		    }
		    catch(ex) {
		        //alert('entra');
			    oSelect.add(oOption); // Para IE
		    }
        }
        
    }
}

function agregaBlanco(oSelect) {
    var oOption = document.createElement("OPTION");
    oOption.value = "";
    oOption.text = "Seleccione un centro";

    try {
        oSelect.add(oOption, oSelect.options[0]); // Para cumplir con el estándar
    }
    catch(ex) {
        oSelect.add(oOption, 0); // Para IE
    }
}





/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////VARIOS CON DDL DYG /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function rellenaDDLCentroDYG(provincia)
{
    //var idProvincia = document.getElementById('ctl00_CPHCentro_ddlCentro').value;    
    var res = DejaloYGana.datosDDLCentros(provincia);
    rellenaDDLDYG(res, 'ctl00_CPHCentro_ddlCentro', true);
}

function rellenaDDLDYG(res, elemento, conBlanco)
{
	var dt = res.value;
	var html = new Array();
	var oSelect = document.getElementById(elemento);
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
	    if (conBlanco) {
	        agregaBlanco(oSelect);
	    }
		for(var i = 0; i < dt.Rows.length; i++)
		{
		    var oOption = document.createElement("OPTION");
//			oOption.value = dt.Rows[i].codigo;
//			oOption.text = dt.Rows[i].denominacion;
		    oOption.value = dt.Rows[i].codigo;
		    oOption.text = dt.Rows[i].denominacion;
			
		    try {
			    oSelect.add(oOption, null); // Para cumplir con el estándar
		    }
		    catch(ex) {
		        //alert('entra');
			    oSelect.add(oOption); // Para IE
		    }
        }
        var oOption = document.createElement("OPTION");
		oOption.value = '99' + dt.Rows[0].provinciaid + '0001';
		oOption.text = 'Otro Centro';
			
		    try {
			    oSelect.add(oOption, null); // Para cumplir con el estándar
		    }
		    catch(ex) {
		        //alert('entra');
			    oSelect.add(oOption); // Para IE
		    }
    }
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////VARIOS CON DDL CLH /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function calculaSumatorio(elementodestino, elemento2, valor) {

    var elem = document.getElementById(elementodestino);
    var elem2 = document.getElementById(elemento2);
    if (valor == "") valor = 0;
    
    if (elem2.value == "") elem.innerHTML = parseInt(valor);
    else elem.innerHTML = parseInt(elem2.value) + parseInt(valor);
}

function rellenaDDLCentroCLH(provincia)
{
    //var idProvincia = document.getElementById('ctl00_CPHCentro_ddlCentro').value;    
    var res = CentroLibreHumo.datosDDLCentros(provincia);
    rellenaDDLCLH(res, 'ctl00_CPHCentro_ddlCentro', true);
}

function rellenaDDLCLH(res, elemento, conBlanco)
{
	var dt = res.value;
	var html = new Array();
	var oSelect = document.getElementById(elemento);
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
	    if (conBlanco) {
	        agregaBlanco(oSelect);
	    }
		for(var i = 0; i < dt.Rows.length; i++)
		{
		    var oOption = document.createElement("OPTION");
//			oOption.value = dt.Rows[i].codigo;
//			oOption.text = dt.Rows[i].denominacion;
		    oOption.value = dt.Rows[i].codigo;
		    oOption.text = dt.Rows[i].denominacion;
			
		    try {
			    oSelect.add(oOption, null); // Para cumplir con el estándar
		    }
		    catch(ex) {
		        //alert('entra');
			    oSelect.add(oOption); // Para IE
		    }
        }
    }
}



/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////CONTROLES TBX///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function formatoNumero()
{
    var key = window.event.keyCode;
    if(key >= 48 && key <=57)
        return true;
    else return false;
}

function formatoLetra()
{
    var key = window.event.keyCode;
    if((key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key == 209 || key == 241 || key == 32)
        return true;
    else return false;
}



/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////AUTORELLENAR///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function calculaTotal(elemento1, elemento2, eResultado)
{
    var sum1;
    var sum2;
    var suma;
    
    sum1 = parseInt(document.getElementById(elemento1).value);
    sum2 = parseInt(document.getElementById(elemento2).value);
    
    if(isNaN(sum1))
        sum1 = 0;
    if(isNaN(sum2))
        sum2 = 0;
        
    suma = sum1 + sum2;

    document.getElementById(eResultado).innerHTML = suma;
}


function validaDatosFormularioCCE() {
//var challenge = Recaptcha.get_challenge(); 
    //var response = Recaptcha.get_response(); 
    var todo_ok = true;
    
    if(document.getElementById('ctl00_CPHCentro_tbxProfesor').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtProfesor').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtProfesor').className = 'TextoNormalNegrita';
    }
    
    if(document.getElementById('ctl00_CPHCentro_tbxTelefono').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegrita';
    }

    
    
    if(document.getElementById('ctl00_CPHCentro_tbxCorreoContacto').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxEslogan').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtEslogan').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtEslogan').className = 'TextoNormalNegrita';
    }
    
    if(document.getElementById('ctl00_CPHCentro_ddlCentro').options[document.getElementById('ctl00_CPHCentro_ddlCentro').selectedIndex].value == "")
    {
        document.getElementById('ctl00_CPHCentro_txtCentro').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCentro').className = 'TextoNormalNegrita';
    }

    if (document.getElementById('ctl00_CPHCentro_ddlCurso').options.length > 0) {
        if(document.getElementById('ctl00_CPHCentro_ddlCurso').options[document.getElementById('ctl00_CPHCentro_ddlCurso').selectedIndex].value == "")
        {
            document.getElementById('ctl00_CPHCentro_txtCurso').className = 'TextoNormalNegritaRojo';
            todo_ok = false;
        }
        else
        {
            document.getElementById('ctl00_CPHCentro_txtCurso').className = 'TextoNormalNegrita';
        }
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCurso').className = 'TextoNormalNegritaRojo';
    }
    
    if (document.getElementById('ctl00_CPHCentro_ddlClase').options.length > 0) {
        if(document.getElementById('ctl00_CPHCentro_ddlClase').options[document.getElementById('ctl00_CPHCentro_ddlClase').selectedIndex].value == "")
        {
            document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegritaRojo';
            todo_ok = false;
        }
        else
        {
            document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegrita';
        }
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegritaRojo';
    }
    
    
    
    if(todo_ok == false)
        alert('Revise los errores (marcados en rojo).');
    return todo_ok;
}

function insertaDatosCLH()
{
    
    var Datos = new Array();
    var Tipos = new Array();
    var Nombres = new Array();
    
    var captcha = document.getElementById('ctl00_CPHCentro_tbxCaptcha');
    
    var provincia = document.getElementById('ctl00_CPHCentro_ddlProvincia');
    var centro = document.getElementById('ctl00_CPHCentro_ddlCentro');
    var contacto = document.getElementById('ctl00_CPHCentro_tbxContacto');
    var correo = document.getElementById('ctl00_CPHCentro_tbxCorreoContacto');

    var AlumnosBasica = document.getElementById('ctl00_CPHCentro_tbxAlumnosBasica');
    var AlumnasBasica = document.getElementById('ctl00_CPHCentro_tbxAlumnasBasica');
    var AlumnosAvanzada = document.getElementById('ctl00_CPHCentro_tbxAlumnosAvanzada');
    var AlumnasAvanzada = document.getElementById('ctl00_CPHCentro_tbxAlumnasAvanzada');
    var AlumnosGrupos = document.getElementById('ctl00_CPHCentro_tbxAlumnosGrupos');
    var AlumnasGrupos = document.getElementById('ctl00_CPHCentro_tbxAlumnasGrupos');
    var txtNGrupos1 = document.getElementById('ctl00_CPHCentro_txtNGrupos1');
    var ProfesoresAvanzada = document.getElementById('ctl00_CPHCentro_tbxProfesoresAvanzada');
    var ProfesorasAvanzada = document.getElementById('ctl00_CPHCentro_tbxProfesorasAvanzada');
    var ProfesoresGrupos = document.getElementById('ctl00_CPHCentro_tbxProfesoresGrupos');
    var ProfesorasGrupos = document.getElementById('ctl00_CPHCentro_tbxProfesorasGrupos');
    var txtNGrupos2 = document.getElementById('ctl00_CPHCentro_txtNGrupos2');
    var PersonalHAvanzada = document.getElementById('ctl00_CPHCentro_tbxPersonalHAvanzada');
    var PersonalMAvanzada = document.getElementById('ctl00_CPHCentro_tbxPersonalMAvanzada');
    var PersonalHGrupos = document.getElementById('ctl00_CPHCentro_tbxPersonalHGrupos');
    var PersonalMGrupos = document.getElementById('ctl00_CPHCentro_tbxPersonalMGrupos');
    var txtNGrupos3 = document.getElementById('ctl00_CPHCentro_txtNGrupos3');
    var PadresGrupos = document.getElementById('ctl00_CPHCentro_tbxPadresGrupos');
    var MadresGrupos = document.getElementById('ctl00_CPHCentro_tbxMadresGrupos');
    var txtNGrupos4 = document.getElementById('ctl00_CPHCentro_txtNGrupos4');

    Nombres.push("@idProvincia"); Tipos.push("Int"); Datos.push(provincia.value); 
    Nombres.push("@idCentro"); Tipos.push("Int"); Datos.push(centro.value); 
    Nombres.push("@Contacto"); Tipos.push("VarChar"); Datos.push(contacto.value.toUpperCase()); 
    Nombres.push("@Mail"); Tipos.push("VarChar"); Datos.push(correo.value); 
    
    if (document.getElementById('ctl00_CPHCentro_rbtSenializadoSi').checked == true) {
        Nombres.push("@Serializado"); Tipos.push("VarChar"); Datos.push("Si"); 
    }
    else {
        Nombres.push("@Serializado"); Tipos.push("VarChar"); Datos.push("No"); 
    }
    
    if (document.getElementById('ctl00_CPHCentro_rbtNormativaSi').checked == true) {
        Nombres.push("@Normativa"); Tipos.push("VarChar"); Datos.push("Si"); 
    }
    else {
        Nombres.push("@Normativa"); Tipos.push("VarChar"); Datos.push("No"); 
    }

    Nombres.push("@AlumnosBasica"); Tipos.push("Int"); Datos.push(AlumnosBasica.value); 
    Nombres.push("@AlumnasBasica"); Tipos.push("Int"); Datos.push(AlumnasBasica.value); 
    Nombres.push("@AlumnosAvanzada"); Tipos.push("Int"); Datos.push(AlumnosAvanzada.value); 
    Nombres.push("@AlumnasAvanzada"); Tipos.push("Int"); Datos.push(AlumnasAvanzada.value); 
    Nombres.push("@AlumnosGrupos"); Tipos.push("Int"); Datos.push(AlumnosGrupos.value); 
    Nombres.push("@AlumnasGrupos"); Tipos.push("Int"); Datos.push(AlumnasGrupos.value); 
    Nombres.push("@txtNGrupos1"); Tipos.push("Int"); Datos.push(txtNGrupos1.value); 
    Nombres.push("@ProfesoresAvanzada"); Tipos.push("Int"); Datos.push(ProfesoresAvanzada.value); 
    Nombres.push("@ProfesorasAvanzada"); Tipos.push("Int"); Datos.push(ProfesorasAvanzada.value); 
    Nombres.push("@ProfesoresGrupos"); Tipos.push("Int"); Datos.push(ProfesoresGrupos.value); 
    Nombres.push("@ProfesorasGrupos"); Tipos.push("Int"); Datos.push(ProfesorasGrupos.value); 
    Nombres.push("@txtNGrupos2"); Tipos.push("Int"); Datos.push(txtNGrupos2.value); 
    Nombres.push("@PersonalHAvanzada"); Tipos.push("Int"); Datos.push(PersonalHAvanzada.value); 
    Nombres.push("@PersonalMAvanzada"); Tipos.push("Int"); Datos.push(PersonalMAvanzada.value); 
    Nombres.push("@PersonalHGrupos"); Tipos.push("Int"); Datos.push(PersonalHGrupos.value); 
    Nombres.push("@PersonalMGrupos"); Tipos.push("Int"); Datos.push(PersonalMGrupos.value); 
    Nombres.push("@txtNGrupos3"); Tipos.push("Int"); Datos.push(txtNGrupos3.value); 
    Nombres.push("@PadresGrupos"); Tipos.push("Int"); Datos.push(PadresGrupos.value); 
    Nombres.push("@MadresGrupos"); Tipos.push("Int"); Datos.push(MadresGrupos.value); 
    Nombres.push("@txtNGrupos4"); Tipos.push("Int"); Datos.push(txtNGrupos4.value); 
    
    var resultado;
    
    resultado = CentroLibreHumo.InsertaDatosCLH(Nombres.toJSONString(),Tipos.toJSONString(),Datos.toJSONString(), captcha.value);
    
    return resultado;

}

function validaDatosFormularioCLH() {
//var challenge = Recaptcha.get_challenge(); 
    //var response = Recaptcha.get_response(); 
    var todo_ok = true;
       
    
    if(document.getElementById('ctl00_CPHCentro_tbxContacto').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtContacto').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxCorreoContacto').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegrita';
    }
    
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosBasica').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnosBasica').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasBasica').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnasBasica').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnosAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnasAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnosGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxAlumnasGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_txtNGrupos1').value.length == 0) document.getElementById('ctl00_CPHCentro_txtNGrupos1').value = 0;
    
    if(document.getElementById('ctl00_CPHCentro_tbxProfesoresAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxProfesoresAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxProfesorasAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxProfesorasAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxProfesoresGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxProfesoresGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxProfesorasGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxProfesorasGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_txtNGrupos2').value.length == 0) document.getElementById('ctl00_CPHCentro_txtNGrupos2').value = 0;
    
    if(document.getElementById('ctl00_CPHCentro_tbxPersonalHAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxPersonalHAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxPersonalMAvanzada').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxPersonalMAvanzada').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxPersonalHGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxPersonalHGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxPersonalMGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxPersonalMGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_txtNGrupos3').value.length == 0) document.getElementById('ctl00_CPHCentro_txtNGrupos3').value = 0;
    
    if(document.getElementById('ctl00_CPHCentro_tbxPadresGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxPadresGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_tbxMadresGrupos').value.length == 0) document.getElementById('ctl00_CPHCentro_tbxMadresGrupos').value = 0;
    if(document.getElementById('ctl00_CPHCentro_txtNGrupos4').value.length == 0) document.getElementById('ctl00_CPHCentro_txtNGrupos4').value = 0;

    if(todo_ok == false)
        alert('Revise los errores (marcados en rojo).');
    else
        {
            var dev = insertaDatosCLH();
           
            if(dev.value == 'OK') {
                //document.getElementById('recaptcha_div').style.border = '0px';
                document.getElementById('recaptcha_span').style.display = 'none';
                alert('Se ha registrado correctamente. Por favor, compruebe su correo electronico pues le hemos enviado un acuse de recibo con la confirmacion de su registro. Gracias.');
            }
            else if(dev.value == 'Captcha Erroneo') {
                //document.getElementById('recaptcha_div').style.border = 'solid 2px red';
                document.getElementById('recaptcha_span').style.display = 'block';
            }
            else
                location.href = 'Error.aspx?error=' + dev.value; 
        }
    
    return false;
}

function insertaDatosCLH()
{
    
    var Datos = new Array();
    var Tipos = new Array();
    var Nombres = new Array();
    
    var captcha = document.getElementById('ctl00_CPHCentro_tbxCaptcha');
    
    var provincia = document.getElementById('ctl00_CPHCentro_ddlProvincia');
    var centro = document.getElementById('ctl00_CPHCentro_ddlCentro');
    var contacto = document.getElementById('ctl00_CPHCentro_tbxContacto');
    var correo = document.getElementById('ctl00_CPHCentro_tbxCorreoContacto');

    var AlumnosBasica = document.getElementById('ctl00_CPHCentro_tbxAlumnosBasica');
    var AlumnasBasica = document.getElementById('ctl00_CPHCentro_tbxAlumnasBasica');
    var AlumnosAvanzada = document.getElementById('ctl00_CPHCentro_tbxAlumnosAvanzada');
    var AlumnasAvanzada = document.getElementById('ctl00_CPHCentro_tbxAlumnasAvanzada');
    var AlumnosGrupos = document.getElementById('ctl00_CPHCentro_tbxAlumnosGrupos');
    var AlumnasGrupos = document.getElementById('ctl00_CPHCentro_tbxAlumnasGrupos');
    var txtNGrupos1 = document.getElementById('ctl00_CPHCentro_txtNGrupos1');
    var ProfesoresAvanzada = document.getElementById('ctl00_CPHCentro_tbxProfesoresAvanzada');
    var ProfesorasAvanzada = document.getElementById('ctl00_CPHCentro_tbxProfesorasAvanzada');
    var ProfesoresGrupos = document.getElementById('ctl00_CPHCentro_tbxProfesoresGrupos');
    var ProfesorasGrupos = document.getElementById('ctl00_CPHCentro_tbxProfesorasGrupos');
    var txtNGrupos2 = document.getElementById('ctl00_CPHCentro_txtNGrupos2');
    var PersonalHAvanzada = document.getElementById('ctl00_CPHCentro_tbxPersonalHAvanzada');
    var PersonalMAvanzada = document.getElementById('ctl00_CPHCentro_tbxPersonalMAvanzada');
    var PersonalHGrupos = document.getElementById('ctl00_CPHCentro_tbxPersonalHGrupos');
    var PersonalMGrupos = document.getElementById('ctl00_CPHCentro_tbxPersonalMGrupos');
    var txtNGrupos3 = document.getElementById('ctl00_CPHCentro_txtNGrupos3');
    var PadresGrupos = document.getElementById('ctl00_CPHCentro_tbxPadresGrupos');
    var MadresGrupos = document.getElementById('ctl00_CPHCentro_tbxMadresGrupos');
    var txtNGrupos4 = document.getElementById('ctl00_CPHCentro_txtNGrupos4');

    Nombres.push("@idProvincia"); Tipos.push("Int"); Datos.push(provincia.value); 
    Nombres.push("@idCentro"); Tipos.push("Int"); Datos.push(centro.value); 
    Nombres.push("@Contacto"); Tipos.push("VarChar"); Datos.push(contacto.value.toUpperCase()); 
    Nombres.push("@Mail"); Tipos.push("VarChar"); Datos.push(correo.value); 
    
    if (document.getElementById('ctl00_CPHCentro_rbtSenializadoSi').checked == true) {
        Nombres.push("@Serializado"); Tipos.push("VarChar"); Datos.push("Si"); 
    }
    else if (document.getElementById('ctl00_CPHCentro_rbtSenializadoNo').checked == true) {
        Nombres.push("@Serializado"); Tipos.push("VarChar"); Datos.push("No"); 
    }
    
    if (document.getElementById('ctl00_CPHCentro_rbtNormativaSi').checked == true) {
        Nombres.push("@Normativa"); Tipos.push("VarChar"); Datos.push("Si"); 
    }
    else if (document.getElementById('ctl00_CPHCentro_rbtNormativaNo').checked == true) {
        Nombres.push("@Normativa"); Tipos.push("VarChar"); Datos.push("No"); 
    }

    Nombres.push("@AlumnosBasica"); Tipos.push("Int"); Datos.push(AlumnosBasica.value); 
    Nombres.push("@AlumnasBasica"); Tipos.push("Int"); Datos.push(AlumnasBasica.value); 
    Nombres.push("@AlumnosAvanzada"); Tipos.push("Int"); Datos.push(AlumnosAvanzada.value); 
    Nombres.push("@AlumnasAvanzada"); Tipos.push("Int"); Datos.push(AlumnasAvanzada.value); 
    Nombres.push("@AlumnosGrupos"); Tipos.push("Int"); Datos.push(AlumnosGrupos.value); 
    Nombres.push("@AlumnasGrupos"); Tipos.push("Int"); Datos.push(AlumnasGrupos.value); 
    Nombres.push("@txtNGrupos1"); Tipos.push("Int"); Datos.push(txtNGrupos1.value); 
    Nombres.push("@ProfesoresAvanzada"); Tipos.push("Int"); Datos.push(ProfesoresAvanzada.value); 
    Nombres.push("@ProfesorasAvanzada"); Tipos.push("Int"); Datos.push(ProfesorasAvanzada.value); 
    Nombres.push("@ProfesoresGrupos"); Tipos.push("Int"); Datos.push(ProfesoresGrupos.value); 
    Nombres.push("@ProfesorasGrupos"); Tipos.push("Int"); Datos.push(ProfesorasGrupos.value); 
    Nombres.push("@txtNGrupos2"); Tipos.push("Int"); Datos.push(txtNGrupos2.value); 
    Nombres.push("@PersonalHAvanzada"); Tipos.push("Int"); Datos.push(PersonalHAvanzada.value); 
    Nombres.push("@PersonalMAvanzada"); Tipos.push("Int"); Datos.push(PersonalMAvanzada.value); 
    Nombres.push("@PersonalHGrupos"); Tipos.push("Int"); Datos.push(PersonalHGrupos.value); 
    Nombres.push("@PersonalMGrupos"); Tipos.push("Int"); Datos.push(PersonalMGrupos.value); 
    Nombres.push("@txtNGrupos3"); Tipos.push("Int"); Datos.push(txtNGrupos3.value); 
    Nombres.push("@PadresGrupos"); Tipos.push("Int"); Datos.push(PadresGrupos.value); 
    Nombres.push("@MadresGrupos"); Tipos.push("Int"); Datos.push(MadresGrupos.value); 
    Nombres.push("@txtNGrupos4"); Tipos.push("Int"); Datos.push(txtNGrupos4.value); 
    Nombres.push("@curso"); Tipos.push("VarChar"); Datos.push("2009-10"); 
    var resultado;
    
    resultado = CentroLibreHumo.InsertaDatosCLH(Nombres.toJSONString(),Tipos.toJSONString(),Datos.toJSONString(), captcha.value);
    
    return resultado;

}

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////VALIDACIONES CSH///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function validaDatosFormularioCSH()
{
    //var challenge = Recaptcha.get_challenge(); 
    //var response = Recaptcha.get_response(); 
    var challenge = "comentario"; 
    var response = "comentario"; 
    var todo_ok = true;
    
    if(document.getElementById('ctl00_CPHCentro_ddlCentro').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtCentro').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCentro').className = 'TextoNormalNegrita';
    }
    if(document.getElementById('ctl00_CPHCentro_tbxOtro').value.length == 0 && document.getElementById('ctl00_CPHCentro_ddlCentro').options[document.getElementById('ctl00_CPHCentro_ddlCentro').selectedIndex].text == "Otro...")
    {   
        document.getElementById('ctl00_CPHCentro_lblOtroCentro').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_lblOtroCentro').className = 'TextoNormal';
    }


    if(document.getElementById('ctl00_CPHCentro_tbxProfesor').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtProfesor').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtProfesor').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxTelefono').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxCorreoContacto').value.length == 0 || !IsEmail(document.getElementById('ctl00_CPHCentro_tbxCorreoContacto').value))
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxClase').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumado').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumado').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumado').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumado').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumarRegularmente').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumarRegularmente').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumarRegularmente').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumarRegularmente').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosFumanRegularmente').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnosFumanRegularmente').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasFumanRegularmente').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnasFumanRegularmente').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnosCadaDia').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnosCadaDia').value = 0;
    }

    if(document.getElementById('ctl00_CPHCentro_tbxAlumnasCadaDia').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_tbxAlumnasCadaDia').value = 0;
    }
    
    if(todo_ok == false)
        alert('Revise los errores (marcados en rojo).');
    else
        {
            var dev = insertaDatosCSH(challenge,response);
            if(dev.value == 'OK') {
                document.getElementById('recaptcha_span').style.border = '0px';
                document.getElementById('recaptcha_span').style.display = 'none';
                alert('Datos guardados correctamente.');
            }
            else if(dev.value == 'Captcha Erroneo') {
                document.getElementById('recaptcha_span').style.border = 'solid 2px red';
                document.getElementById('recaptcha_span').style.display = 'block';
            }
            else if(dev.value == 'Session Erronea') { //La sessión ha expirado
                alert("Lo sentimos, la session ha expirado, vuelva a rellenar los datos.");
                var tiempo = new Date();
                var id = tiempo.getUTCMilliseconds() * tiempo.getUTCMilliseconds() * tiempo.getUTCMilliseconds();
                location.href = 'clasesinhumo.aspx?reload=' + id; 
            }
            else
                location.href = 'Error.aspx?error=' + dev.value;
        }
    
    return false;
}

function insertaDatosCSH(challenge,response)
{
    
    var Datos = new Array();
    var Tipos = new Array();
    var Nombres = new Array();

    var captcha = document.getElementById('ctl00_CPHCentro_tbxCaptcha');

    var provincia = document.getElementById('ctl00_CPHCentro_ddlProvincia');
    var centro = document.getElementById('ctl00_CPHCentro_ddlCentro');
    var nombre = document.getElementById('ctl00_CPHCentro_tbxOtro');
    var profesor = document.getElementById('ctl00_CPHCentro_tbxProfesor');
    var telefono = document.getElementById('ctl00_CPHCentro_tbxTelefono');
    var correo = document.getElementById('ctl00_CPHCentro_tbxCorreoContacto');
    var curso = document.getElementById('ctl00_CPHCentro_ddlCurso');
    var clase = document.getElementById('ctl00_CPHCentro_tbxClase');
    var alumnoNoFumado = document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumado');
    var alumnaNoFumado = document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumado');
    var alumnoNoRegular = document.getElementById('ctl00_CPHCentro_tbxAlumnosNoFumarRegularmente');
    var alumnaNoRegular = document.getElementById('ctl00_CPHCentro_tbxAlumnasNoFumarRegularmente');
    var alumnoFumaRegular = document.getElementById('ctl00_CPHCentro_tbxAlumnosFumanRegularmente');
    var alumnaFumaRegular = document.getElementById('ctl00_CPHCentro_tbxAlumnasFumanRegularmente');
    var alumnoCadaDia = document.getElementById('ctl00_CPHCentro_tbxAlumnosCadaDia');
    var alumnaCadaDia = document.getElementById('ctl00_CPHCentro_tbxAlumnasCadaDia');

    Nombres.push("@idProvincia"); Tipos.push("Int"); Datos.push(provincia.value); 
    Nombres.push("@idCentro"); Tipos.push("Int"); Datos.push(centro.value); 
    Nombres.push("@Profesor"); Tipos.push("VarChar"); Datos.push(profesor.value.toUpperCase()); 
    Nombres.push("@Tlf"); Tipos.push("VarChar"); Datos.push(telefono.value); 
    Nombres.push("@Mail"); Tipos.push("VarChar"); Datos.push(correo.value); 
    Nombres.push("@Curso"); Tipos.push("Bit"); Datos.push(curso.value); 
    Nombres.push("@Clase"); Tipos.push("VarChar"); Datos.push(clase.value.toUpperCase()); 
    Nombres.push("@N_Alumnos_No_Fumado"); Tipos.push("Int"); Datos.push(alumnoNoFumado.value); 
    Nombres.push("@N_Alumnas_No_Fumado"); Tipos.push("Int"); Datos.push(alumnaNoFumado.value); 
    Nombres.push("@N_Alumnos_No_Regular"); Tipos.push("Int"); Datos.push(alumnoNoRegular.value); 
    Nombres.push("@N_Alumnas_No_Regular"); Tipos.push("Int"); Datos.push(alumnaNoRegular.value); 
    Nombres.push("@N_Alumnos_Regular"); Tipos.push("Int"); Datos.push(alumnoFumaRegular.value); 
    Nombres.push("@N_Alumnas_Regular"); Tipos.push("Int"); Datos.push(alumnaFumaRegular.value); 
    Nombres.push("@N_Alumnos_Cada_Dia"); Tipos.push("Int"); Datos.push(alumnoCadaDia.value); 
    Nombres.push("@N_Alumnas_Cada_Dia"); Tipos.push("Int"); Datos.push(alumnaCadaDia.value); 
    
    var resultado;
    
    resultado = ClaseSinHumo.InsertaDatosCSH(Nombres.toJSONString(),Tipos.toJSONString(),Datos.toJSONString(), nombre.value, captcha.value );
    
    return resultado;

}



/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////VALIDACIONES DYG///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function validaDatosFormularioDYG()
{
    //var challenge = Recaptcha.get_challenge(); 
    //var response = Recaptcha.get_response(); 
    var todo_ok = true;

    if(document.getElementById('ctl00_CPHCentro_tbxNombre').value.length == 0)
    {   
        document.getElementById('ctl00_CPHCentro_txtAlumno').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtAlumno').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxTelefono').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtTelefono').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxCorreoContacto').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtCorreoContacto').className = 'TextoNormalNegrita';
    }

    if(document.getElementById('ctl00_CPHCentro_tbxClase').value.length == 0)
    {
        document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegritaRojo';
        todo_ok = false;
    }
    else
    {
        document.getElementById('ctl00_CPHCentro_txtClase').className = 'TextoNormalNegrita';
    }
    
    if(todo_ok == false)
        alert('Revise los errores (marcados en rojo).');
    else
        { 
            var dev = insertaDatosDYG();//challenge,response);
            
            if(dev.value == 'OK') {
                //document.getElementById('recaptcha_div').style.border = '0px';
                document.getElementById('recaptcha_span').style.display = 'none';
                alert('Se ha registrado correctamente. Por favor, compruebe su correo electrónico pues le llegará un acuse de recibo con la confirmación de su registro. Gracias.');
            }
            else if(dev.value == 'Captcha Erroneo') {
                //document.getElementById('recaptcha_div').style.border = 'solid 2px red';
                document.getElementById('recaptcha_span').style.display = 'block';
            }
            else
                location.href = 'Error.aspx?error=' + dev.value + '&dyg=1';
        }
    
    return false;
}

function insertaDatosDYG()//challenge,response)
{
  
    var Datos = new Array();
    var Tipos = new Array();
    var Nombres = new Array();
  
    var compromiso = document.getElementById('ctl00_CPHCentro_ddlCompromiso');
    var provincia = document.getElementById('ctl00_CPHCentro_ddlProvincia');
    var centro = document.getElementById('ctl00_CPHCentro_ddlCentro');
    var nombre = document.getElementById('ctl00_CPHCentro_tbxNombre');
    var apellidos = document.getElementById('ctl00_CPHCentro_tbxApellidos');
    var telefono = document.getElementById('ctl00_CPHCentro_tbxTelefono');
    var correo = document.getElementById('ctl00_CPHCentro_tbxCorreoContacto');
    var sexo = document.getElementById('ctl00_CPHCentro_ddlSexo');
    var edad = document.getElementById('ctl00_CPHCentro_ddlEdad');
    var curso = document.getElementById('ctl00_CPHCentro_ddlCurso');
    var clase = document.getElementById('ctl00_CPHCentro_tbxClase');
    var anterior = document.getElementById('ctl00_CPHCentro_ddlAnterior');
    var fuma = document.getElementById('ctl00_CPHCentro_ddlFuma');
    var cigarrosDia = '' + (document.getElementById('ctl00_CPHCentro_tbxCigarrosDia').value == '' ? 0 : document.getElementById('ctl00_CPHCentro_tbxCigarrosDia').value);

    var malo = "6";
    var olor = "6";
    var adiccion = "6";
    var llevar = "6";
    var caro = "6";
    
	var listado = document.getElementById('listaOrden');
	for (var i=0; i<listado.options.length; i++) {
		if (listado.options[i].text == "Es malo para la salud") malo = '' + parseInt(i+1);
		else if (listado.options[i].text == "Impregna de olor mi ropa o mi boca") olor = '' + parseInt(i+1);
		else if (listado.options[i].text == "No quiero dejarme llevar por la gente y la publicidad") llevar = '' + parseInt(i+1);
		else if (listado.options[i].text == "Es caro") caro = '' + parseInt(i+1);
		else adiccion = '' + parseInt(i+1);
		
	}
	/*
    var malo = determina('ctl00_CPHCentro_rbMalo');
    var olor = determina('ctl00_CPHCentro_rbOlor');
    var adiccion = determina('ctl00_CPHCentro_rbAddiccion');
    var llevar = determina('ctl00_CPHCentro_rbLlevar');
    var caro = determina('ctl00_CPHCentro_rbCaro');
    */
    var otrosMotivos = document.getElementById('ctl00_CPHCentro_tbxOtrosMotivos');
    var apoyo = document.getElementById('ctl00_CPHCentro_ddlApoyo');
    //var apoNsnc = document.getElementById('ctl00_CPHCentro_cbxnsnc');
    var apoFam = document.getElementById('ctl00_CPHCentro_cbxFamiliares');
    var apoAmi = document.getElementById('ctl00_CPHCentro_cbxAmigos');
    var apoPro = document.getElementById('ctl00_CPHCentro_cbxProfesores');
    var apoSal = document.getElementById('ctl00_CPHCentro_cbxSalud');
    var apoLib = document.getElementById('ctl00_CPHCentro_cbxLibros');
    var apoOtr = document.getElementById('ctl00_CPHCentro_cbxOtros');
    var apoyos = document.getElementById('ctl00_CPHCentro_tbxApoyos');
    var ayuda = document.getElementById('ctl00_CPHCentro_ddlAyuda');
    var edad1 = '' + (document.getElementById('ctl00_CPHCentro_tbxEdad').value == '' ? 0 : document.getElementById('ctl00_CPHCentro_tbxEdad').value);
    var dejFum = document.getElementById('ctl00_CPHCentro_ddlDejarFumar');
    var dejAlg = document.getElementById('ctl00_CPHCentro_ddlDejAlgVez');
    
    var captcha = document.getElementById('ctl00_CPHCentro_tbxCaptcha');
    
    Nombres.push("@Compromiso"); Tipos.push("Int"); Datos.push(compromiso.value); 
    Nombres.push("@idProvincia"); Tipos.push("Int"); Datos.push(provincia.value); 
    Nombres.push("@idCentro"); Tipos.push("Int"); Datos.push(centro.value); 
    Nombres.push("@Nombre"); Tipos.push("VarChar"); Datos.push(nombre.value.toUpperCase()); 
    Nombres.push("@Tlf"); Tipos.push("VarChar"); Datos.push(telefono.value); 
    Nombres.push("@Correo"); Tipos.push("VarChar"); Datos.push(correo.value); 
    Nombres.push("@Sexo"); Tipos.push("VarChar"); Datos.push(sexo.value); 
    Nombres.push("@Edad"); Tipos.push("int"); Datos.push(edad.value); 
    Nombres.push("@Curso"); Tipos.push("Int"); Datos.push(curso.value); 
    Nombres.push("@Clase"); Tipos.push("VarChar"); Datos.push(clase.value.toUpperCase()); 
    Nombres.push("@Anterior"); Tipos.push("VarChar"); Datos.push(anterior.value); 
    Nombres.push("@Fuma"); Tipos.push("VarChar"); Datos.push(fuma.value); 
    Nombres.push("@CigarrosDia"); Tipos.push("Int"); Datos.push(cigarrosDia); 
    Nombres.push("@Malo"); Tipos.push("VarChar"); Datos.push(malo); 
    Nombres.push("@Olor"); Tipos.push("VarChar"); Datos.push(olor); 
    Nombres.push("@Adiccion"); Tipos.push("VarChar"); Datos.push(adiccion); 
    Nombres.push("@Llevar"); Tipos.push("VarChar"); Datos.push(llevar); 
    Nombres.push("@Caro"); Tipos.push("VarChar"); Datos.push(caro); 
    Nombres.push("@OtrosMotivos"); Tipos.push("VarChar"); Datos.push(otrosMotivos.value.toUpperCase()); 
    Nombres.push("@Apoyo"); Tipos.push("VarChar"); Datos.push(apoyo.value); 
    //Nombres.push("@ApoyoNSNC"); Tipos.push("Bit"); Datos.push('' + apoNsnc.checked); 
    Nombres.push("@ApoyoFamiliar"); Tipos.push("Bit"); Datos.push('' + apoFam.checked); 
    Nombres.push("@ApoyoAmigo"); Tipos.push("Bit"); Datos.push('' + apoAmi.checked); 
    Nombres.push("@ApoyoProfesores"); Tipos.push("Bit"); Datos.push('' + apoPro.checked); 
    Nombres.push("@ApoyoSalud"); Tipos.push("Bit"); Datos.push('' + apoSal.checked); 
    Nombres.push("@ApoyoLibros"); Tipos.push("Bit"); Datos.push('' + apoLib.checked); 
    Nombres.push("@ApoyoOtro"); Tipos.push("Bit"); Datos.push('' + apoOtr.checked); 
    Nombres.push("@Apoyos"); Tipos.push("VarChar"); Datos.push(apoyos.value.toUpperCase()); 
    Nombres.push("@Ayuda"); Tipos.push("VarChar"); Datos.push(ayuda.value); 
    Nombres.push("@EdadEmpFum"); Tipos.push("Int"); Datos.push(edad1); 
    Nombres.push("@DejarFumar"); Tipos.push("VarChar"); Datos.push(dejFum.value); 
    Nombres.push("@DejarFumarVez"); Tipos.push("VarChar"); Datos.push(dejAlg.value); 
    Nombres.push("@apellidos"); Tipos.push("VarChar"); Datos.push(apellidos.value.toUpperCase()); 
    
    var resultado;
    resultado = DejaloYGana.InsertaDatosDYG(Nombres.toJSONString(),Tipos.toJSONString(),Datos.toJSONString(), nombre.value, captcha.value); //challenge, response, 
    alert(resultado.value);
    return resultado;

}
    function ordena(indice) {
        var selectOrden = document.getElementById('listaOrden');
        var selectTotal = document.getElementById('listaTotal');
        var elemento = selectTotal.options[indice].text;
        try{
            selectOrden.add(new Option(elemento, elemento), null);
        }
        catch(e){ //in IE, try the below version instead of add()
            selectOrden.add(new Option(elemento, elemento));
        }
        selectTotal.remove(indice);

    }
    
    function desordena(indice) {
        var selectOrden = document.getElementById('listaOrden');
        var selectTotal = document.getElementById('listaTotal');
        var elemento = selectOrden.options[indice].text;

        try{
            selectTotal.add(new Option(elemento, elemento), null);
        }
        catch(e){ //in IE, try the below version instead of add()
            selectTotal.add(new Option(elemento, elemento));
        }
        selectOrden.remove(indice);
    
    }
    
    function IsEmail(correo) {
//        var filter = /^[A-Za-z0-9][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    var filter = /\w+([-+.']\w+)*@\w+([\-.]\w+)*\.\w+([\-.]\w+)*/;
    
    if (correo.length == 0) return true;
    
    if (filter.test(correo)) return true;
    else return false;
}