$(document).ready(function(){
    $.getJSON("../js/country.json",function(data){
        for(var i=0;i<data.country.length;i++){
            $('#country').append("<option value='"+data.country[i].name+"'>"+data.country[i].value+"</option>");
        }
    $('#country').attr("value","USA");
    });
    $("input.mandatory,input.email,select.mandatory").each(function(){
        $(this).prev("label").append("<span class=\"red\">*</span>");
    });
    $("#btnsubmit").click(function(){
        var chk = true;
        $("input,select").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();
                }
            }
            });//end of each loop
        if(chk==true){
            $("#hidemail").val("CAC-INQ-3344");
            $("#frmmed").attr("action","thankyou-inquiry.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+$/,"");
}
