/**
 * @Author: lloydirvin (lloyd@agyuku.net)
 * @Modifications: edsonworks (nuqui_edson@yahoo.com)
 * @date: 12.06.2009
 **/

$(function() {
		$('#submitbtn').click(function() {
			var error = false, email_error = false, error_message = '';
			var name = $.trim($('#name').val());
			var position = $.trim($('#position').val());
			var email = $.trim($('#email').val());
			var company = $.trim($('#company').val());
			var country = $.trim($('#country').val());
			var telephone = $.trim($('#telephone').val());
			var message = $.trim($('#message').val());
			
			if(!name) {
				$('#name').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}
			
			if(!position) {
				$('#position').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}

			if(!email) {
				$('#email').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}

			if(email) {
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if(reg.test(email) == false) {
   					$('#email').attr({style:'border: 1px solid #FF6F6F'});
   					error = true;
   					email_error = true;
				}

			}

			if(!company) {
				$('#company').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}
			
			if(!country) {
				$('#country').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}
			
			if(!telephone) {
				$('#telephone').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}

			if(!message) {
				$('#message').attr({style:'border: 1px solid #FF6F6F'});
				error = true;
			}
			
			if(error) {	                				
				if(email_error)										
					error_message += '*Please enter a valid email address. <br />';
				else	
					error_message += '* Please fill in the required fields.';										

				$('#error').html(error_message);
				$('#error').show();

    			setTimeout(function() {
    				$('.contact-field').attr({style:'border: 1px solid #A5ACB2'});
    				$('#error').hide();
    			}, 4500);
			} else {
				$('#contactform').submit();
			}
			
			return false;
		});
	});