
var culture = 'English (United States)';
var serverPath = self.location.protocol + '//' + self.location.host;
var languageId = 0;
var callbackUrl = self.location.href;
var timeZoneOffset;
var isMobileDevice = '0';


$(function() {
	timeZoneOffset = readCookie('TimeZoneOffset');
	var currentTimeZoneOffset = -(new Date()).getTimezoneOffset();

	if (timeZoneOffset !== null) {
		if (currentTimeZoneOffset != timeZoneOffset) {
			timeZoneOffset = currentTimeZoneOffset;
			createCookie('TimeZoneOffset', timeZoneOffset, 365);
		}
	}
	else {
		timeZoneOffset = currentTimeZoneOffset;
		createCookie('TimeZoneOffset', timeZoneOffset, 365);
	}

	var preload;

	preload = new Image();
	preload.src = 'http://images.mindz.com/css/images/loader/center.gif';
	preload = new Image();
	preload.src = 'http://images.mindz.com/css/images/loader/right.png';
	preload = new Image();
	preload.src = 'http://images.mindz.com/css/images/loader/left.png';

	jQuery.fn.fadeIn = function(speed, callback) {
		return this.animate.apply(this, [{ opacity: 'show' }, speed, function() {
			if (jQuery.browser.msie) {
				this.style.removeAttribute('filter');
			}
			if (jQuery.isFunction(callback)) {
				callback.call(this, null);
			}
		} ]);
	};

	jQuery.fn.fadeOut = function(speed, callback) {
		return this.animate.apply(this, [{ opacity: 'hide' }, speed, function() {
			if (jQuery.browser.msie) {
				this.style.removeAttribute('filter');
			}
			if (jQuery.isFunction(callback)) {
				callback.call(this, null);
			}
		} ]);
	};

	jQuery.fn.fadeTo = function(speed, to, callback) {
		return this.animate.apply(this, [{ opacity: to }, speed, function() {
			if (to == 1 && jQuery.browser.msie) {
				this.style.removeAttribute('filter');
			}
			if (jQuery.isFunction(callback)) {
				callback.call(this, null);
			}
		} ]);
	};
	
	$.ajaxSetup({
		error: function(xmlHttpRequest, textStatus, errorThrown) {
			ShowRetryButton(this, xmlHttpRequest);
		},
		timeout: 100000
	});	
});

function GenerateUrlFriendlyName(input) {
	return input.replace(/[^a-zA-Z0-9-$_*(),]/g, '_');
}

function GetPopup(popup, webservice, options) {
	if (typeof(options) == 'undefined') {
		options = { languageId : 0 };
	}
	else if (typeof(options.languageId) == 'undefined') {
		options.languageId = 0;
	}

	if (eval('typeof(Show' + popup + ')') == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/' + webservice + '.asmx/Get' + popup + 'Html?callback=?',
			{ languageId: options.languageId, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				eval('Show' + popup + '(options)');
			});
	}
	else {
		eval('Show' + popup + '(options)');
	}
}

function ShowPopup(link, path, popup, options) {
	var showLoader = (link && link.tagName == 'A');

	if (showLoader) {
		// Show loader image
		var originalLink = $(link);
		var replacementLink = $('<span style="position: relative;"><img style="position: absolute; left: 0px" src="http://images.mindz.com/css/images/loader/left.png" /><img style="position: absolute; right: 0px" src="http://images.mindz.com/css/images/loader/right.png" /></span>');
		replacementLink.css('display', 'inline-block').css('position', 'relative').css('top', '0px').css('background', 'url(http://images.mindz.com/css/images/loader/center.gif) no-repeat top').css('width', originalLink.width() + 'px').css('height', originalLink.height() + 'px');
		replacementLink.addClass(originalLink.attr('class'));
		
		originalLink.hide();
		originalLink.after(replacementLink);
	}
	if (typeof(options) == 'undefined') {
		options = { languageId: 0 };
	}
	else if (typeof(options.languageId) == 'undefined') {
		options.languageId = 0;
	}

	$.getJSON('http://www.frisinjehoofd.nl/WebServices/UserControlWS.asmx/GetUserControlHtml?callback=?', {
		userControl: path + '/' + popup,
		languageId: options.languageId,
		parameters: JSON.stringify(options),
		form: 'json'
	},
	function(result) {
		var $resultContainer = $('#' + popup + 'ResultContainer');
		if ($resultContainer.length > 0) {
			$resultContainer.remove();
		}
		$('<div id="' + popup + 'ResultContainer">' + result + '</div>').appendTo($('body'));
		eval('Show' + popup + '(options)');
		if (showLoader) {
			// Hide loader image
			replacementLink.remove();
			originalLink.show();
		}
	});
}

