//
// FORM内の全コントロール値をJSON化する
//
function phpsus_make_params(id, cmd)
{
	var j = {};
	var str = 'frm input,frm textarea,frm select';
	j$(str.replace(/frm/g, id)).each(
		function(i)
		{
			if (this.type.match(/(radio|checkbox)/))
			{
				if (this.checked) j[this.name] = this.value;
			}
			else if (this.name.match(/^cmd\-/))
			{
				if (cmd)
				{
					if (("cmd-" + cmd) == this.name) j[this.name] = 1;
				}
				else
				{
					j[this.name] = this.value;
				}
			}
			else
			{
				j[this.name] = this.value;
			}
		}
	);
	return j;
}

//
// FORMデータをPOSTする
//
function phpsus_post(id, cmd, successFunc, errorFunc, ret)
{
	var d = phpsus_make_params(id, cmd);
	j$.post(
		location.href,
		d,
		function (ret)
		{
			if (ret.status == "SUCCESS")
			{
				if (successFunc)
				{
					successFunc();
				}
				else
				{
					location.href = location.href;
				}
			}
			else
			{
				if (errorFunc)
				{
					errorFunc();
				}
				else
				{
					alert(ret.msg);
				}
			}
		},
		"json"
	);
	return (ret) ? ret : false;
}

