function flash(width,height,path,div_id)
{

	var flash = '<object type="application/x-shockwave-flash" data="'+path+'" width="'+width+'" height="'+height+'">';
	flash += '<param name="movie" value="'+path+'" />';
	flash += '<param name="quality" value="high" />';
	flash += '<param name="allowScriptAccess" value="sameDomain" />';
	flash += '<param name="wmode" value="transparent" />';
	flash += '<param name="bgcolor" value="#ffffff" />';
	flash += '<param name="menu" value="false" />';
	flash += '<param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer" />';
	flash += '</object>';
	document.getElementById(div_id).innerHTML = flash;
}
// JavaScript Document
function flash(width,height,path,div_id)
{

	var flash = '<object type="application/x-shockwave-flash" data="'+path+'" width="'+width+'" height="'+height+'">';
	flash += '<param name="movie" value="'+path+'" />';
	flash += '<param name="quality" value="high" />';
	flash += '<param name="allowScriptAccess" value="sameDomain" />';
	flash += '<param name="wmode" value="transparent" />';
	flash += '<param name="bgcolor" value="#ffffff" />';
	flash += '<param name="menu" value="false" />';
	flash += '<param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer" />';
	flash += '</object>';
	
	
	document.getElementById(div_id).innerHTML = flash;
}

window.onload = function() 
{
	
	Sortable.create('left_sortable', 
       { 
	   		containment: ['left_sortable','right_sortable'], tag:'div', hoverclass:'hoverActive', dropOnEmpty: true, handle:'drag_me',
			onUpdate: function() 
			{
              new Ajax.Request('update_left_sidebar.php' , 
			  {
	    	  	method: "post",
              	parameters: 
			  		{
						data:Sortable.serialize('left_sortable')
			  		}
        	  });
			} 
			
			
	   });
	Sortable.create('right_sortable', 
       { 
	   	containment: ['left_sortable','right_sortable'], tag:'div', hoverclass:'hoverActive', dropOnEmpty: true, handle:'drag_me',
		onUpdate: function() 
			{
              new Ajax.Request('update_right_sidebar.php' , 
			  {
	    	  	method: "post",
              	parameters: 
			  		{
						data:Sortable.serialize('right_sortable')
			  		}
        	  });
			} 
	   });
if ( $('box_my_profile_content') ) option_change('box_my_profile_content', 'C1');
if ( $('box_favorites_content') ) option_change('box_favorites_content', 'C2');
if ( $('box_invite_content') ) option_change('box_invite_content', 'C3');
if ( $('box_search_content') ) option_change('box_search_content', 'C4');
if ( $('box_shortcut_content') ) option_change('box_shortcut_content', 'C5');
if ( $('box_forum_content') ) option_change('box_forum_content', 'C6');


}
   
function updatebox_fun(boxtype)
{	
	var handlerFunc= function(t) 
	{
		location.reload();
	}
	var errFunc= function(t) {
		alert('Error');
	}		
	new Ajax.Request('update_box.php', {method: 'post', postBody:'id='+boxtype, onSuccess:handlerFunc, onFailure:errFunc} );		
}

function updatebox_config(form)
{	
  var handlerFunc= function(t) {
  	location.reload();
  }
  var errFunc= function(t) {
	alert('Error');
  }
  var comFunc= function(t) {
  }
  var data = new String("id="+form.id+"&boxcount="+form.elements.length);
  for( var i = 0; i < form.elements.length; i++ ) {        
	data=data + "&box"+i+"="+form.elements[i].checked;
  }    
  new Ajax.Request('update_box_config.php', {method: 'post', postBody: data, onComplete: comFunc, onSuccess:handlerFunc, onFailure:errFunc} );
}

function sendInvite(input)
{  
  var handlerFunc= function(t) {	
  }
  var errFunc= function(t) {
	alert('Error');
  }
  var comFunc= function(t) {
	document.getElementById('invitemessage').innerHTML = t.responseText;
	setTimeout("document.getElementById('invitemessage').innerHTML = \" \";",2100);
  } 
  var email = new String("?mail="+input.value);
  new Ajax.Request('send_invite.php'+email, {method: 'get',  onComplete: comFunc, onSuccess:handlerFunc, onFailure:errFunc} );
}

