// JavaScript Document

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function CheckLink(kL, cod) {
  	document.form.id.value = cod;
	document.form.kindlink.value = kL; 
	document.form.task.value = 'checklink';
   	document.form.submit();
}

function ChangeCategoria() {
  	document.form.parent.value = 0;
	document.form.editor.value = editor.getHTML();
	document.form.submit();
}

function ExecPreview() {
	var winl = (screen.width - 640) / 2;
	var wint = (screen.height - 480) / 2;
	win = window.open('preview.php', 'Preview', 'height=480,width=640,top='+wint+',left='+winl+',scrollbars=yes')
    win.window.focus(); 
}

function ExecUpload() {
	var winl = (screen.width - 500) / 2;
	var wint = (screen.height - 250) / 2;
	win = window.open('upload.php', 'Upload', 'height=250,width=500,top='+wint+',left='+winl+',scrollbars=yes,status=yes')
    win.window.focus(); 
}

function ExecFunction(task) {
  	document.form.task.value = task;
	if (task == 'save_page') {
		document.form.editor.value = editor.getHTML();
	}
    else if (task == 'save_message') { 
		document.form.imagesprop.value = createListProps('imagespage');
		document.form.editor.value = editor.getHTML();
	}
	else  if (( (task == "html") || (task == "edit")) && (document.form.radiochecked.value == 0)) {
  		alert("Attenzione: occorre selezionare una riga per procedere all'operazione");
		exit();
	}
   	document.form.submit();
}

function SetPathImage(path) {
	document.PreviewImage.src = path+getSelectedValue('form','listimage');
	document.form.sourceimg.value = getSelectedValue('form','listimage');
}

function SetPathImageSelected(path) {
	var ImageName = getSelectedValue('form','imagespage').split('|');
	document.SelectedImage.src = path+ImageName[0];
}


function  ShowMessage(indx){
	var Message = new Array();
	Message[0] = "Il documento è accessibile solo previa autenticazione";

	alert(Message[indx]);
}

function OpenWinDoc(accesslimited, pathFile) {
	var xleft = screen.height;
	var xtop = screen.width;
	var XX = (xtop - 800)/2;
	var YY = (xleft - 600)/2;
	if (accesslimited == 'false') {
   		ShowMessage(0);
	}
	else { 
		Mywin = window.open('Documento','Documento','left='+XX+',top='+YY+',width=800,height=600,scrollbars=yes');
		Mywin.location.href = pathFile;
		Mywin.focus();
	}
}

function OpenImageGallery(pathFile, fileName, imgwidth, imgheight) {
	var xleft = screen.height;
	var xtop = screen.width;
	var XX = (xtop - imgwidth)/2;
	var YY = (xleft - imgheight)/2;
	Mywin = window.open('','Documento','left='+XX+',top='+YY+',width='+imgwidth+',height='+imgheight+',scrollbars=no');
	with (Mywin.document) {
		open();
		writeln('<html>');
		writeln('<head>');
		writeln('<title>'+fileName+'</title>');
		writeln('</head>');
		writeln('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">');
		writeln('<img src="'+pathFile+'" border="0">');
		writeln('</body>');
		writeln('</html>');
		close();
	}
	Mywin.focus();
}


function OrderBy(name) {
  	document.form.orderBy.value = name;
	document.form.submit();
}

function SetEnableRadioB(el) {
  	var  objPageHTML = eval('document.form.pageHTML');
  	var  objPageDB = eval('document.form.pageDB');
  	var  objFunctions = eval('document.form.functions');
  	var  objGalleries = eval('document.form.galleries');
	
  	if (objPageHTML != null) {
		if ((el == 'pageHTML') && (objPageHTML.disabled)) objPageHTML.disabled = false; 
		else {
			objPageHTML.disabled = true;
			objPageHTML.value = '';
		}
	}
  	if (objPageDB != null) {
		if ((el == 'pageDB') && (objPageDB.disabled)) objPageDB.disabled = false; 
		else {
			objPageDB.disabled = true;
			objPageDB.value = '';
		}
	}
  	if (objFunctions != null) {
		if ((el == 'functions') && (objFunctions.disabled)) objFunctions.disabled = false; 
		else {
			objFunctions.disabled = true;
			objFunctions.value = '';
		}
	}
  	if (objGalleries != null) {
		if ((el == 'galleries') && (objGalleries.disabled)) objGalleries.disabled = false; 
		else {
			objGalleries.disabled = true;
			objGalleries.value = '';
		}
	}
}
