// Instructors and courses
var Instructors = new Array();

//-------- Instructor 0 -------------------- 
Instructors[0] = new Instructor(
"zoran",
"jazz",
"Zoran",
"Bogdanovic",
"381601",
"1961-11-24",
"Krusevac",
"Courses0",
"1", 
"");

// declare array to hold all courses for the instructor 
var Courses0 = new Array();

Courses0[0] = new Course (
"Personal Protection Level 1",
"1993-05-01",
"965001",
"2007-12-31",
"",
"personalProtectionLevelOne"
);

Courses0[1] = new Course (
"Tactical Shotgun",
"1993-08-21",
"965001",
"2007-12-31",
"",
"tacticalShotgun"
);

Courses0[2] = new Course (
"Tactical Vehicle",
"1994-04-12",
"965000",
"2007-12-31",
"",
"tacticalVehicle"
);

Courses0[3] = new Course (
"Tactical Blade Concepts Level 1",
"1993-02-15",
"965002",
"2007-12-31",
"",
"tacticalBlade"
);

//-------- Instructor 1 -------------------- 
Instructors[1] = new Instructor(
"nash",
"Burnaby",
"Nebojsa",
"Djordjevic",
"381602",
"1964-12-10",
"Zajecar",
"Courses1",
"1",
""
);

// declare array to hold all courses for the instructor 
var Courses1 = new Array();

Courses1[0] = new Course (
"Alpine Operation",
"2000-10-08",
"381601",
"2007-12-31",
"",
""
);

//-------- Instructor 2 -------------------- 
Instructors[2] = new Instructor(
"igor",
"#1636",
"Igor",
"Grujic",
"381371",
"1975-08-18",
"Krusevac",
"Courses2",
"1",
""
);

// declare array to hold all courses for the instructor 
var Courses2 = new Array();

Courses2[0] = new Course (
"Defensive Tactics for Security Professional",
"2006-07-06",
"381601",
"2007-12-31",
"",
""
);

Courses2[1] = new Course (
"Tactical Blade Concepts Level 1",
"2006-03-27",
"381601",
"2007-12-31",
"",
"tacticalBlade"
);


//-------- Instructor 3 -------------------- 
Instructors[3] = new Instructor(
"braca",
"#0812",
"Branimir",
"Markovic",
"381372",
"1975-04-06",
"Krusevac",
"Courses3",
"1",
""
);

// declare array to hold all courses for the instructor 
var Courses3 = new Array();

Courses3[0] = new Course (
"Bomb Countermeasures",
"2007-04-24",
"381601",
"2007-12-31",
"",
"bombCountermeasures"
);

Courses3[1] = new Course (
"Tactical Blade Concepts Level 1",
"2006-09-24",
"381601",
"2007-12-31",
"",
"tacticalBlade"
);

/*---------------------------------*/
/* START OF COURSES MATERIAL       */
/*---------------------------------*/

/* Tactical Blade */
var tacticalBlade = new Array();

tacticalBlade[0] = new fileItem (
"How to Buy a Knife",
"../files/HowtoBuyaKnife.pdf"
);

tacticalBlade[1] = new fileItem (
"Edged Weapon Tactics",
"../files/EdgedWeaponTactics.doc"
);
/* end of Tactical Blade */

/* Personal Protection Level One  */
var personalProtectionLevelOne = new Array();

personalProtectionLevelOne[0] = new fileItem (
"Observation Techniques",
"../files/ObservationTechniques.doc"
);
/* end Personal Protection Level One */

/* Tactical Shotgun  */
var tacticalShotgun = new Array();

tacticalShotgun[0] = new fileItem (
"Tactical Shotgun",
"../files/TacticalShotgun.doc"
);
/* end Tactical Shotgun */

/* Tactical Vehicle  */
var tacticalVehicle = new Array();

tacticalVehicle[0] = new fileItem (
"IDENTIFYING AND REPORTING UNUSUAL VEHICLES",
"../files/IDENTIFYING_AND_REPORTING_UNUSUAL_VEHICLES.ppt"
);
/* end Tactical Vehicle */

/* Bomb Countermeasures  */
var bombCountermeasures = new Array();

bombCountermeasures[0] = new fileItem (
"Terror Bomber Recognition Card",
"../files/LawEnforcement.doc"
);

