/*
 * Fonction javascript pour l'identification de l'utilisateur
 * =========================================
 */
 
function changeLangue()
//=====================
{
  document.location = './index.php?lang='+$F('langue');
}
 
function verifContactCod()
//========================
{  
   //cas si codutil est vide
   if ($F('contact_cod') == '') {
    $('msg_codutil').innerHTML = msg_login_manquant;
  }
  //cas si codutil n'est pas vide
  else {
    $('msg_codutil').innerHTML = '&nbsp;';
  }
}

function verifPassword()
//======================
{  
   //cas si codutil est vide
   if ($F('password_cod') == '') {
    $('msg_pwd').innerHTML = msg_mdp_manquant;
  }
  //cas si codutil n'est pas vide
  else {
    $('msg_pwd').innerHTML = '&nbsp;';
  }
}

function verif()
//==============
{
	verif_pwd();
	verif_contact_cod()
	valider();
}

/**
 * Validation du formulaire
 */
function valider()
//================
{
	//login et password non vides
	if (($F('password_cod') !='' ) && ($F('contact_cod') != ''))
	{
			// envoie le formulaire au serveur
			$('formulaire').submit(); 
	}
}	

function msg_erreur(msg)
//======================
{
	if (msg!=null)
	if (msg!='')
	openPopupErreur('Login',msg);

}


function garder(login,pwd)
//========================
{
	$('contact_cod').value=login;
	$('password_cod').value=pwd;
}

function initAccueil()
//====================
{
  if ($F('contact_cod') != '') {
    Field.focus('password_cod');
  }
  else {
    Field.focus('contact_cod');
  }
}

function demandeMdp()
//===================
{
  $('envMdp1').value = $F('contact_cod');
  var txt = '<TABLE border="0" width="400px"><TR><TD><FIELDSET><LEGEND>'+msg_ident_mail+'</LEGEND>';
  txt += '<TABLE><TD width="100px">'+lib_identifiant+' : </TD>';
  txt += '<TD><input type="texte" id="login" class="ZoneForm150" value="'+$F('contact_cod')+'" onchange="majZoneMdp(this,1);" /></TD></TR>';
  txt += '<TR><TD>'+lib_email+' : </TD>';
  txt += '<TD><input type="texte" id="email" class="ZoneForm250"  onchange="majZoneMdp(this,2);" /> </TD></TR></TABLE></FIELDSET></TD>';
  txt += '<TR><TD align="center" height="30px">';
  txt += '<div class="btVertValid" onclick="envoiMdp();">'+bt_envoyer+'</div>';
  txt += '</TD>';
  txt += '</TR></TABLE>';
  
  openPopupRico(mdp_oublie,txt,'auto','auto',450,300,'',0,0);
}

function envoiMdp()
//=================
{
  var param = 'login='+$F('envMdp1')+'&email='+$F('envMdp2')+'&Action=ENVOIMDP&Retour=XML';
  new Ajax.Request('./cli/contact/GesCli_contact.php',
    {
      method: 'get',
      parameters: param,
      onComplete: retourMdp
    }
  );
}

function retourMdp(retour)
//========================
{
  var xml = retour.responseXML;  
  var reponse = xml.getElementsByTagName("REPONSE")[0];
  var okExist = reponse.getElementsByTagName("ENVOI_OK")[0].firstChild.nodeValue;
  
  var icone = 'Info';
  var titre = msg_mdp_envoye;
  var msg = msg_conf_envoi;
  if (okExist == 'N') {
    icone = 'Warning';
    titre = lib_util_inconnu;
    msg = msg_util_inconnu;
  }

  var txt = '<TABLE border="0" width="100%"><TR>';
  txt += '<TD align="center" valign="middle" height="75px"><IMG SRC="./gene/icone/'+icone+'.png" width="50px" height="50px" /></TD>';
  txt += '<TD align="center" valign="middle">'+msg+'</TD>';
  txt += '</TR><TR>';
  txt += '<TD align="center" colspan="2">';
  txt += '<div class="btVertValidPt" onclick="closeBoxRico();">'+popup_bt_ok+'</div>';
  txt += '</TD>';
  txt += '</TR></TABLE>';

  openPopupRico(titre,txt,'7em','20em',450,300,'',0,0);
  
}

function majZoneMdp(composant,num)
//================================
{
  var zone = 'envMdp'+num;
  $(zone).value = composant.value;
}

function favoris(title, location) 
//===============================
{
	if ( navigator.appName != 'Microsoft Internet Explorer' )	{
    window.sidebar.addPanel(title, location, ""); 
	}
	else { 
	  window.external.AddFavorite(location, title); 
	} 
}
