function mseDown(e){
  if (navigator.appName == 'Microsoft Internet Explorer' && event.button == 2 && event.ctrlKey != 1){
    alert('Copyright © 2002 - 2007\nAsian School of Education, S\'pore.\nAll rights reserved.');
  }
  if (navigator.appName == 'Netscape' && e.button == 0){ // 0 is left click
    return true; // Allow the event to propagate on.
  }
  return false;
}
document.onmousedown = mseDown;

function mySelect(e){
  if (navigator.appName == 'Microsoft Internet Explorer' && event.ctrlKey == 1){
    return true;
  }

  return false;
}

document.onmousedown = mseDown;
document.onselectstart = mySelect;
//document.onselectstart = new Function ('return false');

function MM_preloadImages(){
	var d = document;
	
	if(d.images){
		if(!d.MM_p) d.MM_p = new Array();
		
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		
		for(i = 0; i < a.length; i++){
			if(a[i].indexOf("#") != 0){
				d.MM_p[j] = new Image; d.MM_p[j++].src = a[i];
			}
		}
	}
}

function MM_findObj(n, d){
	var p, i, x;
	
	if(!d) d = document;
	
	if((p = n.indexOf("?")) > 0 && parent.frames.length){
		d = parent.frames[n.substring(p+1)].document; n = n.substring(0,p);
	}
	
	if(!(x = d[n]) && d.all) x = d.all[n];
	
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n,d.layers[i].document);
	
	if(!x && d.getElementById) x = d.getElementById(n);
	
	return x;
}

function MM_swapImage(){
	var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array;
	
	for(i = 0; i < (a.length-2); i+=3){
		if((x = MM_findObj(a[i])) != null){
			document.MM_sr[j++] = x;
			
			if(!x.oSrc) x.oSrc = x.src;
			
			x.src = a[i+2];
		}
	}
}

function MM_swapImgRestore(){
	var i, x, a = document.MM_sr;
	
	for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_jumpMenu(targ,selObj,restore){
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	
	if(restore) selObj.selectedIndex = 0;
}

function setCookie(name, value){
	var expire = new Date();
	
	fixDate(expire);
	var period = expire.getTime() + (30*24*3600*1000);
	expire.setTime(period);
	
	document.cookie = name + "=" + value + "; path=/; expires=" + expire.toGMTString();
}

function getCookie(name){
	var dcookie = document.cookie; 
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;

	while (cbegin < clen){
		var vbegin = cbegin + cname.length;

		if (dcookie.substring(cbegin, vbegin) == cname){ 
			var vend = dcookie.indexOf (";", vbegin);

			if (vend == -1){
				vend = clen;
			}

			return unescape(dcookie.substring(vbegin, vend));
		}

		cbegin = dcookie.indexOf(" ", cbegin) + 1;

		if (cbegin == 0){
			break;
		}
	}

	return null;
}

function fixDate(date){
	var base = new Date(0);
	var skew = base.getTime();
	
	if(skew > 0){
		date.setTime(date.getTime() - skew);
	}
}

function goPage(url){
	window.location.href = url;
}

function goBlankPage(url, title, opt){
	window.open(url, title, opt);
}

function viewCert(url){
	window.open(url,'ViewCertWindow','width=550,height=400');
}

function viewCert2(url){
	window.open(url,'ViewCertWindow','width=725,height=500,scrollbars=yes');
}

function viewCert3(url){
	window.open(url,'ViewCertWindow','width=520,height=580');
}

function viewMap(url){
	window.open(url,'ViewMapWindow','width=460,height=510');
}

function viewShapeVideo(url){
	window.open(url,'ViewShapeVideoWindow','width=370,height=365');
}

function viewShapeVideo2(url, x){
	window.open(url + '_' + x,'ViewShapeVideoWindow','width=370,height=365');
}

function viewNewInt(url, x, y){
	vniw = window.open(url,'ViewNewIntWindow','width=280,height=280,scrollbars=1');
	vniw.moveTo(x, y);
}

function viewTempCourses(url, x, y){
	a = window.open(url,'ViewTempCoursesWindows','width=490,height=400,scrollbars=1');
	a.moveTo(x, y);
}

function addFavorite(){
	window.external.AddFavorite(location.href, document.title);
}

function printThisPage(){
	window.print();
}

function printAndHide(){
	document.getElementById("print_fr").style.visibility = 'hidden';
	
	printThisPage();
	
	document.getElementById("print_fr").style.visibility = 'visible';
}

function resetForm(formId){
	eval('document.' + formId + '.reset()');
}

function toggleMode(formId, action, mode){
	eval('document.' + formId + '.MM_action.value = action');
	eval('document.' + formId + '.MM_mode.value = mode');
	eval('document.' + formId + '.submit()');
}

function toggleBlockDisplay(blockId, mode){
	if(mode == '0'){
		document.getElementById(blockId).style.display = 'none';
	}
	
	else if(mode == '1'){
		document.getElementById(blockId).style.display = 'block';
	}
	
	else if(mode == '2'){
		if(document.getElementById(blockId).style.display == 'block'){
			document.getElementById(blockId).style.display = 'none';
		}
		else{
			document.getElementById(blockId).style.display = 'block';
		}
	}
}

function toggleLayerDisplay(layerId, mode){
	if(mode == '0'){
		document.getElementById(layerId).style.visibility = 'hidden';
	}
	
	else if(mode == '1'){
		document.getElementById(layerId).style.visibility = 'visible';
	}
	
	else if(mode == '2'){
		if(document.getElementById(layerId).style.visibility == 'visible'){
			document.getElementById(layerId).style.visibility = 'hidden';
		}
		else{
			document.getElementById(layerId).style.visibility = 'visible';
		}
	}
}

function changeBgImage(tdId, url){
	document.getElementById(tdId).style.background = 'url(' + url + ')';
}

function checkDate(dayStr, monthStr, yearStr){
	var day = parseInt(dayStr);
	var month = parseInt(monthStr);
	var year = parseInt(yearStr);
	
	if(isNaN(year) == true){
		return false;
	}
	else if(year < 1901 || year > 2099){
		return false;
	}
	
	if(month == 2){
		if(day == 29){
			if(year%4 != 0){
				return false;
			}
		}
		else if(day > 29){
			return false;
		}
	}
	else if(month == 4 || month == 6 || month == 9 || month == 11){
		if(day > 30){
			return false;
		}
	}
	
	return true;
}

function checkEmail(eml){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)(?:(\.[a-zA-Z]{2})?)$/;
	
	return filter.test(eml);
}

window.status = 'Asian School of Education, Singapore   Tel: (65) 6338 2281   Fax: (65) 6338 7877';


