function isEmpty(id, msg) {
	if (isBlank($("#" + id).val())) {
		alert(msg);
		$("#" + id).focus();
		return true;
	}
	return false;
}

//with jquery check if blank
function isBlank(s) {
	if ($.trim(s) == "") return true;
	return false;
}

//check if numeric (integer only. without decimal point)
function isNumeric(n) {
	if (isBlank(n)) return false;
	var pat = /^\d+$/;
	if (n.match(pat) == null) return false;
	return true;
}

function isDateValid(d) {
	if (isBlank(d)) false;
	var pat = /^\d{1,2}\/\d{1,2}\/\d{4}$/;	//ensures we have m/d/yyy pattern
	if (d.match(pat) == null) {	
		return false;
	} 
	//pattern passed ... next test
	var v = d.split(/\//);
	var month = v[0], day = v[1], year = v[2];
	var maxdays = 31;
	switch (parseInt(month)) {
		case 9:	case 4:	case 6: case 11: maxdays = 30; break;
		case 2: maxdays = (year % 4 == 0) ? 29:28; break;
		default: 
	}
	if (day > maxdays) {
		return false;
	}
	
	return true;
}

function isEmail(e) {
	if (isBlank(e)) return false;
	//var pat = /^\w+\@\w+(\.[a-zA-Z]{2,4})+$/;
	var pat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
	if (e.match(pat) == null) {	
		return false;
	} 
	return true;
}

function in_array(needle, haystack) {
	for (a = 0; a<haystack.length; a++) {
		if (needle.toUpperCase() == haystack[a].toUpperCase()) return true;
	}
	return false;
}

function isMobile(d) {
	if (isBlank(d)) {		
		return false;
	}
	var pat = /^\d{11}$/;	
	if (d.match(pat) == null) return false;	
	
	//check if number is from smart mobile numbers....
	var smart_phones = new Array(
							"0908", "0918", "0919", "0920", "0921", "0929", "0939", "0947", "0949", "0999",
							"0907", "0909", "0910", "0912", "0928", "0930", "0946", "0948",
							"0905", "0906", "0915", "0916", "0917", "0925", "0926", "0927", "0935", "0936", "0937", "0989", "0996", "0997"
							);
	var first_four = d.substring(0,4);
	return in_array(first_four, smart_phones);
}

function show_status(s) {
	var img = "<img src='images/50.png' alt='Error(s) Found!' /><br />";
	$("#status").html(img + s);
	$("#status").stop(true, true);
	$("#status").fadeIn().delay(10000).fadeOut();
}

function check_contact_form() {	
	if (isBlank($("#name").val())) {			
		show_status("Please enter your fullname.");
		$("#name").focus();
		return false;	
	} else if (!isEmail($("#email").val())) {
		show_status("Please enter a valid email address.");
		$("#email").focus();
		return false;
	} else if (isBlank($("#msg").val())) {					
		show_status("Please enter a message or your inquiry on the field provided.");
		$("#msg").focus();
		return false;
	}
	
	return true;	
}

