/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/



var Utf8 = {

	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}


/**
 * msieurx kisangela functions
 * http://msieurx.net/
 */
function mxSelectNode(node){
	return $(node)
}

function toggleNode(node){
  if($(node).style.display == 'none')
  {
    $(node).style.display = 'block'
  }
  else if ($(node).style.display == 'block')
	{
		$(node).style.display = 'none'
	}
	else
	{
		$(node).style.display = 'block'
	}
}

function showAdminToolBar(){
  toggleNode("kisAdminToolBar")
  toggleNode("openAdminToolBar")
  toggleNode("closeAdminToolBar")
}
function showAdminFileToolBar(){
  toggleNode("kisAdminFileToolBar")
  toggleNode("openAdminFileToolBar")
  toggleNode("closeAdminFileToolBar")
}
function verifRadios(radio_name){
  var radioType = document.getElementsByName(radio_name);
  var radio_namechecked = false;
  for (var cpt = 0 ; (cpt < radioType.length) && !radio_namechecked ; cpt++) {
    radio_namechecked = radio_namechecked || radioType[cpt].checked;
		if (radio_namechecked) {
			var chkd_value = radioType[cpt].value
		}
  }
  return chkd_value
}

function go(url){
  return window.location.replace(url)
}


/**
 * from ja_purity template
 */
function setCookie (name, value) {
  var aujourdhui = new Date() ;
  var expdate = new Date() ;
  expdate.setTime( aujourdhui.getTime() + (365*24*60*60*1000 ))
  document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() ;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
    end = dc.length;
	}
  return unescape(dc.substring(begin + prefix.length, end));
}

