jQuery.fn.extend({
	resume: function () {
		if (this) {
			$(this).submit(function(){
				result = true;
				$(this).find('h3 span').removeClass('alert').html('Все поля обязательны для заполнения!');
				
				
				if (!$(this).find('input[name=resume_'+'name]').validatorLength(3,150)){result = false;}
				if (!$(this).find('input[name=resume_'+'email]').validatorMail()){result = false;} 
				if ($(this).find('input[name=resume_'+'type]:checked').val() == 0){
					if (!$(this).find('input[name=resume_'+'education]').validatorLength(3,500)){result = false;}
					if (!$(this).find('input[name=resume_'+'year]').validatorLength(3,150)){result = false;}
					if (!$(this).find('textarea[name=resume_'+'operational_experience]').validatorLength(2,3000)){result = false;}
				}else{
					if (!$(this).find('input[name=resume_'+'file]').validatorFile()){result = false;}
				}
				if (!$(this).find('input[name=resume_'+'captcha]').validatorLength(5,5)){result = false;}
				
				if(!result)
				{
					$(this).find('h3 span').addClass('alert').html('Проверьте правильность заполнения полей!');
				}
				else
				{
					$(this).find('h3 span').removeClass('alert').html('Все поля обязательны для заполнения!');
				}
				
				return result;
			});
			
			$(this).find('input[type=button]').click(function() {
				$(this).parents('form').submit();
			});
			
			$(this).find('select[name=resume_country]').change(function() {
				$('#cities-load').load('/data/'+$(this).val()+'/'+$('#cities-load').attr('rel')+'/'+$('#cities-load').attr('rev')+'/tpl-vacancies_form_cities/');
			}).change();
			
			$(this).find('input[name=resume_type]').change(function() {
				if($(this).attr('checked') == 'checked'){
					if($(this).val() == 0){
						$('#file-resume').hide(300);
						$('#full-resume').slideDown(300);
					}else{
						$('#full-resume').hide(300);
						$('#file-resume').slideDown(300);
					}
				}
			}).change();
		}
	},
	contacts: function () {
		if (this) {
			$(this).submit(function(){
				result = true;
				$(this).find('h3 span').removeClass('alert').html('Все поля обязательны для заполнения!');
				
				if (!$(this).find('input[name=contacts_'+'name]').validatorLength(3,150)){result = false;}
				if (!$(this).find('input[name=contacts_'+'email]').validatorMail()){result = false;} 
				if (!$(this).find('textarea[name=contacts_'+'message]').validatorLength(2,3000)){result = false;}
				if (!$(this).find('input[name=contacts_'+'captcha]').validatorLength(5,5)){result = false;}
				
				if(!result)
				{
					$(this).find('h3 span').addClass('alert').html('Проверьте правильность заполнения полей!');
				}
				else
				{
					$(this).find('h3 span').removeClass('alert').html('Все поля обязательны для заполнения!');
				}
				
				return result;
			});
			
			$(this).find('input[type=button]').click(function() {
				$(this).parents('form').submit();
			});
		}
	}
});
