/****************************************************************************/
//  DDX - dynamic data exchange
//
//  Description:
//  Validation wrappers for forms
//  
//  Author: Ralph Lorenc 
//  E-Mail: r.lorenc@it-system.pl	 
//  (c) 1999-2004, Internet Technology System Solutions Sp. z o.o. 
//  http://www.it-system.pl (.com) (.de)
//	   
//  All right reserved. Any portions of this code cannot be 
//  used in any form  without licence by IT-SYSTEM company.  
/****************************************************************************/

function DDXLen(control,minLen,maxLen,errmsg)
{
	var s = control.value;
	if (s.length < minLen || s.length > maxLen )
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}
	return true;
}
	
function DDXInt(control,min,max,errmsg)
{
	var s = control.value;
	
	if ( isNaN (s,10)  )
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}
	
	if ( s.valueOf() < min || s.valueOf() > max )
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}
	return true;
}


function DDXChecked(control,nochecked,errmsg)
{
	var l = control.length;
	var bRet = false;
	
	for ( i=0;i<l;i++ ) {
		if ( control[i].checked ) {
			nochecked--;
		}
	}
	
	bRet = (nochecked <= 0);
	
	if ( !bRet )
		alert(errmsg);
		
	return bRet;
}


function DDXEMail(control, errmsg)
{
	var s = control.value;
	//var rE = /^(\w)+(\w\.)*@.*\.\w+$/;/ => nie akceptuje kropki w nazwie usera w adresie email.
	var rE = /^(\w)+([\w_\.]*)@.*\.\w+$/;
	var mArr = s.match(rE);
	if (mArr == null) 
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}	

	return true;		
}

function DDXRExp(control, rE, errmsg)
{
	var s = control.value;
	var ms
	var mArr = s.match(rE)
	if (mArr != null)  {
		ms = mArr.toString();
	}
	else
		ms = "";
		
	if (ms != s) 
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}	
	return true;		
}


