

//***************************************************************************
// Set Global vars															*
//***************************************************************************

var IE				= document.all?true:false;
if(IE){
	try{
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err){		
	}
}

var alertMsg		= new Array();
var errorMsg		= new Array();
var popup;

var a;
var anchorObject;
var tmpAnchor;

var refreshKeyCodes		= new Array();
refreshKeyCodes[0]		= 116;
refreshKeyCodes[1]		= 82;
refreshKeyCodes[2]		= 114;

var backSpaceKeyCodes	= new Array();
backSpaceKeyCodes[0]	= 8;

// the defaultFilename can be changed in the globalProjectVars within your project

if(!defaultFilename) {
	var defaultFilename		= 'marcompro.php';
}
// base64 encoding vars
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

// IE7 detect

var IE7 = null;
var ua = navigator.userAgent;
var re  = new RegExp("MSIE ([7-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null) {
  IE7 = parseFloat( RegExp.$1 );
}


//***************************************************************************
// SetAnchorEvents															*
// comments:	Set standard anchor events									*
//***************************************************************************
setAnchorEvents = function() {
	
	$$('a').each(function(obj) {
	
		Event.observe(obj, 'click', setAnchorObject);
	});
}

//***************************************************************************
// setAnchorObject															*
// @a	'obj'																*
// comments: 	set the anchor object 										*
//***************************************************************************
setAnchorObject = function (evt) {

	var a = '';
	if(IE) {
		if(typeof(evt) == 'object') {
			a = evt;
		} else {
			
			var obj = event.srcElement;
		
			// stupid dumb IE bug for child Elements
			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															*
// comments: 	call this function when the anchor event is lost 			*
//***************************************************************************
getAnchorObject = function () {
	return anchorObject;
}









//***************************************************************************
// Set Global vars															*	
//***************************************************************************


//***************************************************************************
// ChangedFieldValues Constructor											*	
// Comment:	use the this.onFocusNewValues for changed values of the fields	*
//			use the this.onFocusFirstValues to save the original values of 	*
//			the fields														*
//***************************************************************************
function ChangedFieldValues() {
	this.onFocusNewValues		= new Object();
	this.onFocusFirstValues		= new Object();
	this.onclick				= false;
	this.popupCancel			= false;
	this.popupSubmit			= false;
}


//***************************************************************************
// ChangedFieldValues setFieldFirstValue									*
// @id	'string'															*
// @value	'string'														*
// comments:	Sets an array of all the first  values of the fields that 	*
//				are editted													*
//				Use the id of the field as a reference so we can check for 	*
//				changes later												*
//***************************************************************************
ChangedFieldValues.prototype.setFieldFirstValue = function (id, value) {
		this.onFocusFirstValues[id] 		= new Object();
		this.onFocusFirstValues[id][0]  	= value;
}


//***************************************************************************
// ChangedFieldValues setFieldsFirstValuesLoad								*
// @id	'string'															*
// comments:	
//***************************************************************************
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 setFieldsFirstValues									*
// @id	'string'															*
// comments:	Sometimes fields in a form will be filled by ajax			*
//				Normally we use the onfocus to set the first field values	*
//				But when fields are filled with ajax, no onfucus occures
//***************************************************************************
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 images		= obj.getElementsByTagName('IMG');

		var lenInputs	= inputs.length;
		var lenTextareas= textareas.length;
		var lenSelects	= selects.length;
		var lenImages	= images.length;
		
		// find the inputs
		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);
			}
			
		}
		// find the images
		for(var i=0; i<lenImages; i++) {
			
			var elem = 	images[i];
			if(elem.id) {
				var fieldId = elem.id;
				var value	= elem.src
				this.setFieldFirstValue(fieldId, value);
			}
			
		}
		
		// find the textareas
		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);
			}
			
		}
		
		// find the selects
		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 setFieldNewValue										*
// @id	'string'															*
// @value	'string'														*
// comments:	Sets an array of all the fields that are editted			*
//				Use the id of the field as a reference						*
//***************************************************************************
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 chechForChanges										*
// @obj	'object'															*
// @showPopup 'bool'														* 
// @onclick	'function'	temp onclick action									*
// comments:	Sets an array of all the fields that are editted			*
//				Use the id of the field as a reference						*
//***************************************************************************
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;
		
		// first get the right template
		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);
			
			// check if there are still ' at the front and back of the tpl
			if(first.match(rExp4) && last.match(rExp4)) {
				
				newLink 		= newLink.replace(rExp4, '');
			}
		}
	
		var get = fields + '&redirect=' + newLink;
		
		// load the popup template
		if(showPopup) {
			
			loadingTemplatesWithAjax.loadTplPost('?do=popupchangedfields', get);

			popup.checkSubmit('changedFieldValues.checkSubmit()');
		}
		return false;
		
	}
	return true;
}

//***************************************************************************
// ChangedFieldValues setLink												*
// @str_obj	'object || string'												*
// comments:	Sets the link for the popup									*
//***************************************************************************
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;
			//ie creates an anonymous function, we have to remove it to get to the string within
			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) {
							// remove the anonymous function wrapper 
							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) {
					// remove the anonymous function wrapper 
					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 checkCancel											*
// comments:	Check if the user pressed cancel in the popup				*
//***************************************************************************
ChangedFieldValues.prototype.checkCancel = function () {
	this.popupCancel = true;
}

//***************************************************************************
// ChangedFieldValues checkSubmit											*
// comments:	Check if the user pressed cancel in the submit button		*
//				if he has, all the values of the fields must be the set to	*
//				the first field values										*
//***************************************************************************
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);
	}

}

var changedFieldValues = new ChangedFieldValues();

/**
 * 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.
definitiontypes[5]	= 'phone';

var submittypes	= new Array();
submittypes[0]	= 'ajax';

/**
 * FormControl Constructor
 * @constructor
**/
function FormControl() {
	this.errorMsgRequired	= new Object();
	this.errorMsgTypes		= new Object();
	this.errors				= 0;
	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.errors = 1;
		this.setTheMessage();
		return false;
	} else {
		this.errors = 0;
		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(showPopupAtt) {
		this.showPopup = showPopupAtt;

		// check for a link

		var linkAtt 	= obj.getAttribute(link);
		if(linkAtt) {
			this.linkAtt = linkAtt;
		}
	}


	saveFormWithAjax.send(obj);
	return false;


}


/**
 * 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 == '') {
				//errorMsg.push(e + ' (FormControl.js)');
				//debugWindow.handleAjaxError(errorMsg);
				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(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;
				}
			}
		} else if(definitionAtt == definitiontypes[5]) {
			if(elem.value != '') {
				var phoneCheck	= this.checkPhone(elem);
				if(!phoneCheck) {
					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 validRegExp = new RegExp("^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([a-zA-Z0-9\\-\\.]+)(\\.)([a-zA-Z]{2,4})$");
	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 checkPhone
 * @param elem	'object'	the field object
 * @member FormControl
**/
FormControl.prototype.checkPhone = function (elem) {
	var validChars = "0123456789";
	var character;
	
	for (var z=0;z<elem.value.length;z++) { 
		character = elem.value.charAt(z); 
		if (validChars.indexOf(character) == -1 || elem.value.length < 10) {
			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) {
		msg		+= '&requiredContent[' + i + ']=' + msgRequired[i].id;
	}

	msgTypes	= this.errorMsgTypes;
	for(var i in msgTypes) {
		msg		+= '&wrongContent[' + i + ']=' + msgTypes[i].id;
	}


	// load the popup template
	loadingTemplatesWithAjax.loadTplPost(this.fieldserror, msg);

	// make sure the loader will apear
	// its just a check
	xmlHttpObject.resetLoader();

	// reset
	this.errorMsgRequired	= new Object();
	this.errorMsgTypes		= new Object();

	return true;
}

var formControl	= new FormControl();


//***************************************************************************
// Set Global vars															*	
//***************************************************************************
var popupId;
//********************
// Popup Constructor *
//********************
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) {
	// do not close the popup after an onclick
	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) {
	try {
		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;
	} catch(e) {
		errorMsg.push(e + ' (Popup_v0.1.js)');
	}
}

