var obj,x,y;
function Move(e){
if(!e) var e = window.event;
if(e.pageX){
x = e.pageX;
y = e.pageY;
	} else if (e.clientX){
		x = e.clientX;
		y = e.clientY;
	}
obj = document.getElementById('move_div');
if(obj) {
	obj.style.left = x + 5+'px';
	obj.style.top = y + 5+'px';
	}
}

//wykryj ruch myszy
document.onmousemove = Move;

function email_validate(id){
	var zmienna = document.getElementById(id).value
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(zmienna);
}
function check_form(id,znak,mail){
// za id podajemy id sprawdzanego formularza
//za znaki wprowadzamy liczbę znaków, które mają być wprowadzone np. kod pocztowy - sprawdza tylko cyfry
var zmienna = document.getElementById(id)
var zmienna_length = zmienna.value.length
var zmienna_value = zmienna.value
if(!zmienna_value) { zmienna.style.background = 'red'; return false }
if(zmienna_value != '' && znak == 0) zmienna.style.background = '#ffffff'
if(zmienna_value != '' && znak != 0){
		var znaki = check_value(id,znak)
				if(znaki == false) { zmienna.style.background = 'red'; return false }
				else zmienna.style.background = '#ffffff'
	}
if(zmienna_value != '' && mail == 1){
		var email = email_validate(id)
				if(email == false) { zmienna.style.background = 'red'; return false }
				else zmienna.style.background = '#ffffff'
}
return zmienna_value;
}
function check_value(id,znaki){
var cena = document.getElementById(id)
var cena_s = cena.value.length
var cena_v = cena.value
if(cena_s != znaki) return false
//sprawdzanie znaków
for(var i=0;cena_s > i;i++){
	//sprawdzanie wprowadzonego znaku
	var znak = cena_v[i]
	if((znak >= 'a' && znak <= 'z') || (znak >= 'A' && znak <= 'Z')) return false
	if(znak == '/' || znak == '?' || znak == '"' || znak == ';' || znak == ':' || znak == '`' || znak == '<' || znak == '>' || znak == '!' || znak == '@' || znak == '#' || znak == '$' || znak == '%' || znak == '^' || znak == '&' || znak == '*' || znak == '('|| znak == ')' || znak == '-' || znak == '_' || znak == '=' || znak == '+' || znak == '.' || znak == '|' || znak == '[' || znak == ']' || znak == '{' || znak == '}' || znak == ' ') return false
}
}

function rm_DIV(id){
	var doc = parent.document;
	var body = doc.body;
	var div = doc.getElementById(id);
	body.removeChild(div);
}

function rm_FULL(id){
	rm_DIV(id)
	rm_DIV('full_div')
	document.getElementById('page_all').style.position = 'relative';
}

function clear_div(){
	rm_DIV('new_div')
	rm_DIV('full_div')
	document.getElementById('page_all').style.position = 'relative';
}

function clear_full(){
	rm_DIV('id_user')
	rm_DIV('full_div')
	document.getElementById('page_all').style.position = 'relative';
}

function clear_form(id){
	id.style.color = '#000';
	id.value = '';
}

function close_id(id) {
	var zmienna = document.getElementById(id);
	zmienna.style.display = 'none';
	}

function DIV(size,top,txt,color){
	if(document.getElementById('new_div')) rm_DIV('new_div')
	var divTag = document.createElement("div");
	divTag.id = "new_div";
	divTag.setAttribute("align","center");
	divTag.style.width = size+'px';
	if(color) divTag.style.color = color;
//pobieranie informacji o szerokości okna
var width_size = screen.width;
var height_size = ((screen.height)/2)-top;
var pr_width = 50-(((size*100)/width_size)/2);
	divTag.className = "new_div_class";
	divTag.innerHTML = txt;
	document.body.appendChild(divTag);
//ustawianie wysokości od okna
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
var dsocleft=document.all? iebody.scrollLeft : pageXOffset
var dsoctop=document.all? iebody.scrollTop : pageYOffset
if (document.all||document.getElementById){
divTag.style.left=parseInt(dsocleft)+pr_width+"%"
divTag.style.top=dsoctop+height_size+"px"
}
}

