///////////////////////////////////////////////////////

// Set countdown

  var interval, m=30, s=0;
 
  function countdown() { 
    if(s==0) 
	{
		if(m==0)
		{
			clearInterval(interval);
			parent.close();
			return;
		} 
		m-=1; s=60;
	}
    s-=1;
    document.getElementById("time").innerHTML = m + ":" + (s<10?"0":"") + s;
    document.getElementById("timeleft").value = m + ":" + (s<10?"0":"") + s;

  }


///////////////////////////////////////////////////////
var unsf =0;
var esf =0;
// Close popus 
function unloadsafe()
{
	unsf=1;
}
function exitsafe()
{
	esf =1;
}
function CloseEvent()
{
	if(unsf) return;
	if(esf) {
		parent.close();
		return;
	}
	parent.main.location.href="test.php?p=3&tinterrupt=1&submit=1" 
		+"&timeleft="+parent.main.document.getElementById("timeleft").value
		+"&currentpage="+parent.main.document.getElementById("p").value;
	alert("Your test is terminated!");
	parent.close();
}


///////////////////////////////////////////////////////


var message="Sorry, you do not have permission to right click.";
///////////////////////////////////
function clickIE() {
	if (document.all) {
		(message);
		return false;
	}
}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			(message);
			return false;
		}
	}
}

if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
}
else {
	document.onmouseup=clickNS;document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false") 

////////////////////////////////////////////////////////////

// Open new window 

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}


/////////////////////////////////////////////////////////////

// Validate email address
function checkfrm()
{
	var frm = document.studfrm;
	if(!frm.student.value)
	{
		alert("Please enter student number");
		return false;
	}
    if(!frm.surname.value)
	{
		alert("Please enter Surname");
		return false;
	}

	if(!checkEmail(frm.st_email.value)) {
		
		return false;
	}
	if(confirm("Do you want to begin the test now?")){NewWindow("","test","700","800","yes"); return true;}else return false;	
}

function checkEmail(eml) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eml)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}


