// JavaScript Document
/*
 * Author : Germain Guglielmetti
 * Company : ashorlivs
 * URL : www.ashorlivs.fr
 */
function check_email(email)
{
  var verif =/^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$/;
 if (verif.exec(email) == null)
 {
 
 return(false);
 }
 else
 {
 return(true);
 } 
}

Request.HTML.implement({
  
	 processHTML: function(text){
		 var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
		 text = (match) ? match[1] : text;
		
		 var container = new Element('div');
		
		 return $try(function(){
			 var root = '<root>' + text + '</root>', doc;
			 if (Browser.Engine.trident){
				 doc = new ActiveXObject('Microsoft.XMLDOM');
				 doc.async = false;
				 doc.loadXML(root);
			 } else {
				 doc = new DOMParser().parseFromString(root, 'text/html');
			 }
			 root = doc.getElementsByTagName('root')[0];
			 for (var i = 0, k = root.childNodes.length; i < k; i++){
				var child = Element.clone(root.childNodes[i], true, true);
				 if (child) container.grab(child);
			 }
			 return container;
		 }) || container.set('html', text);
	 }
	
});	


function open_inscription_carte(){
    Shadowbox.open({
        content:    'formulaire_programme.php',
        player:     "iframe",
        title:      "",
        height:     436,
        width:      682
    });
}

function open_best_offre_email(offre_id){
    Shadowbox.open({
        content:    'popup_best_offre_email.php?offre_id='+offre_id,
        player:     "iframe",
        title:      "",
        height:     260,
        width:      519
    });
}

function open_best_offre(offre_id){
    Shadowbox.open({
        content:    'popup_bestoffreliste.php?offre_id='+offre_id,
        player:     "iframe",
        title:      "",
        height:     528,
        width:      519
    });
}


function open_mag(id,back){
    Shadowbox.open({
        content:    'commercant.php?id='+id+'&goback='+back,
        player:     "iframe",
        title:      "",
        height:     517,
        width:      541
    });
}

function open_archetype(num){
    Shadowbox.open({
        content:    'archetypes.php?num='+num,
        player:     "iframe",
        title:      "",
        height:     530,
        width:      646
    });
}

function open_chequier(num){
    Shadowbox.open({
        content:    'popup_chequier.php',
        player:     "iframe",
        title:      "",
        height:     376,
        width:      470
    });
}

function open_new_boutique(){
    Shadowbox.open({
        content:    'popup_nouvelles_enseignes.php',
        player:     "iframe",
        title:      "",
        height:     436,
        width:      682
    });
}

function open_login(){
    Shadowbox.open({
        content:    'login.php',
        player:     "iframe",
        title:      "",
        height:     194,
        width:      481
    });
}

function open_profil(){
    Shadowbox.open({
        content:    'popup_profil.php',
        player:     "iframe",
        title:      "",
        height:     436,
        width:      682
    });
}

function open_plan(){
    Shadowbox.open({
        content:   "popup_plan_bis.php?src="+$('image_plan').src,
        player:     "iframe",
        title:      "",
        height:     580,
        width:      580
    });
}

function open_ouvrir_boutique(){
    Shadowbox.open({
        content:   "popup_ouvrir_boutique.php",
        player:     "iframe",
        title:      "",
        height:     376,
        width:      469
    });
}

function open_plan_apied(){
    Shadowbox.open({
        content:   "popup_plan_apied.php",
        player:     "iframe",
        title:      "",
        height:     703,
        width:      591
    });
}


function open_formulaire_programme(){
    Shadowbox.open({
        content:   "formulaire_programme.php",
        player:     "iframe",
        title:      "",
        height:     436,
        width:      682
    });
}

/**************/
/* DIVERS DIV */
/**************/

function AfficherDiv(id){
    document.getElementById(id).style.display = 'block';
}

function MasquerDiv(id){
    document.getElementById(id).style.display = 'none';
}


function AfficherMasquerDiv(id){
    if (document.getElementById(id).style.display != 'none') {
        document.getElementById(id).style.display = 'none';
    }
    else {
        document.getElementById(id).style.display = 'block';
    }
}

function MasquerAfficherDiv(id){
    if (document.getElementById(id).style.display != 'block') {
        document.getElementById(id).style.display = 'block';
    }
    else {
        document.getElementById(id).style.display = 'none';
    }
}

var ferme=0;

function ferme_menu(){
	if(ferme==0){
		ferme=1;
		window.setTimeout('ferme_div()',500);
	}

}
function ferme_div(){
	if(ferme==1){
	$('menuFooterCtr').setStyle('display','none');
	$('menuFooterCtrCtn').setStyle('margin-top','0px');
	$('menuFooterCtr').setStyle('margin-top','0px');
	}

}


/***********/
/* FAVORIS */
/***********/
function favoris(url,description) {
    // attention dans IE les accents en é ne passent pas bien et les accents en &eacute; non plus !
    if ( navigator.appName != 'Microsoft Internet Explorer' )
    {
        window.sidebar.addPanel(description,url,"");
    }
    else {
        window.external.AddFavorite(url,description);
    }
}







/***********/
/* COOKIES */
/***********/

// http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
