function NuevaContratacion(step) {
    switch (step) {
        case 1:
            //tipo = "Clasif";
            Loading();
            $.ajax({
                type: 'POST',
                url: 'include/new_contratacion.php',
                data: 'step=' + step + '&type=Clasif',
                success: function(data) {
                    $('#contratacion').html(data);
                }
            });
            break;
        case 2:
            tipo = $('#tipo').val();
            if (tipo == 'Clasif' || tipo == 'Anun') {
                plantilla = $("input[@name='plantilla']:checked").val();
                if (plantilla >= 1 && plantilla <= 6) {
                    Loading();
                    $.ajax({
                        type: 'POST',
                        url: 'include/new_contratacion.php',
                        data: 'step=' + step + '&type=' + tipo + '&plantilla=' + plantilla,
                        success: function(data) {
                            $('#contratacion').html(data);
                        }
                    });
                } else {
                    alert('selecciona plantilla');
                }


            } else {
                alert('Ha ocurrido un error')
                window.location = 'index.php?secc=anunciate';
            }
            break;
        case 3:
            texto = $('#texto').val();
            titulo = $('#titulo').val();
            plantilla = $('#plantilla').val();
            tipo = $('#tipo').val();
            negritas = $('#negritas').val();
            if (tipo == 'Clasif' || tipo == 'Anun') {
                if (plantilla >= 1 && plantilla <= 6) {
                    if (texto != '' && titulo != '') {
                        Loading();
                        $.ajax({
                            type: 'POST',
                            url: 'include/new_contratacion.php',
                            data: 'step=3&type=' + tipo + '&plantilla=' + plantilla + '&texto=' + texto + '&titulo=' + titulo + '&negritas=' + negritas,
                            success: function(data) {
                                $('#contratacion').html(data);
                            }
                        });
                    } else {
                        alert('Por favor escriba su anuncio');
                        $('#titulo').focus();
                    }
                } else {
                    alert('Ha ocurrido un error');
                }
            } else {
                alert('Ha ocurrido un error');
            }
            break;
    }
}


function End() {
    valores = $('#formcontratacion').serialize();
    Loading();
    $.ajax({
        type: 'POST',
        url: 'include/comprar.php',
        data: valores,
        success: function(data) {
            $('#contratacion').html(data);
        }
    });
}

function llenasub() {
    seccion = $('#seccion').val();
    $('#sub').html('<img src="images/ajax-loader.gif" alt="Loading" border="0" />');
    $.ajax({
        type: 'POST',
        url: 'include/llenasub.php',
        data: 'seccion=' + seccion,
        success: function(data) {
            $('#sub').html(data);
        }
    });
}

function Loading () {
    htm = '<img src="images/ajax-loader.gif" alt="Loading" border="0" />';
    $('#contratacion').html(htm);
}

function CancelSale() {
    if (confirm('¿Deseas cancelar tu compra?')) {
        window.location = 'index.php?secc=anunciate';
    }
}

function llenasubc() {
    seccion = $('#categoria').val();
    if (seccion > 0) {
        $('#subcategoria').html('<img src="images/ajax-loader.gif" alt="Loading" border="0" />');
        $.ajax({
            type: 'POST',
            url: 'include/llenasub.php',
            data: 'seccion=' + seccion + '&type=head',
            success: function(data) {
                $('#subcategoria').html(data);
                $('#subcategoria').focus();
            }
        });
    } else {
        alert('La categoria es incorrecta');
    }
}

function Clima()
{
    try //Internet Explorer
    {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    catch(e)
    {
        try //Firefox, Mozilla, Opera, etc.
        {
            xmlDoc=document.implementation.createDocument("","",null);
        }
        catch(e)
        {
            alert(e.message);
            return;
        }
    }
    xmlDoc.async=false;
    xmlDoc.load("include/get_clima.php");
    //tempe=xmlDoc.getElementsByTagName("yweather:condition")[0].attributes[2].nodeValue;
    tempe='16';

    $('.fecha span').html(tempe + '&deg;');

}

function SubCatego() {
    valor = $('#subcategoria').val();
    if (valor > 0) {
        url = '?secc=destacados&subcat=' + valor;
        window.location = url;
    } else {
        alert('datos incorrectos');
    }
    return false;
}

function Renovar(idclasificado) {
    if (idclasificado > 0) {
        $('.center').html('<img src="images/ajax-loader.gif" alt="Loading" border="0" />');
        $.ajax({
            type: 'POST',
            url: 'include/recontrata.php',
            data: 'idclasif=' + idclasificado,
            success: function(data) {
                $('.center').html(data);
            }
        });
    }
}

function EndR() {
    valores = $('#formcontratacion').serialize();
    Loading();
    alert(valores);
    $.ajax({
        type: 'POST',
        url: 'include/renovar.php',
        data: valores,
        success: function(data) {
            $('#contratacion').html(data);
        }
    });
}
