function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function HSP_openBrWindow(theURL,winName,contentType) {
  <!--features = "menubar=yes,scrollbars=yes,resizable=yes,width=700,height=300";-->
  if(contentType == "a"){
  	features = "menubar=yes,scrollbars=yes,resizable=yes,width=500,height=400";
  }
  if(contentType == "b"){
  	features = "menubar=yes,scrollbars=yes,resizable=yes,width=750,height=550";
  } 
   if(contentType == "c"){
  	features = "menubar=yes,scrollbars=yes,toolbar=1,resizable=yes,width=660,height=550"
  }
  if(contentType == "d"){
  	features = "menubar=yes,scrollbars=yes,resizable=yes,width=750,height=600";
  }
  if(contentType == "e"){
  	features = "menubar=no,scrollbars=no,resizable=yes,width=275,height=220";
  }
    
  if(contentType == "f"){
  	features = "menubar=yes,scrollbars=yes,resizable=yes,width=1000,height=650";
  }
  window.open(theURL,winName,features);
}



///////////////////////////////////////////////////
//  Protecting protected content
///////////////////////////////////////////////////

//  Here are the session cookies used
//	secure=on  ( set after a successful sign in or registration)
//  requestedProtectedPath=window.location.pathname  ( this is used to direct to content after sign in or registration)

protectedPath = "/ctf/nsmedia/parish/parish/adult_enrichment_resources.html";

protectedPaths = new Array();
protectedPaths[0] = "/ctf/nsmedia/school/admin/adult_enrichment_resources.html";
protectedPaths[1] = "/ctf/nsmedia/school/admin/lesson_resources.html";
protectedPaths[2] = "/ctf/nsmedia/school/admin/lesson_planner.html";
protectedPaths[3] = "/ctf/nsmedia/school/teachers/teacher_enrichment_resources.html";
protectedPaths[4] = "/ctf/nsmedia/school/teachers/lesson_resources.html";
protectedPaths[5] = "/ctf/nsmedia/school/teachers/lesson_planner.html";
protectedPaths[6] = "/ctf/nsmedia/parish/dres/teacher_enrichment_resources.html";
protectedPaths[7] = "/ctf/nsmedia/parish/dres/lesson_resources.html";
protectedPaths[8] = "/ctf/nsmedia/parish/dres/lesson_planner.html";
protectedPaths[9] = "/ctf/nsmedia/parish/catechists/lesson_resources.html";
protectedPaths[10] = "/ctf/nsmedia/parish/catechists/lesson_planner.html";
protectedPaths[11] = "/pof/program/about.html";
protectedPaths[12] = "/pof/program/hfamily.html";
protectedPaths[13] = "/pof/program/john.html";
protectedPaths[14] = "/pof/program/mary.html";
protectedPaths[15] = "/pof/program/michael.html";
protectedPaths[16] = "/pof/program/music.html";
protectedPaths[17] = "/pof/program/overview.html";
protectedPaths[18] = "/pof/program/p_faq.html";
protectedPaths[19] = "/pof/program/p_global.html";
protectedPaths[20] = "/pof/program/p_happen.html";
protectedPaths[21] = "/pof/program/p_select.html";
protectedPaths[22] = "/pof/program/p_share.html";
protectedPaths[23] = "/pof/program/p_web_act.html";
protectedPaths[24] = "/pof/program/p_web_believe.html";
protectedPaths[25] = "/pof/program/p_web_cel.html";
protectedPaths[26] = "/pof/program/p_web_explore.html";
protectedPaths[27] = "/pof/program/p_web_follow.html";
protectedPaths[28] = "/pof/program/p_web_live.html";
protectedPaths[29] = "/pof/program/p_web_pray.html";
protectedPaths[30] = "/pof/program/p_web_worship.html";
protectedPaths[31] = "/pof/program/parish.html";
protectedPaths[32] = "/pof/program/pbudget.html";
protectedPaths[33] = "/pof/program/pdev.html";
protectedPaths[34] = "/pof/program/peval.html";
protectedPaths[35] = "/pof/program/pfac.html";
protectedPaths[36] = "/pof/program/plead.html";
protectedPaths[37] = "/pof/program/plearn.html";
protectedPaths[38] = "/pof/program/pparent.html";
protectedPaths[39] = "/pof/program/ppro.html";
protectedPaths[40] = "/pof/program/pquest.html";
protectedPaths[41] = "/pof/program/preality.html";
protectedPaths[42] = "/pof/program/pschedule.html";
protectedPaths[43] = "/pof/program/pschool.html";
protectedPaths[44] = "/pof/program/pvision.html";
protectedPaths[45] = "/pof/program/psurvey.html";




requestPath = window.location.pathname;

needProtection = "no"
i = 0;
while(i < protectedPaths.length){
	if(requestPath == protectedPaths[i]){
		needProtection = "yes"
	}
	i++;
}

if(needProtection == "yes"){
//	alert("This content needs to be protected");

//	document.cookie = "secure=off; path=/";
	document.cookie = "requestedProtectedPath="+requestPath+"; path=/";

	//  Check to see if the visitor as already signed in
	//  A successfull sign in will set a session cookie of this value secure=on
	
	secure = getCookie("pathsecure");
	if(secure == "on"){
//		alert("secure="+secure);
		// Do nothing.  Let the page load.  The visitor has already signed in.
	}
	else{
//		alert("secure="+secure);
		//  The visitor needs to sign in before seeing this content.
		//  Send them to the sign in page.
		window.location.href = "/ctf/nsmedia/signin/signin.jsp";
	}
}


function getCookie(name){
	var cookieName = name + "=";
	var cookieLength = document.cookie.length;
	var cookieBegin = 0;
	while (cookieBegin < cookieLength) {
		var valueBegin = cookieBegin + cookieName.length;
		if (document.cookie.substring(cookieBegin, valueBegin) == cookieName) { 
			var valueEnd = document.cookie.indexOf (";", valueBegin);
			if (valueEnd == -1) valueEnd = cookieLength;
				return unescape(document.cookie.substring(valueBegin, valueEnd));
			}
		cookieBegin = document.cookie.indexOf(" ", cookieBegin) + 1;      
		if(cookieBegin == 0){
			cookieBegin = cookieLength;
		}
	}
	return null;
}
