


function evalScript ( response )
{
	//while( response.indexOf ( "<script language=\"javascript\">" ) != -1)
	while( response.indexOf ( "<script>" ) != -1)
	{
		var deb = response.indexOf ( "<script language=\"javascript\">" ) + 8/*30*/ ;
		var fin = response.indexOf ( "</script>" );
		//alert(response.substring ( deb, fin ));
		eval ( response.substring ( deb, fin ) );
		response = response.substr ( fin + 9 );
	} // while
}


BG.util.EscapeCote = function	 ( chaine )
{
	var regex = /[']/gi;
	chaine = chaine.replace ( regex, "\\'" );
	
	return chaine;
}


BG.util.ToId = function	 ( chaine )
{
	var temp = chaine;
	var regex = /[' ]/gi;
	temp = temp.replace ( regex, '_');
	
	regex = /[éèê]/gi;
	temp = temp.replace ( regex, 'e');
	
	regex = /[àâä]/gi;
	temp = temp.replace ( regex, 'a');
	
	regex = /[îï]/gi;
	temp = temp.replace ( regex, 'i');
	
	regex = /[ûüù]/gi;
	temp = temp.replace ( regex, 'u');
	
	regex = /[ôö]/gi;
	temp = temp.replace ( regex, 'o');
	
	regex = /[ç]/gi;
	temp = temp.replace ( regex, 'c');
	
	regex = /[-*:;,?\/+$%!&#{|\]\[)}=<>~`\\]/gi;
	temp = temp.replace ( regex, '');
	
	return temp;
}	


/**
 * Definit si le parametre param est de type type.
 * Utile pour tester les parametres que recoit une fonction.
 * @param parm Le paramétre qui doit être testé.
 * @param type {String} Le type de variable attendu pour param <br/>
string<br/>
numeric<br/>
object
 */

BG.util.IsParamValide = function  ( param, type )
{
	if ( typeof param == type && typeof param != "undefined" )
		return true;

	return false;
};


/**
 * Fonction qui applique à un objet une chaine JSON.
 * Cela est donc utilisé pour initialiser ou mettre à jour des variables.
 *
 * @param {String} config - La chaine JSON à appliquer.
 * @param (object) obj	- L'objet à mettre à jour.
 *
 */
BG.util.ApplyConfig = function ( config, obj )
{

	for ( var prop in config )
	{
		if ( typeof prop == "object" )
		{

			ApplyConfig ( config[prop], obj[prop] );
		}
		else
			obj[prop] = config[prop];
	}
};

BG.util.FormatValueForJSON = function( val )
{
	if ( typeof val == "string" )
		return "'" + val + "'";
	else
		return val;
	return "";
};
BG.util.ObjectToJSON  = function ( obj )
{
	var sJSON = new String();
	sJSON += "{";
	for ( var prop in obj )
	{
		sJSON += prop + ":" + BG.util.FormatValueForJSON ( obj[prop] ) + ",";
	}
	sJSON += "}";

	return sJSON;
};


/*
function Cookies_Get ( cookieName )
{
	var cookieNameStart,valueStart,valueEnd,value;
	cookieNameStart = document.cookie.indexOf ( cookieName + "=" );

	if (cookieNameStart < 0)
	{
		return null;
	}
	valueStart = document.cookie.indexOf(cookieName+"=") + cookieName.length + 1;
	valueEnd = document.cookie.indexOf(";",valueStart);

	if (valueEnd == -1)
	{
		valueEnd = document.cookie.length;
	}
	value = document.cookie.substring(valueStart,valueEnd );
	value = unescape(value);
	if (value == "")
	{
		return null;
	}
	return value;
}*/

/*
BG.util.Cookies = function ()
{
};
*/
BG.util.Cookies =
{

	/**
	 *  Fonction de récupération de la valeur d'un cookie
	 *
	 *
	 * @param {String} cookieName - Le nom du cookie dont on veut récupéré la valeur
	 * @return {String} Si le cookie existe, la valeur du cookie, sinon null.
	 *
	 */

	Get:function ( cookieName )
	{
		var cookieNameStart,valueStart,valueEnd,value;
		cookieNameStart = document.cookie.indexOf(cookieName+'=');
		if (cookieNameStart < 0)
		{
			return null;
		}
		valueStart = document.cookie.indexOf(cookieName+'=') + cookieName.length + 1;
		valueEnd = document.cookie.indexOf(";",valueStart);

		if (valueEnd == -1)
		{
			valueEnd = document.cookie.length;
		}
		value = document.cookie.substring(valueStart,valueEnd );
		value = unescape(value);
		if (value == "")
		{
			return null;
		}
		return value;
	},

	/**
	 *  Ecrit ou modifie un cookie.
	 * @param {String } cookieName Le nom du cookie pour lequel on veut stocker une valeur.
	 * @param {String } value La valeur du cookie
	 * @param {int} hoursToLive Le nombre d'heure avant que le cookie expire.
	 *
	 * @param {String}{Optional} path  The path for which the cookie is valid.  Defaults to "/" if not
	 *                             passed, or passed empty.
	 * @param {String}{Optional} domain (Optional) The domain for which the cookie is valid.  Defaults to
	 *                              window.location.hostname if not passed, or passed empty.
	 * @param {boolean}{Optional} secure This is used to instruct the browser to use SSL when sending the
	 *                            cookie to a server.  It is almost never used, and will thus be assumed false
	 *                            unless you explicitly pass true.
	 */
	Set:function ( cookieName, value, hoursToLive, path_, domain_, secure)
	{
		var domain = "bg_alex";
		var path = "/generator/test/";

		var timerObj = new Date();
		timerObj.setTime(timerObj.getTime()+(parseInt(hoursToLive)*60*60*1000));
		var expireAt = timerObj.toGMTString();
		var expireString = "; expires="+expireAt;

		var setCookieString = cookieName + "=" + escape(value) +
       ( expireString) +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");

    	document.cookie = setCookieString;

		document.cookie =
  'ppkcookie1=testcookie; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/; domain='+ domain;

		alert( document.cookie );


	}
	/**
	 * Delete a cookie
	 * @param {String} cookieName The name of the cookie value you wish to delete
	 * @param {String}{Optional} path  The path for which the cookie was set.  This is necessary if
	 *                            the cookie was set with a particular path--you need to delete it with the
	 *                            same.  Defaults to "/" if not passed, or passed empty.
	 * @param {String}{Optional} domain  The domain for which the cookie was set.  This is necessary if
	 *                            the cookie was set with a particular domain--you need to delete it with the
	 *                            same.  Defaults to window.location.hostname if not passed, or passed empty.
	 */

	/*Delete: function ( cookieName, path, domain )
	{
          (!path || !path.length) ? path="" : path=path;
          (!domain || !domain.length) ? domain="" : domain=domain;
		Set(cookieName,"",-8760,path,domain);
	}*/
};

