function AbnTools(lsTitle, liNewsLetterID, lsDescription, lsImageName, liImageWidth, liImageHeight, lsquestionnaire, lsTermsUrl){
	this.title					= lsTitle;
	this.newsLetterID			= liNewsLetterID;
	this.description			= lsDescription;
	this.imageName				= lsImageName;
	this.termsUrl				= lsTermsUrl;
	this.index					= AbnTools.items.length;
	this.imageHeight			= liImageHeight;
	this.imageWidth				= liImageWidth;
	this.questionnaire          = lsquestionnaire;
	AbnTools.items[this.index] = this;
}

AbnTools.items					= [];/*Array for abnTools objects*/
AbnTools.protocol				= location.protocol=='https://'?'https://':'http://';
AbnTools.imagePath_fr				 = 	'prod.abocollecte.com/prod/logoProd/'; /*Chemin d'acc�s aux images*/
AbnTools.isCheckBox            = true; /*Permet de savoir si on utilise des boutons radio (false) ou des checkbox (true)*/
AbnTools.url_visit             = '';/*'http://www.abonews-france.com/visit.asp';*/
AbnTools.url_styles            = '';/*'http//www.abonews-france.com/abonews/styles/.css';*/

function Remplace(str,find,rep) {
   if(str != '' || str != null) {
       var tmp = "";
       for(var i=0; i < str.length; i++) {
           tmp = tmp + str.charAt(i);
           if (str.charAt(i) == find) {
               tmp = tmp.replace(find,rep);
           }
       }
       str = tmp;
       return tmp;
   }
}
function commencePar(str, start) {
   return (str.match("^"+start)==start);
}
function verifierTextelibre(texte){}
function verifierTelfixe(tel) {
  var tmp = tel.value;
  tmp = Remplace(tmp,"-","");
  tmp = Remplace(tmp,".","");
  tmp = Remplace(tmp," ","");
  tmp = Remplace(tmp,"_","");
  tmp = Remplace(tmp,"(","");
  tmp = Remplace(tmp,")","");
  var regexpTelfixe = /^(01|02|03|04|05|08|09)[0-9]{8}$/;
  if(!regexpTelfixe.test(tmp)) {
      alert("Ce num\351ro de t\351l\351phone fixe n'est pas correct. ");
  }
}
function verifierTelmobile(tel){
  var tmp = tel.value;
  tmp = Remplace(tmp,"-","");
  tmp = Remplace(tmp,".","");
  tmp = Remplace(tmp," ","");
  tmp = Remplace(tmp,"_","");
  tmp = Remplace(tmp,"(","");
  tmp = Remplace(tmp,")","");
  var regexpTelmobile = /^(06)[0-9]{8}$/;
  if(!regexpTelmobile.test(tmp)){
      alert("Ce num\351ro de t\351l\351phone mobile n'est pas correct");
  }
}
function verifierCodepostal(codepostal){
  var tmp = codepostal.value;
  tmp = Remplace(tmp,"-","");
  tmp = Remplace(tmp,".","");
  tmp = Remplace(tmp," ","");
  tmp = Remplace(tmp,"_","");
  tmp = Remplace(tmp,"(","");
  tmp = Remplace(tmp,")","");
  var regexpCodepostal = /^[0-9]{5}$/;
  var regexpCodepostalCorse = /^(OZA|oza|OZB|ozb)[0-9]{3}$/;
  if(regexpCodepostal.test(tmp) || regexpCodepostalCorse.test(tmp)){}
  else {
      alert("Ce code postal n'est pas correct");
  }
}
function verifierDate(date){
  if(commencePar(date.id, 'sA')){
      var idjour = 'sADateJ'+date.id.substr(7);
      var idmois = 'sADateM'+date.id.substr(7);
      var idannee = 'sADateA'+date.id.substr(7);
      var jour = document.getElementById(idjour);
      var mois = document.getElementById(idmois);
      var annee = document.getElementById(idannee);
      switch(mois.value){
          case '04' : case '06' : case '09' : case '11' :
              if(jour.value == '31'){ jour.value = '30';}
              break;
          case '02' :
              if(jour.value == '30' || jour.value == '31'){ jour.value = '29';}
              break;
      }
  }
  var idCache = 'specificAnswer'+date.id.substr(7);
  var cache = document.getElementById(idCache);
  cache.value = jour.value+'/'+mois.value+'/'+annee.value;
}


