function newsletter_join(f) {
	var email = f.elements['email'].value;

	if (email == '') { newsletter_error(f); return false; }

	send_xmlHttpRequest("email="+encodeURIComponent(email), "api/newsletter_join.php", false, '');

	if (interpret_query_string(xmlHttpRequest.responseText, "error_id") > 0) { newsletter_error(f); return false; }

	f.elements['email'].value = '';
	newsletter_final();
}
function newsletter_error(f) {
	f.elements['email'].focus();
	alert('Please enter a valid email address');
}
function newsletter_final() {
	document.getElementById('join-our-list-container').style.display = 'none';
	document.getElementById('join-our-list-final').style.display     = 'block';
	setTimeout("newsletter_restore();", 2500);
}
function newsletter_restore() {
	document.getElementById('join-our-list-container').style.display = 'block';
	document.getElementById('join-our-list-final').style.display     = 'none';
}





// ====================================================================================================================================================================
//             XMLHTTPREQUEST
// -----------------------------------------------------------------------------------------------------------------------------
var xmlHttpRequest = null;

function createRequest()
{
	try { xmlHttpRequest = new XMLHttpRequest();  } // This line tries to create a new request-object (by its type)
	catch (trymicrosoft) {
		try { xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } // Here we try to create instance for IE 
		catch (othermicrosoft) {
			try { xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 	} // Here we try to create instance for IE
			catch (failed) { xmlHttpRequest = null;  } // totally doomed
		}
	}
	return xmlHttpRequest != null;
}
// -----------------------------------------------------------------------------------------------------------------------------
//
//
//
// this function is only useful for synchronic communication 
// --- xmlHttpRequest ...  -----------------------------------------------------------------------------------------------------
function send_xmlHttpRequest(send_data, url, isAsync, func_call)
{
	if (isAsync === undefined)
		isAsync = false;

	if (func_call === undefined)
		func_call = false;

      if (createRequest())
      {

	    if (isAsync && func_call != '') { 
		xmlHttpRequest.onreadystatechange = function() {
			switch (func_call) {
			}
		}
	    }// func_call; } // new Function('fx', func_call);
	    xmlHttpRequest.open("POST", url, isAsync);
	    xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlHttpRequest.send(send_data);

      }
      else alert('Please upgrade to a newer browser (use Firefox) in order to run this program');
}
// -----------------------------------------------------------------------------------------------------------------------------
//
//
//
// ---- this next function can crop values that a script outputs by a key
function interpret_query_string(query_string, key)
{
	var pos = query_string.indexOf(key);
	if (pos == -1)
		return false;

	if (key.charAt(key.length-1) != '=') // this is what makes it the var name -- if the = isn't already included, we append it
		key += '=';

	var aftermath = query_string.substring(pos+key.length);
	var pos_next_var = aftermath.indexOf("&"); // where does the next var begin
	if (pos_next_var == -1)
		return decodeURIComponent(aftermath.replace(/\+/g, " ")); // then, that's all we need

	return decodeURIComponent(aftermath.substring(0, pos_next_var).replace(/\+/g, " "));
}
//             END
//             XMLHTTPREQUEST
// ====================================================================================================================================================================

