


// if(!flex.debug){
// 	function alert(msg, msgtype){
// 		if(!msgtype){
// 			msgtype = "error";
// 		};
// 		$('dialog_img') ? $('dialog_img').remove() : 0;
// 		$('dialog_input') ? $('dialog_input').remove() : 0;
// 		$('dialog_title').innerHTML = msgtype;
// 		new Insertion.Before('dialog_msg', '<img id="dialog_img" src="img/dialogs/'+msgtype+'.png"/>');
// 		$('dialog_msg').innerHTML = msg;
// 		new Insertion.After('dialog_msg', '<input id="dialog_input" type="button" class="formbutton" onclick="flexCore.hideDialog(\'dialogContainer\')" value="OK" />');
// 		$('dialog').style.width = '350px';
// 		$('dialog').style.height = '130px';
// 		var dBorder = flexCorners.htmlGen.create({corner:15, border:10, opacity:0.6});
// 		dBorder.render('dialog');
// 		$('overlay').show();
// 		flexCore.center('dialogContainer');
// 		flexCore.disableSelection('dialog');
// // 		new Draggable('dialog', {starteffect:false, endeffect:false});
// 	}
// }

var flexCore = {

	actMaintab: false,

 	/**
	* Holds true if browser is MSIE, otherwise false
	*/
	isMSIE: navigator.appName == "Microsoft Internet Explorer" ? true : false,

	/**
	* Holds true if browser is Firefox (Mozilla)
		*/
	isFF: !document.all && document.getElementById && !this.isOpera,

	/**
	* Holds true if browser is Opera, otherwise false
	*/
	isOpera: navigator.appName == "Opera" ? true : false,

//  loads required JS files( FOR DEVELOPMENT USE ONLY! MUST BE REMOVED BEFORE RELEASE!!)
 	load: function() {
 		if((typeof Prototype=='undefined') ||
 		(typeof Element == 'undefined') ||
 		(typeof Element.Methods=='undefined') ||
 		parseFloat(Prototype.Version.split(".")[0] + "." +
 		Prototype.Version.split(".")[1]) < 1.5)
 		throw("Flex requires the Prototype JavaScript framework >= 1.5.0");
 		$A(document.getElementsByTagName("script")).findAll( function(s) {
 			return (s.src && s.src.match(/flexdev\.js(\?.*)?$/))
 		}).each( function(s) {
 				var includes = s.src.match(/\?.*load=([a-z,]*)/);
				(includes ? includes[1] : 'rugby,admin,jax,corners,effects,dragdrop,controls,auth,cms,editor,tablekit,colourpick,swfobject,flexupload,upload').split(',').each(
				function(include) { flexCore.require(flex.webPath+'/inc/js/'+include+'.js') });
 		});
 	},

  	initExport: function(){
		if(!this.isMSIE){
			try{
				$('nav').select('[class="ITVBTN"]').each(function(element) {
					$S(element).margin = '2px -30px 0px';
				});
			}catch(e){}
		};
	},

 	init: function(){
// 		flexCore.initTooltips(); //tooltips temp removed.

		flexAdmin.initMenu();
		flexCore.goHome();
	},

//  	initTooltips: function(){
// 		if(!flex.helpEnabled){
// 			return;
// 		} else {
// 			$$('*').findAll(function(node){
// 				return node.getAttribute('title');
// 			}).each(function(node){
// 				new Tooltip(node,node.title);
// 				node.removeAttribute('title');
// 			});
// 		}
// 	},
	debug: function(e, t, php) {
		if(flex.debug && window.console){
			if(!php){
				flexCore.debug_(e, t);
			}else {
				e = flexCore.PHP_Unserialize(e);
				e.each(function(i) {
					flexCore.debug_(i, t);
				});
			}
		}
	},

 	debug_: function(e, t){
		if(t == 'err'){
			console.error(e);
		} else if(t == 'warn'){
			console.warn(e);
		} else if(t == 'info'){
			console.info(e);
		} else {
			console.log(e);
		}
	},

	initUpload: function(callback){
		flxu = new flexUpload({
			allowed_filetypes : "*.png;*.jpg;*.gif;*.jpeg;",
			allowed_filetypes_description : "Image Files...",
			flash_loaded_callback : 'flxu.flashLoaded',
			// 		upload_file_queued_callback : "flxUploader.fileQueued",
			upload_file_start_callback : 'flxUploader.uploadFileStart',
			upload_progress_callback : 'flxUploader.uploadProgress',
			upload_file_complete_callback : 'flxUploader.uploadFileComplete',
			upload_file_cancel_callback : 'flxUploader.uploadFileCancelled',
			upload_queue_complete_callback : callback,
			upload_error_callback : 'flxUploader.uploadError',
			upload_cancel_callback : 'flxUploader.uploadCancel',
			auto_upload : true
		});
	},
	//Omniture click tracking Code
 	omniTrack: function(str){
		try{
			s.pageName=str;
			void(s.t());
		}catch(e){
			flexCore.debug('Omnitrack: '+e, 'warn')
		}
	},
 	//End Omniture click tracking Code

 	setLang: function(lng){
		if(Cookie.get('flx_lng') != lng){
			Cookie.set('flx_lng', lng, 360);
			flexCore.goHome();
		}
	},

 	clearInput: function(el){
		el = $(el)
		el.onfocus = function(){
			if (el._cleared) return;
			el.clear();
			el._cleared = true;
		}
	},

	PHP_Unserialize: function(input){
		var result = flexCore.PHP_Unserialize_(input);
		return result[0];
	},


    /**
 * Function which performs the actual unserializing
 *
 * @param string input Input to parse
	*/
	PHP_Unserialize_: function(input){
		var length = 0;

		switch (input.charAt(0)) {
				/**
			* Array
				*/
			case 'a':
					length = flexCore.PHP_Unserialize_GetLength(input);
			input  = input.substr(String(length).length + 4);

			var arr   = new Array();
			var key   = null;
			var value = null;

			for (var i=0; i<length; ++i) {
				key   = flexCore.PHP_Unserialize_(input);
				input = key[1];

				value = flexCore.PHP_Unserialize_(input);
				input = value[1];

				arr[key[0]] = value[0];
			}

			input = input.substr(1);
			return [arr, input];
			break;

				/**
			* Objects
				*/
			case 'O':
					length = flexCore.PHP_Unserialize_GetLength(input);
			var classname = String(input.substr(String(length).length + 4, length));

			input  = input.substr(String(length).length + 6 + length);
			var numProperties = Number(input.substring(0, input.indexOf(':')))
					input = input.substr(String(numProperties).length + 2);

					var obj      = new Object();
					var property = null;
					var value    = null;

					for (var i=0; i<numProperties; ++i) {
						key   = flexCore.PHP_Unserialize_(input);
						input = key[1];

						// Handle private/protected
						key[0] = key[0].replace(new RegExp('^\x00' + classname + '\x00'), '');
						key[0] = key[0].replace(new RegExp('^\x00\\*\x00'), '');

						value = flexCore.PHP_Unserialize_(input);
						input = value[1];

						obj[key[0]] = value[0];
					}

					input = input.substr(1);
					return [obj, input];
					break;

				/**
					* Strings
				*/
			case 's':
					length = flexCore.PHP_Unserialize_GetLength(input);
			return [String(input.substr(String(length).length + 4, length)), input.substr(String(length).length + 6 + length)];
			break;

				/**
			* Integers and doubles
				*/
			case 'i':
			case 'd':
					var num = Number(input.substring(2, input.indexOf(';')));
			return [num, input.substr(String(num).length + 3)];
			break;

				/**
			* Booleans
				*/
			case 'b':
					var bool = (input.substr(2, 1) == 1);
			return [bool, input.substr(4)];
			break;

				/**
			* Null
				*/
			case 'N':
					return [null, input.substr(2)];
			break;

				/**
			* Unsupported
				*/
			case 'o':
			case 'r':
			case 'C':
			case 'R':
			case 'U':
					alert('Error: Unsupported PHP data type found!');

				/**
			* Error
				*/
			default:
					return [null, null];
			break;
		}
	},
    /**
 * Returns length of strings/arrays etc
 *
 * @param string input Input to parse
	*/
	PHP_Unserialize_GetLength: function(input){
		input = input.substring(2);
		var length = Number(input.substr(0, input.indexOf(':')));
		return length;
	},
		/**
	* Trims whitespaces of the given string
	*
	* @param str String
	* @return Trimmed string
		*/
	trim: function(str) {
		return str.replace(/^\s*|\s*$/g,"");
	},

		/**
	* Determine if the given parameter is defined
	*
	* @param p Parameter
	* @return true/false dependents on definition of the parameter
		*/
	defined: function(p) {
		return typeof p == "undefined" ? false : true;
	},

		/**
	* Determine if the browser version is compatible
	*
	* @return true/false depending on compatiblity of the browser
		*/
	isBrowserCompatible: function() {
			// Validate browser and compatiblity
		if ((navigator.userAgent.indexOf('Safari') != -1 ) || !document.getElementById || !document.designMode){
				//no designMode (Safari lies)
			return false;
		}
		return true;
	},

		/**
	* Set the style attribute of the given element.
	* Private method to solve the IE bug while setting the style attribute.
	*
	* @param {DOMElement} node The element on which the style attribute will affect
	* @param {String} style Stylesheet which will be set
		*/
	_setStyleAttribute: function(node, style) {
		if(style == null) return;
		var styles = style.split(";");
		var pos;
		for(var i=0;i<styles.length;i++) {
			var attributes = styles[i].split(":");
			if(attributes.length == 2) {
				try {
					var attr = flexCore.trim(attributes[0]);
					while((pos = attr.search(/-/)) != -1) {
						var strBefore = attr.substring(0, pos);
						var strToUpperCase = attr.substring(pos + 1, pos + 2);
						var strAfter = attr.substring(pos + 2, attr.length);
						attr = strBefore + strToUpperCase.toUpperCase() + strAfter;
					}
					var value = flexCore.trim(attributes[1]).toLowerCase();
					node.style[attr] = value;
				}
				catch (e) {
					alert(e);
				}
			}
		}
	},

		/**
	* Fix's the issue while getting the attribute style on IE
	* It's return an object but we need the style string
	*
	* @private
	* @param {DOMElement} node Node element
	* @return {String} Stylesheet
		*/
	_getStyleAttribute: function(node) {
		if(this.isMSIE) {
			return node.style['cssText'].toLowerCase();
		}
		else {
			return node.getAttribute("style");
		}
	},

		/**
	* Set an attribute's value on the given node element.
	*
	* @param {DOMElement} node Node element
	* @param {String} attr Attribute which is set
	* @param {String} value Value of the attribute
		*/
	setAttribute: function(node, attr, value) {
		if(value == null || node == null || attr == null) return;
		if(attr.toLowerCase() == "style") {
			this._setStyleAttribute(node, value);
		}
		else {
			node.setAttribute(attr, value);
		}
	},

		/**
	* Removes an attribute on the given node
	*
	* @param {DOMElement} node Node element
	* @param {String} attr Attribute which will be removed
		*/
	removeAttribute: function(node, attr) {
		node.removeAttribute(attr, false);
	},

		/**
	* Get the vale of the attribute on the given node
	*
	* @param {DOMElement} node Node element
	* @param {String} attr Attribute which value will be returned
		*/
	getAttribute: function(node, attr) {
		if(node == null || attr == null) return;
		if(attr.toLowerCase() == "style") {
			return this._getStyleAttribute(node);
		}
		else {
			return node.getAttribute(attr);
		}
	},

		/**
	* Get the path out of an given url
	*
	* @param {String} url The url with is used to get the path
		*/
	getDocumentPathOfUrl: function(url) {
		var path = null;

			// if local file system, convert local url into web url
		url = url.replace(/file:\/\//gi, "file:///");
		url = url.replace(/\\/gi, "\/");
		var pos = url.lastIndexOf("/");
		if(pos != -1) {
			path = url.substring(0, pos + 1);
		}
		return path;
	},

		/**
	* Get the documents url, convert local urls to web urls
	*
	* @param {DOMElement} doc Document which is used to get the url
		*/
	getDocumentUrl: function(doc) {
			// if local file system, convert local url into web url
		var url = doc.URL;
		url = url.replace(/file:\/\//gi, "file:///");
		url = url.replace(/\\/gi, "\/");
		return url;
	},

		/**
	* Find a parent node with the given name, of the given start node
	*
	* @param {String} tagName - Tag name of the node to find
	* @param {DOMElement} node - Node element
		*/
	findParentNode: function(tagName, node) {
		while (node.tagName != "HTML") {
			if (node.tagName == tagName){
				return node;
			}
			node = node.parentNode;
		}
		return null;
	},

		/**
	* Cancel the given event.
	*
	* @param e Event which will be canceled
		*/
	cancelEvent: function(e) {
		if (!e) return false;
		if (this.isMSIE) {
			e.returnValue = false;
			e.cancelBubble = true;
		} else {
			e.preventDefault();
			e.stopPropagation && e.stopPropagation();
		}
		return false;
	},

		/**
	* Converts a RGB color string to hex color string.
	*
	* @param color RGB color string
	* @param Hex color string
		*/
	toHexColor: function(color) {
		color = color.replace(/^rgb/g,'');
		color = color.replace(/\(/g,'');
		color = color.replace(/\)/g,'');
		color = color.replace(/ /g,'');
		color = color.split(',');
		var r = parseFloat(color[0]).toString(16).toUpperCase();
		var g = parseFloat(color[1]).toString(16).toUpperCase();
		var b = parseFloat(color[2]).toString(16).toUpperCase();
		if (r.length<2) { r='0'+r; }
		if (g.length<2) { g='0'+g; }
		if (b.length<2) { b='0'+b; }
		return r + g + b;
	},

		/**
	* Converts a decimal color to hex color string.
	*
	* @param Decimal color
	* @param Hex color string
		*/
	_dec_to_rgb: function(value) {
		var hex_string = "";
		for (var hexpair = 0; hexpair < 3; hexpair++) {
			var myByte = value & 0xFF;            // get low byte
			value >>= 8;                          // drop low byte
			var nybble2 = myByte & 0x0F;          // get low nybble (4 bits)
			var nybble1 = (myByte >> 4) & 0x0F;   // get high nybble
			hex_string += nybble1.toString(16);   // convert nybble to hex
			hex_string += nybble2.toString(16);   // convert nybble to hex
		}
		return hex_string.toUpperCase();
	},

		/**
	* Replace RGB color strings with hex color strings within a string.
	*
	* @param {String} str RGB String
	* @param {String} Hex color string
		*/
	replaceRGBWithHexColor: function(str) {
		if(str == null) return "";
			// find all decimal color strings
		var matcher = str.match(/rgb\([0-9 ]+,[0-9 ]+,[0-9 ]+\)/gi);
		if(matcher) {
			for(var j=0; j<matcher.length;j++) {
				var regex = eval("/" + flexCore.stringToRegex(matcher[j]) + "/gi");
					// replace the decimal color strings with hex color strings
				str = str.replace(regex, "#" + this.toHexColor(matcher[j]));
			}
		}
		return str;
	},

		/**
	* Execute the given command on the given editor
	*
	* @param n The editor's identifier
	* @param cmd Command which is execute
		*/
	execCommand: function(n, cmd, value) {
		if(typeof(value) == "undefined") value = null;

			// firefox BackColor problem fixed
		if(cmd == 'BackColor' && flexCore.isFF) cmd = 'HiliteColor';

			// firefox cut, paste and copy
		if(flexCore.isFF && (cmd == "Cut" || cmd == "Paste" || cmd == "Copy")) {
			try {
				flexEdit.getEditorWindow(n).document.execCommand(cmd, false, value);
			}
			catch(e) {
				if(confirm("Copy/Cut/Paste is not available in Mozilla and Firefox\nDo you want more information about this issue?")) {
					window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html');
				}
			}
		}

		else {
			flexEdit.getEditorWindow(n).document.execCommand(cmd, false, value);
		}
	},

		/**
	* Parse a given string to a valid regular expression
	*
	* @param {String} string String to be parsed
	* @return {RegEx} Valid regular expression
		*/
	stringToRegex: function(string) {

		string = string.replace(/\//gi, "\\/");
		string = string.replace(/\(/gi, "\\(");
		string = string.replace(/\)/gi, "\\)");
		string = string.replace(/\[/gi, "\\[");
		string = string.replace(/\]/gi, "\\]");
		string = string.replace(/\+/gi, "\\+");
		string = string.replace(/\$/gi, "\\$");
		string = string.replace(/\*/gi, "\\*");
		string = string.replace(/\?/gi, "\\?");
		string = string.replace(/\^/gi, "\\^");
		string = string.replace(/\\b/gi, "\\\\b");
		string = string.replace(/\\B/gi, "\\\\B");
		string = string.replace(/\\d/gi, "\\\\d");
		string = string.replace(/\\B/gi, "\\\\B");
		string = string.replace(/\\D/gi, "\\\\D");
		string = string.replace(/\\f/gi, "\\\\f");
		string = string.replace(/\\n/gi, "\\\\n");
		string = string.replace(/\\r/gi, "\\\\r");
		string = string.replace(/\\t/gi, "\\\\t");
		string = string.replace(/\\v/gi, "\\\\v");
		string = string.replace(/\\s/gi, "\\\\s");
		string = string.replace(/\\S/gi, "\\\\S");
		string = string.replace(/\\w/gi, "\\\\w");
		string = string.replace(/\\W/gi, "\\\\W");

		return string;
	},

		/**
	* Add an event listener
	*
	* @param obj Object on which the event will be attached
	* @param ev Kind of event
	* @param fu Function which is execute on the event
		*/
	addEvent: function(obj, ev, fu) {
		if (obj.attachEvent)
		obj.attachEvent("on" + ev, fu);
		else
			obj.addEventListener(ev, fu, false);
	},

		/**
	* Remove an event listener
	*
	* @param obj Object on which the event will be attached
	* @param ev Kind of event
	* @param fu Function which is execute on the event
		*/
	removeEvent:  function(obj, ev, fu) {
		if (obj.attachEvent)
		obj.detachEvent("on" + ev, fu);
		else
			obj.removeEventListener(ev, fu, false);
	},

		/**
	* Includes a javascript file
	*
	* @param file Javascript file path and name
		*/
	includeJS: function(file) {
		var script = document.createElement("script");
		this.setAttribute(script, "type", "text/javascript");
		this.setAttribute(script, "src", file);
		var heads = document.getElementsByTagName("head");
		for(var i=0;i<heads.length;i++) {
			heads[i].appendChild(script);
		}
		return true;
	},

		/**
	* Includes a stylesheet file
	*
	* @param file Stylesheet file path and name
		*/
	includeCSS: function(path) {
		var link = document.createElement("link");
		this.setAttribute(link, "rel", "stylesheet");
		this.setAttribute(link, "type", "text/css");
		this.setAttribute(link, "href", path);
		var heads = document.getElementsByTagName("head");
		for(var i=0;i<heads.length;i++) {
			heads[i].appendChild(link);
		}
	},

		/**
	* Get the screen position of the given element.
	*
	* @param {HTMLObject} elm1 Element which position will be calculate
	* @param {HTMLObject} elm2 Element which is the last one before calculation stops
	* @param {Object} Left and top position of the given element
		*/
	getElementPosition: function(elm1, elm2) {
		var top = 0, left = 0;
		while (elm1 && elm1 != elm2) {
			left += elm1.offsetLeft;
			top += elm1.offsetTop;
			elm1 = elm1.offsetParent;
		}
		return {left : left, top : top};
	},

		/**
	* Get the window size
	* @private
		*/
	windowSize: function() {
		if (window.innerWidth) {
			return {width: window.innerWidth, height: window.innerHeight};
		}
		else if (document.body && document.body.offsetWidth) {
			return {width: document.body.offsetWidth, height: document.body.offsetHeight};
		}
		else {
			return {width: 800, height: 600};
		}
	},

		/**
	* Initialise the Editor
	* @private
		*/
	initEditor: function() {
		var span = $("editable");

		var editid = "textarea_"+span.id;
		if (span != null) {
			try {
				$('editbutton').style.display = 'none';
				span.innerHTML = '<textarea name="text" id="'+ editid +'">'+span.innerHTML+'</textarea>';
				flexEdit.attach(editid);
			} catch (e) {
				flex.debug ? alert(e) : 0;
			}
		} else {
			alert('No Editable Content Found.')
		}
	},

	hideDialog: function (){
		$('dialogContainer').hide();
		$('overlay').hide();
		$('dialog_img') ? $('dialog_img').remove() : 0;
		$('dialog_input') ? $('dialog_input').remove() : 0;
	},

 	showLoading: function (txt){
		var el_ovr = $('overlay');
		var el_ldn = $('loading');
		var loadBorder = flexCorners.htmlGen.create({ corner:6, shadow:12, border:1});
		$('load_text').innerHTML = txt;
		el_ldn.style.position = 'absolute';
		!this.isMSIE ? loadBorder.render(el_ldn) : $S('loading').background = "#fff";
		el_ldn.style.left = flexCore.centerWithin('contentContainer')[0] - 50 + "px";
		el_ldn.style.top = flexCore.centerWithin('contentContainer')[1] + 30 + "px";
		el_ovr.show();
		el_ldn.show();
	},

	hideLoading: function (){
		Effect.Appear('content', {duration: 0.3});
		$('overlay').hide();
		$('loading').hide();
	},

 	require: function(libraryName) {
		document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
	},

 	initTopTabs: function(resp){
		$('topMenu').update(resp);
		$('topMenu').select('[class="mainBtn"]').each(function(element) {
			$(element).observe('click', function(event) {
				flexCore.catSelect(Event.element(event));
				Event.stop(event);
			});
		});
		el = $('topMenu').select('[class="mainBtn"]').first()
		flexCore.catSelect(el);
	},

 	initBotTabs: function(resp){
		$('botMenu').update(resp);
		$('botMenu').select('[class="mainBtn"]').each(function(element) {
			$(element).observe('click', function(event) {
				flexCore.catSelect(Event.element(event));
				Event.stop(event);
			});
		});
	},

 	catSelect: function(el){
		try{
//			alert('HERE');
			$('topMenu').select('[class="mainBtn active"]').each(function(element) {
				$(element).removeClassName('active');
			});
			$('botMenu').select('[class="mainBtn active"]').each(function(element) {
				$(element).removeClassName('active');
			});
		}catch(e){
			flexCore.debug('No Active Button Found', 'warn')
		};
		this.callArr = el.id.split('_');
		this.actModule = this.callArr[0];
		$(el).addClassName('active');
		$('content').update('');
		$S('content').display = 'none';
// 		$('sideContent').update('');
		$('matchsel', 'matchMenu', 'submenu').invoke('update', '');
		try{
			eval(this.callArr[0]+'.init()');
		}catch(e){
			flexCore.debug('Module has no init', 'warn')
		};
		ajaxObj.call('call=submenu&menuid='+this.callArr[1], flexCore.initSubMenu, 'Loading...');
	},

 	initSubMenu: function(resp){
		
 		el = $('submenu');
		
		el.update(resp);
		el.select('[class="subBtn"]').each(function(element) {
			!flexCore.isMSIE ? $S(element).margin = '2px -30px 0px' : 0;
			$(element).observe('click', function(event) {
				flexCore.pageSelect(Event.element(event));
				Event.stop(event);
			});
		});
		
		el.select('[class="subBtn"]').first(function(element) {
			$(element).addClassName('active');
		});
	},

 	pageSelect: function(el){
		try{
			$('submenu').select('[class="subBtn active"]').each(function(element) {
				$(element).removeClassName('active');
			});
			$('submenu').select('[class="subBtn active navactive"]').each(function(element) {
				$(element).removeClassName('active navactive');
			});
			
		}catch(e){};
		this.actPage = el.id.split('_') [0];
		matchcentre.actPage = this.actPage;
		$(el).addClassName('active');
		$('content').hide();
		ajaxObj.call('call=phppage&page='+this.actPage+'&mod='+this.actModule, 'content', 'Loading...');
	},

//  	callPage: function(page, module, arg, callback, tabid, pagename, loadtxt){
// // 		this.actMaintab ? $(this.actMaintab).className = 'inactive' : 0 ;
// 		$('content').hide();
// 		$('main_'+tabid).className = 'active';
// // 		this.actMaintab = 'main_'+tabid;
// 		!arg ? arg = '&matchid='+matchcentre.matchID : arg += '&matchid='+matchcentre.matchID;
// 		ajaxObj.call('call=phppage&page='+page+'&mod='+module+arg, callback , loadtxt);
// 	},

 	goHome: function(){
		flexCore.rebuildMenu();
		try{
			!$('login').empty() ? flexAuth.hideLogin() : 0;
		}catch(e){
			flexCore.debug(e, 'warn');
		}

	},

	rebuildMenu: function(){
		ajaxObj.call('call=menu&menu=top', flexCore.initTopTabs, false);
		ajaxObj.call('call=menu&menu=bot', flexCore.initBotTabs, false);

	},

 	renderText: function(txt, style){
		return '<img src="?call=image&amp;text='+txt+'&amp;style='+style+'" alt="'+txt+'" border="0"/>';
	},

	//very simple form validator - to be replaced
	formCheck: function(el){
		!$(el).getValue() ? $(el).className = "forminvalid" : $(el).className = "formok" ;
	},

	savedResponse: function(resp){
		!resp ? alert(resp) : alert(resp, 'info');
	},

	disableSelection: function(el){
		el = $(el);
		if (typeof el.onselectstart!="undefined"){
			el.onselectstart=function(){return false;};
		} else if (typeof el.style.MozUserSelect!="undefined"){
			el.style.MozUserSelect="none";
		} else {
			el.onmousedown=function(){return false;};
			el.style.cursor = "default";
		};
  	},

   togOpt: function(el){
	   try{
		   pel = $(el).ancestors().find(function(s) {
			   return s.id;
		   });
		   mel = $(pel.id).select('[class="curOpt"]').pluck('id').first();
		   if(mel != el){
			   try{
				   $(mel).removeClassName('curOpt');
				   Effect.toggle(mel, 'slide', {queue: {position:'front', scope: '1'}, duration:0.4} );
			   } catch(e){}
			   $(el).addClassName('curOpt');
		   }else{
			   $(el).removeClassName('curOpt');
		   }
		   Effect.toggle(el, 'slide', {queue: {position:'end', scope: '2'}, duration:0.5} );
	   }catch(e){
		   flex.debug ? alert(e) : 0 ;
	   }
   },

  	centerWithin: function(el){
		el = $(el);
		var ofsX = (Element.getDimensions(el).width / 2) + Position.cumulativeOffset(el)[0];
		var ofsY = (Element.getDimensions(el).height / 4) + Position.cumulativeOffset(el)[1];
		return [ofsX, ofsY];
	},

	center: function (element){
		try{
			element = $(element);
		}catch(e){
			return;
		};

		var my_width  = 0;
		var my_height = 0;

		if ( typeof( window.innerWidth ) == 'number' ){
			my_width  = window.innerWidth;
			my_height = window.innerHeight;
		}else if ( document.documentElement &&
		( document.documentElement.clientWidth ||
				document.documentElement.clientHeight ) ){
			my_width  = document.documentElement.clientWidth;
			my_height = document.documentElement.clientHeight;
				}
				else if ( document.body &&
				( document.body.clientWidth || document.body.clientHeight ) ){
					my_width  = document.body.clientWidth;
					my_height = document.body.clientHeight;
				};

				element.style.position = 'absolute';
				element.style.zIndex   = 10000;

				var scrollY = 0;

				if ( document.documentElement && document.documentElement.scrollTop ){
					scrollY = document.documentElement.scrollTop;
				}else if ( document.body && document.body.scrollTop ){
					scrollY = document.body.scrollTop;
				}else if ( window.pageYOffset ){
					scrollY = window.pageYOffset;
				}else if ( window.scrollY ){
					scrollY = window.scrollY;
				};

				var elementDimensions = Element.getDimensions(element);

				var setX = ( my_width  - elementDimensions.width  ) / 2;
				var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

				setX = ( setX < 0 ) ? 0 : setX;
				setY = ( setY < 0 ) ? 0 : setY;

				element.style.left = setX + "px";
				element.style.top  = setY + "px";

				element.show();
	}
};

flexCore.load();

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    };
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    };
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};