//********************
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);

	//this.setContent();
	
}

ShowPopup.prototype.setContent = function() {
	try {
		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);
				}
			}
			
			//buttons[i] = null;
		}
		
		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;
	} catch(e) {
		alert(e);
	}

}



setPopupGoEvent = function(evt) {
	
	if(click) {
		return;
	}
	
	
	var click 	= showPopup.getOnclick();
		
	var method 	= showPopup.getMethod();
	
	// call to an extra function by a submit
	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') {
			// first close the popup
			// otherwise the objects are gone
			closePopup();
			// do the event when the var is a function
			btn.onclick();
		} else if(method == 'function') {
			eval(click);
		} else {
			closePopup();
			
			try {

				// else, when the var is a string, load the string in the template loader
				if(method == 'post') {
					btn.onclick = loadingTemplatesWithAjax.loadTplPost(click, 1);
				} else if(method == 'get') {
					
					btn.onclick = loadingTemplatesWithAjax.loadTpl(click);
				} else if(!method)  {
					// temp hack
					// we need to re-write this class soon
					
					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;
	}

	// clean the method, otherwise it will be remembered!	
	method			= null;
	_this.method 	= null;
	btn 			= null;
	click			= null;
	type			= null;
	return;
	
}

setPopupNoEvent = function(evt) {
	// call to an extra function
	
	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 popup				= document.getElementById('popup');
			var obj					= document.getElementById(popupId);
			
			obj.className			= 'hide';	
			popupFilter.className	= 'hide';
			// clean up the mess
			
			$('popups').setStyle({height:0, margin:0, padding: 0});
			$('popups').innerHTML = '';
		} catch(e) {
			errorMsg.push(e + ' (Popup_v0.1.js)');
			
		}
	}
	
	// clean the method, otherwise it will be remembered!	
	_this.method 	= null;
	method			= null;
	
	
}

// hide select boxes for IE
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;
	}

}

var showPopup = new ShowPopup();


//***************************************************************************
// StatusErrors Constructor  												*
// comments:	Class wich returns all the errors that can occure			*
//***************************************************************************

function StatusErrors() {
	
}

//***************************************************************************
// XMLHttpObject post														*
// comments:
//***************************************************************************
StatusErrors.prototype.statusCheck = function(status, url) {

	try {
		rExp 			= /&/gi;
		replaceInUrl 	= new String("{{||}}");
		newUrl 			= url.replace(rExp, replaceInUrl);
		
		switch(status) {
		// bad request ( Impossible request or syntax error)
		case 400:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Unauthorized (Request should be retried with proper authorization header.)
		case 401:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Payment Required ( Request should be retried with proper charge-to header)
		case 402:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Forbidden ( Authorization will not help)
		case 403:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// page not found (A document with that URL doesn't exist)
		case 404:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// No such group ( (NCSA httpd) the newsgroup in news:newsgroup doesn't exist.)
		case 411:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Internal Error
		case 500:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Not implemented
		case 501:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;
		// Timed out
		case 502:
			loadingTemplatesWithAjax.loadTpl('marcompro.php?do=popuploaderror&errorType=' + status + '&url=' + newUrl);
			
			return false;
			break;	
			
		default:
			return true;
			break;
		}
	} catch(e) {
		
	}
}

var statusErrors = new StatusErrors();



/**
 * 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;
	instance.loading();
	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;
		// loaded
		case 2:
			//instance.loading();
			break;
		// interactive
		case 3:
			//instance.interactive();
			break;
		//complete
		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);
			}
			
			instance.loaded();

			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;
	instance.loading();
	this._xmlhttp.open('GET', url, true);
	this._xmlhttp.onreadystatechange = function() {
		switch(instance._xmlhttp.readyState) {
			case 1:
				//instance.loading();
				break;
			// loaded
			case 2:
				
				//instance.loading();
				break;
			// interactive
			case 3:
				//instance.interactive();
				break;
			//complete
			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);
				}
				
				instance.loaded();
	
				break;
		}
	}
	this._xmlhttp.send(null);
}

XMLHttpObject.prototype.loading = function() {
	this.requesting();
}

XMLHttpObject.prototype.loaded = function() {
	
	this.endRequesting();
}

XMLHttpObject.prototype.interactive = function() {
	this.requesting();
}

/**
 * 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) {

		// disable all the possible clicks
		showAppLayer();
		
		if(IE) {
			document.body.attachEvent("onclick", disableClick, false);
		} else {
			document.body.addEventListener("click", disableClick, false);
		}


		// show the loader
		document.body.style.cursor = 'wait';
		
		
		if(document.getElementById('page-busy-loading')) {
			this.endRequest = 0;
			this.pageLoading();
		}

	}

}

/**
 * XMLHttpObject pageLoading
 * @comments:
**/
XMLHttpObject.prototype.pageLoading = function () {
	
	if(this.loader == true) {
		this.loadingAnim = new YAHOO.util.Anim("page-busy-loading", {
			width: {from: 0, to:100}
		}, 1.3);
		
		this.loadingAnim.animate();
		
		this.loadingAnim.onComplete.subscribe(function() {
			if(!xmlHttpObject.endRequest) {
				xmlHttpObject.pageLoading();
			} else {
				document.getElementById('page-busy-loading').style.width = 0;
			}
		});
	}
}

/**
 * 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';
	
		hideAppLayer();
		
		if(document.getElementById('page-busy-loading')) {
			document.getElementById('page-busy-loading').style.width = 0;
			
			this.endRequest = 1;
		
		}
	}

}

/**
 * XMLHttpObject tplStatus
 * @param string func 		the function to be evaluated
 * @param int 	 delay 		delay for re-invoking the function
 * @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) {
	
	if(!delay) {
		var delay = 1000;
	}

	if(this._xmlhttp.readyState == 4 && this._xmlhttp.responseText != '') {
		// do something with a method
		
		if(func && func != '') {
			
			eval(func);
		}
		return true;
	} else {

		setTimeout("xmlHttpObject.tplStatus('" + func + "', '" + delay + "')", delay);
	}

}
*/
XMLHttpObject.prototype.tplStatus = function (func, delay, emptyResponse) {
	
	if(!delay) {
		var delay = 1000;
	}
	
	if(this._xmlhttp.readyState == 4) {
		// do something with a method
		
		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) {
			// set the response
			loadingTemplatesWithAjax.setResponse(result);

			this.rawResponse = result;
			// the template is loaded correctly, now we can save the last url that was used
			loadingTemplatesWithAjax.setLastLoadedTpl();

			if(this.initializer && MARCOMPRO_MODE) {
				init();
			}
			
			
			/*if(MARCOMPRO_MODE) {
				
				//initCB();
			}*/
		} else {
			// probably the users session has ended!Give a notice
			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';
	}
}

var xmlHttpObject = new XMLHttpObject();


