//nyspltc.js

var glossaryWindow=null;
var footnoteWindow=null;
var largeImageWindow=null;
var loginWindow=null;

function openGlossary(term)
{
	//Opens Glossary window and goes to term. Currently does not scroll to Term
	//Anchors are term characters (filter a-Z 0-9 only, no spaces, no non-alphanumerics) so 
	//we need to take term and strip spaces and non-alphanumerics and ass that to the url to be opened
	//jh.kx - 06-07-2001
	var text="../../glossary.htm#"+term;

         	if (glossaryWindow != null) 
	{
		if (!glossaryWindow.closed) 
		{
			glossaryWindow.close();
		}
		glossaryWindow = null;
	}
        
	if(!glossaryWindow || glossaryWindow.closed) 
	{
		glossaryWindow = window.open(text,"glossaryWindow",'toolbar=no,resizable=yes,status=yes,scrollbars=yes,location=no,menubar=no,directories=no,width=400,height=400,left=200,top=200');
	}

	glossaryWindow.document.location= text;
	glossaryWindow.focus();
}

function openFootnote(footnotenumber)
{
	//Opens Footnotes window. scroll to anchor who's text is equivalent to footnotenumber
	//jh.kx - 06-07-2001

	var text="../footnotes/content.htm#"+footnotenumber;

         	if (footnoteWindow != null) 
	{
		if (!footnoteWindow.closed) 
		{
			footnoteWindow.close();
		}
		footnoteWindow = null;
	}
        
	if(!footnoteWindow || footnoteWindow.closed) 
	{
		footnoteWindow = window.open(text,"footnoteWindow",'toolbar=no,resizable=yes,status=yes,scrollbars=yes,location=no,menubar=no,directories=no,width=650,height=400,left=200,top=200');
	}

	footnoteWindow.document.location= text;
	footnoteWindow.focus();
}

function enlargeImage(url)
{
	//handles click to enlarge image window
	//maybe in the future we'll add a Click Here to Close Window link
	//we'll need to open a window and write the html with <img> and <a> 's in it 
	//instead of just targeting the image.
	//this way is simple and works
	//jh.kx - 06-07-2001

	var text=url;

         	if (largeImageWindow != null) 
	{
		if (!largeImageWindow.closed) 
		{
			largeImageWindow.close();
		}
		largeImageWindow = null;
	}
        
	if(!largeImageWindow || largeImageWindow.closed) 
	{
		largeImageWindow = open("","largeImageWindow",'toolbar=no,resizable=yes,status=yes,scrollbars=yes,location=no,menubar=no,directories=no,width=680,height=520,left=200,top=200');
	}

		largeImageWindow.document.writeln('<html><body bgcolor="#FFFFFF">');
		largeImageWindow.document.writeln('<link rel="stylesheet" href="../../styles/nysltc.css">');
	
		largeImageWindow.document.writeln("<a href='javascript:window.close()' class='closeWindowLink' >Click Here to Close Window<\/a>");
		largeImageWindow.document.writeln("<img src='"+text+"'>");
		largeImageWindow.document.writeln("<\/body><\/html>");
		largeImageWindow.document.close();
		largeImageWindow.focus();
}

function openLoginWindow(){
	//handles login window
	//jh.kx - 06-07-2001

	var text='login_pop.htm';

         	if (loginWindow != null) 
	{
		if (!loginWindow.closed) 
		{
			loginWindow.close();
		}
		loginWindow = null;
	}
        
	if(!loginWindow || loginWindow.closed) 
	{
		loginWindow = window.open(text,"loginWindow",'scrollbars=yes,width=520,height=500');
	}

	loginWindow.document.location= text;
	loginWindow.focus();

	
}



