var options = { 
        target:        '#response',   // target element(s) to be updated with server response 
        beforeSubmit:  validateForm,
        //success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      post,        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
    
function validateForm(){
	var pattern = new RegExp(/^[0-9a-zA-ZāčēģīķļņšūžĀČĒĢĪĶĻŅŠŪŽа-яА-Я .,@-]+$/);
	var return_var = true;
	$('#applyForm td.required input').each(function(i){
		if (pattern.test(this.value) == false){
			this.focus();
			$(this).css('background', '#f7b5b5');
			return_var = false;
		}
		else {
			$(this).css('background', '#FFFFFF');
		}
	});
	$('textarea').each(function(i){
		if (pattern.test($(this).val()) == false){
			this.focus();
			$(this).css('background', '#f7b5b5');
			return_var = false;
		}
		else {
			$(this).css('background', '#FFFFFF');
		}
	});
	pattern.compile(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/);
	$('#applyForm #Epasts').each(function(i){
		if (pattern.test(this.value) == false){
			this.focus();
			$(this).css('background', '#f7b5b5');
			return_var = false;
		}
		else {
			$(this).css('background', '#FFFFFF');
		}
	});
	return return_var;
	//alert('OK');
}

$(document).ready(function() { 
	$('#applyForm').ajaxForm(options);	
});