/**
 * 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() {
	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') {
			// if an id isset instead of an object
			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.disabled) {

				continue;
			}
			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 != '') {
								
								url			+= '&' + name + '=' + encodeURIComponent(value);
								
							}

						} else if (field.type == 'checkbox') {

							if(name != '') {
								var submitempty = field.getAttribute('submitempty');
								
								if(!submitempty) {
									url			+= '&' + name + '=0';
								}
							}
						}
					} else if(field.type == 'file') {
						var upload = this.upload(form);
						if(upload) {
							// prevent form submitting twice
							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 != '') {
							
							url			+= '&' + name + '=' + encodeURIComponent(value);
						
						} else {
							if(IE) {
								// ons zorgen kindje IE
								a
								if(field.getAttribute('hack_ie')) {
									var name = field.getAttribute('hack_ie');
									
									url			+= '&' + name + '=' + encodeURIComponent(value);
								
								}
							}								
						}
					} else {

						if(field.value) {
							var value	= field.value;
						} else {
							var value	= '';
						}

						var name	= field.name;
						if(name != '') {
							
							url			+= '&' + name + '=' + encodeURIComponent(value);
						
						} else {
							if(IE) {
								// ons zorgen kindje IE
								if(field.getAttribute('hack_ie')) {
									var name = field.getAttribute('hack_ie');
									url			+= '&' + name + '=' + encodeURIComponent(value);
								}
							}
						}
					}
				}
			}
		}
		
		
		

		
		if(IE) {
			file = loadingTemplatesWithAjax.checkFilename(file);
		}

		var submit	= this.sendForm(file, url);
		if(submit) {


			return true;
		}

		return false;
	} catch(e) {
		
		errorMsg.push(e + 'saveformWithAjax.js (method: send())');
		debugWindow.handleAjaxError(errorMsg);
	}
}


/**
 * 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;
}

var saveFormWithAjax = new SaveFormWithAjax();


/**
 * 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 there are any loopings, stop them so we do not have multiple requests
	if(typeof(timer) == 'object') {
		timer.stop();
	}
	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
 * @param obj	'object'	Whem the clicked element is not an anchor tag, whe can use this object as a reference
 * @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 there are any loopings, stop them so we do not have multiple requests
	if(typeof(timer) == 'object') {
		timer.stop();
	}
	
	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;
	// first set the post values
	// if we already know the postvalues, use them as a get
	if(get) {
		if(get == 1) {
			var url = file;
		} else {
			var url = get;
		}
	} else {
		
		// else find the post values within the document
		postValues.setPostValues(obj);
		// then get the post values as a url string
		
		if(postValues.fieldErrors) {
			return;
		}
		
		var url	= postValues.getPostValues();
	}

	if(IE) {
		file = this.checkFilename(file);
	}

	if(file) {
		this.sendType	= 'post';
		this.file		= this.checkUrl(file);
		
		if(url != '') {
			this.url 		= this.checkUrl(url);
		}
		
		xmlHttpObject.post(file, url);

		return true;
	}
}

/**
 *LoadingTemplatesWithAjax preloadImgWait
 *@param url	'string'
 *@comments: 	Wait till all images are preloaded before we show the content
**/
LoadingTemplatesWithAjax.prototype.preloadImgWait = function (id, count) {
	
	try {
		if(!count) {
			var count			= 0;
		}
		var contentObj 		= document.getElementById(id);
		var docImages 		= contentObj.getElementsByTagName('img');
		
		if(docImages) {
			var len = docImages.length;
			var c	= 0;
			for(var i=0; i<len; i++) {
				var img	= docImages[i];
			
				if(img && img.complete) {
					c++;
					var loaderObj 	= find.findPreviousSibling(img, 'IMG');
				
					if(loaderObj) {
						
						var definition = '';
						if(loaderObj.getAttribute('definition')) {
						
							definition	= loaderObj.getAttribute('definition');
							
							if(definition == 'loader') {
								
								loaderObj.className = 'marcompro_hide';
								loaderObj = null;
								
							}
							
						}
						
					}
					
					img.className			= 'marcompro_show';
					
				}
			}
			
			if (c == len) {
				var obj					= document.getElementById('temp_preloader');
				if(obj) {
					obj.remove(obj);
				}
				
				this.show = '';

			} else { 	
				if(this.show == 'false' && count == 0) {
					this.preloadContent(contentObj);
				}
				count++;
				setTimeout("loadingTemplatesWithAjax.preloadImgWait('"+id+"','"+count+"')", 700); 
			}
		}
		
		contentObj 	= null;
		img			= null;
		docImages	= null;
		obj			= null;
		
	} catch(e) {
		
	}
}

/**
 *LoadingTemplatesWithAjax preloadContent
 *@param url	'string'
 *@comments: 	Wait till all images are preloaded before we show the content
**/
LoadingTemplatesWithAjax.prototype.preloadContent = function (contentObj) {
	var div				= document.createElement('div');
	div.id	 			= 'temp_preloader';
	//div.innerHTML		= this.imagepreload;
	contentObj.parentNode.insertBefore(div, contentObj);
}

/**
 *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) {
	
	try {
		if(url.match('&amp;')) {
			url = url.replace('amp;', '');
		}

		return url;
	} catch(e) {
		errorMsg.push(e + ' (LoadingTemplatesWithAjax.js) method: checkUrl');
		debugWindow.handleAjaxError(errorMsg);
	}
}

/**
 *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 = /^\?/;
	// we have to check wheather a filename has been put in the url
	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) {
	
	// check for fatal errors within the response
	this.checkFatalError(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++) {		
			
				// first reset all attributes
				var id 				= '';
				var type 			= '';
				var definition 		= '';
				var imagepreload 	= '';
				var placeContent	= '';
				var action 			= '';
				var doAction 		= '';
				var disabled 		= '';
				var show			= ''; // bool
				var method			= '';
				var init			= '';
				var func			= '';

				// get the nodes
				var node 	= nodes[i];

				// get the attributes
				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('imagepreload')) {
						var imagepreload	= node.getAttribute('imagepreload');
						this.imagepreload	= imagepreload;
					}

					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');
						this.show		= 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!');
				}
				
				
				// get the content
				
				if(node.childNodes[0]) {
					var content	= node.childNodes[0].nodeValue;
					this.content= content;
					
					if(id && id != '') {
						var contentToDoc	= document.getElementById(id);
						
						if(id == 'admin-content-indent' && !contentToDoc) {
							id		= 'admin-content';
							this.id = 'admin-content';
							contentToDoc	= document.getElementById(id);
						} else if(id == 'admin-content' && !contentToDoc) {
							id		= 'admin-content-indent';
							this.id = 'admin-content-indent';
							contentToDoc	= document.getElementById(id);
						}
						
						if(show && show != '') {
							if(show == 'true') {
								contentToDoc.className = 'marcompro_show';
							} else {
								contentToDoc.className = 'marcompro_hide';
							}
						}

						
						if(contentToDoc) {
							this.contentToDoc = contentToDoc;
						
							if(imagepreload && imagepreload != '') {
								//contentToDoc.className = 'hidden';
							}
							
							switch(placeContent){
								case 'value':
									contentToDoc.value	= content;
									break;
								case 'src':
									contentToDoc.src	= content;
									break;
								case 'none':
									break;
								default:

									contentToDoc.innerHTML = content;
									break;
							}
							
							if(imagepreload && imagepreload != '') {
								this.preloadImgWait(id);
								
							}

						} 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 = content.evalScripts();
					//this.checkJS = triggerJavascript(content);

				}

				if(func && func != '') {
					eval(func);
					func = 0;
				}

				// do the attributes
				// only when the correct type is set
				if(type && type != '') {
					this.doAttr(type, definition, action, doAction, disabled, func);
				}

				// with this we can set and unset the init()
				if(init  == 'false') {
					xmlHttpObject.unsetInit();
				} else if(init == 'true') {
					xmlHttpObject.setInit();
				}

		}

		// after loading the templates look for extra's
		var formSavedPopup 	= this.checkFormSavedPopup();

		// when all is loaded check for errors
		var errorLength	= this.errorMsg.length;

		if(errorLength) {
			debugWindow.handleAjaxError(this.errorMsg);
		}
	
	} catch(e) {
		
		errorMsg.push(e + ' (LoadingTemplatesWithAjax.setResponse)');
		debugWindow.handleAjaxError(errorMsg);
	}
		
		
}

/**
 *LoadingTemplatesWithAjax checkFatalError									*
 *@param xml	'str'														*
 *@comments: 	Check if there are any fatal errors within the response 	*
 *				If there are, show them in the debugger						*
**/
LoadingTemplatesWithAjax.prototype.checkFatalError = function (str) {
	if(str.match('<b>Fatal error</b>')) {
		errorMsg.push('A fatal error has encountered within the response!Check the firebug response code to track the error! (LoadingTemplatesWithAjax.checkFatalError)');
		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;
   	// Internet Explorer, create a new XML document using ActiveX
  	 // and use loadXML as a DOM parser.
   		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 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);

			//reset the savepopup otherwise we stay in a loop
			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) {
		// 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(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') {
				// make sure the onclick is not in use
				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);
					}
				}
				// make sure the link is not in use
				popup.setLink('');
				// we have our own link to trigger, so disable all the other links that are set
				formControl.resetSavePopup();
				popup.setOnclick(doAction);
			} else {
				this.errorMsg.push('The values of the action attribute do not match "url" or "onclick"!');
			}
		}

		// first reset cache content
		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) {
			// somehow IE doesn't want to change the className :S
			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') {
				// make sure the onclick is not in use
				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);
					}
				}

				// make sure the link is not in use
				popup.setLink('');
				// we have our own link to trigger, so disable all the other links that are set
				formControl.resetSavePopup();

				popup.setOnclick(doAction);
			} else if(action == 'saveform') {

				// check if the popup is triggered by saving a form

				// look for the link to redirect to
				var doAction = formControl.getRedirectLink();

				if(doAction) {

					if(this.method) {
						method = this.method;
					} else {
						method = 'get';
					}

					popup.setMethod(method);
					// we have our own link to trigger, so disable all the other links that are set
					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);
			}
		}

		// first reset cache content
		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(definition == 'setFieldNewValue' && this.placeContent == 'value') {
				//changedFieldValues.setFieldNewValue(this.id, this.content);
			}
			
			var containerObj	= document.getElementById('admin-content');
			if(!containerObj) {
				var containerObj	= document.getElementById('admin-content-indent');
			}
			
			if(containerObj) {
				var div				= document.createElement('div');
				div.className	 	= 'navbox-tabs-hor-pageTopIndent';
				containerObj.insertBefore(div, containerObj.childNodes[0]);
			}
			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:

		
			break;
	}
}

