$(document).ready(function(){
//
$("#short").keyup(function () { $("#do").text("http://echap.net/" + $(this).val());
        }).change();
		
//
$('a.ema').each(function(){
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
		});

$('#ex').hide();

$('#show_ex').click(function(){
		$('#ex').slideToggle("slow");					
		});

$('.corn').corner();


});

////////////////////////////////////////////////////////////////////////////////////

function validin(evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	var nop = 'àâäãçéèêëìîïòôöõùûüñ &*?!:;,#~"^¨%$£?²¤§%*()[]{}<>|\\/`\'';
	if (nop.indexOf(String.fromCharCode(keyCode)) >= 0) {
		return false;
	}
}


function add_fav() {
	if (window.sidebar)
   {
   window.sidebar.addPanel("créer l'url", 'http://echap.net/create.php?url='+escape(location.href),"");
   }
   else if( document.all )
   {
   window.external.AddFavorite('http://echap.net/create.php?url='+escape(location.href), "créer l'url !");
   }
   else
        {
   return true;
   } 
}

function copicol()
{/*
  	var textRange = document.body.createTextRange();
  	textRange.moveToElementText(document.getElementById('ui'));
  	textRange.execCommand("Copy");*/
	window.clipboardData.setData("Text",document.getElementById('ui').value());
}

//////////////////////////////////////////////////////////////////////////////////// 

var http; // Notre objet XMLHttpRequest

function createRequestObject()
{
    var http;
    if(window.XMLHttpRequest)
    { // Mozilla, Safari, ...
        http = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    { // Internet Explorer
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return http;
}

function dourl()
{
	var url = escape(document.getElementById("url").value);
	var short = escape(document.getElementById("short").value);
	var data = 'url='+url+'&short='+short;
    document.getElementById('ajax').innerHTML =  '';
    http = createRequestObject();
    http.open('GET', 'create.php?'+data, true);
	http.send(null);
    http.onreadystatechange = handleAJAXReturn;
    
}

function handleAJAXReturn()
{
    if(http.readyState == 4)
    {
        if(http.status == 200)
        {
            if(http.responseText != 'nok')
			{ document.getElementById('ajax').innerHTML = '<strong>Félicitations : </strong> votre lien est accessible via <a href="http://echap.net/'+ http.responseText +'">http://echap.net/'+ http.responseText +'</a>';
			}
			else
			{
			document.getElementById('ajax').innerHTML = '<strong>Erreur : </strong>L\'url demandée est déjà prise ....';
			}
			
        }
        else
        {
            document.getElementById('ajax').innerHTML = "empty";
        }
    }
}

