function file(fichier){
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);		
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4)
	return(xhr_object.responseText);
	else return(false);
}

function file_quick (fichier){
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);		
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 2)
	return(xhr_object.responseText);
	else return(false);
}

function checkEmail(email) {
	if (email.search(/^[_a-z0-9-]+(\.[_a-z0-9-]*)*[^._-]@[a-z0-9-]+(\.[a-z0-9]{2,4})$/i) == -1) { return false; }
	else { return true; }
}

function stats_fhg_click(lg, template, type_m, idm) {
	error_in = file("http://media.acces-charme.com/galeries/click.php?lg="+escape(lg)+"&template="+escape(template)+"&type_m="+escape(type_m)+"&idm="+escape(idm)+"");
}

function stats_pdv_click (idpdv) {
	error_in = file("http://media.acces-charme.com/pdv/click.php?idpdv="+escape(idpdv)+"");
}

function stats_pdv_click2 (idpdv,url_pop) {
	error_in = file("http://media.acces-charme.com/pdv/click.php?idpdv="+escape(idpdv)+"");
	popup2(url_pop);
}

function stats_banniere_click (ide, ido) {
	error_in = file_quick("http://media.acces-charme.com/bannieres/click.php?ide="+escape(ide)+"&ido="+escape(ido)+"");
}

function verifFormAndSaveEmailDHTML (ide, ido, params) {
	var error = 0;
	var email_input = document.getElementById("email_dhtml").value;
	if ((typeof(wnc_lang) == "undefined") || (wnc_lang == "")) { wnc_lang = "fr"; }
	
	if (!checkEmail(email_input)) {
		error = 1;
		msg = "Champ EMAIL non valide !\n";
		if (wnc_lang == "fr") { msg = "Veuillez entrer un EMAIL valide (ex : nom@fournisseur.com) !\n"; }
		else if (wnc_lang == "en") { msg = "Please enter a valid EMAIL (ex : name@company.com) !\n"; }
		else if (wnc_lang == "es") { msg = "Por favor entren un EMAIL valido (por ejemplo: apellido@proveedor.com) !\n"; }		
	}
	
	if (error == 0) {
		 error_in = file_quick("http://media.acces-charme.com/dhtml/click.php?ide="+escape(ide)+"&ido="+escape(ido)+"&email="+escape(email_input)+"&"+params);
		return true;
	} else {
		alert(msg);
		return false;
	}
}


function verifFormAndSaveEmailPDV (params) {
	var error = 0;
	var email_input = document.getElementById("email").value;
	if ((typeof(wnc_lang) == "undefined") || (wnc_lang == "")) { wnc_lang = "fr"; }
	
	if (!checkEmail(email_input)) {
		error = 1;
		msg = "Champ EMAIL non valide !\n";
		if (wnc_lang == "fr") { msg = "Veuillez entrer un EMAIL valide (ex : nom@fournisseur.com) !\n"; }
		else if (wnc_lang == "en") { msg = "Please enter a valid EMAIL (ex : name@company.com) !\n"; }
		else if (wnc_lang == "es") { msg = "Por favor entren un EMAIL valido (por ejemplo: apellido@proveedor.com) !\n"; }		
	}
	
	if (error == 0) {
		 error_in = file_quick("http://media.acces-charme.com/pdv/click.php?email="+escape(email_input)+"&"+params);
		return true;
	} else {
		alert(msg);
		return false;
	}
}

