//
//	This function will set the values of data in the HWOS web page to
//	the appropriate field, listbox, dropdown...
//	c contains a variable that describe what call was made along with
//  array of row(s) of data.
//
var JObj, s;

function doResponse(resp){
	var f, b, t, module;
	rsp = resp;
	// Check to make sure we are not passing back raw data to fill
	// containers or divs we are not using the retuned action right now.
	f = rsp.search('"html":"get"');
	if (f != -1) {
		var e = rsp.indexOf("}",f);
		// The JSON format is stripped out
		json = rsp.substring(0, e+1);
//alert(json);
		if (isobj("debugtxt")) {
			appendtext("debugtxt",json);
		}
		try {
			eval('var bf = ' + json);
		}catch(err) {
//			JObj.json=json;
			alert("Error with JSON page!");
			return;
		}
		// The html follows the JSON format
		bf.html=rsp.substring(e+1);
//alert(bf.html);
		if (bf.css) load_css(bf.css);
		if (bf.js) {
 			SysLoad(bf.js, bf);
			return;
		}
	}else{
    	//Find the module and action in the JSON
    	b = rsp.substring(rsp.search("{\"module\":"));
    	b=trim(b); //trim
    	if (b.length == 0) return;
    	if (isobj("debugtxt")) {
    		appendtext("debugtxt",b);
    	}
    	try {
    		eval('var bf = ' + b);
    	}catch(err) {
//    		alert("Error with page!");
            alert(resp);
    		return;
    	}
    }
	continue_rsp(bf);
}

function continue_rsp(buf){

	var newFnc;
	if (buf.msgtyp) {
		if (buf.msgtyp == "x") {
			//Severe system error, stop and eXit the system
//			kill_timer();
			show_err(buf.msgtxt,buf.msgid);
		}
	}
	if (buf.module == "") return;
	// Let's setup the function call to the appropriate JS function and pass the buffer to it as a parm
	if (buf.module == "psd") {
		newFnc = new psd(buf);
	}else {
		alert("Missing response function call in response.js for " + buf.module);
		return;
	}
	if (!newFnc) return;
	var fnc= "newFnc." + buf.action;
	if (eval('typeof ' + fnc) == 'function') {
		eval(fnc+'()');
	}else{
		alert("Missing function " + buf.action + " in "+buf.module+".js!");
	}
	return;
}

