fwexec = new Object;

fwexec.scrapePage = function()
{
	fwexec.invalidInputs = new Array;
	fwexec.showInvalidError = false;
	fwexec.vars = "";
	fwexec.files = new Array;
	l = 0;
	if(!document.getElementById('appCont'))
		return;
		
	tagsToProcess = new Array("input","select","textarea");
	fwexec.invalidCounter = 0;
	fwexec.showInvalidError = false;
	
	for(tag in tagsToProcess)
	{
		allTags = document.getElementById('appCont').getElementsByTagName(tagsToProcess[tag]);
		for(i=0;i<allTags.length;i++)
			fwexec.getEleVals(allTags[i]);
	}
	//take off the last delimiter
	fwexec.vars = fwexec.vars.substr(0,fwexec.vars.length-bofDlimiter.length)
	return fwexec.vars;
	
}

fwexec.getEleVals = function (ele)
{
	switch(ele.type)
	{			
		case "text" : case "textarea" :
			fwexec.vars += ele.name+eqlsDlimiter+ele.value;
		break;		
	
		case "select" : case "select-one":
			if(ele.selectedIndex >= 0 )
				fwexec.vars += ele.name+eqlsDlimiter+ele.options[ele.selectedIndex].value;
		break;
		
		case "select-multiple" :
			if(ele.options.length - ele.selectedIndex > 1)
			{
				fwexec.vars += "SELECT_ARRAY"+ele.name;
				fwexec.vars += eqlsDlimiter;	
				for(m=0;m < ele.options.length;m++)
				{
					if(ele.options[m].selected)
						fwexec.vars += "<s=s>"+ele.options[m].value+"<v=v>"+ele.options[m].innerHTML;
				}
			}
			else
			{
				fwexec.vars += ele.name+eqlsDlimiter+ele.value;
			}
		break;
		
		case "checkbox" :
			if(ele.checked == true)
			{
				fwexec.vars += 'FW_CHECKBOX'+ele.name+eqlsDlimiter+ele.value;
			}
			else
			{
				fwexec.vars += 'FW_NOCHECKBOX'+ele.name+eqlsDlimiter+ele.value;
			}
		break;
		
		case "radio" :
			if (ele.checked == true)
			{
				fwexec.vars += ele.name+eqlsDlimiter+ele.value;
			}
		break;
		
		case "file" :
			fwexec.files[fwexec.files.length+1] = ele.id;
		break;		
					
		default :
			fwexec.vars += ele.name+eqlsDlimiter+ele.value;
		break;
	}
	
	if(ele.title == "_invalid" || (ele.alt == "mandatory" && ele.value == ""))
	{
		fwexec.invalidInputs[fwexec.invalidCounter] = ele.id;
		fwexec.invalidCounter++;
		fwexec.showInvalidError = true;
	}
	
	fwexec.vars += bofDlimiter;	
}

document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

//for running an applocation control state via ajax
function fwExecAjax(param1,param2,param3,param4,param5)
{
	if(!param1)
		param1 = "";
	if(!param2)
		param2 = "";
	if(!param3)
		param3 = "";
	if(!param4)
		param4 = "";
	if(!param5)
		param5 = "";
	param6 = 'ajax';
	fwExec(param1,param2,param3,param4,param5,param6)
}

function fwExecReq(scriptName,headerVars,popupId,altAction)
{	
	if(!scriptName)
		scriptName = "";
	if(!headerVars)
		headerVars = "";
	if(!popupId)
		popupId = "";
	if(!altAction)
		altAction = "";
		
	fwExec("FW_serverscript",scriptName,popupId,headerVars,"","ajax",altAction)
}

fwexec.validate = function(param1,param2,param3,param4,param5,param6)
{
	if(!param1)
		param1 = "";
	if(!param2)
		param2 = "";
	if(!param3)
		param3 = "";
	if(!param4)
		param4 = "";
	if(!param5)
		param5 = "";
	if(!param6)
		param6 = "";
	param7 = 'validate';
	fwExec(param1,param2,param3,param4,param5,param6,param7)
}

function fwExecValidate(param1,param2,param3,param4,param5,param6)
{
	if(!param1)
		param1 = "";
	if(!param2)
		param2 = "";
	if(!param3)
		param3 = "";
	if(!param4)
		param4 = "";
	if(!param5)
		param5 = "";
	if(!param6)
		param6 = "";
	param7 = 'validate';
	fwExec(param1,param2,param3,param4,param5,param6,param7)
}

