function browser_compatible()	{
	var appName = navigator.appName;
	var vers = navigator.appVersion;
	var compatible = "false";
	vers = vers.substring(0,1); // or 0,4  could return 4.5 instead of just 4
	
	if (appName == "Microsoft Internet Explorer" && vers >= 4) 	compatible = "true";
	if (appName == "Netscape" && vers >= 5)	compatible = "true";
	
	return (compatible);
}

function ch_lang()	{
	var oldLink = parent.location.toString();
	var linkArray = oldLink.split("/");
	var newLink = "";
	for (i=0; i<linkArray.length-1; i++)	{
		if (linkArray[i] == "chi")	linkArray[i] = "eng";
		else if (linkArray[i] == "eng") linkArray[i] = "chi";
		newLink = newLink + linkArray[i] + "/";
	}
	newLink = newLink + linkArray[i];
	parent.location.href = newLink;
}	

function go_nav(form) {
	var myIndex=form.dest.selectedIndex;
        var myValue=form.dest.options[myIndex].value;
        if (myValue!="null") parent.location=myValue;
}

/***********************************************************************/
/* The following 4 functions are needed for on Mouse Over Image effect */
/***********************************************************************/
function imagesPreload(preload) { //v3.0
	var i, a=new Array();
	for (i=0; i<img.length; i++)	{
		a[i]=new Image;
		a[i].src=preload[i];
	}
}

function imageRestore() { //v3.0
  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 findObj(n, d) { //v3.0
  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=findObj(n,d.layers[i].document); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-1);i+=2)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+1];}
}


/************************************************************/
/* The following function is designed for insert HTML files */
/************************************************************/

//if (browser_compatible()=="false") parent.location.href="http://www.alumni.cuhk.edu.hk/html/cuhk/error/noncompatible.html";

function insertPage(name, link, width, height, top, left)	{
	var compatible = browser_compatible();
	if (compatible=="true")	{
		document.write('<iframe src="'+link+'" width="'+width+'" height="'+height+'" frameborder="no" noresize scrolling="no"><\/iframe>');
	}
	else	{


		document.write('<layer src="'+link+'" clip="'+width+','+height+'" top="'+top+'" left="'+left+'" name="news"><\/layer>');

	}
}

/********************************/
/* Windows Management Functions */
/********************************/
function new_window(link, width, height, scrollbars)
{
	var par="scrollbars=" + scrollbars + ", toolbar=no, status=no, width=" + width + ", height=" + height;
        remote = window.open("", '', par);

	if (remote != null) {
		if (remote.opener == null) {
			remote.opener = self;
		}
		remote.location.href = link;
	}               
	if (remote.focus) remote.focus();
}

function popit(URL,width,height,off_x,off_y,options,winname)
{
	if (screen) {
		var bottom = screen.availHeight;
		var right = screen.availWidth;
		var pos_x = parseInt((right- width)/2) ;
		var pos_y = parseInt((bottom - height)/2);
		options += (',left=' + (pos_x + 0) + ',top=' + (pos_y + 0) );
	}
	var remote = window.open(URL,winname,options);
}

function randomNum(max) {               
	var rNum=NaN                          
	while (isNaN(rNum)) {                 
		rNum=Math.floor(Math.random()*(max))
	}                                     
	return rNum                           
}                                       

/****************************/
/* Tables / Forms Handeling */
/****************************/
function confirmSubmit () {
	if (confirm('Your information will be transferred. Are you sure?')) {
		document.MyForm.mailfrom.value = document.MyForm.Email_add.value;
		return true;
	} else {
		return false;
	}
}                                                    