function fnHTMLEditor(pInput)
{
	windowOpen("@cmseditor.asp?INPUT=" + pInput, "popHTMLEditor", 850, 650);
}

function fnUpdateFile(pstrTipoFile, puploadSubdir1, puploadSubdir2, parrVersioni)
{
	puploadSubdir1 = isNull(puploadSubdir1, "");
	puploadSubdir2 = isNull(puploadSubdir2, "");
	parrVersioni = isNull(parrVersioni, "");
	
	var strFileEsistente = document.forms["mainForm"].elements[pstrTipoFile + "OLD"].value;
	windowOpen("@UploadFileSelect.asp?TipoFile=" + pstrTipoFile + "&FileEsistente=" + strFileEsistente + "&uploadSubdir1=" + puploadSubdir1 + "&uploadSubdir2=" + puploadSubdir2 + "&arrVersioni=" + parrVersioni, "popFileSelect", 750, 180, true);
}

function fnDeleteFile(nomeCampo)
{
	resetInputTextField(nomeCampo);
	
	document.forms["mainForm"].elements[nomeCampo].value = "";
	fnUpdateDIV(nomeCampo);
}

function fnUpdateDIV(nomeCampo, uploadSubdir, arrVersioni)
{
	resetInputTextField(nomeCampo);
	
	uploadSubdir = isNull(uploadSubdir, "");
	arrVersioni = isNull(arrVersioni, "");
	var arrSubdir		= new Array();
	var arrTmpFolder	= new Array();
	var arrFolder		= new Array();
	
	var strUploadUrl = GappPublicUrl;
	
	if (uploadSubdir != "")
	{
		arrSubdir = uploadSubdir.split(",");
		
		for (ii = 0; ii < arrSubdir.length; ii++)
		{
			strUploadUrl = strUploadUrl + "/" + arrSubdir[ii];
		}
	}
	
	if (arrVersioni != "")
	{
		arrTmpFolder	= arrVersioni.split("|");
		arrFolder		= arrTmpFolder[1].split(",");
	}
	
	strUploadUrl = (arrVersioni == "") ? strUploadUrl : strUploadUrl + "/" + arrFolder[0];
	
	if (document.getElementById("div" + nomeCampo))
	{
		var strNuovaImmagine = isNull(document.forms["mainForm"].elements[nomeCampo].value, "");
		
		var arrImgType	= ["jpg", "gif", "png", "bmp", "jpeg"];
		for (ii = 0; ii < arrImgType.length; ii++)
		{
			if (strNuovaImmagine.indexOf("." + arrImgType[ii]) != -1)
				document.getElementById("div" + nomeCampo).innerHTML = "<img src=\"" + strUploadUrl + "/" + strNuovaImmagine + "\" border=\"0\" />";
		}

	}
}

function fnSearchFile(nomeCampo, fileTypeToSearch, uploadSubdir, arrVersioni)
{
	resetInputTextField(nomeCampo);
	
	nomeCampo			= isNull(nomeCampo, "");
	fileTypeToSearch	= isNull(fileTypeToSearch, "");
	uploadSubdir		= isNull(uploadSubdir, "");
	arrVersioni			= isNull(arrVersioni, "");
	windowOpen("@SelectFileFromDirectory.asp?fileTypeToSearch=" + fileTypeToSearch + "&nomeCampo=" + nomeCampo + "&uploadSubdir=" + uploadSubdir+ "&arrVersioni=" + arrVersioni, "fnSearchFile", 900, 650, true);
}

