function checkMail(val)
{
	//var x = document.forms[0].email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(val))  {
	        return true;
	    }
	else { 
	        alert('Invalid email address');
	        return false;
	     }
}


function checkForm()
{
    // Check emails are in the correct format
    if(checkMail(val))
        return true
    else
    return false;
	
}

function GetCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}  

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


function SetCookie(name, value) 
{
	if(name == null) return;
	var expires = new Date ();
	expires.setTime (expires.getTime() + (24 * 60 * 60 * 1000 * 31));
	document.cookie = name + "=" + escape (value) +	"; expires=" + expires.toGMTString();
	 
}

function DelCookie(name)
{
  if ( GetCookie(name) == null ) return;
  else document.cookie = name + "=;";
}

function handlesubmit()
{
 	var username = document.getElementById( "j_username");
 	var passnotword = document.getElementById( "j_password");
 	var flag = document.getElementById("j_flag_a24nz");
  	if(username ==null || passnotword == null || flag == null) return true;

	if(flag.checked == true){
		SetCookie("flag","true");
		SetCookie("usernotname",username.value);
		SetCookie("passnotword",passnotword.value);
	}
	else {
		DelCookie("flag");
		DelCookie("usernotname");
		DelCookie("passnotword");
	}
	return true;
}

function populate()
{
	var username = document.getElementById("j_username");
	var passnotword = document.getElementById("j_password");
	var flag = document.getElementById("j_flag_a24nz");
	if (username == null || passnotword == null || flag == null) return;
	var c_flag = GetCookie("flag");
	if(c_flag){
		var c_username = GetCookie("usernotname");
		var c_passnotword = GetCookie("passnotword");
		username.value = c_username;
		passnotword.value = c_passnotword;
		flag.checked = true;
	}	
	username.focus();
}

