// JavaScript Document
function VoteForIt() {
	this.vote = "";
	this.type = "";
	this.id = 0;
	
	createConnection = function()
	{
		var xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}

		return xmlhttp;
	}
	
	this.check = function() {
		if(this.id > 0 && (this.vote == "yes" || this.vote == "no") && (this.type == "preview" || this.type == "review" || this.type == "blog" || this.type == "feature"))
			return true;
		else
			alert("Something went wrong while you were trying to vote!");
			
		return false;
	}
	
	this.submit = function(){
		connection.open('post','/_ajax/_vote.php');
		connection.onreadystatechange = getResponse;
		connection.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		connection.send('Vote=' + this.vote + '&Target=' + this.id + '&Type=' + this.type);
	}
	
	getResponse = function() {}
	
	connection = createConnection();
}

function Vote(div, id, type, choice) {
	var vote = new VoteForIt();
	vote.id = id;
	vote.type = type;
	vote.vote = choice;
	
	if(vote.check()) {
		vote.submit();
		document.getElementById(div).innerHTML = '<img src="/_nhg/base/im/thanks.png" />';
	}
		
}