function resetInputTextField(nomeCampo)
{
	nomeCampo = isNull(nomeCampo, "");
	
	if ((document.forms["mainForm"].elements[nomeCampo].type).toLowerCase() == "file")
	{
		document.forms["mainForm"].setAttribute("action",	"");
		document.forms["mainForm"].setAttribute("method",	"post");
		document.forms["mainForm"].setAttribute("enctype",	"application/x-www-form-urlencoded");
		document.forms["mainForm"].setAttribute("encoding",	"application/x-www-form-urlencoded");
		document.forms["mainForm"].setAttribute("target",	"");
	
		document.getElementById("divLoading" + nomeCampo).innerHTML = "";
		
		var htmForm = "<input style=\"width:100%;\" type=\"Text\" name=\"" + nomeCampo + "\" id=\"" + nomeCampo + "\" value=\"" + document.forms["mainForm"].elements[nomeCampo + "OLD"].value + "\" />"
		document.getElementById("divUpload" + nomeCampo).innerHTML = htmForm;
		document.getElementById("divMessaggio" + nomeCampo).innerHTML = "";
	}
}

function fnUpdateDIVbyUpload(uploadSubdir, arrVersioni, nomeCampo, imgName, strMessage)
{
	strMessage = isNull(strMessage, "");
	
	document.forms["mainForm"].setAttribute("action",	"");
	document.forms["mainForm"].setAttribute("method",	"post");
	document.forms["mainForm"].setAttribute("enctype",	"application/x-www-form-urlencoded");
	document.forms["mainForm"].setAttribute("encoding",	"application/x-www-form-urlencoded");
	document.forms["mainForm"].setAttribute("target",	"");
	
	document.getElementById("divLoading" + nomeCampo).innerHTML = "";
	
	if (strMessage == "")
	{
		var htmForm = "<input style=\"width:100%;\" type=\"Text\" name=\"" + nomeCampo + "\" id=\"" + nomeCampo + "\" value=\"" + imgName + "\" />"
		document.getElementById("divUpload" + nomeCampo).innerHTML = htmForm;
		document.getElementById("divMessaggio" + nomeCampo).innerHTML = "Il file " + imgName + " è stato correttamente caricato.";
		
		fnUpdateDIV(nomeCampo, uploadSubdir, arrVersioni);
	}
	else
	{
		var htmForm = "<input style=\"width:100%;\" type=\"Text\" name=\"" + nomeCampo + "\" id=\"" + nomeCampo + "\" value=\"" + document.forms["mainForm"].elements[nomeCampo + "OLD"].value + "\" />"
		document.getElementById("divUpload" + nomeCampo).innerHTML = htmForm;
		document.getElementById("divMessaggio" + nomeCampo).innerHTML = unescape(strMessage);
	}
}

function fnUpload(uploadSubdir, arrVersioni, nomeCampo, fileEsistente)
{
	document.forms["mainForm"].setAttribute("action",	"@UploadFileUpload.asp?uploadSubdir=" + uploadSubdir + "&arrVersioni=" + arrVersioni + "&nomeCampo=" + nomeCampo + "&fileEsistente=" + fileEsistente);
	document.forms["mainForm"].setAttribute("method",	"post");
	document.forms["mainForm"].setAttribute("enctype",	"multipart/form-data");
	document.forms["mainForm"].setAttribute("encoding",	"multipart/form-data");
	document.forms["mainForm"].setAttribute("target",	"frameUpload");
	
	document.getElementById("divLoading" + nomeCampo).innerHTML = "<img src=\"images/loading.gif\" width=\"16\" height=\"16\" title=\"file in caricamento...\" alt=\"\" />";
	
	document.forms["mainForm"].submit();
}

function fnShowUpload(uploadSubdir, arrVersioni, nomeCampo)
{
	var htmForm = "";
	
	var fileEsistente = document.forms["mainForm"].elements[nomeCampo + "OLD"].value;
	
	htmForm	+=	"<input onChange=\"javascript:fnUpload('" + uploadSubdir + "', '" + arrVersioni + "', '" + nomeCampo + "', '" + fileEsistente + "');\" id=\"" + nomeCampo + "\" name=\"" + nomeCampo + "\" type=\"file\" value=\"\" style=\"background-color:#ffff00; width:100%;\" />"
			+	"<iframe name=\"frameUpload\" id=\"frameUpload\" style=\"width:300px; height:300px; display:none;\"></iframe>";
	
	document.getElementById("divMessaggio" + nomeCampo).innerHTML = "";
	document.getElementById("divUpload" + nomeCampo).innerHTML = htmForm;
}
