function showProperties(obj) {
	var s = "";
	for (var property in obj) {
		s += property + " ";
	}	
	alert(s);

}

// Returns an XMLHTTPObject
// Returns false on an error
function getXMLHTTPObject() {
	var xmlhttp=false;
  try {
    xmlhttp = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        xmlhttp = false;
      }
    }
  }
  
  //showProperties(xmlhttp);

  if (!xmlhttp) alert("Error initializing XMLHttpRequest!");
  return xmlhttp;
}

function vote(emoface, emotype, score, url) {
	var xmlhttp = getXMLHTTPObject();
	try {
		if (xmlhttp != false) {
			document.getElementById('e' + emoface).innerHTML = 'Processing vote';
			xmlhttp.open("POST", url + "/inc/vote.php",true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//alert("emoface=" + emoface + "&emotype=" + emotype + "&score=" + score);
			xmlhttp.send("emoface=" + emoface + "&emotype=" + emotype + "&score=" + score);
			xmlhttp.onreadystatechange=function() {
				switch(xmlhttp.readyState) {
					case 1: // open
						window.status = 'Opening connection';
					break;
					case 2: // sent
						window.status = 'Sending vote';
					break;
					case 3: // receiving
						window.status = 'Receive reply';
					break;
					case 4: // loaded
						window.status = 'Done';

						document.getElementById('e' + emoface).innerHTML = xmlhttp.responseText;
					break;
				}
			}
			/*** Track Event ***/
			switch(emotype) {
				case 1: te_et = 'Emoticon'; break;
				case 2: te_et = 'Buddy Icon'; break;
				case 3: te_et = 'Smile'; break;
			}
			pageTracker._trackEvent('Voting', te_et + ' vote', emoface, score);
			/*** End Track Event ***/
		}
	} catch (error) {
		document.location.href = url + "/inc/vote.php?emoface=" + emoface + "&emotype=" + emotype + "&score=" + score + "&url=" + document.location.href
	}
}

function getRadioValue(radioButton) {
	for (var i=0; i < radioButton.length; i++) {
		if (radioButton[i].checked) {
			return radioButton[i].value;
		}
	}
	return null;
}

function trim(str) {
	return str.replace(/^\s*|\s*$/g,"");
}
