var param = ['_comosoCommentFormName', '_comosoCommentFormUrl', '_comosoCommentFormEmail', '_comosoCommentFormComment'];
var paramStatus = [true, true, true, true];	// true:エラー表示されていない、false:エラー表示されている

function exec(action)
{
	var error = false;
	
	for (var i = 0; i < param.length; i++)
	{
		// 必須入力項目が存在する場合
		if (document.getElementsByName(param[i])[0])
		{
			// その項目が入力されているかを確認、されていない場合…
			if (document.getElementsByName(param[i])[0].value == '')
			{
				// エラー表示されていないのであれば、エラー表示する
				if (paramStatus[i])
				{
					mustInput(param[i]);
					paramStatus[i] = false;
				}
				
				error = true;
			}
			// その項目が入力されている場合…
			else
			{
				// その項目に関して入力エラーが表示されている場合は、それを消去
				var errorMsg = document.getElementById(param[i].replace(/_/, '')+'_error');
				
				if (errorMsg)
				{
					var parent = errorMsg.parentNode;
					parent.removeChild(errorMsg);
					paramStatus[i] = true;
				}
			}
		}
	}
	
	// 入力エラーがなければsubmit
	if (!error)
	{
		document.getElementById('comosoCommentForm').action = action;
		document.getElementById('comosoCommentForm').submit();
	}
}

function mustInput(param)
{
	param = param.replace(/_/, '');
	
	var p = document.createElement('p');
	p.setAttribute('id', param+'_error');
	p.style.cssText = 'color:#aa0000;font-weight:bold;';			// ie用
	p.setAttribute('style', 'color:#aa0000;font-weight:bold;');		// firefox用
	
	var node = document.createTextNode('※入力エラーです');
	p.appendChild(node);
	
	var obj = document.getElementById(param);
	DOMNodeInsertAfter(p, obj);
}

function DOMNodeInsertAfter(newChild, refChild)
//Post condition: if childNodes[n] is refChild, than childNodes[n+1] is newChild.
{
	var parent = refChild.parentNode;
	
	if (parent.lastChild == refChild)
	{
		return parent.appendChild(newChild);
	}
	else
	{
		return parent.insertBefore(newChild, refChild.nextSibling);
	}
}
