// squirrelmail remote login script
// brett d, 12/05/07

// remove spaces from any string
function removeSpaces(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

// pass all the info to squirrelmail login!
function processLogin(account,domain,pass)
{
	window.location = "https://webmail." + domain + "/src/redirect.php?login_username=" + account + "&secretkey=" + pass + "&js_autodetect_results=0&just_logged_in=1";
}

function webmail()
{

	// get the values from the form
	var wmAddress = document.forms['webmaillogin'].webmailusername.value;
	var wmPassword = document.forms['webmaillogin'].webmailpassword.value;
	
	// delete any spaces
	wmAddress = removeSpaces(wmAddress);
	wmPassword = removeSpaces(wmPassword);
	
	// hey user!  there are no spaces in addresses or passwords!
	document.forms['webmaillogin'].webmailusername.value = wmAddress;
	document.forms['webmaillogin'].webmailpassword.value = wmPassword;
	
	// filter for valid email
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(wmAddress))
	// email's valid
		{
			if (wmPassword != "")
			// and password's not blank!
				{
					var wmAddressArray = wmAddress.split("@");
					processLogin(wmAddressArray[0],wmAddressArray[1],wmPassword);
				}
			else
				{
				alert("Please enter your password.")
				}
		}
	// email's invalid
		else
			{
				alert("Please enter a valid email address.")
			}
return false;
}
	