function kxInit()
{
	var loc=document.location.href+"";
	//function to execute on onLoad of each page
	//we'll be setting the user's cookie for the current location
	//might need to check if user is logged in and redirct to login page if not
	//not sure if this functionality is required yet
	//jh.kx -06-07-2001
	
	cookieName ="nyspltctrainingLPV";
	
	var cookie = document.location ;
//	alert("LPV Cookie  is " + cookie);
	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
	SetCookie(cookieName,cookie,expdate,"/",null);
	
	
	

//	content tracking

	if ((loc.indexOf('ch01')>0) &&(loc.indexOf('chapter')>0))
		{
	//		alert('chapter 1 - in progress');
			cookieName ="Ch01Progress";
			var cookie = 'started';
		//	alert("LPV Cookie  is " + cookie);
			var expdate = new Date ();
			FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
			expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
			SetCookie(cookieName,cookie,expdate,"/",null);
			if (loc.indexOf('01_13')>0) {
		//		alert ('Completed');
				cookieName ="Ch01ProgressComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
				
			
		}
		

	if ((loc.indexOf('ch02')>0) &&(loc.indexOf('chapter')>0))
		{
	//		alert('chapter 2 - in progress');
			cookieName ="Ch02Progress";
			var cookie = 'started';
		//	alert("LPV Cookie  is " + cookie);
			var expdate = new Date ();
			FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
			expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
			SetCookie(cookieName,cookie,expdate,"/",null);
			if (loc.indexOf('02_19')>0) {
		//		alert ('Completed');
				cookieName ="Ch02ProgressComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
		}
	
	if ((loc.indexOf('ch03')>0) &&(loc.indexOf('chapter')>0))
		{
	//		alert('chapter 3 - in progress');
			cookieName ="Ch03Progress";
			var cookie = 'started';
		//	alert("LPV Cookie  is " + cookie);
			var expdate = new Date ();
			FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
			expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
			SetCookie(cookieName,cookie,expdate,"/",null);
			if (loc.indexOf('03_20')>0) {
	//			alert ('Completed');
				cookieName ="Ch03ProgressComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
		}
	
	
	
	
	
	// assessment tracking
	
	if  ((loc.indexOf('ch01')>0) &&(loc.indexOf('assessment')>0))
		{
			//alert('chapter 1 assessment - in progress');
			if (loc.indexOf('q_6')>0) {
	//			alert ('Completed');
				cookieName ="Ch01AssessmentComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
				
			
		}	

		

	if  ((loc.indexOf('ch02')>0) &&(loc.indexOf('assessment')>0))
		{
			//alert('chapter 2 assessment - in progress');
			if (loc.indexOf('q_7')>0) {
	//			alert ('Completed');
				cookieName ="Ch02AssessmentComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
				
			
		}

	if  ((loc.indexOf('ch03')>0) &&(loc.indexOf('assessment')>0))
		{
			//alert('chapter 3 assessment - in progress');
			if (loc.indexOf('q_8')>0)  {
	//			alert ('Completed');
				cookieName ="Ch03AssessmentComp";
				var cookie = 'Completed';
			//	alert("LPV Cookie  is " + cookie);
				var expdate = new Date ();
				FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
				expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
				SetCookie(cookieName,cookie,expdate,"/",null);
			}
		}
	
//	if (idx>0) {
//		cookieName ="NYSPLTCprogress";
//		cookie=cookie.substr(idx,4);
//		alert("Progress Cookie  is " + cookie);
//		var expdate = new Date ();
//		FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
//		expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
//		SetCookie(cookieName,cookie,expdate,"/",null);
//	}
	

}



<!--

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}


function GetCookie (name) {
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//

  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
//  alert("Document's Cookie is " + document.cookie);
  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,expires,path,domain,secure) {
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//

 //  alert("Setting the cookie");

  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


function DeleteCookie (name,path,domain) {
//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//

  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function submitLoginForm(location) {
	
	//this function will check the users cookie
	//UserID and Password aand must match cookie values	
	//location is where we're going on a sucessful login
	// jh.kx 06-07-2001

	//alert("Submitting Form Location is " + location);
	var c1 = GetCookie("nyspltctraining");

	var cookName = "";
	var cookPwd = "";

	if (c1 != null) {
		var vals = c1.split(",");
		cookName = vals[0];
		cookPwd = vals[1];
	}

	var uName = document.forms[0].uid.value;
	var uPwd = document.forms[0].pwd.value;

	if (c1 == null || uName != cookName) {
		alert("Please Register as a new User");
	}
	else if (uName != cookName || uPwd != cookPwd) {
		alert ("Please Check Your User ID and Password and try again");
	}
	else {
		if (location=="lastVisit") {
		    location=GetCookie("nyspltctrainingLPV");
		    if (!location) {
		       location="";
		    }
		}
		opener.document.location = location;
		window.close();
	}
	return false;
}

function submitAddUserForm(location) {
	
	//this function will get info from adduser login form and write it to the users cookie
	//UserID and Password are required, all others are optional	
	//location is where we're going on a sucessful add user
	// jh.kx 06-07-2001

	//alert(" Setting Cookies ");
	// Let's add the cookie
	cookieName ="nyspltctraining";
	var jobType = "";

	//check if job type is other and set jobType to the input field value
	//check the radio buttons
	
	for (i=0; i< document.forms[1].jobDesc.length; i++){
		if ( document.forms[1].jobDesc[i].checked ) jobType=document.forms[1].jobDesc[i].value;
	}
	if ((document.forms[1].newUid.value == null) || (document.forms[1].newUid.value == "") || (document.forms[1].newPwd.value == null) || (document.forms[1].newPwd.value == "")) {
		alert ("User ID and Password are Required");
	}
	else {
		var cookie = document.forms[1].newUid.value + ',' + document.forms[1].newPwd.value + ',' + document.forms[1].firstname.value + ',' + document.forms[1].lastname.value + ',' + document.forms[1].email.value + ',' + jobType;
	//	alert("Cookie  is " + cookie);
		var expdate = new Date ();
		FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
		expdate.setTime (expdate.getTime() + (30 *24 * 60 * 60 * 1000)); // 24 hrs from now 
		SetCookie(cookieName,cookie,expdate,"/",null);
		opener.document.location.href = location ;
		document.forms[1].submit();
		window.close();
		DeleteCookie ("Ch01Progress","/",null);
		DeleteCookie ("Ch01ProgressComp","/",null);
		DeleteCookie ("Ch01Assessment","/",null);
		DeleteCookie ("Ch02Progress","/",null);
		DeleteCookie ("Ch02ProgressComp","/",null);
		DeleteCookie ("Ch02Assessment","/",null);
		DeleteCookie ("Ch03Progress","/",null);
		DeleteCookie ("Ch03ProgressComp","/",null);
		DeleteCookie ("Ch03Assessment","/",null);
		DeleteCookie ("Ch01AssessmentComp","/",null);
		DeleteCookie ("Ch02AssessmentComp","/",null);
		DeleteCookie ("Ch03AssessmentComp","/",null);
	}
	
	
}

function doCrossLink(loc){
	loc=String(loc);
//	alert(loc);
	if (loc=="logo"){
		document.location="#"+loc
	}
	if (loc!="logo"){
		idx=loc.indexOf('lesson')
		loc=loc.substr(idx+6,5);
		idx=loc.indexOf("_");
		chapt=loc.substr(0,idx);
		sect=loc.substr(idx+1,idx+3);
		if (chapt<10) {
			chapt="0"+chapt;
		}
	
		if (sect<10) {
			sect="0"+sect;
		}
		loc = "../../ch"+chapt+"/chapter"+chapt+"_"+sect+"/content.htm";
//		alert(loc);
		parent.document.location = loc;
	}
	
}

function readCookies () {
	var nyspltctrainingLPV=""
	GetCookie(nyspltctrainingLPV);
	nyspltctrainingLPV=document.cookie
	//alert(nyspltctrainingLPV);
	idx=nyspltctrainingLPV.indexOf('Ch01Progress')
	if (idx>0){
		ch1Content=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch01ProgressComp')
		Ch01ContentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch01ContentComp);
		if (ch1Content=="Ch01Progress=started"){
			document.images.lesson1.src="images/progress2.gif"
		}
		if (Ch01ContentComp=="Ch01ProgressComp=Complet"){
			document.images.lesson1.src="images/progress3.gif"
		}
	}
	idx=nyspltctrainingLPV.indexOf('Ch02Progress')
	if (idx>0){
		ch2Content=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch02ProgressComp')
		Ch02ContentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch02ContentComp);
		if (ch2Content=="Ch02Progress=started"){
			document.images.lesson2.src="images/progress2.gif"
		}
		if (Ch02ContentComp=="Ch02ProgressComp=Complet"){
			document.images.lesson2.src="images/progress3.gif"
		}
	}
	idx=nyspltctrainingLPV.indexOf('Ch03Progress')
	if (idx>0){
		ch3Content=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch03ProgressComp')
		Ch03ContentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch03ContentComp);
		if (ch3Content=="Ch03Progress=started"){
			document.images.lesson3.src="images/progress2.gif"
		}
		if (Ch03ContentComp=="Ch03ProgressComp=Complet"){
			document.images.lesson3.src="images/progress3.gif"
		}
	}
	idx=nyspltctrainingLPV.indexOf('Ch01Assessment')
	if (idx>0){
		ch1Assessment=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch01AssessmentComp')
		Ch01AssessmentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch01AssessmentComp);
		if (ch1Assessment=="Ch01Assessment=start"){
			document.images.understanding1.src="images/progress2.gif"
		}
		if (Ch01AssessmentComp=="Ch01AssessmentComp=Compl"){
			document.images.understanding1.src="images/progress3.gif"
		}
	}
	idx=nyspltctrainingLPV.indexOf('Ch02Assessment')
	if (idx>0){
		ch2Assessment=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch02AssessmentComp')
		Ch02AssessmentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch02AssessmentComp);
		if (ch2Assessment=="Ch02Assessment=start"){
			document.images.understanding2.src="images/progress2.gif"
		}
		if (Ch02AssessmentComp=="Ch02AssessmentComp=Compl"){
			document.images.understanding2.src="images/progress3.gif"
		}
	}
	idx=nyspltctrainingLPV.indexOf('Ch03Assessment')
	if (idx>0){
		ch3Assessment=nyspltctrainingLPV.substr(idx,20)
		idxComp=nyspltctrainingLPV.indexOf('Ch03AssessmentComp')
		Ch03AssessmentComp=nyspltctrainingLPV.substr(idxComp,24)
	//	alert(Ch03AssessmentComp);
		if (ch3Assessment=="Ch03Assessment=start"){
			document.images.understanding3.src="images/progress2.gif"
		}
		if (Ch03AssessmentComp=="Ch03AssessmentComp=Compl"){
			document.images.understanding3.src="images/progress3.gif"
		}
	}
}


