id_table_cash = '';
file = 2;
step_1 = true;
step_2 = true;
position_slide = new Array();
position_slide[1] = 0;
position_slide[2] = -649;
position_slide[3] = -1298;
position_slide[4] = -1947;
step_active = 1;
step_error = new Array();
step_error[1] = '';
step_error[2] = '';
step_error[3] = '';
step_error[4] = '';

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}


function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}


function autoheight(){
	$('#content-bg').css('min-height', ($(window).height()-158)+'px');
	}

function show_selected_block(){
		
		if($("#ur_fiz_select").val() == 0){$('#ur_table').css('display', 'table'); $('#fiz_table').css('display', 'none');}
		if($("#ur_fiz_select").val() == 1){$('#ur_table').css('display', 'none'); $('#fiz_table').css('display', 'table');}
	}
	
function show_table(id_table){
	if(id_table == 'table_dictors_page_edit'){
		
			if($('#table_dictors_page_edit').css('display') != 'block'){
				$('.link_dictor').attr( 'style','color:#49A3DF; border-bottom: 1px dashed;'); 
				$('.table').hide('slow');
				$('#table_dictors_page_edit').show(2500);
				 
			}
		}
	else{
		$('.table').hide('slow');
		$('#table_'+id_table).show(2500);
		$('.link_dictor').attr( 'style','color:#49A3DF; border-bottom: 1px dashed;');
		$('#link_'+id_table).attr('style','color:#666666;  border:none;');
		$(document).scrollTop(100);
	}
}


function show_table_admin(id_table , count){
	
	if(id_table != id_table_cash){
		id_table_cash = id_table;
		$('.table').hide('slow');
		for($i=1; $i<=count; $i++){
			$('#table_'+id_table+'_'+$i).show(2500);
		}
	

	}
}



function show_table_page_dictors_edit(){
		$('.table').hide('slow');
		$('#table_dictors_edit').show(2500);
}

function show_table_admin_edit(id, position, num){
		$('.table').hide('slow');
		$('.link_dictor').attr( 'style','color:#49A3DF; border-bottom: 1px dashed;');
		$('#link_'+position+'_'+num).attr('style','color:#666666;  border:none;');
		$.post('../admin/dictor.php', { form_type: "show", id: ""+id+"" },
		function(data){
			$('#form_block_dictor_edit').empty().html(data);
		 });
		$('#table_edit_dictor').show(2500);
		$(document).scrollTop(100);

}

function show_table_admin_edit_portfolio(id, position, num){
		$('.table').hide('slow');
		$('.link_dictor').attr( 'style','color:#49A3DF; border-bottom: 1px dashed;');
		$('#link_'+position+'_'+num).attr('style','color:#666666;  border:none;');
		$.post('../admin/portfolio_function.php', { form_type: "show", id: ""+id+"" },
		function(data){
			$('#form_block_portfolio_edit').empty().html(data);
		 });
		$('#table_edit_portfolio').show(2500);
		$(document).scrollTop(100);
}

function show_admin_dictors_page(id, position, num){
		$('.link_dictor').attr( 'style','color:#49A3DF; border-bottom: 1px dashed;');
		$('#link_'+position+'_'+num).attr('style','color:#666666;  border:none;');
		$('.table').hide('slow');
		$.post('../admin/dictors_function.php', { form_type: "show_dictors_page", id: ""+id+"" },
		function(data){
			$('#table_pages_edit').empty().html(data);
		 });
		$('#table_pages_edit').show(2500);

}


function show_admin_dictors_table_properties(id){
	//alert();
		//$('#dictor_table_list_1 option:selected').val()
		//$('#table_page_dictors_table_property').empty();
		$('#table_page_dictors_table_property').hide();
		//alert($('#dictor_table_list_1 option:selected').val());
		$.post('../admin/dictors_function.php', { form_type: "show_table_dictors", id: ""+$('#dictor_table_list option:selected').val()+"" },
		function(data){
			$('#table_page_dictors_table_property').empty().html(data);
		 });
		$('#table_page_dictors_table_property').show(1000);

}

function admin_dictor_remove(id, name, position, num){
	if(confirm('Подтвердить удаление \n'+name)){
	
	//id_string = $('#tr_'+position+'_'+num).parent().parent().parent().attr('id');
	$('#tr_'+position+'_'+num).remove();
		
	$.post('../admin/dictor.php', { form_type: "remove", id: ""+id+"" },
		function(data){
			
		 });
	}
}

function admin_portfolio_remove(id, name, position, num){
	if(confirm('Подтвердить удаление \n'+name)){
	
	//id_string = $('#tr_'+position+'_'+num).parent().parent().parent().attr('id');
	$('#tr_'+position+'_'+num).remove();
		
	$.post('../admin/portfolio_function.php', { form_type: "remove", id: ""+id+"" },
		function(data){
			
		 });
	}
}


