function codeCountry()
{
    // Rempli les champs de code de téléphone en fonction du choix dans la liste des pays

    var code;
    code = document.inscription.id_countries[document.inscription.id_countries.selectedIndex].value;
    code = code.substring(3, code.length);
    document.inscription.par_code_phone.value = code;
    document.inscription.par_code_mobile.value = code;
    document.inscription.par_code_fax.value = code;
    document.inscription.par_assistant_code_phone.value = code;

}


function badge_popup(data,page,formName)
{
    // On récupère les élèments demandé
    var check = document.forms[formName].elements[data];
    wdth = (screen.availWidth*80)/100;
    hgth = (screen.availHeight*80)/100;
    var request = '';

    request += 'id=';
    var float = 0;

    for(i=check.length-1;i>=0;i--)
    {
        if(check[i].checked == true)
        {
            id_contact = check[i].id.substr(6,check[i].id.length-6);
            if(float!=0) request+=",";
            request += id_contact;
            float = 1;
        }
    }
    if(check.length==null)
    {
        request += document.forms[formName].elements[data].value;
    }

    window.open(page+'?'+request,'','location=no,menubar=no,toolbar=no,status=yes,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top=15,left=15,screenx=0,screeny=0');


}

function ajout_marqueur(champ,marqueur)
{
    // Ajoute juste le marqueur aprés clic sur celui-ci
    document.getElementById(champ).value += marqueur+',';
}

function active(id,method)
{
    // Activer une ligne de participant aprés un clic sur le checkbox
    // Selon method, si == check, c'est un clic sur le check
    // sinon, c'est appelé par une fonction avec juste l'ID
    if(method == 'check')
    {
        if(document.getElementById('check_'+id).checked == 1)
        {
            document.getElementById('Row_'+id).style.background = '#FFDFA4';

        }
        else
        {
            document.getElementById('Row_'+id).style.background = '#ffffff';
        }
    }
    else
    {
        if(document.getElementById('check_'+id).checked == 1)
        {
            document.getElementById('Row_'+id).style.background = '#ffffff';
            document.getElementById('check_'+id).checked = 0;
        }
        else
        {
            document.getElementById('Row_'+id).style.background = '#FFDFA4';
            document.getElementById('check_'+id).checked = 1;
        }
    }
}

function selectAll(formName,toCheck)
{
    // Sélectionne ou déselectionne tous les row de la page

    var check = document.forms[formName].elements[toCheck];
    action = document.forms[formName].elements['toCheck'];

    for(i=0;i<check.length;i++)
    {
        id = 'Row_' + check[i].id.substr(6,check[i].id.length-6);
        if(action.value == 'check')
        {
            check[i].checked = true;
            document.getElementById(id).style.background = '#FFDFA4';
        }
        else
        {
            check[i].checked = false;
            document.getElementById(id).style.background = '#ffffff';
        }
    }

    if(check.length == null)
    {
        id = 'Row_' + check.value;
        if(action.value == 'check')
        {
            check.checked = true;
            document.getElementById(id).style.background = '#FFDFA4';
        }
        else
        {
            check.checked = false;
            document.getElementById(id).style.background = '#ffffff';
        }
    }

    if(action.value == 'check') action.value='uncheck';
    else action.value = 'check';

}

function exportVcard(data,page,formName)
{
    // On récupère les élèments demandé
    var check = document.forms[formName].elements[data];

    var request = '';

    request += 'id=';
    var float = 0;

    for(i=check.length-1;i>=0;i--)
    {
        if(check[i].checked == true)
        {
            id_contact = check[i].id.substr(6,check[i].id.length-6);
            if(float!=0) request+=",";
            request += id_contact;
            float = 1;
        }
    }
    if(check.length==null)
    {
        request += document.forms[formName].elements[data].value;
    }
    window.open(page+'?'+request,'','location=no,menubar=no,toolbar=no,status=no,scrollbars=1,resizable=0,width=10,height=10,top=15,left=15,screenx=0,screeny=0');

}

function windowOpen(w,h,page)
{
    wdth = (screen.availWidth*w)/100;
    hgth = (screen.availHeight*h)/100;
window.open(page,'','location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top=20,left=20,screenx=0,screeny=0,');
}

function Loop(page,method,contenu)
{
   sendData('','count_progress.php', 'GET', 'progress',false);
   setTimeout(Loop,1000);
}

