// JavaScript Document<script type="text/javascript">

var xmlHttp = false;
//funzioni aJax
function initAjax()
{

try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }


	return xmlHttp;

  }
  
  function SendAjaxRequest(id,language,type)
  {
  	var xmlHttp =  initAjax();
	
  	xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      	OnDataReceived(xmlHttp.responseText,id);
      }
    }
	
	var query = GetValueForm(id);
	
	query = query + "&idRecord=" + id + "&language=" +  language + "&type=" + type
	
	var loader = document.getElementById('loader' + id);
	var sendMailBtn = document.getElementById('sendMail' + id);
	
	loader.style.display="block";
	sendMailBtn.value = "...inviando";
	
  xmlHttp.open("GET","/dynamic/common/send_mail.asp?" + query,true);
  xmlHttp.send(null);
  }
  
  function OnDataReceived(testo,id)
  {
  	var res = xmlHttp.responseText;
	var objBox = document.getElementById('boxEmail' + id);
	var form = document.getElementById('form' + id);
	var conferma = document.getElementById('confirm' + id);
	var error = document.getElementById('error' + id);

	var loader = document.getElementById('loader' + id);
	loader.style.display="none";

	var sendMailBtn = document.getElementById('sendMail' + id);
	sendMailBtn.value = "Invia";
	
	if (testo.indexOf('true') >= 0)
	{
		error.style.display="none";
		conferma.style.display="block";
	}else
	{
		conferma.style.display="none";
		error.style.display="block";
	}
	
  }
  
  function GetValueForm(id)
  {
  		var url;
  		var mailDest = document.getElementById("mailDest" + id);
		var mailMit = document.getElementById("mailMySelf" + id);
		var mailContx = document.getElementById("mailContent" + id);
		
		url = "mailTo=" + mailDest.value  + "&mailFrom="  + mailMit.value + "&msg=" + mailContx.value

		return url;
  }

