//AJAX
var ajax_req; var ajax_result=''; var ajax_external=''; 
function loadXMLDoc(url) { 
	if (window.XMLHttpRequest) { 
		ajax_req = new XMLHttpRequest(); 
		ajax_req.onreadystatechange = processReqChange; 
		ajax_req.open("GET", url, true); 
		ajax_req.setRequestHeader("Referer", window.location); 
		ajax_req.send(null); 
	}else if (window.ActiveXObject) { 
		ajax_req = new ActiveXObject("Microsoft.XMLHTTP"); 
		if (ajax_req) { 
			ajax_req.onreadystatechange = processReqChange; 
			ajax_req.open("GET", url, true); 
			ajax_req.send(); 
		} 
	} 
} 
function processReqChange() { 
	if (ajax_req.readyState == 4) { 
		try { 
			if (ajax_req.status == 200) { 
				if (ajax_reading) { 
					ajax_result=ajax_req.responseText; 
				} else { 
					ajax_result='ERROR:busy'; } 
			} else { 
				ajax_result='ERROR:'+ajax_req.statusText; 
			} 
			ajax_reading = false; 
		} catch (E){ 
			ajax_reading = false; 
			return false; 
		} 
		if (ajax_external!='') eval(ajax_external); 
	} 
	return false; 
} 
var ajax_reading = false; 

function LoadURL(url, external) {
	if (!ajax_reading) {
		ajax_reading = true; 
		ajax_result='';
		var d = new Date()
		var uID = '' + d.getDate()+d.getMonth() +1+d.getFullYear()+d.getHours()+d.getMinutes()+d.getSeconds()+Math.random();
		if (url.indexOf('?')>0) url  = url+'&ajaxID='+uID;
		else url  = url+'?ajaxID='+uID;
		ajax_external=external;
		loadXMLDoc(url);
		return ajax_result;
	}
	else return '';
}


function do_vote(vote){
	LoadURL('http://www.justrave.com/foro/vote_song.php?vote=' + vote, 'show_vote(' + vote + ')'); 
 	//LoadURL('http://localhost/top10/vote_song.php?vote=' + vote + '&test_desa=1&user_id=39', 'show_vote(' + vote + ')');
 
}

function do_top10(){
	 LoadURL('http://www.justrave.com/foro/mejores10.php', 'show_top10()');
	//document.location.href='http://www.justrave.com/foro/mejores10.php';
	//document.location.href='http://localhost/top10/mejores10.php?test_desa=1';
}

function show_top10(){
	var div_res = document.getElementById('div_top10');
	div_res.innerHTML = ajax_result;
}


function show_vote(vote){
        var div_res = document.getElementById('div_result');
 	
       if(ajax_result == 'OK'){
                if (vote == '1'){
                        div_res.innerHTML = 'SI';
                }else{
                        div_res.innerHTML = 'NO';
                }
        }else{
                div_res.innerHTML = 'ERROR: Intenta luego.';
        }
}