var monthtext=['', 'Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'];
var m_statetext=['','Wolny(a)','W związku', 'Zaręczony(a)', 'Żonaty/Zamężna'];
var kidstext=['','Żadnego','Jedno dziecko', 'Dwoje dzieci', 'Troje dzieci', 'Wiecej'];

function date_select(birth_day, birth_month, birth_year, bds, bms, bys)
{
	var today=new Date();
	var birthday=document.getElementById(birth_day);
	var birthmonth=document.getElementById(birth_month);
	var birthyear=document.getElementById(birth_year);	
	birthday.options[0]=new Option('', '');		
	for (var i=1; i<32; i++) { 
		birthday.options[i]=new Option(i, i);	
	}
	if (i=bds) birthday.selectedIndex=i;
	for (var m=0; m<13 	; m++)
		birthmonth.options[m]=new Option(monthtext[m], monthtext[m]);
	if (bms) {
		for (var tmp=0; tmp<13; tmp++) if (monthtext[tmp]==bms) birthmonth.options[tmp]=new Option(monthtext[tmp], monthtext[tmp], true, true)
	}
	var thisyear=today.getFullYear();
	birthyear.options[0]=new Option('', '');
	for (var y=1; y<70; y++){
		birthyear.options[y]=new Option(thisyear, thisyear);
		thisyear-=1;
	}
	if (bys) {
		var thisyear=today.getFullYear();
		for (var tmp=0; tmp<70; tmp++) {
			if (thisyear==bys) birthyear.options[tmp]=new Option(bys, bys, true, true); 
			thisyear-=1;
		}
	}
}

function m_state_select(m_state, ms)
{
	var mstate=document.getElementById(m_state);
	for (var i=0; i<5; i++) {
		mstate.options[i]=new Option(m_statetext[i], m_statetext[i]);
	}
	if (ms) {
		for (var tmp=0; tmp<5; tmp++) if (m_statetext[tmp]==ms) mstate.options[tmp]=new Option(m_statetext[tmp], m_statetext[tmp], true, true);
	}
}

function kids_select(kids_count, ks)
{
	var kidscount=document.getElementById(kids_count);
	for (var i=0; i<6; i++) {
		kidscount.options[i]=new Option(kidstext[i], kidstext[i]);
	}
	if (ks) {
		for (var tmp=0; tmp<6; tmp++) if (kidstext[tmp]==ks) kidscount.options[tmp]=new Option(kidstext[tmp],kidstext[tmp],true,true);
	}
}

function profile_edit(p)
{
	var comFunc= function(t) {
		document.getElementById('avatarimg').innerHTML="<img src=\"uploaded_images/avatars/noavatar.jpg\">";
		document.getElementById('avatar_head').innerHTML="<a href=\"show_profile\"><img src=\"img/TMP_user_logo.gif\"/></a>";
		document.getElementById('description').innerHTML="";
 	}
	
	if (p==1) {								//change password
	param=new String ("?param="+p);
	new Ajax.Updater ('passwordchange', 'profile_edit2.php'+param);
	}
	
	if (p==2) {
	pass=document.getElementById('a_password').value;
	newpass=document.getElementById('1_pass').value;
	newpass2=document.getElementById('2_pass').value;
	param=new String ("?param="+p+"&pass="+pass+"&newpass="+newpass+"&newpass2="+newpass2);
	new Ajax.Updater ('passwordchange', 'profile_edit2.php'+param);
	}
	
	if (p=="avatar") {					  //avatary
	param=new String ("?param="+p);
	new Ajax.Updater ('avatarchange', 'profile_edit2.php'+param);
	}
	
	if (p=="delavatar") {
	avatarid=document.getElementById('avatar_id').value;
	param=new String ("?param="+p+"&avatarid="+avatarid);
	new Ajax.Updater ('avatarchange', 'profile_edit2.php'+param, {onComplete: comFunc});
	}
	
	if (p=="jpg") {
	param=new String ("?param="+p);
	new Ajax.Updater ('avatarchange', 'profile_edit2.php'+param);	
	}
	
	if (p=="noavatar") {
	param=new String ("?param="+p);
	new Ajax.Updater ('noavatar', 'profile_edit2.php'+param);	
	}
}

