// form; check for mandatory fields
// 2006. 3. 19. fixed by QUDO according to http://jira.magnolia.info/browse/MAGNOLIA-242
// 2006. 3. 19. email-check by QUDO

function checkMandatories(formName,alertText)
{
	var theForm=document[formName];
	var m=theForm.mgnlMandatory;
	var i=0;
	var ok=true;
	var email_ok=true;
	if (m)
	{	
		if (!m[0])
		{
			var tmp=m;
			m=new Object();
			m[0]=tmp;
		}
		while (m[i])
		{
			var name=m[i].value;
            		var type;

			var mgnlField;
			if(document.all) mgnlField=theForm(name);
			else mgnlField=theForm[name];
			//if (theForm[name].type) type=theForm[name].type;
            		//else if (theForm[name][0] && theForm[name][0].type) type=theForm[name][0].type

			if (mgnlField.type) type=mgnlField.type;
			else if (mgnlField[0] && mgnlField[0].type) type=mgnlField[0].type

			switch (type)
			{
				case "select-one":
					//if (theForm[name].selectedIndex==0) ok=false;
					if (mgnlField.selectedIndex==0) ok=false;
					
					break;
                		case "checkbox":
                		case "radio":
                    			var obj=new Object();
                    			//if (!theForm[name][0]) obj[0]=theForm[name];
                    			//else obj=theForm[name];

					if (!mgnlField[0]) obj[0]=mgnlField;
					else obj=mgnlField;

					var okSmall=false;
                    			var ii=0;
                    			while (obj[ii])
                        		{
                        			if (obj[ii].checked)
                            			{
                            				okSmall=true;
                            				break;
                            			}
                        			ii++;
                        		}
                    			if (!okSmall) ok=false;
                    			break;
				default:
					//if (!theForm[name].value) ok=false;
					if (mgnlField.name == '011') 
					{
						var at_pos = mgnlField.value.lastIndexOf('@');
						var dot_pos = mgnlField.value.lastIndexOf('.');
						if (at_pos <= 0) email_ok=false;
						if (dot_pos <= 0) email_ok=false;
						if (at_pos > dot_pos) email_ok=false;
					} else {
						if (!mgnlField.value) ok=false;
					}
			}
			if (!ok)
			{
				while (alertText.indexOf("<br>")!=-1)
				{
					alertText=alertText.replace("<br>","\n");
				}
				alert(alertText);
				//if (!theForm[name][0]) theForm[name].focus();
				if (!mgnlField[0]) mgnlField.focus();
				
				return false;
			}
			if (!email_ok)
			{
				alert("Please enter a valid email address.");
				if (!mgnlField[0]) mgnlField.focus();
				
				return false;
			}
			i++;
		}
	}
	//if (ok)	theForm.submit();
	if (ok && email_ok) return true;
	else return false;
}


function hidestatus()
{
	window.status=''
	return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus