
function popup_villes() {
	//alert(url);
	var w=window.open("/","mcad_ville","width=750, height=550, toolbars=no, scrollbars=yes, menubars=no, status=no");
}

function popup(url) {
	//alert(url);
	var w=window.open(url,"popup","width=500, height=500, toolbars=no, scrollbars=yes, menubars=no, status=no");
}

function popup(url,width,height) {
	//alert(url);
	if (document.all || document.layers) {
		w = screen.availWidth;
		h = screen.availHeight;
	}

	var leftPos = (w-width)/2;

	var w=window.open(url,"popup","width="+width+", height="+height+", top=50, left="+leftPos+", toolbars=no, scrollbars=yes, menubars=no, status=no");
}

function VerificationEmail(elm) {
	if (elm.value.indexOf("@") != "-1" &&
	    elm.value.indexOf(".") != "-1" &&
	    elm.value.indexOf(" ") == "-1" &&
	    elm.value != "") {
	    return true;
	}
	alert('Votre adresse email ne semble pas correct.');
	return false;
}

function VerifInscriptionNewsletter(form)
{
if (form.cpnewsletter.value.length!=5) {
	alert('Merci de renseigner votre code postal (5 chiffres).');
	return false;
} else if (VerificationEmail(form.newsletter) == true) {
	return true;
}
return false;
}

function isModifie()
{
	var el,i, modifie;
	modifie = false;
	if(window.document.forms[0] != null)
	{
		var elts=window.document.forms[0].elements ;
		for(i=0;i<elts.length-2;i++)
		{
		 	el=elts[i];
		 	// alert(el.validate);
			//pour chaque élt de type text ou select
		  	//if (el.type=="TEXT" || el.type=="SELECT")
		    //{
		    	if(el.validate){
		      		modifie = true;
		      		break;
		    	}
		   //	}
		}
	}
	return modifie;
}
function isValid(url){

	modifie = isModifie();

	if(modifie)
	{
		if(confirm("Des modifications ont eu lieu,voulez vous quitter sans enregistrer ?"))
		{
			window.location=url+sidJS;
		}
	}
	else
	{
		window.location=url+sidJS;
	}
}



	//Formate une date saisie au format dd/mm/YYYY
	function testDate(elmt)
	{
		str = elmt.value;
		var reg=new RegExp("^[0-9/]{6,10}$","g");
		if(reg.test(str))
		{

			if((str.length == 6 || str.length == 8) && str.indexOf('/') != 2 && str.indexOf('/') != 5)
			{
				str = str.substr(0,2)+"/"+str.substr(2,2)+"/"+str.substr(4);
			}
			else if((str.length == 7 || str.length == 9) && str.indexOf('/') != 2 && str.indexOf('/') == 4)
			{
				str = str.substr(0,2)+"/"+str.substr(2,2)+str.substr(4);
			}
			else if((str.length == 7 || str.length == 9) && str.indexOf('/') == 2 && str.indexOf('/') != 5)
			{
				str = str.substr(0,5)+"/"+str.substr(5);
			}
			if(str.length == 8)
			{
				annee = str.substr(6,2);
				if(annee > 70)
				{
					anneeOK = '19'+annee;
				}
				else
				{
					anneeOK = '20'+annee;
				}
				str = str.substr(0,6)+anneeOK;
			}
		}
		elmt.value = str;

	}

	function ajouterAuxFavoris()
	{
		if ( navigator.appName != 'Microsoft Internet Explorer' )
		{
			window.sidebar.addPanel("mon-commerce-a-dit.com - Soldes, promos, bons plans près de chez vous","http://www.moncommerceadit.com/","");
		}
		else
		{
			window.external.AddFavorite("http://www.moncommerceadit.com/","mon-commerce-a-dit.com - Soldes, promos, bons plans près de chez vous");
		}
	}

	function isValidDate(mot)
	{
	    if (mot.length!=10)
	    {
	    	alert("Merci de saisir une date au format JJ/MM/AAAA (exemple : 12/02/2009)");
	    	return false;;
	    }
	    else
	    {
		    motjour=mot.substring(0,2);
		    motmois=mot.substring(3,5);
		    motan=mot.substring(6,10);
		    motsep=mot.charAt(2)+mot.charAt(5);
		    if (isNaN(motjour+motmois+motan)|| motan>3000 ||motan<1900 || motsep!="//")
		    {
	    		alert("Merci de saisir une date au format JJ/MM/AAAA (exemple : 12/02/2009)");
		    	return false;
		    }
		    else
		    {
			    choix="";
			    valide = true;

			    if (motan-(parseInt(motan/4)*4)==0) {choix="bi"};
			    if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/100)*100)==0) {choix=""};
			    if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/400)*400)==0) {choix="bi"}
			    switch (motmois)
			    {
				    case "01":if(motjour<1 || motjour>31){alert("Attention, le mois de Janvier comporte 31 jours.");valide = false;};
				    break;
				    case"02":if(choix=="bi")
				    		{
				    			if(motjour<1 || motjour>29){alert("Attention, le mois de Février comporte 29 jours cette année.");valide = false;}
				    		}
				            else
				            {
				            	if(motjour<1 || motjour>28){alert("Attention, le mois de Février comporte 28 jours cette année.");valide = false;}
				            };
				    break;
				    case "03":if(motjour<1 || motjour>31){alert("Attention, le mois de Mars comporte 31 jours.");valide = false;};
				    break;
				    case "04":if(motjour<1 || motjour>30){alert("Attention, le mois de Avril comporte 30 jours.");valide = false;};
				    break;
				    case "05":if(motjour<1 || motjour>31){alert("Attention, le mois de Mai comporte 31 jours.");valide = false;};
				    break;
				    case "06":if(motjour<1 || motjour>30){alert("Attention, le mois de Juin comporte 30 jours.");valide = false;};
				    break;
				    case "07":if(motjour<1 || motjour>31){alert("Attention, le mois de Juillet comporte 31 jours.");valide = false;};
				    break;
				    case "08":if(motjour<1 || motjour>31){alert("Attention, le mois de Août comporte 31 jours.");valide = false;};
				    break;
				    case "09":if(motjour<1 || motjour>30){alert("Attention, le mois de Septembre comporte 30 jours.");valide = false;};
				    break;
				    case "10":if(motjour<1 || motjour>31){alert("Attention, le mois de Octobre comporte 31 jours.");valide = false;};
				    break;
				    case "11":if(motjour<1 || motjour>30){alert("Attention, le mois de Novembre comporte 30 jours.");valide = false;};
				    break;
				    case "12":if(motjour<1 || motjour>31){alert("Attention, le mois de Décembre comporte 31 jours.");valide = false;};
				    break;
				    default:alert("Merci de saisir une date au format JJ/MM/AAAA (exemple : 12/02/2009).");valide = false;
				}
				return valide;
			}
		}
	}

	function set_opacity(id, opacity)
{
        el = document.getElementById(id);
        el.style["filter"] = "alpha(opacity="+opacity+")";
        el.style["-moz-opacity"] = opacity/100;
        el.style["-khtml-opacity"] = opacity/100;
        el.style["opacity"] = opacity/100;
        return true;
}

	var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};


function is_mobile(){
	if(/iPhone|iPod|Android|opera mini|blackberry|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce;smartphoneiemobile/i.test(navigator.userAgent)){
  		return true; // Retourne True si ses un mobile sinon False.
	}
}

$is_mobile_browser = is_mobile();
BrowserDetect.init();

