//var sousdomaine = "preprod";

//Panier
var panierSurLeSite	= null;
function getPanier(){
	if(panierSurLeSite == null){
		panierSurLeSite = new Panier({
			"name"				:	"panier",
			"adresseDonnees"	: 	"traitements_panier.php"
		});
	}
	return panierSurLeSite;
}

//Tips
var tipsSurLeSite	= null;
function getTips(){
	if(tipsSurLeSite == null){
		tipsSurLeSite = new Tips('.tooltip', {
		      className: 'tipz',
		      fixed: 'true'
		});
	}
	return tipsSurLeSite;
}

//fonction Alerte pour afficher les caracteres HTML //
function Alerte(msg){
	var div = new Element('div', {id: 'div-alert', style: 'display:none'});
	div.innerHTML = msg;
	alert(div.innerHTML);
	div.dispose();
}

//Datepicker
function ajoutCalendrier(id,default_value,alignX){
	default_value = default_value || false;
	alignX = alignX || 'right';
	
	var calendrier = new vlaDatePicker(id,{ 
		'prefillDate' : default_value,
		'filePath' : 'lib/javascript/logics/calendrier/',
		'alignX' : alignX
	});
}

//Datepicker
function ajoutCalendrierAdmin(id,default_value,alignX){
	default_value = default_value || false;
	alignX = alignX || 'right';
	
	var calendrier = new vlaDatePicker(id,{ 
		'prefillDate' : default_value,
		'filePath' : '../lib/javascript/logics/calendrier/',
		'alignX' : alignX
	});
}

// Fonctions pour placer et afficher les infos bulles des univers de ZePass //
function ds_getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}
function ds_gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

function showInfobulle(origine, div, status){
	if(status == true) {
		$(div).setStyle('display', 'block');	
		the_left = ds_getleft(origine);
		the_top = ds_gettop(origine) + origine.offsetHeight - 110;
		$(div).setStyles({
			left: the_left + 'px',
			top:  the_top + 'px'
		});
	}else if(status == false) {
		var fx = new Fx.Tween($(div), {
			property: 'opacity',
			duration: 2000,
			onComplete: function(){ 
				$(div).fade('out');
			}
		})
		// On passe d'une opacité 1 à 0 : effet de fondu avec le timer duration //
		fx.start(1,0);
	}
}

function changerPaysAllopassJson(country, audio, sms, type) {
	type = type || 'annonce';
	var contenerNumtel = $('contener-numtel');
	var contenerLegal = $('contener-legal');

	var request = new Request({
		url : "traitements_ajax.php?",
		method : 'post',
		onComplete : function(response){
			var jsonRes = JSON.decode(this.getHeader('X-JSON'));
			switch(jsonRes.status){
				case 'valid':
					contenerNumtel.innerHTML = jsonRes.datas[0];
					contenerLegal.innerHTML = jsonRes.datas[1];
					break;
				case 'error':
					break;
				default:
					break;
			}
		}
	
	});
	
	request.send("traitement=allopass_json&country="+country+"&audio="+audio+"&sms="+sms+"&type="+type);
}


function ComptageCaracteres(theform, max) {
    var txt = document.forms[theform].elements["conditions"].value;
    var nb = txt.length;
    if (nb >= 0) { nb++; }
    if (nb > max) {
        alert("Ce champ ne doit pas contenir plus de "+max+" caractères !");
        document.forms[theform].elements["conditions"].value = txt.substring(0, max);
        nb = max;
    }
    document.forms[theform].elements["nbcar"].value = "(" + nb + " / " + max + " caractères maximum) :";
}

function CheckAnonymat(theform) {
	// On vérifie que le champ commentaires ne contient pas d'email, ni de téléphone
	var conditions = document.forms[theform].elements["conditions"].value;
	if(conditions != null) {
		var stringtocontrol = conditions.split(/ /);
		var reg = /^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,3}$|arob|@rob|AROB|@ROB|^[0-9]{10}$|^[0-9._-]{14}$/
		var reg2 = /^[0-9]{2}$/
		var fraude = 0;
		var suite = 0;
		for(var i = 0; i < stringtocontrol.length; i++) {
			if(reg.exec(stringtocontrol[i].trim()) != null) { fraude = 1; }
			if(reg2.exec(stringtocontrol[i].trim()) != null) { suite++; }
		}
		if(fraude == 1 || suite >= 5) {
			document.getElementById('warning-conditions').style.display = "block";
			document.getElementById('help-warning-conditions').style.display = "block";
		}
		else {
			document.getElementById('warning-conditions').style.display = "none";
			document.getElementById('help-warning-conditions').style.display = "none";
		}
	}
}

function commentAdmin(theform){
	letter = document.forms[theform].elements['statut'].value;
	if(letter == 'R' || letter == 'B'){
		document.getElementById('commentadmin').style.display = 'block';
	}else{
		document.getElementById('commentadmin').style.display = 'none';
	}
}