// Params parameter properties:
// ----------------------------------------------------
// PageItemId:			long	| Unique Id every control receives	| default: current time in milliseconds
// And you can add all your own kay/value pairs

// Options parameter properties:
// ----------------------------------------------------
// ControlLanguageId:	int		| Language Id of the language the control should have					| default: 0
// FadeTarget:			bool	| Whether to fade out the target when loading and fade in when finished	| default: false
// SlideDown:			bool	| Whether to hide the control when loading and slide down when finished	| default: false
// ReplaceTarget:		bool	| Whether to replace the target control with the loaded control			| default: false
// ClearTarget:			bool	| Whether to clear the contents of the target or append to the end		| default: false

// OnShowControlComplete event and callback properties:
// ----------------------------------------------------
// UniqueId:			long	| Unique Id every control receives
// Control:				jQuery	| The jQuery object that was created and added to the DOM
function ShowPageItem(path, control, params, options, target, callback) {
	if (typeof(params.PageItemId) == 'undefined') {
		return;
	}
	params.UniqueId = params.PageItemId;		
	ShowControlNew(path, control, params, options, target, callback);	
}

// Params parameter properties:
// ----------------------------------------------------
// UniqueId:			long	| Unique Id every control receives	| default: current time in milliseconds
// And you can add all your own kay/value pairs

// Options parameter properties:
// ----------------------------------------------------
// ControlLanguageId:	int		| Language Id of the language the control should have					| default: 0
// FadeTarget:			bool	| Whether to fade out the target when loading and fade in when finished	| default: false
// SlideDown:			bool	| Whether to hide the control when loading and slide down when finished	| default: false
// ReplaceTarget:		bool	| Whether to replace the target control with the loaded control			| default: false
// ClearTarget:			bool	| Whether to clear the contents of the target or append to the end		| default: false
// InsertBefore:		bool	| Whether to insert the control before the target or append to the end	| default: false
// InsertAfter:			bool	| Whether to insert the control after the target or append to the end	| default: false

// OnShowControlComplete event and callback properties:
// ----------------------------------------------------
// UniqueId:			long	| Unique Id every control receives
// Control:				jQuery	| The jQuery object that was created and added to the DOM
function ShowControlNew(path, control, params, options, target, callback) {
	if (options.FadeTarget === true) {
		target.fadeTo('fast', 0.4);
	}
	if (typeof(options) == 'undefined') {
		options = { ControlLanguageId: 0 };
	}
	else if (typeof(options.ControlLanguageId) == 'undefined') {
		options.ControlLanguageId = 0;
	}
	if (typeof(params.UniqueId) == 'undefined') {
		params.UniqueId = Math.abs(new Date().getTime());
	}

	$.post('http://www.frisinjehoofd.nl/WebServices/UserControlWS.asmx/GetUserControlHtml?form=json', {
		userControl: path + '/' + control,
		languageId: options.ControlLanguageId,
		parameters: JSON.stringify(params)
	},
	function(result) {
		var $control = $(result);
		if (options.SlideDown === true) {
			$control.css('display', 'none');
		}
		if (options.ReplaceTarget === true) {
			target.replaceWith($control);
		}
		else if (options.ClearTarget === true) {
			target.html($control);
		}
		else if (options.InsertBefore === true) {
			$control.insertBefore(target);
		}
		else if (options.InsertAfter === true) {
			$control.insertAfter(target);
		}
		else {
			target.append($control);
		}
		if (options.SlideDown === true) {
			$control.first().slideDown('slow', function() {
				ShowControlNewFinished($control.first(), control, params, options, callback);
			});
		}
		else if (options.FadeTarget === true) {
			target.fadeTo('fast', 1, function() {
				ShowControlNewFinished($control.first(), control, params, options, callback);
			});
		}
		else {
			ShowControlNewFinished($control.first(), control, params, options, callback);
		}
	}, 'json');
};

