function changeLocation(url){
	window.location=url;
}

function changeVisible(id){
	var status = (document.getElementById(id).style.display == "block") ? "none" : "block";
    document.getElementById(id).style.display = status;
    document.cookie="menu="+id;
    document.cookie="menustatus="+status;
}

function unsetDisabled(id){
	document.getElementById(id).disabled = false;
}

function favorites(){
	if(navigator.appName=="Netscape")
		alert('Aby dodać do ulubionych wciśnij klawisze: CTRL+D');
	else
		window.external.AddFavorite(document.location,document.title);
}

function test(){
	alert(navigator.appName);
}

function noweOkno(URL,Name,w,h) {
	var X = ((screen.width)/3);
	var Y = ((screen.height)/3.5);
	window.open(URL,Name,'toolbar=no,location=no,directories=no,status=no,\
				menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,\
				width='+w+',height='+h+', left='+X+', top='+Y);
}

function setCursorIn(id){
        document.getElementById(id).focus();
}

function addFileField(id){
	var files = document.getElementById(id);
	var newf = document.createElement('input');
	var numi = document.getElementById('value');
	var num = (numi.value -1)+2;
	numi.value = num;
	var newId = 'f'+num;
	
	newf.setAttribute('type','file');
	newf.setAttribute('id','f'+num);
	newf.setAttribute('name','f'+num);
	files.appendChild(newf);
	files.innerHTML += "<br />";
}
function delFileField(fid,div){
	var files = document.getElementById(div);
	var oldFile = document.getElementById(fid);
	files.removeChild(oldFile);
}

function addNews(){
if(xmlHttp){
	try{
			var url = "panel.php";
			var par = "url=newsForm";
			
			xmlHttp.open("POST",url,true);
			xmlHttp.onreadystatechange = openFile;
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlHttp.send(par);
		}catch(e){
			alert('Błąd odpowiedzi: '+e.toString());
		}
	}
}

function saveNews(job){
if(xmlHttp){
	try{
			var url = "panel.php";
			var txt = encodeURIComponent(document.getElementById('elm1').value);
			var title = encodeURIComponent(document.getElementById('title').value);
			var status = encodeURIComponent(document.getElementById('status').value);
			if(job=='update'){
				job="updateNews&id="+encodeURIComponent(document.getElementById('id').value);
			}else
				job="saveNews";
			var par = "url="+job+"&txt="+txt+"&title="+title+"&status="+status;
			
			xmlHttp.open("POST",url,true);
			xmlHttp.onreadystatechange = openFile;
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlHttp.send(par);
		}catch(e){
			alert('Błąd odpowiedzi: '+e.toString());
		}
	}
}

function getValue(id){
	return encodeURIComponent(document.getElementById(id).value);
}

function testMail(){
		var test = document.getElementById('test');
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		while(reg.test(mtest)==false){
			var mtest=prompt('Podaj adres e-mail na który ma zostać wysłany\n testowa wiadomość','');
		}
		test.value=mtest;
}