// Portent Form Tracker, v1.1
var xmlhttp_form;
/*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp_form=new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttp_form=new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttp_form=false } } @else xmlhttp_form=false @end @*/
if (!xmlhttp_form && typeof XMLHttpRequest != 'undefined') { 
	try { xmlhttp_form = new XMLHttpRequest(); } 
	catch (e) { xmlhttp_form = false; }
}
var formname, fieldname, fieldindex; fieldname = ""; fieldindex = -1; hasform =false;
for (i = 0; i < document.forms.length; i++) { 
	fm = document.forms[i]; 
	if (fm.elements[0].name == "portent_form") { 
		formname = fm.name; hasform = true; 
		for (j = 0; j < fm.elements.length; j++) { 
			fld = fm.elements[j]; 
			fld.onchange = (fld.onchange) ? new Function("", portent_functionBody(portent_formChange) + portent_functionBody(fld.onchange)) : portent_formChange; 
		} 
	} 
}
if (hasform) window.onunload = (window.onunload) ? new Function("", portent_functionBody(window.onunload) + portent_functionBody(portent_unLoad_form)) : portent_unLoad_form;

function portent_functionBody(fn) {	
	fb = fn.toString(); 
	return fb.substr(fb.indexOf("{") + 1, fb.lastIndexOf("}") - fb.indexOf("{") - 1).replace(/^ */g, '').replace(/ *$/g, ''); 
}
function portent_unLoad_form() { 
	if (xmlhttp_form) { 
		xmlhttp_form.open("POST", document.location.protocol + "//" + document.location.hostname + "/portent_form.cfm", true); 
		xmlhttp_form.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		xmlhttp_form.send("s=" + document.location.hostname + "&t=" + document.location.pathname + "&fm=" + formname + "&fd=" + fieldname + "&fi=" + fieldindex + "&c=" + document.cookie); 
	} 
}
function portent_formChange() { 
	els = this.form.elements; 
	for (i = 0; i < els.length; i++) { 
		if (els[i].name == this.name) 
			break; 
	} 
	if (i > fieldindex) { 
		fieldindex = i;
		fieldname = this.name; 
	}
}