function add_page_dictors_menu_item(num){
		string = '<tr>'
						+'<td class="form_block_admin_left">Пункт меню '+num+'</td>'
						+'<td>'
							+'<input style="width:125px;" type="text"  name="new_page_dicrors_menu_en_'+num+'" />'
							+'<input style="width:125px;" type="text"  name="new_page_dicrors_menu_ru_'+num+'" />'
						+'</td>'
					+'</tr>';
					
	$('#add_page_dictors_menu').before(string);	
	$('#add_page_dictors_menu input').attr('onClick', 'add_page_dictors_menu_item(\''+(parseInt(num)+1)+'\')')			
}

function admin_dictors_add_table(id, num){
	
	
	//id_string = $('#tr_'+position+'_'+num).parent().parent().parent().attr('id');
	//$.ajaxSetup({scriptCharset: "windows-1251" , contentType: "application/json; charset=windows-1251"});
	//count_option = $('#dictor_table_list :last').val();
	
	//alert(c);		
	$.post('../admin/dictors_function.php', { form_type: "add_table_dictors", menu_id: ""+num+"", new_dictors_table: ""+$('#new_dictors_table').val()+"" },
		function(data){
			if(data != 'Ошибка, данные не были внесены в БД'){$('#dictor_table_list').append( $('<option value="'+data+'">'+$('#new_dictors_table').val()+'</option>'));}
		 	else{alert(data);}
		 });


}

function admin_dictors_change_table(){
	
	 if (confirm('Сохранить изменения?')){
		$.post('../admin/dictors_function.php', $('#dictor_table_propertis').serializeArray(),
		function(data){
			alert(data);
		 });
	} 	 
}

function admin_dictor_table_remove(id){
	if(confirm('Подтвердить удаление')){
	
	//id_string = $('#tr_'+position+'_'+num).parent().parent().parent().attr('id');
	$('#dictor_table_list option[value="'+id+'"]').remove();
	$('#table_page_dictors_table_property').html(' ');	
	$.post('../admin/dictors_function.php', { form_type: "remove_table_dictors", id: ""+id+"" },
		function(data){
			alert(data);
		 });
	}
}

function show_table_zakaz_et_1(){
			$('#zakaz_dicrors_table').empty().html('<tr><td style="width:100%; text-align:center;"><img src="images/loading.gif" style="float:none; margin:10px auto; width:150px;"<td><tr>');
			$.post('zakaz_new_function.php', { form_type: "dictors_table", section: $('#filter_zakaz_section').val(), lang: $('#filter_zakaz_language').val(), sex: $('#filter_zakaz_sex').val() },
			function(data){
				$('#zakaz_dicrors_table').empty().html(data);
				visible_block_height('1');
				//alert($('#filter_zakaz_sex').val());
			 });
			//$('#table_page_dictors_table_property').show(1000);
			step_1 = false;
}

function show_table_zakaz_et_2(){
			$('#zakaz_decor_table').empty().html('<tr><td style="width:100%; text-align:center;"><img src="images/loading.gif" style="float:none; margin:10px auto; width:150px;"<td><tr>');
			$.post('zakaz_new_function.php', { form_type: "decor_table", decor: $('#filter_zakaz_decor').val() },
			function(data){
				$('#zakaz_decor_table').empty().html(data);
				visible_block_height('2');
				//alert($('#filter_zakaz_sex').val());
			 });
			//$('#table_page_dictors_table_property').show(1000);
			step_2 = false;
}


function add_file(){
	num = file;
	count = $('tr.file_row').length;
	if(count < 3){
		$('.remove').removeClass('hide');
		$('.add').remove();
		string = '<tr class="file_row" id="file_row_'+num+'">'
						+'<td></td>'
						+'<td>'
							+'<img class="loading file_'+num+'" src="images/loading.gif" style="display:none;"><input type="hidden" id="h_file_'+num+'" name="file_'+num+'"/><input onchange="return ajaxFileUpload(\'file_'+num+'\');" type="file" id="file_'+num+'" name="file_'+num+'" style="width: 230px; height:24px;" class="disabele"><button class="remove hide disabele"  style="width:30px; height:23px; margin:0px 0 0 5px;" onclick="$(\'#file_row_'+num+'\').remove(); visible_block_height(\'3\');  return false;" >-</button><button  class="add disabele"  style="width:30px; height:23px;  margin:0px 0 0 5px;" onclick="add_file(); return false;">+</button>'
						+'</td>'
				  +'</tr>';
		$('#file_befor').before(string);
		file += 1;
		visible_block_height('3');
		}
		else{alert('максимум 3 файла'); return false;}
	}
	