var loadingTemplatesWithAjax = new LoadingTemplatesWithAjax();



//***************************************************************************
// Set Global vars															*	
//***************************************************************************

//***************************************************************************
// DebugWindow Constructor													*	
//***************************************************************************
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 setDebugValue												*
// @values:	'string'														*
// comments: 	Set a debug array											*
//***************************************************************************
DebugWindow.prototype.setDebugValue = function (value) {
	this.debugValue.push(value);
}

//***************************************************************************
// DebugWindow showDebug													*
// @time:	'integer'														*
// comments:																*
//***************************************************************************
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);
	}
}

var debugWindow = new DebugWindow();

//***************************************************************************
// PostValues Constructor													*
// Comment:
//***************************************************************************
function PostValues() {
	this.errorMsg		= new Array();
	this.types			= new Array();
	this.url			= '';
	this.formId			= null;
}


//***************************************************************************
// PostValues setPostValues													*
// @id	'string'															*
// comments:
//***************************************************************************
PostValues.prototype.setPostValues = function (obj) {
	
	
	var anchor 		= obj;
	// check if the anchor isn't an event object
	// if it its, make it an anchor object
	if(IE) {
		
		if(anchor.srcElement) {
			// check if the evtn didn't bubble
			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);
			}
			
			// now we got the form object we can search for the correct fields
			// and their values
			
			var url	= this.formFields(formObj, 'reference', reference);
			
			if(url != '') {
				// set the url as a global var
				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 != '') {
					// set the url as a global var
					this.url = url;


				} else {
					this.errorMsg.push('Notice: the url is empty, so no request is send! (PostValues.js)');
				}

			} else {
				// serach the document for form tags with elements reference
				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 true;
}


//***************************************************************************
// PostValues setPostFormId													*
// comments: sets an id of a form											*
//***************************************************************************
PostValues.prototype.setPostFormId = function (id) {
	this.formId = id;
}

//***************************************************************************
// PostValues getPostFormId													*
// comments: get a form id
//***************************************************************************
PostValues.prototype.getPostFormId = function () {
	return this.formId;
}


//***************************************************************************
// PostValues getPostValues													*
// comments: return the post url
//***************************************************************************
PostValues.prototype.getPostValues = function () {
	return this.url;
}

//***************************************************************************
// PostValues getPostValues													*
// comments: return the post url
//***************************************************************************
PostValues.prototype.createReference = function (reference) {
	this.reference = reference;
}

//***************************************************************************
// PostValues formFields													*
// @obj	'object'															*
// @attr	'string'	the attribute to look for							*
// @reference	'string'	the correct ones								*
// comments:	Search the fields and check there values					*
//***************************************************************************
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 the field is validated
				// create the url
				if(checkDef == 0 && checkReq == 0) {
					
					var value	= elem.value;
					var name	= elem.name;
					
					if(elem.type == 'radio') {
						if(elem.checked) {
							url			+= '&' + name + '=' + encodeURIComponent(value);
						}
					} else if(elem.type == 'checkbox' && !elem.checked) {
						var submitempty = elem.getAttribute('submitempty');
						
						if(!submitempty) {
							url			+= '&' + name + '=0';
						}
					} else {
						
						
						if(name != '') {
							
							url			+= '&' + name + '=' + encodeURIComponent(value);
						
						} else {
							if(IE) {
								// ons zorgen kindje IE
								if(elem.getAttribute('hack_ie')) {
									var name = elem.getAttribute('hack_ie');
									url			+= '&' + name + '=' + encodeURIComponent(value);
									
								}
							}
						}
					}
				}
			}
		}
		

	}

	if(count) {
		this.fieldErrors = 1;
		formControl.setTheMessage();
		url = '';
	} else {
		this.fieldErrors = 0;
	}

	return url;

}

//***************************************************************************
// PostValues findFormObjectsInDocument										*
// comments: 	find all form objects in the document, then look for 		*
//				elements with a reference									*
//***************************************************************************
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];
		// create the url
		var url	=+ this.formFields(formObj, 'reference', reference);
	}

	if(url != '') {
		// set the url as a global var
		this.url = url;

	} else {
		this.errorMsg.push('Notice: the url is empty, so no request is send! (PostValues.js)');
	}
}

var postValues				= new PostValues();

//***************************************************************************
// Find Constructor															*		
// comments: 	Class to find all kind of stuff, like finding the left or 	*
//				top position of an object or a parent object				*
//***************************************************************************

function Find() {
	this.errorMsg		= new Array();
}

//***************************************************************************
// Searchbox findPosX														*
// @obj	'object'															*
// comments:	find the left position of the selected object				*
//***************************************************************************
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;
	
}

//***************************************************************************
// Searchbox findPosY														*
// @obj	'object'															*
// comments:	find the top position of the selected object				*
//***************************************************************************
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;
	
}
//***************************************************************************
// Searchbox findObjectByTagName											*
// @obj 'object' Current object												*
// @tagName	'string'														*
// comments:	find a parent object by tagname								*
//***************************************************************************
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;
	}
}

//***************************************************************************
// Searchbox findObjectById													*
// @id	'string'															*
// @obj 'object' Current object												*
// comments:	find a parent object by tagname								*
//***************************************************************************
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;
	}
}

//***************************************************************************
// Searchbox findObjectByClassName											*
// @id	'string'															*
// @obj 'object' Current object												*
// comments:	find a parent object by tagname								*
//***************************************************************************
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;
	}
}

//***************************************************************************
// Searchbox findNextSibling												*
// @id	'string'															*
// @obj 'object' Current object												*
// comments:	find a next sibling by its tag name							*
//***************************************************************************
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;
	}
}

