function popup(page,w,h,scro, nom) {

	if(!nom)
	{
		var nom = "popup";
	}

	var w =  window.open(page,nom,'width='+w+',height='+w+',toolbar=false,scrollbars='+scro+',top=0,left=0');	
	w.document.close();
	w.focus();
}

function VerifMail(chps)
{

  var place = chps.indexOf("@",1);
  var point = chps.indexOf(".",place+1);
  if (!((place > -1)&&(chps.length >2)&&(point > 1)))
  {
	return(false);
  }
  else
  {
	return(true);
  }
}

function in_array(needle, haystack, argStrict) {
  
    var found = false, key, strict = !!argStrict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}

// Fonction d'extraction des paramètres
function TJSExtraireParam() {

		url = window.location.href;
		var exp=new RegExp("[&?]+","g");
		var exp2=new RegExp("[=]+","g");
		var tabNom=url.split(exp);
		var	tabParam=new Array();
		if (tabNom!=null) {
			for (var i=1;i<tabNom.length;i++){
				var tabTemp=tabNom[i].split(exp2);
				tabParam[tabTemp[0]]=urldecode(tabTemp[1]);
			}
		}
		return tabParam;
	}

function urldecode(carac)
{
	var caractere = new Array;
	caractere["+"] 	= " "; 
	caractere["%20"] 	= " "; 
	caractere["%27"] 	= "'";
	caractere["%E7"] 	= "ç"; 
	caractere["%F4"] 	= "ô";
	caractere["%F6"] 	= "ö";
	caractere["%E0"]	= "à";
	caractere["%E2"]	= "â";
	caractere["%E4"]	= "ä";
	caractere["%E8"]	= "è";
	caractere["%E9"]	= "é";
	caractere["%EA"]	= "ê";
	caractere["%EB"]	= "ë";
	caractere["%F9"]	= "ù";
	caractere["%FB"]	= "û";
	caractere["%FC"]	= "ü";
	caractere["%EC"]	= "ì";
	caractere["%EE"]	= "î";
	caractere["%EF"]	= "ï";
	
	for(i in caractere)
	{
		carac = str_replace(i, caractere[i], carac)
	}
	
	return carac;
}	
	
// Voici les 3 fonctions de gestions des cookies
////////////////////////////////////////////////
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
date_exp.setTime(date_exp.getTime()+(365*24*3600*1000));
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 SetCookie (name, value) {
// un cookie a besoin d'un nom, d'une valeur, d'un nom de domaine, d'une date d'expiration
// 
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	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 count( mixed_var, mode ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Waldo Malqui Silva
    // +      bugfixed by: Soren Hansen
    // *     example 1: count([[0,0],[0,-4]], 'COUNT_RECURSIVE');
    // *     returns 1: 6
    // *     example 2: count({'one' : [1,2,3,4,5]}, 'COUNT_RECURSIVE');
    // *     returns 2: 6
 
    var key, cnt = 0;
 
    if (mixed_var === null){
        return 0;
    } else if (mixed_var.constructor !== Array && mixed_var.constructor !== Object){
        return 1;
    }
 
    if( mode === 'COUNT_RECURSIVE' ) {
        mode = 1;
    }
    if( mode != 1 ) {
        mode = 0;
    }
 
    for (key in mixed_var){
        cnt++;
        if( mode==1 && mixed_var[key] && (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object) ){
            cnt += count(mixed_var[key], 1);
        }
    }
 
    return cnt;
}
		 
function implode( glue, pieces ) {
   
    return ( ( pieces instanceof Array ) ? pieces.join( glue ) : pieces );
}


function str_replace(search, replace, subject, count) {
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function explode( delimiter, string, limit ) 
{
   var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

//on prepare les listes
	//liste de Iles
function getDestination()
{
	var liste_destination = new Array;
	z = 0;
	for (i in tableau)
	{
		if(count(tableau[i]) > 0)
		{
			liste_destination[z] = i;
			z++;
		}
	} 
	
	return liste_destination;
}
	//liste des types d'Hebergements
function getHebergement(pays)
{
	var liste_hebergement = new Array;
	z = 0;
	for (i in tableau[pays])
	{
		if(count(tableau[pays][i]) > 0)
		{
			liste_hebergement[z] = i;
			z++;
		}
	} 
	
	return liste_hebergement;
}
	//liste des Villes
function getVille(pays, hebergement)
{
	var liste_ville = new Array;
	z = 0;
	for (i in tableau[pays][hebergement])
	{
		if(count(tableau[pays][hebergement][i]) > 0)
		{
			liste_ville[z] = i;
			z++;
		}
	} 
	
	return liste_ville;
}
	// l'url
function getUrl(pays, hebergement, ville)
{
	if(tableau[pays][hebergement][ville])
	{
		return tableau[pays][hebergement][ville];
	}
	else
	{
		return false;
	}
}

function createListeDeroulante(type)
{
	document.FORMULAIRE.elements[type].options.length=0;
	
	if(type == "pays")
	{
		//on cree la liste
		liste = getDestination();
		
	}
	if(type == "hebergement")
	{
		//on cree la liste
		liste = getHebergement(document.FORMULAIRE.pays.value);
	}
	if(type == "ville")
	{
		//on cree la liste
		liste = getVille(document.FORMULAIRE.pays.value, document.FORMULAIRE.hebergement.value);
	}
	nb = liste.length;
	for(i=0; i<nb; i++)
	{
		xmlNom = liste[i];
		xmlId = liste[i];
		document.FORMULAIRE.elements[type].options[i] = new Option(xmlNom, xmlId);
	}
	
	if(!urlParam[type] || !in_array(urlParam[type],liste))
	{
		document.FORMULAIRE.elements[type].options[0].selected = true;
	}
	else
	{
		document.FORMULAIRE.elements[type].value = urlParam[type];
	}
	
	if(type == "pays")
	{
		
		createListeDeroulante('hebergement');
	}
	if(type == "hebergement")
	{
		createListeDeroulante('ville');
	}
	
}

function validForm()
{	
	if(url = getUrl(document.FORMULAIRE.pays.value, document.FORMULAIRE.hebergement.value, document.FORMULAIRE.ville.value))
	{
		//on valide le formulaire
		document.FORMULAIRE.action = url;
		document.FORMULAIRE.submit();
	}
	else
	{
		alert("Nous sommes désolé mais il n'existe aucune offre pour cette séléction dans notre catalogue");
		return false;
	}
}

function RotatePub(key)
{
	max = infopub["bloc"].length-1;
	
	DrawBlocPub(key);

	if(key == max)
	{
		i=0;
	}
	else
	{
		i=key+1;
	}

	 setTimeout("RotatePub("+i+")",cst_rota);
}

function RotateBandeauPub(key)
{
	max = infopub["popup"].length-1;
	
	DrawBandeauPub(key);
	
	if(key == max)
	{
		i=0;
	}
	else
	{
		i=key+1;
	}

	 setTimeout("RotateBandeauPub("+i+")",cst_rota);
}

function RotateSkycraper(key)
{
	max = infopub["skycraper"].length-1;
	
	DrawSkycraper(key);

	if(key == max)
	{
		i=0;
	}
	else
	{
		i=key+1;
	}

	 setTimeout("RotateSkycraper("+i+")",cst_rota);
}