function getRss(){
    var xmlHttp;
    xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRss").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdRss").innerHTML = xmlHttp.responseText;
			$idRss = document.getElementById("rssOpen").value;
			if($idRss != ''){ leeRss($idRss); }
		} 
	}
	xmlHttp.open("GET",baseURL+"getRss.php",true);   
	
	xmlHttp.send(null);	
}

function getRssBox($idBox,$id){
    var xmlHttp;
    xmlHttp = checkCapabilities();
   
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRss"+$idBox).innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			try{
				document.getElementById("tdRss"+$idBox).innerHTML = xmlHttp.responseText;
				$idRss = document.getElementById("rssOpen"+$idBox).value;
				if($idRss != ''){ leeRss($idRss,$idBox); }
			}catch($err){}	
		}  
	}
	xmlHttp.open("GET",baseURL+"getRss.php?box="+$idBox+"&select="+$id,true);   
	
	xmlHttp.send(null);	
}

function insertaRss($box, $id){
    var xmlHttp;
	xmlHttp = checkCapabilities();
	var titulo = document.getElementById('tituRss'+$box).value;
	var canal = document.getElementById('canalRss'+$box).value;
	
	if(titulo == '' || canal == ''){
		alert('Complete los datos');
	}else{
		xmlHttp.onreadystatechange=function(){
	 		if(xmlHttp.readyState == 4){
				//alert(xmlHttp.responseText);
				getRssBox($box, $id);
			}
		}
		xmlHttp.open("GET",baseURL+"addRss.php?titulo="+titulo+"&canal="+canal+"&box="+$box,true);
		xmlHttp.send(null);
	} 
}

function editRss($box) {
	var xmlHttp;
    xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRss_"+$box).innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			$texto = xmlHttp.responseText;
			document.getElementById("tdRss_"+$box).innerHTML = $texto;
			if($texto == ''){
				alert("El máximo de Feeds por widget es 3. Se agregará una nueva.");
				newFeedBox();
			}	  
		} 
	}
	xmlHttp.open("GET",baseURL+"editRss.php?box="+$box,true);   
	
	xmlHttp.send(null);		
}

function cerrarEdit(id) {
	document.getElementById(id).innerHTML = '';
}

function leeRss(id,$idBox){
    try{
        var xmlHttp;
        xmlHttp = checkCapabilities();
            
        xmlHttp.onreadystatechange=function(){
            if(xmlHttp.readyState < 4){
                document.getElementById("tdDataRss"+$idBox).innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
            } 
            if(xmlHttp.readyState == 4){
                document.getElementById("tdDataRss"+$idBox).innerHTML = xmlHttp.responseText;
            } 
        }
        xmlHttp.open("GET",baseURL+"getDataRss.php?id="+id,true);   
        
        xmlHttp.send(null);
    }catch($err){}
}

function borrarRss(id) {

	var xmlHttp;
    xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4){
			getRss();
		} 
	}
	xmlHttp.open("GET",baseURL+"borrarRss.php?id="+id,true);   
	xmlHttp.send(null);		
}

function newFeedBox(){
	var xmlHttp;
    xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4){
			location.href = "./index.php";
		} 
	}
	xmlHttp.open("GET",baseURL+"newRssBox.php",true);   
	xmlHttp.send(null);			
}
