$(document).ready(function(){

	var val = '';
	var valArray = Array;
	
	$(':text').each(function(i){
		valArray[i] = $(this).val();
	});
	
	//сброс значения поля
	$(':text').live('focus', function(){
		val = $(this).val();
		$(this).val('').css('color', 'black');
	});
	
	$(':text').live('blur', function(){
		if($(this).val() == '')
			$(this).val(val);
	});
	
	var sel = '';
	
	//выбор формы
	jQuery('#form_wrap').ajaxStart(function(){
		$(this).html('<img id="load_img" src="img/load.gif" width="37" height="37" alt="load" />');
	});
	
	$('#sel').live('change', function(){
		sel = $(this).val();
		$.post('form_home/' + sel + '.php', function(data){
			$('#form_wrap').html(data);
		});
	});
	
	jQuery('#form_wrap').ajaxStop(function(){
		$(':text').each(function(i){
			valArray[i] = $(this).val();
		});
	});
	
	//сброс значений всех полей
	$('#clear_form').live('click', function(){
		$(':text').each(function(i){
			$(this).val(valArray[i]).css('color', 'black');
		});
		return false;
	});
	
	$('.file').live('click', function(){
		$(this).next().hide();
	});
	
	var ret = false;
	//отправка формы
	$('.but').live('click', function(){
		var count = 0;
		$(':text').not('[name="stop"]').each(function(i){
			if((valArray[i] == $(this).val()) && ($(this).attr('class') != 'n')){
				$(this).val(valArray[i]).css('color', 'red');
				count++;
			}	
		});
		if(count == 0)
			ret = true;
			
		return ret;
	});
	
});