bombCountermeasures[1] = new fileItem (
"IED Safe Standoff Distance Cheat Sheet",
"../files/IED_Standoff.pdf"
);
/* end Bomb Countermeasures */

/*---------------------------------*/
/* END OF THE COURSES MATERIAL     */
/*---------------------------------*/


// Instructor Object Constructor 
function Instructor(
    userName,
 	userPassword,
    firstName, 
 	lastName,
 	idNum,
 	birthDate,
 	birthPlace,
 	coursePtr,
 	linkLevel,
 	linkName)
{
	this.userName = userName;                    // User Name
	this.userPassword = userPassword;            // User Password
	this.firstName = firstName;                  // First Name
	this.lastName = lastName;                    // Last Name
	this.idNum = idNum;                          // Instructor #
	this.birthDate = birthDate;                  // Date of birth
	this.birthPlace = birthPlace;                // Place of birth
	this.coursePtr = coursePtr;                  // Pointer to courses	
	this.linkLevel = linkLevel;                  // Link Level
	this.linkName = linkName;                    // Link to instructors Page
}

// Course Object Constructor
function Course (
	certifyToTeach,
 	certificationDate,
 	certifyByIdNum,
 	licenseExpiryDate,
 	Note,
 	materialPtr)
{
	this.certifyToTeach = certifyToTeach;        // Cerify to teach
	this.certificationDate = certificationDate;  // Cerification Date
	this.certifyByIdNum = certifyByIdNum;        // Certified by instructor #
	this.licenseExpiryDate = licenseExpiryDate;  // Instructor license expiry date
	this.Note = Note;                            // Note
	this.materialPtr = materialPtr;              // Pointer to course material		
}

// Course Item Object Constructor. Each course can have
// many docs
function fileItem (
	showText,
 	fileName)
{
	this.showText = showText;  // Cerify to teach
	this.fileName = fileName;  // Cerification Date
}

// Find Instructor
function getInstructor(arrayPtr, userName, userPassword)
{
	var idx = eval(arrayPtr + ".length");		
	var retIdx = -1;
	
	// search array
	for (var i=0; i <idx; i++) {
		// get user name and password
		var iUserName = eval(arrayPtr + "[" + i + "].userName");		
		var iUserPassword = eval(arrayPtr + "[" + i + "].userPassword");
		// compare user name and password
		if (iUserName == userName && iUserPassword == userPassword) {			
			retIdx = i;			
			break;	
		}		
	}
	return retIdx;
}

// Checks password. If wrong 3 times redirects user to predefined page
function chkPsw(formPtr) {
     	
  	var targetURL = "./instructor.htm?";
    var homeURL = "./home.htm";
          
    // get form data     
	userName = formPtr.username.value 
	userPassword = formPtr.psw.value;		
	userCnt = formPtr.cnt;
			
	// check password
	retVal = getInstructor("Instructors", userName, userPassword);
	if(retVal != -1) {
		encPar = encode(retVal + userName);		
		window.location=targetURL + escape(encPar);
	} else {
		userCnt.value++;
		showL("psw_warnning");
	}
	
	//if wrong 3 times go to home page
	if (userCnt.value >= 3) {
		userCnt.value = 0;		
	  	window.location=homeURL;
	}
}

// "encrypt" data. Just do something, not real protection
function encode(inStr) {
	var outStr = "";
	var key = "k87hf*u&5$cnjgrd";
	
	for (i = 0; i < inStr.length; i++) {
		outStr += String.fromCharCode(inStr.charCodeAt(i) ^ key.charCodeAt(i%(key.length)));
	}
	
	return outStr;	
}

// Shows (unhides) given layer
function showL(a) {
	
	var ns4 = (document.layers)? true:false;
	
	if (ns4) {
		document.layers[a].position = "absolute";
		document.layers[a].visibility = "show";
	} else {
		document.getElementById(a).style.visibility = "visible";
	}	
}

// Hides given layer
function hideL(a) {
	
	var ns4 = (document.layers)? true:false;
	
	if (ns4) {
		document.layers[a].position = "relative";
		document.layers[a].visibility = "hide";
	} else {
		document.getElementById(a).style.visibility = "hidden";
	}	
}
 
