﻿function CreateXmlHttp()
{
    var xmlHttp;
    xmlHttp=false;
    try
    {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            xmlHttp = null;
        }
    }
    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

function ajaxanuncios(sfuncion,Param,txt,Reg)
{
    var xmlHttp = new CreateXmlHttp();
    var ajaxRequest = "http://www.anunciosmail.com/ajax.aspx?funcion=" + sfuncion + Param + "&Start=" + parseInt(txt);
    txt = parseInt(txt)+25
    var More = ( Reg > txt )
    EnviaRecogeInfo( xmlHttp, 'Anuncios', ajaxRequest );
    if(!More){
        document.getElementById('iAjax').style.visibility='hidden';
    } else {
        document.getElementById('iAjax').value = txt + " anuncios listados. ¿Ver más?";
    }
}

function ajaxycierra(sfuncion, sDiv, Param)
{
    var xmlHttp = new CreateXmlHttp();

    var ajaxRequest = "http://www.anunciosmail.com/ajax.aspx?funcion=" + sfuncion + Param;

    EnviaRecogeInfo( xmlHttp, sDiv, ajaxRequest );
    ajax('cerrar', sDiv, '' );
}

function ajax(sfuncion, sDiv, Param)
{
    var xmlHttp = new CreateXmlHttp();
    if (document.getElementById('bAjax' + sDiv) != null){
	
        if (document.getElementById('bAjax' + sDiv).value=='+')
        {
            document.getElementById('bAjax' + sDiv).value='-';
        } else {
             document.getElementById('bAjax' + sDiv).value='+';
             sfuncion = 'cerrar';
        }
    }
    var ajaxRequest = "http://www.anunciosmail.com/ajax.aspx?funcion=" + sfuncion + Param;
    if (sfuncion == 'subtipos')
    {
	    document.getElementById('secciones').innerHTML = "";
    }

    else if (sfuncion == 'cerrar')
    {
        ajaxRequest =  ajaxRequest + "&texto=" + sDiv;
    }

    document.getElementById(sDiv).innerHTML = "";
    EnviaRecogeInfo( xmlHttp, sDiv, ajaxRequest );
}
function EnviaRecogeInfo( xmlHttp, sDiv, ajaxRequest )
{
    if (typeof(xmlHttp.onprogress)=='object'){
        xmlHttp.onload = xmlHttp.onerror = xmlHttp.onabort = function(){
        recogeInfo(sDiv,xmlHttp);
    };
    } else {
        xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4){
            recogeInfo(sDiv,xmlHttp);
        }
    };
    }
    xmlHttp.open("GET", ajaxRequest, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(null);
}
function recogeInfo(sDiv, xmlHttp)
{
    if(xmlHttp.status == 200 || window.location.href.indexOf("http")==-1)
    {
        document.getElementById(sDiv).innerHTML = document.getElementById(sDiv).innerHTML + xmlHttp.responseText;
    }
}
function validar(formulario){
if(formulario.Tipo.value == ''){
alert('Tienes que seleccionar una SECCIÓN');
formulario.Tipo.focus();
return false;
}
if(formulario.tbTitulo.value.length < 10){
alert('Pon un TITULO corto pero no tanto, mínimo 10 caracteres');
formulario.tbTitulo.focus();
return false;
}
if(formulario.tbAnuncio.value == ''){
alert('Inserta la DESCRIPCION del anuncio');
formulario.tbAnuncio.focus();
return false;
}
if(formulario.tbAnuncio.value.length > 5000){
alert('El anuncio no puede superar los 5000 caracteres');
formulario.tbAnuncio.focus();
return false;
}
if(formulario.tbTelefono.value == '' && formulario.tbMail.value == ''){
alert('Si no pones ni TELEFONO ni MAIL no podrán contactar contigo');
formulario.tbTelefono.focus();
return false;
}
return true;
}

