

// returns whether the test string is a decimal number
function is_decimal(test) {	
	var expr = /^[-+]?[0-9]+([.][0-9]+)?$/i;			
	return (trim(test).search(expr) > -1);	
}


// returns whether the test string is a datetime (or simply a date/time)
function is_datetime(test) {

	var expr = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/i
	return (trim(test).search(expr) > -1);
}


// matches for canadian postal codes
function is_postal_code(test) {
	expr = /^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$/i;
	return (trim(test).search(expr) > -1);	
}

// this function checks for valid url entries
// matches mailto:whatever, ftp://whatever, http://whatever, https://whatever
function is_url(test){
	expr = /((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/i;	
	return (trim(test).search(expr) > -1);	
}


function is_name(test) {
	var expr = /^[A-Za-z\.\'\- ]+$/i;		
	return (trim(test).search(expr) > -1);
}

// alpabetic chars only
function is_alpha(test) {		
	var expr = /^[A-Za-z]+$/i;		
	return (trim(test).search(expr) > -1);	
}


// alpha numeric characters
function is_alphanumeric(test) {		
	var expr = /^[A-Za-z0-9]+$/i;		
	return (trim(test).search(expr) > -1);	
}

// alpha numeric characters, space, underscore
function is_text(test) {		
	expr = /^[A-Za-z0-9 _]+$/i;		
	return (trim(test).search(expr) > -1);
}

// alpha numeric, special chars, space + underscore
function is_special_text(test) {
	var expr = /^[A-Za-z0-9! _@',=`~#"}{.$%^&*()?+-\/\\\r\n]+$/i;
	return (trim(test).search(expr) > -1);	
}

// alpha numeric + special chars
function is_password(test) {
	var expr = /^[A-Za-z0-9!@#$%^&*()?+-]+$/i;		
	return (trim(test).search(expr) > -1);	
}

// alpha numeric + special chars
function is_address(test) {
	var expr = /^[A-Za-z0-9#()+-\. ]+$/i;		
	return (trim(test).search(expr) > -1);	
}

// test for phone number characters
function is_phone(test) {
	var expr = /^[0-9#\. -ext]+$/i;		
	return (trim(test).search(expr) > -1);		
}


// email address form
function is_email(test) {
	var expr = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i;		
	return (trim(test).search(expr) > -1);
}

// returns true for a match of filename.extension or simply filename
// where filename and extension can be alphanumeric
function is_filename(test) {
	var expr = /^[A-Za-z0-9_]*\.?[A-Za-z0-9_]*$/i;	
	return (trim(test).search(expr) > -1);	
}

// same pattern as filename, except includes / \ and _ characters
function is_pathname($test) {
	var expr = /^[A-Za-z0-9_\/\\]*\.?[A-Za-z0-9_]*$/i;
	return (trim(test).search(expr) > -1);
}


// string trimming function
function trim(str) { return str.replace(/^\s+|\s+$/g,""); }


// returns whether at least one radio or checkbox (specified by name) in
// the frm (given by frmID) has been checked
function is_checked(frmID, name) {
    
    var checked = false;    
    
    if (document.getElementById(frmID) && document.getElementById(frmID).name) {
        var i;
        var frm = document.getElementById(frmID);
        var check = document.getElementsByName(name);
        
        for (i=0; i<check.length; i++) {
            if (check[i].checked) { checked = true; break; }
        }
    }
    
    return checked;
    
}


