var flag = false;
var shift_x;
var shift_y;


var lastZ = 100;

indicator_image = new Image();
indicator_image.src = "/_img/indicator.gif";

function start_drag(itemToMove,e){
	if(!e) e = window.event;
	flag = true;
	lastZ += 1;
	itemToMove.style.zIndex = lastZ;

	shift_x = e.clientX-parseInt(itemToMove.style.left);
	shift_y = e.clientY-parseInt(itemToMove.style.top);

	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	if(e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}

function end_drag() { 
	flag = false; 
}

function dragIt(itemToMove,e) {
	if(!flag) return;
	if(!e) e = window.event;
	itemToMove.style.left = (e.clientX-shift_x) + "px";
	itemToMove.style.top = (e.clientY-shift_y) + "px";

	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	if(e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}

function hide_wait_window() {
	$("#wait_window").css("display", "none");
}

//registration
function show_registration_window(method_name) {
	$("#registration_window").css("display", "block");
	$("#reg_login").focus();
	
}

function hide_registration_window() {
	$("#registration_window").css("display", "none");
	$("#show_registration_window").css("display", "inline");
	$("#show_registration_window").focus();
}

function http_registration_processor() {
 	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_registration.php";
	sr.form_tag = "form_registration";
	sr.accept_tag = "result_registration_string";
	sr.error_tag = "result_registration_string";
	sr.type_res = "obj";
	
	//Переопределим стадартную функцию
	sr.add_accept_function_obj = function(xml) {
		$("#frame_registration_close").css("display", "block");
		$("#frame_registration").css("display", "none");
		$("#show_registration_window").css("display", "none");
		$("#show_registration_window").css("display", "none");
		$("#result_registration_string").html($("glob_message", xml).text()+"<br/><img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите, страница будет обновлена");
		setTimeout("location.reload();", 1000);
	}
	sr.send();
}


function http_authorization_processor(type) {
	var sr = new sendForm_symp;
	
	sr.sever_file_name = "/ajax_sent_authorization.php";
	sr.form_tag = "form_authorization"+type;
	sr.accept_tag = "result_wait_window_string";
	sr.error_tag = "result_wait_window_string";
	sr.type_res = "obj";
	empty_string_au_login(type);
	empty_string_au_password(type);

	$("#wait_window").css("display", "block");
	
	//Переопределим стадартную функцию
	sr.add_accept_function_obj = function(xml) {
		$("#result_wait_window_string").html($("glob_message", xml).text()+"<br/><img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите, страница будет обновлена");
		setTimeout('$("#wait_window").css("display", "none"); location.reload();', 1000);
	}
	sr.send();
}


function empty_string_au_login(type) {
	if ($("#au_login"+type).val() == "логин") {
		$("#au_login"+type).val("");
	}
}

function empty_string_au_password(type) {
	if ($("#au_password"+type).val() == "пароль") {
		$("#au_password"+type).val("");
	}

}

//logout
function http_logout_processor() {
	res_param = "&logout=1";
	$.post("/ajax_sent_logout.php", res_param, function(xml) {
		setTimeout("location.reload();", 1000);
	});
}

