
var blink = 0;
function light(obj, color1, color2)
{
  if(blink == 0)
  {
    obj.style.color = color2;
	blink = 1;
  }
  else
  {
    obj.style.color = color1;
	blink = 0;
  }
}

function disableme(obj, form)
{
  obj.disabled = true;
  document.getElementById(form).submit();
}

function CheckboxReverse(oObject)
{
  var iObjectElements = oObject.elements.length;

  for (iElement = 0; iElement <iObjectElements; iElement++)
  {
    if(oObject.elements[iElement].type == "checkbox" && oObject.elements[iElement].disabled == false)
    {
      if(oObject.elements[iElement].checked == true)
        oObject.elements[iElement].checked = false;
      else
        oObject.elements[iElement].checked = true;
    }
  }
}

function CheckboxCheck(oObject, bMode)
{
  var iObjectElements = oObject.elements.length;
  var bMode = (bMode === true) ? true : false;
   
  for (iElement = 0; iElement <iObjectElements; iElement++)
  {
    if(oObject.elements[iElement].type == "checkbox" && oObject.elements[iElement].disabled == false)
    {
      oObject.elements[iElement].checked = bMode;
    }
  }
}

function PartyJoin(id, type) {

  if(type == true)
  {
    var mode = 'wejdz';
    var text = 'Chcesz przyjść na tą imprezę?';
  }
  else
  {
    var mode = 'wyjdz';
    var text = 'Chcesz opuścić tą imprezę?';
  }
    
  if(confirm(text))
  {
    advAJAX.get({
    
      url: "/imprezy/" + mode + "/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.location.href = "/imprezy/pokaz/" + id + "/";
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function GroupJoin(id, type) {

  if(type == true)
  {
    var mode = 'wejdz';
    var text = 'Chcesz dołączyć do tej grupy?';
  }
  else
  {
    var mode = 'wyjdz';
    var text = 'Chcesz opuścić tą grupę?';
  }
    
  if(confirm(text))
  {
    advAJAX.get({
    
      url: "/grupy/" + mode + "/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.location.href = "/grupy/pokaz/" + id + "/";
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function editMovieDesc(id) {

  var text = prompt("Podaj podpis filmu (max 40 znaków):", "");
  
  if(text != null)
  {
    if(confirm("Na pewno chcesz zmienić tytuł?"))
    {
      var text = text.substr(0,40);
      
      advAJAX.get({
  		
  			url: "/konto_filmy/action/desc/id/" + id + "/text/" + text + "/",
  			timeout: 15000,
  			retry: 1,
  			retryDelay: 1000,
  			
  			onSuccess : function(obj){
        
  				responseMod = obj.responseText.substr(0,3);
      		responseText = obj.responseText.substr(3, 10000);
      		
      		alert(responseText);
      		
      		if(responseMod == '[1]')
      			document.getElementById("movie_desc_" + id).innerHTML = text;
          
  			},
  			onError : function(obj) {
  				alert("Stracono połączenie!");
  			}
  		});
    }
  }
}

function editMovieDelete(id) {

  if(confirm("Na pewno chcesz usunąć film?"))
  {
    advAJAX.get({
    
      url: "/konto_filmy/action/delete/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("movie_panel_" + id).innerHTML = '';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function editPhotoDesc(id) {

  UkryjWstepniak2();
  var text = prompt("Podaj podpis fotografii (max 40 znaków):", "");
  
  if(text != null)
  {
    if(confirm("Na pewno chcesz zmienić tytuł?"))
    {
      var text = text.substr(0,40);
      
      advAJAX.get({
  		
  			url: "/konto_fotki/action/desc/id/" + id + "/text/" + text + "/",
  			timeout: 15000,
  			retry: 1,
  			retryDelay: 1000,
  			
  			onSuccess : function(obj){
        
  				responseMod = obj.responseText.substr(0,3);
      		responseText = obj.responseText.substr(3, 10000);
      		
      		alert(responseText);
      		
      		if(responseMod == '[1]')
      			document.getElementById("photo_desc_" + id).innerHTML = text;
          
  			},
  			onError : function(obj) {
  				alert("Stracono połączenie!");
  			}
  		});
    }
  }
}

function editPhotoDelete(id) {

  UkryjWstepniak2();
  if(confirm("Na pewno chcesz usunąć fotografię?"))
  {
    advAJAX.get({
    
      url: "/konto_fotki/action/delete/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("photo_panel_" + id).innerHTML = '';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function editPhotoFake(id) {

  if(confirm("Na pewno dodać fotografię do FAKE?"))
  {
    advAJAX.get({
    
      url: "/konto_fotki/action/fake/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("photo_panel_" + id).innerHTML = '';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function editPhotoAvatar(id) {

  if(confirm("Na pewno chcesz ustawić tą fotkę jako avatar? Uwaga: poprzedni zostanie zastąpiony."))
  {
    advAJAX.get({
    
      url: "/konto_fotki/action/avatar/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function editPhotoSort(position, id) {

  advAJAX.get({
  
    url: "/konto_fotki/action/move/id/" + id + "/position/" + position + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    onSuccess : function(obj){
    
      responseMod = obj.responseText.substr(0,3);
      responseText = obj.responseText.substr(3, 10000);
      
      alert(responseText);
      
      if(responseMod == '[1]')
        location.reload();
    },
    onError : function(obj) {
      alert("Stracono połączenie!");
    }
  });
}

function editFavDelete(id) {

  if(confirm("Na pewno chcesz usunąć osobę z ulubionych?"))
  {
    advAJAX.get({
    
      url: "/ulubione/action/delete/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("fav_panel_" + id).innerHTML = '';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}


function editBlackDelete(id) {

  if(confirm("Na pewno chcesz usunąć osobę z czarnej listy?"))
  {
    advAJAX.get({
    
      url: "/czarna/action/delete/id/" + id + "/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("black_panel_" + id).innerHTML = '';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}
function VotesReset() {

  if(confirm("Czy na pewno chcesz wyzerować swoją średnią? Wyzerowanie nie oznacza możliwości powtórnego głosowania przez te same osoby."))
  {
    advAJAX.get({
    
      url: "/stat_glosy/reset/",
      timeout: 15000,
      retry: 1,
      retryDelay: 1000,
      
      onSuccess : function(obj){
      
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          document.getElementById("rating_panel").innerHTML = 'Średnia została wyzerowana.';
        
      },
      onError : function(obj) {
        alert("Stracono połączenie!");
      }
    });
  }
}

function ProfileSwitchPhoto(url, 
							//url2,
							height, text, pos)
{
  document.getElementById('preview_photo').src = url;
  //document.getElementById('current_image').value = url2;
  
  document.getElementById('preview_text').innerHTML = text;
  showPreview(url, pos, height);
}

function ProfileVote(id, vote) {

  advAJAX.get({
  
    url: "/glosuj/id/" + id + "/vote/" + vote + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    onInitialization : function() {
		$("#votetext").fadeIn('fast');
		$("#votetext").html('<img src="/www/img/ico_load.gif" alt="" style="vertical-align: middle;" /> Trwa oddawanie głosu...');
		var kk;
		for (kk=1;kk<11;kk++)
		{
			$("#v"+kk).attr('disabled','true');
			if (kk != vote)
				$("#v"+kk).fadeOut(1800-150*(kk > vote ? kk-vote : vote-kk));
			else{
				$("#v"+vote).fadeOut(8000);
				$("#v"+vote).blur();
			}
		}
    },
    onSuccess : function(obj){
    
      responseMod = obj.responseText.substr(0,3);
      responseText = obj.responseText.substr(3, 10000);
      
      if(responseMod == '[0]')
        color = "<center><table border=\"0\" width=\"600\" cellspacing=\"1\"><tr><td style=\"border:2px solid #F40000; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px\" bgcolor=\"#FFEAEA\" bordercolor=\"#F40000\"><font face=\"Tahoma\" style=\"font-size: 8pt; font-weight: 700\" color=\"#F40000\"><center>";
      else
        color = "<center><table border='0' width='600' cellspacing='1'><tr><td style='border:2px solid #5AA230; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px' bgcolor='#F3FFCE' bordercolor='#5AA230'><font face='Tahoma' style='font-size: 8pt; font-weight: 700' color='#488226'><center>";
        $("#votetext").fadeIn('fast');
		$("#votetext").html(color + responseText + '</center></font></td></tr></table></center>');
    },
    onError : function(obj) {
		$("#votetext").fadeIn('fast');
		$("#votetext").html('<span style="color: red">Stracono połączenie, spróbuj za moment!</span>');
		$("#voteline").fadeTo(1,5000,function()
		{
			$("#votetext").fadeOut('fast',function() 
			{
				$("#voteline").children("button").fadeIn('normal');
			});
		});
	}
  });
}

function CheckUserName (name,minchars,maxchars) {
  if (name == null)
    return;
  var length = name.length;
  
  if (length < minchars)
  {
	$("#checktext").fadeIn('fast');
	$("#checktext").html('<span style="font-weight: bold; color: red">Nazwa użytkownika zbyt krótka!</span>');
	return;
  }
  
  if (length > maxchars)
  {
	$("#checktext").fadeIn('fast');
	$("#checktext").html('<span style="font-weight: bold; color: red">Nazwa użytkownika za długa!</span>');
	return;
  }
  
  advAJAX.get({
    url: "/sprawdz/name/" + name + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 5000,

    onInitialization : function() {
		$("#checktext").fadeIn('fast');
		$("#checktext").html('<img src="/www/img/ico_load.gif" alt="Sprawdzanie..." style="vertical-align: middle;" />');
    },
    onSuccess : function(obj){
      responseMod = obj.responseText.substr(0,3);
      responseText = obj.responseText.substr(3, 10000);
      
      if(responseMod == '[1]')
        color = 'green';
      else
        color = 'red';
        $("#checktext").fadeTo(900,1,function () {
			$("#checktext").fadeOut('fast',function() {
				$("#checktext").fadeIn('fast');
				$("#checktext").html('<span style="font-weight: bold; color: '+color+'">' + responseText + '</span>');
			});
		});
		
    },
    onError : function(obj) {
		$("#checktext").fadeIn('fast');
		$("#checktext").html('<span style="color: red">Błąd połączenia, spróbuj za moment!</span>');
	}

  });
}


function ProfileFriend(id) {

  advAJAX.get({
  
    url: "/znajomi/action/add/id/" + id + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    
    onInitialization : function() {
      $("#ajax_friend").html('<span>Dodawanie do znajomych...</span>');
    },
    onSuccess : function(obj){
    
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          var html = '<span>Dodano do znajomych</span>';
        else
          var html = '<a href="javascript:ProfileFriend(' + id + ');">Zaproś do znajomych</a>';
          
       $("#ajax_friend").html(html);
    },
    onError : function(obj) {
      alert("Stracono połączenie!");
    }
  });
}

function ProfileFav(id) {

  advAJAX.get({
  
    url: "/ulubione/action/add/id/" + id + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    onInitialization : function() {
      document.getElementById("ajax_fav").innerHTML = '<span>Dodawanie do ulubionych...</span>';
    },
    onSuccess : function(obj){
    
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          var html = '<span>Dodano do ulubionych</span>';
        else
          var html = '<a href="javascript:ProfileFav(' + id + ');">Dodaj profil do ulubionych</a>';
          
       document.getElementById("ajax_fav").innerHTML = html;
    },
    onError : function(obj) {
      alert("Stracono połączenie!");
    }
  });
}

function ProfileBlack(id) {

  advAJAX.get({
  
    url: "/czarna/action/add/id/" + id + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    onInitialization : function() {
      document.getElementById("ajax_black").innerHTML = '<span>Dodawanie do czarnej listy...</span>';
    },
    onSuccess : function(obj){
    
        responseMod = obj.responseText.substr(0,3);
        responseText = obj.responseText.substr(3, 10000);
        
        alert(responseText);
        
        if(responseMod == '[1]')
          var html = '<span>Dodano do czarnej listy</span>';
        else
          var html = '<a href="javascript:ProfileBlack(' + id + ');">Dodaj profil do czarnej listy</a>';
          
       document.getElementById("ajax_black").innerHTML = html;
    },
    onError : function(obj) {
      alert("Stracono połączenie!");
    }
  });
}

function ProfileAdmin(profile) {

  var text = prompt("Podaj powód jaki zostanie przedstawiony administracji:", "");
  
  if(text != null && text != '')
  {
    if(confirm("Na pewno chcesz wysłać informację do administratora? Fałszywe powiadomienia są łamaniem regulaminu!"))
    {
      advAJAX.get({
      
        url: "/naruszenie_zasad/profil/" + profile + "/text/" + text + "/",
        timeout: 15000,
        retry: 1,
        retryDelay: 1000,
        
        onInitialization : function() {
          document.getElementById("ajax_admin").innerHTML = '<span>Wysyłanie...</span>';
        },
        onSuccess : function(obj){
        
            responseMod = obj.responseText.substr(0,3);
            responseText = obj.responseText.substr(3, 10000);
            
            alert(responseText);
            
            if(responseMod == '[1]')
              var html = '<span>Wysłano informację do administratora.</span>';
            else
              var html = '<a href="javascript:ProfileAdmin(\'' + profile + '\');">Zgłoś naruszenie regulaminu</a>';
              
           document.getElementById("ajax_admin").innerHTML = html;
        },
        onError : function(obj) {
          alert("Stracono połączenie!");
        }
      });
    }
  }
}

function EditProfileComment(comText, comId)
{
	var formText = document.getElementById("newComment");
	var formId = document.getElementById("editId");
	formText.value = comText;
	formId.value = comId;
	
}
function ProfileComment() {
	advAJAX.assign(document.getElementById("ajax_comment"), 
	{
	
	onInitialization : function(obj) {
		$("#commentAnswer").html('<img src="/www/img/ico_load.gif" alt="Sprawdzanie..." style="vertical-align: middle;" />');
		$("#commentAnswer").fadeTo('fast',1);
		$("#ajax_comment_text").attr('disabled','true');
		$("#ajax_comment_button").attr('disabled', 'true');
    },
	onSuccess : function(obj) {

		responseMod = obj.responseText.substr(0,3);
		responseText = obj.responseText.substr(3, 10000);
		if(responseMod == '[1]')
    {
    			var formId = document.getElementById("editId");
    			var formText = document.getElementById("newComment");
   			var date = new Date();
			var y = date.getYear();
			var year = (y < 1000) ? y + 1900 : y;
			var d = date.getDate();
			var day = (d < 10) ? '0' + d : d;
			var m = date.getMonth() + 1;
			var month = (m < 10) ? '0' + m : m;
			var hours = date.getHours();
			var mm = date.getMinutes();
			var minutes = (mm<10) ? '0' + mm : mm;
			
			var dodajacy = $("#jako").html();
			var zawartosc = $("textarea#newComment").val();
			
			var koment = "<tr><td class='label2'>\n<a href='http://www.fotka.sex.pl/profil/" + dodajacy + "/'><img src='http://www.fotka.sex.pl/./fotki/avatary/" + dodajacy + ".jpg' alt='" + dodajacy + "' class='shade_mini'></a><a href='http://www.fotka.sex.pl/profil/" + dodajacy + "/'>" + dodajacy + "</a>,<br>" + day + "." + month + "." + year + " " + hours + ":" + minutes + "</td><td class='contents'>" + zawartosc + "</td></tr>\n";

	
			$("#ajax_comment_text").attr('disabled','true');
			$("#ajax_comment_button").attr('disabled', 'true');
			if(formId.value == '-1')
			{

				$("#comments").html(koment + $("#comments").html());
//				$("#commentAnswer").html("<span style='color:green;'>" + responseText + "</span>");
				$("#commentAnswer").html("<center><table border='0' width='600' cellspacing='1'><tr><td style='border:2px solid #5AA230; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px' bgcolor='#F3FFCE' bordercolor='#5AA230'><font face='Tahoma' style='font-size: 8pt; font-weight: 700' color='#488226'><center>"+ responseText +"</center></font></td></tr></table></center>");
			}
			else
			{
	
			var commentDiv = document.getElementById("com_" + formId.value).innerHTML = formText.value;
//				$("#commentAnswer").html("<span style='color:green;'>" + responseText + "</span>");
				$("#commentAnswer").html("<center><table border='0' width='600' cellspacing='1'><tr><td style='border:2px solid #5AA230; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px' bgcolor='#F3FFCE' bordercolor='#5AA230'><font face='Tahoma' style='font-size: 8pt; font-weight: 700' color='#488226'><center>"+ responseText +"</center></font></td></tr></table></center>");				
				formText.value = '';
				formId.value = '-1';
			}
			
    }
    else
       {
	//$("#commentAnswer").html("<span style='color:red;'>" + responseText + "</span>");
		$("#commentAnswer").html("<center><table border=\"0\" width=\"600\" cellspacing=\"1\"><tr><td style=\"border:2px solid #F40000; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px\" bgcolor=\"#FFEAEA\" bordercolor=\"#F40000\"><font face=\"Tahoma\" style=\"font-size: 8pt; font-weight: 700\" color=\"#F40000\"><center>"+ responseText +"</center></font></td></tr></table></center>");    	
      }
	},
	onError : function(obj)
	{
	  $("#commentAnswer").fadeOut('fast',function () {
		$("#commentAnswer").html("Stracono połączenie!");
		$("#commentAnswer").fadeIn('fast');
      });
		$("#ajax_comment_text").attr('disabled','false');
		$("#ajax_comment_button").attr('disabled', 'false');
	}
	
	});
}




function ProfileCommentsAjaxPageChange(user_id, page) {

	var url = "/profile_comments/?comments_user_id=" + user_id + "&comments_page_number=" + page + "&comments_ajax=1";
	

  $("#profile_comments_container").load(url);

}

function NewsAjaxPageChange(page) {
	var url = "/index_news/" + page;

    $("#news_comments_container").load(url);

}

function LastPhotosChange(a) {
	var url = "/last_photos/" + a;

    $("#last_photos_container").load(url);

}

function SearchCheck(pro)
{
	var access = true;
	var part = document.getElementsByName('part');
	var nick = document.getElementsByName('nick');
	var location = document.getElementsByName('location');

	if(pro)
	{
		var hairs = document.getElementsByName('hairs');
		var hairs_lenght = document.getElementsByName('hairs_lenght');
		var eyes = document.getElementsByName('eyes');
		var gg = document.getElementsByName('gg');
		var skype = document.getElementsByName('skype');
		var photos = document.getElementsByName('photos');
		var smoking = document.getElementsByName('smoking');
		var drink = document.getElementsByName('drink');
		var usablity = document.getElementsByName('usablity');
		var childrens = document.getElementsByName('childrens');
		var phone = document.getElementsByName('phone');
		var mail = document.getElementsByName('mail');
		
		if(location[0].value == '' && part[0].value == 0 && nick[0].value == '' && hairs[0].value == 0 && hairs_lenght[0].value == 0 && eyes[0].value == 0 && gg[0].checked == 0 && skype[0].checked == 0 && photos[0].checked == 0 && phone[0].checked == 0 && mail[0].checked == 0 && photos[0].checked == 0 && smoking[0].value == 0 && drink[0].value == 0 && usablity[0].value == 0 && childrens[0].value == 0)
		{
			access = false;
		}
	}
	else if(location[0].value == '' && part[0].value == 0 && nick[0].value == '')
	{

		access = false;
	}
	
	if(!access)
	{
		var kom = document.getElementById('kom').innerHTML = 'Musisz zawęzić kryteria wyszukiwania';
		return false;
	}
	return true;
}

function StatPodgladaczSzczegoly(a) {

	var url = "/stat_podgladacz/ajax/" + a;

    $("#stat_podgladacz_szczegoly").load(url);

}

function UkryjWstepniak2()
{
	$('#wstepniak2').hide();
}
