function light(obj, color1, color2)
{
  if(obj.style.color == color1)
    obj.style.color = color2;
  else
    obj.style.color = color1;
}

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) {

  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) {

  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 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() {
      document.getElementById("voteline").innerHTML = '<img src="/www/img/ico_load.gif" alt="" style="vertical-align: middle;" /> Trwa oddawanie głosu...';
    },
    onSuccess : function(obj){
    
      responseMod = obj.responseText.substr(0,3);
      responseText = obj.responseText.substr(3, 10000);
      
      if(responseMod == '[1]')
        color = 'green';
      else
        color = 'red';
      
      document.getElementById("voteline").innerHTML = '<span style="font-weight: bold; color: '+color+'">' + responseText + '</span>';
    },
    onError : function(obj) {
      alert("Stracono połączenie!");
    }
  });
}

function ProfileFriend(id) {

  advAJAX.get({
  
    url: "/znajomi/action/add/id/" + id + "/",
    timeout: 15000,
    retry: 1,
    retryDelay: 1000,
    
    
    onInitialization : function() {
      document.getElementById("ajax_friend").innerHTML = '<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>';
          
       document.getElementById("ajax_friend").innerHTML = 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 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 ProfileComment() {

	advAJAX.assign(document.getElementById("ajax_comment"), {
	
	onSuccess : function(obj) {
		
		responseMod = obj.responseText.substr(0,3);
		responseText = obj.responseText.substr(3, 10000);
		
		if(responseMod == '[1]')
    {
			location.reload();
			document.getElementById("ajax_comment_text").disabled = true;
			document.getElementById("ajax_comment_button").disabled = true;
    }
    else
      alert(responseText);
		
	},
	onError : function(obj)
	{
		alert("Stracono połączenie!");
	}
	
	});
}
