// Array function...

function makeArray() {
var args=makeArray.arguments;
    for (var i=0; i < args.length; i++) {
    this[i]=args[i];
    }
this.length=args.length;
}

// This function determines which page is selected and goes to it...

function goPage(form) {
i=form.menu.selectedIndex;            
    if (i != 0) {
//    window.parent.location.href=urls[i];  
    parent.location.href=urls[i];  
    }
}

function goto_page(page){
   parent.location.href=page;
}

function set_progress_bar() {
   document.prog_bar.src=prog_bar_src;
   document.prog_bar.alt=prog_bar_alt;
}

function EvalCompleted() {
var comment_string;
var today=new Date();
var year=today.getYear();
var i;

      if (year < 1000 ) {year += 1900}; 
            document.EvalForm.date.value=(today.getMonth()+1)+"/"+today.getDate()+"/"+year;
     return true;
}


//cookie read-write functions

function setCookie(name, value, expires, path, domain, secure)
{
	
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
   endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,endstr));
}

//function to return the value of the cookie specified by "name".

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 deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function isNumberString (InString)  {
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}


//functions and arrays for the no_skip feature

//this array holds the URLs of the pages that are required.  By 
//default, the policy page is required.  If there are any additional 
//pages required, add them to this list.

var access_pages_array=new makeArray(
                         "520.php");

//this array holds the titles of the pages that are required.  By 
//default, the policy page is required.  If there are any additional 
//pages required, add them to this list.

var access_pages_desc_array=new makeArray(
                         "Policy");

//function to get the list of pages that have been accessed and pass to the cgi script to compare to the required list of pages.

function CheckAccessList() {
var i;
var accessed_pages, checkValue;
now = new Date();
var endTime = now.getTime();
var total_duration = prevTime + (endTime - startTime);
var total_duration_string = displayTime(total_duration);

if (total_duration < total_elapsed_time)
{
   alert("You have not spent at least "+total_time_text+", the required amount of time reviewing the material. You have spent "+total_duration_string+".  The next screen will provide a list of supplemental material you may have overlooked.");
  location.href="supplemental.php";
   return false;
}
else
{
   accessed_pages=getCookie("NML_PAGE_LIST");
   for (i=0;i<access_pages_array.length;i++)
   {
     if (i == 0)
       document.User.access_page_list.value = access_pages_array[i] + ":" + access_pages_desc_array[i];
     else
      document.User.access_page_list.value = document.User.access_page_list.value + "~" + access_pages_array[i] + ":" + access_pages_desc_array[i];
   }
    document.User.cookie_set_list.value=accessed_pages;
    return true;
}
}

function AccessPage(page_name, page_url) 
{
  var access_pages_set, saved_access_pages;
  var end_page = new Date();
  var endTime = end_page.getTime();
  var now=new Date();

// first check if cookie is already set
  access_pages_set=getCookie("NML_PAGE_LIST");
  if (access_pages_set != null)
  {
    access_pages_set=access_pages_set+";"+page_name+"="+page_url;
  }
  else
  {
    access_pages_set=page_name+"="+page_url;
  }
//now check if cookie was saved from a previous session
  saved_access_pages=getCookie("savedNML_PAGE_LIST");
//  alert("found saved cookies "+saved_access_pages);
  if (saved_access_pages != null)
  {
     access_pages_set=access_pages_set+";"+saved_access_pages;
     deleteCookie("savedNML_PAGE_LIST");
  }
//set page list cookie to expire in 2 hrs.
   exp_date=endTime + time_to_live;
   now.setTime(exp_date);
   setCookie("NML_PAGE_LIST", access_pages_set,now);
}




