function isValueInArray(arr,val) {
	var inArray=false;
	for (i=0; i<arr.length; i++) if (val==arr[i]) inArray=true;
	return inArray;
}

function showpopup(id,w,h) {
	var stile="top=50, left=50, width="+w+", height="+h+", status=no, menubar=no, toolbar=no, scrollbars=yes";
	window.open("news/popup.php?id="+id,"_popup",stile);
}

function shownewspopup() {
	var stile="top=50, left=50, width=780, height=450, status=no, menubar=no, toolbar=no, scrollbars=yes";
	window.open("newspopup.php","_popup",stile);
}

function getImgSize(image) {
	/* controllo che sia una immagine */
	var ext=image.value.split('.').pop();
	var arr=new Array("jpeg","jpg","png","gif");
	var h=0; var w=0; var src='';
	/* calcolo le dimensioni dell'immagine */
	if (isValueInArray(arr,ext)) {
		var newImg=new Image();
		newImg.src=image.files.item(0).getAsDataURL();
		h=newImg.height;
		w=newImg.width;
		/* scalo l'immagine in proporzione */
		if (w>h) {
			if (w/h>4/3) { /* 640x400 */
				src='<img border="0" src="'+image.files.item(0).getAsDataURL()+'" width="200" height="'+Math.round(h/(w/200))+'">';
			} else { /* 640x560 */
				src='<img border="0" src="'+image.files.item(0).getAsDataURL()+'" width="'+Math.round(w/(h/150))+'" height="150">';
			}
		} else { /* w<=h */
			src='<img border="0" src="'+image.files.item(0).getAsDataURL()+'" width="'+Math.round(w/(h/150))+'" height="150">';
		}
		document.getElementById('tempimmagine').innerHTML=src;
	}
}

function ismaxlength(obj){
	var mlength=obj.getAttribute?parseInt(obj.getAttribute("maxlength")):"";
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength);
}

function on_off() {
	document.getElementById('vis_from').disabled=!document.getElementById('popup').checked;
	document.getElementById('vis_to').disabled=!document.getElementById('popup').checked;
}


