function check() {

    var Name = document.getElementById('Name');
    var Company = document.getElementById('Company');
    var JobTitle = document.getElementById('JobTitle');
    var Email = document.getElementById('Email');
    var Tel = document.getElementById('Tel');
    var Note = document.getElementById('Note');
	var Code = document.getElementById('Code');

	if (!trim(Name.value)) { alert('The your name is required.'); Name.focus(); return false; }
	if (!trim(Company.value)) { alert('The company name is required.'); Company.focus(); return false; }
	if (!trim(JobTitle.value)) { alert('The job title is required.'); JobTitle.focus(); return false; }
	if (!trim(Email.value)) { alert('The e-mail address is required.'); Email.focus(); return false; }
	if (!isEmail(Email.value)) { alert('This is an incorrect email address.'); Email.focus(); return false; }
	if (!trim(Tel.value)) { alert('The telephone number is required.'); Tel.focus(); return false; }
	if (!trim(Note.value)) { alert('The remark is required.'); Note.focus(); return false; }
	if (!trim(Code.value)) { alert('The access code is required.'); Code.focus(); return false; }

    if(!ischar(Code.value)){Code.select();return false;}

	var mag;

	$().ajaxStart(function () { showLoading() });

	var PostParam = $("#ContactForm").serialize();
	$.ajax({
	    type: "POST",
	    url: "api/contact_send.ashx",
	    data: PostParam,
	    cache: false,
	    dataType: 'json',
	    error: function(xhr) {
	        msg = 'Ajax request error'; icon = 2;
	        showMessage(msg, icon);
	    },
	    success: function(result) {
	        if (!result.success) {
	            msg = result.msg; icon = 2;
	            showMessage(msg, icon);
	        } else {
	            ContactForm.style.display = 'none';
	            SuccessMessage.style.display = '';
	            $.unblockUI();
	        }
	    }
	});
	Code.value = '';
}
function ischar(s){
        var errorChar;
        var badChar = "><[]{}?/\+=|'~!#$%^&()`"; 

        errorChar = isCharsInBagEx(s,badChar);
        if (errorChar != ''){
            alert('Do not enter special characters(' + badChar + ')');
            return false;
        }
        return true;
}
function isCharsInBagEx(s,bag){ 
        var i,c;
        for (i = 0; i < s.length; i++){ 
                c = s.charAt(i);
                if (bag.indexOf(c) > -1){
                return c
                }
        }
        return '';
}
function trim(instr){
        return instr.replace(/^[\s]*/gi,'').replace(/[\s]*$/gi,'');
}
function isEmail(str) {
    var reg = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
    var r = str.match(reg);
    if (r == null) {
        return false;
    } else {
        return true;
    }
}
function isNoSpecialKey(e) {
    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);

    if ((key < 48 || key > 57) && (key < 65 || key > 90) && (key < 97 || key > 122) && (key != 95) && (key != 45) && (key != 8)) {
        return false;
    }
}
function isInteger(e){
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);

        if((key < 48 || key > 57) && (key != 8)){
		return false;
	}
}