/*function json_form(chaine,urlservice)
  {
  if(window.XMLHttpRequest){ // Firefox 
  p= new XMLHttpRequest(); 
  p.onload = null;
  }
  else if(window.ActiveXObject) // Internet Explorer 
  p = new ActiveXObject("Microsoft.XMLHTTP"); 
  else { // XMLHttpRequest non supporté par le navigateur 
  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
  return; 
  } 
  p.open("POST",urlservice, false);
  p.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  p.send(chaine);
  status = p.status;
  if ( status != "200" ) {
  alert("arg ! mauvaise réponse http ("+ status +")");
  } else {
  var donnees =eval('('+p.responseText+')');
  return donnees;
  }
  return null;
  }
 */
function json_form(chaine, urlservice){

		var xmlhttp = false;

		/* Compilation conditionnelle d'IE */
		/*@cc_on 
		  @if (@_jscript_version >= 5)
		  try
		  {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		  }
		  catch (e)
		  {
		  try
		  {
		  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  catch (E)
		  {
		  xmlhttp = false;
		  }
		  }
		  @else
		  xmlhttp = false;
		  @end 
		  @*/

		/* on essaie de créer l'objet si ce n'est pas déjà fait */
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
		{
				try
				{
						xmlhttp = new XMLHttpRequest();
				}
				catch (e)
				{
						xmlhttp = false;
				}
		}

		xmlhttp.open("POST",urlservice, false);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send(chaine);


		if (xmlhttp)
		{
				if (xmlhttp.status != 200) /* 200 : code HTTP pour OK */
				{

						alert("Je comprends rien !!");


				}


				else {
						/*
						   Traitement de la réponse.
						   Ici on affiche la réponse dans une boîte de dialogue.
						 */
						var donnees =eval('('+xmlhttp.responseText+')');
						return donnees;
				}

		}

		return null;
}



function base64Encode(str)
{
		var charBase64 = new Array(
						'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
						'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
						'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
						'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
						);

		var out = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		var len = str.length;

		do
		{
				chr1 = str.charCodeAt(i++);
				chr2 = str.charCodeAt(i++);
				chr3 = str.charCodeAt(i++);

				//enc1 = (chr1 & 0xFC) >> 2;
				enc1 = chr1 >> 2;
				enc2 = ((chr1 & 0x03) << 4) | (chr2 >> 4);
				enc3 = ((chr2 & 0x0F) << 2) | (chr3 >> 6);
				enc4 = chr3 & 0x3F;

				out += charBase64[enc1] + charBase64[enc2];

				if (isNaN(chr2))
				{
						out += '==';
				}
				else if (isNaN(chr3))
				{
						out += charBase64[enc3] + '=';
				}
				else
				{
						out += charBase64[enc3] + charBase64[enc4];
				}
		}
		while (i < len);

		return out;
}


function base64Decode(str)
{
		var indexBase64 = new Array(
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
						52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
						-1, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
						15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
						-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
						41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
						-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
						);

		var out = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		// trim invalid characters in the beginning and in the end of the string

		str = str.replace(/^[^a-zA-Z0-9\+\/\=]+|[^a-zA-Z0-9\+\/\=]+$/g,"")

				var len = str.length;

		do
		{
				enc1 = indexBase64[str.charCodeAt(i++)];
				enc2 = indexBase64[str.charCodeAt(i++)];
				enc3 = indexBase64[str.charCodeAt(i++)];
				enc4 = indexBase64[str.charCodeAt(i++)];

				chr1 = (enc1 << 2) | (enc2 >> 4);
				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				chr3 = ((enc3 & 3) << 6) | enc4;

				out += String.fromCharCode(chr1);

				if (enc3 != -1)
				{
						out += String.fromCharCode(chr2);
				}
				if (enc4 != -1)
				{
						out += String.fromCharCode(chr3);
				}
		}
		while (i < len);

		if (i != len)
		{
				new Error(BASE64_BROKEN);
				return "";
		}

		return out;
}

