// JavaScript for the music-charts
// lightbox on voting, and the calling the vote itself(php-script)

function vote(interpret, song) {
	// the country has to be set in interdependence to the selected programm
	var programm_id = document.getElementById('suche_programm').value;

	// url to the php sript which executes the vote
	interpret = interpret.replace("&", "#UND#");
	
	url = '/_include/tools/musicCharts.php?interpret='+interpret+"&song="+song;
	
	//document.getElementById('status_div').style.visibility='visible';
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	http_request.onreadystatechange = createMusicChartsLightbox;
	http_request.open('GET', url, true);
	http_request.send(null);

}

function createMusicChartsLightbox() {
	// the response is a boolean
	error = http_request.responseText;
	
	if(http_request.readyState == 4) {
		if(http_request.status == 200) {
			// if it was successfull unlock the lightbox
			if (!error){
				showMusicChartsSuccessbox();
			// otherwise just alert that an error occured
			} else {
				showMusicChartsErrorbox(error);
			}
		}
	}
}

function showMusicChartsSuccessbox(){
	document.getElementById('lightbox_music_charts').style.opacity = '0.2';
	document.getElementById('lightbox_music_charts').style.filter = 'alpha(opacity=20)';
	document.getElementById('musicChartsVotedText').style.display = 'block';
}

function showMusicChartsErrorbox(error){
	document.getElementById('musicChartsErrortext').innerHTML = error;
	document.getElementById('lightbox_music_charts').style.opacity = '0.2';
	document.getElementById('lightbox_music_charts').style.filter = 'alpha(opacity=20)';
	document.getElementById('musicChartsErrorbox').style.display = 'block';
}

function hideMusicChartsErrorbox(){
	document.getElementById('lightbox_music_charts').style.opacity = '1';
	document.getElementById('lightbox_music_charts').style.filter = 'alpha(opacity=100)';
	document.getElementById('musicChartsErrorbox').style.display = 'none';
}