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 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)
{
  document.getElementById('preview_photo').src = url;
  showPreview(url, height);
}

function ProfileFriend(id) {

  advAJAX.get({
  
    url: "osoba.php?d=show&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(id) {

  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!");
	}
	
	});
}
