var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var Mouse_X = 0;
var Mouse_Y = 0;
var Margin_Top = 112;
var Screen_width;
var Screen_height;
var Popup_ON = false;
var Popup_X;
var Popup_Y;
var Popup_Timer;
var Popup_Counter;

var Win_move=false;
var Win_move_begin=false;
var Win_move_type="";
var Win_move_X;
var Win_move_Y;
var Win_move_width;
var Win_move_height;
var Win_move_lastgood_X;
var Win_move_lastgood_Y;
var Win_move_lastgood_width;
var Win_move_lastgood_height;
var Win_move_id;
var Clickpos_X=0;
var Clickpos_Y=0;
var Win_offset_X;
var Win_offset_Y;

var Win_X = new Array();
var Win_Y = new Array();
var Win_width = new Array();
var Win_height = new Array();
var Win_min_width = new Array();
var Win_min_height = new Array();
var Win_full = new Array();

var window0_item = new Array();
var window1_item = new Array();
var window2_item = new Array();
var window3_item = new Array();
var window4_item = new Array();
var window5_item = new Array();

function Get_item(Window_num,Item_num) {
	var Return_var ="";
	switch(Window_num) {
		case 0:	Return_var=window0_item[Item_num]; break;
		case 1:	Return_var=window1_item[Item_num]; break;
		case 2:	Return_var=window2_item[Item_num]; break;
		case 3:	Return_var=window3_item[Item_num]; break;
		case 4:	Return_var=window4_item[Item_num]; break;
		case 5:	Return_var=window5_item[Item_num]; break;
	}	
	return Return_var;
}

function Free_layer() {
	var i=0;
	while (i<10 && Form_id[i] != "" ) { i++; }
	if (i==10) { alert('Nincs több Layer'); }
	return i;
}

function Put_item(Window_num,Item_num,Item_value) {
	switch(Window_num) {
		case 0:	window0_item[Item_num]=Item_value; break;
		case 1:	window1_item[Item_num]=Item_value; break;
		case 2:	window2_item[Item_num]=Item_value; break;
		case 3:	window3_item[Item_num]=Item_value; break;
		case 4:	window4_item[Item_num]=Item_value; break;
		case 5:	window5_item[Item_num]=Item_value; break;
	}	
}

function Get_Layer_name_by_id(Id) {
	var Layer_name="window" + Id;
	return Layer_name;
	}
	
function Get_Layer_name_by_Form(Form_name) {
	var Layer_name='window' + Get_Form_num(Form_name);
	return Layer_name;
	}
	
function PCT_resize() {
	popup_background.style.width = '100%';
	popup_background.style.height = '100%';
	Screen_width = popup_background.offsetWidth;
	Screen_height = popup_background.offsetHeight;
	if (Screen_width<800) { 
		Screen_width=800; 
		popup_background.style.width = '800px';
	}
	if (Screen_height<600) { 
		Screen_height=600; 
		popup_background.style.height = '600px';
	}
	tools.style.width = Screen_width + 'px';
}

function PCT_begin(System_name,Parameter)	{
	PCT_resize();
	popup_background.style.top =  '0px';
	popup_background.style.left = '0px';
	popup_background.style.opacity = '0.8';
	popup_background.style.filter = 'alpha(opacity=80)';
	popup_background.style.visibility = 'hidden';
	var i=0;
	for (i=0;i<10;i++) { if (Form_id[i]!="") { Window_off(Form_id[i]) }	}
	switch (System_name) {
	case "menu":
		AjaxPHP('menu','source/menu.php','');
		AjaxPHP('tools','source/tools.php','');
		AjaxPHP('desktop','source/webstart.php','');
	break;
	case "logout":
		AjaxPHP('menu','source/menu.php','');
		AjaxPHP('tools','source/tools.php','');
		AjaxPHP('desktop','source/logout.php','');
	break;
	case "activate":
		AjaxPHP('menu','source/menu.php','');
		AjaxPHP('tools','source/tools.php','');
		Form_start("act_reg",'code=' + Parameter);
	break;
	case "modul":
		AjaxPHP('menu','source/menu.php','');
		AjaxPHP('tools','source/tools.php','');
		AjaxPHP('desktop','source/desktop.php','');
	break;
	}
}

