//-----------------------------------
// Form validation helper functions
//-----------------------------------

function isFieldEmpty(value) {
    if (typeof(value) == "string"){
	if (jQuery.trim(value) !==''){
	    return false;
	}else{
	    return true;
	}
    }
    else return -1;
}

function isValidEmail(email){
    var isValid = false;

    if (email != '') {
	var emailMatch = "[a-zA-Z0-9-+]*@[a-zA-Z0-9-+]*[\.][a-zA-Z]{2,4}";
	if (email.match(emailMatch)) {
	    isValid = true;
	}
    }
    return isValid;
}

function isValidPhone(value){
    var isValid = false;

    var phoneMatch = /[?1\(\s]{0,2}\d{3}[?\-\.\)\s]{0,2}\d{3}[?\-\.\s]{0,3}\d{4}/;
    if (value.match(phoneMatch)) {
	isValid = true;
    }
    return isValid;
}


function isValidZip(value){
    var isValid = false;

    var zipMatch = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    if (value.match(zipMatch)) {
	isValid = true;
    }
    return isValid;
}

function highlightErr(elem){
    if (typeof(elem) != undefined) {
	$("label:has[for="+elem.id+"]").addClass("error");

    };
}

function removeErr(elem){
    if (typeof(elem) != undefined) {
	$("label:has[for="+elem.id+"]").removeClass("error");
    };
}

function checkField(name) {
    if ($('#' + name).val() == '') {
        $('#' + name).prev().addClass('error');
        return true;
    }
    else {
        $('#' + name).prev().removeClass('error');
        return false;
    }
}