//provided by jQuery
function tgt_display_errors_and_messages(errors, messages, errors_div, messages_div) {
	var err_str = '';
	var mess_str = '';
	jQuery('#' + errors_div).html ('');
	jQuery('#' + errors_div).hide();
	jQuery('#' + messages_div).html ('');
	jQuery('#' + messages_div).hide();
	
	for (i=0; i<errors.length; i++) {
		err_str += errors[i] + '<br/>';
	}
	for (i=0; i<messages.length; i++) {
		mess_str += messages[i] + '<br/>';
	}
	
	if (err_str != '') {			
		jQuery('#' + errors_div).html (err_str);
		jQuery('#' + errors_div).show();
	}
	if (mess_str != '') {
		jQuery('#' + messages_div).html (mess_str);
		jQuery('#' + messages_div).show();
	}
}

function tgt_is_mail(id)
{
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
	return emailPattern.test(id);
} 

function tgt_is_empty(str) {
	return jQuery.trim( str ) == '';
}

function tgt_is_numeric(input) {
	return (input - 0) == input && input.length > 0;
}

function tgt_is_date(input) {
	//date structer: yyyy-mm-dd
	input = jQuery.trim( input );
	//if (input.charAt(4)!=input.charAt(7) || input.charAt(4)!='-') return false;
	year = input.substr(0, 4);
	month = input.substr(5, 2);
	day = input.substr(8);
	
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	var tempDate = new Date(year, month, day);
	if ( (tempDate.getFullYear() == year) &&(month == tempDate.getMonth()) && (day == tempDate.getDate()) )
		return true;
	else
		return false
}
function tgt_is_phone_number( input ) {

	if (input.match(/^[0-9\-\ \(\)\+]+[0-9\-\ \(\)\+]$/)){
		return true;
	}
	return false;
}
function tgt_is_url( input ) {
	//structure http://yoursite.com
	var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return RegexUrl.test( input );
}
