var C_SERVEUR = "http://www.accorhotels.com/hotel-cms/";
function Contexte(){
	this.site = null;
	this.domain = null;
	this.lang = null;
	this.filtre = null;
	this.valeur = null;
	this.affinage = null;
	this.periodeFin = null;
	this.pageCourante = null;
	this.fichier = null;
	
	this.listPackageLoaded = false;
}

Contexte.prototype.isAvailable = function (){
	if ( this.lang != null && this.filtre != null && this.valeur != null ){
		return true;
	}
	return false;
}

Contexte.prototype.loadListePackages = function (){
	var url = null;
	if ( this.isAvailable() )
	{
		if ( C_MODE_PACKAGE != "PROD" ){
			//url = "ebn.ebn?nodoctype=0&lang=fr&langid=1&site=7&pid=523&objet=page&prefix=accorhotels.packages.listes.js&filtre=theme&valeur=8&affinage=PFR"
			url = "ebn.ebn?nodoctype=0";
			url += "&pid=" + getUrlParam( "pid" );
			url += "&objet=page";
			url += "&prefix=accorhotels.packages.listes.js";
			url += "&lang=" + getUrlParam( "lang" );
			url += "&langid=" + getUrlParam( "langid" );
			url += "&site=" + getUrlParam( "site" );
			url += "&filtre=" + this.filtre;
			url += "&valeur=" + this.valeur;
			if ( this.affinage != null && this.affinage.length > 0 ){
				url += "&affinage=" + this.affinage;
			}
			if ( this.periodeFin != null && this.periodeFin.length > 0 ){
				url += "&fin=" + this.periodeFin;
			}

		}else{
			/*
			if ( this.periodeFin != null && this.periodeFin.length > 0 ){
				url = "accorhotels/fr/packages/listes/js/" + this.filtre + "/" + this.valeur + "/" + this.periodeFin + ".js";
			}else{
				if ( this.affinage == null || this.affinage.length == 0 ){
					url = "fr/packages/listes/js/" + this.filtre + "/" + this.valeur + ".js";
				}else{
					url = "fr/packages/listes/js/" + this.filtre + "/" + this.valeur + "/" + this.affinage + ".js";
				}
			}
			*/
			if (this.fichier != null )
			{
				url = this.lang + "/packages/listes/js/" + this.fichier + ".js";
			}
			//url = "http://www." + this.site + ".com/hotel-cms/" + url;
			url = "http://" + this.domain + "/hotel-cms/" + url;
			//prompt('',url);
		}
		if (this.site != "" )
		{
			FCKScriptLoader.AddScript( url ) ;
			this.listPackageLoaded = true;
			window.status = ''; 
		}
		
	}
}
Contexte.prototype.loadContexteFromCookie = function (){
	var tmp = GetCookie( "package_filtre" );
	this.filtre = (  tmp != null && tmp != "null" ) ? tmp : "";

	tmp = GetCookie( "package_valeur" );
	this.valeur = (  tmp != null && tmp != "null" ) ? tmp : "";
	
	tmp = GetCookie( "package_affinage" );
	this.affinage = (  tmp != null && tmp != "null" ) ? tmp : "";
	
	tmp = GetCookie( "package_pagecourante" );
	this.pageCourante = (  tmp != null && tmp != "null" ) ? tmp : 0;
	
	tmp = GetCookie( "package_lang" );
	this.lang = (  tmp != null && tmp != "null" ) ? tmp : "";
	
	tmp = GetCookie( "package_fichier" );
	this.fichier = (  tmp != null && tmp != "null" ) ? tmp : "";

	tmp = GetCookie( "package_site" );
	this.site = (  tmp != null && tmp != "null" ) ? tmp : "";

	tmp = GetCookie( "package_domain" );
	this.domain = (  tmp != null && tmp != "null" ) ? tmp : "";
}

Contexte.prototype.writeContexteToCookie = function ()
{
	SetCookie( "package_filtre", this.filtre );
	SetCookie( "package_valeur" , this.valeur );
	SetCookie( "package_affinage" , this.affinage );
	SetCookie( "package_pagecourante" , this.pageCourante );
	SetCookie( "package_lang" , this.lang );
	SetCookie( "package_fichier" , this.fichier );
	SetCookie( "package_site", this.site );
	SetCookie( "package_domain", this.domain );
}

Contexte.prototype.getPageCourante = function (){
	if ( this.pageCourante == null || this.pageCourante.length == 0 ){
		return 0;	
	}
	return this.pageCourante;
}

function initialiseCookie(){
	SetCookie( "package_filtre", null );
	SetCookie( "package_valeur" , null );
	SetCookie( "package_affinage" , null );
	SetCookie( "package_pagecourante" , null );
	SetCookie( "package_lang" , null );
	SetCookie( "package_fichier" , null );
	SetCookie( "package_site" , null );
	SetCookie( "package_domain" , null );
}

function removeCookie(){
	ResetCookie( "package_filtre");
	ResetCookie( "package_valeur");
	ResetCookie( "package_affinage");
	ResetCookie( "package_pagecourante");
	ResetCookie( "package_lang");
	ResetCookie( "package_fichier");
	ResetCookie( "package_site");
	ResetCookie( "package_domain");
}

function getUrlParam( paramName )
{
	var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
	var oMatch = oRegex.exec( unescape(window.top.location.search) ) ;
	
	if ( oMatch && oMatch.length > 1 )
		return oMatch[1] ;
	else
		return '' ;
}



function SetCookie(name, value)
{
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        //var expires = (argc > 2) ? argv[2] : null;
		var expires = new Date();
		var cinqm = expires.getTime() + (5*60*1000);
		expires.setTime(cinqm);
        //var path = (argc > 3) ? argv[3] : null;
        var path = "/";
		var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape (document.cookie.substring(offset, endstr));
}
function GetCookie(name) {
   var arg = name+"=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}
function ResetCookie(name)
{
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	SetCookie(name,null,date); 
}