
function validByRegExp( regExp, str ) {
	return str.match( regExp );
}

function isGPS( str, needed ) {
	res = "^\\s*([NS](([0-8][0-9])|90)\\s+[0-5][0-9]\\.\\d{3}\\s+[EW](([01][0-7][0-9])|180)\\s+[0-5][0-9]\\.\\d{3}(\\s+[\\+\\-]?\\d+)?)" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isTimePeriodList( str, needed ) {
	res = "^\\s*(((0?\\d)|(1\\d)|(2[0-3])):[0-5]\\d\\s*\\-\\s*((0?\\d)|(1\\d)|(2[0-3])):[0-5]\\d\\s*(;\\s*((0?\\d)|(1\\d)|(2[0-3])):[0-5]\\d\\s*\\-\\s*((0?\\d)|(1\\d)|(2[0-3])):[0-5]\\d\\s*)*)" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isTuristId( str, needed ) {
	res = "^\\s*([A-Z]\\d{3})" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isTuristMainCategory( str, needed ) {
	res = "^\\s*(A\\d{2})" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isTuristCategory( str, needed ) {
	res = "^\\s*([A-Z]\\d{2})" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isTuristCategoryList( str, needed ) {
	res = "^\\s*([B-Z]\\d{2}([^\\dA-Z]+[B-Z]\\d{2})*)" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isPostcode( str, needed ) {
	res = "^\\s*(\\d{4})" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isPhoneNo( str, needed ) {
	res = "^\\s*(\\+\\d{2}\\s\\(\\d+\\)\\s\\d{3}\\-\\d+(\/\d+)?)" + ( needed ? "" : "?" ) + "\\s*$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isNotEmpty( str, needed ) {
	res = "^.+$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isPictureFile( str, needed ) {
	res = "\\.(gif|jpg|jpeg|png)$";
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

function isEmail( str, needed ) {
	res = '^([0-9a-z\\_\\-\\.]+@[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*\\.([a-z]{2}|com|org|net|edu|mil))' + ( needed ? '' : '?' ) + '$';
	regExp = new RegExp( res, "i" );
	return validByRegExp( regExp, str );
}

/**
 * check form
 * array def:
 *   0 - string, the field name
 *   1 - boolean, if true, the field is required
 *   2 - string, name of validator function
 *   3 - string, the alert message
 */
 
 function checkForm( f, a ) {
 	if( typeof( a ) == "undefined" ) return true;
 	if( typeof( f ) == "undefined" ) return true;
 	for( var fname in f.elements ) {
 		for( var i = 0; i < a.length; i++ ) {
 			if( fname == a[ i ][ 0 ] ) {
 				var obj = f[ fname ];
 				var flag = false;
 				eval( "flag = " + 
 					a[ i ][ 2 ] + "( obj.value, " + ( a[ i ][ 1 ] ? "true" : "false" ) + " );" );
 				if( ( ! flag ) && ( a[ i ][ 1 ] ) ) {
 					alert( a[ i ][ 3 ] );
 					obj.select();
 					obj.focus();
 					return false;
 				}
 		
 			}
 		}
 	}
 	return true;
 }
 