
function validateEmail( emailad ) 
{
    // Return True if not valid, otherwise false.
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	
	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
		return true;
	else 
		return false;
}

function check_contact_form() 
{
	var name	  = $('#name').val();
	var position  = $('#position').val();
	var company   = $('#company').val();
	var telephone = $('#telephone').val();
	var email     = $('#email').val();
	var address   = $('#address').val();
	var message   = $('#message').val();
	var code      = $('#code').val();
	var returnVal = false;

    // Verify Name
	    if (name == '' || name.length < 2 ) { inlineMsg('name','Please specify your Name!',3); return false; }

    // Verify Position
	    if (position == '' || position.length < 2 ) { inlineMsg('position','Please specify your Position!',3); return false; }
	    
    // Verify Company
	    if (company == '' || company.length < 2 ) { inlineMsg('company','Please specify your Company!',3); return false; }

    // Verify Telephone
	    if (telephone == '' || telephone.length < 2 ) { inlineMsg('telephone','Please specify your Telephone!',3); return false; }

    // Verify Email
	    if (email == '' || email.length < 2 || validateEmail(email) ) { inlineMsg('email','Please specify your Email!',3); return false; }
	    
    // Verify Address
	    if (address == '' || address.length < 2 ) { inlineMsg('address','Please specify your Address!',3); return false; }

    // Verify Query
	    if (message == '' || message.length < 2 ) { inlineMsg('message','Please specify your Enquiry!',3); return false; }

    // Verify Security Code
	    if (code == '' || code.length < 2 ) { inlineMsg('code','Please specify exactly the Security Code shown in the image!',3); return false; }

	// Verify captcha
		$.ajax
		({
			type: "POST",
			url: "ajax/ajax_check_captcha.php",
			data: "code="+escape(code)+"&rand="+Math.random(),
			async: false,
			success: function(msg)
			{		
				
				if ( msg == '1' )	
					returnVal = true;				
				else 
				{					
					inlineMsg('code','<b>Invalid code!</b> <br> Please specify exactly the Security Code shown in the image.',3);
				}
			},
			error: function(msg) 
			{
	                alert("Invalid request!\n"+msg);
			}
		});

	return returnVal;
}