function ID_USER(id){
	if(document.getElementById('id_user')) rm_DIV('id_user')
	var divTag = document.createElement("div");
	divTag.id = "id_user";
	divTag.setAttribute("align","center");
//pobieranie informacji o szerokości okna
var width_size = screen.width;
var height_size = screen.height;
var pr_width = 50-(((1024*100)/width_size)/2);
	divTag.className = "full_div";
	divTag.innerHTML = 'trwa ładowanie...';
	document.body.appendChild(divTag);
//ustawianie wysokości od okna
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
var dsocleft=document.all? iebody.scrollLeft : pageXOffset
var dsoctop=document.all? iebody.scrollTop : pageYOffset
if (document.all||document.getElementById){
divTag.style.left=parseInt(dsocleft)+pr_width+"%"
}

}

function move_DIV(txt){
	if(document.getElementById('move_div')) rm_DIV('move_div')
	var divTag = document.createElement("move_div");
	divTag.id = "move_div";
	divTag.innerHTML = txt;
	divTag.className = "move_div";
	document.body.appendChild(divTag);
}

function MA(id,user,div){
	var reg = mint.Request()
	reg.Send("../ajax/ajax.php?userid="+user+"&ajax="+id,div);
}

function show_div(size,top,txt,id,mareq){
	new DIV(size,top,txt)
	new MA(mareq,id,'new_div')
}

function show_name(id){
	move_DIV('ładowanie...')
	MA('show_name',id,'move_div')
}

function randPhoto(id){
	MA('randPhoto',id,'randPhotoID')
}

function add_gallery(id){
	FULL()
	DIV(600,200,'load...')
	MA('add_gallery',id,'new_div')
}

function add_foto_kat(id){
	FULL()
	DIV(600,200,'load...')
	MA('add_foto_kat',id,'new_div')
}

function multifoto(id){
	DIV(600,300,'load...')
	MA('multifoto',id,'new_div')
}

function add_info(id){
	DIV(600,300,'load...')
	MA('add_info',id,'new_div')
}

function fotoebay(id){
		FULL()
		ID_USER()
		MA('fotoebay',id,'id_user')
}

function cancel(){
	rm_DIV('new_div')
	rm_DIV('full_div')
	document.getElementById('page_all').style.position = 'relative';
}

function priv_foto(id,user,fotoid){
	FULL()
	ID_USER(id)
	var reg = mint.Request()
	reg.Send("../ajax/ajax.php?userid="+id+"&ajax=gallery_info&privfoto="+fotoid+"&selectuser="+user+"",'id_user');
}

function check_register(uname,ufirst_name,pass,adres,email,mobile,about){
		var uname = check_form(uname,0,0)
		var ufirst_name = check_form(ufirst_name,0,0)
		var password = check_form(pass,0,0)
		var adres = check_form(adres,0,0)
		var email = check_form(email,0,1)
		var mobile = check_form(mobile,0,0)
		var about = check_form(about,0,0)
		if(uname != false && ufirst_name != false && password != false && adres != false && email != false && mobile != false && about != false) document.getElementById('button_register_button').type = 'submit';
}
function edit_dane(uname,ufirst_name,adres,email,mobile,about){
		var uname = check_form(uname,0,0)
		var ufirst_name = check_form(ufirst_name,0,0)
		var adres = check_form(adres,0,0)
		var email = check_form(email,0,1)
		var mobile = check_form(mobile,0,0)
		var about = check_form(about,0,0)
		if(uname != false && ufirst_name != false && adres != false && email != false && mobile != false && about != false) document.getElementById('button_edit_button').type = 'submit';
}
function check_dell(pass){
		var password = check_form(pass,0,0)
		if(password != false) document.getElementById('button_dell_konto').type = 'submit';
}


function show_info(id){
	move_DIV('load...')
	MA('show_name',id,'move_div')
}

function info_user(id){
	move_DIV('load...')
	MA('info_user',id,'move_div')
}

function edit_photo(id){
	DIV(600,300,'trwa ładowanie...')
	MA('edit_photo',id,'new_div')
}
	
var nameid, changeid

function check_id(){
	document.getElementById(changeid).value = nameid
	document.getElementById('info').innerHTML = nameid
}

