/*
 * ScienceActive's interface to oz.
 *
 * This script was created by Hervé Soulard(Herve.Soulard@sienceactive.com)
 * Copyright 2007
 * 
 * Version: 1.0
 * Created: 2007-07-05	First working version
 *
 * Requires: pip_book.js
 */

/**
 *
 */
function browser_addElement(eleHTML) {
	var co = document.getElementById("browser-content");
	if (co != null) {
		var newEle = document.createElement("div");
		co.appendChild(newEle);
		newEle.innerHTML = eleHTML;
	}
}

/**
 *
 */
function browser_replaceElement(ele, eleHTML) {
	var co = document.getElementById(ele);
	if (co != null) {
		
		var nn = document.createElement("div");
		nn.innerHTML = eleHTML;
		
		var parent = co.parentNode;
		parent.replaceChild(nn.firstChild, co);
	}
}

/**
 * From Yves Jaradin.
 */
function ask_browse(ele) {
	var opi = document.getElementById("opiApplet");
	if (opi != null) {
		opi.askBrowse(ele);
	}
}
/* End YJ */

/**
 *
 */
function browser_clear() {
	var co = document.getElementById("browser-content");
	if (co != null) {
		co.innerHTML = "<div></div>";
	}
}

/**
 *
 */
function console_clear() {
	var co = document.getElementById("console-content");
	if (co != null) {
		co.innerHTML = "<div></div>";
	}
}


/**
 *
 */
function browser_stdout(text) {
	var stdout = document.getElementById("console-content");
	if (stdout != null) {
		switchToConsole();
		stdout.innerHTML += "<pre>" + text + "</pre>";
	}
}

/**
 *
 */
function browser_stderr(text) {
	var stderr = document.getElementById("console-content");
	if (stderr != null) {
		switchToConsole();
		stderr.innerHTML += "<pre>" + text + "</pre>";
	}
}

/**
 *
 */
function browser_openFile(codeStr) {
	
	if (codeStr == null) {
		return;
	}
	
	var code = document.getElementById("codeEntry");
	if (code == null) {
		return;
	}
	
	switchToBrowser();
	code.value = codeStr;
}

