function TrimString(sInString){
	sInString = sInString.replace(/ /g, '');
	return sInString.replace(/(^\s+)|(\s+$)/g, "");
}

function process_faq_form(){	isError = false;

	element = 'faq_subject';
	stringValue = $('#'+element).val();	if(TrimString(stringValue) == ''){		$('#'+element+'_area').addClass('faq_form_item_warning');
		isError = true;	}
    element = 'faq_text';
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('faq_form_item_warning_textarea');
		isError = true;
	}
	element = 'faq_fullname';
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('faq_form_item_warning');
		isError = true;
	}

	element = 'faq_phone';
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('faq_form_item_warning');
		isError = true;
	}

	element = 'faq_email';
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('faq_form_item_warning');
		isError = true;
	}

	element = 'faq_protectcode';
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('faq_form_item_warning');
		isError = true;
	}

	return ! (isError);}

function FormClick(){
	if(process_faq_form() == true){
		var str = $("#myForm").serialize();
		$.post("templates/process_faq_form.php", str, displayAddQuestionResult);
	} else {
		//alert("not send");
	}
}

function displayAddQuestionResult(data){
	//alert(data + '\n'+data.length);
	answerCode = '';
	if(data.length >= 2){		answerCode = data.substring(0,2);	}

	switch(answerCode){		case 'OK':
			faq_last_added = data.substring(2, data.length);
			//alert(faq_last_added);
			show_faq_success_message();
			append_faq_by_id('faq_content', faq_last_added);
			break;
		case 'ER':
            items = data.substring(2, data.length);
            wrong_items = items.split('\n');
            show_faq_warnings(wrong_items);
			break;
		case 'DE':
			message = data.substring(2,data.length);
            $('#errorPlace').html(message);
			break;	}}

function append_faq_by_id(placeid, faqid){
	$.get('templates/get_faq_by_id.php', {qid: faqid}, function(data){
    	$('#'+placeid).prepend(data);
  	});}