function Window_on(Form_name,Pos_X,Pos_Y,Layer_widht,Layer_height,Full,Min_width,Min_height,Popup)	{
/*
	var Id = Get_Form_num(Form_name);
	var Layer = Get_Layer_name_by_Form(Form_name);
	if (Popup=="Y") { Form_popup[Id]=true; popup_background.style.visibility = 'visible'; }
	Win_X[Id] = Number(Pos_X); 
	Win_Y[Id] = Number(Pos_Y);
	Win_width[Id] = Number(Layer_widht);
	Win_height[Id] = Number(Layer_height);
	Win_min_width[Id] = Number(Min_width);
	Win_min_height[Id] = Number(Min_height);
	Win_full[Id] = Full;
	if (Full=="Y") {
		Pos_X=0;
		Pos_Y=Margin_Top;
		Layer_widht=Screen_width;
		Layer_height=Screen_height-Margin_Top;	
	}
	document.getElementById(Layer).style.left = Pos_X;
	document.getElementById(Layer).style.top = Pos_Y;
	document.getElementById(Layer).style.width = Layer_widht;
	document.getElementById(Layer).style.height = Layer_height;	
	document.getElementById(Layer).style.zIndex = 1;
	document.getElementById(Layer).style.visibility = "visible";
*/
}

function Window_off(Form_name)	{
	var Id = Get_Form_num(Form_name);
	var Layer = Get_Layer_name_by_Form(Form_name);
	if (Form_popup[Id]==true) { popup_background.style.visibility = 'hidden'; }
	document.getElementById(Layer).style.zIndex = 0;
	document.getElementById(Layer).style.visibility = "hidden";
	document.getElementById(Layer).innerHTML = "";
	Form_id[Id] = "";
}
	
function Window_full(Form_name)	{
	var Timer;
	if (Win_full[Get_Form_num(Form_name)]=="N") {
		var X_temp = Win_X[Get_Form_num(Form_name)];
		var Y_temp = Win_Y[Get_Form_num(Form_name)];
		var Width_temp = Win_width[Get_Form_num(Form_name)];
		var Height_temp = Win_height[Get_Form_num(Form_name)];
	} else {
		var X_temp = 0;
		var Y_temp = Margin_Top;
		var Width_temp = Screen_width;
		var Height_temp = Screen_height;
		}
	var X_step = Win_X[Get_Form_num(Form_name)]/10;
	var Y_step = (Win_Y[Get_Form_num(Form_name)]-Margin_Top)/10;
	var width_step = (Screen_width-Win_width[Get_Form_num(Form_name)])/10;
	var height_step = ((Screen_height-Margin_Top)-Win_height[Get_Form_num(Form_name)])/10;
	var Timer_counter = 0;
	Anim = function(Form_name) {
		if (Win_full[Get_Form_num(Form_name)]=="N") {
			X_temp = X_temp - X_step;
			Y_temp = Y_temp - Y_step;
			Width_temp = Width_temp + width_step;
			Height_temp = Height_temp + height_step;
		} else {
			X_temp = X_temp + X_step;
			Y_temp = Y_temp + Y_step;
			Width_temp = Width_temp - width_step;
			Height_temp = Height_temp - height_step;
		}
		Timer_counter++;
		if (Timer_counter==10) {
			if (Win_full[Get_Form_num(Form_name)]=="N") {
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.left = "0px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.top = Margin_Top + "px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.width = Screen_width + "px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.height = (Screen_height-Margin_Top) + "px";
				Win_full[Get_Form_num(Form_name)]="Y";
			} else {
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.left = Win_X[Get_Form_num(Form_name)] + "px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.top = Win_Y[Get_Form_num(Form_name)] + "px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.width = Win_width[Get_Form_num(Form_name)] + "px";
				document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.height = Win_height[Get_Form_num(Form_name)] + "px";
				Win_full[Get_Form_num(Form_name)]="N";
			}
		} else {
			document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.left = X_temp + "px";
			document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.top = Y_temp + "px";
			document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.width = Width_temp + "px";
			document.getElementById(Get_Layer_name_by_id(Get_Form_num(Form_name))).style.height = Height_temp + "px";
			Timer = setTimeout("Anim('" + Form_name + "')",10);
		}
	}
	Timer = setTimeout("Anim('" + Form_name + "')",10);
}
	
function Window_move(Form_name,Type) {
	if (Win_full[Get_Form_num(Form_name)]=="N") { 
		Win_move_id=Get_Form_num(Form_name);
		Clickpos_X=Mouse_X;
		Clickpos_Y=Mouse_Y;
		Win_move_lastgood_X=Win_X[Win_move_id];
		Win_move_lastgood_Y=Win_Y[Win_move_id];
		Win_move_lastgood_width=Win_width[Win_move_id];
		Win_move_lastgood_height=Win_height[Win_move_id];
		Win_move_begin=false;
		Win_move_type=Type;
		Win_move=true;
	}
}
	
