﻿// script for popup

var popscroll;
var _gaq = _gaq || [];
function MyPopupnm(fieldname, popupname) {
 
 if(fieldname=="signin"){
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
}

 if(fieldname=="popuphelp"){
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
}

if(fieldname=="soffer"){
_gaq.push(['_trackEvent', 'Button', popupname + ' ' + fieldname, 'Members Sorties Main']);
  if(popscroll!=undefined)
  document.getElementById(popscroll).style.display = "none";
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
  getpoppos();
}

if(fieldname=="shoffer"){
_gaq.push(['_trackEvent', 'Button', popupname + ' ' + fieldname, 'Members Shopping Main']);
  if(popscroll!=undefined)
  document.getElementById(popscroll).style.display = "none";
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
  getpoppos();
}

if(fieldname=="eoffer"){
_gaq.push(['_trackEvent', 'Button', popupname + ' ' + fieldname, 'Members Evasion Main']);
  if(popscroll!=undefined)
  document.getElementById(popscroll).style.display = "none";
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
getpoppos();	
}

if(fieldname=="coffer"){
_gaq.push(['_trackEvent', 'Button', popupname + ' ' + fieldname, 'Members Chez Main']);
 if(popscroll!=undefined)
 document.getElementById(popscroll).style.display = "none"; 
 popscroll=popupname;
 myPopupRelocate();
 document.getElementById(popupname).style.display = "block";
getpoppos();
}

if(fieldname=="offer"){
  if(popscroll!=undefined)
  document.getElementById(popscroll).style.display = "none";
  popscroll=popupname;
  myPopupRelocate();
  document.getElementById(popupname).style.display = "block";
getpoppos();
}
}

function myPopupRelocate() {
  var scrolledX, scrolledY;
  if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
  } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
  }

  var centerX, centerY;
  if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
  } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
  }

  var leftOffset = scrolledX + (centerX - 750) / 2;
  var topOffset = scrolledY + (centerY - 350) / 2;

  document.getElementById(popscroll).style.top = topOffset + "px";
  document.getElementById(popscroll).style.left = leftOffset + "px";

}

function printpop()
{
window.print();
}


// Promo Popup Scripts 

function MyPopupPromo(fieldName, popupName) 
{
  PopupnmRelocate(fieldName, popupName);
  document.getElementById(popupName).style.display = "block";
}