function show_faq_warnings(warningsid){	for(i=0; i<warningsid.length; i++){		if(warningsid[i] == 'faq_text'){
			$('#'+warningsid[i]+'_area').addClass('faq_form_item_warning_textarea');
		} else {
			$('#'+warningsid[i]+'_area').addClass('faq_form_item_warning');
		}
		//$('#'+warningsid[i]+'_wrong').attr('class', 'yes_display');	}}

function hide_warning(warningid){	if($('#'+warningid).val() != ''){		if(warningid == 'faq_text'){			$('#'+warningid+'_area').removeClass('faq_form_item_warning_textarea');		} else {			$('#'+warningid+'_area').removeClass('faq_form_item_warning');
		}
	}}

function show_faq_success_message(){	$('#faqSccessAddedPlace').css('display', 'block');
	hide_faq_form();
	$('form')[0].reset();}

function show_faq_form(){	$('form')[0].reset();
	//$('#myForm').css('display', 'block');
	$("#myForm").fadeIn("normal");
	//$("#myForm").slideDown("slow");


	$('#faqSccessAddedPlace').css('display', 'none');
	$('#faqInternalErrorTextPlace').css('display', 'none');
	$('#add_faq_button').css('display', 'none');}

function hide_faq_form(){
   $('#myForm').css('display', 'none');
   $('#add_faq_button').css('display', 'block');
}

function hide_faq_answers(answid){	$('#hide_'+answid+'_answ').fadeOut("normal", function(){
		$('#show_'+answid+'_answ').fadeIn("normal", function(){
			$('#answer_for_'+answid).fadeOut("normal");
		});
	});}
function show_faq_answers(answid){    //$('#hide_'+answid+'_answ').fadeIn("slow");
    //$('#show_'+answid+'_answ').fadeOut("slow");

	$('#show_'+answid+'_answ').fadeOut("normal", function(){
		$('#hide_'+answid+'_answ').fadeIn("normal", function(){
			$('#answer_for_'+answid).fadeIn("normal");
		});
	});
}

function resend_registration_form(){
	$('#result_place_error').fadeOut('normal', function(){
		$('#reg_submiting_form_waiting').fadeIn('normal', function(){
			check_registration_form();
		});
	});

}

function check_registration_form(){
	//alert('call : check_registration_form()');

	$(":text").removeAttr('disabled');
	$(":password").removeAttr('disabled');

	var str = $("#registration_form").serialize();
//alert(str);


	isError = false;
	all_element = new Array();
	element = 'reg_name';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_address';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_phone';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_http';
	all_element.push(element);


	element = 'reg_email';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_anons';
	all_element.push(element);


	element = 'reg_login';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_passw';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_bbcode';
	all_element.push(element);
	stringValue = $('#'+element).val();
	if(TrimString(stringValue) == ''){
		$('#'+element+'_area').addClass('reg_value_wrong');
		isError = true;
	} else {
		$('#'+element+'_area').removeClass('reg_value_wrong');
	}

	element = 'reg_submit';
	all_element.push(element);

	if(isError == false){
		//$('#reg_submiting_form_waiting').removeClass('no_display');
		$('#reg_submiting_form_waiting').fadeIn('normal');

		for(i=0; i<all_element.length; i++){
			$('#'+all_element[i]).attr('disabled', 'disabled');
		}
		//alert(str);
		$.post("actions/registration.php", str, displayRegistrationResult);
	}
}

function displayRegistrationResult(data){
	//alert(data);
	answerCode = '';
	if(data.length >= 2){
		answerCode = data.substring(0,2);
	}

	switch(answerCode){
		case 'RD':
			items = data.substring(2, data.length);
			wrong_items = items.split('\n');
			show_reg_warnings_notequal(wrong_items);

		case 'ER':
            items = data.substring(2, data.length);
            wrong_items = items.split('\n');
            show_reg_warnings(wrong_items);
			break;
		case 'DE':
			$("#reg_submit").removeAttr('disabled');
			message = data.substring(2,data.length);
            $('#result_place_error_text').html(message);
            $('#reg_submiting_form_waiting').fadeOut('normal', function(){
            	$('#registration_form').fadeOut('normal', function(){
            		$('#result_place_error').fadeIn('normal');
            	});
            });
            //$('#result_place').fadeIn('slow');
			break;
		case 'OK':
			message = data.substring(2,data.length);
			show_reg_success(message);
            //$('#result_place').html(message);
			break;
		default:
			show_reg_warnings(new Array());
	}
}

function show_reg_success(message){
	$('#result_place_success_text').html(message);
    $('#reg_submiting_form_waiting').fadeOut('normal', function(){
    	$('#registration_form').fadeOut('normal', function(){
    		$('#result_place_success').fadeIn('normal');
    	});
    });
}

function show_reg_warnings(items){
	$('#reg_submiting_form_waiting').fadeOut('fast');

	$(":text").removeAttr('disabled');
	$(":password").removeAttr('disabled');
	$("#reg_submit").removeAttr('disabled');

	for(i=0; i<items.length; i++){
		$('#'+items[i]+'_area').addClass('reg_value_wrong');
	}
}

function show_reg_warnings_notequal(wrong_items){

	show_reg_warnings(wrong_items);

	var requiredFieldsImg = new Array('reg_email', 'reg_login');
	try{
		for(i=0; i < requiredFieldsImg.length; i++){

			if(my_in_array(requiredFieldsImg[i], wrong_items) == true){
				$('#'+requiredFieldsImg[i]+'_status').attr('src', 'images/question_no.jpg');
			} else {
				$('#'+requiredFieldsImg[i]+'_status').attr('src', 'images/question_ok.jpg');
			}
		}
	} catch(e) {
		alert(e.toString());
	}


}

function show_reg_form(){
	$('#reg_submiting_form_waiting').fadeOut('fast');

	$(":text").removeAttr('disabled');
	$(":password").removeAttr('disabled');
	$("#reg_submit").removeAttr('disabled');

	$('#result_place_error').fadeOut('normal', function(){
    	$('#registration_form').fadeIn('normal');
    });
}

function show_reg_category(){

	$('#expand_reg_category_list_control').fadeOut("normal", function(){
		$('#colaps_reg_category_list_control').fadeIn('normal', function(){
			$('#reg_category_list').slideDown("normal");
		});
	});
}

function hide_reg_category(){
	$('#reg_category_list').slideUp("normal", function(){
		$('#colaps_reg_category_list_control').fadeOut("normal", function(){
			$('#expand_reg_category_list_control').fadeIn('normal');
		});
	});
	/*$('#reg_category_list').slideUp("normal", function(){
		$('#expand_reg_category_list_control').fadeIn("normal");
	});*/
}

function my_in_array(needle, haystack) {
    var found = false;

    for (mia_i=0; mia_i<haystack.length; mia_i++) {
        if ( haystack[mia_i] == needle ) {
            found = true;
            break;
        }
    }

    return found;
}

function set_no_not_check(elid){
	var ell = elid.getAttribute('id');
	$('#'+ell+'_status').attr('src', 'images/question.jpg');
}

function reg_check_email(){

}

function reg_check_passw(){

}

function check_authority(){
	hide_authority_warning();
	$(":text").attr('disabled', 'disabled');
	$(":password").attr('disabled', 'disabled');
	$("#auth_submit").attr('disabled', 'disabled');
	hide_authority_warning_srv();

	var auth_notready = false;
	if(TrimString($('#auth_login')[0].value) == ''){
		auth_notready = true;
	}

	if(TrimString($('#auth_password')[0].value) == ''){
		auth_notready = true;
	}

	if(auth_notready == true){
		show_authority_warning();

		$(":text").removeAttr('disabled');
		$(":password").removeAttr('disabled');
		$("#auth_submit").removeAttr('disabled');

	} else {
		$('#auth_submiting_form_waiting').fadeIn('normal' , function(){
			$.post("actions/make_me_auth.php", { auth_login: $('#auth_login')[0].value, auth_password: $('#auth_password')[0].value }, function(data){
				//alert('Data : '+data);
				$('#auth_submiting_form_waiting').fadeOut('normal', function(){
					$(":text").removeAttr('disabled');
					$(":password").removeAttr('disabled');
					$("#auth_submit").removeAttr('disabled');

					answerCode = '';
					if(data.length >= 2){
						answerCode = data.substring(0,2);
					}
					//alert('answerCode : '+answerCode);
					switch(answerCode){
						case 'ER':
							show_authority_warning();
							break;
						case 'NF':
							message = data.substring(2,data.length);
				            show_authority_warning_srv(message);
							break;
						case 'NC':
							//alert('answerCode : '+answerCode);
							message = data.substring(2,data.length);
							//alert('message : '+message);
				            show_authority_warning_srv(message);
							break;
						case 'OK':
							message = data.substring(2,data.length);
							//show_authority_warning_srv(message);
							//alert('Page contents : ' + message);
							update_page_contents('auth_content', message);
							//alert('Page contents : ' + message);
					}
				});
			});
		});
	}
}

function show_authority_warning(){
	$('#wrong_auth_text').fadeIn('normal');
}

function hide_authority_warning(){
	$('#wrong_auth_text').fadeOut('normal');
}

function show_authority_warning_srv(message){
	$('#wrong_auth_text_srv').html(message);
	$('#wrong_auth_text_srv').fadeIn('normal');
}

function hide_authority_warning_srv(){
	$('#wrong_auth_text_srv').fadeOut('normal');
}

function update_page_contents(page_place, content){
	//alert(content);

	location.href = "index.php?mod=myprof";
	return false;

	$('#'+page_place).fadeOut('fast' , function(){
		$('#'+page_place).html(message);
		$('#'+page_place).fadeIn('fast');
	});
}


function make_account_recovery(){
	hide_authority_warning();
	hide_authority_message_srv();
	hide_authority_warning_srv();

	$(":text").attr('disabled', 'disabled');
	$(":password").attr('disabled', 'disabled');
	$("#auth_submit").attr('disabled', 'disabled');


	$('#auth_submiting_form_waiting').fadeIn('normal', function(){
		$.post("actions/recovery_password.php", { auth_login: $('#auth_login')[0].value}, function(data){
			$('#auth_submiting_form_waiting').fadeOut('normal', function(){
				//alert('Data : '+data);
				$(":text").removeAttr('disabled');
				$(":password").removeAttr('disabled');
				$("#auth_submit").removeAttr('disabled');

				answerCode = '';
				if(data.length >= 2){
					answerCode = data.substring(0,2);
				}
				//alert('answerCode : '+answerCode);
				switch(answerCode){
					case 'OK':
						message = data.substring(2,data.length);
						//alert('message : '+message);
			            show_authority_message_srv(message);
						break;
					case 'ER':
						message = data.substring(2,data.length);
						show_authority_warning_srv(message);
						break;
					default:
						show_authority_warning_srv('Код відповіді не передбачений. Спробуйте пізніше...'); //Дія завершилась помилкою
						break;
				}
			});
		});
	});

}

function show_authority_message_srv(message) {
	$('#message_auth_text_srv').html(message);
	$('#message_auth_text_srv').fadeIn('normal');
}

function hide_authority_message_srv() {
	$('#message_auth_text_srv').fadeOut('normal');
}

function show_profile_tab(num, all){
	//alert('show_profile_tab');
	for(pti=1; pti<=all; pti++){
		if(pti != num && $('#tab'+pti).css('display') == 'block'){
			$('#img_bab_'+pti).attr('src', 'images/prof_but_'+pti+'.png');
			//$('#img_bab_'+pti).attr('height', 32);
			//$('#img_bab_'+pti).attr('width', 32);

			$('#tab'+pti).fadeOut('normal', function(){
				$('#img_bab_'+num).attr('src', 'images/prof_but_'+num+'a.png');
				//$('#img_bab_'+num).attr('height', 52);
				//$('#img_bab_'+num).attr('width', 52);
				$('#tab'+num).fadeIn('normal');
			});
		}
	}

	if(num == 5 || num == 6){		document.getElementById('profile_submit_buton').style.display = 'none';
		$('#profile_submit_buton_area').removeClass('border_hor_top');	} else {
		document.getElementById('profile_submit_buton').style.display = 'block';
		$('#profile_submit_buton_area').addClass('border_hor_top');	}
}

function save_profile_form(){
	countTabs = $('[id^="tab"]').size();
	//alert(countTabs);
	spf_found = 0;
	for(spf_i=1; spf_i<=countTabs; spf_i++){
		//alert('#tab'+spf_i);
		if( $('#tab'+spf_i).css('display') == 'block'){
			spf_found = spf_i;
		}
	}

	switch(spf_found){
		case 1:
			save_profile_tab1();
			break;
		case 2:			
			save_profile_tab2();
			break;
		case 3:
			save_profile_tab3();
			break;
		case 4:
			save_profile_tab4();
			break;

		default:
			alert('Not defined processing unit for actions');
	}
}

function save_profile_tab1(){

	profile_groups = '';
	count_spt = $('[name^="profile_catid_"]').size();
	for(spt_i=1; spt_i<=count_spt; spt_i++){
		if($('#profile_catid_'+spt_i).attr('checked') == true){
			if(profile_groups != ''){
				profile_groups += ',';
			}
			profile_groups += $('#profile_catid_'+spt_i).val();
		}
	}

	$.post('actions/profile_save_part_1.php',
			{
				profile_name: $('#profile_name').val(),
				profile_http: $('#profile_http').val(),
				profile_email: $('#profile_email').val(),
				profile_anons: $('#profile_anons').val(),
				profile_groupid: profile_groups
			}, function(data){
				//alert(data);
				code = '';
				if(data.length >= 2){
					code = data.substring(0,2);
				}

				switch(code){
					case 'OK':
					case 'NF':
					case 'NL':
						message = data.substring(2,data.length);
						alert(message);
						break;

					default:
						alert('Помилка! Невизначений код відповіді');
				}
	});
}

function save_profile_tab2(){

	var oEditor = FCKeditorAPI.GetInstance('profile_about');
	
	$.post('actions/profile_save_part_2.php',
			{
				profile_about: oEditor.GetData()
			}, function(data){
				//alert(data);
				code = '';
				if(data.length >= 2){
					code = data.substring(0,2);					
				}

				switch(code){
					case 'OK':
					case 'NF':
					case 'NL':
						message = data.substring(2,data.length);
						alert(message);
						break;

					default:
						alert('Помилка! Невизначений код відповіді');
				}
	});
}

function save_profile_tab3(){
	phone_array = $('[name^="profile_phone_"]').get();
	count_spt_phone = phone_array.length;

	email_array = $('[name^="profile_email_"]').get();
	count_spt_email = email_array.length;

	ipager_array_mod = $('[name^="profile_ipager_type_"]').get();
	ipager_array_num = $('[name^="profile_ipager_num_"]').get();
	count_spt_ipager = ipager_array_num.length;

	string_spt_phone = '';
	for(spt_3 = 1; spt_3 <= count_spt_phone; spt_3++){
		if(string_spt_phone != ''){
			string_spt_phone += ',';
		}
		string_spt_phone += $(phone_array[spt_3-1]).val();
	}

	string_spt_email = '';
	for(spt_3 = 1; spt_3 <= count_spt_email; spt_3++){
		if(string_spt_email != ''){
			string_spt_email += ',';
		}
		string_spt_email += $(email_array[spt_3-1]).val();
	}

	string_spt_ipager_mod = '';
	string_spt_ipager_num = '';
	for(spt_3 = 1; spt_3 <= count_spt_ipager; spt_3++){
		if(string_spt_ipager_mod != ''){
			string_spt_ipager_mod += ',';
			string_spt_ipager_num += ',';
		}
		string_spt_ipager_mod += $(ipager_array_mod[spt_3-1]).val();
		string_spt_ipager_num += $(ipager_array_num[spt_3-1]).val();
	}

	//alert(count_spt_phone + ' : ' + count_spt_email + ' : ' + count_spt_ipager);

	$.post('actions/profile_save_part_3.php',
			{
				profile_phones: string_spt_phone,
				profile_emails: string_spt_email,
				profile_ipager_mods: string_spt_ipager_mod,
				profile_ipager_numbers: string_spt_ipager_num
			}, function(data){
				//alert(data);
				code = '';
				if(data.length >= 2){
					code = data.substring(0,2);
				}

				switch(code){
					case 'OK':
					case 'NF':
					case 'NL':
						message = data.substring(2,data.length);
						alert(message);
						break;

					default:
						alert('Помилка! Невизначений код відповіді');
				}
	});
}

function save_profile_tab4(){
	//alert('CALL : save_profile_tab4()');
	$.post('actions/profile_save_part_4.php',
			{
				profile_login_change: ( ($('#leave_old_password').attr('checked') == true) ? 'false' : 'true'),
				profile_old_pass: $('#profile_old_pass').val(),
				profile_new_pass: $('#profile_new_pass').val(),
				profile_new_pass_confirm: $('#profile_new_pass_confirm').val()
			}, function(data){
				//alert(data);
				code = '';
				if(data.length >= 2){
					code = data.substring(0,2);
				}

				switch(code){
					case 'OK':
					case 'NF':
					case 'NL':
					case 'SE':
					case 'SE':
					case 'PN':
					case 'PW':
					case 'LE':
						message = data.substring(2,data.length);
						alert(message);
						break;

					default:
						alert('Помилка! Невизначений код відповіді : '+code);
				}
	});
}

function add_phones(div_area){

	found = 0;
	index = 1;
	do {
		count_exist = $('[id="user_phone_'+index+'"]').size();
		if(count_exist == 0){
			found = index;
			//alert('found at '+found);
		}

		index = index+1;

		if(index > 1000){
			alert('Not found');
			break;
		}
	} while (found == 0);


	block_add = '<div id="user_phone_'+found+'" class="marg_bot_8"><div class="phone_list_item">Номер телефону:</div><input id="profile_phone_'+found+'" name="profile_phone_'+found+'" type="text" value="" class="marg_right_10"><a href="" onclick=" return false;"><img src="images/delete.gif" width="16" height="16" alt="" border="0" onclick="delete_phone_item(\'user_phone_'+found+'\')"/></a></div>';
	//alert(div_area + block_add);
	$('#'+div_area).append(block_add);

	//alert($('#'+div_area).css('display'));
	if($('#'+div_area).css('display') == 'none'){
		$('#phone_list_empty').fadeOut('normal', function(){
			$('#'+div_area).fadeIn();
		});
	}

}

function add_emails(div_area){
	found = 0;
	index = 1;
	do {
		count_exist = $('[id="user_email_'+index+'"]').size();
		if(count_exist == 0){
			found = index;
			//alert('found at '+found);
		}

		index = index+1;

		if(index > 1000){
			alert('Not found');
			break;
		}
	} while (found == 0);

	//return false;
	block_add = '<div id="user_email_'+found+'" class="marg_bot_8"><div class="phone_list_item">Адреса email:</div><input id="profile_email_'+found+'" name="profile_email_'+found+'" type="text" value="" class="marg_right_10 profile_email"><a href="" onclick=" return false;"><img src="images/delete.gif" width="16" height="16" alt="" border="0" onclick="delete_email_item(\'user_email_'+found+'\')"/></a></div>';
	$('#'+div_area).append(block_add);

	if($('#'+div_area).css('display') == 'none'){
		$('#email_list_empty').fadeOut('normal', function(){
			$('#'+div_area).fadeIn();
		});
	}
}

function add_inetpagers(div_area){
	found = 0;
	index = 1;
	do {
		count_exist = $('[id="user_inetpager_'+index+'"]').size();
		if(count_exist == 0){
			found = index;
			//alert('found at '+found);
		}

		index = index+1;

		if(index > 1000){
			alert('Not found free tag');
			break;
		}
	} while (found == 0);

	//return false;
	block_add = '<div id="user_inetpager_'+found+'" class="marg_bot_8"><span class="ipager_list_item_type">Тип:</span><input id="profile_ipager_type_'+found+'" name="profile_ipager_type_'+found+'" type="text" value="" class="marg_right_10 profile_ipager"><span class="ipager_list_item_num">Номер:</span><input id="profile_ipager_num_'+found+'" name="profile_ipager_num_'+found+'" type="text" value="" class="marg_right_10"><a href="" onclick=" return false;"><img src="images/delete.gif" width="16" height="16" alt="" border="0" onclick="delete_inetpager_item(\'user_inetpager_'+found+'\')"/></a></div>';
	$('#'+div_area).append(block_add);

	if($('#'+div_area).css('display') == 'none'){
		$('#inetpagers_list_empty').fadeOut('normal', function(){
			$('#'+div_area).fadeIn();
		});
	}
}

function delete_phone_item(item){
	//alert('delete -> '+item);

	count_exist = $('[id^="user_phone_"]').size();
	//alert(count_exist);
	fadeList = false;
	if(count_exist == 1){
		fadeList = true;
	}

	if(confirm('Дійсно бажаєте видалити номер') == true){
		if(fadeList == true){
			$('#addit_phones').fadeOut('normal', function(){
				$('#phone_list_empty').fadeIn('normal', function(){
					$('#'+item).remove();
				});
			});
		} else {
			$('#'+item).fadeOut('normal', function(){
				$('#'+item).remove();
			});
		}
	}
}

function delete_email_item(item){
	//alert('delete -> '+item);
	count_exist = $('[id^="user_email_"]').size();

	fadeList = false;
	if(count_exist == 1){
		fadeList = true;
	}

	if(confirm('Дійсно бажаєте видалити адресу email') == true){
		if(fadeList == true){
			$('#addit_emails').fadeOut('normal', function(){
				$('#email_list_empty').fadeIn('normal', function(){
					$('#'+item).remove();
				});
			});
		} else {
			$('#'+item).fadeOut('normal', function(){
				$('#'+item).remove();
			});
		}
	}
}

function delete_inetpager_item(item){
	//alert('delete -> '+item);
	count_exist = $('[id^="user_inetpager_"]').size();

	fadeList = false;
	if(count_exist == 1){
		fadeList = true;
	}

	if(confirm('Дійсно бажаєте видалити параметри пейджера') == true){
		if(fadeList == true){
			$('#addit_inetpagers').fadeOut('normal', function(){
				$('#inetpagers_list_empty').fadeIn('normal', function(){
					$('#'+item).remove();
				});
			});
		} else {
			$('#'+item).fadeOut('normal', function(){
				$('#'+item).remove();
			});
		}
	}
}

function change_password_profile_visibility(call_chbox_element){
	if(document.getElementById('leave_old_password').checked == false){
		$('#profile_change_password_area').fadeIn('normal');
		$('#profile_old_pass').removeAttr('disabled');
		$('#profile_old_pass').val('');
		$('#profile_new_pass').removeAttr('disabled');
		$('#profile_new_pass_confirm').removeAttr('disabled');
	} else {
		$('#profile_change_password_area').fadeOut('normal');
		$('#profile_old_pass').attr('disabled', 'disabled');
		$('#profile_old_pass').val('********');
		$('#profile_new_pass').attr('disabled');
		$('#profile_new_pass_confirm').attr('disabled');
	}
}

function make_me_logout(){	//alert('CALL make_me_logout()');
	$.post("actions/make_me_logout.php", "", function(data){
		//alert('Data : '+data);
		if(data == "LOGOUT_OK"){        	/*
        	$('#auth_submiting_form_waiting').fadeOut('normal', function(){
				$(":text").removeAttr('disabled');
				$(":password").removeAttr('disabled');
				$("#auth_submit").removeAttr('disabled');

				location.href = 'index.php?mod=myprof';
			});
			*/
			location.href = 'index.php?mod=myprof';		} else if(data == "LOGOUT_ERROR"){        	location.href = 'index.php?mod=myprof';		} else {			location.href = 'index.php?mod=myprof';		}
	});}

function update_videogallery(){//	alert('CALL : update_videogallery()');

	$('#vgallery_update_content_area').fadeOut('normal', function(){		$('#vgallery_update_waiting').fadeIn('normal', function(){			$.post("actions/show_user_vgalleries.php", null, function(data){
				if(data == 'NEED_REFRESH'){
					location.href = 'index.php?mod=myprof';
				} else {					$('#vgallery_update_content').html(data);
					$('#vgallery_update_waiting').fadeOut('normal', function(){
						$('#vgallery_update_content_area').fadeIn('normal', function(){
                            ;
						});
					});
				}
			});		});	});}

function update_fotogallery(galID){	//alert('call -> update_fotogallery('+galID+')');

	$('#fgallery'+galID+'_items_list_empty').fadeOut('normal', function(){		$('#fgallery'+galID+'_items_list_content').fadeOut('normal', function(){
			$('#fgallery'+galID+'_items_list_waiting').fadeIn('normal', function(){				$.post("actions/show_user_gallery.php", {gallery : galID}, function(data){
					//alert(data);
					if(data != ''){						if(data == 'NEED_REFRESH'){							location.href = 'index.php?mod=myprof';						} else {
							$('#fgallery'+galID+'_items_list').html(data);
							$('#fgallery'+galID+'_items_list_waiting').fadeOut('normal', function(){
								//$('#fgallery'+galID+'_items_list_content').fadeIn('normal');
							});						}
					} else {						$('#fgallery'+galID+'_items_list_waiting').fadeOut('normal', function(){
							$('#fgallery'+galID+'_items_list_empty').fadeIn('normal');
						});					}
				});
			});
		});
	});}

//Переменные для окна загрузки фото
maxFGallery = 0;
maxFilesInFGallery = 0;
countFilesInGallery = new Array();
maxFGallery = 0;
maxFilesInVGallery = 0;

function delete_image(galID, imgName){	//alert('call delete_image: '+galID+':'+imgName);
	if(confirm('Дійсно бажаєте видалити файл?') == true){		$('#fgallery'+galID+'_items_list_content').fadeOut('normal', function(){			$('#fgallery'+galID+'_items_list_waiting').fadeIn('normal');		});
		$.post("actions/delete_user_gallery_file.php", {gallery : galID, file:imgName}, function(data){        	//alert(data);
        	if(data == "OK"){        		update_fotogallery(galID);        	} else if(data == "NEED_REFRESH"){        		update_page_contents();        	} else {        		alert(data);
        		update_page_contents();        	}		});	}}

function delete_video(videoID){    if(confirm('Дійсно бажаєте видалити файл?') == true){    	$('#vgallery_update_content_area').fadeOut('normal', function(){
			$('#vgallery_update_waiting').fadeIn('normal', function(){				;			});
		});
		$.post("actions/delete_user_vgallery_file.php", {fileID : videoID}, function(data){
        	//alert(data);
        	if(data == "OK"){
        		update_videogallery();
        	} else if(data.indexOf("NEED_REFRESH") != -1){
        		update_page_contents();
        	} else {
        		alert(data);
        		update_page_contents();
        	}
		});    }}

function ShowModalAddImage(GallTitle, GallIndex){	//alert(GallTitle + ':' + GallIndex);

	$('#CreateGallery_GalleryItem_CError').css( 'display', 'none' );
    $('#CreateGallery_GalleryItem_SError').css( 'display', 'none' );
    $('#CreateGallery_GalleryItemSrcReq').removeClass('modal_error');

	document.getElementById('CreateGallery_GalName').value = GallIndex;
	document.getElementById('CreateGallery_GalName').innerHTML = GallTitle;	$('#add_image_to_gallery_modal').fadeIn('normal', function(){		//document.getElementById("block_overlay").style.display = 'block';	});
	//$('#block_overlay').fadeIn('fast');
}
function HideModalAddItemToGallery(){

	//$('#block_overlay').fadeOut('fast');
	//document.getElementById("block_overlay").style.display = 'none';
	$('#add_image_to_gallery_modal').fadeOut('normal', function(){		$('#add_gallery_items_modal_reset').click();	});
}

function ShowModalAddGallery(){
	$('#add_gallery_modal').fadeIn('normal');
}

function HideModalAddGallery(){
	$('#add_gallery_modal').fadeOut('normal', function(){		document.getElementById('CreateGallery_GalleryName_CError').style.display = 'none';
		document.getElementById('CreateGallery_GalleryName_SError').style.display = 'none';
		$('#CreateGallery_GalleryNameReq').removeClass('modal_error');

		$('#add_gallery_modal_waiting').fadeOut('normal', function(){
			$('#add_gallery_modal_content').fadeIn('normal', function(){});
		});	});
	$('#add_gallery_modal_reset').click();
}

function ShowModalAddVGalleryItem(){	$('#add_vgallery_item_modal').fadeIn('normal');
}
function HideModalAddVGalleryItem(){
	$('#CreateVGallery_GalleryItemSrcReq').removeClass('modal_error');
    $('#CreateVGallery_GalleryItemThumbsSrcReq').removeClass('modal_error');
	$('#modal_add_vgal_item_area').css('display', 'none');
	$('#add_vgallery_item_modal').fadeOut('normal', function(){
		document.getElementById('CreateVGallery_GalleryName_CError').style.display = 'none';
		document.getElementById('CreateVGallery_GalleryName_SError').style.display = 'none';
		$('#CreateVGallery_GalleryNameReq').removeClass('modal_error');

		$('#add_vgallery_item_modal_waiting').fadeOut('normal', function(){
			$('#add_vgallery_item_modal_content').fadeIn('normal', function(){});
		});
	});
	$('#add_vgallery_item_modal_reset').click();
}

function ShowModalChangeGallery(title, active, id){	//alert(title + ':' + active+':'+id);
	document.getElementById('ChangeGallery_GalleryID').value = id;
	document.getElementById('ChangeGallery_GalleryName').value = title;
	if(active == '1' || active == 1){		document.getElementById('ChangeGallery_GalleryActive').checked = true;	} else {		document.getElementById('ChangeGallery_GalleryActive').checked = false;	}
	$('#property_gallery_modal').fadeIn('normal');
}
function HideModalProperyGallery(){	$('#property_gallery_modal').fadeOut('normal', function(){
		document.getElementById('PropertyGallery_GalleryName_CError').style.display = 'none';
		document.getElementById('PropertyGallery_GalleryName_SError').style.display = 'none';
		$('#ChangeGallery_GalleryNameReq').removeClass('modal_error');

		$('#property_gallery_modal_waiting').fadeOut('normal', function(){
			$('#property_gallery_modal_content').fadeIn('normal', function(){});
		});
	});
	$('#property_gallery_modal_reset').click();}
function UpdateGallery(title, active, id){	$('#PropertyGallery_GalleryName_CError').css( 'display', 'none' );
    $('#PropertyGallery_GalleryName_SError').css( 'display', 'none' );
    $('#ChangeGallery_GalleryNameReq').removeClass('modal_error');

    $('#property_gallery_modal_content').fadeOut('normal', function(){
		$('#property_gallery_modal_waiting').fadeIn('normal', function(){        	if(TrimString(title.value) == ""){
            	document.getElementById('PropertyGallery_GalleryName_CError').style.display = 'block';
            	$('#ChangeGallery_GalleryNameReq').addClass('modal_error');
            	$('#property_gallery_modal_waiting').fadeOut('normal', function(){
					$('#property_gallery_modal_content').fadeIn('normal', function(){});
				});
			} else {
				var req = new JsHttpRequest();
				req.onreadystatechange = function() {
					//alert(req.responseText);
					if (req.readyState == 4) {

						if(req.responseText == 'OK'){
							HideModalProperyGallery();
							UpdateFotoGalleries();
						} else {
							//alert(req.responseText);

							$('#PropertyGallery_GalleryName_SError').html(req.responseText);
							document.getElementById('PropertyGallery_GalleryName_SError').style.display = 'block';

							$('#property_gallery_modal_waiting').fadeOut('normal', function(){
								$('#property_gallery_modal_content').fadeIn('normal', function(){});
							});
						}
					}
				}
			    req.open(null, 'actions/create_gallery.php', true);
	   			req.send( { GN: title, GM:"update", GA: active, GID:id} );			}		});
	});}

function DeleteGallery(id){	if(confirm('Ви дійсно бажаєте видалити галерею?') == true){		var req = new JsHttpRequest();
		req.onreadystatechange = function() {
			//alert(req.responseText);
			if (req.readyState == 4) {

				if(req.responseText == 'OK'){
					HideModalProperyGallery();
					UpdateFotoGalleries();
				} else {
					//alert(req.responseText);
					UpdateFotoGalleries();
				}
			}
		}
	    req.open(null, 'actions/create_gallery.php', true);
  		req.send( { GM:'delete', GID:id} );	}}

function CreateGallery(GalleryName){	//alert(GalleryName);

    $('#CreateGallery_GalleryName_CError').css( 'display', 'none' );
    $('#CreateGallery_GalleryName_SError').css( 'display', 'none' );
    $('#CreateGallery_GalleryNameReq').removeClass('modal_error');
	$('#add_gallery_modal_content').fadeOut('normal', function(){		$('#add_gallery_modal_waiting').fadeIn('normal', function(){
			if(TrimString(GalleryName.value) == ""){
            	document.getElementById('CreateGallery_GalleryName_CError').style.display = 'block';
            	$('#CreateGallery_GalleryNameReq').addClass('modal_error');
            	$('#add_gallery_modal_waiting').fadeOut('normal', function(){
					$('#add_gallery_modal_content').fadeIn('normal', function(){});
				});
			} else {

				var req = new JsHttpRequest();
				req.onreadystatechange = function() {					if (req.readyState == 4) {
						if(req.responseText == 'OK'){							HideModalAddGallery();
							UpdateFotoGalleries();						} else {							//alert(req.responseText);
							$('#CreateGallery_GalleryName_SError').html(req.responseText);
							document.getElementById('CreateGallery_GalleryName_SError').style.display = 'block';

							$('#add_gallery_modal_waiting').fadeOut('normal', function(){
								$('#add_gallery_modal_content').fadeIn('normal', function(){});
							});						}
					}				}
			    req.open(null, 'actions/create_gallery.php', true);
	   			req.send( { GN: GalleryName } );
			}		});	});}

function UpdateFotoGalleries(){	$('#foto_galeries_content_block').fadeOut('normal', function(){
		$('#foto_galleries_waiting_block').fadeIn('normal', function(){

            $.get("actions/show_user_galleries.php", function(data){
				$('#foto_galeries_content_block').html(data);
				$('#foto_galleries_waiting_block').fadeOut('normal', function(){
					$('#foto_galeries_content_block').fadeIn('normal', function(){});
				});
				//alert("Data Loaded: " + data);
			});

			/*
        	var req = new JsHttpRequest();
			req.onreadystatechange = function() {				//alert(req.readyState);
				if (req.readyState == 4) {

					alert(req.responseText);
    				//$('#CreateGallery_GalleryName_SError').html(req.responseText);
					//document.getElemntById('CreateGallery_GalleryName_SError').style.display = 'block';

					$('#add_gallery_modal_waiting').fadeOut('normal', function(){
						$('#add_gallery_modal_content').fadeIn('normal', function(){});
					});

				}
			}
		    req.open(null, 'actions/show_user_galleries.php', false);
   			req.send( { isf:"" } );
   			*/
		});
	});}

function AddItemToVGallery(VideoFile, VideoFileThumbs, VideoTitle){	$('#CreateVGallery_GalleryName_CError').css( 'display', 'none' );
    $('#CreateVGallery_GalleryName_SError').css( 'display', 'none' );
    $('#CreateVGallery_GalleryItemSrcReq').removeClass('modal_error');
    $('#CreateVGallery_GalleryItemThumbsSrcReq').removeClass('modal_error');

    $('#add_vgallery_item_modal_content').fadeOut('normal', function(){
		$('#add_vgallery_item_modal_waiting').fadeIn('normal', function(){            if(VideoFile.value == '' || VideoFileThumbs.value == ''){
				if(VideoFile.value == ''){					$('#CreateVGallery_GalleryItemSrcReq').addClass('modal_error');				}
				if(VideoFileThumbs.value == ''){					$('#CreateVGallery_GalleryItemThumbsSrcReq').addClass('modal_error');				}

				$('#CreateVGallery_GalleryName_CError').css( 'display', 'block' );
				$('#add_vgallery_item_modal_waiting').fadeOut('normal', function(){
					$('#add_vgallery_item_modal_content').fadeIn('normal', function(){
						return false;
					});
				});
			} else {				var req = new JsHttpRequest();

			    req.onreadystatechange = function() {                	 if (req.readyState == 4) {
			            //alert(req.responseText);
			            $('#add_vgallery_item_modal_waiting').fadeOut('normal', function(){
							$('#add_vgallery_item_modal_content').fadeIn('normal', function(){

					            if(req.responseText == 'NEED_UPDATE'){
					            	HideModalAddVGalleryItem();
					            	update_videogallery();
					            } else {
					            	//alert('Помилка: '+req.responseText);
					            	$('#CreateVGallery_GalleryName_SError').html(req.responseText);
									document.getElementById('CreateVGallery_GalleryName_SError').style.display = 'block';
					            }

                        	});
						});
			        }			    }

			    req.open(null, 'actions/upl_video_backend.php', true);
			    req.send( { q: VideoFile, qTh: VideoFileThumbs, VideoTitle:VideoTitle} );			}		});
	});}

function AddItemToGallery(FotoGallID, FotoFile, FotoTitle) {

    $('#CreateGallery_GalleryItem_CError').css( 'display', 'none' );
    $('#CreateGallery_GalleryItem_SError').css( 'display', 'none' );
    $('#CreateGallery_GalleryItemSrcReq').removeClass('modal_error');

	$('#add_image_to_gallery_modal_content').fadeOut('normal', function(){
		$('#add_image_gallery_modal_waiting').fadeIn('normal', function(){			if(FotoFile.value == ''){
				$('#CreateGallery_GalleryItemSrcReq').addClass('modal_error');
				$('#CreateGallery_GalleryItem_CError').css( 'display', 'block' );
				$('#add_image_gallery_modal_waiting').fadeOut('normal', function(){
					$('#add_image_to_gallery_modal_content').fadeIn('normal', function(){						return false;					});
				});
			} else {

			    var req = new JsHttpRequest();
			    var gid = FotoGallID.value;
				//alert(FotoGallID.value+':'+FotoTitle.value);
				//return false;

			    req.onreadystatechange = function() {
			        //alert('readyState:' + req.readyState);
			        if (req.readyState == 4) {
			            //alert(req.responseText);
			            $('#add_image_gallery_modal_waiting').fadeOut('normal', function(){
							$('#add_image_to_gallery_modal_content').fadeIn('normal', function(){

					            if(req.responseText == 'NEED_UPDATE'){
					            	HideModalAddItemToGallery();
					            	update_fotogallery(gid);					            } else {					            	//alert('Помилка: '+req.responseText);
					            	$('#CreateGallery_GalleryItem_SError').html(req.responseText);
									document.getElementById('CreateGallery_GalleryItem_SError').style.display = 'block';					            }

                        	});
						});
			        }
			    }

			    req.open(null, 'actions/upl_backend.php', true);

			    req.send( { q: FotoFile, gallery: FotoGallID, ImgTitle:FotoTitle} );
		    }
	    });
	});
}

function colapse_addit_modal(galleryID){	$('#addition_gallery_'+galleryID).slideUp();
	document.getElementById('addition_gallery_button_'+galleryID).src='images/modal_bd_action_expand.jpg';}

function colapse_expand_addit_modal(galleryID){	if($('#addition_gallery_'+galleryID).css('display') == 'block'){		$('#addition_gallery_'+galleryID).slideUp();
		document.getElementById('addition_gallery_button_'+galleryID).src='images/modal_bd_action_expand.jpg';
	} else {
		$('#addition_gallery_'+galleryID).slideDown();
		document.getElementById('addition_gallery_button_'+galleryID).src='images/modal_bd_action_collapse.jpg';
	}}

function reload_video(filePlayer, thumbs, moviefile){	var player = '<object type="application/x-shockwave-flash" data="'+filePlayer+'" height="383.06666666667" width="450"><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="false" /><param name="allowScriptAccess" value="always" /><param name="movie" value="'+filePlayer+'" /><param name="FlashVars" value="way='+moviefile+'&amp;swf='+filePlayer+'&amp;w=450&amp;h=383.06666666667&amp;pic='+thumbs+'&amp;autoplay=0&amp;tools=1&amp;skin=whitegrey&amp;volume=50&amp;q=&amp;comment=" /></object>';


	$('#video_player').css('display', 'none');
	$('#video_player_waiting').css('display', 'block');

	$('#video_player').html(player);
	$('#video_player').css('display', 'block');
	$('#video_player_waiting').css('display', 'none');


	//document.getElementById('video_player').innerHTML = strOutput;
	/*
	$('#video_player').fadeOut('normal', function(){
		$('#video_player_waiting').fadeIn('normal');
	});

	alert('Show');

	$('#video_player_waiting').fadeOut('normal', function(){
		$('#video_player').fadeIn('normal');
	});

	$('#video_player_waiting').fadeOut('normal', function(){
		$('#video_player').fadeIn('normal');
	});
	*/}

function search_ents(words){	alert('CALL : search_ents ->'+words);}