function change_name_patch(id){
	var zmienna = document.getElementById(id).value
	var reg = mint.Request()
	var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&ajax=edit_name_patch&newname="+zmienna);
	if(ajax != false) document.getElementById(id).value = 'trwa zapis ...'
	changeid = id
	nameid = zmienna
	setTimeout("check_id()",2000)
}

function change_info(id){
	var zmienna = document.getElementById('edit_photo_'+id).value
	var reg = mint.Request()
	var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&ajax=edit_info&newname="+zmienna);
	if(ajax != false) document.getElementById('edit_photo_'+id).value = 'trwa zapis ...'
	changeid = 'edit_photo_'+id
	nameid = zmienna
	setTimeout("check_id()",2000)
}

function change_patch(id){
	var zmienna = document.getElementById('form_patch').value
	var reg = mint.Request()
	var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&ajax=change_patch&newname="+zmienna);
	if(ajax != false) alert('Katalog został zmieniony')
}

function del_patch(id){
		var del = MA('dell_patch',id,"new_div")
		if(del != false) setTimeout("rm_FULL('new_div')",4000)
}

function send_friend(id){
		var send = MA('send_friend',id,"new_div")
		if(send != false) setTimeout("rm_DIV('new_div')",4000)
}

function check_friend(id){
	MA('check_friend',id,"zaproszenia")
}

function users_enabled(on){
	document.sub.company.disabled = on;
	document.sub.sex.disabled = on;
	document.sub.province.disabled = on;	
}

function sex_enabled(event,on){
	document.sub.sex.disabled = on;
	if(event.value == 1) document.sub.menu.disabled = false;
	else document.sub.menu.disabled = true;
}

function check_inbox(id){
	var wsize = screen.width;
	if(wsize){
		wsize = wsize - 243;
		document.getElementById('inbox_message').style.left = wsize+'px';
	}
	MA('check_inbox',id,"inbox_message")
}

function read_inbox(id){
	var check = MA('read_inbox',id,"menu_bg");
	check_inbox()
}

function dell_friend(id){
	var dell = MA('dell_friend',id)
	if(dell != false)
	{ 
	check_friend()
	accept_friend()
	}
}

function dell_friend_me(id){
	var dell = MA('dell_friend',id)
	if(dell != false) 
	{
	rm_DIV('new_div')
	full_info(id)
	}
}

function dell_friend_id(id){
	DIV(600,300,'trwa ładowanie...')
	MA('dell_friend_id',id,"new_div")
}

function dellMess(id){
	var conf = confirm("Czy napewno usunąć ?");
	if(conf){
	MA('dellMess',id,"mess_"+id)
	}
}

function dellObserved(id){
	var conf = confirm("Czy napewno usunąć ?");
	if(conf){
	MA('dellObserved',id,"mess_"+id)
	}
}

function read_old_mess(id){
	MA('read_old_mess',id,"old_mess_inbox")
}

function sendMessAjax(id){
	FULL()
	DIV(600,300,'trwa ładowanie...')
	MA('sendMessAjax',id,"new_div")	
}

function ok_friend(id){
	var ok = MA('ok_friend',id)
	if(ok != false)
	{ 
	check_friend()
	accept_friend()
	}
}

function add_friend(id){
	DIV(600,300,'trwa ładowanie...')
	MA('add_friend',id,'new_div')
}

function addObserved(id){
	FULL()
	DIV(600,300,'trwa ładowanie...')	
	MA('addObserved',id,'new_div')
}

function coment_dell(id){
	DIV(600,300,'trwa ładowanie...')
	MA('coment_dell',id,'new_div')
}

function all_com(id,place,class_id){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&place="+place+"&ajax=coment",'coment_'+class_id);
}

function createADV(){
	alert('Już niedługo funkcja zostanie aktywna !')
}
function keyPress(event,id,place,class_id)
{
	txt = document.getElementById('coment_form_'+class_id).value;
	size = txt.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 0){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&place="+place+"&ajax=coment&info="+txt,'coment_'+class_id);
		document.getElementById('coment_form_'+class_id).value = '';
	}
}

