function activateThese(ids){
	//alert(ids);
	location.href = '?action=activate_alerts&ids=' + ids;
}
function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
 document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
 (document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}
function validate() {

if (isEmpty("username")) {
	alert("Please fill your username.");
	setFocus("username");
	return false;
}
if (isEmpty("password")) {
	alert("Please fill in your password.");
	setFocus("password");
	return false;
}
if (!isAnEmailAddress("email")) {
	alert("The entered email address is invalid.");
	setFocus("email");
	return false;
}
return true;

}

function deleteAlert(ss) {
	y = confirm('Are you sure?');
	if (y) location.href = '?action=deleteAlert&searchstring=' + ss;
}
function cancel() {
	location.href='?view=manage';
}
function killEverything() {
	return confirm('Are you sure you want to delete your account and all your alerts?');
}

function ValidateEmail(emailobj) {
		var isvalid = true;
		var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
		isvalid = email.test(emailobj.value);
		if (!isvalid){
			errormsg = 'Please enter a valid email address.';
			emailobj.value = '';
			emailobj.focus();
		}
		return(isvalid);
	}

function checkFields(fobj) {
	ok2go	= true;
	msg		= false;
	if (!fobj.password1.value.length) {
		msg = 'You must enter your password.';
		fobj.password1.focus();
		ok2go = false;
	}
	if (fobj.password1.value != fobj.password2.value) {
		msg = 'Your passwords do not match.';
		fobj.password1.value = '';
		fobj.password2.value = '';
		fobj.password1.focus();
		ok2go = false;
	}
	if (!ValidateEmail(fobj.email)) {
		msg = 'Please enter a valid email address.';
		fobj.email.value = '';
		fobj.email.focus();
		ok2go = false;
	}
	if (msg) alert(msg);
	//alert(ok2go);
	return ok2go;
}

function disalowEmpty(thefield) {
	ok2go	= true;
	msg		= false;
	if (!thefield.value.length)	{
		ok2go = false;
		msg = 'You cannot create an empty alert. Please put a search string in the text box.';
		thefield.focus();
	}
	if (msg) alert(msg);					
	return ok2go;
}