function browser(){
	if (navigator.appName == "Netscape"){
		if (navigator.appVersion.indexOf('Safari') > -1){css='sf';}
		else{css=(parseInt(navigator.appVersion.substring(0,1))== 4)?'ns':'mz';}
	}
	else{css=(navigator.appVersion.indexOf('MSIE 6')>-1)?'ie':'ie4';}
	document.write ('<link rel="stylesheet" type="text/css" href="/admin/css/'+css+'.css">');
}
browser();

function opener(where,w,h){
	var url = where;
	var width = w;
	var height = h;
	mywin = window.open("","","resizable=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,status=no,width="+width+",height="+height+",left=0,top=0");
	mywin.document.open();
	mywin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Preview</title></head><body marginheight=0 marginwidth=0 topmargin=0 leftmargin=0><img src="'+url+'" border=0></body></html>');
	mywin.document.close();
}

function elimina(img,where){
	if(confirm('Sei sicuro di voler eliminare il file "'+img+'"?')){
		document.location.href='./admin.php?elimina='+img+'&view='+where;
	}
}

function eliminaPreview(img,where1,where2){
	if(confirm('Sei sicuro di voler eliminare il file '+img.substring(3)+'?')){
		document.location.href='./admin.php?delpreview='+img.substring(3)+'&padre1='+where1+'&progetto1='+where2;
	}
}

function eliminaDir(){
check=false;
	for(i=0; i<document.getElementsByName('dir').length; i++){
		if(document.getElementsByName('dir').item(i).checked==true){
			check=true;
		}
	}
	if(!check){alert('Seleziona una cartella da eliminare');}
	else{
		if(confirm('Sei sicuro di voler eliminare la directory?')){document.getElementById('deletedir').submit();}
	}
}

function uploadMe(){
	if(document.getElementById('upload').img.value==''){alert('Seleziona un file dal tuo hd');}
	else{document.getElementById('upload').submit();}
}

function createDir(){
	check=0;
	if(document.getElementById('createdir').newdir.value==''){check=1;}
	if(document.getElementById('createdir').password.value==''){check=1;}
	if(check==1){alert('Controlla che tutti i campi siano riempiti');}
	else{document.getElementById('createdir').submit();}
}

function invia(n){
	thisform = document.getElementById(n);
	if(thisform.name.value == ''){alert('Scrivi la tua userID');}
//	else if(thisform.pwd.value == ''){alert('Scrivi la tua password');}
	else {thisform.submit();}
}

function rename(what,ext){
	document.getElementById('renamebox').style.display='block';
	document.getElementById('oldname').value=what;
	document.getElementById('extension').value=ext;
	document.getElementById('newname').focus();
	return;
}

function sendMail(){
	if(document.getElementById('sendmail').oggetto.value=='' || document.getElementById('sendmail').body.value==''){alert('Non lasciare nessun campo vuoto');}
	else {document.getElementById('sendmail').submit();}
}

function eliminaMail(what){
	if(confirm('Sei sicuro di voler eliminare questo indirizzo di posta?')){
		document.location.href='./newsletter.php?delmail='+what;
	}
}

function addMail(){
	if(document.getElementById('addThisMail').nome.value=='' || document.getElementById('addThisMail').email.value==''){alert('Non lasciare nessun campo vuoto');}
	else {
		if(document.getElementById('addThisMail').nome.value.indexOf('\'')>-1 || document.getElementById('addThisMail').email.value.indexOf('\'')>-1){alert('Attenzione!\nNon è possibile inserire caratteri speciali come \' o \'"');}
		else{document.getElementById('addThisMail').submit();}
	}
}

function newProject(where){
	document.getElementById('padre').value=where;
	document.getElementById('newproject').style.display='block';
}

function delProj(what){
	if(confirm('Sei sicuro di voler eliminare questo progetto?')){
		document.location.href='./admin.php?delproj='+what;
	}
}

function switchPic(who,commento){
	var immagini=document.getElementsByName('images');
	document.getElementById('switchme').src='./'+who;
	document.getElementById('commento').innerHTML='<b>'+who.substring(0,who.length-4)+'</b>'+'<br>'+commento;
	for(var i=0;i<immagini.length;i++){
		if(immagini[i].href.indexOf(who)>-1){
			if((i-1)>=0){
				document.getElementById('preva').style.display='inline';
				document.getElementById('preva').href=immagini[i-1].href;
			}
			else{document.getElementById('preva').style.display='none';}
			if((i+1)<immagini.length){
				document.getElementById('nexta').style.display='inline';
				document.getElementById('nexta').href=immagini[i+1].href;
			}
			else{document.getElementById('nexta').style.display='none';}
		}
	}
	document.getElementById('prevnext').style.display='block';
}

function checkAll(){
	var check_status = document.getElementById('checkall').checked;
	if (!document.getElementsByName('exclude[]')){
		// non esiste alcun elemento
		return;
	}
	if (!document.getElementsByName('exclude[]').length){
		// esiste un solo elemento
		document.getElementsByName('exclude[]').checked=check_status;
	}
	else {
		var end = document.getElementsByName('exclude[]').length;
		for (i=0;i<end;i++){
			document.getElementsByName('exclude[]')[i].checked=check_status;
		}
	}
}