function openItem(id,type) { switch (type) { case 1: openImage(id); break; case 0: openDownload(id); break; } } function openDownload(id) { if (document.getElementById('FileViewer')) { closeObject('FileViewer'); } document.getElementById("FileViewerIcon").src = "icon.php?file="+id; document.getElementById("FileViewerName").innerHTML = document.getElementById("item_"+id+"_name").value; document.getElementById("FileViewerSize").innerHTML = document.getElementById("item_"+id+"_size").value; document.getElementById("FileViewerTime").innerHTML = document.getElementById("item_"+id+"_ctime").value; document.getElementById("FileViewerAuthor").innerHTML = document.getElementById("item_"+id+"_author").value; document.getElementById("FileViewerLink").href = "download.php?file="+id; showCenterLayout(document.getElementById("FileViewerTemp").cloneNode(true),"FileViewer"); } function openImage(id) { if (document.getElementById('ImageViewer')) { closeObject('ImageViewer'); } image = document.createElement("img"); image.src = "image.php?file="+id; image.setAttribute("id","ImageViewerImage"); image.alt = "Click to Close"; image.setAttribute("className","ImageViewerImage"); image.setAttribute("class","ImageViewerImage"); table = document.createElement("table"); table.setAttribute("className","ImageViewer"); table.setAttribute("class","ImageViewer"); a = document.createElement("a"); a.href = "javascript:closeObject('ImageViewer');"; a.appendChild(image); td = document.createElement("td"); td.appendChild(a); tr = document.createElement("tr"); tr.appendChild(td); tbody = document.createElement("tbody"); tbody.appendChild(tr); table.appendChild(tbody); showCenterLayout(table,'ImageViewer'); } function showVote() { obj = document.getElementById("VoteBoxTemp"); showCenterLayout(obj.cloneNode(true),"VoteBox"); }// Basic functions -------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- // use a transparency layer to disable the screen function disableScreen() { div = document.createElement("div"); div.style.width = "100%"; div.style.height = "100%"; div.style.backgroundColor = "#000000"; div.style.position = "absolute"; div.style.top = "0"; div.style.left = "0"; div.style.zIndex = "100"; if (div.style.setAttribute) { div.style.setAttribute("filter","alpha(opacity=50)"); } else { div.style.MozOpacity = 0.5; div.style.Opacity = 0.5; } div.setAttribute("id","DisableScreenLayer"); document.body.appendChild(div); document.body.scroll = "no"; } // close the transparency layer created by disableScreen() function enableScreen() { closeObject("DisableScreenLayer"); } // delete an HTML object by its id function closeObject(objId) { if (document.getElementById(objId)) { document.body.removeChild(document.getElementById(objId)); } } // to display something in the center of the browser // obj - HTML object which will be displayed in the center // objId - The ID which will be given to obj (need to close the object) function showCenterLayout(obj,objId) { table = document.createElement("table"); tbody = document.createElement("tbody"); tr = document.createElement("tr"); td = document.createElement("td"); obj.style.margin = "auto"; table.style.width = "100%" table.style.height = "100%" table.style.position = "absolute"; table.style.top = document.body.scrollTop; table.style.left = 0; table.style.zIndex="101"; table.setAttribute("id",objId); td.style.textAlign = "center"; td.setAttribute("valign","middle"); td.appendChild(obj); tr.appendChild(td); tbody.appendChild(tr); table.appendChild(tbody); document.body.appendChild(table); } // to display a Box in center of the browser while the page is disabled // id - an ID which will be given to the Box // title - a title of the Box // bodycode - a HTML object which will be used to create the body of the Box // width - Box's width // height - Box's height // bgColor - Box's background color // titleColor - Box's title's text color // titleFont - Box's title's font name // titleSize - Box's title's font size // titleWeight - Box's title's font weight // closeButton - a boolean value, true means the box have close button in the top right corner function showBox(id, title, bodyCode, width, height, bgColor, titleColor, titleFont, titleSize, titleWeight, closeButton) { disableScreen(); idiv = document.createElement("div"); idiv.style.width = width+"px"; idiv.style.padding = "0"; idiv.style.minHeight= height+"px"; idiv.style.backgroundColor = bgColor; idiv.style.textAlign = "center"; itbody = document.createElement("tbody"); itable = document.createElement("table"); itr1 = document.createElement("tr"); itr2 = document.createElement("tr"); itd1 = document.createElement("td"); itd2 = document.createElement("td"); itable.style.width = width+"px"; itable.style.height = height+"px"; itable.setAttribute("cellSpacing","0"); itable.setAttribute("cellPadding","0"); itr1.appendChild(itd1); itr2.appendChild(itd2); itbody.appendChild(itr1); itbody.appendChild(itr2); itable.appendChild(itbody); iitable = document.createElement("table"); iitbody = document.createElement("tbody"); iitr = document.createElement("tr"); iitd1 = document.createElement("td"); iitd2 = document.createElement("td"); itd1.style.textAlign = "center"; iitable.style.width = (width-20)+"px"; iitable.style.height = titleSize; iitable.setAttribute("cellSpacing","0"); iitd1.style.fontFamily = titleFont; iitd1.style.fontSize = titleSize; iitd1.style.fontWeight = titleWeight; iitd1.style.color = titleColor; iitd1.style.textAlign = "left"; iitd1.innerText = title; if (closeButton) { a = document.createElement("a"); a.style.fontFamily = "verdana"; a.style.fontSize = "10px"; a.style.color = titleColor; a.style.textDecoration = "none"; a.href = "javascript:closeBox('"+id+"')"; a.innerText = "X"; iitd2.valign = "top"; iitd2.style.textAlign = "right"; iitd2.appendChild(a); } itd2.appendChild(bodyCode); itd1.appendChild(iitable); itd1.style.height = 30; itd2.style.height = height-30; // set table iitable iitr.appendChild(iitd1); iitr.appendChild(iitd2); iitbody.appendChild(iitr); iitable.appendChild(iitbody); idiv.appendChild(itable); showCenterLayout(idiv,id); } // close the Box opened by showBox() // id - box's ID function closeBox(id) { closeObject(id); enableScreen(); } // Specialised functions -------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- function showConfirmBox(message, width, height, buttons, funcs) { div = document.createElement("div"); p = document.createElement("p"); p.style.fontFamily = "arial"; p.style.fontSize = "14px"; p.style.color = "#CCCCCC"; p.setAttribute("align","center"); p.innerText = message; div.appendChild(p); p = document.createElement("p"); p.style.fontFamily = "verdana"; p.style.fontSize = "12px"; p.style.color = "#CCCCCC"; p.style.fontWeight = "bold"; p.setAttribute("align","center"); for (i=0; i < buttons.length; i++) { a = document.createElement("a"); if (funcs[i] && funcs[i] != "") { a.href = "javascript: closeBox('ConfirmBox');"+funcs[i]; } else a.href = "javascript: closeBox('ConfirmBox');"; a.style.fontFamily = "verdana"; a.style.fontSize = "12px"; a.style.fontweight = "bold"; a.style.textDecoration = "none"; a.style.color = "#CCCCCC"; a.innerText = ' [ '+buttons[i]+' ] '; p.appendChild(a); } div.appendChild(p); showBox("ConfirmBox", "Confirmation", div, width, height, "#282828", "#CCCCCC", "Arial", "16px", "bold", true); } function showErrorBox(message, width, height) { p = document.createElement("p"); p.style.fontFamily = "arial"; p.style.fontSize = "14px"; p.style.color = "#222222"; p.innerText = message; p.setAttribute("align","center"); showBox("ErrorBox", "Error", p, width, height, "#B76148", "#222222", "Arial", "16px", "bold", true) } // shorten version of showBox specialised to suit showConfirmBox() function showInformationBox(title, bodyCode, width, height, closeButton) { showBox("InformationBox", title, bodyCode, width, height, "#282828", "#CCCCCC", "Arial", "16px", "bold", closeButton); } function createProgressBar(id, width, height, percent) { table = document.createElement("table"); table.setAttribute("id",id); table.style.width = width; table.style.height = height; table.style.borderWidth = 1; table.style.borderColor = "#CCCCCC"; table.style.borderStyle = "solid"; tbody = document.createElement("tbody"); tr = document.createElement("tr"); td1 = document.createElement("td"); td2 = document.createElement("td"); td1.style.width = percent+"%"; td2.style.width = (100-percent)+"%"; td1.style.backgroundColor = "#CCCCCC"; tr.appendChild(td1); tr.appendChild(td2); tbody.appendChild(tr); table.appendChild(tbody); return table; } function updateProgressBar(obj, percent) { td = obj.getElementsByTagName("tbody")[0].getElementsByTagName("tr")[0].getElementsByTagName("td"); td[0].style.width = percent+"%"; td[1].style.width = (100-percent)+"%"; }