var filearray=[34,43,13];
var unitno=1;
var unit1array=[2,1,3,1,2,1,1,1,1,2,2,1,3,2,3,1,1,1,1,1,3];


function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value)
{  
	var ckyDate = new Date;
	ckyDate.setDate(ckyDate.getDate( ) + 1);
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value)+'; expires=' + ckyDate.toGMTString( ) + ';';
}


function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function DeleteCookie (name)
{
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	//window.close();
}




function goprevious(){

		var myfilepos=parseInt(GetCookie("pos"));
		var mytopic=parseInt(GetCookie("mytopic"));


	if ((myfilepos == 1) && (mytopic==1)){
		alert("You are in the first page.");
		return;
	}
		
		if(myfilepos<=filearray[mytopic-1]){
			if(myfilepos>1){
				
				myfilepos=myfilepos-1;
				SetCookie("pos",myfilepos);
				//document.getElementById("mytd").innerText=myfilepos+"   of   "+filearray[mytopic-1]
				window.open("esl"+mytopic+"_"+myfilepos+".htm","content");
			}else{
				
				SetCookie("mytopic",mytopic-1);
				SetCookie("pos",filearray[mytopic-2]);
				var myfilepos=parseInt(GetCookie("pos"));
				var mytopic=parseInt(GetCookie("mytopic"));
				//document.getElementById("mytd").innerText=myfilepos+"   of   "+filearray[mytopic-1]
				window.open("esl"+mytopic+"_"+myfilepos+".htm","content");
			}
		}
}


function gonext(){
		var myfilepos=parseInt(GetCookie("pos"))+1;
		var mytopic=parseInt(GetCookie("mytopic"));
        var sum=0;
		unitno=unitno+1;
		for(j=0;j<unitno;j++){
			sum=sum+unit1array[j];
		}
        myfilepos=sum;
		alert(myfilepos);
		if ((myfilepos-1 == filearray[2]) && (mytopic==3)){
		alert("You are in the last page.");
		return;
	}

		if(myfilepos<=filearray[mytopic-1]){
			SetCookie("pos",myfilepos);
			//document.getElementById("mytd").innerText=myfilepos+"   of   "+filearray[mytopic-1]
			window.open("esl"+mytopic+"_"+myfilepos+".htm","content");
		}else{
			
			SetCookie("mytopic",mytopic+1);
			SetCookie("pos",1);
			var myfilepos=parseInt(GetCookie("pos"));
			var mytopic=parseInt(GetCookie("mytopic"));
			//document.getElementById("mytd").innerText=myfilepos+"   of   "+filearray[mytopic-1]
			window.open("esl"+mytopic+"_"+myfilepos+".htm","content");
		
		}
		
}

function mydate(){
	var my_date=new Date();
	mydate=my_date.getDate();
	mymonth=my_date.getMonth();
	mymonth=parseInt(mymonth)+1;
	myyear=my_date.getYear();
	//mytime=my_date.getHours();
	//mymin=my_date.getMinutes();
	//mysec=my_date.getSeconds();
	document.getElementById("mydate").innerText="Date: "+mymonth+"/"+mydate+"/"+myyear;
	//document.getElementById("mytime").innerText=+" : "+mymin+" : "+mysec;
	
}

function exit(){
	top.window.close();
}

function toc(unit,no){
	SetCookie("mytopic",unit);
	SetCookie("pos",no);
	window.open("esl"+unit+"_"+no+".htm","content");
}