/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/
var override;
var condition = "";

function overrideSet(override, condition){
	this.override = override;
	this.condition = condition;
}

function vlabSet(vlab){
	this.vlab = vlab;
}

function show(status){
	if(status == "old"){
		document.getElementById('old').style.display = "";
	}else{
		this.id = "";
		document.getElementById('old').style.display = "none";
	}
}

function check(exp, cond){
	var status = "start";
	var id = "";
	this.condition = cond;
	if(document.getElementById('newRadio').checked){
		status = "new";
	}else if(document.getElementById('oldRadio').checked){
		status = "old";
		id = document.getElementById("oldid").value;
	}
	submit(status, id, exp);
}

function submit(status, id, exp){
	var extra = '';
	if(this.override == "1"){
		extra = "&override=true&condition=" + condition;

	}

	if(!(this.vlab=="")){
		extra+= "&vlab="+this.vlab;
	}
	ajax("./controllers/introController.php","experiment=" + exp + "&status=" + status + "&id=" + id + extra, updateInterface);
}

function updateInterface(data){
	document.getElementById('announceContent').innerHTML = data;
}

function ajax(url, vars, callbackFunction) {

  var request =  new XMLHttpRequest();
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                          "application/x-www-form-urlencoded");
 
  request.onreadystatechange = function() {
    var done = 4, ok = 200;
    if (request.readyState == done && request.status == ok) {
      if (request.responseText) {
        callbackFunction(request.responseText);
      }
    }
	if(request.readyState == done && request.status == 404){
		window.location = "./fail.html";
	}
  };
  request.send(vars);
}
