﻿
function initFields() {
    loadPart();
    //courseChanged();
    removeOtro();
}

function addOtro() {
    var o = document.createElement('option');
    o.text = "Otro";
    o.value = "Otro";
    try {
       document.forms[0].DropDownList3.add(o,document.forms[0].DropDownList3.options[0]);
    }
    catch (ex) {
       document.forms[0].DropDownList3.add(o,0);
    }
    document.forms[0].DropDownList3.selectedIndex = 0;
    document.forms[0].TextBox7.value = "<Escribe aqui el nombre del curso>";
    document.forms[0].TextBox8.value = "<Escribe aqui la fecha del curso>";
    document.forms[0].TextBox9.value = "<Escribe aqui el lugar del curso>";
    document.forms[0].TextBox7.focus();
    document.forms[0].TextBox7.select();
}

function removeOtro() {
    if (document.forms[0].DropDownList3.options[0].text == "Otro") {
        document.forms[0].DropDownList3.remove(0);
    }
    document.forms[0].DropDownList3.selectedIndex = -1;
}



function courseChanged() {
    var index = document.forms[0].DropDownList3.selectedIndex;
    var id = document.forms[0].DropDownList3.options[index].value;
    var text = document.forms[0].DropDownList3.options[index].text;
    if (text == "Otro") {
        document.forms[0].HiddenField1.value = 0;
        document.forms[0].TextBox7.value = "<Escribe aqui el nombre del curso>";
        document.forms[0].TextBox8.value = "<Escribe aqui la fecha del curso>";
        document.forms[0].TextBox9.value = "<Escribe aqui el lugar del curso>";
        document.forms[0].TextBox7.focus();
        document.forms[0].TextBox7.select();
    } else {
        var name = text.substring(0, text.indexOf(" -- "));
        var text2 = text.substring(text.indexOf(" -- ")+4);
        var place = text2.substring(0, text2.indexOf(" -- "));
        var date = text2.substring(text2.indexOf(" -- ")+4);
        document.forms[0].HiddenField1.value = id;
        document.forms[0].TextBox7.value = name;
        document.forms[0].TextBox8.value = place;
        document.forms[0].TextBox9.value = date;
    }
    //document.forms[0].DropDownList3.selectedIndex = -1;
}

function validar() {
    if (document.forms[0].TextBox1.value.length == 0) {
        document.forms[0].TextBox1.focus();
        alert("Favor de proporcionar su nombre");
        return false;
    }
    if (document.forms[0].TextBox3.value.length == 0) {
        document.forms[0].TextBox3.focus();
        alert("Favor de proporcionar su dirección de correo electrónico");
        return false;
    }
    if (document.forms[0].TextBox3.value.indexOf("@") == -1) {
        document.forms[0].TextBox3.focus();
        document.forms[0].TextBox3.select();
        alert("Favor de proporcionar una dirección de correo electrónico válida");
        return false;
    }
    if (document.forms[0].TextBox4.value.length < 10) {
        document.forms[0].TextBox4.focus();
        document.forms[0].TextBox4.select();
        alert("Favor de proporcionar su telefóno, incluyendo clave de larga distancia y, en su caso, código de su país");
        return false;
    }
    if (document.forms[0].TextBox5.value.length == 0) {
        document.forms[0].TextBox5.focus();
        alert("Favor de proporcionar su ciudad");
        return false;
    }
    if (document.forms[0].TextBox6.value.length == 0) {
        document.forms[0].TextBox6.focus();
        alert("Favor de proporcionar su país");
        return false;
    }
    if (document.forms[0].Select1.value < 6) {
        if (document.forms[0].TextBox7.value.length == 0) {
            document.forms[0].DropDownList3.focus();
            alert("Favor de seleccionar un curso");
            return false;
        }
    } else {
        if (document.forms[0].TextBox7.value.length == 0) {
            document.forms[0].TextBox7.focus();
            alert("Favor de seleccionar el nombre del curso deseado");
            return false;
        }
        if (document.forms[0].TextBox9.value.length == 0) {
            document.forms[0].TextBox9.focus();
            alert("Favor de seleccionar fecha para el curso");
            return false;
        }
        if (document.forms[0].TextBox8.value.length == 0) {
            document.forms[0].TextBox8.focus();
            alert("Favor de seleccionar el lugar donde se impartirá el curso");
            return false;
        }
    }
    //document.forms[0].Button1.disabled = true;
    return true;
}

function loadPart() {

    var length = document.forms[0].Select1.options.length;
    for (i=0; i<=length; i++) {
        document.forms[0].Select1.remove(0);
    }
    if (document.forms[0].RadioButtonList2_0.checked) {
        removeOtro();
        document.forms[0].TextBox7.readOnly = true;
        document.forms[0].TextBox8.readOnly = true;
        document.forms[0].TextBox9.readOnly = true;
        document.forms[0].RadioButtonList1_0.disabled = true;
        document.forms[0].RadioButtonList1_1.disabled = true;
        document.forms[0].TextBox7.value = "";
        document.forms[0].TextBox8.value = "";
        document.forms[0].TextBox9.value = "";
        document.forms[0].HiddenField1.value = "0";
        for (i=1; i<=5; i++) {
            var o = document.createElement('option');
            o.text = "" + i;
            o.value = "" + i;
            try {
                document.forms[0].Select1.add(o,null);
            }
            catch (ex) {
                document.forms[0].Select1.add(o);
            }
        }
    } else {
        addOtro();
        document.forms[0].TextBox7.readOnly = false;
        document.forms[0].TextBox8.readOnly = false;
        document.forms[0].TextBox9.readOnly = false;
        document.forms[0].RadioButtonList1_0.disabled = false;
        document.forms[0].RadioButtonList1_1.disabled = false;
        for (i=6; i<=20; i++) {
            var o = document.createElement('option');
            o.text = "" + i;
            o.value = "" + i;
            try {
                document.forms[0].Select1.add(o,null);
            }
            catch (ex) {
                document.forms[0].Select1.add(o);
            }
        }
    }
    document.forms[0].RadioButtonList1_0.checked = false;
    document.forms[0].RadioButtonList1_1.checked = true;
    document.forms[0].Select1.selectedIndex = 0;
    updateParticipants();
}

function updateParticipants() {
    document.forms[0].HiddenField2.value = document.forms[0].Select1.options[document.forms[0].Select1.selectedIndex].value;
}
