function setBorderAndBackground( aField, borderColor, backgroundColor )
{       // green='1px solid #49c24f', red/pink='1px solid #c24949', yellow='1px solid #ffff00', white='1px solid #ffffff'
    aField.style.border = borderColor;
        // green='#bcffbf', red/pink='#ffbcbc', yellow='#ffffcc'
    aField.style.background = backgroundColor;
}
//-----------------------------------------------------------------------------------------------------------------------------
function createRequestObject()
{   var xmlhttp = null;
    try
    {   if ( window.XMLHttpRequest )
            xmlhttp = new XMLHttpRequest();							// Firefox, Chrome, Opera, Safari
        else if ( window.ActiveXObject )
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");		// IE (or Msxml2.XMLHTTP in IE5, IE6; Microsoft.XMLHTTP in ?)
    }
    catch(e)
    {   alert("Browser doesn't support XMLHttpRequest.");
    }
    return  xmlhttp;
}
//-----------------------------------------------------------------------------------------------------------------------------
var http = createRequestObject();
var theForm;
//-----------------------------------------------------------------------------------------------------------------------------
// captcha check
function processCaptchaResponse()
{   var formItem = theForm.captcha;                             // captcha from global form
    if ( http.readyState == 4 )
	{   if ( http.status == 200 )                               // Complete
        {   if ( http.responseText == '1' )
            {   setBorderAndBackground( formItem, '1px solid #49c24f', '#bcffbf' );     // green
                theForm.submit.disabled = false;
            }
            else
                setBorderAndBackground( formItem, '1px solid #c24949', '#ffbcbc' );     // red/pink
        }
        else
            alert( "AJAX error: " + http.statusText );
	}
    theForm.submit.value = "Send";                              // put the button name back to normal
}
function captchaKeyUp( aForm )
{   aForm.submit.disabled = true;
    var formItem = aForm.captcha;
    if ( formItem.value.length > 5 )
    {   aForm.submit.value = "Wait";
        setBorderAndBackground( formItem, '1px solid #ffff00', '#ffffcc' );             // yellow

        var url = "securimage/captcheck.php";
        http.open('POST', url, true);
        http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        theForm = aForm;                                        // make aForm global
        http.onreadystatechange = processCaptchaResponse;
        http.send("id=1&captcha=" + aForm.captcha.value);       // emulate a post
    }
    else
        setBorderAndBackground( formItem, '1px solid #ffffff', '#ffffff' );             // white
	return  true;                                               // must be true to get the button state to post back
}
//-----------------------------------------------------------------------------------------------------------------------------
// display hidden stuff