function PopupnmRelocate(fieldName, popupName) 
{
  document.getElementById(popupName).style.top = findPosY(document.getElementById(fieldName));
  document.getElementById(popupName).style.left = findPosX(document.getElementById(fieldName));
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


// Start Validation for Member Contact Us Form 
	function contactcheck() {		
		var missing = "";
		var invalid = " "; 
		if ((document.contactusfrm.Email.value  == "") || (document.contactusfrm.Email.value  == " ")) { missing +="Vous devez saisir votre adresse e-mail.<br>"; };
		if ((document.contactusfrm.question.value  == "" ) || (document.contactusfrm.question.value  == " " )) { missing +="Vous devez saisir votre message.<br>"; };
		if ((document.contactusfrm.subject.value  == "Autre" ) && ((document.contactusfrm.specify.value  == "" ) || (document.contactusfrm.specify.value  == " " )) ) { missing +="Vous devez pr&eacute;ciser le sujet de votre message.<br>"; };

		if (missing !="") 
		{
			CM.innerHTML = ""+missing;
			window.scrollTo(0,0);	
			return false;
		}	
		else
		{
		return true;
		}
	
	}


//  Validation for Partner Form 
function partnernmcheck() {
		var missing = "";
		var invalid = " "; 
			
		if (document.partnerfrm.civilite.value  == "S&eacute;lectionnez") { missing +="La Civilit&eacute; est un champ obligatoire. <br>"; };
		if ((document.partnerfrm.LastName.value  == "") || (document.partnerfrm.LastName.value  == " ")) { missing +="Le Nom est un champ obligatoire.<br>"; };
		if ((document.partnerfrm.FirstName.value  == "") || (document.partnerfrm.FirstName.value == " ")) { missing +="Le Prenom est un champ obligatoire<br>"; };
		if ((document.partnerfrm.phone.value  == "") || (document.partnerfrm.phone.value  == " ")) { missing +="Le T&eacute;lephone est un champ obligatoire.<br>"; };
		if ((document.partnerfrm.activitysector.value  == "" ) || (document.partnerfrm.activitysector.value  == " " )) { missing +="Le Secteur d&#146;activit&eacute; est un champ obligatoire.<br>"; };
		
		if (missing !="") 
		{
			PNM.innerHTML = ""+missing;
			window.scrollTo(0,0);	
			return false;
		}	
		else
		{
		return true;
		}
	
	}

// Validation for firstname only character
function firstname1(cname)
{
if (cname.value=="") return true;
var num = /\d/;
var anum = /[a-zA-Z]/;
var spchar = /\$/;
if ((num.test(cname.value) && anum.test(cname.value)) || (num.test(cname.value)) || (spchar.test(cname.value))) {
alert("Le champ prenom ne doit contenir que des lettres");
	document.getElementById(cname.id).value="";
		var nameTxt=document.getElementById(cname.id);
		nameTxt.focus();
		return false;
	} 
	else {return true;}
 }


// Validation for lastname only character
function lastname1(cname)
{
if (cname.value=="") return true;
var num = /\d/;
var anum = /[a-zA-Z]/;
var spchar = /\$/;
if ((num.test(cname.value) && anum.test(cname.value)) || (num.test(cname.value)) || (spchar.test(cname.value))) {
alert("Le champ nom ne doit contenir que des lettres");
	document.getElementById(cname.id).value="";
		var nameTxt=document.getElementById(cname.id);
		nameTxt.focus();
		return false;
	} 
	else {return true;}
 }


// validation for phone number
function phonenumber(obj)
	{
		var x=obj.value

		if (x=="") return true;
			var anum=/(^\d+$)|(^\d+\.\d+$)/
			if (anum.test(x)&& (x.length==10)&&(x!="0000000000"))
			testresult=true
			else{
			alert("Le champ T&eacute;l&eacute;phone est invalide.")
			obj.value = x.substring(0,x.length)
			var ph= document.getElementById(obj.id);
			ph.focus();
			ph.value="";
			testresult=false
			}
		return (testresult)

	}

// Start Validation for Non Member Contact Us Form //-->
function contactnmcheck() {		
		var missing = "";
		var invalid = " "; 
			
		if ((document.contactusfrm.FirstName.value  == "") || (document.contactusfrm.FirstName.value == " ")) { missing +="Le pr&eacute;nom est un champ obligatoire.<br>"; };
		if ((document.contactusfrm.LastName.value  == "") || (document.contactusfrm.LastName.value  == " ")) { missing +="Le nom est un champ obligatoire.<br>"; };
		if ((document.contactusfrm.Email.value  == "") || (document.contactusfrm.Email.value  == " ")) { missing +="Vous devez saisir votre adresse e-mail.<br>"; };
		if ((document.contactusfrm.question.value  == "" ) || (document.contactusfrm.question.value  == " " )) { missing +="Vous devez saisir votre message.<br>"; };
		if ((document.contactusfrm.subject.value  == "Autre" ) && ((document.contactusfrm.specify.value  == "" ) || (document.contactusfrm.specify.value  == " " )) ) { missing +="Vous devez pr&eacute;ciser le sujet de votre message.<br>"; };

		if (missing !="") 
		{
			CNM.innerHTML = ""+missing;
			window.scrollTo(0,0);	
			return false;
		}	
		else
		{
		return true;
		}
	
	}

// script to Validate member number to accept only digit
	function checkmembernumber(obj)
		{
		var x=obj.value

		if (x=="") return true;
			var anum=/(^\d+$)|(^\d+\.\d+$)/
			if (anum.test(x))
			testresult=true
			else{
			alert("Le num&eacute;ro de membre ne peut contenir que des chiffres.")
			obj.value = x.substring(0)
			testresult=false
			document.getElementById("MemberNumber").focus();
			document.getElementById("MemberNumber").value="";
			}
		return (testresult)
		}

// script to Validate firstname to accept only character
function firstname(cname)
{
if (cname.value=="") return true;
var num = /\d/;
var anum = /[a-zA-Z]/;
var spchar = /\$/;
if ((num.test(cname.value) && anum.test(cname.value)) || (num.test(cname.value)) || (spchar.test(cname.value))) {
alert("Certains caractères ne sont pas accept&eacute;s, veuillez resaisir le pr&eacute;nom.");
	document.getElementById(cname.id).value="";
		var nameTxt=document.getElementById(cname.id);
		nameTxt.focus();
		return false;
	} 
	else {return true;}
 }

// script to Validate lastname to accept only character
function lastname(cname)
{
if (cname.value=="") return true;
var num = /\d/;
var anum = /[a-zA-Z]/;
var spchar = /\$/;
if ((num.test(cname.value) && anum.test(cname.value)) || (num.test(cname.value)) || (spchar.test(cname.value))) {
alert("Certains caractères ne sont pas accept&eacute;s, veuillez resaisir le nom.");
	document.getElementById(cname.id).value="";
		var nameTxt=document.getElementById(cname.id);
		nameTxt.focus();
		return false;
	} 
	else {return true;}
 }

// script for Email
function emailvalid(obj) {
var str = obj.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if ((str!="") && (str.indexOf(at)==-1)){
		   alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		   return false
		}

		if ((str!="") && (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)){
		   alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		   return false
		}

		if ((str!="") && (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)){
		    alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		    return false
		}

		 if ((str!="") && (str.indexOf(at,(lat+1))!=-1)){
		    alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		    return false
		 }

		 if ((str!="") && (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)){
		    alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		    return false
		 }

		 if ((str!="") && (str.indexOf(dot,(lat+2))==-1)){
		    alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		    return false
		 }
		
		 if ((str!="") && (str.indexOf(" ")!=-1)){
		    alert("Le format de l'adresse e-mail est incorrect.")
			obj.value=""
			obj.focus()
		    return false
		 }

 		 return true					
	}

// script for dropdown
function checksubject(id) {
var nosubject=document.getElementById("subject1").value;

	if (nosubject=="Autre")
	{
		subj.innerHTML="<table><tr><td style='font-family:Trebuchet MS;font-size:11px;'>Pr&eacute;cisez *<br><input type='text' name='specify' size='10px' tabindex='6'></td></tr><tr><td>&nbsp;</td></tr></table>";
		subj.style.visibility="visible";
	}else{
		subj.innerHTML="<span style='padding:-40px 0px -40px 0px;'></span>";
		subj.style.visibility="hidden";
	}
}

// script for offers and about us 
function showoffer(n)
{
var a,b,i,j,f;
var _gaq = _gaq || [];
f=n.substring(0,3);
if(f=="sor")
m=5;
if(f=="shp")
m=4;
if(f=="eva")
m=5;
if(f=="che")
m=2;
if(f=="abt")
m=4;

for(i=1;i<=m;i++)
{
	j=f.concat(i);
	b=document.getElementById(j);
	b.style.display='none';
}

a=document.getElementById(n);
a.style.display='block';

_gaq.push(['_trackEvent', 'Button', 'Shopping Arrow Button', 'Member Home']);

}




function bb()
{

window.open('<tri:Url Content="pop"/>','pop','toolbar=no, statusbar=no, location=no, scrollbars=no, resizable=no, width=400, height=340')
}

function getpoppos(){
t=$('.popoffer').position().top;

if(t<260)
{
$('.previewalign').css({top:-60});
}

if((t>260) && (t<450))
{
$('.previewalign').css({top:-200});
}

if(t>450)
{
$('.previewalign').css({top:-600});
}

t=$('.popoffer').position().top;
//alert(t);

}