function ShowControlNewFinished($control, control, params, options, callback) {
	$('body').trigger({
		type: 'OnShowControlComplete',
		UniqueId: params.UniqueId,
		Control: $control
	});

	if (callback) {
		callback({
			UniqueId: params.UniqueId,
			Control: $control
		});
	}
	
	if (eval('typeof(Show' + control + '_' + params.UniqueId + ')') != 'undefined') {
		eval('Show' + control + '_' + params.UniqueId + '(options)');
	}
	else {
		window.setTimeout(function() {
			if (eval('typeof(Show' + control + '_' + params.UniqueId + ')') != 'undefined') {
				eval('Show' + control + '_' + params.UniqueId + '(options)');
			}
			else {
				window.setTimeout(function() {
					if (eval('typeof(Show' + control + '_' + params.UniqueId + ')') != 'undefined') {
						eval('Show' + control + '_' + params.UniqueId + '(options)');
					}
				}, 10000);
			}
		}, 2000);
	}
};

/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
function PageItem(pageItemId, isEditable, hasEditRights, isDeletable, hasDeleteRights) {
	var myself = this;
	
	this.qTipVisible = false;
	this.pageItemHover = false;
	this.dragging = false;

	if (pageItemId > 0 && (isEditable && hasEditRights || isDeletable && hasDeleteRights)) {
		$('#pageItem_' + pageItemId).mousemove(function() {
			PageItemHover(pageItemId, this);
			myself.pageItemHover = true;
		});
		
		$('#pageItem_' + pageItemId).mouseleave(function() {
			if (!myself.dragging) {
				if (!myself.qtipVisible) {
					PageItemUnHover(pageItemId, this);
				}
			}
			myself.pageItemHover = false;
		});
		
		
		$('#pageItemSettingsLabel_' + pageItemId).qtip({
			content: $('#pageItemLinkSystemContainer_' + pageItemId).html(),
			position: {
				corner: {
					target: 'bottomRight',
					tooltip: 'topRight'
				},
				adjust: {
					y: 0
				}
			},
			show: {
				when: 'click'
			},
			hide: {
				when: 'unfocus'
			},
			api: {
				beforeShow: function(e) {
					myself.qtipVisible = true;
					PageItemHover(pageItemId, this.elements.target.parent().parent());
				},
				beforeHide: function(e) {
					myself.qtipVisible = false;
					if (!myself.pageItemHover) {
						PageItemUnHover(pageItemId, this.elements.target.parent().parent());
					}
				}
			},
			style: {
				classes: {
					tooltip: 'pageItemQtip'
				}
			}
		});
	}
	
	$('#pageItem_' + pageItemId).data('PageItem', this);	
}

function CreatePageItem(type, pageColumnId, profileKey) {
	//$.getJSON('http://api.mindz.com/PageService.asmx/CreatePageItem?form=json&callback=?', {
	//	pageColumnId: pageColumnId,
	//	profileKey: profileKey,
	//	typeString: type
	//},
	$.post(serverPath + '/Functions/RequestProxy.aspx', {
		'request_url': 'http://api.mindz.com/PageService.asmx/CreatePageItem?form=json',
	    'pageColumnId': pageColumnId,
	    'profileKey': profileKey,
	    'typeString': type
	},
	function(data) {
		if (data == 'Error.PageItem') {
			$.growlUI('Error', 'PageItem not found');
		}
		else if (data == 'Error.Type') {
			$.growlUI('Error', 'Type not found');
		}
		else if (data == 'Error.Profile') {
			$.growlUI('Error', 'Profile not found');
		}
		else {
			$('body').trigger({
				type: 'OnPageItemCreated',
				PageItemId: Number(data)
			});
			$('body').trigger({
				type: 'On' + type + 'Created',
				PageItemId: Number(data)
			});
		}
	}, "json");
}

function EditPageItem(type, pageItemId) {
	ShowPopup(this, 'PageItem/' + type, 'Set' + type, { 'PageItemId': pageItemId });
}

function DeletePageItem(type, pageItemId) {
	ShowPopup(this, 'PageItem', 'DeletePageItem', { 'PageItemId': pageItemId });
}

