	google.loader.ApiKey='ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q';
	google.load('language','1');
	google.setOnLoadCallback(init);
	
	function init() {
		document.getElementById('xx').disabled=false;
		document.getElementById('yy').disabled=false;
		document.getElementById('loading').innerHTML = '';
		document.getElementById('xx').focus();
		checkdomain();
	}
	
	function del(){
		document.getElementById('xx').focus();
		document.getElementById('xx').value='';
		document.getElementById('yy').value='';		
	}
	function xfr(text,a,b){
		if( text.length == 0 ) return false;
		text=text.substring(0,512);
		google.language.translate(text,a,b,function(res){
			if(!res.error) document.getElementById('yy').value=unescapeHTML(res.translation);
			else document.getElementById('yy').value='Error';
		});
	}
	function yfr(text,a,b){
		if( text.length == 0 ) return false;
		text=text.substring(0,512);
		google.language.translate(text,a,b,function(res){
			if(!res.error) document.getElementById('xx').value=unescapeHTML(res.translation);
			else document.getElementById('xx').value='Error';
		});
	}
	function xajax(u,l1,l2,text,div) {	
		try{
			http = new XMLHttpRequest();
		} catch (e){
			try{
				http = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					http = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					alert("Your browser broke!");
					return false;
				}
			}
		}
		var url = "ajax/"+u+".php";
		var params = "l1="+l1+"&l2="+l2+"&text="+text;
		http.open("POST", url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = function() {
			if( http.readyState == 4 ) {
				//alert(http.responseText);
				document.getElementById(div).value = http.responseText;
				document.getElementById('loading').innerHTML = '';
			} else {
				document.getElementById('loading').innerHTML = "<img src='images/spinner.gif'>";
			}
		}
		http.send(params);
	}
	
	function trad(a,b,w) {
		var url = w;
		document.getElementById('xx').focus();
		var x = document.getElementById('xx').value;
		var y = document.getElementById('yy').value;
		if( x.length==0 && y.length==0 ) return false;
		if( x.length > 0 && y.length==0 ) xajax(url,a,b,x,'yy');
		if( x.length == 0 && y.length>0 ) xajax(url,b,a,y,'xx');			
	}
	
	function checkdomain() {
		var ok = false;
		var domm = document.domain;
		if( domm == 'dictionnaire-francais.net' || domm == 'www.dictionnaire-francais.net' ) ok = true;
		if( !ok ) {
			alert('Error!');
			window.location='http://google.fr';
		}
	}
	function unescapeHTML(html) {
		html = html.replace("&quote;", "\"");
		html = html.replace("&#34;",   "\"");
		html = html.replace("&amp;",   "&");
		html = html.replace("&#38;",   "&");
		html = html.replace("&#lt;",   "<");
		html = html.replace("&#60;",   "<");
		html = html.replace("&#gt;",   ">");
		html = html.replace("&#62;",   ">");	
		html = html.replace("&#nbsp;", " ");
		html = html.replace("&#160;",  " ");
		html = html.replace("&#39;",   "'");			
		html = unescape(html);	
		return html;
	} 	
	