// get data passed between pages
function getPassedData(dataArray)
{
	var query = window.location.search;
	
  	// Skip the leading ?, which should always be there
  	if (query.substring(0, 1) == '?') {
    	query = query.substring(1);
  	}
  	
  	// Split into vars
  	dataArray = query.split(',');
  	
  	// unescape vars
  	for (i = 0; (i < dataArray.length); i++) {
    	dataArray[i] = unescape(dataArray[i]);
  	}
}

// get passed index
function getPassedIndex()
{
	var query = window.location.search;
	
  	// Skip the leading ?, which should always be there
  	if (query.substring(0, 1) == '?') {
    	query = query.substring(1);
  	}
  	
  	return query;  	
}

// get passed instructors index
function decodePassedIndex()
{
	var query = window.location.search;
	
  	// Skip the leading ?, which should always be there
  	if (query.substring(0, 1) == '?') {
    	query = encode(unescape(query.substring(1)));
  	}
  	
  	return query.charAt(0);  	
}

// get passed course pointer
function decodePassedCoursePtr()
{
	var query = window.location.search;
	
  	// Skip the leading ?, which should always be there
  	if (query.substring(0, 1) == '?') {
    	query = encode(unescape(query.substring(1)));
  	}
  	
  	return query;  	
}

//Generate page with course material
function getMaterial(materialPtr)
{
	var targetURL = "./material.htm?";
	
	encPar = encode(materialPtr);		
	window.location=targetURL + escape(encPar);
}

// dummy function
function dummy()
{
};