function SavePageItemSettings(type, pageItemId, settings, parentSelector) {
	//$.getJSON('http://api.mindz.com/PageService.asmx/SetSettings?form=json&callback=?', {
	//	pageItemId: pageItemId,
	//	settings: JSON.stringify(settings)
	//},
	$.post(serverPath + '/Functions/RequestProxy.aspx', {
		request_url: 'http://api.mindz.com/PageService.asmx/SetSettings?form=json',
	    pageItemId: pageItemId,
	    settings: JSON.stringify(settings)
	},
	function(data) {
		if (data == "Error.PageItem") {
			$.growlUI('Error', 'PageItem not found');
		}
		else if (data == "OK") {
			$.growlUI('Bedankt', 'De instellingen zijn opgeslagen');
			if (parentSelector !== '') {
				ShowPageItem('PageItem/' + type, type, settings, { SlideDown: true }, $(parentSelector), null);
			}
			else {
				ShowPageItem('PageItem/' + type, type, settings, { ReplaceTarget: true }, $('#pageItem_' + pageItemId));
			}
			$('body').trigger({
				type: 'OnPageItemSettingsSaved',
				PageItemId: pageItemId
			});				
			$('body').trigger({
				type: 'On' + type + 'SettingsSaved',
				PageItemId: pageItemId
			});				
		}
		else {
			$.growlUI('Error', data);
		}
	}, "json");
}

function PageItemHover(pageItemId, element) {
	$(element).addClass('pageItemContainerHover');
	$(element).find('.headerContainer').addClass('headerContainerHover');
	$(element).find('#pageItemSettingsLabel_' + pageItemId).show();
}

function PageItemUnHover(pageItemId, element) {
	$(element).removeClass('pageItemContainerHover');
	$(element).find('.headerContainer').removeClass('headerContainerHover');
	$(element).find('#pageItemSettingsLabel_' + pageItemId).hide();
}
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/


function ShowControl(path, control, options, target, slideDown, clear, replace) {
	if (!slideDown) {
		target.fadeTo('fast', 0.4);
	}
	if (typeof(options) == 'undefined') {
		options = { languageId: 0 };
	}
	else if (typeof(options.languageId) == 'undefined') {
		options.languageId = 0;
	}
	if (typeof(options.UniqueId) == 'undefined') {
		options.UniqueId = Math.abs(new Date().getTime());
	}

	$.post('http://www.frisinjehoofd.nl/WebServices/UserControlWS.asmx/GetUserControlHtml?form=json', {
		userControl: path + '/' + control,
		languageId: options.languageId,
		parameters: JSON.stringify(options)
	},
	function(result) {
		var $control = $(result);
		if (slideDown) {
			$control.css('display', 'none');
		}
		if (replace) {
			target.replaceWith($control);
		}
		else if (clear) {
			target.html($control);
		}
		else {
			target.append($control);
		}
		if (slideDown) {
			$control.slideDown('slow');
		}
		else {
			target.fadeTo('fast', 1);
		}

		if (eval('typeof(Show' + control + options.UniqueId + ')') != 'undefined') {
			eval('Show' + control + options.UniqueId + '(options)');
		}
		else {
			window.setTimeout(function() {
				if (eval('typeof(Show' + control + options.UniqueId + ')') != 'undefined') {
					eval('Show' + control + options.UniqueId + '(options)');
				}
				else {
					window.setTimeout(function() {
						if (eval('typeof(Show' + control + options.UniqueId + ')') != 'undefined') {
							eval('Show' + control + options.UniqueId + '(options)');
						}
					}, 10000);
				}
			}, 2000);
		}
	}, 'json');
}

function GetMappingPopup(options) {
	if (typeof(ShowMapping) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/RegisterWS.asmx/GetMappingHtml?callback=?',
			{ languageId: languageId, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				if (options) {
					ShowMapping(options);
				}
				else {
					ShowMapping({});
				}
			});
	}
	else {
		if (options) {
			ShowMapping(options);
		}
		else {
			ShowMapping({});
		}
	}
}

function GetInviteToPlazaPopup(options) {
	if (typeof(ShowInviteToPlaza) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/CircleWS.asmx/GetInviteToPlazaHtml?callback=?',
			{ languageId: languageId, plazaId: options.plazaId, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				ShowInviteToPlaza(options);
			});
	}
	else {
		ShowInviteToPlaza(options);
	}
}

