﻿function Jtrim(str)
{

        var i = 0;
        var len = str.length;
        if ( str == "" ) return( str );
        j = len -1;
        flagbegin = true;
        flagend = true;
        while ( flagbegin == true && i< len)
        {
           if ( str.charAt(i) == " " )
                {
                  i=i+1;
                  flagbegin=true;
                }
                else
                {
                        flagbegin=false;
                }
        }

        while  (flagend== true && j>=0)
        {
            if (str.charAt(j)==" ")
                {
                        j=j-1;
                        flagend=true;
                }
                else
                {
                        flagend=false;
                }
        }

        if ( i > j ) return ("")

        trimstr = str.substring(i,j+1);
        return trimstr;
}

function isWhiteSpace(c)
{
	return (c == ' ');
}
function isEmpty(str)
{
  if(str == null)
  {
    return true;
  }

  var strLen = str.length;
  if(strLen == 0)
  {
    return true;
  }

  for(var i = 0; i < strLen; i++) 
  {
    if(!isWhiteSpace(str.charAt(i)))
    {
      return false;
    }
  }

  return true;
}

function isEmail(str)
{
	if(isEmpty(str))
	{
		return false;
	}
	var strlen=str.length;
	var counterAt=0;
	var posAt=-1;
	var counterDot=0;
	var posDot=-1;
	var posLastDot=-1;
	if(strlen<=6){
		return false;
	}
	for(var i = 0 ; i < strlen ; i++){
		if(str.charAt(i)=='@'){
			counterAt+=1;
			if(counterAt==1){
				posAt=i;
			}
		}
		if(str.charAt(i)=='.'){
			counterDot+=1;
			if(counterDot==1){
				posDot=i;
			}
			posLastDot=i;
		}
	}
	if(counterAt==1&&counterDot>=1&&posAt<posLastDot&&posAt>=2&&posLastDot<strlen-2){
		return true;
	}
	return false;

}



var onImages=new Array();
function Rollover(imgName, imgSrc)
{
	onImages[imgName] = new Image();
	onImages[imgName].src = imgSrc;
}

function turnOn(imgName){ 
	document.images[imgName].offSrc = document.images[imgName].src;
	document.images[imgName].src    = onImages[imgName].src;
}

function turnOff(imgName){ 
	document.images[imgName].src = document.images[imgName].offSrc;
}

//Specify name of participating images, plus paths to their onMouseover replacements:
Rollover("courses","menu/menu1.jpg");
Rollover("school","menu/menu2.jpg");
Rollover("learningCenter","menu/menu3.jpg");
Rollover("about",  "menu/menu4.jpg");
Rollover("contact",  "menu/menu5.jpg");
Rollover("forkids",  "menu/menu6.jpg");
Rollover("event",  "menu/menu7.jpg");

function checkemail(){
if(Jtrim(document.form1.email.value)==''||Jtrim(document.form1.email.value)>80){
window.alert('Please input E-mail');document.form1.email.focus();return false;
}
if(Jtrim(document.form1.email.value)!=''){
if ( !isEmail(document.form1.email.value) ){
window.alert ("E-mail format error！");document.form1.email.focus();return false;
}
}

return true;
}
function checkemail1(){
if(Jtrim(document.form2.mail.value)==''||Jtrim(document.form2.mail.value)>80){
window.alert('Please input E-mail');document.form2.mail.focus();return false;
}
if(Jtrim(document.form2.mail.value)!=''){
if ( !isEmail(document.form2.mail.value) ){
window.alert ("E-mail format error！");document.form2.mail.focus();return false;
}
}

return true;
}