// Print Instructor's Information
function generateInstructorInfo()
{	
	var instructorIdx = decodePassedIndex();
	
	if ((instructorIdx == "") || (instructorIdx < 0) || (instructorIdx >= Instructors.length)) {
		window.location="./home.htm";
	}
		
	document.writeln("<div id=\"main_body\" class=\"main\">");
	document.writeln("<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");
	document.writeln("<tr>");
	document.writeln("<td ALIGN=CENTER VALIGN=bottom WIDTH=\"625\" HEIGHT=\"1\" ><img SRC=\"../images/spacer.gif\" height=1 width=625></td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td ALIGN=CENTER VALIGN=bottom WIDTH=\"600\" HEIGHT=\"40\" ><img SRC=\"../images/t_training.gif\" height=34 width=115></td>");
	document.writeln("</tr>");
	// Section title
	document.writeln("<tr>");	
	document.writeln("<td WIDTH=\"625\"><span class=\"s71\"><br>Personal Information</span></td>");
	document.writeln("</tr>");		
	// First and Last Name
	document.writeln("<tr>");	
	var iName = "<td WIDTH=\"625\"><span class=\"s41\"><br>Name: " + Instructors[instructorIdx].firstName + " " + Instructors[instructorIdx].lastName + "</span></td>";
	document.writeln(iName);
	document.writeln("</tr>");
	// Instructor ID
	document.writeln("<tr>");
	var iId = "<td WIDTH=\"625\"><span class=\"s41\"><br>Instructor Number: " + Instructors[instructorIdx].idNum + "</span></td>";	
	document.writeln(iId);
	document.writeln("</tr>");
	// Date of Birth
	document.writeln("<tr>");
	var iBirthDate = "<td WIDTH=\"625\"><span class=\"s41\"><br>Date of Birth: " + Instructors[instructorIdx].birthDate + "</span></td>";	
	document.writeln(iBirthDate);
	document.writeln("</tr>");
	// Place of birth
	document.writeln("<tr>");
	var iBirthPlace = "<td WIDTH=\"625\"><span class=\"s41\"><br>Place of Birth: " + Instructors[instructorIdx].birthPlace + "</span></td>";	
	document.writeln(iBirthPlace);
	document.writeln("</tr>");
	// Section title
	document.writeln("<tr>");	
	document.writeln("<td WIDTH=\"625\"><span class=\"s71\"><br>Courses Cerifications</span></td>");
	document.writeln("</tr>");	
	// Print courses
	var idx = eval(Instructors[instructorIdx].coursePtr + ".length");
	for (var i=0; i<idx; i++) {
		document.writeln("<tr>");
		document.writeln("<table BORDER=0 colspan=2 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");
		if (i > 0) {
			document.writeln("<tr><td><br></td></tr>");
			document.writeln("<tr>");
			document.writeln("<td ALIGN=CENTER VALIGN=bottom WIDTH=\"10\" HEIGHT=\"2\"><img SRC=\"../images/spacer.gif\" height=2 width=10></td>");		
			document.writeln("<td BGCOLOR=\"#607a97\" ALIGN=CENTER VALIGN=bottom WIDTH=\"615\" HEIGHT=\"2\"><img SRC=\"../images/spacer.gif\" height=2 width=615></td>");
			document.writeln("</tr>");			
		}
		document.writeln("</table>");		
		document.writeln("</tr>");		
		// Course
		document.writeln("<tr>");		
		var iCourse = "<td WIDTH=\"625\"><span class=\"s41\"><br>Certified to Teach: " + eval(Instructors[instructorIdx].coursePtr + "[" + i + "].certifyToTeach") + "</span></td>";
		document.writeln(iCourse);
		document.writeln("</tr>");
	    // Certification Date
	    document.writeln("<tr>");
		var iCertificationDate = "<td WIDTH=\"625\"><span class=\"s41\"><br>Certification Date: " + eval(Instructors[instructorIdx].coursePtr + "[" + i + "].certificationDate") + "</span></td>";	
		document.writeln(iCertificationDate);
		document.writeln("</tr>");
		// Certified by Instructor
		document.writeln("<tr>");
		var iCertifiedByNum = "<td WIDTH=\"625\"><span class=\"s41\"><br>Certified by Instructor ID: " + eval(Instructors[instructorIdx].coursePtr + "[" + i + "].certifyByIdNum") + "</span></td>";	
		document.writeln(iCertifiedByNum);
		document.writeln("</tr>");
		// License Expiry Date
		document.writeln("<tr>");
		var iExpiryDate = "<td WIDTH=\"625\"><span class=\"s41\"><br>License Expiry Date: " + eval(Instructors[instructorIdx].coursePtr + "[" + i + "].licenseExpiryDate") + "</span></td>";	
		document.writeln(iExpiryDate);
		document.writeln("</tr>");
		// Note		
		var iNote = eval(Instructors[instructorIdx].coursePtr + "[" + i + "].Note");
		if (iNote != "") {
			document.writeln("<tr>");
			document.writeln("<td WIDTH=\"625\"><span class=\"s41\"><br>Note: " + iNote + "</span></td>");
			document.writeln("</tr>");
		}
		// Course Material
		var iMaterial = eval(Instructors[instructorIdx].coursePtr + "[" + i + "].materialPtr");
		if	(iMaterial != "") {
			document.writeln("<tr>");
			// use void(null) to avoid jump to page top			
			//document.writeln("<td WIDTH=\"625\"><span class=\"s41\"><br><a class=\"a32\"" + "href=\"javascript:void(null)\"" + " onClick=\"getMaterial('" + iMaterial + "');\"" + " onmouseover=\"this.style.color='orange';\" onmouseout=\"this.style.color='navajowhite';\">Click here to download course material</a></span></td>");
			document.writeln("<td WIDTH=\"625\"><span class=\"s41\"><br><a class=\"a32\"" + "href=\"javascript:dummy()\"" + " onClick=\"getMaterial('" + iMaterial + "');\"" + " onmouseover=\"this.style.color='orange';\" onmouseout=\"this.style.color='navajowhite';\">Click here to download course material</a></span></td>");
			//var iHref = "getMaterial('" + iMaterial + "')";
			//document.writeln("<td WIDTH=\"625\"><span class=\"s41\"><br><a class=\"a32\"" + "href=\"javascript:" + iHref + "\"" + " onmouseover=\"this.style.color='orange';\" onmouseout=\"this.style.color='navajowhite';\">Click here to download course material</a></span></td>");
			document.writeln("</tr>");
		}
	}
	document.writeln("</table>");
	// bottom menu
	document.writeln("<table BORDER=0 colspan=2 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");
	document.writeln("<tr>");
	document.writeln("<td ALIGN=center VALIGN=top>");
	document.writeln("<br><br>");
	document.writeln("<a href=\"#Top\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightsteelblue\';\">Top of the page</a>");
	document.writeln("<p align=\"center\"><span class=\"s11\">| <a class=\"small\" href=\"training.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">TRAINING</a> | <a class=\"small\" href=\"services.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">SERVICES</a> | <a class=\"small\" href=\"photo1.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">PHOTO ALBUM</a> | <a class=\"small\" href=\"equipment.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">EQUIPMENT</a> | <a class=\"small\" href=\"miscellaneous.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">MISCELLANEOUS</a> | <a class=\"small\" href=\"links.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">LINKS</a> | <a class=\"small\" href=\"contact.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">CONTACT US</a> | <a class=\"small\" href=\"home.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">HOME</a> |</span></p>");
	document.writeln("</tr>");
	document.writeln("</table>");
	// copyright
	document.writeln("<table BORDER=0 colspan=2 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");	
	document.writeln("<tr>");	
	document.writeln("<TD VALIGN=CENTER ALIGN=CENTER><span class=\"s2\"><br><br>Web design by Maluco. All Rights Reserved. Copyright © 2003.<br><br></span></TD>");
	document.writeln("</tr>");
	document.writeln("</table>");
	document.writeln("</div>");
}

function generateCourseMaterial()
{
	var coursePtr = decodePassedCoursePtr();
	
	
	if (eval(coursePtr) == null) {
		window.location="./home.htm";
	}	
	
	var len = eval(coursePtr + ".length");
	
	document.writeln("<div id=\"main_body\" class=\"main\">");
	document.writeln("<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");
	document.writeln("<tr>");
	document.writeln("<td ALIGN=CENTER VALIGN=bottom WIDTH=\"625\" HEIGHT=\"1\" ><img SRC=\"../images/spacer.gif\" height=1 width=625></td>");
	document.writeln("</tr>");	
	// Section title
	document.writeln("<tr>");	
	document.writeln("<td WIDTH=\"625\"><span class=\"s71\"><br>Course Material</span></td>");
	document.writeln("</tr>");			
	// Print material	
	for (var i=0; i<len; i++) {			
		// file title and name
		document.writeln("<tr>");
		var iItem = eval(coursePtr + "[" + i + "]");
		var iFileName = "href=\"" + iItem.fileName + "\"";
		var iShowText = iItem.showText + " - right click here to download the file";		
		var iFile = "<td WIDTH=\"625\"><span class=\"s41\"><br><a class=\"a32\" " + iFileName + " onmouseover=\"this.style.color='orange';\" onmouseout=\"this.style.color='navajowhite';\">" + iShowText + "</a></span></td>";
		document.writeln(iFile);
		document.writeln("</tr>");
	}
	document.writeln("</table>");
	// bottom menu
	document.writeln("<table BORDER=0 colspan=2 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");
	document.writeln("<tr>");
	document.writeln("<td ALIGN=center VALIGN=top>");
	document.writeln("<br><br>");
	document.writeln("<a href=\"#Top\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightsteelblue\';\">Top of the page</a>");
	document.writeln("<p align=\"center\"><span class=\"s11\">| <a class=\"small\" href=\"training.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">TRAINING</a> | <a class=\"small\" href=\"services.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">SERVICES</a> | <a class=\"small\" href=\"photo1.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">PHOTO ALBUM</a> | <a class=\"small\" href=\"equipment.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">EQUIPMENT</a> | <a class=\"small\" href=\"miscellaneous.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">MISCELLANEOUS</a> | <a class=\"small\" href=\"links.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">LINKS</a> | <a class=\"small\" href=\"contact.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">CONTACT US</a> | <a class=\"small\" href=\"home.htm\" onmouseover=\"this.style.color=\'navajowhite\';\" onmouseout=\"this.style.color=\'lightskyblue\';\">HOME</a> |</span></p>");
	document.writeln("</tr>");
	document.writeln("</table>");
	// copyright
	document.writeln("<table BORDER=0 colspan=2 CELLSPACING=0 CELLPADDING=0 WIDTH=\"625\">");	
	document.writeln("<tr>");	
	document.writeln("<TD VALIGN=CENTER ALIGN=CENTER><span class=\"s2\"><br><br>Web design by Maluco. All Rights Reserved. Copyright © 2003.<br><br></span></TD>");
	document.writeln("</tr>");
	document.writeln("</table>");
	document.writeln("</div>");
}	