// JavaScript Document
var profiles =
{

    window800:
    {
        height:800,
        width:800,
        status:1
    },


    windowCenter:
    {
        height:800,
        width:800,
        center:1,
        scrollbars:1,
        resizable:1
    },
		
    windowHV:
    {
        height:300,
        width:800,
        center:1,
        scrollbars:1,
        resizable:1
    }

};


$(function() {
    $('#home').click(function (event){
        event.preventDefault();
        $('#indexContent').load("home/index.php");
    });
    $('#btnProductos').click(function (event){
        event.preventDefault();
        $('#indexContent').load("productos/index.php");
    });
    $('#btnEmpresa').click(function (event){
        event.preventDefault();
        $('#indexContent').load("empresa/index.php");
    });
    $('#btnFamilia').click(function (event){
        event.preventDefault();
        $('#indexContent').load("familia/index.php");
    });
    $('#btnCobertura').click(function (event){
        event.preventDefault();
        $('#indexContent').load("cobertura/index.php");
    });
    $('#btnOportunidades').click(function (event){
        event.preventDefault();
        $('#indexContent').load("oportunidades/index.php");
    });
	
	
    $('#btnNoticias').click(function (event){
        event.preventDefault();
        $('#indexContent').load("noticias/index.php");
    });
	
    $('#btnPatrocinio').click(function (event){
        event.preventDefault();
        $('#indexContent').load("patrocinio/index.php");
    });
	
    $('.contactos').click(function (event){
        event.preventDefault();
        $('#indexContent').load("oportunidades/index.php?contac=1");
    });
	
    $('#contactosIndex').click(function(){
        $('#contactenos').dialog('open');
        return false;
    });
	
    $(".popupwindow").popupwindow(profiles);
	
    // Dialog

    $('#contactenos').dialog({
        autoOpen: false,
        modal: true,
        width: 650,
        buttons: {
            "Enviar": function() {
				
                if($('#txtNombre').val() == '' || $('#txtApellido').val() == '' ||
                    $('#txtDireccion').val() == '' || $('#txtTelefono').val() == '' ||
                    $('#txtCelular').val() == '' || $('#txtEmail').val() == '' ||
                    $('#txtDesc').val() == ''){
                    alert("Tiene que llenar los campos oblicatorios");
					
                }else{
				
                    var datos = 'tipoPersona='+$("#txtTipoPersona").val()+'&nombre='+$('#txtNombre').val()
                    +'&apellido='+$('#txtApellido').val()+'&dir='+$('#txtDireccion').val()+'&tel='+$('#txtTelefono').val()
                    +'&cel='+$('#txtCelular').val()+'&email='+$('#txtEmail').val()+'&ciudad='+$('#txtCiudad').val()
                    +'&tipo='+$('#txtTipo').val()+'&contactar='+$('#txtOpcion').is(':checked')+'&descCon='+$('#txtDesc').val();
                    $.ajax({
                        url: './php/contactos.php',
                        type: "POST",
                        data: datos,
                        success: function(msj){
                            if(msj ==1){
                                alert("Muchas gracias por comunicarse con nosotros.  Su información esta será procesada. En los próximos días nos estaremos comunicando con usted");
                                $('#txtNombre').val('');
                                $('#txtApellido').val('');
                                $('#txtDireccion').val('');
                                $('#txtTelefono').val('');
                                $('#txtCelular').val('');
                                $('#txtEmail').val('');
                                $('#txtDesc').val('');
                                $('#txtCiudad').val('');
                                $('#contactenos').dialog('close');

                            }else{
                                if(msj ==0){
                                    alert("Error al enviar el mensaje.");
                                    $('#txtNombre').val('');
                                    $('#txtApellido').val('');
                                    $('#txtDireccion').val('');
                                    $('#txtTelefono').val('');
                                    $('#txtCelular').val('');
                                    $('#txtEmail').val('');
                                    $('#txtDesc').val('');
                                    $('#txtCiudad').val('');
                                    $('#contactenos').dialog('close');
                                }else{
                                    if(msj ==2){
                                        alert("Todos los capos deben estar dilegenciados.");
                                    }else{
                                        if(msj ==3){
                                            alert("Email incorrecto");
                                        }

                                    }
                                }
                            }
								
                        }
                    });
                }


            },

            "Cancelar": function() {
                $(this).dialog("close");
            }

        }

    });
	
	
});
