/* File browser functions */
var strSaveToField = '';
var strImageName = '';
var strAllowedFileTypes = '';
var intWidth = 32; // Default value
var intHeight = 32; // Default value
function filebrowser_open(inputField,strImage,strAllowedFile,Width,Height) {
strSaveToField = inputField
strImageName = strImage;
strAllowedFileTypes = strAllowedFile;
intWidth = Width;
intHeight = Height;
try {
if (typeof(TheFilebrowser) != 'undefined') {
TheFilebrowser.focus();
} else {
TheFilebrowser = window.open("","filebrowser","width=1,height=1,left=2000,toolbar=no,scrollbars=no,resizable=no")
if (TheFilebrowser.document.location.href.toLowerCase().indexOf('fileexplorer') == -1) {
TheFilebrowser.close();
filebrowser_open_window();
}
setTimeout('TheFilebrowser.focus();',100);
}
}
catch(er) {
filebrowser_open_window();
}
}
function filebrowser_open_window() {
var intWidth = 790;
var intheight = 521;
var strExtraQuerystring = '';
field = document.getElementById(strSaveToField);
if (field != null) {
strExtraQuerystring = '?id=' + field.value;
}
TheFilebrowser = window.open('FileExplorer' + strExtraQuerystring,"filebrowser","toolbar=no,width="+intWidth+",height="+intheight+",scrollbars=yes,resizable=yes");
setTimeout('TheFilebrowser.focus();',100);
}
function filebrowser_open_for_browse() {
var intWidth = 790;
var intheight = 521;
TheFilebrowser = window.open('FileExplorer?sfsi=0',"filebrowser","toolbar=no,width="+intWidth+",height="+intheight+",scrollbars=yes,resizable=yes");
}
function filebrowser_select(file) {
// Moved ImageControlName to an input-field on function: filebrowser_open, AEH 21-12-2006
//filetypes = document.getElementById(strSaveToField + '_AllowedFileTypes');
//image = document.getElementById(strSaveToField + "Img");
filetypes = document.getElementById(strAllowedFileTypes);
field = document.getElementById(strSaveToField);
image = document.getElementById(strImageName);
if (field != null && image != null) {
var booSetFile = false;
if (filetypes.value != "") {
if (!isNaN(file)) {
loadFileInfoXML(file);
} else {
getFileTypeFromString(file);
}
if (strFileType != '') {
if (filetypes.value.indexOf(strFileType) != -1) {
booSetFile = true;
}
}
} else {
booSetFile = true;
}
if (booSetFile) {
field.value = file;
image.src = 'FileExplorer/fetchfile.aspx?file=' + file + '&mw=' + intWidth + '&mh=' + intHeight + '';
window.focus();
} else {
window.focus();
//alert("Den valgte fil er af en ugyldig filtype! Følgende filtyper er tilladt:\n\n" + filetypes.value);
alert("Invalid filetype\n\n" + filetypes.value);
TheFilebrowser.focus();
}
}
}
var xmlDoc;
var strFileType = '';
function loadFileInfoXML(intID) {
// Load xml file
if (window.ActiveXObject) { // code for IE
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load('FileExplorer/fetchfile.aspx?id=' + intID + '&i=1');
getFileTypeFromXML()
} else if (document.implementation && document.implementation.createDocument) { // code for Mozilla, etc.
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load('FileExplorer/fetchfile.aspx?id=' + intID + '&i=1');
xmlDoc.onload = getFileTypeFromXML
} else {
//alert('Your browser cannot handle this script');
}
}
function getFileTypeFromXML() {
var strName = xmlDoc.getElementsByTagName("Name")[0].firstChild.nodeValue;
strFileType = strName.substr(strName.indexOf(".") +1,(strName.length - strName.indexOf(".") +1));
strFileType = strFileType.toLowerCase();
}
function getFileTypeFromString(strName) {
strFileType = strName.substr(strName.indexOf(".") +1,(strName.length - strName.indexOf(".") +1));
strFileType = strFileType.toLowerCase();
}