var IE  = document.all?true:false;
var alertMsg = new Array();
var errorMsg = new Array();
var popup;
var a;
var anchorObject;
var tmpAnchor;
var selectedOption;
var dragableComponent;
var refreshTimerSecs = 2000; // 2 seconds between each refresh
var refreshKeyCodes = new Array();
refreshKeyCodes[0] = 116;
refreshKeyCodes[1] = 82;
refreshKeyCodes[2] = 114;
var backSpaceKeyCodes = new Array();
backSpaceKeyCodes[0] = 8;
var defaultFilename = 'marcompro.php';
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
if((!wysiwyg)||(wysiwyg == 'undefined')){
var wysiwyg = null;
}
if((!wysiwyg2)||(wysiwyg2 == 'undefined')){
var wysiwyg2 = null;
}
setAnchorEvents = function() {
var anchors = document.getElementsByTagName('A');
for(i=0;i<anchors.length;i++) {
var anchor = anchors[i];
if(IE) {
anchor.attachEvent("onfocus", focusEventAction);
anchor.onmouseup = lookForChanges;
anchor.attachEvent("onmouseup", setAnchorObject);
} else {
anchor.addEventListener("focus", focusEventAction, true);
anchor.addEventListener("click", setAnchorObject, true);
anchor.addEventListener("click", lookForChanges, true);
anchor.addEventListener("mouseover", checkMouseOvers, true);
}
}
}
checkMouseOvers = function(evt) {
var a = evt.currentTarget;
if(a.onclick != '') {
a.onclick_tmp = a.onclick;
a.onclick = '';
}
}
focusEventAction = function(evt) {
if(IE) {
var obj = event.srcElement;
obj.blur();
} else {
var obj = evt.currentTarget;
obj.blur();
}
}
lookForChanges = function(evt) {
if(IE) {
var obj = event.srcElement;
if(obj.tagName != 'A') {
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.tagName == 'A') {
a = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
} else {
a = obj;
}
} else {
a = evt.currentTarget;
}
if(!IE) {
a.onclick = a.onclick_tmp;
}
var link = a.href;
var type = a.type;
var map  = a.getAttribute('map');
var check = checkForExternalLink(link, type);
if(check) {
var changes = changedFieldValues.chechForChanges(a, 1);
if(!changes) {
if(IE) {
a.onclick = '';
event.returnValue = false;
return;
} else {
if(evt.cancelable) {
evt.preventDefault();
return;
}
}
}
}
if(map && map != '') {
doMap(map);
if(IE) {
event.returnValue = false;
return;
} else {
if(evt.cancelable) {
evt.preventDefault();
return;
}
}
}
if(type == 'select_all' || type == 'deselect_all') {
selectingList.doSelects(type);
}
if(!IE) {
if(a.onclick) {
a.onclick();
}
evt.stopPropagation();
} else {
event.cancelBubble = true;
}
}
checkForExternalLink = function(link, type) {
if(link.length > 1) {
var end = link.length;
var start = end - 1;
var extLink = link.substring(start, end);
} else if(link.length == 1){
extLink = link;
} else {
return false;
}
if(type == 'no_load') {
return false;
} else if(extLink == '#' && type != 'load') {
return false;
} else if(extLink == '' && type != 'load') {
return false;
} else if(extLink == ';' && type != 'load') {
return false;
} else {
return true;
}
}
doMap = function(map) {
loadingTemplatesWithAjax.loadTpl('?do=' + map);
return false;
}
setAnchorObject = function (evt) {
var a = '';
if(IE) {
if(typeof(evt) == 'object') {
a = evt;
} else {
var obj = event.srcElement;
if(obj.tagName != 'A') {
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.tagName == 'A') {
a = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
} else {
a = obj;
}
}
} else {
if(typeof(evt) == 'object') {
a = evt;
} else {
a = evt.currentTarget;
}
}
anchorObject = a;
return;
}
getAnchorObject = function () {
return anchorObject;
}
/**
* setFormEvents
* comments: Set standard submit events
**/
setFormEvents = function() {
var forms = document.getElementsByTagName('FORM');
for(i=0;i<forms.length;i++) {
form = forms[i];
if(IE) {
form.onsubmit = submitAction;
} else {
form.addEventListener("submit", submitAction, false);
}
}
}
/**
* submitAction
* comments: Give the form a submit
* @param evt 'event'
**/
submitAction = function(evt) {
if(IE) {
var form = event.srcElement;
} else {
var form = evt.currentTarget;
}
var check = formControl.checkFormFields(form);
if(!check) {
if(IE) {
event.returnValue = false;
} else {
evt.preventDefault();
}
} else {
var submit = formControl.setSubmit(form);
var reset = changedFieldValues.checkSubmit();
if(!submit) {
if(IE) {
event.returnValue = false;
} else {
evt.preventDefault();
}
}
}
}
/**
* submitAction
* Give the form, selected by id, a submit
* @param evt 'event'
**/
submitActionById = function(id) {
var synchWysiwyg= saveFormWithAjax.synchWysiwyg();
var form = document.getElementById(id);
if(form) {
var check = formControl.checkFormFields(form);
if(!check) {
return false;
} else {
var submit = formControl.setSubmit(form);
changedFieldValues.checkSubmit();
}
}
return true;
}
/**
* setInputFieldsCSS
* Coz IE does not support selectors, we have to write a little
* event to set a class to input fields
*
* @param param evt 'event'
**/
setInputFieldsCSS = function(evt) {
if(IE) {
var inputFields = document.getElementsByTagName('INPUT');
for(i=0;i<inputFields.length;i++) {
var inputField = inputFields[i];
if(inputField.type == 'text' || inputField.type == 'password') {
inputField.className = 'input_type_text';
} else if(inputField.type == 'submit' || inputField.type == 'reset' || inputField.type == 'button') {
inputField.className = 'input_type_buttons';
} else if(inputField.type == 'radio') {
inputField.className = 'input_type_radio';
}
}
}
}
function ChangedFieldValues() {
this.onFocusNewValues = new Object();
this.onFocusFirstValues = new Object();
this.onclick  = false;
this.popupCancel  = false;
this.popupSubmit  = false;
}
ChangedFieldValues.prototype.setFieldFirstValue = function (id, value) {
this.onFocusFirstValues[id]  = new Object();
this.onFocusFirstValues[id][0]  = value;
}
ChangedFieldValues.prototype.setFieldsFirstValuesLoad = function (id) {
try{
var obj = document.getElementById(id);
var form = find.findObjectByTagName(obj, 'FORM');
var len = form.elements.length;
for(var i=0; i<len; i++) {
var elem = form.elements[i];
if(elem.id) {
var fieldId = elem.id;
var value = elem.value
this.setFieldFirstValue(fieldId, value);
}
}
} catch(e) {
errorMsg.push(e + ' (ChangedFieldValues.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
ChangedFieldValues.prototype.setFieldsFirstValues = function (id) {
this.setFieldsFirstValuesId = id;
try {
var obj  = document.getElementById(id);
var inputs = obj.getElementsByTagName('INPUT');
var textareas = obj.getElementsByTagName('TEXTAREA');
var selects = obj.getElementsByTagName('SELECT');
var lenInputs = inputs.length;
var lenTextareas= textareas.length;
var lenSelects = selects.length;
for(var i=0; i<lenInputs; i++) {
var elem = inputs[i];
if(elem.id) {
var fieldId = elem.id;
var value = elem.value
this.setFieldFirstValue(fieldId, value);
}
}
for(var i=0; i<lenTextareas; i++) {
var elem = Textareas[i];
if(elem.id) {
var fieldId = elem.id;
var value = elem.value
this.setFieldFirstValue(fieldId, value);
}
}
for(var i=0; i<lenSelects; i++) {
selected = selects.selectedIndex;
for(a=0; a<select.length; a++) {
if(selected == a) {
if(elem.id) {
var fieldId = elem.id;
var value = elem.value
this.setFieldFirstValue(fieldId, value);
}
}
}
}
obj = null;
} catch(e) {
errorMsg.push(e + ' (ChangedFieldValues.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
ChangedFieldValues.prototype.setFieldNewValue = function (id, value) {
try{
var obj = document.getElementById(id);
if(obj) {
this.onFocusNewValues[id]  = new Object();
this.onFocusNewValues[id][0]  = value;
}
} catch (e) {
errorMsg.push(e + ' (ChangedFieldValues.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
ChangedFieldValues.prototype.chechForChanges = function (obj, showPopup) {
var link = '';
var newValues = this.onFocusNewValues;
var firstValues = this.onFocusFirstValues;
this.obj = obj;
if(obj != '') {
link = this.setLink(obj);
} else {
link = this.link;
}
var fields = '';
var b = 0;
for(var i in newValues) {
try {
var id  = i;
var newValue = newValues[i][0];
var firstValue = firstValues[i][0];
if(newValue != firstValue) {
var obj = document.getElementById(i);
if(obj) {
var title = obj.title;
if(title == 'undefined' || title == '') {
title = 'onbekend veld met id: ' + i;
fields += '&field[' + b + ']=' + i;
} else {
title = title;
fields += '&field[' + b + ']=' + title;
}
}
}
b++;
} catch(e) {
errorMsg.push(e + ' (changedFieldValues.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
if(fields != '') {
rExp  = /&/gi;
replaceInUrl = new String("%26");
newLink  = link.replace(rExp, replaceInUrl);
rExp3  = /(\'.*\')/gi;
rExp4  = /\'/gi;
rExp5  = /\'.*\'/gi;
if(newLink.match(rExp3)) {
newLink = new String(newLink.match(rExp3));
var first = newLink.charAt(0);
var len = (newLink.length) -1;
var last = newLink.charAt(len);
if(first.match(rExp4) && last.match(rExp4)) {
newLink  = newLink.replace(rExp4, '');
}
}
var get = fields + '&redirect=' + newLink;
if(showPopup) {
loadingTemplatesWithAjax.loadTplPost('?do=popupchangedfields', get);
popup.checkSubmit('changedFieldValues.checkSubmit()');
}
return false;
}
return true;
}
ChangedFieldValues.prototype.setLink = function (str_obj) {
if(typeof str_obj == 'object') {
var obj = str_obj;
var link = obj.href;
var end = link.length;
var start = end - 1;
var extLink = link.substring(start, end);
if(extLink == '' || extLink == '#') {
this.onclick = true;
var click = obj.getAttribute('onclick').toString();
rExp  = /;/g;
rExp2  = /loadingTemplatesWithAjax/g;
rExp3  = /function anonymous()/g;
if(click.match(rExp)) {
var splittedClick = click.split(rExp);
var len  = splittedClick.length;
for(var i=0; i<len; i++) {
if(splittedClick[i].match(rExp2)) {
if(IE) {
if(splittedClick[i].match(rExp3)) {
var link = splittedClick[i].split('{');
link = link[1];
}
} else {
var link = splittedClick[i];
}
break;
}
}
} else if(click.match(rExp2)){
if(IE) {
if(click.match(rExp3)) {
var link = click.split('{');
link = link[1].split('}');
link = link[0];
}
} else {
var link = click;
}
} else {
errorMsg.push('No link could be set from var click: ' + click + ' (Popup_v0.1.js)');
}
}
} else if(typeof str_obj == 'string') {
var string = str_obj;
this.onclick = true;
this.link = string
}
if(link) {
if(link.match('tmi=')) {
var tmi = link.split('&');
var len = tmi.length;
var re  = /tmi=/g;
for(var i=0; i<len; i++) {
if(tmi[i].match(re)) {
var theTmi = tmi[i];
break;
}
}
tmi = theTmi.split('=')[1];
var re = /\'\)/g;
if(re.test(tmi)) {
tmi = tmi.replace(re,'');
}
eval('marcomproMenu.setSelectedItemsById(\'menuId'+tmi+'\')');
}
return link;
}
}
ChangedFieldValues.prototype.checkCancel = function () {
this.popupCancel = true;
}
ChangedFieldValues.prototype.checkSubmit = function () {
try {
obj  = this.obj;
var newValues = this.onFocusNewValues;
var firstValues = this.onFocusFirstValues;
var link = this.setLink(obj);
var msg  = '';
for(var i in newValues) {
var id  = i;
var newValue = newValues[i][0];
var firstValue = firstValues[i][0];
if(newValue != firstValue) {
var obj = document.getElementById(i);
if(obj) {
this.setFieldFirstValue(i, firstValue);
this.setFieldNewValue(i, firstValue)
}
}
}
} catch(e) {
errorMsg.push(e + ' (ChangedFieldValues.js: method checkSubmit())');
debugWindow.handleAjaxError(errorMsg);
}
}
/**
* Set Global vars
**/
var required = 'required';
var minlength = 'minlength';
var definition = 'definition';
var formpopup = 'popupref';
var link  = 'link';
var definitiontypes = new Array();
definitiontypes[0] = 'email';
definitiontypes[1] = 'postalcode';
definitiontypes[2] = 'zipcode';
definitiontypes[3] = 'int';
definitiontypes[4] = 'nospecialchars'; // for directories etc.
var submittypes = new Array();
submittypes[0] = 'ajax';
/**
* FormControl Constructor
* @constructor
**/
function FormControl() {
this.errorMsgRequired = new Object();
this.errorMsgTypes = new Object();
this.onFocusFirstValues = new Object();
this.showPopup  = false;
this.linkAtt  = false;
this.fieldserror = '?do=popupfieldserror';
}
/**
* setFormObject
* @member FormControl
* @param obj 'object' The form object
* @param saveType 'string' (ajax)
* @comment: The saveType is the type in which the form has to save stuff
*  For example: a for can be saved with ajax, when all the form
*  fields are filled in correctly, save the form with ajax        *
**/
FormControl.prototype.checkAjaxFormObject = function (obj) {
}
/**
* checkFormFields
* @member FormControl
* @param obj 'object' The form object
* @comment: check the form field values
*
**/
FormControl.prototype.checkFormFields = function (obj) {
var count  = 0;
var elements = obj.elements;
var len  = elements.length;
for(i=0;i<len;i++) {
var elem = elements[i];
var fieldId = elem.id;
var title = elem.title;
this.checkRequired(elem, title, obj);
this.checkDefinitions(elem, title);
this.checkMinLength(elem, title);
}
for(var i in this.errorMsgRequired) {
count++;
}
for(var i in this.errorMsgTypes) {
count++;
}
if(count > 0) {
this.setTheMessage();
return false;
} else {
return true;
}
}
/**
* setSubmit
* @member FormControl
* @param obj 'object' The form object
**/
FormControl.prototype.setSubmit = function (obj) {
var definitionAtt = obj.getAttribute(definition);
var showPopupAtt = obj.getAttribute(formpopup);
if(obj.getAttribute('fieldserror')) {
this.fieldserror = obj.getAttribute('fieldserror');
}
if(definitionAtt) {
if(definitionAtt == submittypes[0]) {
if(showPopupAtt) {
this.showPopup = showPopupAtt;
var linkAtt = obj.getAttribute(link);
if(linkAtt) {
this.linkAtt = linkAtt;
}
}
saveFormWithAjax.send(obj);
return false;
}
}
return true;
}
/**
* showSavePopup - to open a confirm popup in the template that is loaded,
* return this function in a true <br/>
* this.showPopup is set in setSubmit function when the <strong>formpopup</strong> attribute<br />
* in the form tag is set to true
* @member FormControl
**/
FormControl.prototype.showSavePopup = function () {
return this.showPopup;
}
/**
* savePopupLink
* Sets a link for the extra button (besides the cancel button) <br/>
* in the popup. If no link is set the value will be false
* @member FormControl
**/
FormControl.prototype.savePopupLink = function () {
return this.linkAtt;
}
/**
* FormControl getRedirectLink
* Set a link for the extra button (besides the cancel button)<br />
* in the popup. If no link is set the value will be false
* @member FormControl
**/
FormControl.prototype.getRedirectLink = function () {
return this.linkAtt;
}
/**
* FormControl resetSavePopup
* When popup is shown, reset the values, otherwise we will stay in a loop
* @member FormControl
**/
FormControl.prototype.resetSavePopup = function () {
this.showPopup = false;
}
/**
* FormControl resetSavePopup
* Set the url to which the error message has to be send
* @member FormControl
**/
FormControl.prototype.setFieldsErrorUrl = function (value) {
this.fieldserror = value;
}
/**
* FormControl checkrequired
* @param elem 'object' the field object
* @param title 'string' the field title
* @param obj 'object' the form obj
* @comment: Look for required form elements
* @member FormControl
**/
FormControl.prototype.checkRequired = function (elem, title, obj) {
var id  = elem.id;
var value = elem.value;
var requiredAtt = elem.getAttribute(required);
var count = 0;
if(requiredAtt && requiredAtt == 'required') {
if(elem.type == 'radio' || elem.type == 'checkbox') {
var name = elem.name;
var check = this.getRadioCheckboxItems(obj, name);
} else{
var check = 1;
}
if(value == '' || !check) {
if(!title || title == '' || title == 0 || title == "0") {
return count;
}
this.errorMsgRequired[title]  = new Object();
this.errorMsgRequired[title].id = id;
count++;
}
}
return count;
}
/**
* FormControl getRadioItems
* @param obj 'object' the form obj
* @param name 'string' the radio btn name
* @comment: Look for required form elements
* @member FormControl
**/
FormControl.prototype.getRadioCheckboxItems = function (obj, name) {
var elements = obj.elements;
var len  = elements.length;
for(var i=0; i<len; i++) {
var elem = elements[i];
var type = elem.type;
if(type == 'radio' || type == 'checkbox') {
var elemName = elem.name;
if(elemName == name) {
if(elem.checked) {
return 1;
}
}
}
}
return 0;
}
/**
* FormControl checkdefinitions
* @param obj 'elem' the field object
* @param title 'string' the field title
* @comment: Look for correct values in the form fields
* @member FormControl
**/
FormControl.prototype.checkDefinitions = function (elem, title) {
var definitionAtt = elem.getAttribute(definition);
var count  = 0;
var id  = elem.id;
var value  = elem.value;
if(title == '') {
return;
}
if(definitionAtt) {
if(definitionAtt == definitiontypes[0]) {
if(elem.value != '') {
var emailCheck = this.checkEmail(elem);
if(!emailCheck) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].id = id;
}
}
} else if(definitionAtt == definitiontypes[1]) {
if(elem.value != '') {
var postalcodeCheck = this.checkPostalcode(elem);
if(!postalcodeCheck) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].id = id;
}
}
} else if(definitionAtt == definitiontypes[2]) {
if(elem.value != '') {
var zipcodeCheck = this.checkZipcode(elem);
if(!zipcodeCheck) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].title = id;
}
}
} else if(definitionAtt == definitiontypes[3]) {
if(elem.value != '') {
var intCheck = this.checkInt(elem);
if(!intCheck) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].id = id;
}
}
} else if(definitionAtt == definitiontypes[4]) {
if(elem.value != '') {
var intCheck = this.noSpecialChars(elem);
if(!intCheck) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].id = id;
}
}
}
}
return count;
}
/**
* FormControl checkMinLength
* @param obj 'elem' the field object
* @param title 'string' the field title
* @comment: check if the min length of content is reached
* @member FormControl
**/
FormControl.prototype.checkMinLength = function (elem, title) {
var minLengthAtt = elem.getAttribute(minlength);
if(minLengthAtt) {
var count  = 0;
var id  = elem.id;
var value  = elem.value;
var strlen  = value.length;
if(strlen < minLengthAtt) {
count++;
this.errorMsgTypes[title]  = new Object();
this.errorMsgTypes[title].id = id;
}
}
return count;
}
/**
* FormControl checkEmail
* @param elem 'object' the field object
* @member FormControl
**/
FormControl.prototype.checkEmail = function (elem) {
var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
var strEmail = elem.value;
if (strEmail.search(validRegExp) == -1)
{
return false;
}
return true;
}
/**
* FormControl checkInt
* @param elem 'object' the field object
* @member FormControl
**/
FormControl.prototype.checkInt = function (elem) {
if(isNaN(elem.value)) {
return false;
}
return true;
}
/**
* FormControl noSpecialChars
* @param elem 'object' the field object
* @member FormControl
**/
FormControl.prototype.noSpecialChars = function (elem) {
var validRegExp = /[^$A-Za-z0-9_]/;
var value = elem.value;
if (value.match(validRegExp) == -1) {
return false;
}
return true;
}
/**
* FormControl checkPostalcode
* @param elem 'object' the field object
* @member FormControl
**/
FormControl.prototype.checkPostalcode = function (elem) {
var validRegExp_1 = /^[1-9][0-9]{3} [A-Za-z]{2}$/;
var validRegExp_2 = /^[1-9][0-9]{3}[A-Za-z]{2}$/;
var strZipcode = elem.value;
if (strZipcode.search(validRegExp_1) == -1 && strZipcode.search(validRegExp_2) == -1)
{
return false;
}
return true;
}
/**
* FormControl checkZipcode
* @param elem 'object' the field object
* @member FormControl
**/
FormControl.prototype.checkZipcode = function (elem) {
var validRegExp_1 = /^[1-9][0-9]{3} [a-z|A-Z]{2}$/;
var validRegExp_2 = /^[1-9][0-9]{3}[a-z|A-Z]{2}$/;
var strZipcode = elem.value;
if (strZipcode.search(validRegExp_1) == -1 && strZipcode.search(validRegExp_2) == -1)
{
return false;
}
return true;
}
/**
* FormControl setTheMessage
* Set the message fields and pass them to the template loader as a post. An error popup will be opened
* @requires LoadingTemplatesWithAjax loads the popupfieldserror-map containing the form-validationerrors
* @requires XmlHTTPObject resets the loader
* @member FormControl
**/
FormControl.prototype.setTheMessage = function () {
var msg = '';
msgRequired = this.errorMsgRequired;
for(var i in msgRequired) {
if(i != 0 || i != "0") {
msg += '&requiredContent[' + i + ']=' + msgRequired[i].id;
}
}
msgTypes = this.errorMsgTypes;
for(var i in msgTypes) {
msg += '&wrongContent[' + i + ']=' + msgTypes[i].id;
}
loadingTemplatesWithAjax.loadTplPost(this.fieldserror, msg);
xmlHttpObject.resetLoader();
this.errorMsgRequired = new Object();
this.errorMsgTypes = new Object();
return true;
}
if(!IE) {
try {
var len = document.body.childNodes.length;
with (window.document.body)
for (var i=0;i<len;++i) {
if (/]>/.test(childNodes[i].data)) {
removeChild(childNodes[i]);
break;
}
}
} catch(e) {}
}
var popupId;
function ShowPopup() {
this.content  = '';
this.title  = '';
this.link  = '';
this.onclick  = '';
popupClose  = true;
callCancelFunction = null;
callSubmitFunction = null;
popupOnclick  = '';
method   = null;
}
ShowPopup.prototype.setMessage = function(content) {
this.content = content;
}
ShowPopup.prototype.setTitle = function(title) {
this.title = title;
}
ShowPopup.prototype.resetContent = function() {
this.title = '';
this.content = '';
popupClose = true;
}
ShowPopup.prototype.disabled = function(disabled) {
if(disabled == 'false') {
popupClose = false;
}
}
ShowPopup.prototype.setMethod = function(methodType) {
method = methodType;
}
ShowPopup.prototype.getMethod = function() {
return method;
}
ShowPopup.prototype.setOnclick = function(link) {
popupOnclick = link;
}
ShowPopup.prototype.getOnclick = function() {
return popupOnclick;
}
ShowPopup.prototype.setGoBtnName = function(id, name) {
obj  = document.getElementById(id);
var buttons = obj.getElementsByTagName('INPUT');
for(i=0;i<buttons.length;i++) {
if(buttons[i].name == 'go') {
buttons[i].name = name;
}
}
}
ShowPopup.prototype.setCancelBtnName = function(id, name) {
obj  = document.getElementById(id);
var buttons = obj.getElementsByTagName('INPUT');
for(i=0;i<buttons.length;i++) {
if(buttons[i].name == 'cancel') {
buttons[i].name = name;
}
}
}
ShowPopup.prototype.setLink = function(link) {
var newLink = link.split('/');
if(newLink) {
var size = (newLink.length) -1;
this.link = newLink[size];
} else {
this.link = link;
}
}
ShowPopup.prototype.checkCancel = function(callFunction) {
callCancelFunction = callFunction;
}
ShowPopup.prototype.checkSubmit = function(callFunction) {
callSubmitFunction = callFunction;
}
ShowPopup.prototype.getCancelFunc = function() {
return callCancelFunction;
}
ShowPopup.prototype.getSubmitFunc = function() {
return callSubmitFunction;
}
ShowPopup.prototype.checkBtns = function(id) {
obj  = document.getElementById(id);
var count = new Array;
var buttons = obj.getElementsByTagName('INPUT');
for(i=0;i<buttons.length;i++) {
if(buttons[i].name == 'cancel') {
count[i] = 'cancel';
} else if(buttons[i].name == 'go') {
count[i] = 'go';
}
}
return count;
}
ShowPopup.prototype.position = function(id) {
if(IE) {
checkDocumentSelectBoxes('hidden');
}
try {
this.popupFilter = document.getElementById('popupFilter');
this.obj  = document.getElementById(id);
this.popupFilter.className    = 'show';
this.obj.className   = 'show';
} catch(e) {
errorMsg.push(e + ' (Popup_v0.1.js)');
}
setPopupId(id);
}
ShowPopup.prototype.setContent = function() {
var spans  = this.obj.getElementsByTagName('SPAN');
var buttons  = this.obj.getElementsByTagName('INPUT');
_this  = this;
for(i=0;i<buttons.length;i++) {
var button = buttons[i];
if(button.name == 'go') {
if(IE) {
button.onclick = setPopupGoEvent;
} else {
button.addEventListener("click", setPopupGoEvent, false);
}
} else if(button.name == 'cancel') {
if(IE) {
button.onclick = setPopupNoEvent;
} else {
button.addEventListener("click", setPopupNoEvent, false);
}
}
}
if(this.content != '' && this.content != '') {
for(i=0;i<spans.length;i++) {
if(spans[i].className == 'content') {
if(this.content != '') {
spans[i].innerHTML = this.content;
}
} else if(spans[i].className == 'title') {
if(this.title != '') {
spans[i].innerHTML = this.title;
}
}
}
}
button = null;
buttons = null;
spans = null;
return;
}
setPopupGoEvent = function(evt) {
if(click) {
return;
}
var click = showPopup.getOnclick();
var method = showPopup.getMethod();
if(showPopup.getSubmitFunc()) {
eval(showPopup.getSubmitFunc());
}
if(click != '') {
if(IE) {
var btn  = event.srcElement;
} else {
var btn  = evt.currentTarget;
}
btn.onclick = click;
var type = typeof(btn.onclick);
if(type == 'function') {
closePopup();
btn.onclick();
} else if(method == 'function') {
eval(click);
} else {
closePopup();
try {
if(method == 'post') {
btn.onclick = loadingTemplatesWithAjax.loadTplPost(click, 1);
} else if(method == 'get') {
btn.onclick = loadingTemplatesWithAjax.loadTpl(click);
} else if(!method) {
if(click.charAt(0) == '?') {
btn.onclick = loadingTemplatesWithAjax.loadTpl(click);
} else {
errorMsg.push('the var click is not an url, but probably a function (Popup_v0.1.js.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
} catch (e) {
errorMsg.push(e + ' (Popup_v0.1.js.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
} else {
document.location.href = _this.link;
}
method  = null;
_this.method = null;
btn  = null;
click  = null;
type  = null;
return;
}
setPopupNoEvent = function(evt) {
if(callCancelFunction) {
eval(callCancelFunction);
}
popupClose = 1;
closePopup();
}
setPopupId = function(id) {
popupId = id;
}
closePopup = function() {
if(popupClose) {
if(IE) {
checkDocumentSelectBoxes('visible');
}
try {
var popupFilter  = document.getElementById('popupFilter');
var popups  = document.getElementById('popups');
var obj   = document.getElementById(popupId);
obj.className  = 'hide';
popupFilter.className = 'hide';
popups.innerHTML = '';
} catch(e) {
errorMsg.push(e + ' (Popup_v0.1.js)');
}
}
_this.method = null;
method  = null;
}
checkDocumentSelectBoxes = function(type) {
var selects = document.getElementsByTagName('SELECT');
var len = selects.length;
for(var i=0;i<len;i++) {
var select = selects[i];
select.style.visibility = type;
}
}
function StatusErrors() {
}
StatusErrors.prototype.statusCheck = function(status, url) {
rExp  = /&/gi;
replaceInUrl = new String("{{||}}");
newUrl  = url.replace(rExp, replaceInUrl);
switch(status) {
case 400:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 401:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 402:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 403:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 404:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 411:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 500:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 501:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
case 502:
loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
return false;
break;
default:
return true;
break;
}
}
/**
* Set Global vars
**/
var returnValue;
/**
* XMLHttpObject Constructor
**/
function XMLHttpObject() {
this.errorMsg = new Array();
this.connectionSecs = 10000; // 10 seconds
this.loader  = true;
this.initializer = 1;
}
/**
* XMLHttpObject post
* @comments:
**/
XMLHttpObject.prototype.post = function(file, url) {
if (window.XMLHttpRequest) this._xmlhttp = new XMLHttpRequest();
else if (window.ActiveXObject) this._xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
this.requesting();
var instance = this;
this._xmlhttp.open('POST', file, true);
this._xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset:UTF-8');
this._xmlhttp.onreadystatechange = function() {
switch(instance._xmlhttp.readyState) {
case 1:
instance.loading();
break;
case 2:
instance.loaded();
break;
case 3:
instance.interactive();
break;
case 4:
var status = 1;
if(MARCOMPRO_MODE) {
status = statusErrors.statusCheck(instance._xmlhttp.status, url);
}
if(status) {
var result = instance._xmlhttp.responseText;
instance.response(result);
}
break;
}
}
this._xmlhttp.send(url);
}
/**
* XMLHttpObject get
* @comments:
**/
XMLHttpObject.prototype.get = function(url) {
if (window.XMLHttpRequest) this._xmlhttp = new XMLHttpRequest();
else if (window.ActiveXObject) this._xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
this.url  = url;
var instance = this;
this._xmlhttp.open('GET', url, true);
this._xmlhttp.onreadystatechange = function() {
switch(instance._xmlhttp.readyState) {
case 1:
instance.loading();
break;
case 2:
instance.loaded();
break;
case 3:
instance.interactive();
break;
case 4:
var status = 1;
if(MARCOMPRO_MODE) {
var status = statusErrors.statusCheck(instance._xmlhttp.status, url);
}
if(status) {
var result  = instance._xmlhttp.responseText;
instance.response(result);
}
break;
}
}
this._xmlhttp.send(null);
}
XMLHttpObject.prototype.loading = function() {
this.requesting();
}
XMLHttpObject.prototype.loaded = function() {
this.endRequesting();
}
XMLHttpObject.prototype.interactive = function() {
}
/**
* XMLHttpObject unsetInit
* @comments: set the initializer to false, so not always will the init()
*  be triggered
**/
XMLHttpObject.prototype.unsetInit = function() {
this.initializer = 0;
}
/**
* XMLHttpObject setInit
* @comments: reset the this.initializer so the init() will be triggerd
*  again after a tpl load
**/
XMLHttpObject.prototype.setInit = function() {
this.initializer = 1;
}
/**
* XMLHttpObject unsetLoader
* @comments: When the this.loader = false, do not disable the anchor tags
*  and don't show the sandglass :-)
**/
XMLHttpObject.prototype.unsetLoader = function() {
this.loader = false;
}
/**
* XMLHttpObject resetLoader
* @comments:
**/
XMLHttpObject.prototype.resetLoader = function() {
this.loader = true;
}
/**
* XMLHttpObject requesting
* @comments: When the loader is false, show a sandglass and make
*  users can not click when the templates are loading
**/
XMLHttpObject.prototype.requesting = function () {
if(this.loader == true) {
showAppLayer();
if(IE) {
document.body.attachEvent("onclick", disableClick, false);
} else {
document.body.addEventListener("click", disableClick, false);
}
document.body.style.cursor = 'wait';
}
}
/**
* XMLHttpObject requesting
* @comments: When the loader is false, show a sandglass and make
*  users can not click when the templates are loading
**/
XMLHttpObject.prototype.endRequesting = function () {
if(this.loader == true) {
document.body.style.cursor = 'default';
var anchor = getAnchorObject();
if(anchor) {
if(anchor.style) {
anchor.style.cursor = 'hand';
anchor.style.cursor = 'pointer';
}
} else {
errorMsg.push('No anchor tag is found (XMLHttpObject.js method endRequesting())');
}
if(errorMsg.length) {
debugWindow.handleAjaxError(errorMsg);
}
/*
timer.stop();
*/
hideAppLayer();
}
}
/**
* XMLHttpObject tplStatus
* @param string func  the function to be evaluated
* @param int  delay  delay for re-invoking the function
* @param bool  emptyResponse  the response text can be empty to perform the eval
* @comments: U can call this method from everywhere, so you can keep on
*  checking the status when the template is loading
*  returns true when the template is loaded completely
*  You can also give a method name as a parameter
**/
XMLHttpObject.prototype.tplStatus = function (func, delay, emptyResponse) {
if(!delay) {
var delay = 1000;
}
if(this._xmlhttp.readyState == 4) {
if(emptyResponse) {
if(func && func != '') {
eval(func);
}
} else if(this._xmlhttp.responseText != '') {
if(func && func != '') {
eval(func);
}
}
return true;
} else {
setTimeout("xmlHttpObject.tplStatus('" + func + "', '" + delay + "', '" + emptyResponse + "')", delay);
}
}
/**
* XMLHttpObject checkContent
* @param string result
* @comments: Check the result. If the result starts with an xml tag, we
*  cannot convert the content in the loadingTemplatesWithAjax
*  class. Redirect to the login, probably the session has ended
**/
XMLHttpObject.prototype.checkContent = function (result) {
var content = result;
if(content.match('xml version="1.0" encoding="utf-8"')) {
return false;
}
return true;
}
/**
* XMLHttpObject abort
* @comments: U can call this method from everywhere, so you can keep on
*  checking the status when te template is loading
*  returns true when the template is loaded completely
*  You can also give a method name as a parameter
**/
XMLHttpObject.prototype.abort = function () {
this._xmlhttp.abort();
}
/**
* response
* @comments:
**/
XMLHttpObject.prototype.response = function(result) {
if(result) {
var checkContent = this.checkContent(result);
if(checkContent) {
loadingTemplatesWithAjax.setResponse(result);
this.rawResponse = result;
loadingTemplatesWithAjax.setLastLoadedTpl();
if(this.initializer && MARCOMPRO_MODE) {
init();
} else if(this.initializer) {
setAnchorEvents();
setFormEvents();
}
if(MARCOMPRO_MODE) {
initCB();
}
} else {
loadingTemplatesWithAjax.loadTpl('?do=sessionEnded');
}
} else {
errorMsg.push('Resultset was empty or not set (url: ' + xmlHttpObject.url + ' in file: XMLHttpObject.js)');
debugWindow.handleAjaxError(errorMsg);
}
return;
}
/**
* getRawResponse
* @comments: get the raw response before it is being converted
**/
XMLHttpObject.prototype.getRawResponse = function() {
return this.rawResponse;
}
/**
* disableClick
* @comments: When templates are loaded disable the clicks. When the
*  req.status == 200 (templates are completely loaded) remove
*  the event
**/
disableClick = function(evt) {
if(returnValue == 200) {
this.removeEventListener("click", arguments.callee, false);
}
}
/**
* showAppLayer
* @comments: Showing the application layer means that a layer will be on
*  top of the application,so nothing can be clicked while
*  templates are being loaded
**/
showAppLayer = function() {
var appLayer = document.getElementById('appLayer');
if(appLayer) {
appLayer.className = 'show';
}
}
/**
* showAppLayer
* @comments: Hide the application layer
**/
hideAppLayer = function() {
var appLayer = document.getElementById('appLayer');
if(appLayer) {
appLayer.className = 'hide';
}
}
/**
* SaveFormWithAjax Constructor
* @param popupObj 'object'
* @param XMLHttpObject 'object'
* @return 'bool'
* @comments: use popup object when errors occure
*  when there's a response needed, set the response to true
**/
function SaveFormWithAjax(popupObj) {
this.loop = 0;
this.count = 0;
}
/**
* SaveFormWithAjax send
* @param obj 'object' the form object
* @comments: loop through the form, only fields with an id will be saved
**/
SaveFormWithAjax.prototype.send = function (obj) {
try {
if(typeof(obj) == 'string') {
obj = document.getElementById(obj);
}
var url  = '';
var action = obj.action;
var file = this.getFile(action);
var synchWysiwyg= this.synchWysiwyg();
var form = obj;
var fields = form.elements;
var len  = fields.length;
for(var i=0;i<len;i++) {
var field = fields[i];
if(field.id) {
if(field.type != 'submit' && field.type != 'button' && field.type != 'label') {
if(field.type == 'checkbox' || field.type == 'radio') {
var value = field.value;
var name = field.name;
if(field.checked) {
if(name != '') {
if (name.indexOf('[]') != -1){
if (url.indexOf('&' + name + '=0')!= -1){
url = url.replace ('&' + name + '=0', '');
}
}
if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
}
} else if (field.type == 'checkbox') {
var tofind = url.indexOf(name);
if(name != '' && tofind == -1) {
url  += '&' + name + '=0';
}
}
} else if(field.type == 'file') {
var upload = this.upload(form);
if(upload) {
return false;
}
} else if(field.type == 'textarea') {
var txt = field.value;
field.value = txt.replace(/<br>/g,''); //Now we replace the <br> tag, since the editor combines a <br> with a newline, we do not need to place it ourself
field.value = txt.replace(/<br \/>/g,''); //Now we replace the <br> tag, since the editor combines a <br> with a newline, we do not need to place it ourself
var value = field.value;
var name = field.name;
if(name != '') {
if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
}
} else {
if(field.value) {
var value = field.value;
} else {
var value = '';
}
var name = field.name;
if(name != '') {
if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
} else {
if(IE) {
if(field.getAttribute('hack_ie')) {
var name = field.getAttribute('hack_ie');
if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
}
}
}
}
}
}
}
if(IE) {
file = loadingTemplatesWithAjax.checkFilename(file);
}
var submit = this.sendForm(file, url);
if(submit) {
return true;
}
return false;
} catch(e) {
alert(e);
errorMsg.push(e + 'saveformWithAjax.js (method: send())');
debugWindow.handleAjaxError(errorMsg);
}
}
/**
* SaveFormWithAjax synchWysiwyg
* @comments: if we are dealing with a wysiwyg, we must synch it with the textareas
**/
SaveFormWithAjax.prototype.synchWysiwyg = function () {
if(wysiwygEditor && wysiwygEditor != 'undefined' && typeof(wysiwygEditor) == 'object') {
var hasWysiwyg = wysiwygEditor.hasWysiwyg;
if(hasWysiwyg) {
wysiwygEditor.synchronize();
wysiwygEditor.killAll();
}
wysiwygEditor.hasWysiwyg = 0;
}
}
/**
* SaveFormWithAjax upload
* @param field 'object'
* @comments:
**/
SaveFormWithAjax.prototype.upload = function (form) {
if(this.iFrame) {
form.submit();
return true;
} else {
errorMsg.push('No iframe to save the form in!When we want to upload a file, we need an iframe! (SaveFormWithAjax.js)');
debugWindow.handleAjaxError(errorMsg);
return false;
}
}
/**
* SaveFormWithAjax setUpload
* @obj 'object' iFrame object
* @comments:
**/
SaveFormWithAjax.prototype.setUpload = function (obj) {
this.iFrame = obj;
}
/**
* SaveFormWithAjax sendForm
* @param file 'string' the marcompro.php?do=something
* @param url 'string' The post values
* @comments: Sending the url as a post to the action using the
*  XMLHttpObject
*  return true if everything went ok
*  return false if an error occures
**/
SaveFormWithAjax.prototype.sendForm = function (file, url) {
xmlHttpObject.post(file, url);
return true;
}
/**
* SaveFormWithAjax getFile
* @action 'string' the absolute path
* @comments: Return the relative action path
**/
SaveFormWithAjax.prototype.getFile = function (action) {
var newFile = action.split('/');
var size = (newFile.length) -1;
var file = newFile[size];
return file;
}
/**
* Set Global vars
*/
var popup = new ShowPopup();
/*
* LoadingTemplatesWithAjax Constructor
* @comments:
**/
function LoadingTemplatesWithAjax() {
this.errorMsg = new Array();
this.lastLoadedTpl = new Array();
this.newStr  = new Object();
this.url  = '';
this.sendType = '';
}
/**
* LoadingTemplatesWithAjax loadTpl
* @param url 'string'
* @comments: Sending the url as a get to the action using the
*  XMLHttpObject
*  return true if everything went ok
*  return false if an error occures
**/
LoadingTemplatesWithAjax.prototype.loadTpl = function (url) {
if(IE) {
url = this.checkFilename(url);
}
this.sendType = 'get';
this.url  = this.checkUrl(url);
xmlHttpObject.get(url);
return true;
}
/**
* LoadingTemplatesWithAjax loadTplPost
* @param file 'string' (example: marcompro.php?do=popup)
* @param get 'bool || string' treat the post as a get using the & as params
* @comments: Sending the file as a post to the action using the
*  XMLHttpObject
*  return true if everything went ok
*  return false if an error occures
*  By setting the get, means that a url is already set
*  the get can be a part of a url or a boolean
*  2 examples @ Popup_v0.1.js and Refresh.js
*  Otherwise we have to look for the right fields and make a url
**/
LoadingTemplatesWithAjax.prototype.loadTplPost = function (file, get, obj) {
if(get == '' && get != 0) {
errorMsg.push(' The post your are sending is empty (LoadingTemplatesWithAjax.js)');
debugWindow.handleAjaxError(errorMsg);
this.loadTpl(file);
return;
}
var url = false;
if(get) {
if(get == 1) {
var url = file;
} else {
var url = get;
}
} else {
postValues.setPostValues(obj);
var url = postValues.getPostValues();
}
if(IE) {
file = this.checkFilename(file);
}
if(url && url != '') {
this.sendType = 'post';
this.file = this.checkUrl(file);
this.url  = this.checkUrl(url);
xmlHttpObject.post(file, url);
return true;
}
}
/**
*LoadingTemplatesWithAjax checkParams
*@param url 'string'
*@comments: Check if a &amp; isset within the link...if there is/are replace them with only a &
*  when sending an &amp; the get/post result will be for example [amp;menu_id] => 1
**/
LoadingTemplatesWithAjax.prototype.checkUrl = function (url) {
if(url.match('&amp;')) {
url = url.replace('amp;', '');
}
return url;
}
/**
*LoadingTemplatesWithAjax checkFilename
*@param file 'string'
*@comments: Only for IE to check if a filename isset in the url, like
*  marcompro.php? instead of only a ?
**/
LoadingTemplatesWithAjax.prototype.checkFilename = function (file) {
var check = /^\?/;
if(file.match(check)) {
file = defaultFilename + file;
}
return file;
}
/**
*LoadingTemplatesWithAjax setResponse
*@param str 'string'
*@comments: Handles the response of the view-class
**/
LoadingTemplatesWithAjax.prototype.setResponse = function (str) {
try {
this.errorMsg = new Array();
var strXml  = '<?xml version="1.0"?>\n<templates>\n';
strXml  += str + '\n';
strXml  += '</templates>';
var xml  = this.stringToXMLParser(strXml);
var xmlDocRoot = xml.documentElement;
var nodes  = xmlDocRoot.getElementsByTagName('ajax');
var len  = nodes.length;
var placeContent = 'innerHTML';
this.placeContent = placeContent;
var disabled = false;
for(var i=0;i<len;i++) {
var id  = '';
var type  = '';
var definition = '';
var placeContent= '';
var action  = '';
var doAction = '';
var disabled = '';
var show = '';
var method = '';
var init = '';
var func = '';
var node = nodes[i];
var attr = true;
if(attr) {
if(node.getAttribute('id')) {
var id  = node.getAttribute('id');
this.id  = id;
}
if(node.getAttribute('type')) {
var type = node.getAttribute('type');
}
if(node.getAttribute('definition')) {
var definition = node.getAttribute('definition');
}
if(node.getAttribute('content')) {
placeContent = node.getAttribute('content');
this.placeContent = placeContent;
}
if(node.getAttribute('action')) {
var action = node.getAttribute('action');
}
if(node.getAttribute('do')) {
var doAction = node.getAttribute('do');
}
if(node.getAttribute('disabled')) {
var disabled = node.getAttribute('disabled');
}
if(node.getAttribute('show')) {
var show = node.getAttribute('show');
}
if(node.getAttribute('function')) {
var func = node.getAttribute('function');
}
if(node.getAttribute('init')) {
var init = node.getAttribute('init');
this.init = node.getAttribute('init');
}
if(node.getAttribute('method')) {
var method = node.getAttribute('method');
this.method = node.getAttribute('method');
}
} else {
this.errorMsg.push('No attribute was set in the <ajax> tag. No reference to any id!');
}
if(node.childNodes[0]) {
var content = node.childNodes[0].nodeValue;
this.content= content;
if(id && id != '') {
var contentToDoc = document.getElementById(id);
if(show && show != '') {
if(show == 'true') {
contentToDoc.className = 'marcompro_show';
} else {
contentToDoc.className = 'marcompro_hide';
}
}
if(contentToDoc) {
switch(placeContent){
case 'value':
contentToDoc.value = content;
break;
case 'src':
contentToDoc.src = content;
break;
case 'none':
break;
default:
contentToDoc.innerHTML = content;
break;
}
} else {
this.errorMsg.push('The id with value ' + id + ' is not in use in the document');
}
} else {
this.errorMsg.push('One or more id\'s are not set. No reference possible!');
}
this.checkJS = triggerJavascript(content);
}
if(func && func != '') {
eval(func);
func = 0;
}
if(type && type != '') {
this.doAttr(type, definition, action, doAction, disabled, func);
}
if(init == 'false') {
xmlHttpObject.unsetInit();
} else if(init == 'true') {
xmlHttpObject.setInit();
}
}
var formSavedPopup = this.checkFormSavedPopup();
var errorLength = this.errorMsg.length;
if(errorLength) {
debugWindow.handleAjaxError(this.errorMsg);
}
} catch(e) {
errorMsg.push(e + ' (LoadingTemplatesWithAjax.setResponse)');
debugWindow.handleAjaxError(errorMsg);
}
}
/**
*LoadingTemplatesWithAjax StringToXMLParser    *
*@param xml 'str'        *
*@comments: Parse the string content into xml object   *
**/
LoadingTemplatesWithAjax.prototype.stringToXMLParser = function (str) {
if(IE) {
var myDocument;
myDocument = new ActiveXObject("Microsoft.XMLDOM")
myDocument.async= "false";
var parsed_xml = myDocument.loadXML(str);
return myDocument;
} else {
var xml = new DOMParser().parseFromString(str, 'text/xml');
return xml;
}
}
/**
* LoadingTemplatesWithAjax parseStrToXml  *
* @param xml 'str'     *
* @comments: Parse the xml content into a string *
**/
LoadingTemplatesWithAjax.prototype.parseStrToXml = function (xml) {
var str = (new XMLSerializer()).serializeToString(xml);
return str;
}
/**
* LoadingTemplatesWithAjax lastLoadedTpl     *
* @comments: sets an array of the last loaded template url and its method*
*  the method can only be a post or a get   *
**/
LoadingTemplatesWithAjax.prototype.setLastLoadedTpl = function () {
this.lastLoadedTpl[0] = this.sendType;
this.lastLoadedTpl[1] = this.url;
this.lastLoadedTpl[2] = this.file;
}
/**
*LoadingTemplatesWithAjax lastLoadedTpl     *
*@comments: returns an array of the last loaded template url and its *
*  method       *
**/
LoadingTemplatesWithAjax.prototype.getLastLoadedTpl = function () {
return this.lastLoadedTpl;
}
/**
*LoadingTemplatesWithAjax triggerSwitchPngImages    *
*@comments: The function to trigger the switch png images javascript *
*  Used by the steps templates     *
**/
LoadingTemplatesWithAjax.prototype.triggerSwitchPngImages = function () {
switchPngImages.setValues();
switchPngImages.highLightFirstElement('1_on.png');
switchPngImages.switchImage(1, true);
}
/**
* LoadingTemplatesWithAjax checkFormSavedPopup    *
* @comments: Open the formControl class and check if a form is saved and*
*  if it is, check if a popup has to open   *
*  the formControl.showSavePopup() returns a true or false *
**/
LoadingTemplatesWithAjax.prototype.checkFormSavedPopup = function () {
var formSavedPopup = formControl.showSavePopup();
var btnLink  = formControl.savePopupLink();
if(formSavedPopup) {
var popupObj = document.getElementById(formSavedPopup);
if(popupObj) {
if(btnLink) {
popup.setOnclick(btnLink);
}
popup.position(formSavedPopup);
formControl.resetSavePopup();
} else {
this.errorMsg.push('The popup object ' + formSavedPopup + ' does not exist!(LoadingTemplatesWithAjax.js method: checkFormSavedPopup())');
}
}
}
/**
* LoadingTemplatesWithAjax openPopup
* @param id 'string'  the ID of the element where the popup should be placed
* @param action 'string' the action to be coupled to the corresponding buttons
* @param doAction 'string' onclick-event to be coupled
* @comments: Opens a selected popup if the definition is set and the type
*  is set to openpopup
**/
LoadingTemplatesWithAjax.prototype.openPopup = function (id, action, doAction) {
var popupObj = document.getElementById(id);
if(popupObj) {
if(action && action != '') {
var checkPopupBtns = popup.checkBtns(id);
var len  = checkPopupBtns.length;
if(len == 1 && checkPopupBtns[0] == 'cancel') {
popup.setCancelBtnName(id, 'go');
}
if(action == 'url') {
popup.setOnclick('');
popup.setLink(doAction);
} else if(action == 'onclick') {
if(this.method) {
if(this.method != 'post' || this.method != 'get') {
this.errorMsg.push('The values of the method attribute do not match "post" or "get"!');
} else if(this.method == 'post') {
popup.setMethod(this.method);
}
}
popup.setLink('');
formControl.resetSavePopup();
popup.setOnclick(doAction);
} else {
this.errorMsg.push('The values of the action attribute do not match "url" or "onclick"!');
}
}
popup.resetContent();
popup.position(id);
popup.setContent();
} else {
this.errorMsg.push('The popup object ' + id + ' does not exist!(LoadingTemplatesWithAjax.js method: openPopup())');
}
}
/**
* LoadingTemplatesWithAjax isopenPopup
* @param id 'string' the id of the open popup
* @param action 'string' the type action
* @param doAction 'string'
* @param disabled 'boolean'
* @comments: If a popup is already open, change the content of the popup
**/
LoadingTemplatesWithAjax.prototype.isopenPopup = function (id, action, doAction, disabled, func) {
/**
* set the actions of the buttons
* if there is only a cancel button in the popup, but you still want
* to do an action, change the button into a 'go' button
**/
if(disabled == 'true') {
obj  = document.getElementById(id);
if(IE) {
obj.style.display = 'none';
} else {
obj.className = 'hide';
}
} else {
if(action && action != '') {
var checkPopupBtns = popup.checkBtns(id);
var len  = checkPopupBtns.length;
/**
* if the popup has only one button and the button is a cancel button,
* change the button name to 'go',
* a new event will be added to the button
**/
if(len == 1 && checkPopupBtns[0] == 'cancel') {
popup.setCancelBtnName(id, 'go');
}
if(action == 'url') {
popup.setOnclick('');
popup.setLink(doAction);
} else if(action == 'onclick') {
if(this.method) {
if(this.method != 'post' && this.method != 'get' && this.method != 'function') {
this.errorMsg.push('The values of the method attribute do not match "post", "get" or "function"!');
} else if(this.method == 'post' || this.method == 'function') {
popup.setMethod(this.method);
}
}
popup.setLink('');
formControl.resetSavePopup();
popup.setOnclick(doAction);
} else if(action == 'saveform') {
var doAction = formControl.getRedirectLink();
if(doAction) {
if(this.method) {
method = this.method;
} else {
method = 'get';
}
popup.setMethod(method);
formControl.resetSavePopup();
popup.setOnclick(doAction);
} else {
popup.setMethod('function');
popup.setOnclick('closePopup()');
}
} else {
this.errorMsg.push('The values of the action attribute do not match "url" or "onclick"!');
}
}
if(func && func != 'undefined') {
if(action == 'onclick') {
popup.checkSubmit(func);
} else {
popup.checkCancel(func);
}
}
popup.resetContent();
popup.setContent();
}
}
/**
* LoadingTemplatesWithAjax doAttr
* if the attribute type exists, doi something with the attributes
*
* @param type  'string'
* @param definition 'string'
* @param action 'string'
* @param doAction 'string'
* @param disabled 'string'
* @param func  'string'
*
* @requires changedFieldValues
* @requires adproJobStatus
* @requires projectAttributes
**/
LoadingTemplatesWithAjax.prototype.doAttr = function (type, definition, action, doAction, disabled, func) {
switch (type){
case 'steps':
if(this.checkJS) {
this.triggerSwitchPngImages();
}
if(definition == 'setFieldNewValue' && this.placeContent == 'value') {
changedFieldValues.setFieldNewValue(this.id, this.content)
}
break;
case 'important':
important.doAction(disabled);
break;
case 'openpopup':
if(definition) {
this.openPopup(definition, action, doAction);
} else {
this.errorMsg.push('Don\'t know which popup to show! The definition is not set');
}
break;
case 'isopenpopup':
this.isopenPopup(definition, action, doAction, disabled, func);
break;
case 'pdf':
adproJobStatus.getStatus(definition, action, func);
break;
default:
projectAttributes.doAttr(type, definition, action, doAction, disabled, func);
break;
}
/* if(type == 'steps') {
if(this.checkJS) {
this.triggerSwitchPngImages();
}
if(definition == 'setFieldNewValue' && this.placeContent == 'value') {
changedFieldValues.setFieldNewValue(this.id, this.content)
}
} else if(type == 'important') {
important.doAction(disabled);
} else if(type == 'openpopup') {
if(definition) {
this.openPopup(definition, action, doAction);
} else {
this.errorMsg.push('Don\'t know which popup to show! The definition is not set');
}
} else if(type == 'isopenpopup') {
this.isopenPopup(definition, action, doAction, disabled, func);
} else if(type == 'pdf') {
adproJobStatus.getStatus(definition, action, func);
} else {
go to own project function and handle project based attributes
projectAttributes.doAttr(type, definition, action, doAction, disabled, func);
}*/
}
function DebugWindow() {
}
DebugWindow.prototype.initDebugger = function () {
this.debug  = document.getElementById('debugWindow');
this.debugValue = new Array();
if(IE) {
document.attachEvent("onclick", errorHandler);
} else {
document.addEventListener("click", errorHandler, false);
}
}
DebugWindow.prototype.setDebugValue = function (value) {
this.debugValue.push(value);
}
DebugWindow.prototype.showDebug = function () {
if(this.debugValue.length) {
this.debug.innerHTML = '';
this.debug.innerHTML += '<h2>Debug window</h2><hr /><br />';
this.debug.innerHTML += '<p>';
for(i=0;i<this.debugValue.length;i++) {
this.debug.innerHTML += (i +1) + '. ' + this.debugValue[i] + '<br />';
}
this.debug.innerHTML += '</p>';
this.debug.className = 'show';
}
}
DebugWindow.prototype.handleAjaxError = function (errorMsg) {
var errorLength = errorMsg.length;
if(errorLength) {
var errorXmlStr = '<errors>\n';
for(a=0;a<errorLength;a++) {
errorXmlStr += '\t<error>\n\t\t' + errorMsg[a] + '\n\t</error>\n';
}
errorXmlStr += '</errors>\n';
var obj = document.getElementById('ajax_debugger');
if(obj) {
obj.innerHTML = errorXmlStr;
}
}
}
errorHandler = function(evt) {
if(errorMsg.length) {
debugWindow.handleAjaxError(errorMsg);
}
}
function PostValues() {
this.errorMsg = new Array();
this.types  = new Array();
this.url  = '';
this.formId  = null;
}
PostValues.prototype.setPostValues = function (obj) {
if(obj) {
var anchor  = obj;
} else {
var anchor  = getAnchorObject();
}
if(IE) {
if(anchor.srcElement) {
if(anchor.srcElement.nodeName != 'A') {
var anchor = find.findObjectByTagName(anchor.srcElement, 'A');
} else {
var anchor = anchor.srcElement;
}
}
} else {
if(anchor.currentTarget) {
var anchor = anchor.currentTarget;
}
}
this.url = false;
try {
if(!this.reference) {
var reference = anchor.getAttribute('reference');
} else {
var reference = this.reference;
}
} catch (e) {
errorMsg.push(e + ' (PostValues.js)');
debugWindow.handleAjaxError(errorMsg);
}
if(reference) {
var formObj = find.findObjectByTagName(anchor, 'FORM');
if(formObj) {
var fieldserror = formObj.getAttribute('fieldserror');
if(fieldserror) {
formControl.setFieldsErrorUrl(fieldserror);
}
var url = this.formFields(formObj, 'reference', reference);
if(url != '') {
this.url = url;
} else {
this.errorMsg.push('Notice: the url is empty, so no request is sent! (PostValues.js)');
}
} else {
var formId = this.getPostFormId();
var formObj = document.getElementById(formId);
if(formObj) {
var url = this.formFields(formObj, 'reference', reference);
if(url != '') {
this.url = url;
} else {
this.errorMsg.push('Notice: the url is empty, so no request is send! (PostValues.js)');
}
} else {
var formObj = this.findFormObjectsInDocument(reference);
if(!formObj) {
this.errorMsg.push('Could not find a form object! (PostValues.js)');
}
}
}
} else {
this.errorMsg.push('A reference must be set to the anchor tag to find the fields you want to post! (PostValues.js)');
}
if(this.errorMsg.length > 0) {
debugWindow.handleAjaxError(this.errorMsg);
}
return;
}
PostValues.prototype.setPostFormId = function (id) {
this.formId = id;
}
PostValues.prototype.getPostFormId = function () {
return this.formId;
}
PostValues.prototype.getPostValues = function () {
return this.url;
}
PostValues.prototype.createReference = function (reference) {
this.reference = reference;
}
PostValues.prototype.formFields = function (obj, attr, reference) {
var elements = obj.elements;
var len  = elements.length;
var count = 0;
var url  = '';
for(var i=0;i<len;i++) {
var checkDef= 0;
var checkReq= 0;
var elem = elements[i];
if(elem.getAttribute(attr)) {
if(elem.getAttribute(attr) == reference) {
var fieldId = elem.id;
var title = elem.title;
var checkReq = formControl.checkRequired(elem, title, obj);
var checkDef = formControl.checkDefinitions(elem, title);
var checkMinLength = formControl.checkMinLength(elem, title);
if(checkReq) {
count++;
}
if(checkDef) {
count++;
}
if(checkMinLength) {
count++;
}
if(checkDef == 0 && checkReq == 0) {
var value = elem.value;
var name = elem.name;
if(elem.type == 'radio') {
if(elem.checked) {
if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
}
} else if(elem.type == 'checkbox' && !elem.checked) {
url  += '&' + name + '=0';
} else if(value.match('&')) {
url  += '&' + name + '=' + escape(value);
} else {
url  += '&' + name + '=' + value;
}
}
}
}
}
if(count) {
formControl.setTheMessage();
url = '';
}
return url;
}
PostValues.prototype.findFormObjectsInDocument = function (reference) {
var objects = document.getElementsByTagName('FORM');
var len  = objects.length;
var url  = '';
this.url = false;
for(var i=0; i<len; i++) {
var formObj = objects[i];
var url =+ this.formFields(formObj, 'reference', reference);
}
if(url != '') {
this.url = url;
} else {
this.errorMsg.push('Notice: the url is empty, so no request is send! (PostValues.js)');
}
}
function Find() {
this.errorMsg = new Array();
}
Find.prototype.findPosX = function (obj) {
var curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
} else if (obj.x) {
curleft += obj.x;
}
return curleft;
}
Find.prototype.findPosY = function (obj) {
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop
obj = obj.offsetParent;
}
} else if (obj.y) {
curtop += obj.y;
}
obj = null;
return curtop;
}
Find.prototype.findObjectByTagName = function (obj, tagName) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.nodeName == tagName) {
newObject = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent tag ' + tagName + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.findObjectById = function (obj, id) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.id == id) {
newObject = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent object with id ' + id + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.findObjectByClassName = function (obj, name) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.className == name) {
newObject = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent object with className ' + name + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.findNextSibling = function (obj, name) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.nextSibling) {
while (obj.nextSibling) {
if(obj.nextSibling.nodeName == name) {
newObject = obj.nextSibling;
break;
} else {
obj = obj.nextSibling;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent object with className ' + name + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.findPreviousSibling = function (obj, name) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.previousSibling) {
while (obj.previousSibling) {
if(obj.previousSibling.nodeName == name) {
newObject = obj.previousSibling;
break;
} else {
obj = obj.previousSibling;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent object with className ' + name + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.findObjectByTitle = function (obj, value) {
checkObj = this.isObj(obj);
if(!checkObj) {
return false;
}
var newObject = null;
if (obj.parentNode) {
while (obj.parentNode) {
if(obj.title == value) {
newObject = obj;
break;
} else {
obj = obj.parentNode;
}
}
}
obj = null;
if(newObject) {
return newObject;
} else {
this.errorMsg.push('No parent object with title ' + value + ' was found');
debugWindow.handleAjaxError(this.errorMsg);
return false;
}
}
Find.prototype.selectedOption = function (obj) {
var options  = obj.getElementsByTagName('option');
var sel  = obj.selectedIndex;
var option  = options[sel];
if(option) {
return option;
} else {
errorMsg.push('Could not find a selected option');
debugWindow.handleAjaxError(errorMsg);
return false;
}
}
Find.prototype.isObj = function (obj) {
if(typeof(obj) != 'object') {
errorMsg.push('Could not find a selected option');
debugWindow.handleAjaxError(errorMsg);
return false;
}
return true;
}
/**
* Set Global vars
*/
/**
* alertDebugger
* @message 'string'
* @comments: You can call this function wherever you like to create a alert box.
* @comments: Call the executeAlert() method to display the alert
*/
function alertDebugger(message) {
alertMsg.push(message);
}
/**
* executeAlert
*/
function executeAlert() {
var len  = alertMsg.length;
var alertWindow = document.getElementById('alert');
var msg  = '';
try {
if(len) {
alertWindow.className = 'show';
for(var i=0; i<len; i++) {
msg += alertMsg[i] + '<br />';
}
var divs = alertWindow.getElementsByTagName('DIV');
var divsLen = divs.length;
for(var i=0; i<divsLen; i++) {
var div = divs[i];
if(div.className == 'alertMessage') {
div.innerHTML = msg;
}
}
}
} catch(e) {
errorMsg.push(e + ' (Alert.js)');
}
}
/**
* closeAlert
* @comments gets the element by id 'alert'
*/
function closeAlert() {
var alertWindow = document.getElementById('alert');
try {
alertWindow.className = 'hide';
var divs = alertWindow.getElementsByTagName('DIV');
var divsLen = divs.length;
alertMsg = new Array();
for(var i=0; i<divsLen; i++) {
var div = divs[i];
if(div.className == 'alertMessage') {
div.innerHTML = '';
}
}
} catch(e) {
errorMsg.push(e + ' (Alert.js)');
}
}
/**
* UserAgent constructor
* @comments: find out what the users platform and browser is
**/
function BrowserPlatform() {
this.browserPlatform = navigator.userAgent;
}
/**
* UserAgent getPlatform
* @comments: get the platform!
**/
BrowserPlatform.prototype.getPlatform = function() {
if(this.browserPlatform.indexOf("Win") != -1) {
var platform = 'Win';
} else if(this.browserPlatform.indexOf("Mac") != -1) {
var platform = 'Mac';
} else if(this.browserPlatform.indexOf("Lin") != -1) {
var platform = 'Lin';
} else {
var platform = false;
}
return platform;
}
/**
* UserAgent getBrowser
* @comments: get the browser!
*/
BrowserPlatform.prototype.getBrowser = function() {
if(navigator.userAgent.indexOf("Safari/3") != -1) {
var browser = false; // in the future marcompro has t run under Safari
} else if(navigator.userAgent.indexOf("Safari/4") != -1) {
var browser = false; // in the future marcompro has t run under Safari
} else if(navigator.userAgent.indexOf("Firefox/1.5") != -1) {
var browser = 'Firefox/1.5';
} else if(navigator.userAgent.indexOf("Firefox/2.0") != -1) {
var browser = 'Firefox/2.0';
} else if (navigator.userAgent.indexOf("MSIE 6.0") != -1) {
var browser = 'MSIE 6.0';
} else if (navigator.userAgent.indexOf("MSIE 7.0") != -1) {
var browser = 'MSIE 7.0';
} else {
var browser = false;
}
return browser;
}
BrowserPlatform.prototype.checkBrowserCompatibility = function(type) {
var browser = this.getBrowser();
if(!browser) {
if(type == 'alert') {
var msg = 'Marcompro does not (yet) support this browser!\nBrowser information:' + navigator.userAgent + '\n\nBrowsers that are available for Marcompro are: Mozilla Firefox 1.5 on Windows, Linux and Macintosh\nInternet explorer 6.0 on Windows';
}
}
}
triggerJavascript = function(value) {
var content = value;
var re =/<script.*>\s*(.*)<\/script>\s*/gi
var i = 0;
while(script = re.exec(content)) {
eval(script[1]);
i++;
}
if(i) {
return true;
} else {
return false;
}
}
var MARCOMPRO_MODE  = 0;
var errorMsg  = new Array();
var statusErrors  = new StatusErrors();
var xmlHttpObject  = new XMLHttpObject();
var browserPlatform  = new BrowserPlatform();
var debugWindow  = new DebugWindow();
var loadingTemplatesWithAjax= new LoadingTemplatesWithAjax();
var changedFieldValues = new ChangedFieldValues();
var formControl  = new FormControl();
var showPopup   = new ShowPopup();
var saveFormWithAjax = new SaveFormWithAjax(popup);
var postValues  = new PostValues();
var find   = new Find();
var projectAttributes  = new ProjectAttributes();
init = function() {
try {
setAnchorEvents();
setFormEvents();
debugWindow.initDebugger();
if(window.document.getElementById('debugWindow')) {
window.document.getElementById('debugWindow').style.display = "none";
}
projectInit();
} catch (e) {
errorMsg.push(e + ' (InitSiteview.js)');
debugWindow.handleAjaxError(errorMsg);
}
}
window.onload = init;

function stripTags(evt){
	if (IE){
		var e		= event;
		var obj		= event.srcElement;
	} else {
		var obj		= evt.currentTarget;
	}

	var HTMLRegExp 	= /<(.|\n)+?>/;
	var string 		= obj.value;
	if (string.match(HTMLRegExp)||string.match('<')||string.match('>')){
		var newstring	= string.replace(HTMLRegExp, '');
		newstring 		= newstring.replace('<', '&lt;');
		newstring 		= newstring.replace('>', '&gt;');

		obj.value		= newstring;
	}
}