function Window_nomove() {
	if (Win_move && Win_move_begin) {
		Win_X[Win_move_id]=Win_move_lastgood_X;
		Win_Y[Win_move_id]=Win_move_lastgood_Y;
		Win_width[Win_move_id]=Win_move_lastgood_width;
		Win_height[Win_move_id]=Win_move_lastgood_height;
		var Popup_Present=false;
		for (i=0;i<10;i++) {
			if (Form_popup[i]==true) { Popup_Present=true; }
		}
		if (!Popup_Present) { popup_background.style.visibility = 'hidden'; }
	}
	Win_move=false;
}

function getMouseXY(e) {
	if (e == null) { e = window.event;}
	Mouse_X = e.clientX + document.body.scrollLeft;
	Mouse_Y = e.clientY + document.body.scrollTop;
	if (Mouse_X < 0){MouseX = 0;}
	if (Mouse_Y < 0){MouseY = 0;} 
	if (Win_move) {
		Win_offset_X = Mouse_X - Clickpos_X;
		Win_offset_Y = Mouse_Y - Clickpos_Y;
		if (!Win_move_begin && (Win_offset_X!=0 || Win_offset_Y!=0)) { 
			if (Form_popup[Win_move_id]) { popup_background.style.visibility = 'visible'; }
			Win_move_begin=true;
			}
		if (Win_move_begin) {
			Win_move_X=Win_X[Win_move_id];
			Win_move_Y=Win_Y[Win_move_id];
			Win_move_width=Win_width[Win_move_id];
			Win_move_height=Win_height[Win_move_id];
			if (Win_move_type=='move' || Win_move_type=='w' || Win_move_type=='nw' || Win_move_type=='sw') {
				Win_move_X = Win_X[Win_move_id] + Win_offset_X;
				}
			if (Win_move_type=='move' || Win_move_type=='n' || Win_move_type=='ne' || Win_move_type=='nw') {
				Win_move_Y = Win_Y[Win_move_id] + Win_offset_Y;
				}
			if (Win_move_type=='n' || Win_move_type=='ne' || Win_move_type=='nw') {
				Win_move_height = Win_height[Win_move_id] + (0-Win_offset_Y);
				}
			if (Win_move_type=='s' || Win_move_type=='se' || Win_move_type=='sw') {
				Win_move_height = Win_height[Win_move_id] + Win_offset_Y;
				}
			if (Win_move_type=='w' || Win_move_type=='nw' || Win_move_type=='sw') {
				Win_move_width = Win_width[Win_move_id] + (0-Win_offset_X);
				}
			if (Win_move_type=='e' || Win_move_type=='ne' || Win_move_type=='se') {
				Win_move_width = Win_width[Win_move_id] + Win_offset_X;
				}
			var Win_out=false;
			if (Win_move_X<0) { Win_out=true; }
			if (Win_move_Y<0) { Win_out=true; }
			if (Win_move_width<Win_min_width[Win_move_id]) { Win_out=true; }
			if (Win_move_height<Win_min_height[Win_move_id]) { Win_out=true; }
			if (Win_move_X+Win_move_width>Screen_width) { Win_out=true; }
			if (Win_move_Y+Win_move_height>Screen_height) { Win_out=true; }
			if (!Win_out) { 			
				document.getElementById(Get_Layer_name_by_id(Win_move_id)).style.left = Win_move_X + "px";
				document.getElementById(Get_Layer_name_by_id(Win_move_id)).style.top = Win_move_Y + "px";
				document.getElementById(Get_Layer_name_by_id(Win_move_id)).style.width = Win_move_width + "px";
				document.getElementById(Get_Layer_name_by_id(Win_move_id)).style.height = Win_move_height + "px";
				Win_move_lastgood_X=Win_move_X;
				Win_move_lastgood_Y=Win_move_Y ;
				Win_move_lastgood_width=Win_move_width;
				Win_move_lastgood_height=Win_move_height;
				} 
		}
	}
//	Screen_width = popup_background.offsetWidth;
//	Screen_height = popup_background.offsetHeight;
	return true;
}

function Halt(Halt_type,Halt_string) {
	document.write("<b>Végzetes hiba történt!</b><br>A kellemetlenégért elnézést kérünk.<br><br>");
	document.write("Kérjük mentse el ezt az oldalt és juttassa el hozzánk.<br><br>");
	document.write("<b>Version: </b><br>");
	document.write("<b>Modul: </b> <br>");
	document.write("<b>PHP: </b> <br>");
	document.write("<b>MySQL: </b><br>");
	document.write("<b>System: </b><br>");
	document.write("<b>Browser: </b><br>");
	document.write("<b>Tasks: </b><br>");
	document.write("<b>Error type: </b>"+Halt_type+"<br>");
	document.write("<b>Error:</b><br>"+Halt_string+"<br>");
}
