// JavaScript Document
//<SCRIPT LANGUAGE="JavaScript">
//only alpha numeric and underscore "_" will be allowed
function block_special_chars(){

    if ((event.keyCode > 31 && event.keyCode < 48) 
        || (event.keyCode > 57 && event.keyCode < 65) 
        || (event.keyCode > 90 && event.keyCode < 95)
        || event.keyCode==96 || event.keyCode > 122 ) 
    
        event.returnValue = false;
}


/* right trim a string */
 function rtrim(str)
{
	for (var i = str.length - 1; i >= 0; i--)
	{
		if (str.charAt(i) != ' ')
			break;
		str = str.substring(0, i);
	}
	return str;
}

/* left trim a string */
 function ltrim(str)
{
	for (var i =0; i<= str.length - 1; i++)
	{
		if (str.charAt(i) != ' ')
			break;
	}

	str = str.substring(i,str.length);
	return str;
}

/* combine right and left trim functions to a full trim function */
function trim(str)
{
	str=rtrim(str);
	str=ltrim(str)
	return str;
}

function isBlank(val)
{
	val=trim(val);
	if (val==""){
		return true;
	}
	    return false;
}
function validate(){
    if(isBlank(trim(document.login.LOGIN_NAME.value)))
    {
	alert("Login Name cannot be blank.");
	document.login.LOGIN_NAME.focus();
	return false;
    }
	
	if(isBlank(trim(document.login.PW.value))) {
	alert("Password cannot be blank.");
	document.login.PW.focus();
	return false;
    }
	/*
    if (document.login.SessionID.value == '') {
        alert("Need to select a semester. Be sure to select the right one!");
	document.login.SessionID.focus();
	return false;
    }
	*/
    return true;
}


function formSubmit(){
	//alert("hui is here");
  if(validate())
  	//document.login.target="_blank";
	if(document.login.login_option[0].checked == true)
  {
	  document.login.target="_blank";
    	document.login.action ="cgi-bin/main/login.pl";
  }
  

  else
  	if(document.login.login_option[1].checked == true)
  	{
	 document.login.target="_blank";		
     document.login.action ="http://www.newtonchineseschool.org/cgi-bin/main/teacherlogin.pl";
  	}

	if(document.login.login_option[2].checked == true)
  	{
	 document.login.target="_blank";
     document.login.action ="http://www.newtonchineseschool.org/cgi-bin/main/stafflogin.pl";
  	}
	document.login.submit();
}

//</script>                                                         XX