if (REQUIRE_ONCE == null)
{
	var REQUIRE_ONCE = true;

	var wrestMsg = "";
	var wrestFld = null;
	var wrestFldDefaultColor = "#F6F6F6"; 
	var wrestFldBackColor = "#F4F2E0"; 
	var arrAttr  = new Array ("required", "trim", "minlength", "email", "nospace", "numeric", "alpha", "alphanumeric", "jumin", "saupja");

	function wrestItemname(fld)
	{
		var itemname = fld.getAttribute("itemname");
		if (itemname != null && itemname != "")
			return itemname;
		else
			return fld.name;
	}

	function wrestTrim(fld) 
	{
		var pattern = /(^\s*)|(\s*$)/g;
		fld.value = fld.value.replace(pattern, "");
		return fld.value;
	}

	function wrestRequired(fld)
	{
		if (wrestTrim(fld) == "")
		{
			if (wrestFld == null)
			{
				wrestMsg = wrestItemname(fld) + " : essentiality "+(fld.type=="select-one"?"select":"input")+" is.\n";
				wrestFld = fld;
			}
		}
	}

	function wrestMinlength(fld)
	{
		var len = fld.getAttribute("minlength");
		if (fld.value.length < len)
		{
			if (wrestFld == null)
			{
				wrestMsg = wrestItemname(fld) + " :  min " + len + "input.\n";
				wrestFld = fld;
			}
		}
	}

	function wrestEmail(fld) 
	{
		if (!wrestTrim(fld)) return;

		var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
		if (!pattern.test(fld.value))
		{
			if (wrestFld == null)
			{
				wrestMsg = wrestItemname(fld) + " : not email\n";
				wrestFld = fld;
			}
		}
	}

	function wrestNumeric(fld) 
	{ 
		if (fld.value.length > 0)
		{ 
			for (i = 0; i < fld.value.length; i++)
			{ 
				if (fld.value.charAt(i) < '0' || fld.value.charAt(i) > '9')
				{ 
					wrestMsg = wrestItemname(fld) + " : not number\n"; 
					wrestFld = fld; 
				}
			}
		}
	}

	function wrestAlpha(fld) 
	{ 
		if (!wrestTrim(fld)) return; 

		var pattern = /(^[a-zA-Z]+$)/; 
		if (!pattern.test(fld.value))
		{ 
			if (wrestFld == null)
			{ 
				wrestMsg = wrestItemname(fld) + " : not english\n"; 
				wrestFld = fld; 
			} 
		} 
	} 

	function wrestAlphaNumeric(fld) 
	{ 
		if (!wrestTrim(fld)) return; 
		var pattern = /(^[a-zA-Z0-9]+$)/; 
		if (!pattern.test(fld.value))
		{ 
			if (wrestFld == null)
			{ 
				wrestMsg = wrestItemname(fld) + " : not english or number\n"; 
				wrestFld = fld; 
			} 
		} 
	} 

	function wrestJumin(fld) 
	{ 
		if (!wrestTrim(fld)) return; 
		var pattern = /(^[0-9]{13}$)/; 
		if (!pattern.test(fld.value))
		{ 
			if (wrestFld == null)
			{ 
				wrestMsg = wrestItemname(fld) + " : jumin 13\n"; 
				wrestFld = fld; 
			} 
		}
		else
		{
			var sum_1 = 0;
			var sum_2 = 0;
			var at=0;
			var juminno= fld.value;
			sum_1 = (juminno.charAt(0)*2)+
					  (juminno.charAt(1)*3)+
					  (juminno.charAt(2)*4)+
					  (juminno.charAt(3)*5)+
					  (juminno.charAt(4)*6)+
					  (juminno.charAt(5)*7)+
					  (juminno.charAt(6)*8)+
					  (juminno.charAt(7)*9)+
					  (juminno.charAt(8)*2)+
					  (juminno.charAt(9)*3)+
					  (juminno.charAt(10)*4)+
					  (juminno.charAt(11)*5);
			sum_2=sum_1 % 11;
         
			if (sum_2 == 0)
			{
				at = 10;
			}
			else
			{
				if (sum_2 == 1) 
					at = 11;
				else 
					at = sum_2;
			}

			att = 11 - at;
			if (juminno.charAt(12) != att || 
				 juminno.substr(2,2) < '01' ||
				 juminno.substr(2,2) > '12' ||
				 juminno.substr(4,2) < '01' ||
				 juminno.substr(4,2) > '31' ||
				 juminno.charAt(6) > 4)
			{
				wrestMsg = wrestItemname(fld) + " : not jumin\n"; 
				wrestFld = fld; 
			}
		}
	} 


    function wrestNospace(fld)
    {
        var pattern = /(\s)/g;
        if (pattern.test(fld.value))
		  {
            if (wrestFld == null)
				{
                wrestMsg = wrestItemname(fld) + " : space not\n";
                wrestFld = fld;
            }
        }
    }

    function wrestSubmit()
    {
        wrestMsg = "";
        wrestFld = null;

        var attr = null;

        for (var i = 0; i < this.elements.length; i++)
		  {
            if (this.elements[i].type == "text" || 
                this.elements[i].type == "file" || 
                this.elements[i].type == "password" ||
                this.elements[i].type == "textarea")
				{
                for (var j = 0; j < arrAttr.length; j++)
					 {
                    if (this.elements[i].getAttribute(arrAttr[j]) != null)
						  {
                        if (this.elements[i].getAttribute("required") != null)
								{
                            this.elements[i].style.backgroundColor = wrestFldDefaultColor;
                        }
                        switch (arrAttr[j])
								{
                            case "required"     : wrestRequired(this.elements[i]); break;
                            case "trim"         : wrestRequired(this.elements[i]); break;
                            case "minlength"    : wrestMinlength(this.elements[i]); break;
                            case "email"        : wrestEmail(this.elements[i]); break;
                            case "nospace"      : wrestNospace(this.elements[i]); break;
                            case "numeric"      : wrestNumeric(this.elements[i]); break; 
                            case "alpha"        : wrestAlpha(this.elements[i]); break; 
                            case "alphanumeric" : wrestAlphaNumeric(this.elements[i]); break; 
                            case "jumin"        : wrestJumin(this.elements[i]); break; 
                            case "saupja"       : wrestSaupja(this.elements[i]); break; 
                            default : break;
                        }
                    }
                }
            }
        }

        if (wrestFld != null)
		  {
            alert(wrestMsg);
            wrestFld.style.backgroundColor = wrestFldBackColor;
            wrestFld.focus();
            return false;
        }

        if (this.oldsubmit && this.oldsubmit() == false)
		  {
            return false;
        }

        return true;
    }

    function wrestInitialized()
    {
        for (var i = 0; i < document.forms.length; i++)
		  {
            if (document.forms[i].onsubmit) document.forms[i].oldsubmit = document.forms[i].onsubmit;
            document.forms[i].onsubmit = wrestSubmit;
            for (var j = 0; j < document.forms[i].elements.length; j++)
				{
                if (document.forms[i].elements[j].getAttribute("required") != null)
					 {
                    document.forms[i].elements[j].style.backgroundColor = wrestFldDefaultColor;
                }
            }
        }
    }

    wrestInitialized();
}
