/*
function getHTTPobj() {
	var xmlhttp;
	
	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 getHTTPobj() {
  var xmlhttp;
 
  /*@cc_on
 
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
      xmlhttp = false;
    }
  }
  @else
    xmlhttp = false;
  @end @*/
 
 if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
    try {
      xmlhttp = new XMLHttpRequest();
    }catch(e){
      xmlhttp = false;
    }
  }
 
  return xmlhttp;
}

function checkEnter(e) { 
	if (e.keyCode==13) { addliner(document.getElementById('liner')); }
}

function addliner(l) {
	l.value = l.value.replace(/http:\/\//gi,"http///");
	l.value = l.value.replace(/ftp:\/\//gi,"ftp///");
	l.value = l.value.replace(/mailto:\/\//gi,"mailto///");
	l.value = l.value.replace(/#/gi,"%23");
	http.open("GET","oneliners.php?add="+encodeURI(l.value), true);
	/* http.onreadystatechange = httpResponse(); */
	http.send(null);
	document.getElementById('liner').value = '';
	tliner = "";
	rc = 1;
	httpResponse();
}


function remliner(l) { 
	http.open("GET","oneliners.php?rem="+l,true);
	/* http.onreadystatechange = httpResponse(); */
	http.send(null);
	rc = 1;
	httpResponse();
}

function refreshliners() {
	http.open("GET","oneliners.php",true);
	/* http.onreadystatechange = httpResponse(); */
	http.send(null);
	httpResponse();
	var refonl = setTimeout("refreshliners()", refreshdelay);
	if (document.getElementById('liner')) { tliner = document.getElementById('liner').value; }
}

function httpResponse() {
	if (http.readyState==4) {
		document.getElementById('oneliners').innerHTML = http.responseText;
		if (typeof tliner != "undefined" && tliner.length > 0) { 
			document.getElementById('liner').value = tliner; 
			document.getElementById('liner').focus();
		}
	}
	else {
		rc++;
		if (rc < 60) { setTimeout("httpResponse();", 500); }
	}
}

/* initialize global variables */
var rc, refreshdelay, tliner, http;

function startliners() {
	rc = 1;
	refreshdelay = 1200000;
	tliner = "";
	http = getHTTPobj();
	refreshliners();
}