function auth_form()
{
    valid=true;
    userid = document.getElementById("username").value;
    passwd = document.getElementById("password").value;
    hideAllErrors();
    if(document.authform.userid.value == "")
    {
        document.getElementById("useridError").style.display = "inline";
        document.getElementById("username").select();
        document.getElementById("username").focus();
        valid=false;
    }
    if(document.authform.passwd.value  == "")
    {
        document.getElementById("passwdError").style.display = "inline";
        document.getElementById("password").select();
        document.getElementById("password").focus();
        valid=false;
    }
    return valid;
}

function hideAllErrors()
{
/*This function is used by forms both before and after login. So using a 
try-catch to check whether the div 'aliasError' is present. If not, handle the 
reference exception.( i.e) Do nothing ;-) */

    try
    {
    document.getElementById("useridError").style.display = "none";
    document.getElementById("passwdError").style.display = "none";
    document.getElementById("aliasError").style.display="none";
	}
	catch(e)
	{
	// Nothing here 
	}
	
}
function checkMailAlias()
{
    alias=document.forms["create_mail_alias"].alias.value;
    mail_alias_regex=/^[a-z][a-z0-9_][a-z0-9_]+$/;
    if(!mail_alias_regex.test(alias))
    {
	document.getElementById("aliasError").style.display="inline";
	return false;
    }
    return true;
}

function get_staff_dept(base_url,department)
{
   
    var url = base_url + "/py/profile/admin/get_staff_dept?dept=" + department;
    
      


    if (window.XMLHttpRequest)
	{
	    xmlhttp=new XMLHttpRequest();
	}
    else
	{
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
    xmlhttp.open("GET",url,false);
    xmlhttp.send(null);

    var staff_details = xmlhttp.responseText;
    var slice_result = staff_details.slice(1,staff_details.length-1);

    var split_result = slice_result.split(',');
   
    var val = "<select name=\"staff_names\">";

    var temp="";

    var i=0;
    

    
    while(i<split_result.length)
	{
	        
	    temp = split_result[i];
            
	    if(temp.charAt(2) == "'")
		{
		    temp = temp.slice(3,temp.length-1);
		}
	    else
		{
		    temp = temp.slice(2,temp.length-1);
		}
            
	    val = val + "<option value="+temp+">";
	    i=i+1;
	    temp = split_result[i];
	    temp = temp.slice(2,temp.length-2);
	    val=val+temp+"</option>";
	    i=i+1;
	    
	        
	      	        
	}
    val = val + "</select>";


    document.getElementById('test').innerHTML=val;

}


