class ClassValidate
{
public function validate($_type,$_name,$_value,$_params=array())
	{
	global $class_errors;
	switch ($_type)
		{
		case 'num':
			$_value = $_value * 1;
			return $_value;
			break;
		case 'list':
			$_value = trim($_value);
			$_value = in_array($_value,$_params[0]) ? $_value : $_params[0][0];
			return $_value;
			break;
		case 'str':
			$_value = trim($_value);
			$_value = substr($_value,0,255);
			$reg    = '/[a-zA-Z0-9]{0,}/m';
			$_value = preg_match($reg,$_value) ? $_value : '';
			return $_value;
			break;
		case 'str_reg':
			$_value = trim($_value);
			$_value = substr($_value,0,255);
			$reg    = $_params[0];
			if ($reg!=='')
				{
				$_value = preg_match($reg,$_value) ? $_value : '';
				}
			else	{
				$class_errors->setErr('validate',$_name.' prazdny reg. vyraz'); break;
				}
			return $_value;
			break;
		case 'tel':
			$_value = trim($_value);
			$_value = substr($_value,0,255);
			$_value = preg_replace('/( \| )|( \|)|( \|)/m','|',$_value);	//smaz mezery kolem oddelovace
			switch ($_params[0])
				{
				//case 1 :  $reg = '^[+#][0-9]{3,} [0-9]{3,} [0-9]{3,}$'; break;	//tel +420 xxx xxx
				//case 2 :  $reg = '([+#][0-9]{3,} [0-9]{6,})'; break;		//tel +420 xxxxxx
				//case 3 :  $reg = '(([+#][0-9]{3,} [0-9]{6,})[|]{0,1})*'; break;	//tel +420 xxxxxx|+420 xxxxxx
				case 4 : $reg = '/[0-9]{6,}/m'; break;				//fax xxxxxx
				case 5 : $reg = '/((([+#][0-9]{3,} [0-9]{6,})|([+#][0-9]{3,} [0-9]{3,} [0-9]{3,}))[|]{0,1}){0,}/m'; break;	//tel +420 xxxxxx|+420 xxxxxx
				default: break;
				}
			//$_value = str_replace(' ','',$_value);
			if ($reg!=='')
				{
				$_value = preg_match($reg,$_value) ? $_value : '';
				}
			else	{
				$class_errors->setErr('validate',$_name.' prazdny reg. vyraz'); break;
				}
			return $_value;
			break;
		case 'mail':
			$_value   = trim($_value);
			$_value   = substr($_value,0,255);
			$reg_mail = '[a-zA-Z0-9.]+@[a-zA-Z0-9.]+';
			$reg      = '';
			switch ($_params[0])
				{
				case 1 : $reg = '/^'.$reg_mail.'$/'; break;	//tel +420 xxx xxx
				case 2 : $reg = '/(('.$reg_mail.')[\n]{0,1}){0,}/m'; break;		//tel +420 xxxxxx
				default: break;
				}
			if ($reg!=='')
				{
				$_value = preg_match($reg,$_value) ? $_value : '';
				}
			else	{
				$class_errors->setErr('validate',$_name.' prazdny reg. vyraz'); break;
				}
			return $_value;
			break;
		case 'messagers':
			// icq://307858348\njabber://dron@jabbim.cz\nsip://sipurl\nmsn://peter.mlich@hotmail.com\nirc\ngadu\naim\njahoo"),
			$_value   = trim($_value);
			$_value   = substr($_value,0,255);
			$reg_mail = '[a-zA-Z0-9.]+@[a-zA-Z0-9.]+';
			$reg      = array(
			'icq'   =>'icq\:\/\/[0-9]{6,12}',
				'jabber'=>'jabber\:\/\/'. $reg_mail,
//				'sip'   =>'icq\:\/\/url',
				'msn'   =>'msn\:\/\/'. $reg_mail,
//				'irc'   =>'irc\:\/\/',
//				'gadu'  =>'gadu\:\/\/',
//				'aim'   =>'aim\:\/\/',
//				'jahoo' =>'jahoo\:\/\/',
				'skype' =>'skype\:\/\/'. $reg_mail
				);
			$reg = implode('[\n]{0,1})(',$reg);
			if ($reg!=="")
				{
				$reg      = '/('.$reg.')/m';
				$_value   = preg_match($reg,$_value) ? $_value : '';
				}
			else	{
				$class_errors->setErr('validate',$_name.' prazdny reg. vyraz'); break;
				}
			return $_value;
			break;

		default: break;
		}
	}
}