AbnTools.validation = function () {
  var valid = true;
  /* Si le formulaire est avec des boutons radio*/
  if (!AbnTools.isCheckBox) {
      /* on récupère les composants input */
      var loCheckBoxes = document.getElementById('abntoolcheckboxes').getElementsByTagName('input');
      for(var iAbnTools = 0; iAbnTools < loCheckBoxes.length; iAbnTools++) {
          /* on récupère l'id du contrôle en cours */
          var id = "" + loCheckBoxes[iAbnTools].id;
          /* si le composant est un bouton radio d'abonnement à une news letter (oui) */
          if (id.substring(0,11) == "abntoolsOui") {
              /* si le bouton radio oui n'est pas selectionné */
              if (loCheckBoxes[iAbnTools].checked == false) {
                  /* si le bouton radio non correspondant n'est pas coché non plus */
                  if ( document.getElementById('abntoolsNon' + id.substring(11,id.length) ).checked == false ) {
                      /* message d'alert */
                      alert("Vous devez indiquer votre choix pour toutes les newsletter");
                      /* retourne faux */
                      valid = false;
                  }
              }
          }
      }
  }
  return valid;
}


document.write('<table><tr><td><input name="idSitePartenaire" type="hidden" value="39"/></td><td><input name="idPartenaire" type="hidden" value="29"/></td></tr></table>');

AbnTools.Display = function(){/*routine for displaying each abnTools newsletter*/
	for(var i = 0;i<AbnTools.items.length;i++){
		AbnTools.items[i].display();
	}
}
AbnTools.showhideAbnTools = function(oElem){
	var oDiv = document.getElementById('abntoolsdiv');
	oDiv.style.display = 'block';
	return true;
}

AbnTools.selectAllAbnTools = function (oElem){

	var loCheckBoxes = document.getElementById('abntoolcheckboxes').getElementsByTagName('input');
    var isChecked = oElem.checked;
    
    if (AbnTools.isCheckBox)
	{
    	for(var iAbnTools = 0; iAbnTools < loCheckBoxes.length; iAbnTools++){
            var id = "" + loCheckBoxes[iAbnTools].id;
	        if (id.substring(0,11) == "abntoolsChk")
	        {
	            loCheckBoxes[iAbnTools].checked = !isChecked;
	            loCheckBoxes[iAbnTools].click();
	        }
        }
        oElem.checked = isChecked;
	} else {
	    //alert("ALERT : "+oElem.id+" "+oElem.checked+" : "+isChecked);
		for(var iAbnTools = 0; iAbnTools < loCheckBoxes.length; iAbnTools++){
		    var id = "" + loCheckBoxes[iAbnTools].id;
		    if (isChecked)
		    {
		        if (id.substring(0,11) == "abntoolsOui")
		        {
		            loCheckBoxes[iAbnTools].checked = true;
		            loCheckBoxes[iAbnTools].click();
		        }
		    } else {
		        if (id.substring(0,11) == "abntoolsNon")
		        {
		            loCheckBoxes[iAbnTools].checked = true;
		            loCheckBoxes[iAbnTools].click();
		        }
		    }
	    }
	}	
	return true;
}

afficheQuestionnaire = function(idNewsletter,ouiNon){
    //alert("ALERT affiche: "+idNewsletter+" : "+ouiNon);
	var oDiv = document.getElementById('questionnaire' + idNewsletter);
	if (oDiv != null)
	{
	    if(ouiNon)
	        oDiv.style.display="block";
	    else
	       oDiv.style.display="none";
	}
	return true;
}

AbnTools.getImage	= function(lsURL, lsOnclick, lsAlt, lsStyle){
	var loImg		= new Image();
	loImg.src		= lsURL;
	var lsWidth		= loImg.width?'width="'+ loImg.width +'"':'';
	var lsHeight	= loImg.width?'width="'+ loImg.width +'"':'';
	lsOnclick		= lsOnclick?'onclick="'+ lsOnclick +'"':'';
	lsAlt			= lsAlt||'';
	lsStyle			= lsStyle||'';
	
	return '<img src="'+loImg.src+'" '+lsWidth+' '+lsHeight+' align="middle" '+lsOnclick+' style="'+lsStyle+'" alt="'+lsAlt+'">';
}