function search(event,id)
{
	txt = id.value;
	size = txt.length;
	event = event || window.event;
	if(size > 3){
			var reg = mint.Request();
			var ajax = reg.Send("../ajax/ajax.php?ajax=search&info="+id.value+"",'search_find');
	}
}

function newsletter(event,id)
{
	txt = id.value;
	size = txt.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 3){
		var reg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		if(reg.test(id.value)){
			document.getElementById('newsletter_find').innerHTML = 'Trwa zapis...';
			var reg = mint.Request();
			var ajax = reg.Send("../ajax/ajax.php?ajax=newsletter&info="+id.value,'newsletter_find');
		}else{
			alert('Błędny adres email: '+id.value)
		}
	}
}

function menu_dell(id){
	var conf = confirm("Czy napewno usunąć ?");
	if(conf){
	txt = document.getElementById(id);
	txt.value = 'trwa usuwanie...';
			var reg = mint.Request();
			var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&d=1&ajax=menu",'menu_bg');
	}
}

function menu_root(id,root){
	var conf = confirm("Czy napewno ?");
	if(conf){
	txt = document.getElementById(id);
	txt.value = 'trwa analiza ...';
			var reg = mint.Request();
			var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&root="+root+"&ajax=menu",'menu_bg');
	}
}

function show_menu(id){
		txt = document.getElementById("menu_"+id);
		txt.innerHTML = 'trwa ładowanie...';
		MA('show_menu',id,'m_BG')
}

function show_menu_BL(id){
		txt = document.getElementById("menu_"+id);
		txt.innerHTML = 'trwa ładowanie...';
		MA('show_menu_BL',id,'BL_menu')
}

function menu(event,id)
{
	size = id.value.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 0){
			var reg = mint.Request();
			var ajax = reg.Send("../ajax/ajax.php?userid="+id.id+"&class_id="+id.className+"&d=0&ajax=menu&info="+id.value,'menu_bg');
			id.value = "trwa zapis...";
	}
}

function refresh_coment(event,id,place)
{
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?userid="+id+"&place="+place+"&ajax=coment&info="+txt,'coment');
}

function change_pass(id){
		FULL()
		DIV(600,300,'trwa ładowanie...')
		MA('change_pass',id,'new_div')
}

function function_user(id){
		MA('function_user',id,'fuser_'+id)
}
function active_user(id){
		MA('active_user',id,'fuser_'+id)
}

function add_ogl(id){
		FULL()
		DIV(600,300,'trwa ładowanie...')
		MA('join_friends',id,'new_div')
}

function public_list(id){
		var conf = confirm("Czy napewno ?")
		if(conf){
			MA('public_list',id,'publicID')
		}
}

function scrape(id){
		title = document.getElementById('name_scrape').value;
		info = document.getElementById('info_scrape').value;
		if((title && info) || id){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?ajax=scrapebook&userid="+id+"&title="+title+"&info="+info,'menu_bg');
		}
}

function gifts(id){
		title = document.getElementById('name_gifts').value;
		if(title || id){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?ajax=gifts&userid="+id+"&title="+title,'menu_bg');
		}
}

function questlist(id){
		title = document.getElementById('name_questlist').value;
		if(title || id){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?ajax=questlist&userid="+id+"&title="+title,'menu_bg');
		}
}

function calculator(id){
		title = document.getElementById('name_calculator').value;
		info = document.getElementById('info_calculator').value;
		price = document.getElementById('name_price').value;
		if((title && info && price) || id){
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?ajax=calculator&userid="+id+"&title="+title+"&info="+info+"&price="+price,'menu_bg');
		}
}

function key_company(event,id,ajax_id)
{
	size = id.value.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 3){
	var reg = mint.Request();
	var ajax = reg.Send("../ajax/ajax.php?ajax=keycompany&info="+id.value,ajax_id);
	id.value = 'trwa zapis słów kluczowych...';
	}
}

function find_userscompany(event,id)
{
	size = id.value.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 3){
	var reg = mint.Request();
	var ajax = reg.Send("../ajax/ajax.php?ajax=findusercompany&info="+id.value,'find_usercompany');
	id.value = '';
	}
}
function find_couples(id){
	FULL()
	DIV(600,300,'trwa ładowanie...')
	MA('find_couples',id,"new_div")
}

