function ajaxFunction() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        return xmlHttp;
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            return xmlHttp;
        } catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                return xmlHttp;
            } catch (e) {
                alert("Tu navegador no soporta AJAX!");
                return false;
            }
        }
    }
}
function reloj()
{
    var	ajax;
    ajax = ajaxFunction();
	
    ajax.open("GET", "lib_top_playing.php", true);
    ajax.onreadystatechange = function()
    {
        if (ajax.readyState == 4)
        {
            document.getElementById('reloj').innerHTML = ajax.responseText;
        }
    }
    ajax.send(null);
    setTimeout("reloj()",1000);
}

function imgHOMEBlocke()
{
    var	ajax;
    ajax = ajaxFunction();
	
    ajax.open("GET", "img_blocke.php", true);
    ajax.onreadystatechange = function()
    {
        if (ajax.readyState == 4)
        {
            document.getElementById('imgBlocke').innerHTML = ajax.responseText;
        }
    }
    ajax.send(null);
    setTimeout("imgHOMEBlocke()",30000);
}

function enviar(_pagina,capa) 
{
    var	ajax;
    ajax = ajaxFunction();
    ajax.open("GET", _pagina, true);
    ajax.onreadystatechange = function()
    {
        if (ajax.readyState == 4)
        {
            document.getElementById(capa).innerHTML = ajax.responseText;
            document.getElementById('celPagina').style.backgroundImage='url(img/fondo_int.jpg)';
        }
    }
    ajax.send(null);
}

function delMP3(fk)
{

        var url = "inc_functions.php?a=delmp3&Id="+fk;
        document.location=url;



}

function addagenda()
{
	
    fk_mp3=null;
    miFechaActual = new Date() ;
	
    idmp3=null;
    for (i=0;i<document.getElementById('fk_mp3').length;i++) {
        if (document.getElementById('fk_mp3')[i].checked)
        {
            idmp3 = document.getElementById('fk_mp3')[i].value;
            break;
        }
    }
    if (document.getElementById('fk_mp3').checked)
    {
        idmp3 = document.getElementById('fk_mp3').value;
    }

    if(idmp3==null)
    {
        alert("You must select a MP3");
        return false;
    }
    else
    {
        if(document.getElementById('dia').value=="")
        {
            alert("You must chose a date");
            return false;
        }
				
        /*
                else if(document.getElementById('dia').value<= miFechaActual.format("yyyy-mm-dd"))
		{
			alert("You must chose a date after today");
			return false;
		}
                */
		
        else
        {
            var dia = document.getElementById('dia').value;
            var franja = document.getElementById('h').value + " " + document.getElementById('m').value;
            var gmt = document.getElementById('gmt').value;
            var mp3 = idmp3;
            var url = "inc_functions.php?a=addagenda&mp3="+mp3+"&dia="+dia+"&franja="+franja+"&gmt="+gmt;
            document.location=url;
        }
    }
}

function delwebcast(id)
{
    
        var url = "inc_functions.php?a=delagenda&id="+id;
        //alert(url);
        document.location=url;
    
}

function addContact()
{

    var ArrContactos = new Array();
    ArrContactos = document.getElementById('contacto').value.split(",");
		
    for(i=0;i<ArrContactos.length;i++)
    {
        ArrContactos[i] = allTrim(ArrContactos[i]);
        for(j=0;j<document.getElementById('contactos').options.length;j++)
        {
            if(ArrContactos[i]==document.getElementById('contactos').options[j].text)
            {
                var existe = true;
            }
            else
            {
                var existe = false;
            }
        }
			
        if(isValidEmail(ArrContactos[i]))
        {
            if(!existe)
            {
                if(document.getElementById('contactos').options.length<51)
                {
                    posicion = document.getElementById('contactos').options.length;
                    document.getElementById('contactos').options[posicion] = new Option(ArrContactos[i]);
                }
            }
        }
        else
        {
            alert("'"+ArrContactos[i]+"' No es un email valido");
            return false;
        }
    }
    document.getElementById('contacto').value = '';

}

function sendPlayList()
{
	
    for (i=0;i<document.getElementById('webcast').length;i++) {
        if (document.getElementById('webcast')[i].checked)
        {
            idwebcast = document.getElementById('webcast')[i].value;
            break;
        }
    }

    if (document.getElementById('webcast').checked)
    {
        idwebcast = document.getElementById('webcast').value;
    }
	
    if(idwebcast==null)
    {
        alert("You must select a Webcast");
        return false;
    }
	
    var error ="";
	
    document.getElementById('titulo').value==""?error+="- Title\n":null;
    document.getElementById('asunto').value==""?error+="- Subject\n":null;
    document.getElementById('contactos').options.length==0?error+="- Contacts\n":null;
    if (error!=="") {
        alert("Please complete all fields:\n" + error + "\n");
        return false;
    } else {
	
        var ArrContactos = new Array();
        for(i=0;i<document.getElementById('contactos').options.length;i++)
        {
            ArrContactos[i]=document.getElementById('contactos').options[i].text;
        }
        var contactosList = ArrContactos.toString();
        var s= document.getElementById('asunto').value;
        var t= document.getElementById('titulo').value;
        var idwebcast = document.getElementById('webcast').value;
	
        var url = "inc_functions.php?a=sendList&id="+idwebcast+"&s="+s+"&t="+t+"&m="+contactosList;
        document.location=url;
    }
}
