star_x = "";  // variable that holds the star rating

// our generic AJAX script
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
	  xmlhttp = new XMLHttpRequest();
	} catch (e) {
	  xmlhttp = false;
	}
  }
  return xmlhttp;
}
var http = getHTTPObject(); // Create the HTTP Object


// when user clicks a star we set the star variable
function star(x){
  document.getElementById(x).src='../star_hover.gif';
  if(star_x != "") document.getElementById(star_x).src='http://freepornsite.tv/images/star2.gif';
	if(star_x == x) star_x="";
	else star_x = x;
  rate_it('http://www.freepornsite.tv/process/rate.php',x,'msg(req.responseText);');
}
// onmouseover event .. kill all stars if rated and update the source on the rest of the stars
function stars(x){
  killem();
  switch(x){
	case 5:
	  document.getElementById('e').src='http://freepornsite.tv/images/star.gif';
	case 4:
	  document.getElementById('d').src='http://freepornsite.tv/images/star.gif';
	case 3:
	  document.getElementById('c').src='http://freepornsite.tv/images/star.gif';
	case 2:
	  document.getElementById('b').src='http://freepornsite.tv/images/star.gif';
	case 1:
	  document.getElementById('a').src='http://freepornsite.tv/images/star.gif';
	  break;
  }
}
// kills all the stars sources
function killem(){
  document.getElementById('a').src='http://freepornsite.tv/images/star2.gif';
  document.getElementById('b').src='http://freepornsite.tv/images/star2.gif';
  document.getElementById('c').src='http://freepornsite.tv/images/star2.gif';
  document.getElementById('d').src='http://freepornsite.tv/images/star2.gif';
  document.getElementById('e').src='http://freepornsite.tv/images/star2.gif';
}

// onmouseout event that similarily kills the source
function starsx(x){
  switch(x){
	case 5:
	  if(star_x != 'e') document.getElementById('e').src='http://freepornsite.tv/images/star2.gif';
	case 4:
	  if(star_x != 'd') document.getElementById('d').src='http://freepornsite.tv/images/star2.gif';
	case 3:
	  if(star_x != 'c') document.getElementById('c').src='http://freepornsite.tv/images/star2.gif';
	case 2:
	  if(star_x != 'b') document.getElementById('b').src='http://freepornsite.tv/images/star2.gif';
	case 1:
	  if(star_x != 'a') document.getElementById('a').src='http://freepornsite.tv/images/star2.gif';
	  break;
  }
  switch(star_x){
	case 'e':
	  stars(5);
	  break;
	case 'd':
	  stars(4);
	  break;
	case 'c':
	  stars(3);
	  break;
	case 'b':
	  stars(2);
	  break;
	case 'a':
	  stars(1);
	  break;
  }

}




// SAVE USER RATING

function rate_it(url,x, what)
{				
	var video_id = document.getElementById('videoid').value;
	var url = url;
	var x = x;
	DoCallback("id="+video_id+"&rated="+x, url, what);
}

          
function DoCallback(data, url, what)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();		
		//alert(processReqChange(what));
        req.onreadystatechange = function(){processReqChange(what)}
        req.open('POST', url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.send(data);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject('Microsoft.XMLHTTP')
        if (req) {
            req.onreadystatechange = function(){processReqChange(what)}
            req.open('POST', url, true);
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            req.send(data);
        }
    }
}


function processReqChange(what) {	
    // only if req shows 'loaded'
    if (req.readyState == 4) {
        // only if 'OK'
        if (req.status == 200) {
            eval(what);
        } else {
            alert('There was a problem retrieving the XML data: ' +
                req.responseText);
        }
    }
}

function msg(strRet){
	alert(strRet);
}
			  