function initAjax()
{
	//function to create and return a XMPHTTP object
	var ajaxRequest; 
    ajaxRequest = false;
    try
    {
        // create Opera 8.0+/Firefox/Safari XMPHTTP object
        ajaxRequest = new XMLHttpRequest();
        return ajaxRequest;
    } 
    catch (e)
    {
        // try creating IE object if above fails
        try
        {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            return ajaxRequest;
        } 
        catch (e) 
        {
            try
            {
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e)
            { 
                //browser doesn't support ajax
                return false;
            }
        }
    }
    return;
}

function hasClass(target, theClass) {
  var pattern = new RegExp("(^| )" + theClass + "( |$)");

  if (target) {
    if (pattern.test(target.className)) {
      return true;
    }
  }

  return false;
}

function addClass(target, theClass) {
  if (!hasClass(target, theClass)) {
    if (target.className == "") {
      target.className = theClass;
    } else {
      target.className += " " + theClass;
    }
  }
}

function removeClass(target, theClass) {
  var pattern = new RegExp("(^| )" + theClass + "( |$)");

  target.className = target.className.replace(pattern, "$1");
  target.className = target.className.replace(/ $/, "");
}


function getVoteFn(obj) {
  do {
    obj = obj.parentNode;
  } while (!hasClass(obj, "voteBtn"));

  return obj;
}

function VideoVote(theLink, theID) {
  if (!hasClass(theLink, "voteBtn thanks")) {
    var url = "/videos/competition/votevideo.php?VideoID=" + theID;
    $.get(url, function(data){
	    if ( data == "SUCCESS" ) {
		     removeClass(theLink, "voteBtn vote");
		     addClass(theLink, "voteBtn thanks");
		     alert("Thanks for your Vote");
	    }
		});
  }
  return false;
} 
