function del_news(id){
    $('wait_mod').style.display = 'block';
    var req = mint.Request();
    req.AddParam("id", id);
    req.OnSuccess = function() {
        $('wait_mod').style.display = 'none';
        alert('news usunięto');
    }
    req.OnError= function() {
        $('wait_mod').style.display = 'none';
        alert('error mint.Request');
    }
    req.Send("/news/admin/delete.php");
}

function archiwum(id){
    $('wait_mod').style.display = 'block';
    var req = mint.Request();
    req.AddParam("id", id);
    req.OnSuccess = function() {
        $('wait_mod').style.display = 'none';
        alert(this.responseText);
    }
    req.OnError= function() {
        $('wait_mod').style.display = 'none';
        alert('error mint.Request');
    }
    req.Send("/news/admin/toarchiwum.php");
}

function patronat_add(id, reliability){
    zmget = 'id='+id+'&reliability='+reliability;
    document.getElementById("reliability").style.background = "#ffcccc";
    var myAjax = new Ajax.Request(
    "/news/admin/patronat_add.php", 
    {
        method: 'get',
        parameters: zmget,
        onComplete: function(originalRequest) {
            if(!originalRequest.responseText.match("Wiarygodność patronatu została ustawiona na:")) 
                alert(originalRequest.responseText);
            document.getElementById("reliability").style.background = "#fff";
            if (document.getElementById("reliability")){
                if (document.getElementById("reliability").value == '9'){
                    document.getElementById("Generuj button").style.display = '';
                }else{
                    document.getElementById("Generuj button").style.display = 'none';
                }
            }
            
        },
        onFailure: function() {
            alert('Failure request - prawdopodobnie nie mozna polaczyc sie z serwerem');
        }
    });
}



 function newspatronat(id,reliability)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
  
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  alert('Zmieniono wartość. Odśwież okno aby się upewnić.');

  document.getElementById('reliability').style.background = "#ffcccc";  // nie działa jesli reliability ma normalny, nie pojedynczy cudzysłow 

  }
}

xmlhttp.open("POST", '/news/admin/patronat_add.php',true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send('id='+escape(id) +'&reliability='+escape(reliability));

}

function genButton(id){
    var req = mint.Request();
    req.AddParam("id", id);
    req.AddParam("reliability", reliability);
    document.getElementById("reliability").style.background = "#ffcccc";
    req.OnSuccess = function() {
        if(!this.responseText.match("Wiarygodność patronatu została ustawiona na:")) 
            alert(this.responseText);
        document.getElementById("reliability").style.background = "#fff";
        if (document.getElementById("reliability").value != '9'){
            document.getElementById("Generuj button").style.display = 'none';
        }else{
            document.getElementById("Generuj button").style.display = '';
        }
        
    }
    req.OnError= function() {
        alert('błąd serwera');
    }
    req.Send("/news/admin/patronat_add.php", "tresc_form");
}

function zmiana(co,id,data,id_wait){
        
        if (id_wait) document.getElementById(id_wait).style.display = "block";
        var req = mint.Request();
        req.AddParam("co", co);
        req.AddParam("id", id);
        req.AddParam("date", data);
        req.OnSuccess = function() {
            if (id_wait) document.getElementById(id_wait).style.display = "none";
        }
        req.OnError= function() {
            alert('błąd serwera function zmiana()');
        }
        req.Send("/news/admin/modyf.php");
}

//nowa funkcja do usuwania newsow 
//prototype.js
function del_news2(id){
	zmget = 'id='+id + '&no_redirect=true';
	var myAjax = new Ajax.Request("/news/admin/delete.php", 
		{
			method: 'get',
			parameters: zmget,
			onCreate: function() {
					Element.show('wait_mod');
			},
			onComplete: function() {
					alert('News został usunięty!');
					Element.hide('wait_mod');
			},
			onFailure: function() {
					alert('Nie można usunšć podanego newsa!');
					Element.hide('wait_mod');
			}
		});
}		
		
//nowa funkcja do przenoszenia newsow do archiwum
//prototype.js
function archiwum2(id){
	zmget2 = 'id='+id;
	var myAjax = new Ajax.Request("/news/admin/toarchiwum.php", 
		{
			method: 'get',
			parameters: zmget2,
			onCreate: function() {
					Element.show('wait_mod');
			},
			onComplete: function() {
					alert('News został przeniesiony!');
					Element.hide('wait_mod');
			},
			onFailure: function() {
					alert('Nie można przenieć podanego newsa!');
					Element.hide('wait_mod');
			}
		});
}	
