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();
}

//radio

function show_basket_window(method_name) {
	$("#basket_pop").css("display", "block");
	$("#reg_login").focus();
	
}

function hide_radio_window() {
	$("#basket_pop").css("display", "none");
	$("#show_basket_window").css("display", "inline");
	$("#show_basket_window").focus();
}


//---------------------




function http_registration_processor() {
 	var sr = new sendForm_kifa;
	sr.sever_file_name = "/ajax_sent_registration.php";
	sr.form_tag = "form_registration";
	sr.accept_tag = "result_registration_";
	sr.error_tag = "result_registration_";
	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_").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_kifa;
	
	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);
	});
}

function clock() {
var title="";
var date=new Date();
var year=date.getFullYear();
var month=date.getMonth();
var day=date.getDate();
var hour=date.getHours();
var minute=date.getMinutes();
var second=date.getSeconds();
var months=new Array("Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Декабря");

var monthname=months[month];

if (minute < 10) {
minute="0"+minute;
}

if (second < 10) {
second="0"+second;
}


$("#clock").html(hour+":"+minute+":"+second +"  "+ day+" "+monthname+" "+year);

setTimeout("clock()", 1000)

}
function empty_string_au_name(type) {
 if ($("#name"+type).val() == "Как Вас зовут?*") {
  $("#name"+type).val("");
 }
}
function empty_string_au_email(type) {
 if ($("#email"+type).val() == "Укажите Ваш E-mail*") {
  $("#email"+type).val("");
 }
}

function empty_string_au_number(type) {
 if ($("#phone"+type).val() == "Ваш номер телефона") {
  $("#phone"+type).val("");
 }
}
 function empty_string_au_text(type) {
 if ($("#text"+type).val() == "Напишите нам*") {
  $("#text"+type).val("");
 }
}
 


/*
	function coment(id) {
	
$("#popup").css("display", "block");

document.getElementById("id_picture").value = id;

$.post("/ajax_coment.php", '&id='+id, out_coment);

	}
	
function wait_coment() {
$("#popup").css("display", "none");

	}	
	
	function out_coment(xml)	{
	var out='';
	events = $("event", xml);
	
	for (i=0; i<events.length; i++)	{
	out+='<div>'+$("description", events[i]).text()+'</div>';
	
	}	

	$("#coment").html(out);

	
}
	
*/	