function addtofriends(friend_id,own_id,p)
{
	var comFunc=function() {
		new Ajax.Request('friends.php'); 
		location.reload();
	}
	if (friend_id==own_id) document.getElementById('addfriends').innerHTML="<strong>Oj, chyba nie dobrze</strong>";
	else {
		param=new String("?friend="+friend_id+"&user="+own_id+"&p="+p)
		new Ajax.Updater('addfriends', 'add_friend'+param, {onComplete: comFunc } );
	}
}

function friends(p, user_id)
{
	var comFunc=function() {
		new Ajax.Request('friends.php'); 
		location.reload();
	}
	if (p=="del") {
		var agree=confirm("Jesteś pewien?");
		if(!agree)
		{
			close();
		}
		else
		{
			param=new String ("?user="+user_id);
			new Ajax.Updater('delfriend', 'del_friend'+param, {onComplete: comFunc } );
		}
	}
}

function option_change(id1, id2)
{
	if (document.getElementById(id1).style.display=='none' || document.getElementById(id1).style.overflow=='hidden') document.getElementById(id2).innerHTML="Rozwiń box";
	if (document.getElementById(id1).style.display=='block' || document.getElementById(id1).style.overflow=='visible') document.getElementById(id2).innerHTML="Zwiń box";
	return false;
}

function box_change(id1, id2)
{
	if (document.getElementById(id1).style.display=='none' || document.getElementById(id1).style.overflow=='hidden') {
		Effect.BlindDown(document.getElementById(id1).id); 
		option_change(id1, id2);
		return false;
	}
	if (document.getElementById(id1).style.display=='block' || document.getElementById(id1).style.overflow=='visible') {
		Effect.BlindUp(document.getElementById(id1).id); 		
		option_change(id1, id2);
		return false;
	}
	
	
}

function add_favorite(uri)
{
	var comFunc=function(t) {		
		$('favorite_say').innerHTML=t.responseText;
		setTimeout("document.getElementById('favorite_say').innerHTML = \" \";",2100);
	}
	var handlerFunc= function(t) {
		location.reload();
  	}
    var errFunc= function(t) {
	  alert('Error');
	}	 
	var data= new String("u="+uri);
	data=data.replace(/\&/gi, "|");
	data=data.replace(/\?/gi, "_znakzapytania_");
	data=data.replace(/%20/gi,"_spaCja_");
	new Ajax.Request('add_favorite.php', {method: 'post', parameters: data , onComplete: comFunc, onSuccess:handlerFunc, onFailure:errFunc} );
}

function del_favorite(pos)
{
	var comFunc=function(t) {		
		$('favorite_say').innerHTML=t.responseText;
		setTimeout("document.getElementById('favorite_say').innerHTML = \" \";",2100);
	}
	var handlerFunc= function(t) {
		location.reload();
  	}
    var errFunc= function(t) {
	  alert('Error');
	}	
	var data= new String("pos=");
	data=data+pos;
	new Ajax.Request('del_favorite.php', {method: 'post', parameters: data , onComplete: comFunc, onSuccess:handlerFunc, onFailure:errFunc} );
}

function news(id,subject,text,checked)
{	
	var comFunc=function() {
		location.reload();
	}
	textv=document.getElementById(text);
	subjectv=document.getElementById(subject);
	checkedv=document.getElementById(checked);
	say=document.getElementById('say');	
	news="subject="+subjectv.value+"&id="+id+"&text="+textv.value+"&checked="+checkedv.checked;
	if (textv.value=="" || subjectv.value=="") {say.innerHTML='<strong>Musisz wypełnić wszystkie pola</strong>';}
	else {
		new Ajax.Updater('say', 'admin_news2.php', {method: 'post', parameters: news, onComplete: comFunc});
	}
}

