var WinPop0;
var WinPop1;
var WinPop2;
var timVar;

function timeout(limit) {
	var base = 100;
	var wait = limit.valueOf() * base;
	timVar = setTimeout("PopUp1('timeout.html')", wait);
}

function PopUp0(URL){
	PopUp0_Close();
	WinPop0=window.open(
	URL,"WinPop0","screenx=1,screeny=1,left=1,top=1,width=790,height=590,scrollbars=yes,resize=no,toolbar=no,status=no,menubar=no");
	rePopUp0();
}

function PopUp1(URL){
	PopUp1_Close();
	WinPop1=window.open(
	URL,"WinPop1","screenx=100,screeny=50,left=100,top=50,width=500,height=500,scrollbars=no,resize=no,toolbar=no,status=no,menubar=no");
	rePopUp1();
}

function PopUp2(URL, PARA){
	PopUp2_Close();
	WinPop2=window.open(URL,"WinPop2",PARA);
	rePopUp2();
}

function PopUp0_Close() {
	if (WinPop0 != null) {
		if (!WinPop0.closed) WinPop0.close();
	}
	return true;
}

function PopUp1_Close() {
	if (WinPop1 != null) {
		if (!WinPop1.closed) WinPop1.close();
	}
	return true;
}

function PopUp2_Close() {
	if (WinPop2 != null) {
		if (!WinPop2.closed) WinPop2.close();
	}
	return true;
}

function rePopUp0() {
	if (WinPop0 != null) {
		if (!WinPop0.closed) WinPop0.focus();
	}
	return true;
}

function rePopUp1() {
	if (WinPop1 != null) {
		if (!WinPop1.closed) WinPop1.focus();
	}
	return true;
}

function rePopUp2() {
	if (WinPop2 != null) {
		if (!WinPop2.closed) WinPop2.focus();
	}
	return true;
}

function right(e) {
	if (navigator.appName == 'Netscape' && 
		(e.which == 3 || e.which == 2))
		return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && 
		(event.button == 2 || event.button == 3)) {
		alert("對不起! 你不能使用這功能!");
		return false;
		}
	return true;
	}

// document.onmousedown=right;
// document.onmouseup=right;
// if (document.layers) window.captureEvents(Event.MOUSEDOWN);
// if (document.layers) window.captureEvents(Event.MOUSEUP);
// window.onmousedown=right;
// window.onmouseup=right;

function end() {
	window.close(self);
}

function hide() {
	self.window.moveTo(20, 10);
	self.window.resizeTo(300, 300);
}

   function check_input(inputform) {

	  var ok = true;

  	  var d = inputform.name.value;
	  if (d.length == 0) {
		alert("請 填 寫 負 責 老 師 姓 名");
		ok = false;
		}	  

  	  var d = inputform.school.value;
	  if ((ok != false) && (d.length == 0)) {
		alert("請 填 寫 學 校");
		ok = false;
		}

  	  var d = inputform.tel.value;
	  if ((ok != false) && ((d.length == 0) || !isInt(d))) {
		alert("請 填 寫 聯 絡 電 話");
		ok = false;
		}

  	  var d = inputform.email.value;
	  if ((ok != false) && (d.length != 0) && (emailCheck(d) == false)) {
		ok = false;
		}
		
	  if (ok == true) {
		inputform.submit();
		}
	}

function emailCheck(emailStr) {
// checks if the e-mail address is valid
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null) {
alert("電 郵 地 址 不 正 確! 請 再 填 寫 (請 留 意 電 郵 地 址 內 的 '@' 和 '.' )");
return false;
}
// make sure the IP address domain is valid
var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
if (IPArray != null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("電 郵 地 址 內 的 IP 不 正 確! 請 再 填 寫。")
return false;
      }
   }
}
return true;
}

function isInt(string) {
	var val = parseInt(string);
	return(val > 0);
}
