function textfocus()
{
	var text = new String(document.getElementById('inputtext').value);
	if (text.substring(0, 24) == 'Copy and paste here e.g.')
	document.getElementById('inputtext').value = text.substring(25);
}

function doparse()
{
	textfocus();
	
	text = new String(document.getElementById('inputtext').value);
	text = text.replace(/^\s+/, '');
	text = text.replace(/\s+$/, '');
	if (text.length == 0) {
		alert("Please enter complete contact details in the box on the right.");
		return;
	}

	show_sending_indicator('Processing...');

	ajax_parse(document.form1.inputtext.value, null, null); 
}

/* ***************************************************************** */

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

var bAjax_abort = false;

function ajax_cancel() {
	xmlhttp.abort();
	bAjax_abort = true;
}

function ajax_parse(txt, contactfrm, eventfrm) {
	bAjax_abort = false;
	xmlhttp.open("POST", "integrate_ajax.php", true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status == 200) {
			hide_sending_indicator();
			var resp = eval('(' + xmlhttp.responseText + ')');
			if (resp['faultstring']) {
				alert('Fault: ' + resp['faultstring'] + "\nDetail: " + resp['detail']);
			} else if (resp['message']) {
				alert('Fault: ' + resp['message'] + "\nDetail: " + resp['userinfo']);
			} else {
				if (resp['ContactWork'])
					resp['ContactUnIdPhone1'] = resp['ContactWork'];
				for (var i in resp) {
					if (document.form1.elements[i])
						document.form1.elements[i].value = resp[i];
				}
			}
		}
	}  // end function()

	var data = 'txt=' + encodeURIComponent(txt);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", data.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(data)
 }