function forum2(param,id)
{
	var comFunc=function(t) {
		new Ajax.Request('forum.php');
		new Ajax.Request('forum_subjects.php')
		new Ajax.Request('forum_posts.php')
		location.reload();
	}
	if (param=='delpost') {
		var agree=confirm("Jesteś pewien?");
		if(!agree)
		{
			close();
		}
		else
		{
			new Ajax.Request('forum2.php', {method: 'post', parameters: 'param='+param+'&id='+id, onComplete: comFunc, asynchronous: 'false' } );
		}
	}	
	if (param=='delsub') {
		var agree=confirm("Zostaną usunięte wszystkie posty. Jesteś pewien?");
		if(!agree)
		{
			close();
		}
		else
		{
			new Ajax.Request('forum2.php', {method: 'post', parameters: 'param='+param+'&id='+id, onComplete: comFunc, asynchronous: 'false' } );
		}
	}	
	if (param=='editsub') {
		$('editsubject'+id).show();
		
	}
	if (param=='savesub') {
		var title=$('subjectedit'+id).value;	    
		new Ajax.Request('forum2.php', {method: 'post', parameters: 'param='+param+'&id='+id+'&title='+title, onComplete: comFunc, asynchronous: 'false' } );
	}
	if (param=='delfor') {
		var agree=confirm("Zostaną usunięte wszystkie tematy oraz posty. Jesteś pewien?");
		if(!agree)
		{
			close();
		}
		else
		{
			new Ajax.Request('forum2.php', {method: 'post', parameters: 'param='+param+'&id='+id, onComplete: comFunc, asynchronous: 'false' } );
		}
	}
	if (param=='editfor') {
		$('editforum'+id).show();
	}
	if (param=='savefor') {
		var title=$('forumedit'+id).value;
		var description=$('forumeditd'+id).value;		
		new Ajax.Request('forum2.php',  {method: 'post', postBody: 'param='+param+'&id='+id+'&title='+title+'&description='+description, onComplete: comFunc, asynchronous: 'false' } );
	}
	if (param=='closesub') {
		var agree=confirm("Jesteś pewien?");
		if (!agree) {
			close();
		}
		else {
			new Ajax.Request('forum2.php', {method: 'post', parameters: 'param=closesub&id='+id, onComplete: comFunc, asynchronous: 'false' } );
		}
	}
}

function users(param,id)
{
	var comFunc=function(t) {
		$('say').innerHTML=t.responseText;
		new Ajax.Request('admin_users.php');
		location.reload();
	}
	if (param=='addprivileges') {
		new Ajax.Request('admin_u2.php', {method: 'post', parameters: 'param='+param+'&id='+id, asynchronous: 'false', onComplete: comFunc } );
	}
	if (param=='delprivileges') {
		new Ajax.Request('admin_u2.php', {method: 'post', parameters: 'param='+param+'&id='+id, asynchronous: 'false', onComplete: comFunc } );
	}
	if (param=='deluser') {
		var agree=confirm("Jesteś pewien, że chcesz na stałe usunąć użytkownika "+id+" ?");
		if (!agree) {
			close();
		}
		else {
		new Ajax.Request('admin_u2.php', {method: 'post', parameters: 'param='+param+'&name='+id, asynchronous: 'false', onComplete: comFunc } );
		}
	}
}

function show_countries(region)
{
	var comFunc=function() {
		var x=document.getElementById(region);	
		x.style.display='block';
	
	}	
	if (document.getElementById(region).style.display=='block') document.getElementById(region).style.display='none';
	else {
		document.getElementById('europa').style.display='none';
		document.getElementById('azja').style.display='none';
		document.getElementById('afryka').style.display='none';
		document.getElementById('australia').style.display='none';
		document.getElementById('ameryka_pd').style.display='none';
		document.getElementById('ameryka_pn').style.display='none';	
		new Ajax.Updater(region, 'select_countries.php', {method: 'post', parameters: 'region='+region, onComplete: comFunc });
	}
}

function BUDEffect(element)
{
       new Effect.toggle(element,'Blind', {duration:1});
}

