/*******************/
/* SEND_FRIEND.JS */
/*****************/

/////// LANG ////////
if(langGlobal == "fr"){
  //msg fr
	var msg_mailnonvalide="L'email n'est pas valide !";
	var bouton_envoyer="Envoyer";
	var bouton_fermer="Fermer";
}else{
  //msg en
	var msg_mailnonvalide="Unvalid email address !";
	var bouton_envoyer="Send";
	var bouton_fermer="Close";
}
////// END LANG ///////


function close_pop() {
  var div_to_put = window.document.getElementById('toto');
  child = window.document.getElementById('tell');
  div_to_put.removeChild(child);
  //IE...
  if (document.all) {
    window.document.getElementById('img_friend').onclick=aff_div_envoi;
  //FF
  } else {
    window.document.getElementById('img_friend').setAttribute("onclick","aff_div_envoi()");
  }

}

function aff_div_envoi(id_item, type) {
  //IE...
  if (document.all) {
    window.document.getElementById('img_friend').onclick='';
  //FF
  } else {
    window.document.getElementById('img_friend').setAttribute("onclick","");
  }

var div_to_put = window.document.getElementById('toto');
div_add = window.document.createElement("div");
div_add.id="tell";
div_add.style.width="280px";
div_add.style.height="40px";
div_add.style.border="solid 1px #000000";
//div_add.style.left=mouseX;
//div_add.style.top=mouseY;
div_add.style.position="relative";

div_add.innerHTML="<div><table><tr><td><img height='25' src='images/view_lieu/icone_action_sendfriend.gif' alt='' /></td>"+
"<td><form id='form_sendmail' action='hejo_mailer.php' method='post' onsubmit='return check_mail();'>"+
"<input type='hidden' name='dispatch' value='send_item'>"+
"<input type='hidden' name='type' value='"+type+"'>"+
"<input type='hidden' name='id_item' value='"+id_item+"'>"+
"<input id='champ_mail' type='text' name='to' value='email address' onclick='this.value=\"\";' class='inputcourant' />"+
"&nbsp;<input type='button' value='"+bouton_envoyer+"' onclick='check_mail();' class='inputcourant' /></form></td>"+
"<td><input type='button' value='"+bouton_fermer+"' onclick='close_pop()' class='inputcourant' alt='' /></td></tr></table><div>";
div_to_put.appendChild(div_add);


}

function check_mail() {
  var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" ) ;
  var mail = window.document.getElementById('champ_mail');
  if (mail.value.search(maReg) == -1)  {
    alert(msg_mailnonvalide);
    mail.focus();
    return false;
  } else {
    window.document.getElementById('form_sendmail').submit();
    return true;
  }
}