//***************************************************************************
// Searchbox findPreviousSibling											*
// @id	'string'															*
// @obj 'object' Current object												*
// comments:	find a previous sibling by its tag name						*
//***************************************************************************
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 findObjectByTitle													*
// @obj 'object' Current object												*
// comments:	find a parent object by title								*
//***************************************************************************
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 findObjectByDefinition												*
// @obj 'object' Current object												*
// comments:	find a parent object by its definition						*
//***************************************************************************
Find.prototype.findObjectByDefinition = function (obj, value) {
	checkObj = this.isObj(obj);
	if(!checkObj) {
		return false;
	}

	var newObject = null;
	if (obj.parentNode) {
		while (obj.parentNode) {
			var definition = obj.getAttribute('definition');
			if(definition == 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;
	}
}
//***************************************************************************
// Searchbox selectedOption													*
// @obj 'object' Selectbox													*
// comments:	find the selected option object within a selectbox			*
//***************************************************************************
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 isObj																*
// @obj 'object' 															*
// comments:	check if the object is indeed an object						*
//***************************************************************************
Find.prototype.isObj = function (obj) {
	
	if(typeof(obj) != 'object') {
		errorMsg.push('Could not find a selected option');
		debugWindow.handleAjaxError(errorMsg);
		return false;
	} 
	
	return true;
}	

var find= new Find();


/**
 * 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;

		// make sure we don't leave a mess
		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';
//			alert(msg);
		}
	}
}

var browserPlatform	= new BrowserPlatform();

//***************************************************************************
// Set Global vars															*	
//***************************************************************************

//***************************************************************************
// Timer Constructor														*		
// comments: 	Starts a timer
//***************************************************************************
function Timer() {
	this.loop 		= 0;
	this.count		= 0;
	this.status 	= 0;
	this.tStart  	= null;
	this.maxCount	= null;
	this.func		= null;
	// set default in sec
	this.delay		= 1000;
}

//***************************************************************************
// Timer updateTimer														*
// comments: 	Loop through the timer, untill a max is reached (if a max is*
//				set)	 													*
//***************************************************************************
Timer.prototype.updateTimer = function() {
	
	/*
	if(this.status == 1) {
		return true;
	}
	*/
	
	if(this.maxCount && this.maxCount <= this.count) {   
   		
   		// if a function is set, execute it
   		if(this.func) {
   			
   			// first check if the method(s) are in an object
   			var check = eval(this.func);
   		
   			if(typeof check == 'function') {
   				eval(this.func);
   			} else if(typeof check == 'object') {
   				var len = check.length;
   				
   				for(var i=0;i<len; i++) {
   					eval(check[i]);
   				}
   			}
   			
   		}
		this.stop();
		
		return true;
   	}

   	this.count = this.count + this.delay;
   	this.loop = setTimeout("timer.updateTimer()", this.delay);
  
   	return false;
}

//***************************************************************************
// Timer start																*	
// comments: 	Start the loop here 										*
//***************************************************************************
Timer.prototype.start = function(func) {
	this.loop = setTimeout("timer.updateTimer()", 1);
	
	if(func) {
   			
		// first check if the method(s) are in an object
		var check = eval(func);
	
		if(typeof check == 'function') {
			eval(func);
		} else if(typeof check == 'object') {
			var len = check.length;
			
			for(var i=0;i<len; i++) {
				eval(check[i]);
			}
		}
	}
}

//***************************************************************************
// Timer max																*	
// @sec 'int' set the max mili seconds										*
// @func 'string' set a return function when the max is reached				*
// comments: 	Set a max when the loop has to stop 						*
//***************************************************************************
Timer.prototype.max = function(sec, func) {
	if(isNaN(sec)) {
		return false;
	}
	

	this.maxCount = sec;
	this.status 	= 0;
	// when the max is reached, call a function
	this.func = func;
	return true;
}

//***************************************************************************
// Timer stop																*	
// comments: 	Stops the timer												*
//***************************************************************************
Timer.prototype.stop = function() {
	this.count 		= 0;
	//this.status 	= 1;
	//this.func		= null;
	clearTimeout(this.loop);
}


//***************************************************************************
// Timer setDelay															*	
// comments: 	sets a delay, default delay is 1 sec						*
//***************************************************************************
Timer.prototype.setDelay = function(delay) {
 	this.delay = delay;
}

var timer	= new Timer();


//alert('');
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();

deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}

deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += ' />';
		} else {
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion;
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject;
var SWFObject = deconcept.SWFObject;


/*
     Initialize and render the MenuBar when its elements are ready 
     to be scripted.
*/	

InitMenu = function() {
	
	
	YAHOO.util.Event.onContentReady("menu_bar", function () {
        try {
		
	    /*
	         Instantiate a Menu.  The first argument passed to the 
	         constructor is the id of the element in the DOM that represents 
	         the Menu instance.
	    */
	    
	    oMenuBar = new YAHOO.widget.MenuBar("menu_bar", { 
	                                                autosubmenudisplay: true, 
	                                                hidedelay: 750, 
	                                                lazyload: true });
	    
	    
	    /*
	         Call the "render" method with no arguments since the markup for 
	         this Menu instance already exists in the DOM.
	    */
	    
	    oMenuBar.render();
		positionMainItems();
        } catch(e) {}
	            
	});

	
}

positionMainItems = function(menuId, availableWidth){
	
	//alert(1);
	
	try {		
		var iWidth 	= 0;//will contain the total width of all main menu items
		var aWidth 	= availableWidth;
		var iFills	= $$('#' + menuId + ' li.li_fill');//collection of list items with class li_fill
		
		//loop through main menu items to get the total width
		$$('#' + menuId + ' li.item').each(function(obj){	
			var obj = $(obj);
			
			//alert(obj.getWidth());
			//var	imgMenu		= obj.select("a img");
			//var theWidth	= imgMenu[0].getWidth();
			var theWidth	= obj.getWidth();
			
			iWidth += theWidth;
		}); 
		
		//now calculate the new width of the 'fill' list items
		var nWidth = parseInt((aWidth - iWidth) / iFills.length);
		
		//loop through 'fill' list items an set new width	
		iFills.each(function(obj){
			var obj = $(obj);    		
			obj.setStyle({
				width: nWidth + 'px'
			});
		}); 
	} catch(e) {} 	
}

justifyMenus = function(){	
	positionMainItems('mainMenu', 925);
	positionMainItems('bottomMenu', 750);
}


function screenchange(){
	if (document.documentElement.clientWidth < 985 ){
		document.getElementById('website_container').className = document.getElementById('website_container').className.replace(/website_bigscreen/, 'website_smallwidth');
	} else if (document.documentElement.clientHeight < 550){
		//document.getElementById('website_container').className='website_container website_smallheight';
	} else {
		document.getElementById('website_container').className = document.getElementById('website_container').className.replace(/website_smallwidth/, 'website_bigscreen');
	}
}



resizeIframe = function(iframe){	

	if(document.all){
		var doc = iframe.contentWindow.document
	} else {
		var doc = iframe.contentDocument;
	}
	
	var height = doc.body.scrollHeight;
	
	iframe.style.height = height + 'px';
}



var screenchange;
projectInit = function() {	
	window.onresize  = screenchange;
	screenchange();
}

/*
	some main scripts
*/
function getDefaults(options,default_args)
{
	for(var index in default_args) 
	{
		if(typeof options[index] == "undefined") options[index] = default_args[index];
	}	
	
	return options;
}

function debug(str,useAlert)
{
	try{
		console.log(str);
	} catch (e){
		if(typeof(useAlert)!="undefined")
		{
			if(useAlert) alert(str);
		}
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	    while(1) 
	    {
	      curleft += obj.offsetLeft;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.x)
	    curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	return curtop;
}




//alert('cache dingetje');
/*
 * Orginal: http://adomas.org/javascript-mouse-wheel/
 * prototype extension by "Frank Monnerjahn" <themonnie@gmail.com>
 */
Object.extend(Event, {
	wheel:function (event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120;
			if (window.opera) delta = -delta;
		} else if (event.detail) { delta = -event.detail/3;	}
		return Math.round(delta); //Safari Round
	}
});
/*
 * enf of extension
 */

/*
	contentscroller.js

	v1.2

	* added mousewheel support

	Fransjo
*/
var ContentScroller=Class.create({

	hasInit						: true,

	wrapper						: "",
	elWrapper					: null,
	parentDimensions			: null,

	content						: "",
	elContent					: null,
	contentDimensions			: null,

	upButton					: "",
	elUpButton					: null,

	downButton					: "",
	elDownButton				: null,

	clickInterval				: null, //interval obj als je up of down button ingedrukt hou

	slider						: null, //slider obj

	scrollBarSliderWrapper		: "",
	elScrollBarSliderWrapper	: null,

	scrollBarSlider				: "",
	elScrollBarSlider			: null,

	scrollValue					: -1,

	bottomConstraint			: 0,
	bottomConstraintReal		: 0,
	topConstraint				: 0,

	contentPercent				: 1, // percentage van de content tov de parent container
	scaleFactor					: 1,

	sliderValue					: 0,

	useMouseScroller			: true,

	threshold					: 0.97,

	initialize:function(args)
	{
		// check voor default waarden
		args=getDefaults(args,{
			wrapper					: this.wrapper,
			content					: this.content,
			upButton				: this.upButton,
			downButton				: this.downButton,
			scrollValue				: this.scrollValue,
			scrollBarSliderWrapper	: this.scrollBarSliderWrapper,
			topConstraint			: this.topConstraint,
			bottomConstraint		: this.bottomConstraint,
			scrollBarSlider			: this.scrollBarSlider,
			useMouseScroller		: this.useMouseScroller,
			threshold				: this.threshold
		});

		// bestaat de parent container?
		if(args.wrapper!="" && $(args.wrapper)){
			this.wrapper=args.wrapper;
			this.elWrapper=$(args.wrapper);
		} else {
			this.hasInit=false;
		}

		// bestaat de content container?
		if(args.content!="" && $(args.content)){
			this.content=args.content;
			this.elContent=$(args.content);
		} else {
			this.hasInit=false;
		}

		if(args.scrollBarSliderWrapper!="" && $(args.scrollBarSliderWrapper)){
			this.scrollBarSliderWrapper=args.scrollBarSliderWrapper;
			this.elScrollBarSliderWrapper=$(args.scrollBarSliderWrapper);
			this.elScrollBarSliderWrapper.setOpacity(0);
		} else {
			this.hasInit=false;
		}

		if(this.hasInit){

			this.threshold=args.threshold;
			this.useMouseScroller=args.useMouseScroller;

			//this.elScrollBarSliderWrapper.setOpacity(0);
			this.parentDimensions=this.elWrapper.getDimensions();

			// prepare content
			this.elContent.style.top="0px";
			this.contentDimensions=this.elContent.getDimensions();

			// bereken percentage van content tov scrollerviewport
			this.contentPercent=this.parentDimensions.height/this.contentDimensions.height;

			// setup buttons
			if(args.upButton!="" && $(args.upButton)){
				this.upButton=args.upButton;
				this.elUpButton=$(args.upButton);
				this.elUpButton.hide();
			} else {
				this.upButton="";
			}

			if(args.downButton!="" && $(args.downButton)){
				this.downButton=args.downButton;
				this.elDownButton=$(args.downButton);
				this.elDownButton.hide();
			} else {
				this.downButton="";
			}

			if(this.contentPercent<=this.threshold)
			{
				this.topConstraint=args.topConstraint;
				this.bottomConstraint=args.bottomConstraint;

				// check of er een slider is om aan te kunnen draggen
				if(args.scrollBarSlider!="" && $(args.scrollBarSlider)){
					this.scrollBarSlider=args.scrollBarSlider;
					this.elScrollBarSlider=$(args.scrollBarSlider);
				} else {
					this.scrollBarSlider="";
				}

				// bereken nieuwe hoogte van de slider
				var sliderH=parseInt(this.contentPercent * this.elScrollBarSliderWrapper.getHeight());

				this.scaleFactor=(1/this.elScrollBarSliderWrapper.getHeight()) * 100;


				// bereken waar de slider moet stoppen
				this.bottomConstraint=this.elScrollBarSliderWrapper.getHeight()-sliderH;
				this.bottomConstraintReal=Math.round(this.bottomConstraint * this.scaleFactor);

				// setup slider (waar je aan dragt)
				//this.scrollBarSlider="";
				if(this.scrollBarSlider!=""){
					this.elScrollBarSlider.style.height=sliderH + "px";
				}

				// setup scroller

				this.slider = YAHOO.widget.Slider.getVertSlider(this.scrollBarSliderWrapper, this.scrollBarSlider, this.topConstraint, this.bottomConstraint);
	        	this.slider.subscribe("change",this.onSliderChange.bindAsEventListener(this));
	        	this.setSliderValue(0); // begin bij 0
	        	this.slider.animate = false;

	        	// bepaalt hoeveel stappen de slider moet gaan als je op "up" of "down" gaat
				this.scrollValue=args.scrollValue;
				if(this.scrollValue<=0){
					this.scrollValue=Math.ceil(this.elScrollBarSliderWrapper.getHeight()/22);
				}


				// setup buttons (add events)
				if(this.upButton!=""){
					//Event.observe(this.elUpButton,'click',this.scrollUp.bindAsEventListener(this));
					Event.observe(this.elUpButton,'mousedown',this.onScrollUp.bindAsEventListener(this));
					Event.observe(this.elUpButton,'mouseup',this.stopScrolling.bindAsEventListener(this));
					Event.observe(this.elUpButton,'mouseout',this.stopScrolling.bindAsEventListener(this));
					this.elUpButton.show();
				}

				if(this.downButton!=""){
					//Event.observe(this.elDownButton,'click',this.scrollDown.bindAsEventListener(this));
					Event.observe(this.elDownButton,'mousedown',this.onScrollDown.bindAsEventListener(this));
					Event.observe(this.elDownButton,'mouseup',this.stopScrolling.bindAsEventListener(this));
					Event.observe(this.elDownButton,'mouseout',this.stopScrolling.bindAsEventListener(this));
					this.elDownButton.show();
				}


				// setup mousewheel
				if(this.useMouseScroller && Event.wheel){
					Event.observe(this.elWrapper, "mousewheel", this.onMouseWheelScroll.bind(this), false); // IE
					Event.observe(this.elWrapper, "DOMMouseScroll", this.onMouseWheelScroll.bind(this), false); // Firefox
				}


				this.elScrollBarSliderWrapper.setOpacity(1);
				this.elScrollBarSliderWrapper.style.display="";
			} else {

				this.elScrollBarSliderWrapper.hide();
			}
		}
	},

	onMouseWheelScroll:function(e){

		if(Event.wheel(e)>0){
			this.scrollUp();
		} else {
			this.scrollDown();
		}

	},

	onSliderChange:function(e){

		// deprecated
		if(this.scrollBarSlider=="") this.setSliderValue(this.slider.getValue());

		this.update();
	},

	getSliderRealValue:function(e){
		var realVal=0;

		if(this.scrollBarSlider=="")
		{
			realVal=this.sliderValue;
		} else {
			realVal=this.slider.getValue();
		}

		realVal=Math.round(realVal * this.scaleFactor);

		return realVal;
	},


	stopScrolling:function(){
		if(this.clickInterval!=null) this.clickInterval.stop();
	},

	onScrollUp:function(){
		this.stopScrolling();
		this.clickInterval=new PeriodicalExecuter(this.scrollUp.bind(this), 0.1);
	},


	scrollUp:function(){
		if(this.scrollBarSlider=="")
		{
			this.sliderValue-=this.scrollValue;
		} else {
			this.sliderValue=this.slider.getValue()-this.scrollValue;
		}

		if(this.sliderValue<0) this.sliderValue=0;

		this.setSliderValue(this.sliderValue);
		this.update();
	},


	onScrollDown:function(){
		this.stopScrolling();
		this.clickInterval=new PeriodicalExecuter(this.scrollDown.bind(this), 0.1);
	},



	scrollDown:function(){
		if(this.scrollBarSlider=="")
		{
			this.sliderValue+=this.scrollValue;
		} else {
			this.sliderValue=this.slider.getValue()+this.scrollValue;
		}

		this.setSliderValue(this.sliderValue);
		this.update();
	},

	setSliderValue:function(val){
		if(this.scrollBarSlider=="")
		{
			this.sliderValue=val;
		} else {
			this.slider.setValue(val);
		}
	},

	update:function(){
		var actualValue = this.getSliderRealValue();
		var topValue=0;

		// kijken of we een slider hebben EN onderkant van de slidercontainer bereikt is
		if(this.scrollBarSlider=="" && actualValue>this.bottomConstraintReal) {
			actualValue=this.bottomConstraintReal;
			this.setSliderValue(this.bottomConstraint);
		}

		if(actualValue>0){
			topValue=Math.round(this.contentDimensions.height * (actualValue/100)) * -1;
		}

		this.elContent.style.top=topValue + "px";
	}
});

/*
	photoscroller.js
*/

var MyUtils = {
    getTarget: function(e){
		e = (e.browserEvent || e);
		return (e.target || e.srcElement);
	},
	
    getRelatedTarget: function(ev) { // missing from prototype?
        ev = ev.browserEvent || ev;
        var t = ev.relatedTarget;
        if (!t) {
            if (ev.type == "mouseout") {
                t = ev.toElement;
            } else if (ev.type == "mouseover") {
                t = ev.fromElement;
            }
        }

        return this.resolveTextNode(t);
    },
    
    resolveTextNode: function(node) {
        if (node && 3 == node.nodeType) {
            return node.parentNode;
        } else {
            return node;
        }
    }	
}
Element.addMethods(MyUtils);


var PhotoScroller=Class.create({
	wrapper				: "",
	elWrapper			: null,
	itemsWrapper		: null,
	imageContainer		: "",
	elImageContainer	: null,
	hasInit				: true,
	parentTop			: 0,
	parentLeft			: 0,
	parentCenter		: 0,
	parentCenterABS		: 0,
	preload				: true,		// Safari (windows) heeft een preloader nodig ... 
	scrollerInterval	: 0.05,
	//scrollerInterval	: 0.5,
	scrollerController	: null,
	scrollValue			: 1,
	defaultScrollValue	: 10,
	scroll				: true,
	items				: null,
	paddingRight		: 5,
	totalItemsWidth		: 0,
	imageQue			: null,
	version				: 2,
	centerMargin		: 50,
	counter				: 0,
	direction			: 1,		// 1 = naar rechts, -1 is naar links
	distance			: 0,
	maxLeft				: 150, 		// maximale waarde dat een element naar rechts of links gaat scrollen
	ajaxUrl				: "",
	behaviour			: "normal",

	
	initialize:function(args){
		
		// check voor default waarden
		args=getDefaults(args,{
			wrapper				: this.wrapper,
			scrollerInterval	: this.scrollerInterval,
			scrollValue			: this.scrollValue,
			paddingRight		: this.paddingRight,
			scroll				: this.scroll,
			centerMargin		: this.centerMargin,
			preload				: this.preload,
			imageContainer		: this.imageContainer,
			ajaxUrl				: this.ajaxUrl,
			maxLeft				: this.maxLeft,
			behaviour			: this.behaviour,
			defaultScrollValue	: this.defaultScrollValue
		});		
						
		// bestaat de parent container?
		if(args.wrapper!="" && $(args.wrapper)){
			this.wrapper=args.wrapper;
			this.elWrapper=$(args.wrapper);
		} else {
			this.hasInit=false;
		}
		
		if(this.hasInit){
			this.defaultScrollValue		= args.defaultScrollValue;
			this.behaviour				= args.behaviour;
			this.maxLeft				= args.maxLeft;
			this.preload				= args.preload;
			this.centerMargin			= args.centerMargin;
			this.scroll					= args.scroll;
			this.scrollerInterval		= args.scrollerInterval;
			this.scrollValue			= args.scrollValue;
			this.paddingRight			= args.paddingRight;
						
			var pos=this.elWrapper.positionedOffset();
			this.parentTop	= pos[1];
			this.parentLeft	= pos[0];
			if(this.parentLeft==0) this.parentLeft=findPosX(this.elWrapper);
			
			if(this.behaviour=="normal"){
				
				// deze zijn nodig voor de photoscroller 
				this.parentCenter=Math.round(this.elWrapper.getWidth()/2);
				this.parentCenterABS=this.parentCenter+this.parentLeft;
				this.stopRegionStart=this.parentCenterABS-this.centerMargin;
				this.stopRegionEND=this.parentCenterABS+this.centerMargin;
								
				// bestaat de imagecontainer?
				if(args.imageContainer!="" && $(args.imageContainer)){
					this.imageContainer=args.imageContainer;
					this.elImageContainer=$(args.imageContainer);
				} else {
					this.imageContainer="";
				}			
				
				if(args.ajaxUrl!="") this.ajaxUrl=args.ajaxUrl;
			}
						
			// haal de images
			this.collectItems();	
			
				
		}
		
	},
	
	collectItems:function(){		
		
		this.totalItemsWidth=0;
		this.itemsWrapper=null;
		
		this.hasInit=false;
		
		var itemsWrapper;
		
		
		if(itemsWrapper=this.elWrapper.select(".photoscroller_items"))
		{
			this.itemsWrapper=itemsWrapper[0];
			if(this.items=this.itemsWrapper.select("img")){
				this.hasInit=true;
										
				var itemsCount=this.items.length;
				
				// id's zetten en preloaden
				this.imageQue=new ImageQue();
							
				for(var i=0;i<itemsCount;i++){
					var el=this.items[i];
					el.id=this.wrapper + "_" + i;
					el.setOpacity(0);
					
					this.items[i]=el;
					
					if(this.preload) this.imageQue.add(el);
				};
				
				
				if(this.preload){
					this.imageQue.start();
					this.imageQue.onComplete=this.imagesLoaded.bind(this);
				} else {
					this.imagesLoaded();
				}
				
			}
		}
		
	},
	
	imagesLoaded:function(){		
		
		var itemsCount=this.items.length;		
		for(var i=0;i<itemsCount;i++){
			var el	= this.items[i];
			el.id	= this.wrapper + "_" + i;
			this.totalItemsWidth+=el.getWidth();
								
			this.items[i] = el;
		}
		
		
		// kijken hoevaak de childelementen in de parent container passen
		// moet minstens 2x de width van de parent container zijn
		
		var numDuplicates=parseInt((this.elWrapper.getWidth()*2) / this.totalItemsWidth);
		
		//console.log("numDuplicates = " + numDuplicates);
		
		for(var i=0;i<numDuplicates;i++){
			for(var q=0;q<itemsCount;q++){
				el	= this.items[q];
				
				var clone	= el.cloneNode(false);		
				var newID	= (q+(itemsCount*(i+1)));
					
				//console.log(newID);
				
				clone.id	= this.wrapper + "_" + newID;
				
				this.itemsWrapper.appendChild(clone);				
				this.items.push(clone);
			}
		}
		
		
		// en nu positioneren en events koppelen
		
		var itemsCount=this.items.length;
		this.totalItemsWidth=0;
		for(var i=0;i<itemsCount;i++)
		{
			var el=this.items[i];							
			el.style.top="0px";
			el.style.left=this.totalItemsWidth + "px";			
			el.absolutize();
			
			this.totalItemsWidth+=el.getWidth();
			

			if(this.scroll){
				var attributes = { 
					opacity: { from: 0, to: 1 } 
				}; 			
				
				var fadeIn = new YAHOO.util.Anim(el.id, { opacity: { to: 1 } }, 1);
				fadeIn.animate();
			} else {
				el.setOpacity(1);
			}

			
			if(this.behaviour=="normal") Event.observe(el,'click',this.onClick.bindAsEventListener(this));		
		}
		
		
		
		
		Event.observe(this.elWrapper,'mousemove',this.onMouseMove.bindAsEventListener(this));
		
		if(this.behaviour!="normal"){
			Event.observe(this.elWrapper,'mouseout',this.onMouseOut.bindAsEventListener(this));
		}
		
	},
	
	onMouseOut:function(e){
		var el=e.element();
		
		var myEl2=Element.getRelatedTarget(e);
		if(myEl2.identify()==this.wrapper || myEl2.descendantOf(this.wrapper)){
			this.stop();
		} else {
			this.start();
		}
	},
	
	onMouseMove:function(e){
		
		this.distance=0;
		this.counter++;
		this.direction=0;
		
		// eerst kijken of we in de viewport zitten
		var el=e.element();
		if(el.identify()==this.wrapper || el.descendantOf(this.wrapper)){
						
			if(this.behaviour=="normal")
			{
				// haal absolute X waarde van de muis
				var absX	= e.pointerX();
				
				// zit X waarde in stop regio?
				if(absX>this.stopRegionStart && absX<this.stopRegionEND){
					this.direction	= 0;
				} else {
					
					// X waarde zit niet in stop regio, welke kant dan wel?
					// en bereken nieuwe snelheid voor verplaatsing				
					var distance=0;
					if(absX>this.parentCenterABS){
						this.distance	= absX-this.stopRegionEND;
						this.direction	= -1;
					} else {
						this.direction	= 1;
						this.distance	= this.stopRegionStart-absX;
					}
					
				}
			} else {
				this.stop();
			}
		}
	},
	
	onClick:function(e){
		var el=e.element();
		
		// hebben we een imagecontainer of een plaatje erin te kunnen dumpen?
		if(this.imageContainer != ""){
			
			var fadeOut = new YAHOO.util.Anim(this.elImageContainer, { opacity: { to: 0 } }, 0.1);
			fadeOut.animate();
			
			if(this.ajaxUrl!=""){
				new Ajax.Request(this.ajaxUrl,{
					onComplete:this.onImageRecieved.bindAsEventListener(this)
				});
			}
		}
	},
	
	onImageRecieved:function(transport){
		if(t=transport.responseText.evalJSON()){			
			this.elImageContainer.src	= t.image;
			var fadeIn					= new YAHOO.util.Anim(this.elImageContainer, { opacity: { to: 1 } }, 1);
			fadeIn.animate();			
		}
	},
	
	start:function(){
		if(this.hasInit){
			if(this.scroll){
				
				this.direction		= 0;
				
				if(this.behaviour=="left"){
					this.direction	= -1;
				}
				
				this.scrollerController=new PeriodicalExecuter(this.scrollMe.bind(this), this.scrollerInterval);				
			}
		}
	},
	
	stop:function()
	{
		if(this.hasInit){	
			if(this.scroll){
				this.scrollerController.stop();
			}
		}		
	},
	
	checkStop:function(stopMe){
		if(stopMe){
			this.stop();
		} else {
			this.start();
		}
	},
	
	scrollMe:function(e){	
		
		if(this.scrollerController)	this.scrollerController.stop();	
		
		var itemsCount=this.items.length;

		var distanceProcent=0;
		if(this.behaviour=="normal"){
			distanceProcent=((this.distance * 100) / this.parentCenter) / 100		
			this.scrollValue=Math.round(this.maxLeft * distanceProcent) * this.direction;			
		} else {
			if(this.behaviour=="left"){
				this.direction		= -1;	
				this.scrollValue	= this.defaultScrollValue * this.direction;			
			}
		}
					

		/*
			Stap 1, alle elementen positioneren
		*/		
		for(var i=0;i<itemsCount;i++)
		{		
			var el=this.items[i];					
			var newLeft=(parseInt(el.style.left) + this.scrollValue) ;			

			if(!isNaN(newLeft)){
				el.style.left=newLeft + "px";				
			}
									
			this.items[i]=el;			
		}
		
		/*
			Stap 2, kijken welke kant we op gaan en daarna de boundries opzoeken
		*/
		
		// naar links
		if(this.direction==-1){
			var el=this.items[0];	
			if(parseInt(el.style.left) < (el.getWidth()*-1))
			{
				var lastEL=this.items[this.items.length-1];	
				el.style.left=parseInt(lastEL.style.left) + lastEL.getWidth() + "px";
				
				var items=Array();
				for(var i=1;i<itemsCount;i++){
					var el1=this.items[i];
					items.push(el1);	
				}
				
				items.push(el);					
				this.items=null;
				this.items=items;
			}			
		} else {
			
			// naar rechts
			if(this.direction==1){	
				
				var loopme=true;
		
				/*
					de loop is even nodig om na het verplaatsen van de laatste element nog even te kijken of er nog ruimte is
					aan de linker kant, zo ja, dan moet er weer een element verplaatst worden naar voren
				*/				
				while(loopme){
					
					var el=this.items[this.items.length-1];	
					
					if(parseInt(el.style.left) > this.elWrapper.getWidth()){
						var firstEL=this.items[0];						
						var newL=parseInt(firstEL.style.left) - el.getWidth();
						
						el.style.left=newL + "px";
	
						var items=Array();
						items.push(el);
						
						for(var i=0;i<(itemsCount-1);i++){
							var el1=this.items[i];
							items.push(el1);	
						}
						this.items=null;
						this.items=items;				
					}
					
					// check of er nog ruimte is voor de 1e element
					if(newL>0) {
						loopme=true;
					} else {
						loopme=false;
					}
					
				}
			}
		}	
		
		this.scrollerController=new PeriodicalExecuter(this.scrollMe.bind(this), this.scrollerInterval);			
	}
});

/*
	ImageQue.js V2 
	
	Fransjo Leihitu
	
	Class om foto's te preloaden. Vooral handig in Safari. Die laad de plaatjes te laat in en zodoende weet je dan niet de dimensies van het plaatje
	
	Zodra alle plaatjes binnen zijn, wordt functie onComplete aan geroepen. Je kan dus je eigen functie aan de onComplete function binden en heb je een callback.
	
	
*/
var ImageQue=Class.create({
	numItems:0,
	clearedItems:0,
	items:Array(),
	interval:null,
	
	initialize:function(){
	},
	
	add:function(image){
		if(typeof(image)!="undefined"){
			this.items.push(image);
		}
	},
	
	start:function(){
		this.numItems=this.items.length;
		this.clearedItems=this.numItems;
		
		if(this.numItems>0)
		{
			this.interval=new PeriodicalExecuter(this.checkImages.bind(this), 0.5);			
		} else {
			this.onComplete();
		}		
	},
	
	checkImages:function(){
		
		var notCleared=new Array();
		
		for(var i=0;i<this.numItems;i++){			
			
			var el=this.items[i];			
			if(el){
				if(el.complete==false) {
					notCleared.push(el);
				} else {
					el.writeAttribute("width",el.getWidth());
					el.writeAttribute("height",el.getHeight());
					
					el.style.width=el.getWidth() + "px";
					el.style.height=el.getHeight() + "px";
				}
			}
		}
		
		this.items=notCleared;
				
		if(this.items.length<=0){
			this.interval.stop();
			this.onComplete();
		}
	},
	

	onComplete:function(){		
		// dummy function. Use this function in your own class to bind to
	}
});

showAssetLarge = function(imageprops) {

	if($('tmp_large-asset-img-container')) {
		$('tmp_large-asset-img-container').remove();
	}

	var rndm = function() {
		var chars 			= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length	= 6;
		var randomstring 	= '';

		for (var i = 0; i < string_length; i++) {
			var rnum 		= Math.floor(Math.random() * chars.length);
			randomstring	+= chars.substring(rnum, rnum + 1);
		}

		return randomstring;
	}

	var url  			= '?do=image&url=' + imageprops.url + '&w=' + imageprops.width + '&h=' + imageprops.height + '&type=' + imageprops.type + '&rnd=' + rndm();
	var divContainer	= document.createElement('DIV');
	var imageLoader 	= document.createElement('IMG');
	var center 			= document.createElement('SPAN');
	var image 			= document.createElement('IMG');

	divContainer.id			= 'tmp_large-asset-img-container';
	image.src 				= url;
	imageLoader.className	= 'load';
	imageLoader.src 		= './Frontend/img/ajax-loader_large.gif';

	center.appendChild(imageLoader);
	divContainer.appendChild(center);
	$(imageprops.target).appendChild(divContainer);

	var imageOnload = function() {
		try {
			var imgWidth = image.width;

			if(imageprops.maxwidth){
				if(imgWidth <= imageprops.maxwidth){
					image.className = 'image_border right';
				}
			}
			$(divContainer).down('img.load').remove();
			center.appendChild(image);
		} catch(e) {}
	}

	image.onload = imageOnload;
}

setImageName = function(name){
	$('img_name').update(name);
}