function validate_form(AForm)
{

    if(!AForm.user_name.value)
	{
	alert('Prosze wypelnic pole "Nazwa uzytkownika" ');
	return false;
	}
    if(!AForm.password.value)
	{
	alert('Prosze wypelnic pole "Haslo" ');
	return false;
	}
	if(!AForm.password_2.value)
	{
	alert('Prosze potwierdzic haslo');
	return false;
	}
	
	pass1 = AForm.password_2.value;
	pass2 = AForm.password.value;
	if(pass1 != pass2)
	{
	alert('Potwierdzenie hasla nie zgadza sie z wczesniej podanym haslem! Upewnij sie, ze dobrze wypelniles te pola. ');
	return false;
	}
	
	if(!AForm.email.value)
	{
	alert('Prosze wypelnic pole "E-mail" ');
	return false;
	}
	
    reg1 = /^[a-zA-Z0-9acelnósśżźzACELNÓSŚŻŹZ.]{1,30}@[a-zA-Z0-9acelnószzACELNÓSZZ]+(\.[a-zA-Z0-9acelnószzACELNÓSZZ]+)+$/;
    wyn1 = AForm.email.value.match(reg1);
    if (wyn1 == null) {
        alert("Prosze podac poprawny adres email. " +
              "Poprawny adres musi zawierac malpe " +
              "oraz co najmniej dwa czlony nazwy serwera, " +
              "np. a@b.c lub ala@ma.kota.czarnego.com.");
        return false;
    }

    return true;
}




//================================= search =============================================================//
function update_main_center(query) 
{
	
	var konczacaFunkcja=function(t) 
	{
		document.getElementById('main_center').innerHTML = '<div class="box">'+t.responseText+'</div>';
	}
	new Ajax.Request('engine_scripts/search_places.php',{method: 'post', parameters: 'query='+query, onComplete: konczacaFunkcja});
 	
}
function update_poland_most_wanted(query) 
{
	
	var konczacaFunkcja=function(t) 
	{
		document.getElementById('poland_most_wanted').innerHTML = '<div class="box">'+t.responseText+'</div>';
	}
	new Ajax.Request('engine_scripts/return_most_wanted.php',{method: 'post', parameters: 'query='+query, onComplete: konczacaFunkcja});
 	
}
function update_world_most_wanted(query) 
{
	
	var konczacaFunkcja=function(t) 
	{
		document.getElementById('world_most_wanted').innerHTML = '<div class="box">'+t.responseText+'</div>';
	}
	new Ajax.Request('engine_scripts/return_most_wanted.php',{method: 'post', parameters: 'query='+query, onComplete: konczacaFunkcja});
 	
}

function search_friends(name)
{
	new Ajax.Updater('friends', 'friends2.php', {method: 'post', parameters: 'name='+name});				
}

function startUpload()
{ 
   document.getElementById('f1_upload_process').style.visibility = 'visible';
   return true; 
}
   
function stopUpload(success)
{
   var result = '';
   if (success == 1){   
   //document.getElementById('result').innerHTML =   
     //'<span class="msg">Plik dodano pomyślnie, można dodać kolejne zdjęcie<\/span><br/><br/>';
	 $('result').innerHTML='';
   }   
   else {  
    document.getElementById('result').innerHTML =   
    '<span class="emsg">Wystąpił błąd podczas ładowania pliku (prawidłowe formaty .jpg, .jpeg, rozmiar pliku nie może być większy od 0,5 MB)<\/span><br/><br/>';  
   } 
   new Ajax.Updater('dodane_zdjecia', 'my_places_edit2.php', {method: 'post', parameters: 'param=photos', asynchronous:true, evalScripts:true, onComplete:function(request) { document.getElementById('f1_upload_process').style.visibility = 'hidden';  } } );   
   return true; 
}

function stopUpload2(success,params)
{  
   var result = '';
   if (success == 1){   
   //document.getElementById('result').innerHTML =   
     //'<span class="msg">Plik dodano pomyślnie, można dodać kolejne zdjęcie<\/span><br/><br/>';  
	 $('result').innerHTML='';
   }   
   else {  
    document.getElementById('result').innerHTML =   
    '<span class="emsg">Wystąpił błąd podczas ładowania pliku (prawidłowe formaty .jpg, .jpeg, rozmiar pliku nie może być większy od 0,5 MB)<\/span><br/><br/>';  
   } 
   new Ajax.Updater('dodane_zdjecia', 'places_show_place2.php'+params, {method: 'get', asynchronous:true, evalScripts:true, onComplete:function(request) { document.getElementById('f1_upload_process').style.visibility = 'hidden';   } } );   
   return true; 
}