function payments_select(){
	$('.payments').hide();
	if($('#payment').val() == '3' || $('#payment').val() == '4' || $('#payment').val() == '2'){$('#payments_purse').show();}
	if($('#payment').val() == '1'){$('#payments_requisites').show();}
	if($('#payment').val() == '5'){$('#payments_cards').show();}
	visible_block_height('4');
	}
	
function visible_block_height(num){
		$('#visible_block').height($('#table_zakaz_etap_'+num).height()+20);
	}	
/*	
function next_step(num){
	if(num == '2' && step_2){show_table_zakaz_et_2();}
	else{visible_block_height(num);}
	//alert($('#slide_block').position().left-645);
	slide = $('#slide_block').position().left-649;
	$('#slide_block').animate({left: slide}, "slow");
	$(document).scrollTop(400)
	
	}
*/
function show_step(num){
	step_active = num;
	test_step(num)
	//alert($('.step_position_active').attr('id'));
	$('#'+$('.step_position_active').attr('id')).removeClass('step_position_active');
	$('#spet_position_'+num).removeClass('step_position_good');
	$('#spet_position_'+num).removeClass('step_position_bad');
	$('#spet_position_'+num).addClass('step_position_active');
	if(num == '1' && step_1){show_table_zakaz_et_1();}
	else if(num == '2' && step_2){show_table_zakaz_et_2();}
	else{visible_block_height(num);}
	slide = position_slide[num];
	$('#slide_block').animate({left: slide}, "slow");
	$(document).scrollTop(400);
	
	}	

function test_step(position){
	
	step_error[1] = '';
	step_error[2] = '';
	step_error[3] = '';
	step_error[4] = '';
	if(position > 1){
		$('#spet_position_4').removeClass('step_position_bad');
		$('#spet_position_4').removeClass('step_position_good');
		$('#spet_position_4').removeClass('step_position_acvtive');
		if(!$('input[name="select_dictor"]:checked').val()){
			step_error[1] = '- Вы не выбрали диктора \r\n';
			$('#spet_position_1').addClass('step_position_bad');
			$('#spet_position_1').attr('title', step_error[1]);
		}
		else{$('#spet_position_1').addClass('step_position_good'); $('#spet_position_1').attr('title', 'ошыбоки отсутствуют'); }
	}
	if(position > 2){
		$('#spet_position_4').removeClass('step_position_bad');
		$('#spet_position_4').removeClass('step_position_good');
		$('#spet_position_4').removeClass('step_position_acvtive');
		$('#spet_position_2').addClass('step_position_good'); $('#spet_position_2').attr('title', 'ошыбоки отсутствуют');}
	if(position > 3){
		$('#spet_position_3').removeClass('step_position_bad');
		$('#spet_position_3').removeClass('step_position_good');
		$('#spet_position_3').removeClass('step_position_acvtive');
		if(!$('textarea[name="record_text"]').val()){
			step_error[3] = '- Вы не ввели текст записи \r\n';
		$('#spet_position_3').addClass('step_position_bad');
		$('#spet_position_3').attr('title', step_error[3]);
		}
		else{$('#spet_position_3').addClass('step_position_good'); $('#spet_position_3').attr('title', 'ошыбоки отсутствуют');}
	}	
	if(position == 4){
		if(!$('input[name="client_name"]').val()){
			step_error[4] += '- Вы не представились \r\n';
		}
		
		if(!$('select[name="client_payment"] option:selected').val()){
			step_error[4] += '- Вы не выбрали способ оплаты \r\n';
		}
		
		if(!$('input[name="client_tel"]').val()){
			step_error[4] += '- Вы не оставили контактный телефон \r\n';
		}
		
		if(!$('input[name="client_email"]').val()){
			step_error[4] += '- Вы не оставили контактный email \r\n';
		}
		
		if(!$('input[name="capcha"]').val()){
			step_error[4] += '- Вы не ввели код подтверждения \r\n';
		}
		$('#spet_position_4').removeClass('step_position_bad');
		$('#spet_position_4').removeClass('step_position_good');
		$('#spet_position_4').removeClass('step_position_acvtive');
		if(step_error[4] ){$('#spet_position_4').addClass('step_position_bad'); $('#spet_position_4').attr('title', step_error[4]);}
		else{$('#spet_position_4').addClass('step_position_good'); $('#spet_position_4').attr('title', 'ошыбоки отсутствуют');}
	}	
	if(!step_error[1] && !step_error[2] && !step_error[3] && !step_error[4]){$('.new_submit_hide').hide(); $('.new_submit').show();}
	else{ $('.new_submit').hide(); $('.new_submit_hide').show();}
}
	
function alert_error(){
	string = 'Ви допустили такие ошыбки: \r\n'+step_error[1]+step_error[2]+step_error[3]+step_error[4];
	alert(string);
	}	
	
	

