
function stripVowelAccent(str)
{
var s=str;

var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
/[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
/[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
/[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
/[\xD9-\xDB]/g, /[\xF9-\xFB]/g ];

var repChar=['A','a','E','e','I','i','O','o','U','u'];

for(var i=0; i<rExps.length; i++)
s=s.replace(rExps[i],repChar[i]);

return s;
}

function ajaxTwitter(link,idBlock)
{
  var connection = ajaxConnection();
  connection.onreadystatechange=function()
  {
    if(connection.readyState==1) document.getElementById(idBlock).innerHTML= '<a>Connexion à Twitter...</a>';
    if(connection.readyState==4)
    {
      var response = connection.responseText;
      document.getElementById(idBlock).innerHTML= '<a target="_blank" href="http://twitter.com/home?status=Ma+nouvelle+création+Seyes+:+%20'+response+'">Twitter cette création</a>';
    }
  }

  var url="http://www.seyes.fr/transport.php?action=http://tinyurl.com/api-create.php&method=get&url="+escape(link);
  connection.open("GET",url,true);
  connection.send(null);
}

function ajaxSendgift(url,sku,idBlock)
{

  document.getElementById(idBlock).style.display = 'block';

  var connection = ajaxConnection();
  connection.onreadystatechange=function()
  {
    if(connection.readyState==1) ajaxAttente(idBlock);
    if(connection.readyState==4)
    {
      var response = connection.responseText;
      document.getElementById(idBlock).innerHTML=response;
    }
  }
  var link = generateLink(url,sku);
  url = url + "sendgift/ajax/send";
  url = url + "?url=" + escape(link);
  connection.open("GET",url,true);
  connection.send(null);
}

function ajaxSendgiftValidate(url,idBlock)
{

  var connection = ajaxConnection();
  connection.onreadystatechange=function()
  {
    if(connection.readyState==1) ajaxAttente(idBlock);
    if(connection.readyState==4)
    {
      var response = connection.responseText;
      document.getElementById(idBlock).innerHTML=response;
    }
  }

  var senderName = stripVowelAccent(document.getElementById('senderName').value);
  var senderMail = document.getElementById('senderMail').value;
  var recipientMail = document.getElementById('recipientMail').value;
  var message = stripVowelAccent(document.getElementById('message').value);
  var gifturl = document.getElementById('gifturl').value;

  if(senderName == '' || senderMail == '' || recipientMail == '') {
    document.getElementById('sendgiftValidate').innerHTML = 'Vous avez oublié certaines informations obligatoires';
  }
  else {
    url = url + "sendgift/ajax/validate";
    url = url + "?senderName=" + senderName + "&senderMail=" + senderMail + "&recipientMail=" + recipientMail + "&message=" + message + "&gifturl=" + escape(gifturl);
    connection.open("GET",url,true);
    connection.send(null);
  }
}

function ajaxInspirations(idInspiration,idBlock)
{
  var connection = ajaxConnection();
  connection.onreadystatechange=function()
  {
    if(connection.readyState==1) ajaxAttente(idBlock);
    if(connection.readyState==4)
    {
      var response = connection.responseText;
      document.getElementById(idBlock).innerHTML=response;
    }
  }

  var url="inspirations/ajax/preview";
  url=url+"?id="+idInspiration;
  url=url+"&sid="+Math.random();
  connection.open("GET",url,true);
  connection.send(null);
}


/* FONCTIONS GLOBALES */

function ajaxAttente(idBlock)
{
  document.getElementById(idBlock).innerHTML='<img class="ajaxloader" src="http://www.seyes.fr/seyes_ajaxloader.gif"/>';
}

function ajaxConnection() {

  var xmlhttp;
  if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    return xmlhttp;
  }
  else if (window.ActiveXObject)
  {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlhttp;
  }
  else
  {
    alert("Your browser does not support XMLHTTP!");
  }
}


