// Clear textfield
function ctf(tf) {
	if (tf.value == tf.defaultValue) {
		tf.value = "";
		tf.style.color = "#000000";
	}
}
// Reset textfield
function rtf(tf, color) {
	if (tf.value == "") {
		tf.value = tf.defaultValue;
		tf.style.color = color;
	}
}
// Prevent default searches
function l2f(q) {
	if (q.value == q.defaultValue) {
		q.focus();
		return false;
	}
	return true;
}

function isValidEmail(the_email) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\'\>\,\;\:\\\/\"\[\]]/;
	if (!emailFilter.test(the_email) || the_email.match(illegalChars)) {
		return false;
	}
	return true;
}

function specialPromotionsSignUp() {
	var elem = document.getElementById('promotions-sign-up');
	if( !l2f(elem.email) ) {
		return false;
	}
	if( !isValidEmail(elem.email.value) ) {
		alert('You must enter a valid e-mail address.');
		elem.email.focus();
		return false;
	}
	
	var xmlHttp = initAjaxObj();
	
	xmlHttp.open("POST","/mup/ajax-signup.php",true);
	var post_vars = 'email='+elem.email.value;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", post_vars.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange=function() {
		//alert('test 2');
		if(xmlHttp.readyState==4) {
			elem.innerHTML = '<p class="result">'+xmlHttp.responseText+'</p>';
		}
		else {
			return false;
		}
	};
	
	xmlHttp.send(post_vars);
	
	return false; /* ALWAYS return false so form stays on the same page */
}

function initAjaxObj() {
	//alert('test 2');
	var ajax;
	try {
	// Firefox, Opera 8.0+, Safari
	ajax=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
		ajax=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				ajax=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return ajax;
}