
    //var sURL="../dev.formmonitor/";
    //var sURL="../www.freedomproperty.dev/";
    var sURL="../form.webeventseurope.com/";
    var sClientID=1;
    var TIMEINTERVAL=5000;
	var bAgreedToTCs=false;
	var sSessionID=generateID();	
	var el = new Array();
	var bMonitorActive = false;
	
	//initialise form monitor
	window.onload=setupForm;

	function setupForm() {
	    // first find the mail form 
	    var f;      // = document.forms[0]; 
	    for (var i=0; i < document.forms.length; i++){
	        if (document.forms[i].name == "mailform"){
	            f = document.forms[i]; 
	        }
	    }
	    
	    if(f!=null){
	        //attach monitor to each form element;
		    var l = f.elements.length
		    for (var i=0; i < l; i++) {
			    var e = f.elements[i];		
			    if (e.type!='submit' && e.type!='password' && e.type!='hidden' && e.id !='__VIEWSTATE' && e.id !='__EVENTTARGET' && e.id !='__EVENTARGUMENT' && e.id !='__EVENTVALIDATION') {
				    el[e.id]=getElementValue(e);
				    e.onchange=monitorChange;
				    e.onkeydown=monitorChange;
				    e.onkeyup=monitorChange;
				    e.onclick=monitorChange;
			    }
		    }		
	    }
		
	}

	function monitorChange (){			
		el[this.id]=getElementValue(this);		
		
		if (!bMonitorActive) {
		    
		    //set up timed log event;		
		    timedLog();		
		    
	        //attach close / navigate away event handlers
	        window.onunload=log;
	        window.onbeforeunload=log;		    
	        
	        bMonitorActive = true;
		}
	}
	
	function timedLog() {
	    log(true);
	    window.setTimeout(timedLog, TIMEINTERVAL) 
	}
	
	function log (bTimedTrigger) {
	    
	    if (!bAgreedToTCs)
	        return;
	        	    
	    //is this a timed post or triggered by closing / navigating away
	    if (!bTimedTrigger){
	        //remove closing event handlers, to prevent double logging
	    	window.onunload=null;
	        window.onbeforeunload=null;
	    }	        	        
	    
		var i = serializeArray();
		var img = new Image();
		img.src = sURL + "log.aspx?ts=" + new Date().getTime().toString() + "&s=" + sSessionID.toString() + "&c="+ sClientID + "&m=log&i=" + escape(i);		
		
	}
	
	function serializeArray(){
		var i='';
		for (x in el) {			    
		    if (el[x]!=void(0))
			    i+=x+"=" + el[x] + "|";
		}
		return i;
	}
	
    function getRandomNumber(range)
    {
	    return Math.floor(Math.random() * range);
    }

    function getRandomChar()
    {
	    var chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
	    return chars.substr( getRandomNumber(62), 1 );
    }

    function generateID()
    {
        var size = 32;
	    var str = "";
	    for(var i = 0; i < size; i++)
	    {
		    str += getRandomChar();
	    }
	    return str.toLowerCase();
    }
    
    function getElementValue(oElement) {
	    var strValue='';
	    switch (oElement.type) {
		    case "hidden":
			    strValue = getTextValue(oElement); break;
		    case "password":
			    strValue = getTextValue(oElement); break;
		    case "text":
			    strValue = getTextValue(oElement); break;
		    case "select-one":
			    strValue = getComboValue(oElement); break;
		    case "select-multiple":
			    strValue = getComboValue(oElement); break;
		    case "checkbox":
			    strValue = getCheckValue(oElement); break;
		    case "radio":
			    strValue = getCheckValue(oElement); break;
		    case "textarea":
			    strValue = getTextValue(oElement); break;
	    }	
	    return strValue;	
    }

    function getTextValue (oElement){
	    return oElement.value;
    }
     
    function getComboValue (oElement) {
        var strValue='';
	    var intOptionsLength = oElement.options.length;
	    for (i=0;i<intOptionsLength;i++) {
		    if (oElement.options[i].selected) {
			    if(strValue!='') strValue+=','		
			        strValue+=oElement[i].text;			
		    }
	    }
	    return strValue;
    }

    function getCheckValue (oElement) {
	    var strValue='';
	    if (oElement.checked) {
		    strValue=oElement.value;
	    }
	    return strValue;
    }

    function setTermsStatus (bAgreed) {
        bAgreedToTCs=bAgreed;
    }   
    
    function endSession () {
    
    	var img = new Image();
		img.src = sURL + "log.aspx?ts=" + new Date().getTime().toString() + "&s=" + sSessionID.toString() + "&c="+ sClientID + "&m=sub";
		   
    }