function SetFormFunctions(form, onsubmit) {
form.disabled = false; form.ItemsDisabled = ItemsDisabled; form.ignoreItems = []; form.AutoPostBack = AutoPostBack; form.GetFormContentToSave = GetFormContentToSave; form.oldSubmit = form.submit; form.submit = formSubmit; form.onsubmit = formSubmit; form.__onSubmit = onsubmit; }
function formSubmit(confirm, __onsubmit) {
var __SELF__ = this; if (this.disabled) {
return false; }
if (typeof confirm === 'undefined') {
confirm = true; }
if (typeof __onsubmit === 'undefined') {
__onsubmit = false; }
if (this.__onSubmit != "") {
var tmp; eval("tmp = " + this.__onSubmit + "(this, confirm);"); if (!tmp) {
return false; }}
if (typeof this.confirmMessage !== 'undefined' && this.confirmMessage !== null) {
if (this.AJAX_ACTION && typeof AppStart !== 'undefined') {
AppStart.Confirm(this.confirmMessage, {
"obj" : this, "method" : 'submit'
}); try {
delete this.confirmMessage; } catch(e) {
this.confirmMessage = null; }
return false; } else {
if (!window.confirm(this.confirmMessage)) {
try {
delete this.confirmMessage; } catch(e) {
this.confirmMessage = null; }
return false; }
try {
delete this.confirmMessage; } catch(e) {
this.confirmMessage = null; }}
}
if (confirm) {
this.startTime = new Date(); if (typeof tinyMCE != 'undefined') {
tinyMCE.triggerSave(); }
if (typeof this.AjaxFileUploads === 'undefined') {
this.AjaxFileUploads = {
"Count" : 0, "Items" : [], "Pos" : 0, "lastRefreshFiles" : new Date()
}; var i; for(i = 0; i < this.length; i++) {
if (this[i].nodeName.toUpperCase() === 'INPUT' && this[i].type.toUpperCase() === "FILE" && this[i].getAttribute('ajax') && this[i].value !== "" && !this[i].disabled) {
this.AjaxFileUploads.Count++; this.AjaxFileUploads.Items.push(this[i].id); }}
if (this.AjaxFileUploads.Count > 0) {
this.style.position = "relative"; this.fileLoader = Element.Create('div'); this.fileLoader.className = 'fileLoader'; document.body.appendChild(this.fileLoader); this.fileLoader.style.position = 'absolute'; this.fileLoader.style.top = '0px'; this.fileLoader.style.left = '0px'; this.fileLoader.style.height = document.body.offsetHeight + 'px'; this.fileLoaderContent = Element.Create('div'); this.fileLoaderContent.className = 'fileLoaderContent'; document.body.appendChild(this.fileLoaderContent); this.fileLoaderContent.style.position = 'absolute'; this.fileLoaderContent.style.top = '0px'; this.fileLoaderContent.style.left = '0px'; this.fileLoaderContent.style.textAlign = 'center'; var filename; var content = '<table border="0" cellpadding="3" cellspacing="0" align="center"><tr><th colspan="3"></th></tr>'; for(i = 0; i <this.AjaxFileUploads.Count; i++) {
content += "<tr id=\"" + this.id + "_uploadItem_" + i + "\">"; content += "<td>"; filename = Element(this.AjaxFileUploads.Items[i]).value; if (filename.indexOf("\\") >= 0) {
filename = filename.split("\\"); filename = filename[filename.length-1]; } else if (filename.indexOf("/") >= 0) {
filename = filename.split("/"); filename = filename[filename.length-1]; }
content += filename; content += "</td>"; content += "<td><img src=\"images/transparent.gif\" class=\"upload_wait\"></td>"; content += "<td><div class=\"uploadprogressbar\"><div></div><span>0%</span></div></td>"; content += "</tr>"; }
content += '</table>'; this.fileLoaderContent.innerHTML = content; }}
if (this.AjaxFileUploads.Count > 0 && this.AjaxFileUploads.Count > this.AjaxFileUploads.Pos) {
var file = Element(this.AjaxFileUploads.Items[this.AjaxFileUploads.Pos]); var row = Element(this.id + "_uploadItem_" + this.AjaxFileUploads.Pos); if (!file.uploadInProgress) {
if (!file.uploadFinished) {
row.childNodes[1].innerHTML = "<img src=\"images/transparent.gif\" class=\"upload_start\">"; file.Upload(); } else {
row.childNodes[1].innerHTML = "<img src=\"images/transparent.gif\" class=\"upload_end\">"; row.childNodes[2].firstChild.firstChild.style.width = '100%'; row.childNodes[2].firstChild.childNodes[1].innerHTML = '100%'; this.AjaxFileUploads.Pos++; }} else {
row.childNodes[1].innerHTML = "<img src=\"images/transparent.gif\" class=\"upload_in_progress\">"; if (typeof file.data !== 'undefined') {
var current = parseFloat( (file.data.current / (file.data.total / 100)) ).toFixed(2); row.childNodes[2].firstChild.firstChild.style.width = current + '%'; row.childNodes[2].firstChild.childNodes[1].innerHTML = current + '%'; }}
window.setTimeout("Element('" + this.id + "').submit()",100); var tmpDate = new Date(); if (this.AjaxFileUploads.Pos > 0 && this.AjaxFileUploads.lastRefreshFiles.getTime() + (60 * 1000) < tmpDate.getTime()){
var files = []; var i; for(i = 0; i < this.AjaxFileUploads.Pos; i++) {
files.push(Element(this.AjaxFileUploads.Items[i]).data.temp_filename); }
this.AjaxFileUploads.lastRefreshFiles = new Date(); AJAX.Call("index.php?upload=1&updateFiles=1", { 
"files" : files
}); }
return false; }
if (typeof this.FlashFilesUpload === 'undefined') {
this.FlashFilesUpload = {
"Count" : 0, "Items" : [], "Files": [], "Pos" : 0, "lastRefreshFiles" : new Date(), "Timer": null
}; var i; for(i = 0; i < this.length; i++) {
if (this[i].nodeName.toUpperCase() === 'INPUT' && this[i].type.toUpperCase() === "HIDDEN" && this[i].getAttribute('flashupload') && !this[i].disabled) {
var files = this[i].GetObject().GetFiles(); if (files.length > 0) {
this.FlashFilesUpload.Count++; this.FlashFilesUpload.Items.push(this[i]); this[i].GetObject().OnProgress = function(obj, params) {
var row = Element(__SELF__.id + "_uploadItem_" + params.GUID); row.childNodes[1].innerHTML = "<img src=\"images/transparent.gif\" class=\"upload_in_progress\">"; var current = params.File.progress.percent.toFixed(2); row.childNodes[2].firstChild.firstChild.style.width = current + '%'; row.childNodes[2].firstChild.childNodes[1].innerHTML = current + '%'; }; this[i].GetObject().OnComplete = function(obj, params) {
var row = Element(__SELF__.id + "_uploadItem_" + params.GUID); row.childNodes[1].innerHTML = "<img src=\"images/transparent.gif\" class=\"upload_end\">"; row.childNodes[2].firstChild.firstChild.style.width = '100%'; row.childNodes[2].firstChild.childNodes[1].innerHTML = '100%'; }; this[i].GetObject().OnCompleteAll = function() {
__SELF__.FlashFilesUpload.Pos++; __SELF__.submit(); }; for(var j = 0; j < files.length; j++) {
this.FlashFilesUpload.Files.push(files[j]); }}
}}
if (this.FlashFilesUpload.Files.length > 0) {
this.fileLoader = Element.Create('div'); this.fileLoader.className = 'fileLoader'; document.body.appendChild(this.fileLoader); this.fileLoader.style.position = 'absolute'; this.fileLoader.style.top = '0px'; this.fileLoader.style.left = '0px'; this.fileLoader.style.width = document.body.offsetWidth + 'px'; this.fileLoader.style.width = '100%'; this.fileLoader.style.height = document.body.offsetHeight + 'px'; this.fileLoaderContent = Element.Create('div'); this.fileLoaderContent.className = 'fileLoaderContent'; document.body.appendChild(this.fileLoaderContent); this.fileLoaderContent.style.position = 'absolute'; this.fileLoaderContent.style.top = '0px'; this.fileLoaderContent.style.left = '0px'; this.fileLoaderContent.style.width = '100%'; this.fileLoaderContent.style.textAlign = 'center'; var filename; var content = '<table border="0" cellpadding="3" cellspacing="0" align="center"><tr><th colspan="3"></th></tr>'; for(i = 0; i <this.FlashFilesUpload.Files.length; i++) {
content += "<tr id=\"" + this.id + "_uploadItem_" + this.FlashFilesUpload.Files[i].GUID + "\">"; content += "<td>"; filename = this.FlashFilesUpload.Files[i].File.name; if (filename.indexOf("\\") >= 0) {
filename = filename.split("\\"); filename = filename[filename.length-1]; } else if (filename.indexOf("/") >= 0) {
filename = filename.split("/"); filename = filename[filename.length-1]; }
content += filename; content += "</td>"; content += "<td><img src=\"images/transparent.gif\" class=\"upload_wait\"></td>"; content += "<td><div class=\"uploadprogressbar\"><div></div><span>0%</span></div></td>"; content += "</tr>"; }
content += '</table>'; this.fileLoaderContent.innerHTML = content; for(i = 0; i < this.FlashFilesUpload.Items.length; i++) {
this.FlashFilesUpload.Items[i].Upload(); }
return false; }}
if (this.FlashFilesUpload.Count > 0 && this.FlashFilesUpload.Count > this.FlashFilesUpload.Pos) {
return false; }
if (this.AJAX_ACTION && typeof AppStart !== 'undefined') {
if (this.AjaxFileUploads.Count > 0) {
this.fileLoader.parentNode.removeChild(this.fileLoader); this.fileLoaderContent.parentNode.removeChild(this.fileLoaderContent); }
var post = this.GetFormContentToSave('OBJECT'); var action = this.action.split('?'); if (typeof action[1] !== 'undefined') {
action = action[1]; } else {
action = ""; }
AppStart.LoadModuleContent(this.moduleID, this.module, action, post); return false; } else {
this.oldSubmit(); return true; }} else {
return false; }}
function ItemsDisabled(disabled) {
var i, temp; for(i = 0; i < this.length; i++) {
temp = this[i]; switch(temp.nodeName.toUpperCase()) {
case 'FIELDSET': break; default: temp.disabled = disabled; break; }}
}
function GetNodeContentToSave(node, type, deletePrefix) {
var items = []; var i, inputs, types = [ "input", "select", "textarea" ]; for(var t = 0; t < types.length; t++) {
inputs = node.getElementsByTagName(types[t]); for(i = 0; i < inputs.length; i++) {
items[items.length] = inputs[i]; }}
return CreatePostDataToSave(items, type, [], deletePrefix); }
function GetFormContentToSave(type) {
return CreatePostDataToSave(this, type, this.ignoreItems); }
function CreatePostDataToSave(items, type, ignoreItems, deletePrefix) {
var i, temp, PostData, tmpName; if (typeof ignoreItems === 'undefined') {
ignoreItems = []; }
if (typeof deletePrefix === 'undefined') {
deletePrefix = null; }
if (typeof type === 'undefined') {
type = 'TEXT'; }
switch(type) {
case 'TEXT': PostData = ""; break; case 'XML': PostData = ""; break; case 'OBJECT': PostData = {}; break; }
for(i = 0; i < items.length; i++) {
temp = items[i]; if (typeof temp.name === 'undefined' || (typeof temp.name !== 'undefined' && temp.name == "")) {
continue; } else {
tmpName = (deletePrefix ? temp.name.replace(deletePrefix,'') : temp.name); tmpName = tmpName.replace("-","_"); }
switch(temp.nodeName.toUpperCase()) {
case 'FIELDSET': break; case 'TEXTAREA': if (typeof tinyMCE !== 'undefined') {
if (tinyMCE.get(temp.id)) {
temp.value = tinyMCE.get(temp.id).getContent(); }}
default: if (!ignoreItems.inArray(temp.name)) {
switch(temp.type.toUpperCase()) {
case 'FILE': break; case 'RADIO': case 'CHECKBOX': if (temp.checked) {
switch(type) {
case 'TEXT': PostData += (PostData==""?"":"&") + tmpName + "=" + temp.value; break; case 'XML': PostData = "<" + tmpName + ">" + temp.value + "</" + tmpName + ">"; break; case 'OBJECT': PostData[tmpName] = temp.value; break; }}
break; default: switch(type) {
case 'TEXT': PostData += (PostData==""?"":"&") + tmpName + "=" + AJAX.ConvertHTMLtoPOST(temp.value); break; case 'XML': PostData = "<" + tmpName + ">" + AJAX.ConvertHTMLtoPOST(temp.value) + "</" + tmpName + ">"; break; case 'OBJECT': var match = tmpName.match(/\[([^\]]*)\]/); if (match) {
tmpName = tmpName.replace(/\[[^\]]*\]/,""); if (typeof PostData[tmpName] === 'undefined') {
PostData[tmpName] = {}; }
PostData[tmpName][match[1]] = typeof temp.data === 'undefined' ? AJAX.ConvertHTMLtoPOST(temp.value) : temp.data; } else {
PostData[tmpName] = typeof temp.data === 'undefined' ? AJAX.ConvertHTMLtoPOST(temp.value) : temp.data; }
break; }
break; }}
break; }}
return PostData; } 
function SubmitImage(img, value) {
var tmp = img; while(tmp && tmp.nodeName.toUpperCase() !== 'FORM') {
tmp = tmp.parentNode; }
if (tmp && tmp.nodeName.toUpperCase() === 'FORM') {
if (img.getAttribute('confirmmessage')) {
tmp.confirmMessage = img.getAttribute('confirmmessage'); }
var hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = img.name; hidden.value = value; tmp.appendChild(hidden); return true; }
return false; }
function CreateAjaxFileUpload(id) {
var file = Element.Create('input'); file.type = 'file'; file.id = id; file.name = id; file.setAttribute('ajax',"1"); file.Upload = function() { 
UploadFile(this.id); }; file.uploadInProgress = false; file.uploadFinished = false; return file; }
function UploadFile(id) {
var file = Element(id); var form = file.parentNode; if (!file.uploadInProgress) {
file.uploadInProgress = true; file.uploadFinished = false; while(form && form.nodeName.toUpperCase() !== 'FORM') {
form = form.parentNode; }
var apc_progresskey = Element.Create('input'); apc_progresskey.type = 'hidden'; apc_progresskey.name = 'APC_UPLOAD_PROGRESS'; apc_progresskey.value = (Math.random() * (new Date().getTime())).toString().replace(/\./,""); var tmpForm = Element.Create('form'); tmpForm.action = "?upload=" + apc_progresskey.value; tmpForm.method = "POST"; tmpForm.enctype = "multipart/form-data"; tmpForm.target = "upload_frame_" + apc_progresskey.value; if (UA.isIE()) {
tmpForm.setAttribute('encoding','multipart/form-data'); }
tmpForm.style.display = "inline-block"; tmpForm.style.maring = "0px;"; tmpForm.style.padding = "0px;"; file.parentNode.insertBefore(tmpForm, file); tmpForm.appendChild(apc_progresskey); tmpForm.appendChild(file); var iframe = Element.Create('span'); iframe.innerHTML = '<iframe onload="UploadFinish(\'' + file.id + '\', \'upload_frame_' + apc_progresskey.value + '\');" id="upload_frame_' + apc_progresskey.value + '" name="' + "upload_frame_" + apc_progresskey.value + '" width="1" height="1" frameborder="0" style="visibilty: hidden; position: absolute;"></iframe>'; iframe = iframe.firstChild; tmpForm.parentNode.appendChild(iframe); tmpForm.submit(); var img = Element.Create('img'); img.src = 'images/transparent.gif'; img.className = "fileUploadPreloader"; img.align = "absmiddle"; file.parentNode.insertBefore(img, file); file.style.display = "none"; file.response = false; file.timer = window.setTimeout("CheckUpladedFileStatus('" + id + "', '" + apc_progresskey.value + "')", 100); }}
function UploadFinish(id, iframeID) {
var file = Element(id); var iframe = Element(iframeID); var response; if (iframe.contentWindow.document.body) {
if (iframe.contentWindow.document.body.firstChild && iframe.contentWindow.document.body.firstChild.nodeName.toUpperCase() === 'PRE') {
response = iframe.contentWindow.document.body.firstChild.innerHTML; } else {
response = iframe.contentWindow.document.body.innerHTML; }
if (response == "") {
return; }
try {
var data = response; eval('response = ' + response + ';'); } catch(e) {
alert(e.message); return; }
if (response && response != "false") {
if (file.AJAX) {
try {
} catch(e) {
if (typeof console != 'undefined') {
console.log(e.message); }}
}
if (file.timer) {
window.clearTimeout(file.timer); }
response.filename = response.filename.replace(/^.*[\\,\/](.*)$/,"$1"); var inputHidden = Element.Create('input'); inputHidden.id = file.id; inputHidden.name = file.name; inputHidden.type = 'hidden'; inputHidden.data = response; inputHidden.value = data; inputHidden.uploadInProgress = false; inputHidden.uploadFinished = true; file.parentNode.parentNode.insertBefore(inputHidden, file.parentNode); file.parentNode.parentNode.insertBefore(Element.CreateText(response.filename), file.parentNode); file.parentNode.parentNode.removeChild(file.parentNode); iframe.contentWindow.document.open("text/plain",""); iframe.contentWindow.document.close(); iframe.parentNode.removeChild(iframe); try {
if (typeof file.OnFinishUpload === "function") {
file.OnFinishUpload(response); }
if (file.getAttribute('onfinishupload')) {
eval(file.getAttribute('onfinishupload')); }
if (file.getAttribute('onendupload')) {
eval(file.getAttribute('onendupload')); }} catch(e) {
if (typeof console !== 'undefined' && typeof console.log !== 'undefined') {
console.log('AjaxFileUpload (' + file.id + '): ' + e.message); }}
}}
}
function CheckUpladedFileStatus(id, apc_progresskey) {
var file = Element(id); if (file && file.type === 'file') {
if (file.data && ( (typeof file.data.cancel_upload !== 'undefined' && parseInt(file.data.cancel_upload,10) > 0) || (typeof file.data.done !== 'undefined' && parseInt(file.data.done,10) > 0) ) ) {
return; }
file.AJAX = AJAX.Call("index.php?upload=" + apc_progresskey + "&checkOnly=1", " ", AJAX.JSON, null, UploadFileCallBack, id, apc_progresskey); }}
function UploadFileCallBack(response, id, apc_progresskey) {
var file = Element(id); if (!AJAX.isError(response)) {
if (!file.uploadFinished) {
response.filename = response.filename.replace(/^.*[\\,\/](.*)$/,"$1"); file.data = response; try {
if (typeof file.OnCheckStatus === "function") {
file.OnCheckStatus(response); }
if (file.getAttribute('oncheckstatus')) {
eval(file.getAttribute('oncheckstatus')); }} catch(e) {
} file.timer = window.setTimeout("CheckUpladedFileStatus('" + id + "', '" + apc_progresskey + "')", 500); }}
}
function AutoPostBack() {
this.method = 'POST'; this.action = this.AutoPostBackAction; var names = {
data: [], AddName:function(name) {
if (!this.IssetName(name)) {
this.data.push(name); }}, IssetName:function(name) {
var isset = false; for(var i in this.data) {
if (this.data[i] == name) {
isset = true; }}
return isset; }}; var remove = new Array(); var temp = document.createElement('input'); temp.type = 'hidden'; temp.name = 'AutoPostBack' + this.AutoPostId; temp.value = 1; this.appendChild(temp); for(var i = 0; i < this.length; i++) {
var temp = this[i]; switch(temp.nodeName.toUpperCase()) {
case 'FIELDSET': break; default: switch(temp.type.toUpperCase()) {
case 'FILE': break; default: switch(temp.name.toUpperCase()) {
case 'OP': case 'PARAM': case 'MODID': case 'MODNAME': case 'VALIDATORS': remove.push(temp); break; default: names.AddName(temp.name)
break; }
break; }
break; }}
if (remove.length > 0) {
var tmp = remove.pop(); while(tmp) {
if (typeof tmp == 'object') {
this.removeChild(tmp); }
tmp = remove.pop(); }}
ProcessPostData(this, names); if (typeof tinyMCE != 'undefined') {
tinyMCE.triggerSave(); }
this.submit(); }	
function ProcessPostData(form, names) {
if (form.AutoPostData !== null) {
for(var i in form.AutoPostData) {
if (typeof form.AutoPostData[i] != 'function') {
if (names !== null && !names.IssetName(i)) {
if (typeof form.AutoPostData[i] == 'object') {
var tempData = setObjectData(form.AutoPostData[i]); for(var j = 0; j < tempData.length; j++) {
if (!names.IssetName(i + tempData[j][0])) {
var temp = document.createElement('input'); temp.type = 'hidden'; temp.name = i + tempData[j][0]; temp.value = tempData[j][1]; form.appendChild(temp); }}
} else {
var temp = document.createElement('input'); temp.type = 'hidden'; temp.name = i; temp.value = form.AutoPostData[i]; form.appendChild(temp); }}
}}
}}
function CreateProgressBar(_id, _className) {
var tmp = Element.Create('div'); tmp.id = _id; tmp.innerHTML = '<div></div><div></div>'; if (typeof _className !== 'undefined') {
tmp.className = _className; } else {
tmp.className = 'saveProgressBar'; }
tmp.firstChild.style.width = "0%"; tmp.childNodes[1].innerHTML = "0%"; return tmp; }
function UpdateProgressBar(_id, _max, _current) {
var tmp = Element(_id); var value = 0; value = _current / (_max/100); value = value.toFixed(2); tmp.firstChild.style.width = value + "%"; tmp.childNodes[1].innerHTML = value + "%"; }