
function dataService() {
};
dataService.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModes = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModes.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModes[i]);
				success = true;
			} catch (e) {
			
			}
		}
		if ( !success ) {
		
			return false;
		}
		return true;
	}
}

dataService.prototype.ocupado = function() {
	stateActual = this._xh.readyState;
	return (stateActual && (stateActual < 4));
}

dataService.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

dataService.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		
	}
	return false;
}



function _gr(reqseccion,divcont) {
	remote = new dataService;
	nt = remote.enviar(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}




var urlBase = "videoRating.php?";


function rateVideo(rating,videoId)  {
		remote = new dataService;
		nt = remote.enviar('videoRating.php?rating='+rating+'&videoId='+videoId);
		originalRating = rating;
		currentRating = document.getElementById('current-rating').style.width;
	
		newRatingWidth = rating * 17;
		currentRating = parseInt(currentRating);
		newRatingWidth = parseInt(newRatingWidth);
		newRatingWidth = newRatingWidth + currentRating;
		if (currentRating !== 0) {
		newRatingWidth = newRatingWidth/2;
		}
		document.getElementById('current-rating').style.width = newRatingWidth+'px';
		//document.getElementById('rating-test-div').style.background = "red";
		//document.getElementById('yourRating').innerHTML = "<font style='color:#fff;font-weight:bold'>Current rating is"+currentRating+"NewRating width is"+newRatingWidth+" </font>";
		document.getElementById('yourRating').innerHTML = "<div><strong>Vote registered.</strong> You voted "+originalRating+"/5 </div>";
             
}
