function refreshCaptcha(theElem) {
   img = document.getElementById(theElem);
   //Change the image
   img.src = 'captcha.php?' + Math.random();
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
    if (myfield.form.name == "login")
		myfield.form.submit();
    else
		getMailParam(myfield.form);
    return false;
}
else
   return true;
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();
var currentid = 0;

//Initiate the AJAX request
function makeRequest(url, param, thisid) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
 {
   if(thisid == -2)	//contact
       document.getElementById('contact').innerHTML = '<div align=center><img src="p/loading.gif" alt="loading..." /></div>';
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default)
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePage;

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }
}

//Called every time our XmlHttpRequest objects state changes
function updatePage() {
//Check if our response is ready
	if (receiveReq.readyState == 4)
	{
	    //Set the content of the DIV element with the response text
	    document.getElementById('contact').innerHTML = receiveReq.responseText;
	    //Get a reference to CAPTCHA image
	    img = document.getElementById('captcha');
	    //Change the image
	    img.src = 'captcha.php?' + Math.random();

		document.forms['sendemail'].reset();
 }
}

function getMailParam(theForm) {
 //Set the URL
 var url = '/contact_update.php';
 //Set up the parameters of our AJAX call

 if ((theForm.email.value == '') ||
     (theForm.message.value == '') ||
     (theForm.captcha.value == ''))
 {
     theForm.email.style.border	    =  "solid #BB5555 1px";
     theForm.message.style.border   =  "solid #BB5555 1px";
     theForm.captcha.style.border   =  "solid #BB5555 1px";
 } else {
     theForm.email.style.border	    =  "solid #000000 1px";
     theForm.message.style.border   =  "solid #000000 1px";
     theForm.captcha.style.border   =  "solid #000000 1px";
}
document.getElementById('contact').style.display = "inline";

 var postStr = "name=" + encodeURIComponent( theForm.name.value ) ;
 postStr += "&" + "email=" + encodeURIComponent( theForm.email.value );
 postStr += "&" + "message=" + encodeURIComponent( theForm.message.value );
 postStr += "&" + "artist=" + encodeURIComponent( theForm.artist.value );
 postStr += "&" + "captcha=" + encodeURIComponent( theForm.captcha.value );
 postStr += "&" + "c=" + encodeURIComponent( theForm.c.value );
 currentid = -2;

 curbutton = document.buttoncontact;

 //Call the function that initiates the AJAX request
 makeRequest(url, postStr, -2);
}