function GetLostPasswordPopup(emailAddress) {
	if (typeof(ShowLostPassword) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/RegisterWS.asmx/GetLostPasswordHtml?callback=?',
			{ languageId: languageId, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				ShowLostPassword(emailAddress);
			});
	}
	else {
		ShowLostPassword(emailAddress);
	}
}

function GetMapChoicePopup(options) {
	if (typeof(ShowMapChoice) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/RegisterWS.asmx/GetMapChoiceHtml?callback=?',
			{ languageId: languageId, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				if (options) {
					ShowMapChoice(options);
				}
				else {
					ShowMapChoice({});
				}
			});
	}
	else {
		if (options) {
			ShowMapChoice(options);
		}
		else {
			ShowMapChoice({});
		}
	}
}

function GetRegisterPopup(options) {
	if (typeof(ShowRegister) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/RegisterWS.asmx/GetRegisterHtml?callback=?',
			{ languageId: languageId, callbackUrl: callbackUrl, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				if (options) {
					ShowRegister(options);
				}
				else {
					ShowRegister({});
				}
			});
	}
	else {
		if (options) {
			ShowRegister(options);
		}
		else {
			ShowRegister({});
		}
	}
}

function GetLoginPopup(options) {
	if (typeof(ShowLogin) == 'undefined') {
		$.getJSON('http://www.frisinjehoofd.nl/WebServices/RegisterWS.asmx/GetLoginHtml?callback=?',
			{ languageId: languageId, callbackUrl: callbackUrl, form: 'json' },
			function(result) {
				$(result).appendTo($('body'));
				if (options) {
					ShowLogin(options);
				}
				else {
					ShowLogin({});
				}
			});
	}
	else {
		if (options) {
			ShowLogin(options);
		}
		else {
			ShowLogin({});
		}
	}
}

function createCookie(name,value,days) {
	var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else { expires = ""; }
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)===' ') { c = c.substring(1,c.length); }
		if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

jQuery.IsReservedWord = function(word) {
	if (word.toLowerCase() == 'blog' || word.toLowerCase() == 'blogs' || word.toLowerCase() == 'events' || word.toLowerCase() == 'plazas' || word.toLowerCase() == 'wiki' || word.toLowerCase() == 'network' || word.toLowerCase() == 'about' || word.toLowerCase() == 'aggregator' || word.toLowerCase() == 'qna' || word.toLowerCase() == 'polls' || word.toLowerCase() == 'magazine' || word.toLowerCase() == 'circles' || word.toLowerCase() == 'dashboard' || word.toLowerCase() == 'dialogues' || word.toLowerCase() == 'forums') {
		return true;
	}
	else {
		return false;
	}
};