function CheckCheckbox(lsName)
{
	var chk = eval('document.all.' + lsName);
	
	if (chk.checked==true)
	{
		chk.checked=false;
	}
	else
	{
		chk.checked=true;
	}
}

AbnTools.prototype.display	= function(){

	var lsHTML = '<tr>'+
	'<td class="dots" colspan="5"><img src="' + AbnTools.protocol +
	AbnTools.imagePath_fr +'spacer.gif" width="1" height="20"></td>'+
	'</tr>'+
	'<tr>'+
	'<td valign="top">' +
		'<img src="' + AbnTools.protocol + AbnTools.imagePath_fr + this.imageName + '" width="'+
		this.imageWidth +'" height="'+ this.imageHeight +'" align="left" alt="'+ this.title +
		'"></td><td><img src="'+ AbnTools.protocol + AbnTools.imagePath_fr + 'spacer.gif" width="5" height="1" alt="" /></td><td>'+
		'<span class = "ClickableRow" onclick="document.getElementById(\'abntools' + this.index +
		'\').click();"><label for="abntools' + this.index +'" class="newsletterDescription_Text">'+
		this.description+'</label></span>&nbsp;';
	
lsHTML = lsHTML + '</td><td><img src="/images/spacer.gif" width="5" height="1" alt="" /></td><td align="right" valign="top" >'+'<input type="checkbox" name="abntoolsChk' +this.index +'" value="'+this.newsLetterID+'" id="abntoolsChk' +this.newsLetterID +'" class="newsletterCheckbox" onclick="afficheQuestionnaire('+this.newsLetterID+',this.checked);document.getElementById(\'_abntoolsselectall\').checked=false;if(!this.checked){document.getElementById(\'_abntoolsselectall\').checked=false;}">'+'</td>'+'</tr>';
	if (this.questionnaire != undefined){
	lsHTML = lsHTML + '<tr><td colspan="5"><div id="questionnaire'+this.newsLetterID +'" style="display:none">'+ this.questionnaire +'</div></td></tr>';
	}
	/*lsHTML = lsHTML + '</table>';*/
	document.write(lsHTML);
}
			
AbnTools.UseStyleSheet		= false
AbnTools.CheckboxName		= 'AbnToolsNewsletter';
AbnTools.RadioName         = 'AbnToolsNewsletter';

/*#CreeAbnTools#*/

if(AbnTools.UseStyleSheet){
		document.write('<link rel="stylesheet" href="'+AbnTools.url_styles+'">');
}
document.write('<style>.dots {background-image: url(/abonews/images/dots.gif);'+
				' background-repeat: repeat-x; background-position: 50% 50%;}</style>');

document.write('<div style="display:block" id="abnToolsdiv">' +
	'<table cellpadding="0" cellspacing="0" border="0" id="abntoolcheckboxes" width="100%" class="abntoolsListTable">' +
	'<tr>' +
	'<td class="dots" colspan="5"><img src="' + AbnTools.protocol +
	AbnTools.imagePath_fr +'spacer.gif" width="1" height="20"></td>' +
	'</tr>' +
	'<tr>' +
	'<td colspan="4" class=ClickableRow onclick="document.getElementById(\'_abntoolsselectall\').click()">');

/*Ligne qui permet de selectionner toutes les newsletter*/
document.write('S&eacute;lectionner toutes les newsletters');/*writes select all image*/
document.write('</td>' +
	'<td><input type="checkbox" name="_abntoolsselectall" onclick="AbnTools.selectAllAbnTools(this)"'+
	' id="_abntoolsselectall" class="newsletterCheckbox"></td>' +
	'</tr>' +
	'</tr>');
				
AbnTools.Display()/*displays newsletters by calling display() method for each webbrand object*/

document.write('<tr>' +
	'<td class="dots" colspan="5" width=500 style="width:500;"><img src="' +
	AbnTools.protocol +
	AbnTools.imagePath_fr +
	'spacer.gif" width="1" height="20"><iframe style="position:absolute;left:-20000;"'+
	' src="'+AbnTools.url_visit+'" height="0px" width="0px"></iframe></td>' +
	'</tr>' +
	'</table>' +
	'</div>');
