//Load the CSM Global Styles
angular.module('sn.$sp').run(function($rootScope){
	jQuery('head').append('<link rel="stylesheet" type="text/css" href="/styles/scss/csm-styles.scss?portal_id=' + $rootScope.portal.sys_id + '">');
	jQuery('head').append('<link rel="stylesheet" type="text/css" href="/styles/scss/csm-unified-header-footer-styles.scss?portal_id=' + $rootScope.portal.sys_id + '">');
});

//Utility Object
var csm_util = csm_util || {};

//ROT47 encription/decription along with URI + base64 encoding/decoding
csm_util.enigmia = (function(){

	/////public members
	return {
		encode : encode,
		decode : decode,
		type: 'csm_util'
	};

	/////private members
	function magic(text, map) {
		// Generic ROT-n algorithm for keycodes in MAP.
		var s = '',i, j, c, len = map.length;
		for(i = 0; i < text.length; i++) {
			c = text.charAt(i);
			j = map.indexOf(c);
			if (j >= 0) {
				c = map.charAt((j + len / 2) % len);
			}
			s = s + c;
		}
		return s;
	}

	function ROT47(text) {
		// Hides all ASCII-characters from 33 ("!") to 126 ("~").  Hence can be used
		// to obfuscate virtually any text, including URLs and emails.
		var value = '';
		value = magic(text,"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
		return value;
	}

	function encode(text){
		return btoa(encodeURIComponent(ROT47(text)));
	}
	function decode(text){
		return ROT47(decodeURIComponent(atob(text)));
	}

})();