
//Исполнитель отправки форм

indicator_image = new Image();
indicator_image.src = "/_img/indicator.gif";

function ajax_send_feedback() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_feedback.php";
	sr.form_tag = "form_feedback";
	sr.accept_tag = "frame_feedback";
	sr.error_tag = "frame_feedback_error";
	sr.send();
}


function ajax_send_registration() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_registration.php";
	sr.form_tag = "form_registration";
	sr.accept_tag = "frame_accept";
	sr.error_tag = "error_message";

	sr.add_accept_function = function(accept_text) {
		alert(accept_text);
		$("#frame_registration").html('<h2>'+accept_text+'<h2>'+"<br/><img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите...");
		location.href = "/profile";
	}
	sr.send();
}
function sent_authorization() {
 	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_authorization.php";
	sr.form_tag = "form_authorization";
	sr.accept_tag = "result_authorization_string";
	sr.error_tag = "result_authorization_string";
	sr.type_res = "obj";

	sr.add_accept_function_obj = function(xml) {
		$("#frame_authorization").html($("glob_message", xml).text()+"<br/><img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите, страница будет обновлена");;
		setTimeout("location.reload();", 1000);
	}
	sr.send();
}

function sent_pass() {
 	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_pass.php";
	sr.form_tag = "form_sent_pass";
	sr.accept_tag = "result_sent_pass_string";
	sr.error_tag = "result_sent_pass_string";
	sr.type_res = "obj";

	sr.add_accept_function_obj = function(xml) {
		$("#frame_sent_pass_close").css("display", "block");
		$("#frame_sent_pass").css("display", "none");

		$("#result_sent_pass_string2").html($("glob_message", xml).text());

	}
	sr.send();
}

function ajax_send_profile() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_profile.php";
	sr.form_tag = "form_profile";
	sr.accept_tag = "frame_profile";
	sr.error_tag = "error_message";

	sr.add_accept_function = function(accept_text) {
		$("#error_message").text(accept_text);
		alert(accept_text);
	}
	sr.send();
}

function ajax_send_faq() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_faq.php";
	sr.form_tag = "form_faq";
	sr.accept_tag = "frame_faq";
	sr.error_tag = "error_message";

	sr.add_accept_function = function(accept_text) {
		$("#frame_faq").text(accept_text);
		alert(accept_text);
	}
	sr.send();
}

function ajax_get_best_offers(age, numb) {
	var res_param = "&age="+age+"&numb="+numb;
	$.post("/ajax_get_best_offers.php", res_param, function(xml) {
		$("#best_offers_title").html($("data", xml).text());
	});
}

function auth_in_basket() {
	if($("input[@name = 'flag_auth']:checked").val() == 1) {
		ajax_send_registration_in_basket();
	} else {
		ajax_send_authorization_in_basket();
	}
}

function ajax_send_registration_in_basket() {
	url = '?name='+$("#or_name").val();
	url += '&email='+$("#or_email").val();
	url += '&login='+$("#or_login").val();
	url += '&password='+$("#or_pass").val();
	url += '&double_password='+$("#or_pass").val();

	url += '&control_number='+$("#or_control_number").val();
	url += '&control_code='+$("#or_control_code").val();

	url += '&flag_auth=1';
	$("#res_order_registration").html("<img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите...");
	$.post("/ajax_sent_registration.php", url, function(xml) {
		$("#res_order_registration").html($("message", xml).text());
		if ($("result_flag", xml).text() == 1) {
			str = '<img src="/_img/indicator.gif"/> Подождите перенаправления...';
			$("#res_order_registration").html($("message", xml).text()+str);
			setTimeout("location.href = '/basket/order';", 1000);
		} else {
			$("#res_order_registration").html($("glob_message", xml).text());
		}
	});
}

function ajax_send_authorization_in_basket() {
	url  = '&login='+$("#oa_login").val();
	url += '&password='+$("#oa_pass").val();
	url += '&flag_auth=1';
	$("#res_order_authorization").html("<img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите...");
	$.post("/ajax_sent_authorization.php", url, function(xml) {
		$("#res_order_authorization").html($("glob_message", xml).text());
		if ($("accept", xml).text() == 1) {
			str = '<img src="/_img/indicator.gif"/> Подождите перенаправления...';
			$("#res_order_authorization").html($("message", xml).text()+str);
			setTimeout("location.href = '/basket/order';", 1000);
		} else {
			$("#res_order_authorization").html($("glob_message", xml).text());
		}
	});

}

function ajax_send_shop_order() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_send_shop_order.php";
	sr.form_tag = "form_shop_order";
	sr.error_tag = "shop_order_error";
	sr.type_res = "obj";
	//Переопределим стадартную функцию
	sr.add_accept_function_obj = function(xml) {
		str = '<img src="/_img/indicator.gif"/> Подождите перенаправления...';
		$("#shop_order_error").html($("accept_text", xml).text()+str);
		setTimeout("location.href = '/basket/order/confirm"+"?shop_order_id="+$("shop_order_id", xml).text()+"'", 1000);

	}
	sr.send();
}

function ajax_send_subscribe() {
	
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_subscribe.php";
	sr.form_tag = "form_send_user_sub";
	sr.accept_tag = "frame_subscribe";
	sr.error_tag = "frame_subscribe";
	sr.type_res = "obj";
	
	sr.add_accept_function_obj = function(xml) {
		if ($("accept", xml).text() == 1) {
			$("#form_send_user_sub").hide();
			$("#frame_subscribe").html($("glob_message", xml).text()+'<div class="mt10"><span onclick="$(\'#win_subscribe\').hide();">закрыть</span>');
		}
	}
	sr.send();
}

function checked_data(id) {
	var len = $("#"+id).val();
	var re = /[^0-9]/g;
	end = len.replace(re, "");
	$("#"+id).attr("value", end);
}
