function submitForm()
{
	if(!formInst.chkField())
		return false;
	
	return true;
}

function vlForm(frm)
{
	// members
	this.frm		= frm;
	this.cntErr		= 0;
	this.errmsg		= '';

	// structures
	this.cvalInf		= new Array();
	this.ovalInf		= new Array();

	// methods
	this.addCField		= addCField;
	this.addOField		= addOField;
	this.chkField		= chkField;
	
	this.replaceCField		= replaceCField;
}

//======================
// public methods
//======================

function chkField()
{
	var len = this.cvalInf.length;
	this.errmsg = '';
	this.cntErr = 0;
	for(i=len-1; i>=0; i--)
	{
		var field_name = this.cvalInf[i]['field_name'];
		var field = document.getElementById(field_name);
		var chktype = this.cvalInf[i]['type'];
		var label = this.cvalInf[i]['label'];
		var msg = this.cvalInf[i]['msg'];		
		
		if(label) dFlash(label, this.cvalInf[i]['color'], this.cvalInf[i]['weight']);

		if(chktype == 'TEXT_ONLY' && chkEmpty(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'TEXT_EMAIL' && !chkEMail(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'TEXT_NUMBER' && !chkNumber(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'TEXT_HELLO' && !chkHello(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'HTML_OPTION' && !(field.value > ""&&field.value!="0"))
		{
			//alert(field_name);
			//alert(document.getElementById(field_name).value+'***');
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			//field.focus();
			this.cntErr++;
		}		
	}

	len = this.ovalInf.length;
	for(i=len-1; i>=0; i--)
	{
		field = this.ovalInf[i]['field'];		
		chktype = this.ovalInf[i]['type'];
		label = this.ovalInf[i]['label'];
		msg = this.ovalInf[i]['msg'];
		
		if(label) dFlash(label, this.ovalInf[i]['color'], this.ovalInf[i]['weight']);
		if(chkEmpty(field.value, field)) continue;

		if(chktype == 'TEXT_EMAIL' && !chkEMail(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'TEXT_NUMBER' && !chkNumber(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'TEXT_HELLO' && !chkHello(field.value, field))
		{
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '\n' + this.errmsg ;
			field.focus();
			this.cntErr++;
		}
		else if(chktype == 'HTML_OPTION' && field.selectedIndex == 0)
		{
			//alert(field.value+"***");
			if(label) Flash(label);
			if(msg) this.errmsg = msg + '***\n' + this.errmsg ;
			//field.focus();
			this.cntErr++;
		}		
	}
	if(this.cntErr)
	{
		if(this.errmsg>'')
			alert(this.errmsg);
		return false;
	}
	else
		return true;
	
}


function addCField(field, type)
{

	var len = this.cvalInf.length;
	this.cvalInf[len] = new Array();
	this.cvalInf[len]['field'] = document.getElementById(field);
	this.cvalInf[len]['field_name'] = field;
	this.cvalInf[len]['type'] = type;
	this.cvalInf[len]['label'] = null;
	this.cvalInf[len]['msg'] = null;
 
	//alert('2');
	if (arguments.length>2) 
		if (1) 
		{	
			this.cvalInf[len]['label']  = field + '_err';
			thisElement                 = document.getElementById(field + '_err');
			
   			this.cvalInf[len]['color']  = thisElement.style.color;
   			this.cvalInf[len]['weight'] = thisElement.style.fontWeight;
		}
			
	if (arguments.length>3)
		if (arguments[3]!=null&&arguments[3]!='') 
			this.cvalInf[len]['msg'] = arguments[3];
		
}     

function replaceCField(field, type)
{
	var len = this.cvalInf.length;
	var found = false;
	for(var i=0; i<len; ++i)
	{
		if(this.cvalInf[i]['field_name'] == field)
		{
			found = true;
			break;
		}
	}
	
	if(!found) return false;
	
	len = i;
	this.cvalInf[len] = new Array();
	this.cvalInf[len]['field'] = document.getElementById(field);
	this.cvalInf[len]['field_name'] = field;
	this.cvalInf[len]['type'] = type;
	this.cvalInf[len]['label'] = null;
	this.cvalInf[len]['msg'] = null;
 
	//alert('2');
	if (arguments.length>2) 
		if (1) 
		{	
			this.cvalInf[len]['label']  = field + '_err';
			thisElement                 = document.getElementById(field + '_err');
			
   			this.cvalInf[len]['color']  = thisElement.style.color;
   			this.cvalInf[len]['weight'] = thisElement.style.fontWeight;
		}
			
	if (arguments.length>3)
		if (arguments[3]!=null&&arguments[3]!='') 
			this.cvalInf[len]['msg'] = arguments[3];
			
	return true;		
}


function addOField(field, type, label, msg)
{
	
	var len = this.ovalInf.length;
	this.ovalInf[len] = new Array();
	this.ovalInf[len]['field'] = field;
	this.ovalInf[len]['type'] = type;
	this.ovalInf[len]['label'] = null;
	this.ovalInf[len]['msg'] = null;


	if (arguments.length>2) 
		if (arguments[2]!=null&&arguments[2]!='') 
		{
			this.ovalInf[len]['label']  = arguments[2];
			thisElement                 = document.getElementById(arguments[2]);
   			this.ovalInf[len]['color']  = thisElement.style.color;
   			this.ovalInf[len]['weight'] = thisElement.style.fontWeight;
		}
			
	if (arguments.length>3)
		if (arguments[3]!=null&&arguments[3]!='') 
			this.ovalInf[len]['msg'] = arguments[3];
			
	
}

//======================
// public functions
//======================

function dFlash(id, color, weight)
{
	
	thisElement                  = document.getElementById(id);
   	thisElement.style.color      = color;
   	thisElement.style.fontWeight = weight;   
}

function Flash(id)
{
	
	thisElement                  = document.getElementById(id);
   	thisElement.style.color      = 'red';
   	thisElement.style.fontWeight = "bold";   
}

function mkNumber(str)
{
	
	if(str!=null&&str.length>0)
		return str.replace(/[^0-9]/g, '');
	else
		return null;
}

function remZero(str)
{

	if(str!=null&&str.length>0)
	{
		str = str.replace(/^([0]{2,})?/i, '');
		if(str == '')	str = str.replace(/^/i, '0');
		return str;
	}
	else
		return null;
}

function Trim(str)
{

	str = str.replace(/^([ ]+)?/i, '');
	str = str.replace(/([ ]+)?$/i, '');
	return str;
}

function chkEmpty(str, id)
{
	str = Trim(str);
	if(typeof id != 'undefined')
		id.value = str;
	return str == '';
}

function chkNumber(str, id)
{
	var isNum = /^([-])?[0-9]+(\.[0-9]+)?$/;
	str = remZero(Trim(str));
	if(typeof id != 'undefined')
		id.value = str;
	return isNum.test(str);
}

function chkEMail(str, id)
{
	var isEMail = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	str = Trim(str);
	if(typeof id != 'undefined')
		id.value = str;
	return isEMail.test(str);
}

function chkHello(str, id)
{
	//var isHello = /^([\+])?([ ]+)?([0-9]{2,3})?([ ]+)?([0-9]{3,5})([ ]+|-)([0-9]{5,10})$/;
	var isHello = /^([\+])?([ ]+)?([0-9]{2,3})?([ ]+)?([0-9]{3,3})([ ]+|-)?([0-9]{7,10})$/;
	str = Trim(str);
	str = str.replace(/([\(\)])/g, '');
	//str = str.replace(/([-])/g, ' ');
	//alert(str);
	if(typeof id != 'undefined')
		id.value = str;
	return isHello.test(str);
}


