function GetXmlHttpObject(){
	var xmlHttp=null;

	try{
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}	

 	catch (e){
 		//Internet Explorer
 		try{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 
  		catch (e){
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}

function GET(url, values, state_func){
	
	xmlHttp=GetXmlHttpObject();
	xmlHttp.open("GET", url+"?"+values, true);
	xmlHttp.onreadystatechange=state_func;
	xmlHttp.send(null);
	
}

function POST(url, values, state_func){
	
	xmlHttp=GetXmlHttpObject();
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.onreadystatechange=state_func;
	xmlHttp.send(values);

}

function vote(){
	
	var num1=Math.random();
	var num2=Math.random();
	var num3=Math.random();
	
	var rand=num1*num2*num3*1000;
	
 	GET("/vote/vote.php", "ref="+window.location+"&rand="+rand, stateChanged);
 	
}

function stateChanged() { 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		
		//alert(xmlHttp.responseText);
		
		if (xmlHttp.responseText=='OK'){
			alert("Thank you for casting your vote!");
		}
		
		if(xmlHttp.responseText=='DUPLICATE'){
			alert("You may only vote for this hairstyle once per month!");
		}
		
	} 
}
