var xmlHttp;
function createXMLHttpRequest() 
 {
    if (window.ActiveXObject) 
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) 
    {
        xmlHttp = new XMLHttpRequest();
    }
}

var myid;
function reportBroken(record_id,record_url,link_id)
{
 var submitURL = ''
 + '/ReportBL.php?'
 + 'id='   + record_id
 + '&url=' + record_url ;
 
 myid = link_id;
 isRatingsBarChanged = true;
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = handleReportBLStateChange;
  xmlHttp.open("GET", submitURL, true);
  xmlHttp.send(null);
}

function handleReportBLStateChange() {
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			document.getElementById(myid).href	= '#';
			document.getElementById(myid).innerHTML	= 'thank you';

//			alert("Thank you for reporting");
//		} else {
//			alert("Error in AJAX "+xmlHttp.status);
		}
	}
	return true;
}

function RateTab(id,title,hash,vote)
{
 if( document.getElementById('startitle').innerHTML == 'Thank you for voting' ) { return false; }
 var submitURL = ''
 + '/Rating.php?'
 + 'i='  + id
 + '&n=' + title
 + '&h=' + hash
 + '&v=' + vote ;
 
 isRatingsBarChanged = true;
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = handleVoteStateChange;
  xmlHttp.open("GET", submitURL, true);
  xmlHttp.send(null);
}

function handleVoteStateChange() {
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			var star1 = document.getElementById('star1');
			star1.href = '#'; star1.onclick = '';
				star1.onmouseover = ''; star1.onmouseout = '';

			var star2 = document.getElementById('star2');
			star2.href = '#'; star2.onclick = '';
				star2.onmouseover = ''; star2.onmouseout = '';

			var star3 = document.getElementById('star3');
			star3.href = '#'; star3.onclick = '';
				star3.onmouseover = ''; star3.onmouseout = '';

			var star4 = document.getElementById('star4');
			star4.href = '#'; star4.onclick = '';
				star4.onmouseover = ''; star4.onmouseout = '';

			var star5 = document.getElementById('star5');
			star5.href = '#'; star5.onclick = '';
				star5.onmouseover = ''; star5.onmouseout = '';

			document.getElementById('startitle').innerHTML = "Thank you for voting";
			toggleStarTitle('Thank you for voting');
//			alert("Thank you for voting");
//		} else {
//			alert("Error in AJAX "+xmlHttp.status);
		}
	}
}

var blockid;
function votePoll(record_id,vote,block_id)
{
 var submitURL = ''
 + '/Poll.php?'
 + 'id='   + record_id
 + '&vote=' + record_url ;

 blockid = block_id; 
 isRatingsBarChanged = true;
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = handlePollStateChange;
  xmlHttp.open("GET", submitURL, true);
  xmlHttp.send(null);
}

function handlePollStateChange() {
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			document.getElementById(blockid).innerHTML	= 'Thank you for voting';

//			alert("Thank you for reporting");
//		} else {
//			alert("Error in AJAX "+xmlHttp.status);
		}
	}
	return true;
}
