/****************************************************************************/
//  DDX - dynamic data exchange
//
//  Description:
//  Validation wrappers for forms
//  
//  Author: Ralph Lorenc 
//  E-Mail: r.lorenc@it-system.pl	 
//  (c) 1999-2000, 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 DDXSelect(control,errmsg)
{
	var s = control[control.selectedIndex].value;
	if ( s.length < 1)
	{
		self.status=errmsg;
		control.focus();
		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;
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}	
}

function DDXRExp(control, rE, errmsg)
{
	var s = control.value;
	var ms
	var mArr = s.match(rE)
	if (mArr == null)
	{
		self.status=errmsg;
		control.focus();
		control.select();
		alert(errmsg);
		return false;
	}	
	return true;		
}
