/*
 * Run the Python code
 * DZ 4/7/2010
 */
function runPythonCode(str){
    if (str.length==0){
      document.getElementById("pythonOutput").innerHTML="";
      return;
    }

    xmlhttp=GetXmlHttpObject();
    if (xmlhttp == null){
      alert ("Your browser does not support XMLHTTP!");
      return;
    }
    var url = "/WebCoding/compiler.php";
    url = url + "?pythonCode=" + str;
    url = url + "&sid=" + Math.random(); // avoid the possible cache
    xmlhttp.onreadystatechange = displayPythonResult;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function displayPythonResult(){
    if (xmlhttp.readyState == 4){
        document.getElementById("pythonOutput").innerHTML = xmlhttp.responseText;
    }
}

/*
 * Validate Python code
 * DZ 3/27/2010
 */
function checkPython(code, args) { 
	// no code:
	if (trim(code) == "") {
		alert("Empty code");
		return false;
	}
	// add more cases here
	
	/* show the Python code to be run
	var answer = confirm("Run the following Python code with argument(s): " + args + "?\n" + code);
	
	if (answer) 
		return true;
	else 
		return false;
	*/
	return true;
}

