﻿function limpaCampos() {
	document.getElementById("frmNews").reset();
}

$(document).ready(function () {
    
	var campo_data = new Spry.Widget.ValidationTextField("txtData", "custom", { isRequired : true, format : "custom", pattern : "00/00/0000", hint : "__/__/____", useCharacterMasking : true, validateOn : [ "blur" ] });
	var campo_fone = new Spry.Widget.ValidationTextField("txtTelefone", "custom", { isRequired : true, format : "custom", pattern : "(00) 0000-0000", hint : "(__) ____-____", useCharacterMasking : true, validateOn : [ "blur" ] });

	$('a[rel="#overlay_news"]').overlay({
		expose: {
			color: '#000000',
			loadSpeed: 200,
			opacity: 0.9
		},
		//load: true,
		top: '10px',
		onClose: limpaCampos
	});
	
	$('#overlay_alunos').overlay({
		expose: {
			color: '#000000',
			loadSpeed: 200,
			opacity: 0.9
		},
		load: true,
		top: '10px',
		onClose: limpaCampos
	});

    $('#btEnviarExAluno').click(function () {
        var o = new Object();
        o.Nome = $('#txtNome').val();
        o.DataNascimento = $('#txtData').val();
        if (o.DataNascimento != '') {
            o.DataNascimento = o.DataNascimento.substring(3, 5) + '-' + o.DataNascimento.substring(6, 10) + '-' + o.DataNascimento.substring(0, 2);
        }
        o.De = $('#txtPeriodoDe').val();
        o.Ate = $('#txtPeriodoAte').val();
        o.Endereco = $('#txtEndereco').val();
        o.Telefone = $('#txtTelefone').val();
        o.Email = $('#txtEmail').val();
        var c = new Object();
        c.cad = o;
        $.ajax(
                {
                    type: "POST",
                    url: "default.aspx/CadExAluno",
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    data: JSON.stringify(c),
                    success:
                        function (r) {
                            if (r.d == '1') {
                                alert('Seu cadastro foi enviado com sucesso!');
								$('a[rel="#overlay_news"]').overlay().close();
                            } else {
                                alert(r.d);
                            }
                        },
                    error:
                        function (xhr, textStatus, errorThrown) {
                            alert(xhr.responseText);
                        }
                });
    });
	
	// colorbox do video
	$('a[rel="colorbox-video"]').colorbox({
		iframe:	true,
		width: 480,
		height: 390
	});
});