function fwExecValidateAjax(param1,param2,param3,param4,param5)
{
	if(!param1)
		param1 = "";
	if(!param2)
		param2 = "";
	if(!param3)
		param3 = "";
	if(!param4)
		param4 = "";
	if(!param5)
		param5 = "";
	if(!param6)
		param6 = "";
	param6 = 'ajax';
	param7 = 'validate';
	fwExec(param1,param2,param3,param4,param5,param6,param7)
}

function fwExec(param1,param2,param3,param4,param5,param6,param7)
{	
	//if fwExecObj exists then queue up requests - override for close app requests
	if(typeof(fwExecObj) == "object" && param1 != "FW_closeapp" && param1 != "FW_reload" && param1 != "FWclose" && param1 != "FW_closefw")
	{
		if(fwExecFuncArray.length > 5)//don't process more than 5 stacked requests at a time
			return;
		fwExecFuncArray[fwExecFuncArray.length] = "fwExec('"+param1+"','"+param2+"','"+param3+"','"+param4+"','"+param5+"','"+param6+"','"+param7+"')";
	}
	else if(typeof(fwExecObj) == "string" && fwExecObj == "processNext")
	{	
		fwExecObj = new fwExecFunc(param1,param2,param3,param4,param5,param6,param7);
	}
	else
	{	
		fwExecFuncArray = new Array();
		fwExecFuncArray[0] = "fwExecObj = fwExec('"+param1+"','"+param2+"','"+param3+"','"+param4+"','"+param5+"','"+param6+"','"+param7+"')";
		fwExecObj = new fwExecFunc(param1,param2,param3,param4,param5,param6,param7);
	}
	
	if(fwExecObj.httpType != "ajax")
	{
		fwExecObj = '';
		return;
	}
	
	//handle return calls from ajax
	fwExecObj.reqobj.onreadystatechange = function()
	{
		if (fwExecObj.reqobj.readyState == 4)
		{	
			clearTimeout(fwExecObj.show_process_icon);
			if(fwExecObj.popupObj)
				closePopup(fwExecObj.popupObj.id)

			var response = fwExecObj.reqobj.responseText;
			
			//dont do anything if the script failed
			if(response.substr(0,14) == "FW_fatal_error")
			{
				alert("The request failed\nReason: Server encountered a fatal error");
				fwExecObj = '';
				clearTimeout(show_process_icon);
				return;
			}
			else if(response.substr(0,10) == "FW_exit_fw")
			{
				if(response.substr(10,11) == "closewindow")
					if(!window.close())
						window.location = "index.php";
				else	
					window.location = "index.php";
				return;
			}
			else if(response.substr(0,10) == "FW_expired")
			{
				alert("Session Expired\nYour username has been used to login on another session");
				window.location = "index.php";
				return;
			}
			
			switch(true)
			{
				
				case (document.getElementById(fwExecObj.elementId) != null):
					document.getElementById(fwExecObj.elementId).innerHTML = response;
					//check for popup
					var responseDivs = document.getElementById(fwExecObj.elementId).getElementsByTagName('div');
					if(typeof(responseDivs[0]) == "object" && responseDivs[0].title == 'popup' && responseDivs[0].style.display != "none")
						showPopup(responseDivs[0].id)
					break;
				case (fwExecObj.requestType == "FW_get_popup"):
					if(document.getElementById(fwExecObj.fwGetPopupCont))
						document.getElementById(fwExecObj.fwGetPopupCont).innerHTML = response;
					else
						document.getElementById('fwPopup').innerHTML = response;
					//launch the popup via the function
					var responseDivs = document.getElementById('fwPopup').getElementsByTagName('div');
					if(typeof(responseDivs[0]) == "object" && responseDivs[0].title == 'popup' && responseDivs[0].style.display != "none")
						showPopup(responseDivs[0].id)
					break;
			}
			
			try
			{
				//run any call back function (was getting errors here in javascript so checking for type first)

				if(typeof(fwExecObj.callbackFunc) == "string")
				{
					//now checking for a value
					if(fwExecObj.callbackFunc != "")
					{
						var funcSplit = new Array();
						//check function exists - we need to extract just the function name if the format "funcToRun(params,moreparams)" has been given
						if(fwExecObj.callbackFunc.substr(-1) == ')')
						{
							//split the function string up to get the name
							var funcSplit = fwExecObj.callbackFunc.split('(');
							var funcName = funcSplit[0];
							var funcEnd = funcSplit[1];
						}
						else
						{
							var funcName = fwExecObj.callbackFunc;		
							var funcEnd = "'')";
						}
						
						if(fwExecObj.scriptname)
							var runFunc = 'if(window.'+funcName+')'+funcName+'(fwExecObj.reqobj,"'+fwExecObj.scriptname+'",'+funcEnd;
						else
							var runFunc = 'if(window.'+funcName+')'+funcName+'(fwExecObj.reqobj)';
						try 
						{	
							eval(runFunc);
						}
						catch(e)
						{
							//document.getElementById('jsDebugOutput').innerHTML += e;
						}
					}
				}
			}
			catch(e)
			{
				//document.getElementById('jsDebugOutput').innerHTML += "<div>"+e+"</div>";
			}
	
			//execute embedded javascript code (my god this is a good bit of code..feel free to come and give me a pat on the back)
			//...Meh, it's not that good - I've seen better!!
			var regex = /<script\b.*?>([\s\S]*?)<\/script>/igm;
			var match;
			while (match = regex.exec(response))
			{
				var startInnerJs = match[0].indexOf('>')+1;
				var innerJsEnd = match[0].indexOf('</script>');				
				var innerJs = match[0].substring(startInnerJs,innerJsEnd);
				innerJs = trimAll(innerJs);
				
				try
				{
					eval(innerJs);
				}
				catch(e)
				{	
					//document.getElementById('jsDebugOutput').innerHTML += "<div>"+e+"</div>";
				}
								
				var findSrcStart = match[0].search(/src=[\'\"]/)+4;
				var findSrcEnd = match[0].indexOf('.js');
				
				if(findSrcStart > 0 && findSrcEnd > 0)
				{
					var srcScript = match[0].substring(findSrcStart,findSrcEnd);
					srcScript = srcScript.replace(/[\'\"]/,'')+'.js'; 
					var head = document.getElementsByTagName("head")[0];
					scriptObj = document.createElement('script');
					scriptObj.language = 'javascript';
					head.appendChild(scriptObj);
					scriptObj.src = srcScript;
				}
			}
			
			clearTimeout(fwExecObj.show_process_icon);
			if(document.getElementById('FWloading'))
				document.getElementById('FWloading').style.display = 'none';
			
			//process next request in the array
			if(fwExecFuncArray.length > 1)
			{
				fwExecFuncArray.shift();
				fwExecObj = "processNext";
				eval(fwExecFuncArray[0]);
			}
			else
			{	
				fwExecObj = '';
			}
		}
	}
}

function fwExecFunc(param1,param2,param3,param4,param5,param6,param7)
{
	if(param7 == 'validate')
		var validate = true;
		
	//param6 gets set to ajax if this is an ajax request
	if(!param1 || param1 == "undefined")
		param1 = "";
	//param6 gets set to ajax if this is an ajax request
	if(!param6 || param6 == "undefined")
		param6 = "";
		
	bofDlimiter = '<&>';
	eqlsDlimiter = '<=>';
	pageVars = fwexec.scrapePage();
	
	var jsFwvars = '';	
	//serialise the contents of the jsfwvars object
	for(obj in jsfwvars)
	{
		if(typeof(jsfwvars[obj]) == 'string')
			jsFwvars += '<&>'+obj+'<=>'+jsfwvars[obj];
		else if(typeof(jsfwvars[obj]) == 'object')
		{
			jsFwvars+= "<&>SELECT_ARRAY"+obj+'<=>';
			for(subobj in jsfwvars[obj])
				jsFwvars+= "<s=s>"+subobj+"<v=v>"+jsfwvars[obj][subobj];
		}
	}
	//add to the http header
	fwExecHeader ='FW_jsfwvars='+escape(jsFwvars);
	
	if(document.getElementById('FW_request_type'))
		document.getElementById('FW_request_type').value = param1;
		
	fwExecHeader += '&FW_loginsessionid='+ FW_loginsessionid;
	fwExecHeader += '&FW_sesspath='+FW_sesspath;
	if(typeof(FW_windowsessionid) != "undefined")
		fwExecHeader += '&FW_windowsessionid='+FW_windowsessionid;
	if(document.getElementById('FW_current_appid'))
		fwExecHeader += '&FW_last_applinkid='+document.getElementById('FW_current_appid').value;
		
	this.elementId = '';
	popupId = '';	
	var frameworkJsVars = '';
	showTimer = true;
	
	if(param1.substr(0,7) == "extreq:")
	{
		var extapp = param1.substr(7);
		param1 = param1.substr(0,6);
	}
	
	switch(param1)
	{
		case "FW_newmodule":
		fwExecHeader += '&FW_request_type='+param1;
		fwExecHeader += '&FW_module='+ param2;
		fwExecHeader += '&FW_output_type=modsandmaincontainer';
		var pass_values = '<&>'+pageVars +'<&>'+ param2;
		break;
		
		case "FW_app_inactive": case "FW_app_suspended":case "inactive": case "suspended":
		fwExecHeader += '&FW_request_type='+param1;
		fwExecHeader += '&FW_applinkid='+ param2;
		fwExecHeader += '&FW_output_type=maincontainer';
		this.elementId = 'maincontainer';
		popupId = "";
		var pass_values = '<&>'+pageVars +'<&>'+ param2;
		break;
				
		case "FW_closeapp":
		fwExecHeader += '&FW_request_type=FW_closeapp';
		fwExecHeader += '&FW_applinkid='+param2;
		this.elementId = 'maincontainer';
		break;
				
		case "FW_closefw": case "FW_change_coid": case "FW_change_depot" :
		fwExecHeader += '&FW_request_type='+param1;
		var pass_values = pageVars +'<&>'+ param2;
		if(!param3 || param3 == "undefined")
			this.elementId = 'fw_popup_container';
		else
			this.elementId = param3;
		break;
				
		case "FW_currentstate":
		fwExecHeader += '&FW_output_type=maincontainer';
		break;
		
		case "FW_serverscript"://for running "proper" serverscripts
		fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		fwExecHeader += '&FW_request_type='+ "FW_serverscript";
		fwExecHeader += '&serverscript='+ param2;
		fwExecHeader += '&FW_output_type=appcontents';
		var pass_values = pageVars +'<&>'+ param4;
		popupId = param3;
		this.elementId = param3;
		this.scriptname = param2;
		this.callbackFunc = param7;
		if(!param7)
			this.callbackFunc = "reqAction";
		break;
		
		case "FW_system_cmd":
		fwExecHeader += '&FW_request_type='+ "FW_system_cmd";
		fwExecHeader += '&FW_cmd_name='+ param2;
		fwExecHeader += '&FW_cmd_vars='+ escape(param3);
		if(param4)
			this.elementId = param4;
		if(param5)
			this.callbackFunc = param5;
		showTimer = false;
		break;
		
		case "FW_yeOldeReqScript":
		fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		fwExecHeader += '&FW_request_type='+ "FW_app_active";
		fwExecHeader += '&serverscript='+ param2;		
		fwExecHeader += '&FW_output_type=appcontents';
		var pass_values = pageVars +'<&>'+ param3;
		popupId = param4;
		this.callbackFunc = param5;
		this.scriptname = param2;
		break;
		
		case "FW_get_popup":
		fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		fwExecHeader += '&FW_request_type='+ "FW_app_active";
		fwExecHeader += '&FW_control_state=FW_get_popup';
		fwExecHeader += '&FW_output_type=appcontents';
		fwExecHeader += '&FW_get_popup=' + param2;
		var pass_values = pageVars +'<&>'+ param3;
		this.requestType = "FW_get_popup";
		if(param4 != "")
			this.fwGetPopupCont = param4
		break;
		
		
		case "extreq":
		fwExecHeader += '&FW_request_type='+ "extreq";
		fwExecHeader += '&FW_extapp='+ extapp;
		fwExecHeader += '&FW_control_state='+ param2;
		var pass_values = '<&>'+pageVars +'<&>'+ param3;
		fwExecHeader += '&FW_output_type=appcontents';
		if(param4)
			this.elementId = param4;
		if(param5)
			this.callbackFunc = param5;
		break;
		
		case "drilldown":
		this.elementId = param5;
		this.callbackFunc = param6;
		this.paramType = "default";
		if(document.getElementById('FW_current_appid'))
			fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		fwExecHeader += '&FW_request_type='+ "FW_drilldown";
		fwExecHeader += '&FW_drilldown_app='+ param2;
		fwExecHeader += '&FW_drilldown_control_state='+ param3;
		var pass_values = '<&>'+pageVars +'<&>'+ param4;
		fwExecHeader += '&FW_output_type=appcontents';
		break;
		
		case "shortcut":
		fwExecHeader += '&FW_request_type=FW_shortcut';
		fwExecHeader += '&FW_appshortcut='+ param2;
		fwExecHeader += '&FW_control_state='+ param3;
		fwExecHeader += '&FW_output_type=appcontents';
		if(document.getElementById('FW_current_appid'))
			fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		var pass_values = '<&>'+pageVars;		
		fwExecHeader += '&FW_new_passvalues='+escape(param4);
		break;
		
		
		default:
		this.elementId = param3;
		this.callbackFunc = param4;
		this.paramType = "default";
		if(document.getElementById('FW_current_appid'))
			fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
		fwExecHeader += '&FW_request_type='+ "FW_app_active";
		fwExecHeader += '&FW_control_state='+ param1;
		var pass_values = '<&>'+pageVars +'<&>'+ param2;
		fwExecHeader += '&FW_output_type=appcontents';
		
		break;
		
	}
	
	
	if(validate == true && fwexec.showInvalidError == true && this.paramType == "default")
	{
		//errors with inputs on the page. Output warning and break
		alert("There are invalid or incomplete mandatory fields on the page.");
		for (input in fwexec.invalidInputs)
		{
			document.getElementById(fwexec.invalidInputs[input]).style.background = 'pink';
		}
		//clear request object and return
		fwExecObj = '';
		validate = '';
		return;
	}	
	
	if(popupId)
	{
		if(document.getElementById(popupId))
		{
			this.popupObj = document.getElementById(popupId);
			var popupX = (parseInt(this.popupObj.style.width.substr(0,this.popupObj.style.width.length-2))/2)+this.popupObj.offsetLeft;
			var popupY = (parseInt(this.popupObj.style.height.substr(0,this.popupObj.style.height.length-2))/2)+this.popupObj.offsetTop;
			pass_values += "<&>"+popupId+"X<=>"+popupX;
			pass_values += "<&>"+popupId+"Y<=>"+popupY;
		}
	}
	//finshed building pass values, encode them for http transfer
	fwExecHeader += '&FW_pass_values='+escape(pass_values);	

	if(showTimer)
		this.show_process_icon = setTimeout("document.getElementById('FWloading').style.display = 'block';",3000);

	if(param6 == 'ajax')
	{
		if(document.getElementById(this.elementId))
		{
			document.getElementById(this.elementId).innerHTML = '<img alt="loading..." src="images/tmware_processing_small.gif" />';
		}
		fwExecHeader += '&FW_ajax_container='+this.elementId;
		fwExecHeader += '&FW_request_protocol='+ "ajax";
		this.httpType = "ajax";
		if (window.XMLHttpRequest)
			this.reqobj = new XMLHttpRequest();
		else if (window.ActiveXObject)
			this.reqobj = new ActiveXObject("Microsoft.XMLHTTP")
		if(!this.reqobj)
			this.reqobj = new ActiveXObject("Msxml2.XMLHTTP")
		this.reqobj.open("POST","index.php",true);
		this.reqobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.reqobj.setRequestHeader("Content-length", fwExecHeader.length);
		this.reqobj.setRequestHeader("Connection", "close");
		this.reqobj.send(fwExecHeader);
	}
	else
	{
		this.httpType = "post";
		var headerForm = document.createElement("form");
		headerForm.setAttribute("name","headerForm");
		headerForm.setAttribute("id","headerForm");
		headerForm.setAttribute("method","post");
		headerForm.setAttribute("action","index.php");
		var browser = new Browser();		
		if(browser.isIE)
		{
			headerForm.encoding =  "multipart/form-data";
		}
		else
			headerForm.setAttribute("enctype","multipart/form-data");
		fwExecHeader += '&FW_request_protocol=formpost';
		if(param1 == "detatch")
		{
			fwExecHeader += '&FW_detatched_app='+document.getElementById('FW_current_appid').value;
			window.open("","detatched_"+document.getElementById('FW_current_appid').value, "scrollbars=yes, resizable=yes, directories=no, menubar=no, status=no")
			headerForm.target = "detatched_"+document.getElementById('FW_current_appid').value;
			clearTimeout(this.show_process_icon);
		}
		var splitHeader = fwExecHeader.split("&");
		for(keyval in splitHeader)
		{
			splitKeyval = splitHeader[keyval].split("=");
			var inputEle = document.createElement("input");
    		inputEle.setAttribute("type","hidden");
    		inputEle.setAttribute("name",splitKeyval[0]);
    		inputEle.setAttribute("value",splitKeyval[1]);
    		headerForm.appendChild(inputEle);
		}
		for(fileupload in fwexec.files)
		{
			fileEle = document.getElementById(fwexec.files[fileupload]);
			headerForm.appendChild(fileEle);
		}
		
		document.body.appendChild(headerForm);
		headerForm.submit();
	}
}

unserialise_jsfwvars = function()
{
	
}


/************************************************
*	  Ye Olde controlForm for legacy apps		*
*												*
************************************************/
function controlForm(nextstate,value,value2,value3)
{
	if(!nextstate)
		nextstate = "";
	if(!value)
		value = "";
	if(!value2)
		value2 = "";
	if(!value3)
		value3 = "";
	
	if(http_action == "transfering")
	{
		setTimeout("controlFormWait('" + nextstate + "','" + value + "','" + value2 + "','" + value3 + "')",2000)
	}
    else
   		runControlForm(nextstate,value,value2,value3)
}

function controlFormWait(nextstate,value,value2,value3)
{
	if(http_action == "transfering")
	{
		var confirmValidation = confirm('Still validating Page'+'\\n'+'Click OK to try again')
    	if(confirmValidation)
    	{
			runControlForm(nextstate,value,value2,value3)
		}
    }
	else
		runControlForm(nextstate,value,value2,value3)
}

function runControlForm(param1,param2,param3,param4)
{
	//unset the global variable userClose
	userClose = false;	
	
	if(http_action == "transfering")
    {
    	var confirmValidation = confirm('Still validating Page '+http_action+'\\n'+'Click OK to try again')
    	if(confirmValidation)
    	{
    		controlForm(param1,param2,param3,param4)
    	}
    	else
    		return;
    }
	
    bofDlimiter = '<;>';
    eqlsDlimiter = '<=>';
    fwexec.scrapePage();
    
    //validate page values
    if(fwexec.showInvalidError == true && param3 == "validate")
	{
		var showInvalidVal =" ";
		for(i=0;i<fwexec.invalidInputs.length;i++)
		{
			if(document.getElementById(fwexec.invalidInputs[i]).value != "undefined")
				showInvalidVal += document.getElementById(fwexec.invalidInputs[i]).value+"\\n"
		}
		alert("There are invalid/missing values on the page\\n"+showInvalidVal);
		return;
	}
	
	//set post form vars
	document.getElementById('FW_request_type').value = param1;
	
	switch(param1)
	{
		case "FW_newmodule":
		document.getElementById('FW_module').value = param2;
		document.getElementById('FW_pass_values').value = fwexec.vars;
		break;
		
		case "inactive": case "suspended":
		document.getElementById('FW_application').value = param2;
		document.getElementById('FW_module').value = currentModule;
		document.getElementById('FW_app_parent').value = param3;
		break;
				
		case "FW_closeapp":
		document.getElementById('FW_module').value = currentModule;
		break;
				
		case "FW_currentstate":
		document.getElementById('FW_application').value = currentApp;
		document.getElementById('FW_module').value = currentModule;
		break;
				
		default:
		document.getElementById('FW_application').value = currentApp;
		document.getElementById('FW_module').value = currentModule;
		document.getElementById('FW_request_type').value = "FW_app_active";
		document.getElementById('FW_control_state').value = param1;
		document.getElementById('FW_pass_values').value = fwexec.vars+'<;>'+param2;
		break;		
	}
   	
//	if(save_dom_image == "Y")
//   		document.getElementById('dom_image').value = document.getElementById('innercontainer').innerHTML;
//    setTimeout('document.getElementById("FWloading").style.display = "block"',3000)
//    if(window.removeEventListener)
//    	window.removeEventListener('unload',setUserclose,true);
//    else 
//		window.detachEvent('unload',setUserclose,true);
//	document.getElementById('debug').innerHTML = "Control form done";
	if(document.getElementById('FW_current_appid'))
	{	
		//build a new input element
		var inputEle = document.createElement("input");
		inputEle.setAttribute("type","hidden");
		inputEle.setAttribute("name",'FW_last_applinkid');
		inputEle.setAttribute("value",document.getElementById('FW_current_appid').value);
		document.getElementById('FWcontrolForm').appendChild(inputEle);
		var inputEle = document.createElement("input");
		inputEle.setAttribute("type","hidden");
		inputEle.setAttribute("name",'FW_applinkid');
		inputEle.setAttribute("value",document.getElementById('FW_current_appid').value);
		document.getElementById('FWcontrolForm').appendChild(inputEle);
	}	
	document.FWcontrolForm.submit();
}

function reqScript(scriptName,passVals,popupID,altAction,showIcon,requestType,event,actionEle,override)
{
	
	if(!scriptName)
		scriptName = "";
	if(!passVals)
		passVals = "";
	if(!popupID)
		popupID = "";
	if(!altAction)
		altAction = "reqAction";
	if(!altAction)
		altAction = "";
	
	passVals = passVals.replace(/\&/g, "<&>")
	passVals = passVals.replace(/=/g, "<=>")
		
	//isolate real serverscripts for processing
	if(scriptName == "global_scan" || scriptName == "stkqty" || scriptName == "stock" || scriptName == "userclose" || scriptName == "prompt")
	{
		fwExecReq(scriptName,passVals,popupID,altAction,"ajax")
	}
	else //else process as an application ajax request
	{
		fwExec("FW_yeOldeReqScript",scriptName,passVals,popupID,altAction,"ajax")
	}
	
	return;
	
	
	document.FWcontrolForm.FW_controlform_vars.value = "";
	fwexec.invalidInputs = new Array();
	var l = null;
	fwexec.showInvalidError = false;
	buildHeader = "";
    	
	bofDlimiter = '&';
    eqlsDlimiter = '=';
	pageVars = fwexec.scrapePage();
	pageVars = pageVars+"&"+passVals
	
	pageVars = pageVars.replace(/\&/g, "<&>")
	pageVars = pageVars.replace(/=/g, "<=>")
	
	fwExecHeader = 'FW_loginsessionid='+ FW_loginsessionid;
    fwExecHeader += '&FW_sesspath='+FW_sesspath;
	fwExecHeader += '&FW_windowsessionid='+FW_windowsessionid;
	fwExecHeader += '&FW_request_type='+ "FW_app_active";
	fwExecHeader += '&FW_pass_values='+ escape(pageVars);
	fwExecHeader += '&FW_last_applinkid='+document.getElementById('FW_current_appid').value;
	fwExecHeader += '&FW_output_type=appcontents';
	fwExecHeader += '&FW_request_protocol='+ "ajax";
	if(document.getElementById('FW_current_appid'))
		fwExecHeader += '&FW_applinkid='+document.getElementById('FW_current_appid').value;
	
	var show_timer = "";
	if(showIcon == "Y")
		show_timer = setTimeout('document.getElementById("FWloading").style.display = "block"',3000)
	document.body.style.cursor = 'wait';
	if(document.getElementById(popupID))
	{
		var popupObj = document.getElementById(popupID);
		var popupX = (parseInt(popupObj.style.width.substr(0,popupObj.style.width.length-2))/2)+popupObj.offsetLeft;
		var popupY = (parseInt(popupObj.style.height.substr(0,popupObj.style.height.length-2))/2)+popupObj.offsetTop;
		var fwExecHeader = fwExecHeader+"<&>"+fwexec.vars+"<&>"+popupID+"X<=>"+popupX+"<&>"+popupID+"Y<=>"+popupY	
	}	
	
	if (window.XMLHttpRequest)
  		var req = new XMLHttpRequest();
  	else if (window.ActiveXObject)
		var req = new ActiveXObject("Microsoft.XMLHTTP")
	if(!requestType)
		requestType = "POST"
	req.open("POST","index.php",true);
	http_action = "transfering";
	//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", fwExecHeader.length);
	req.setRequestHeader("Connection", "close");
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.send(fwExecHeader);
	
	req.onreadystatechange = function()
	{
		if (req.readyState==4) 
		{
			http_action = "done";
			document.body.style.cursor = 'default';
			if(req.responseText != "noreturn")
			{	
				if(popupObj)
					closePopup(popupObj.id);
				if(altAction)
				{
					var buildAltAction = altAction+"(req,scriptName)";
					eval(buildAltAction);
				}
				else
					reqAction(req,scriptName);
			}
			if(show_timer != "")
			{
				clearTimeout(show_timer);
			}
			if(document.getElementById("FWloading"))
				document.getElementById("FWloading").style.display = "none";
			if(actionEle)
				document.getElementById("FWloading").innerHTML = req.responseText;
		}		
	}
}