function addbookmark(bookmarkurl, bookmarktitle){
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


function dhtml(p_url, p_id_pdv, p_width, p_height, p_classname, p_oklabel, p_buttonclass){
	Dialog.alert({url: "http://media.acces-charme.com/dhtml/track.php?" + p_url, options: {method: 'get'}}, 
			 {className: p_classname , width:p_width, height:p_height, okLabel: p_oklabel, buttonClass:p_buttonclass});
	
	if (p_id_pdv != "") { stats_pdv_click(p_id_pdv); }
}

function dhtml_fhg(p_url, p_width, p_height, p_classname, p_oklabel, p_buttonclass, p_lang, p_template, p_type_m, p_idm){
	Dialog.alert({url: "http://media.acces-charme.com/dhtml/track.php?" + p_url, options: {method: 'get'}}, 
			 {className:p_classname , width:p_width, height:p_height, okLabel:p_oklabel, buttonClass:p_buttonclass});
	
	if (p_lang != "" && p_template != "" && p_type_m != "" && p_idm != "" ) { stats_fhg_click(p_lang, p_template, p_type_m, p_idm); }
}

function createPlayer (pid, pfile, pimg, id_pdv, width, height) {
	var the_player = "player"+pid;
	var the_payer_play = "play"+pid;
	if (checkFlashVersion() == 1) {
		var msg = '<a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">';
		msg += '<img src="http://img.acces-charme.com/media/pdv/1/fr/images/flash.jpg" border="0" alt="Telecharger la derniere version de Flash Player" /></a>';
		document.getElementById(the_player).innerHTML = msg;
	} else {	
		var s = new SWFObject("http://www.acces-charme.com/mods/mediaplayer/player.swf","mpl"+pid,width,height,"9","#FFFFFF");
		s.addParam("allowfullscreen","true"); 
		s.addParam("allowscriptaccess","always");
		s.addParam("wmode","transparent");
		s.addParam("flashvars","&streamer=lighttpd&bufferlength=5&autostart=true&controlbar=none&file="+pfile+"&image="+pimg);
		s.write(the_player);
	}
	document.getElementById(the_payer_play).style.visibility = 'hidden';
	document.getElementById(the_payer_play).style.display = 'none';
	//stats_pdv_click(id_pdv);
}

function checkFlashVersion() {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (document.getElementById && version["major"] < 9) {
		return "1";
	} else {
	    return "0"; 
	}
}

function popup(url,idpdv) {
	var wnc_cook = wnc_get_cookie("wnc_pdv_"+idpdv);
	if ((wnc_cook == null) || (wnc_cook == "")) {
		var vnc_new_win = window.open(url,"", "width="+screen.availWidth+",height="+screen.availHeight+",scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0");
		if (vnc_new_win) {
			vnc_new_win.blur(); 
			window.self.focus();
			wnc_set_cookie("wnc_pdv_"+idpdv, "oui", 0);
		}
		// return false;
	}
}

function popup2(url) {
	if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("MSIE 8") != -1) {
		var vnc_new_win = window.open(url, '_blank', 'width=1024, height=950 , toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1');
		if (vnc_new_win != null) { 
			vnc_new_win.blur();
		}
	} else {
		window.open(url, '_blank', 'width=1024, height=950 , toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1');
		self.focus();
	}
}

function popunder(url,idpdv) {
	var wnc_cook = wnc_get_cookie("wnc_pdv_"+idpdv);
	if ((wnc_cook == null) || (wnc_cook == "")) {		
		if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("MSIE 8") != -1) {
			var vnc_new_win = window.open(url, '_blank', 'width=1024, height=950 , toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1');
			//window.opener.focus(); 
			self.focus();
			if (vnc_new_win != null) { 
				vnc_new_win.blur();
				wnc_set_cookie("wnc_pdv_"+idpdv, "oui", 0);
			}
		} else {
			window.open(url, '_blank', 'width=1024, height=950 , toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1');
			self.focus();
			//window.opener.focus(); 
			wnc_set_cookie("wnc_pdv_"+idpdv, "oui", 0);
		}
	}
}

function plein_ecran() {
	if (navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Firefox") != -1) { return; }
	window.moveTo(0,0); 
	window.resizeTo(screen.availWidth,screen.availHeight);
}

function wnc_set_cookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" +escape(value)+";"+((expiredays=='') ? "" : "expires="+exdate.toGMTString()+";")+"path=/;";
}

function wnc_get_cookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length+1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1) { c_end = document.cookie.length; }
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function wnc_addEvent(obj, evType, fn){  
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

