$(document).ready(function(){
    $("input.mandatory,input.email").each(function(){
        $(this).prev("label").append("<span class=\"red\">*</span>");
    });
    $("#btnsubmit").click(function(){
        var chk = true;
        $("input[type='text'],input[type='file']").each(function(){
            if($(this).hasClass('mandatory')){
                if($(this).val()==""||!isCheckmsg($(this).val())){
                    $(this).focus().next('span.error').show();
                    chk=false;
                }
                else{
                    $(this).next('span.error').hide();
                }
            }
            else if($(this).hasClass("email")){
                if($(this).val()==""||!$(this).val().match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/)){
                    $(this).focus().next('span.error').show();
                    chk=false;
                }
                else{
                    $(this).next('span.error').hide();
                }
            }
        });
        if(chk==true){
            $("#hidemail").val("CAC-WRK-1122");
            $("#frmmed").attr("action","thankyou.php").trigger("submit");
            return true;
        }
        else{
            return false;
        }
    });
    });
function isCheckmsg(str){
	var ns = str;
	ns = ltrim(ns);
	ns = rtrim(ns);
	if(ns=="")
		return false;
	else
		return true;
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
