//<SCRIPT RUNAT=server LANGUAGE="JScript">   to force the colors in the development tool

var gArgs;
var gOps;

//-----------------------------------------------------------------

function submitForm(ops, nameValues, strTarget, strAlert, strEncoding, newWindow)
{
    var val = true;
	if ((typeof(strAlert) != "undefined") && (strAlert != "") && (strAlert != null)) {
		val = window.confirm(strAlert);
	}
	if (!val) return;

	//var form = (typeof(window.opener) == 'undefined') ? window.document.forms[0] : window.opener.document.forms[0];
	var form = window.document.forms[0];
	
	
	// check idf we need to set any operations to be executed on the server
	if ((typeof(ops) != "undefined") && (ops != "") && (ops != null)) {
	    gOps.UnmarshalFrom(ops);
	}
	form.elements["hdnOps"].value = gOps.Marshal();
	
	// Check if we need to fill any hidden and other form values
	if ((typeof(nameValues) != "undefined") && (nameValues != "") && (nameValues != null)) {
		gArgs.UnmarshalFrom(nameValues);
	}
	for (var key in gArgs.args) {
		if (typeof(form.elements[key]) != 'undefined') {
			form.elements[key].value = gArgs.args[key];
		}
	}
	form.elements["hdnArgs"].value = gArgs.Marshal();
	
	// Check if we need to change the target
	if (typeof(strTarget) != "undefined") {
		var strAction = form.action;
		if (strTarget.substring(0,1) == "?") { // iIf starts with ? just add it to the current target
			if (strAction.indexOf("?", 0) != -1) { // does the current terget already contains a query string
				form.action += "&" + strTarget.substr(1);
			} else
				form.action += strTarget;
		} else
			form.action = strTarget;
	}
	
	if ((typeof(strEncoding) != 'undefined') && (strEncoding != null) && (strEncoding != "")) 
	    form.encoding = strEncoding;
	    
	if ((typeof(newWindow) == 'undefined') || (newWindow == null))  {
		form.submit();
	} else {
		var win = window.open(form.action, 'dialogbox', 
		              '"' + newWindow + '"', false);
		win.focus();
		//var ret = window.showModalDialog(form.action, '', newWindow);
		//while (!win.closed);
	}
}

//----------------------------------------------------------------------

function doAfterLoad() 
{
	var form = window.document.forms[0];
	if (typeof(form) != 'undefined') {
		if (typeof(form.elements["hdnArgs"]) != 'undefined') {
			gArgs = new NameValues(form.elements["hdnArgs"].value);
			gOps  = new NameValues(form.elements["hdnOps"].value);
			var strWin = gArgs.args["NewWindow"];
			if (typeof(strWin) != "undefined")
			window.open(strWin);
		}
	}
}

window.onload = doAfterLoad;