function ShowRetryButton(ajax, xmlHttpRequest) {
	$retryContainer = $('<div class="retryContainer"></div>');
	$retryContainer.css('padding', '10px');
	$retryContainer.css('width', '300px');
	$retryContainer.css('background-color', '#fff');
	$retryContainer.css('border', 'solid 1px #000');
	$retryContainer.css('top', '30px');
	$retryContainer.css('right', '30px');
	$retryContainer.css('position', 'fixed');
	$retryContainer.css('z-index', '9999999');
			
	$retryButton = $('<input type="button" />');
	$retryButton.attr('value', 'De aanroep is mislukt\r\nProbeer opnieuw...');
	$retryButton.css('width', '300px');
	$retryButton.css('height', '150px');
	$retryButton.css('font-size', '24px');
	$retryButton.click(function() {
		$.ajax({
			url: ajax.url.replace(ajax.data, ''),
			dataType: ajax.dataType,
			data: ajax.data,
			success: ajax.success
		});

		$('.retryContainer').remove();
	});

	$retryDetailsLink = $('<a href="javascript:" onclick="$(\'.retryDetailsContainer\').slideToggle();" class="retryDetailsLink">Details</a>');
	$retryCloseLink = $('&nbsp;<a href="javascript:" onclick="$(\'.retryContainer\').remove();" class="retryCloseLink">Sluiten</a>');

	$retryDetailsContainer = $('<div class="retryDetailsContainer"></div>');
	$retryDetailsContainer.css('padding-top', '10px');
	$retryDetailsContainer.hide();

	$retryDetailsUrlLabel = $('<span>Url:</span><br />');
	$retryDetailsUrlLabel.css('font-weight', 'bold');
	$retryDetailsUrlTextBox = $('<input type="text" class="retryDetailsUrlTextBox" value="' + ajax.url.replace(ajax.data, '') + '" />');
	$retryDetailsUrlTextBox.css('width', '295px');

	$retryDetailsDataLabel = $('<span>Data:</span><br />');
	$retryDetailsDataLabel.css('font-weight', 'bold');
	$retryDetailsDataTextBox = $('<input type="text" class="retryDetailsDataTextBox" value="' + ajax.data + '" />');
	$retryDetailsDataTextBox.css('width', '295px');

	$retryDetailsTraceLabel = $('<span>Stacktrace:</span><br />');
	$retryDetailsTraceLabel.css('font-weight', 'bold');
	$retryDetailsTraceTextArea = $('<textarea class="retryDetailsTextArea"></textarea>');
	$retryDetailsTraceTextArea.css('width', '295px');
	$retryDetailsTraceTextArea.css('height', '150px');
	$retryDetailsTraceTextArea.html(xmlHttpRequest.responseText);

	$retryDetailsContainer.append($retryDetailsUrlLabel);
	$retryDetailsContainer.append($retryDetailsUrlTextBox);
	$retryDetailsContainer.append($retryDetailsDataLabel);
	$retryDetailsContainer.append($retryDetailsDataTextBox);
	$retryDetailsContainer.append($retryDetailsTraceLabel);
	$retryDetailsContainer.append($retryDetailsTraceTextArea);
	
	$retryContainer.append($retryButton);
	$retryContainer.append($retryDetailsLink);
	$retryContainer.append($retryCloseLink);
	$retryContainer.append($retryDetailsContainer);

	$('body').append($retryContainer);
};

function urlEncodeCharacter(c) {
	return '%' + c.charCodeAt(0).toString(16);
};

function urlDecodeCharacter(str, c) {
	return String.fromCharCode(parseInt(c, 16));
};

function urlEncode(s) {
	return encodeURIComponent(s).replace(/\%20/g, '+').replace(/[!'()*~]/g, urlEncodeCharacter);
};

function urlDecode(s) {
	return decodeURIComponent(s.replace(/\+/g, '%20')).replace(/\%([0-9a-f]{2})/g, urlDecodeCharacter);
};

Number.prototype.pad = function(char, length) {
	return ('' + this).pad(char, length);
};
String.prototype.pad = function(char, length) {
	var str = '' + this;
	while (str.length < length) {
		str = char + str;
	}

	return str;
};
Date.prototype.getDateString = function() {
	return this.getUTCFullYear() + '-' + (this.getUTCMonth() + 1).pad('0', 2) + '-' + this.getUTCDate().pad('0', 2) + 'T' + this.getUTCHours().pad('0', 2) + ':' + this.getUTCMinutes().pad('0', 2) + 'Z';
};

var CKE = {
	Create : function(textId, toolbar, height, skin) {
		if (isMobileDevice == '0') {
			if (CKEDITOR.instances[textId]) {
				CKEDITOR.instances[id].destroy();
				delete CKEDITOR.instances[textId];
			}
			var currentCKEditor = CKEDITOR.replace(textId, {
				toolbar: toolbar,
				height: height,
				skin: skin
			});
			return currentCKEditor;
		}
	},

	Delete : function(id) {
		if (isMobileDevice == '0') {
			if (CKEDITOR.instances[id]) {
				CKEDITOR.instances[id].destroy();
				delete CKEDITOR.instances[id];
			}
		}
	},

	Get : function(id) {
		if (isMobileDevice == '1') {
			return $('#' + id).val();
		}
		else {
			var editor = CKEDITOR.instances[id];
			if (editor) {
				return editor.getData();
			}
			else {
				return $('#' + id).val();
			}
		}
	},

	Set : function(id, value) {
		if (isMobileDevice == '1') {
			$('#' + id).val(value);
		}
		else {
			var editor = CKEDITOR.instances[id];
			if (editor) {
				editor.setData(value);
			}
			else {
				$('#' + id).val(value);
			}
		}
	}
};