var Input = {
	initialize: function(el) {
		if(!flexCore.isOperas){
			$(el).select('[class="checkbox"]').pluck('id').each(function(element) {
				$(element).observe('mouseup', function(event) {
					Input.handle(Event.element(event));
					Event.stop(event);
				});
				if(!flexCore.isMSIE){
					$(element).observe('mousedown', function(event) {
						Input.effect(Event.element(event));
						Event.stop(event);
					});
				}

			});
		} else {
			$(el).select('[class="checkbox"]').each(function(element) {
				$(element).removeClassName('selected');
				$(element).removeClassName('checkbox');
			});
		}
	},

 	effect: function(el) {
		el = $(el.id);
		if(el.className == "checkbox") {
			el.addClassName('checkboxeffect');
		}
 	},

	handle: function(el) {
		el = $(el.id)
		selector = el.getElementsByTagName("input")[0];
		if(!flexCore.isMSIE){
			var classnames = "checkbox checkboxeffect";
		} else {
			var classnames = "checkbox";
		}
		if(el.className == classnames) {
			!flexCore.isMSIE ? el.removeClassName('checkboxeffect') : 0;
			selector.checked = true;
			el.addClassName('selected');
		} else if(el.className == "checkbox selected") {
			selector.checked = false;
			el.removeClassName('selected');
		}
 	}

};

var browserDetect = Class.create();

browserDetect.prototype = {


	initialize: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