function send_order(){
		$.post('new_zakaz_send.php', $('#form_order').serializeArray(),
		function(data){
			if(data != 'capcha_erorr'){$('#visible_block').empty().html(data); $('#visible_block').height(266);}
			else{alert('Вы ввели неверный код подтверждения');}
		 });
}


function change_status(id_str, id) {
	if($('#'+id_str).attr('class') == 'dictor_on'){
	status_num = 1;
	//$('#'+id).attr('class', 'dictor_off');
	}
	else if($('#'+id_str).attr('class') == 'dictor_off'){
	//$('#'+id).attr('class', 'dictor_on');
	status_num = 0;
	}
	$('#'+id_str).attr('class', 'dictor_atantion');
	$.post('../admin/dictors_function.php', { form_type: "change_status", id: ""+id+"", status: ""+status_num+"" },
		function(data){
			if(data && status_num == '1'){$('#'+id_str).attr('class', 'dictor_off');}
			else if(data && status_num == '0'){$('#'+id_str).attr('class', 'dictor_on');} 
		 });
} 
 
 
function change_status_portfolio(id_str, id) {
	if($('#'+id_str).attr('class') == 'dictor_on'){
	status_num = 1;
	//$('#'+id).attr('class', 'dictor_off');
	}
	else if($('#'+id_str).attr('class') == 'dictor_off'){
	//$('#'+id).attr('class', 'dictor_on');
	status_num = 0;
	}
	$('#'+id_str).attr('class', 'dictor_atantion');
	$.post('../admin/portfolio_function.php', { form_type: "change_status", id: ""+id+"", status: ""+status_num+"" },
		function(data){
			if(data && status_num == '1'){$('#'+id_str).attr('class', 'dictor_off');}
			else if(data && status_num == '0'){$('#'+id_str).attr('class', 'dictor_on');} 
		 });
} 

function test_capha(){	
		$('#okno_capcha').attr('class', '');
		$('#okno_capcha').hide();
		$('#capcha_loadimg').show();
		$.post('new_zakaz_send.php', { form_type: "capcha_test", capcha: $('#input_capcha').val() },
			function(data){
				capcha_data = data;
				
				$('#capcha_loadimg').hide();
				if(data == 'true'){ $('#okno_capcha').show(); $('#okno_capcha').attr('class', 'okno_capcha_ok'); capcha_data = true;}
				else{ $('#okno_capcha').show(); $('#okno_capcha').attr('class', 'okno_capcha_no'); capcha_data = false;}
			 });
	 
}

function capcha_reload(){
    $('#capcha_box img').attr('src', $('#capcha_box img').attr('src')+'&'+Math.random());
	}
	
function new_dictor_send(){	
		$('#new_dictor_form_table').hide();
		$('#loading_img_new').show();
		$.post('dictor.php', $("#add_dictor_form").serialize(),
			function(data){
				$('#loading_img_new').hide();
				if(data == 'OK'){ 
					$('#new_dictor_form_table').show();
					$('#new_dictor_form_table input[name="dictor_name"]').val('');
					$('#new_dictor_form_table input[name="dictor_main_track"]').val('');
					$('#new_dictor_form_table input[name="dictor_main_track_file"]').val('');
					alert("Даные внесены");
				}
				else{ $('#new_dictor_form_table').show(); alert(data);}
			 });
	 
}	

function edit_dictor_send(){	
		$('#edit_dictor_form_table').hide();
		$('#loading_img_edit').show();
		$.post('dictor.php', $("#edit_dictor_form").serialize(),
			function(data){
				$('#loading_img_edit').hide();
				if(data == 'OK'){ 
					$('#edit_dictor_form_table').show();
					alert("Даные внесены");
				}
				else{ $('#edit_dictor_form_table').show(); alert(data);}
			 });
	 
}

function new_portfolio_send(){	
		$('#new_portfolio_form_table').hide();
		$('#loading_img_new').show();
		$.post('portfolio_function.php', $("#add_portfolio_form").serialize(),
			function(data){
				$('#loading_img_new').hide();
				if(data == 'OK'){ 
					$('#new_portfolio_form_table').show();
					$('#new_portfolio_form_table input[name="portfolio_name"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_dictors"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_track"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_track_file"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_img"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_img_file"]').val('');
					$('#new_portfolio_form_table input[name="portfolio_URL"]').val('');
					alert("Даные внесены");
				}
				else{ $('#new_dictor_form_table').show(); alert(data);}
			 });
	 
}	

function edit_portfolio_send(){	
		$('#edit_portfolio_form_table').hide();
		$('#loading_img_edit').show();
		$.post('portfolio_function.php', $("#edit_portfolio_form").serialize(),
			function(data){
				$('#loading_img_edit').hide();
				if(data == 'OK'){ 
					$('#edit_portfolio_form_table').show();
					alert("Даные внесены");
				}
				else{ $('#edit_portfolio_form_table').show(); alert(data);}
			 });
	 
}
