// must be loaded AFTER file-specific .js file which defines thisTopicId
// and AFTER at_<SECTION_NAME>.js which defines array of topic objects
function getPathToRoot() {
//return "http://iffstage.atypica.com";
return "http://www.interfaithfamily.com";
}

var pathtoroot = getPathToRoot(); //save function calls throughout module
var indentPixels = 6;
var levelWidth = 189;
var maxIndent = 6; //8
var thisTopicObj = null;
var maxATcolumns=15;
//var dbgWindow = null;
//alert('in at.js');
function NewWin(u){
	// inaptly named but... this function used by Phorum SLS to create reply
	if (u==null) { alert ("Sorry, we cannot open new window at this time. Please report this error (code=0003). Thank you."); }
	else {
		var newwin=window.open(u,"SLSREPLYWIN","height=500,width=500,resizable=yes,scrollbars=yes,status=yes");
	}
}
function getLogoImages(p2root){
	var retStr='<div align="left">';
	if (arguments.length == 1 || arguments[1] == true) {
		retStr += '<a href="' + getPathToRoot() + '/index.htm"><img src="';
	}
	else {
		retStr += '<img src="';
	}
	if  (p2root.indexOf('www.myjewishlearning.com') > -1) {
		retStr += '/common/images/logo.gif" width="325" height="63" border=0"></a>';
	}
	else if (p2root.indexOf('jewishla.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images/jewishlalogo.gif" width="114" height="63" >';
	}
	else if (p2root.indexOf('hillel.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images/hillel.jpg" width="114" height="63" >';
	}
	else if (p2root.indexOf('hadassah.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><a href="www.hadassah.org" target="_blank"><img src="/common/images/hadassah.jpg" width="114" height="63" alt="Go to Hadassah.org Web site"></a>';
	}
	else if (p2root.indexOf('jcc.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images/jcc.jpg" width="114" height="63" >';
	}
	else if (p2root.indexOf('bbyo.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images/bbyo.jpg" width="114" height="63" >';
	}
	else if (p2root.indexOf('star.myjewishlearning.com') > -1) {
		retStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images/star.jpg" width="114" height="63" >';
	}
	// catch all case
	else {
		retStr += '/common/images/logo.gif" width="325" height="63" border="0" ></a>';
	}
	return retStr ;
}
function getPageContext(){
	var ctx = getParamVal("GL");
	if (ctx == null && typeof(thisPageTemplate) != 'undefined') {
		// for Index pages don't burden caller to specify GL parameter
		//alert('at.js: thisPageTemplate='+thisPageTemplate);
		return thisPageTemplate ;
	}
	else if (ctx != null && ctx.toLowerCase() == 'true') {
		return 'GL';
	}
	else if (ctx != null && ctx.toLowerCase() == 'idx') {
		// in case caller wants to force the "index" style left hand panel
		// even though page doesn't declare it's an Index page
		return 'IDX';
	}
	else {
		// the most common case
		return 'AT';
	}
}
function isSibling(t1,t2){
	// t1 is topic being tested
	// t2 is the selected topic for article
	// if t1 differs from t2 only in last element then they are siblings
	if (chopTopic(t1,1)==chopTopic(t2,1)) { return true; }
	else {return false;}
}
function topicDepth(key){
	// count dots in key
	var count = 0;
	for (var i=0;i < key.length;i++) {
		if (key.charAt(i) == ".") { count++ ; }
	}
	return count;
}
function trimTopic(str,count){
	// cut off "count" leading topic identifiers from string
	var dotloc=-1;
	for (var i=0; i > count; i++){
		if ((dotloc=str.indexOf('.',dotloc+1)) == -1) { return null ; }
	}
	return str.substring(dotloc+1) ;
}
function chopTopic(str,count){
	// cut off "count" trailing path elements
	var dotloc=-1;
	for (var i=0; i < count; i++){
		dotloc=str.lastIndexOf('.');
		if (dotloc == -1) { return null; }
		str = str.substring(0,dotloc);
	}
	return str ;
}

function initAllTopics(){
	// go through array of topics and set items menustate
//	for (var i=0; i < allTopicsElements.length; i++) {
//		// set up object's own index field
//		allTopicsElements[i].arrayIndex=i;
//		if (allTopicsElements[i] != null )
//			initTopic(allTopicsElements[i]) ;
//	}
}
function initTopic(topicObj){
/*
summer 2003:
We compare thisTopicId with the topicid of topicObj:
-we set hasChildren attribute
-we set state for ancestor/sibling/child of current topic:
STATES:
0. default state (do not display at all)
1. display as OPEN in bold using ">" since this is the current item!
2. diplay as OPEN in normal since this is ancestor of current item
3. display as CLOSED in normal since thie is child of current item
3. display as CLOSED in normal since this is sibling of current item
3. display as CLOSED in normal since this is sibling of ancestor current item
3. display as CLOSED in normal since this is first level item (non-ancestral)
*/
	//NOTE: Do not change the order of the following if...else if...else structure!!
	topicObj.menustate = 0;
	// special cases first: this page does not appear in AT and so
	// if we are looking at it we are in GL context or some other context
	if (thisTopicId == null ) { return; }
	else if (topicObj.topicId == thisTopicId) {
		// this is the current topic!
		topicObj.menustate=1;
		hasChildren(topicObj);
		thisTopicObj = topicObj; // save it for later
	}
	else if (thisTopicId.indexOf(topicObj.topicId) == 0) {
		// ancestor of current topic at some level
		topicObj.menustate=2;
		hasChildren(topicObj);
	}
	else if (topicObj.indent == 0) {
		// first level item but not ancestor
		topicObj.menustate=3;
		hasChildren(topicObj);
	}
	else if (topicObj.topicId.indexOf(thisTopicId) == 0 &&
			topicDepth(topicObj.topicId) == (topicDepth(thisTopicId) + 1) ){
		// direct child
		topicObj.menustate=3;
		hasChildren(topicObj);
	}
	else if (chopTopic(topicObj.topicId,1) == chopTopic(thisTopicId,1)){
		// sibling -- show it
		topicObj.menustate=3;
		hasChildren(topicObj);
	}
	else {
		// handle the siblings of each ancestor!
		for (var j=0;j < topicDepth(thisTopicId)-1;j++){
			if (isSibling(topicObj.topicId,chopTopic(thisTopicId,j))){
				topicObj.menustate=3;
				hasChildren(topicObj);
			}
		}
	}
}
function hasChildren(tObj){
	// set tObj.hasChildren to true or false acc. to whether tObj has any children
	tObj.hasChildren = false; // simplifies the ELSE case below
	// note that we need only check the NEXT item but since it might be null we use a strange for loop
	for (var i=tObj.arrayIndex+1;i<allTopicsElements.length; i++) {
		if (allTopicsElements[i] == null) { continue; }
		else if (allTopicsElements[i].topicId.indexOf(tObj.topicId)>-1){
			tObj.hasChildren = true;
			return;
		}
		else {
			return;
		}
	}
}

function chooseTag(i){
	var tObj=allTopicsElements[i];
	var colspan = maxATcolumns - (tObj.indent+1);
	var retStr = '<td colspan="'+ colspan + '" valign="top">';
	if (tObj.menustate != 1) {
		retStr += '<p class="green"><a href="' + tObj.url + '">';
	}
	else {
		retStr += '<p class="current"><a class="gl" href="' +	tObj.url + '">';
	}
	retStr += tObj.tag + '</a><br></p></td>';
    //alert(retStr);
	return retStr;
}
function choosePMA(idx){
	// usual case: has children and is not opened
	var retStr = null;
	var tObj=allTopicsElements[idx];
	if (tObj.menustate==1) {
		retStr = '<p class="current"><a href="' + tObj.url + '">';
		retStr += '<img border="0" src="/common/images/treebits/arrow.gif" width="9" height="9" align="texttop">';
	}
	else if (tObj.menustate==2 || !tObj.hasChildren) {
		retStr = '<p class="green"><a href="' + tObj.url + '">';
		retStr += '<img border="0" src="/common/images/treebits/minus.gif" width="9" height="9" align="texttop">';
	}
	else {
		retStr = '<p class="green"><a href="' + tObj.url + '">';
		retStr += '<img border="0" src="/common/images/treebits/plus.gif" width="9" height="9" align="texttop">';
	}
	retStr += '</a>';
    //alert(retStr);
	return retStr;
}
function fixupDetailLineItemArray(arr){
	// forward traverse array to set branchlast property
	var i=0;
	while (i<arr.length){
		// no branchlast for indent 0 items!
		//20030808 no vertstretch at all
		arr[i].needVertStretch = false;
		if (arr[i].indent==0) {	arr[i].branchlast=null; }
		else {
			//if no next node or next node is less indented, then this node is LAST
			if (i==(arr.length-1) || arr[i+1].indent < arr[i].indent) {
				arr[i].branchlast='last';
			}
			else {
				arr[i].branchlast='branch';
			}
		}
		i++;
	}
	/*
	var dbgStr='Following are array elements \n';
	for (var i=10;i<arr.length;i++){
		dbgStr += '   VSTRETCH:' + arr[i].needVertStretch  + '\n'+
			// 'INDENT:' + arr[i].indent  + '\n'+
			// '   PMA:' + arr[i].pma  + '\n'+
			  '   TAG:' +  arr[i].detail + '\n';
	}
	alert(dbgStr);
	*/
}
function AllTopics(){
	var root= null;
	if (arguments.length > 1 ) { root = arguments[1];}
	var glCtxt=getPageContext();
	document.write('<table width="170" border="0" cellspacing="0" cellpadding="0">');
	if (glCtxt == 'GL' || glCtxt == 'IDX') {
		// just show top level nodes
		collapseAllTopics(root);
	}
	else {
		// open tree to correct node, showing ancestors, siblings, direct children, and siblings of ancestors
		showAllTopics(false,root);
	}
	document.write('</table>');
    //showReadability();
}
function collapseAllTopics(r){
	showAllTopics(true,r);
}

function showAllTopics(top,r){
    // new if Feb 05, 2004 - don't display this info for links pages
    if (allTopicsMainTopicId!='LI') {
    	document.write('<tr><th colspan="'+(maxATcolumns)+'"><p class="menutitle">Explore on Your Own: ');
	    document.write(allTopicsSectionTitle +'<br><span style="text-align:left; font-size:12px">');
    	document.write(allTopicsElements.length +' Articles</span></p></th></tr>');
    }
	if (top == true) {
		// handle special collapsed case quickly
		var tmpidx=0;
		var detailline='';
		var detailline2='';
		for (var i=0;i<allTopicsElements.length;i++){
			if (allTopicsElements[i].indent==0){
				// show all first level items (menustate always 3)
				if ((tmpidx++)>0){
					//end previous item unless first time through
					document.write(detailline + detailline2);
				}
				//20030808 no vertstretch anymore
				//detailline='<tr><td align="left" class="vertstretch" valign="top">';
				detailline='<tr><td align="left" valign="middle">';
				detailline+='<a href="'+allTopicsElements[i].url + '">';
				if (allTopicsElements[i].hasChildren) {
					detailline2='<img border="0" src="/common/images/treebits/plus.gif" width="9" height="9"></a></td>';
				}
				else {
					detailline2='<img border="0" src="/common/images/treebits/minus.gif" width="9" height="9"></a></td>';
				}
                  		detailline2+='<td colspan="'+(maxATcolumns-1)+' valign="middle">';
				detailline2+='<p class="sectionhead"><a href="';
				detailline2+=allTopicsElements[i].url + '">';
				detailline2+=allTopicsElements[i].tag;
				detailline2+='</a></p></td></tr>';
			}
		}
		//20030808 no vertstretch anymore
		// last line does not get a vertstretch!
		//detailline='<tr><td align="left" valign="top">';
		document.write(detailline + detailline2);
		//alert('showAllTopics at end of loop for top==true--wrote out:\n ' + detailline + detailline2);
	}
	else {
		// show each node at appropriate depth and open/closed/invisible state
		// using object state and hasChildren attributes
		// make sure the current node is shown in bold red(?)
		// following set up inside loop for each item
		var detailLineItemArray=new Array();

		var arrayIdx=0;
		var colspan=0;
		var lineItem=null;
		// create array of line item objects
		for (var i=0;i<allTopicsElements.length;i++){
			if (allTopicsElements[i]==null || allTopicsElements[i].menustate == 0) {continue;}
			lineItem = new Object();
			lineItem.indent=allTopicsElements[i].indent;
			lineItem.idx=i;
			lineItem.detail= chooseTag(i);
			lineItem.pma = choosePMA(i);
			lineItem.branchlast='branch'; // default value
			//20030808 no vertstretch anymore
			lineItem.needVertStretch=false; // default value
			// save item
			detailLineItemArray[arrayIdx++]=lineItem;
		}
		// fixup array by setting the "needVertStretch" flag
		fixupDetailLineItemArray(detailLineItemArray);

		// now we go through array and write out the detail lines appropriately
		//030808
		// eliminate these images and use spacers!!!!!!
		//var branchImg ='<img src="/common/images/treebits/branch.gif" width="9" height="9">';
		//var lastImg ='<img src="/common/images/treebits/last.gif" width="9" height="9">';
		var branchImg ='<img src="/common/images/spacer.gif" width="1" height="9">';
		var lastImg ='<img src="/common/images/spacer.gif" width="1" height="9">';

		var thisLineItem=null;

		for (var i=0;i<detailLineItemArray.length;i++){
			document.write('<tr>');
			thisLineItem=detailLineItemArray[i];
			// special case for indent 0

			if (detailLineItemArray[i].indent==0){
				//20030808 no vertstretch anymore
				document.write('<td align="left" valign="middle">');
				document.write(thisLineItem.pma + '</td>');
				document.write(thisLineItem.detail + '</tr>' );
				continue; // do next item
			}
			// handle all non-0 indents...
			// construct each TD
			for (var j=0;j<=thisLineItem.indent;j++){
				// if any later item at this indent level then write out vertstretch
				//20030808 get rid of vertstretch
				/*
				this algorithm won't work!!! only draw vertical lines in those TDs that need them!!
				this means that we need to know if some earlier node at indent N needs to be connected to node later in the array at indent N
				must complicate the array in which we keep this info: let each item remember what tab indents need a vertstretch
				complicate the fixup logic a lot
				MEANTIME try turning off the stretch
				if (thisLineItem.needVertStretch) {document.write('<td align="left" class="vertstretch" valign="top">');}
				else { document.write('<td align="left" valign="top">');  }
				*/
				document.write('<td align="left" valign="top">');
				//terminate all but the last TD before the pma etc
				if (j<thisLineItem.indent){document.write('</td>');}
				else if (thisLineItem.branchlast == 'branch'){
					document.write(branchImg + '</td>');
				}
				else if(thisLineItem.branchlast == 'last'){
					document.write(lastImg + '</td>');
				}
			}
			// now do the rest of the line
			//030808 eliminate vertstretch
			//document.write('<td class="vertstretch" valign="top">' + thisLineItem.pma + '</td>');
			document.write('<td valign="top">' + thisLineItem.pma + '</td>');
            //alert(thisLineItem.detail);
			document.write(thisLineItem.detail);
            //alert(this.colspan);
			document.write('</tr>');
 		}

	}

}
function choosePartnerLogo(){
	// this function is here only for backwards compatibility for Quizzes.
	// Its sole job is to return the file for the partner and/or a background image.
	return getPartnerLogoString();
}
function padspaces(indentlevel){
	//alert('inside padspaces with indentlevel='+indentlevel);
	//var retStr="";
	if (indentlevel == 0) { return ""; }
	var retStr = '<img src="/common/images/space4.gif" border=0 hspace=0 vspace=0 width=1>';
	while (indentlevel > 0) {
		retStr += '<img src="/common/images/space4.gif" border=0 hspace=0 vspace=0 width=5>';
		indentlevel-- ;
	}

	return retStr ;
}


function getBreadCrumbs(){
	return (getSignInUpOut());
	/*
	var retStr =  '<a href="javascript:signinupout();"><img border="2" ' +
		'src="' + getPathToRoot()+ '/common/images/headlines/signinupout.gif" valign="bottom" width="98" height="15" vspace="2"></a>';
	//var retStr = '<b><i>Site Preview. Launch: Chanukah 2002 </i><b>';
	if (thisTopicObj == null || arguments.length>0 ) {
		// might be Index Page or GL page
		retStr += allTopicsTitle;
		if (arguments.length>0){ retStr += "&gt;" + arguments[0] ; }
	}
	else {
		retStr += thisTopicObj.crumbs;
	}
	*/
	return retStr;
}
function getJoinLine(){
	return (getSignInUpOut());
	/*
	var retStr =  '<a href="javascript:signinupout()"><img border="2" ' +
		'src="' + getPathToRoot()+ '/common/images/headlines/referthissite.gif" valign="bottom" width="73" height="23" vspace="2"></a>' +
		'<a href="javascript:survey();"><img border="2" ' +
		'src="' + getPathToRoot()+ '/common/images/headlines/wewantyour.gif" valign="bottom" width="73" height="23" vspace="2"></a>';
	return retStr ;
	*/
}

function TwoLogosLarge(){
	return "";
	/*
	var retStr = '<table width="200" border="0" cellspacing="0" cellpadding="0">';
	retStr += '<tr><td align="center"><br><a href="http://www.hebrewcollege.edu"><img src="/common/images/hebrew_college.gif" border=0 width="200" height="80"></a></td></tr><tr><td><br><a href="http://www.jflmedia.com"><img src="/common/images/jfl_logo.gif" border=0 width="200" height="80"></a></td></tr>';
	retStr += '</table>';
	document.write(retStr);
	*/
}
function TwoLogos(){
	return "";
	/*
	var retStr = '<table width="200" border="0" cellspacing="0" cellpadding="0">';
	retStr += '<tr><td align="center"><br><a href="http://www.hebrewcollege.edu"><img src="/common/images/hebrew_edu_logo_sm.gif" border=0 width="132" height="50"></a></td></tr><tr><td><br><a href="http://www.jflmedia.com"><img src="/common/images/jfl_logo_sm.gif" border=0 width="132" height="50"></a></td></tr>';
	retStr += '</table>';
	document.write(retStr);
	*/
}
function help(key){
	var locStr = getPathToRoot() + '/Help/help.html';
	if (key==null || key=='help') {locStr= getPathToRoot() + '/Help/help.html';}
	else if (key=='browsers') {locStr= getPathToRoot() +'/Help/browsers.html';}
	else if (key=='printer') {locStr= getPathToRoot() +'/Help/printer.html';}
	else if (key=='mlt') {locStr= getPathToRoot() +'/Help/mlt.html';}
	else if (key=='gloss') {locStr= getPathToRoot() +'/Help/glossary.html';}
	else if (key=='glearn') {locStr=getPathToRoot() +'/Help/glearning.html';}
	else if (key=='prnsnd') {locStr=getPathToRoot() +'/Help/printsend.html';}
	else if (key=='join') {locStr= getPathToRoot() + '/Help/join.html';}
	else if (key=='persp') {locStr= getPathToRoot() +'/Help/perspectives.html';}
	else if (key=='disc') {locStr= getPathToRoot() +'/Help/discussions.html';}
	else if (key=='alltopics') {locStr= getPathToRoot() +'/Help/alltopics.html';}
	else if (key=='search') {locStr= getPathToRoot() +'/Help/search.html';}
	else if (key=='journal') {locStr= getPathToRoot() +'/Help/journal.html';}
	else if (key=='print') {locStr= getPathToRoot() +'/Help/print.html';}
	else if (key=='email') {locStr= getPathToRoot() +'/Help/email.html';}
	//alert('locStr is ' + locStr );
	var winprops="height=475,width=530,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	if (arguments.length == 1) {
		win = window.open(locStr, "HELPWIN", winprops);
	}
	else if (arguments[1] == 'SELF'){
		location = locStr;
	}
	else {
		alert('at.js: Error. help() called with unrecognized extra argument');
	}
}
function eletter(){
	var sname = getScreenNameCookie();
	if (sname == null) {
        window.location = '/User/signup.jsp';
		//alert('You will need to login or register in order to take advantage of this and many other Members-only features.\nMembership is free and private.\nThank you.');
		return;
	}
	//var newwin=window.open(getPathToRoot() + "/eletter/launchEletter.htm","ELETTERWIN","height=500,width=650,resizable=yes,scrollbars=yes,status=yes");
    window.location = '/eletter/launchEletter.htm';
}
function jumpMainWindow(pg){
	// this function needs to be made more robust by recursively checking
	// the parent (of parent of...) or opener of top until we find the main
	// window or find that there is none. The main window is the one with
	// window.name='MAINWIN' and this will have to be set in the home.htm page!!
	// For the meantime we can treat the opener as the main window.
	// make sure window is still there
	if (typeof(window.opener)=="undefined" || window.opener == null) {
		//must open new MAIN window for this url
		var mainwin = window.open(pg,"MAINWIN", "height=800,width=600,resizable=yes,scrollbars=yes,status=yes,menubar=yes");
	}
	pg = pathFirstPart + pg ;
	window.opener.location = pg;
}
function heb_eng_date(){
	// First display the Hebrew date
	var now = new Date;
	var tday = now.getDate();
	var tmonth = now.getMonth() + 1;
	var tyear = now.getYear();
	if(tyear < 1900)
		// if date from Netscape, then add 1900
		tyear += 1900;
	var hebDate = civ2heb(tday, tmonth, tyear);
	var hmS = hebDate.substring(hebDate.indexOf(' ')+1, hebDate.length);
	var	hDay = eval(hebDate.substring(0, hebDate.indexOf(' ')));
	var hMonth = eval(hmS.substring(0, hmS.indexOf(' ')));
	var hYear = hmS.substring(hmS.indexOf(' ')+1, hmS.length);
	// Then display the corresponding civil dates
	var day, month, year;
	var today = new Date;
	var yesterday = new Date(today.getTime() - 86400000);
	day   = yesterday.getDate();
	month = yesterday.getMonth() + 1;
	year  = yesterday.getYear();
	if(year < 1900)
		year += 1900; // if date from Netscape, then add 1900
	day   = today.getDate();
	month = today.getMonth() + 1;
	year  = today.getYear();
	if(year < 1900)
		year += 1900; // if date from Netscape, then add 1900
	return('<b>'+hDay + ' ' + hebMonth[hMonth+1] + ' ' + hYear + '/' +
		civMonth[month] + ' ' + day + ', ' + year+'</b>');
}

function SLSjumpMainWindow(pg){
	if (typeof(window.opener)=="undefined" || window.opener  == null) {
		var mainwin = window.open(pg,"MAINWIN",
		"height=800,width=600,resizable=yes,scrollbars=yes,status=yes,menubar=yes");
	}
	else {
		window.opener.location = pg;
	}
}

function discuss(){
	/*
	// FOR EMERGENCY (7-6-03)
	alert("We are sorry but at this time Discussions are offline.\nPlease come back and try again later.");
	return;
	*/
	var discURL = getPathToRoot() + "/phorum/index.php3" ;
	if (arguments.length > 0) {
		discURL = getPathToRoot() + arguments[0];
	}
    window.location = discURL;
    return;
	var newwin=window.open(discURL,"DISCUSSWIN","height=650,width=750,resizable=yes,scrollbars=yes,status=yes");

	/* old code
	var newwin=window.open(getPathToRoot() + "/phorum/index.php3",
"DISCUSSWIN","height=650,width=750,resizable=yes,scrollbars=yes,status=yes");
	*/
}

function discuss2(){
	var discURL = getPathToRoot() + "/phorum/index.php3" ;
	if (arguments.length > 0) {
		discURL = "http://www.myjewishlearning.com/phorum/list.php?num=" + arguments[0];
	}
	var newwin=window.open(discURL,"DISCUSSWIN","height=650,width=750,resizable=yes,scrollbars=yes,status=yes");
}

function journal(){
	var sname = getScreenNameCookie();
	if (sname == null) {
        window.location = '/User/signup.jsp';
		//alert('You will need to login or register in order to take advantage of this and many other Members-only features.\nMembership is free and private.\nThank you.');
		return;
	}
	var newwin=window.open(getPathToRoot() + "/mj/launchJournal.htm","JOURNALWIN","height=650,width=750,resizable=yes,scrollbars=yes,status=yes");
}
function glossary(){
	var newwin=window.open(getPathToRoot() + "/Glossary/a_glosslist.htm","GLOSSWIN","height=500,width=700,resizable=yes,scrollbars=yes,status=yes");
}
function showGlossary(fn) {
	var newwin=window.open(getPathToRoot() + "/Glossary/" + fn,"GLOSSWIN","height=500,width=700,resizable=yes,scrollbars=yes,status=yes");
}
function printarticle(){
    	if (typeof(printerfile)=='undefined' || printerfile==null) {
		window.print();
	}
	else {
		var locStr = getPathToRoot() + printerfile;
		var winprops="height=600,width=750,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
		var newwin = window.open(locStr, "PRINTARTWIN", winprops);
	}
}
function sendarticle(){
    var locStr = pathToJSP + '/User/send_article.jsp?DOCOWNID=' + thisTopicId ;
    var winprops="height=500,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
	win = window.open(locStr, "SENDARTWIN", winprops);
}
function savetojournal(){
	var winprops="height=500,width=500,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	var newloc = pathToJSP + '/mj/savetojournal.jsp?DOCID=' + thisTopicId +
		'&DOCNAME=' + escape(thisTopicName);
	win = window.open(newloc, "SAVEJOURNALWIN", winprops);
}
function getSignInUp(){
	// for backwards compatibility
	return (getSignInUpOut());
}
function getSignInUpOut(){
	var retStr = 	'<a href="javascript:signinupout();"><img border="2" src="/common/images/headlines/signinupout.gif" valign="bottom" width="148" height="15" vspace="2"></a>';
	if (window.homepage==true && ie55up()) {
		var homepg = getPathToRoot() + "/index.htm" ;
		retStr += '<br><a  href="javascript:void(0)" onClick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'' + homepg + '\');"><font size="-2">Make MyJewishLearning.com your homepage!</font></a>';
	}
	return retStr;
}
function signinupout(){
	var winprops="height=500,width=650,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	var newloc = pathToJSP + '/User/SignInUpOut.jsp'; // used to go directly to htm but now we ask user
 //   var newloc =  'http://www.myjewishlearning.com:90/logincheck';
	win = window.open(newloc, "SAVEJOURNALWIN", winprops);
}
function register(){
	// if user is currently logged in, ask user to log out and THEN register as new user
	var sname = getScreenNameCookie();
	if (sname != null) {
		alert('Dear ' + sname + ',\n' +
			'If you are ' + sname + ', click on the Discussions button above to participate in the MyJewishLearning.com community. You do not need to re-register.\n'+
			'If you are NOT ' + sname + ', please logout by clicking the Logout link in the top left-hand corner of the page and then Login or Register (if you haven\'t done so already). '+
			'Once logged in, click on the Discussions button to enjoy all the benefits of being part of our community.');
		return;
	}
    var SS = getRefererCookie();
	var winprops=
"height=650,width=650,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	//var newloc = pathToJSP + '/User/SignInUpOut.jsp';
	//win = window.open(newloc, "LOGINREGISTERWIN", winprops);
    var newloc = pathToJSP + '/User/signup.jsp';
	//win = window.open(newloc, "LOGINREGISTERWIN", winprops);
    window.location = newloc;
}
function showBanner555(TopicId){
//    alert('in showbanner555');
	// all cases show MJL logo ...
	document.write('<td width="231px"><a href="/index.php"><img src="/common/images/mjl_logo.gif" width="231" height="73" border="0"></a></td>');
	var dom = getPartnerDomain();
	// staging only

	if (dom.toLowerCase().indexOf('smyjewishlearning')>-1){ dom ='www' ;}
    if (dom.toLowerCase().indexOf('tst')>-1){ dom ='www' ;}

	if (dom.toLowerCase() == 'www') {
		// handle no partner case
        //document.write('<td width="153px" background="/common/images/grad_bkgnd.gif" height="73px"></td>');
        document.write('<td width="153px" bgcolor="#ffffff" height="73px"></td>');
	}
	else {
	// if partner
		//document.write('<td background="/common/images/grad_bkgnd.gif" width="153px" height="73px">' + getPartnerLogoImage(dom) + '</td>');
        document.write('<td bgcolor="#ffffff" width="153px" height="73px">' + getPartnerLogoImage(dom) + '</td>');
	}
	document.write('<td width="171px" background="/common/images/grad_bkgnd.gif" valign="top">');
	if (TopicId != 'PF') { showBannerNav(TopicId); }
}
function showBanner(){
//    alert('in showbanner');
	var pathtoroot = getPathToRoot();
	if (arguments.length >= 2) {
		pathtoroot = getPathToRoot(arguments[1]);
	}
	var bannerStr = '<div align="left">';
	if (arguments.length == 0 || arguments[0] != 'prn') {
		bannerStr += '<a href="' + pathtoroot + '/index.htm">';
	}
	bannerStr += '<img src="';
	var thishost = location.hostname.toLowerCase();
	if  (pathtoroot.indexOf('www.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/logo.gif" width="325" height="63" border=0"></a>';
	}
	else if (pathtoroot.indexOf('hillel.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images//hillel.jpg" width="114" height="63" >';
	}
	else if (pathtoroot.indexOf('jewishla.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images//jewishlalogo.gif" width="114" height="63" >';
	}
	else if (pathtoroot.indexOf('hadassah.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><a href="http://www.hadassah.org" target="_blank"><img alt="Go to Hadassah.org Web site" src="/common/images//hadassah.jpg" width="114" height="63" border="0"></a>';
	}
	else if (pathtoroot.indexOf('jcc.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images//jcc.jpg" width="114" height="63" >';
	}
	else if (pathtoroot.indexOf('bbyo.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images//bbyo.jpg" width="114" height="63" >';
	}
	else if (pathtoroot.indexOf('star.myjewishlearning.com') > -1) {
		bannerStr += '/common/images/mjl_logo_partners.jpg"  width="211" height="63" border=0" ></a><img src="/common/images//star.jpg" width="114" height="63" >';
	}
	// catch all case
	else {
		bannerStr += '/common/images/logo.gif" width="325" height="63" border="0" ></a>';
	}
	bannerStr += '<img src="/common/images/space/trans.gif" width="50" height="63" border=0">';
	if (arguments.length == 0 || arguments[0] != 'prn') {
		bannerStr += '<a href="javascript:journal();"><img src="/common/images//buttons/journal.gif" border="0" width="67" height="63"></a>';
		bannerStr += '<a href="javascript:discuss();"><img src="/common/images//buttons/discussions.gif" border="0" width="96" height="63"></a>';
      		bannerStr += '<a href="javascript:glossary();"><img src="/common/images/buttons/glossary.gif" border="0" width="62" height="63"></a>';
	}
	else if (arguments[0] == 'prn') {
      		bannerStr += '<a href="javascript:window.print();"><img src="/common/images//buttons/printbig.gif" border="0" width="132" height="63"></a>';
	}
	bannerStr += '<a href="javascript:help(\'help\');"><img src="/common/images/buttons/help.gif" border="0" width="83" height="63"></a>';
	bannerStr += '</div>';
	alert('at.js: bannerStr=' + bannerStr);
	document.write(bannerStr);
}
function feedback(){
	// call the shamoffer() function in user.js
	shmaoffer();
	/*
    	var locStr = getPathToRoot() + '/User/contact_us.html';
	var winprops="height=500,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
	win = window.open(locStr,"CONTACTWIN",winprops);
	*/
}
function showILG(u){
    	var locStr = getPathToRoot() + '/ilg/' + u;
	var winprops="height=500,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
	win = window.open(locStr,"ILGWIN",winprops);
}


function setFontCookie(name, value) {
  //var curCookie = name + "=" + escape(value) + "; path=/; domain=atypica.com";
  var curCookie = name + "=" + escape(value) + "; path=/; domain=interfaithfamily.com";
  document.cookie = curCookie;
  self.location.href = self.location.href;
}

function getFontCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


if (getFontCookie('fontfamily') == null) {
	var fontfamily = 'Verdana';
} else {
	var fontfamily = getFontCookie('fontfamily');
}
if (getFontCookie('fontsize') == null) {
	var fontsize = 12;
} else {
	var fontsize = getFontCookie('fontsize');
}

function changeFontFamily (fontfamily) {
	setFontCookie('fontfamily',fontfamily);
}


function changeFontSize (fontsize) {
	setFontCookie('fontsize',fontsize);
}

function showReadability() {
  	 //document.write('<form>');
	 //document.write('<span class="menutitle2">Readability<\/span><br>');
     document.write('<img src="/common/images/resources/readability.gif">');
  	 document.write('<table cellspacing="0" cellpadding="3"><form><tr><td>Font:<\/td>');
	 document.write('<td><select name="fontfamily" onChange="changeFontFamily(this.options[selectedIndex].value);">');
	 if (fontfamily == "Verdana") {
	 document.write('<option value="Verdana" selected>Verdana<\/option>');
	 } else {
	  document.write('<option value="Verdana">Verdana<\/option>');
	 }
	 if (fontfamily == "Arial") {
	 document.write('<option value="Arial" selected>Arial<\/option>');
	 } else {
	  document.write('<option value="Arial">Arial<\/option>');
	 }
	  if (fontfamily == "Courier") {
	 document.write('<option value="Courier" selected>Courier<\/option>');
	 } else {
	  document.write('<option value="Courier">Courier<\/option>');
	 }
	  if (fontfamily == "Lucida Grande") {
	 document.write('<option value="Lucida Grande" selected>Lucida Grande<\/option>');
	 } else {
	  document.write('<option value="Lucida Grande">Lucida Grande<\/option>');
	 }
	  if (fontfamily == "Times") {
	 document.write('<option value="Times" selected>Times<\/option>');
	 } else {
	  document.write('<option value="Times">Times<\/option>');
	 }
	 document.write('<\/select>');
	 document.write('<\/td><\/tr>');
	 document.write('<td>Size:<\/td>');
	 document.write('<td><select name="fontsize" onChange="changeFontSize(this.options[selectedIndex].value);">');

	 for ( var x=9; x <= 24; x++) {
	 	var sel;
	 	if (Number(x) == Number(fontsize)) {
		sel = "selected";
	 	} else {
		sel = "";
	 	}
		document.write('<option value="'+x+'" '+sel+'>'+x+'<\/option>');
	 }
	 document.write('<\/select><\/td><\/tr><\/form><\/table>');
	 //document.write('<\/form>');

}

function showReadability2() {
	 //document.write('Font: <img border=0 width=32 height=32 src="/templates/images/a1.png"><img border=0 width=32 height=32 src="/templates/images/a2.png"><img border=0 width=32 height=32 src="/templates/images/a3.png"><br>');
	 document.write('Font Size: <select name="fontsize" onChange="changeFontSize(this.options[selectedIndex].value);">');

	 for ( var x=9; x <= 24; x++) {
	 	var sel;
	 	if (Number(x) == Number(fontsize)) {
		sel = "selected";
	 	} else {
		sel = "";
	 	}
		document.write('<option value="'+x+'" '+sel+'>'+x+'<\/option>');
	 }
	 document.write('<\/select>');
}


document.write('<style type="text/css">');
document.write('#main {font-size:'+fontsize+'px; line-height: 160%}');
document.write('#brdcrmbs {font-size:10px;}');
document.write('<\/style>');