function contactEdit(data,link,formName,argument)
{

    wdth = (screen.availWidth*80)/100;
    hgth = (screen.availHeight*80)/100;
    var top =  10;
    var left = 10;
    if(data == 'new')
    {
    window.open(link+'?new&height='+hgth,'','location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top='+top+',left='+left+',screenx=0,screeny=0,');
    return false;
    }

    // On récupère les élèments demandé
    if(argument == true) var check = document.forms[formName].elements[data];
    else var check = document.getElementById(data);

    for(i=0;i<check.length;i++)
    {
        id_contact = check[i].id.substr(6,check[i].id.length-6);
        if(check[i].checked == true)
        {
        window.open(link+'?id='+id_contact+'&height='+hgth,'','location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top='+top+',left='+left+',screenx=0,screeny=0,');
        top = top+30;
        left = left+30;
        if(left+wdth > screen.availWidth) left = 0;
        if(top+hgth > screen.availHeight) top = 0;
        }
    }
    if(check.length==null) window.open(link+'?id='+document.forms[formName].elements[data].value,'','location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top='+top+',left='+left+',screenx=0,screeny=0,');
}

function googleMap(data,link,formName,argument)
{

    wdth = (screen.availWidth*80)/100;
    hgth = (screen.availHeight*80)/100;
    var top =  10;
    var left = 10;

    // On récupère les élèments demandé
    if(argument == true) var check = document.forms[formName].elements[data];
    else var check = document.getElementById(data);
    var id_contact = '';
    for(i=0;i<check.length;i++)
    {
        test = check[i].id.substr(6,check[i].id.length-6);
        if(check[i].checked == true)
        {
            if(id_contact == '') id_contact = test;
            else id_contact = id_contact + ',' + test;
        }
    }

    window.open(link+'?id='+id_contact+'&height='+hgth+'&width='+wdth,'','location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,resizable=1,width='+wdth+',height='+hgth+',top='+top+',left='+left+',screenx=0,screeny=0,');
}

function marqueur(id)
{
    var typ = document.getElementsByName('type_tag');
    for(i=0;i<typ.length;i++)
    {
        if(typ[i].checked == true) var typ_tag = typ[i].value;
    }
    id_tag = 'tag_' + id;
    var tag = document.getElementById('tag_search').value.split(',');
    if(document.getElementById(id_tag).className == 'select')
    {
       document.getElementById(id_tag).className = '';
       for(i=0;i<tag.length;i++)
       {
           if(tag[i]==id) {  tag.splice(i,1); }
           if(tag[0] == '') tag.shift();
           document.getElementById('tag_search').value = tag.join(',');
       }
    }
    else
    {
       document.getElementById(id_tag).className = 'select';
       tag.push(id);
       if(tag[0] == '') tag.shift();
       document.getElementById('tag_search').value = tag.join(',');
    }

if(document.getElementById('search_contact').value != '')
{
    var request = 'search=' + document.getElementById('search_contact').value + "&";
}
else var request = '';
request += 'tag=' + document.getElementById('tag_search').value + "&typ="+typ_tag;
sendData(request,'contact_list.php','GET', 'list_contact',true);

}

function changeTypTag(typ)
{
if(document.getElementById('search_contact').value != '')
{
    var request = 'search=' + document.getElementById('search_contact').value + "&";
}
else var request = '';
request += 'tag=' + document.getElementById('tag_search').value + "&typ="+typ;
sendData(request,'contact_list.php','GET', 'list_contact',true);
}

function init_editor()
{
  if(document.all)
  {
    edoc = window.frames['content'].document;
    edoc.designMode = 'On';
    window.frames['content'].document.innerHTML = document.getElementById('htmlContent').value ;
  }
  else
  {
  edoc = document.getElementById('content').contentDocument;
  edoc.designMode = 'On';
  edoc.body.innerHTML = document.getElementById('htmlContent').value ;
  }

}

function setContent(action,userInterface,value)
{
    if(document.all)
    {
        ewin = window.frames['content'];
        edoc = ewin.document;
        edoc.execCommand(action, userInterface,value);
        ewin.focus();
    }
    else {
        ewin = document.getElementById('content').contentWindow;
        edoc = document.getElementById('content').contentDocument;
        edoc.execCommand(action, userInterface, value);
        ewin.focus();
    }
}

function addLink()
{
var URL = prompt("Entrer l'URL", "");
if(URL) setContent('CreateLink',false,URL);
}

function addImg()
{
var URL = prompt("Entrer l'URL", "");
setContent('InsertImage',false,URL);
}

function translate()
{
edoc = document.getElementById('content').contentDocument;
document.getElementById('htmlContent').value = edoc.body.innerHTML;
}


function test()
{
 alert('test');
}