/* © Copyright 2006 Joe A. Friberg - FamilyPhonics.com. All Rights Reserved. */
function initializefams(lsn){
	i=lsn; // -1; NOTE: all arrays have been 0-1 adjusted below in order to allow easy reference of data based on un-adjusted lesson #
//Database:
	wdfams=new Array('','-at','-an','-it','-ag, -ig, -ab'); //u1
		wdfams.push('-ob, -ap','-ag, -am, -ad'); //u2
	phwds=new Array(0,10,8,9,23); //u1
		phwds.push(); //u2
	nms=new Array(0,3,4,0,0); //u1
		nms.push(); //u2
	stwds=new Array(0,3,3,5,7); //u1
		stwds.push(); //u2
//Rules listed separately (below)

//Format word family list:
	wdfamfmt=new Array();
	wdfamcnt=new Array();
	for(j=0;j<wdfams.length;j++){
		wdfamarr=wdfams[j].split(",");
		wdfamcnt[j]=wdfamarr.length;
		if(wdfamcnt[j]==1){
			wdfamfmt[j]='<span style="white-space:nowrap;">'+wdfamarr[0]+'</span>';
		}else if(wdfamcnt[j]==2){
			wdfamfmt[j]='<span style="white-space:nowrap;">'+wdfamarr[0]+'</span>'+' and '+'<span style="white-space:nowrap;">'+wdfamarr[1]+'</span>';
		}else if(wdfamcnt[j]>2){
			wdfamfmt[j]='<span style="white-space:nowrap;">'+wdfamarr[0]+'</span>';
			for(k=1;k<wdfamcnt[j];k++){
				wdfamfmt[j]+=', ';
				if(k==wdfamcnt[j]-1){wdfamfmt[j]+='and '}
				wdfamfmt[j]+='<span style="white-space:nowrap;">'+wdfamarr[k]+'</span>';
			}
		}
	}

	for(j=1;j<=i;j++){
		twdfamcnt+=wdfamcnt[j];
		tphwds+=phwds[j];
		tnms+=nms[j];
		tstwds+=stwds[j];
	}
}

function initializerules(){
//data fmt: 'short name|first lesson #|Rule....|example(s)|Question|Answer|image.gif'
	ruls=new Array()
	ruls.push('DblLtr|1|A double letter makes 1 sound.|Matt, add|A double letter makes __ (how many) sounds?|1'); 
	ruls.push('ClosedSyll|4|A vowel followed by a buddy consonant is short.|at, can, bit|A vowel followed by a buddy consonant is _______.|short'); 
	ruls.push("CSndsLkK||'c' sounds like 'k' before a, o, or u'.|cute copy cat|When does 'c' sound like 'k'?|before a, o, or u"); 
	ruls.push("CSndsLkS||'c' sounds like 's' before i, e, or y'.|a circus cycle in the center of the cement circle in the city|When does 'c' sound like 's'?|before i, e, or y"); 
	ruls.push('CapNames|2|Names always begin with a Capital/Big letter.|Pat, Jan|Names always begin with a _______?|BIG/capital letter');
	ruls.push('CapSentence|2|A sentence always begins with a Capital/Big letter.|The cat ran fast.|Sentences always begin with a _______?|BIG/capital letter');
	ruls.push("SentenceEnd||A sentence always ends with a '.' period, a '?' question mark, or an '!' exclamation point.||What comes at the end of a sentence?|. or ? or !");
}

function disprulefmt(rar,inclexs,csscl,incllsn){
	exmpl='<p style="text-align:center;">-- as in --</p><div class='+csscl+' style="text-align:center;">'+rar[3]+'</div>';
	if(rar[3]==''||!inclexs){exmpl=''}
	lsn='<div class=note style="float:right;padding:0;">Lesson '+rar[1]+'</div>';
	if(!incllsn){lsn=''}
	document.write('<fieldset class=rule><legend>Rule</legend>'+lsn+'<b>'+rar[2]+'</b>');
	if((inclexs=='hide')&&(exmpl!='')){  //use inclexs = 'hide' to give show/hide option:
		showhidediv('show example(s)','hide example(s)',exmpl);
	}else{document.write(exmpl)}
	document.write('</fieldset>');
}
function disprule(shortnm,inclexs,csscl,incllsn){
	fnd=false;
	for(i=0;i<ruls.length&&!fnd;i++){
		rularr=ruls[i].split("|");
		if((rularr[0]==shortnm)){disprulefmt(rularr,inclexs,csscl,incllsn); fnd=true}
	}
}
function disprules(begles,endles,inclexs,csscl,incllsn,summ){
//summ determines whether summary statements are to be made
	pst=0;
	pr=0;
	if(summ){
		for(i=0;i<ruls.length;i++){
			rularr=ruls[i].split("|");
			if((rularr[1]>=begles)&&(rularr[1]<=endles-1)){pst++}
			if(rularr[1]==endles){pr++}
		}
		if(pr>0){
			if(pr<2){rulcnt=''}else{rulcnt=pr}
			document.write('<p>You have learned '+these(pr)+' '+rulcnt+' new rule'+pl(pr)+':</p>');
			for(i=0;i<ruls.length;i++){
				rularr=ruls[i].split("|");
				if(rularr[1]==endles){disprulefmt(rularr,inclexs,csscl,false)}
			}
		}
		if(pst>0){
			if(pst<2){rulcnt=''}else{rulcnt=pst}
			document.write('<p>You already know '+these(pst)+' '+rulcnt+' rule'+pl(pst)+':</p>');
			for(i=0;i<ruls.length;i++){
				rularr=ruls[i].split("|");
				if((rularr[1]>=begles)&&(rularr[1]<=endles-1)){disprulefmt(rularr,inclexs,csscl,incllsn)}
			}
		}
	}else{
		for(i=0;i<ruls.length;i++){
			rularr=ruls[i].split("|");
			if((rularr[1]>=begles)&&(rularr[1])<=endles){disprulefmt(rularr,inclexs,csscl,incllsn)}
		}
	}
}
function qrulefmt(rar,csscl,wrapdl){
	if(wrapdl){document.write('<dl>')}
	document.write('<dt>Complete this rule:</dt><dd>'+rar[4]);
	showhidediv('show answer','hide answer','<div class='+csscl+'>'+rar[5]+'</div>');
	document.write('</dd	>');
	if(wrapdl){document.write('</dl>')}
}
function qrule(shortnm,csscl,wrapdl){
	fnd=false;
	for(i=0;i<ruls.length&&!fnd;i++){
		rularr=ruls[i].split("|");
		if((rularr[0]==shortnm)){qrulefmt(rularr,csscl,wrapdl); fnd=true}
	}
}
function qrules(begles,endles,csscl,wrapdl){
	for(i=0;i<ruls.length;i++){
		rularr=ruls[i].split("|");
		if((rularr[1]>=begles)&&(rularr[1])<=endles){qrulefmt(rularr,csscl,wrapdl)}
	}
}

function these(cnt){
	if(cnt<2){return 'this'}else{return 'these'}
}
function families(cnt){
	if(cnt<2){return 'family'}else{return 'families'}
}
function pl(cnt){
	if(cnt<2){return ''}else{return 's'}
}
function lessonsummary(lsn){
//depends on: initializestats
	i=lsn;//-1;
	if(wdfamcnt[i]>0){document.write('<li>learned to recognize the '+wdfamfmt[i]+' word '+families(wdfamcnt[i])+'</li>')}
	if(wdfamcnt[i]>0){document.write('<li>learned to read '+(phwds[i]+nms[i])+' words in the '+wdfamfmt[i]+' word '+families(wdfamcnt[i])+'</li>')}
	if(wdfamcnt[i]>0){document.write('<li>learned '+stwds[i]+' sight word'+pl(stwds[i])+'</li>')}
}
function lessonstats(lsn){
//depends on: initializestats
	i=lsn;//-1;

	document.write('<p>In this lesson you learned:</p><ul>');
	if(wdfamcnt[i]>0){document.write('<li>'+wdfamcnt[i]+' new word '+families(wdfamcnt[i])+'</li>')}
	if(phwds[i]>0){document.write('<li>'+phwds[i]+' new words</li>')}
	if(nms[i]>0){document.write('<li>'+nms[i]+' name'+pl(nms[i])+'</li>')}
	if(stwds[i]>0){document.write('<li>'+stwds[i]+' sight word'+pl(stwds[i])+'</li>')}
	document.write('</ul><p>Now you know:</p>');

	document.write('<table cellpadding=5 cellspacing=0 border=1 align=center>');
	document.write('<tr><td align=right>'+tphwds+'</td><td>Phonics Words in '+twdfamcnt+' Word '+families(twdfamcnt)+'</td></tr>');
	document.write('<tr><td align=right>'+tnms+'</td><td>Names</td></tr>');
	document.write('<tr><td align=right>'+tstwds+'</td><td>Sight Words</td></tr>');
	document.write('<tr><td align=right>'+(tphwds+tnms+tstwds)+'</td><td>Words Total!</td></tr>');
	document.write('</table>');
}

function showhidediv(showtxt,hidelnktxt,hidelongtxt){
	document.write('<div class="size8" id="para"><a onmouseover="javascript:hide(this);" id="show" class="clickable" href="javascript:;">');
	document.write(showtxt);
	document.write('</a><span onclick="javascript:hide(this);" id="hide" class="clickable" style="display:none"><a href="javascript:;">');
	document.write(hidelnktxt);
	document.write('</a><div>');
	document.write(hidelongtxt);
	document.write('</div></span></div>');
}

function hide(src) {
   	if(src.onmouseover&&!src.onclick){src.onclick=src.onmouseover;src.onmouseover=''}
    pt=src.parentNode;
	for(j=0;j<pt.childNodes.length;j++){
		if(pt.childNodes[j]==src){
	    	pt.childNodes[j].style.display = "none";
	    }else if(pt.childNodes[j].id){
		    pt.childNodes[j].style.display = "inline";
	    }
	}
}

function showpic(src,pic,top,vert) {
   	if(src.onmouseover&&!src.onclick){src.onclick=src.onmouseover;src.onmouseover=''}
	var txt=src.innerHTML;
	if(txt.toLowerCase().indexOf("show")>-1){ //SHOW imgs:
		var pth=webroot()+'images/';//document.location.href.toLowerCase()
		if(txt.indexOf("show")>-1){txt=txt.replace("show","hide")}else{txt=txt.replace("Show","Hide")}
		src.innerHTML='';
		if(top){src.innerHTML=txt+'<br>'}
		var imgs=pic.split("|");
		for(j=0;j<imgs.length;j++){
			if(vert&&j>0){src.innerHTML+='<br>'}
			src.innerHTML+='<img src="'+pth+imgs[j]+'" border="0" title="click to hide" alt="" style="margin:0px">';
		}
		if(!top){src.innerHTML+='<br>'+txt}
	}else{ //HIDE imgs:
		j=0; //remove img nodes:
		while(chd=src.childNodes[j]){
			if((chd.tagName)&&(chd.tagName.toLowerCase()=='img')){
		    	src.removeChild(chd);
			}else{j++;}
		}
		//remove br nodes if at beginning or end:
	while((chd=src.childNodes[0])&&(chd.tagName)&&(chd.tagName.toLowerCase()=='br')){src.removeChild(chd)}
	while((chd=src.childNodes[src.childNodes.length-1])&&(chd.tagName)&&(chd.tagName.toLowerCase()=='br')){src.removeChild(chd)}
		txt=src.innerHTML;
		if(txt.indexOf("hide")>-1){txt=txt.replace("hide","show")}else{txt=txt.replace("Hide","Show")}
		src.innerHTML=txt;
	}
}

function showversetable(src) { //shows only table w/ id=verse
//if(src.onmouseover&&!src.onclick){src.onclick=src.onmouseover;src.onmouseover=''} do not want to use onmouseover--more intentional
    pt=src.parentNode;
    if(src.innerHTML.toLowerCase().indexOf('verse only')>-1){
		for(j=0;j<pt.childNodes.length;j++){
			if((pt.childNodes[j].id!=undefined)&&(pt.childNodes[j].id!='navlocal')&&(pt.childNodes[j].id!='showverse')&&(pt.childNodes[j].id!='verse')){pt.childNodes[j].style.display = "none"}
			if(pt.childNodes[j].id=='showverse'){pt.childNodes[j].innerHTML='Show notes'}
		}
	}else{
		for(j=0;j<pt.childNodes.length;j++){
			if((pt.childNodes[j].id!=undefined)&&(pt.childNodes[j].id!='navlocal')&&(pt.childNodes[j].id!='showverse')&&(pt.childNodes[j].id!='verse')){pt.childNodes[j].style.display = "block"}
			if(pt.childNodes[j].id=='showverse'){pt.childNodes[j].innerHTML='Show verse only'}
			if(pt.childNodes[j].id=='showverse2'){pt.childNodes[j].style.display='inline'}
		}
	}
}

function scripturelink(vv){
	document.write('<a target="bgmain" title="Show '+vv+' in the BibleGateway window" href="http://www.biblegateway.com/passage/?search='+vv+';&version=77" class=size8>'+vv+'</a>'); //bgmain is the name that BibleGateway uses for any window that opens its URL
}

function printpage(){
	if(document.location.href.toLowerCase().indexOf('print=true')>-1){
		document.getElementById('leftnavbar').style.display="none";
		document.getElementById('topleft').style.display="none";
		document.getElementById('topright').style.display="none";
		document.getElementById('bottomleft').style.display="none";
		document.getElementById('bottomright').style.display="none";
		document.getElementById('navbottom').style.display="none";
		if(document.getElementById('timer')){document.getElementById('timer').style.display="none"}
		document.getElementById('content').width="100%";
		document.getElementById('bodytable').width="100%";
		elt=document.getElementById('navtop');
		elt.childNodes[0].align='left'
		elt.childNodes[0].innerHTML='<a href="?" class=size8>&lt;Back to Standard Format</a>'
	}
}

function insertpageref(){
	links=document.links;
	txt='(please describe which page if you do not have javascript enabled)';
	for(j=0;j<links.length;j++){
		links[j].href=links[j].href.replace(txt,document.location.href);
	}
}

function timer(){
	tm=0;
	setTimeout("startClock()", 60000);
}
function startClock(){
	tm+=1;
	if(document.getElementById("time2")){document.getElementById("time2").value = tm}
	document.getElementById("time").innerHTML = tm;
	setTimeout("startClock()", 60000);
}
function checkdate(elt) {
	dttxt=elt.value;
	now=new Date();
	if(isNaN(new Date(dttxt))){
		dttxt+='/'+now.getFullYear();
		if(isNaN(new Date(dttxt))){
			alert('Check your date format!');
		}
	}
	if(!isNaN(new Date(dttxt))){
		dt = new Date(dttxt);
		if(dt.getFullYear()<(now.getFullYear()-50)){
			dt.setFullYear(dt.getFullYear()+100);
		}
		elt.value = (dt.getMonth()+1)+'/'+dt.getDate()+'/'+dt.getFullYear();
	}
}
/***** Begin Handwriting Worksheet construction *****/
function getwkshtvars(fm){
	txt=fm.T1.value;
	sz=fm.Sz.value; //line height in 1/16"
	sztxt=fm.Sz.options[fm.Sz.selectedIndex].text.replace(/[=-]{2,}/g,'');
	st=fm.St.value; //lettering style
	sttxt=' - '+fm.St.options[fm.St.selectedIndex].text;
	picsp=fm.Picsp.value*96; //picture space height in pixels
	ntr=fm.Ntr.value; //# traceable reps
	ndt=fm.Ndt.value; //# reps w/ start-dot-only
	if(ntr==0&&ndt==0){sttxt=' Manuscript Paper'}
	nbl=fm.Nbl.value; //# blank lines
	wdwrap=fm.Wdwrap.value; //blank line width inches
	dat=new Date();
	ttl=fm.Ttl.value;
	hdg=fm.Hdg.checked;
	rul1=fm.Rul1.value;
	rul2=fm.Rul2.value;
	rul3=fm.Rul3.value;
	if(st=="P1Dt"){
	charwdth=new Array(124,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,13,0,0,0,0,0,0,0,0,0,0,0,0,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47,0,91,72,77,73,68,68,88,70,33,62,64,67,88,70,84,67,84,68,63,73,67,62,109,71,71,67,0,0,0,0,0,0,53,52,53,53,52,51,54,50,17,43,49,17,80,50,52,53,74,50,49,45,50,50,77,53,52,52,0,0,0,0,0,0,0,0,0,0,0);
	}else{return '<span class=size13 style="color:red;">Coming soon!</span>';}
}

function genwksht(btn){
	fm=btn.form;
	getwkshtvars(fm);
document.write('<html><head><title>'+ttl+'</title>');
document.write('<link rel=stylesheet type=text/css href="../include/phonics.css" >');
document.write('</head><body>');
if(hdg){ //Heading:
	document.write('<table width=100%><tr><td>Student Name ______________________</td><td align=right>Date ______________</td></tr></table>');
	document.write('<h3 align=center style="margin:0;padding:0">'+ttl+'</h3>');
}
//ID box:
document.write('<table class=note style="margin-bottom:20px;" cellpadding=2 cellspacing=0 border=0 width=100%><tr><td><a href="javascript:history.back();">&lt;Back to FamilyPhonics.com</a></td><td align=right>'+sztxt+sttxt+'</td></tr></table>');
//Pic space:
document.write('<img src=images/blank.gif height='+picsp+' width=1 border=0>');
	re=new RegExp('['+String.fromCharCode(13)+String.fromCharCode(10)+']','g')
	txt=txt.replace(re,'|');
	txt=txt.replace(/\|\|/g,'|')
	paragr=txt.split('|');
	var jj, ii
	for(jj=0;jj<paragr.length;jj++){
		lnarr=genlnarr(paragr[jj]);
		for(ii=0;ii<ntr;ii++){document.write(genmsln(lnarr,''))} //document.write(genmstxt(paragr[jj],''))
		for(ii=0;ii<ndt;ii++){document.write(genmsln(lnarr,'dot'))}
		for(ii=0;ii<nbl;ii++){document.write(genmsln(lnarr,'blank'))}
	}
document.write('</body></html>');
document.close();
}

function tblmsln(msln){
var txtout='<table cellpadding=0 cellspacing=0 border=0 style="clear:both"><tr><td nowrap>'+msln+'</td></tr></table>';
txtout+=divmsrul('solid',rul1,Math.round(117*sz/13)+1);
txtout+=divmsrul('dashed',rul2,Math.round(78*sz/13)+3);
txtout+=divmsrul('solid',rul3,Math.round(40*sz/13)+4);
return txtout;
}

function divmsrul(style,color,offset){ //style = 'solid' or 'dashed'
return '<div style="margin:0;padding:0;border-top:1px '+style+' '+color+';position:relative;top:-'+offset+'px;"><img src="images/blank.gif" height=1px width=1px></div>';
}

function genlnarr(tx){
	txtarr=tx.split(' ');
	txtlow=tx.toLowerCase();
	txtlowarr=txtlow.split(' ');
	if(txtarr.length==1&&txtarr[0].length==0){txtarr[0]=' ';txtlowarr[0]=' '}
	lnpixelwdth=96*wdwrap;
	lnpixelsum=0;
	spwdth=Math.round(charwdth[32]*sz/charwdth[1]);
	var lnarr=new Array();
	txtout='';
	for(i=0;i<txtarr.length;i++){
		txtwd=txtarr[i];
		if(txtwd==''){continue}//needed? only for 0 and last??
		txtwdlow=txtlowarr[i];
		txtoutwd='';
		wdpixelsum=0;
		for(j=0;j<txtwd.length;j++){
			ltr=txtwd.charAt(j);
			ltrlow=txtwdlow.charAt(j);
//			alert(txtwd.charCodeAt(j)+' '+charwdth[txtwd.charCodeAt(j)]);
			wdth=Math.round(charwdth[txtwd.charCodeAt(j)]*ht/charwdth[0]);
			wdpixelsum+=wdth;
			txtoutwd+=ltr;
		}
		if(lnpixelsum==0){
			txtout+=txtoutwd;
			lnpixelsum+=wdpixelsum;
		}else if((lnpixelsum+spwdth+wdpixelsum)>lnpixelwdth){
			lnarr.push(txtout);
			txtout=txtoutwd;
			lnpixelsum=wdpixelsum;
		}else{
			txtout+=' '+txtoutwd;
			lnpixelsum+=spwdth+wdpixelsum;
		}
	}
	lnarr.push(txtout);
	return lnarr;
}
function genmsln(lnar,pfx){
	try{!lnar.push('');lnar.pop()}catch(er){lnar=new Array(lnar.toString())}
	if(!pfx){pfx=''}
	pfxar=pfx.split('|');
	var i,j,k
	ht=Math.round(charwdth[0]*sz/charwdth[1]);
	var txtout='';
	for(i=0;i<lnar.length;i++){ //each line
		txtln=lnar[i];
		txtlnlow=lnar[i].toLowerCase();
		for(j=0;j<pfxar.length;j++){ //repeated pfx array times
			pfx=pfxar[j].toLowerCase();
			if(pfx=='blank'){txtln=' ';txtlnlow=' ';pfx=''}
			txtlnout='';
			for(k=0;k<txtln.length;k++){ //each letter in line processed
				ltr=txtln.charAt(k);
				ltrlow=txtlnlow.charAt(k);
				wdth=Math.round(charwdth[txtln.charCodeAt(k)]*ht/charwdth[0]);
				shft=false;
				if(ltr!=ltrlow){shft=true}
				txtlnout+='<img src="'+imgsrc(ltrlow,shft,st,pfx)+'" height='+ht+' width='+wdth+'>';
			}
			txtout+=tblmsln(txtlnout); //line has been prepared
		}
	}
	return txtout;
}

function genmstxt(tx,pfx){
	if(!pfx){pfx=''}
	txtarr=tx.split(' ');
	txtlow=tx.toLowerCase();
	txtlowarr=txtlow.split(' ');
	if(txtarr.length==1&&txtarr[0].length==0){txtarr[0]=' ';txtlowarr[0]=' '}
	ht=Math.round(charwdth[0]*sz/charwdth[1]);
	lnpixelwdth=96*wdwrap;
	lnpixelsum=0;
	spwdth=Math.round(charwdth[32]*sz/charwdth[1]);
	txtout=tblmsop();//START
	for(i=0;i<txtarr.length;i++){
		txtwd=txtarr[i];
		txtwdlow=txtlowarr[i];
		txtoutwd='';
		wdpixelsum=0;
		for(j=0;j<txtwd.length;j++){
			ltr=txtwd.charAt(j);
			ltrlow=txtwdlow.charAt(j);
//			alert(txtwd.charCodeAt(j)+' '+charwdth[txtwd.charCodeAt(j)]);
			wdth=Math.round(charwdth[txtwd.charCodeAt(j)]*ht/charwdth[0]);
			wdpixelsum+=wdth;
			shft=false;
			if(ltr!=ltrlow){shft=true}
			txtoutwd+='<img src="'+imgsrc(ltrlow,shft,st,pfx)+'" height='+ht+' width='+wdth+'>';
		} //word has been prepared
		if((lnpixelsum+spwdth+wdpixelsum)>lnpixelwdth){
			txtout+=tblmscl();//FINISH
			txtout+=tblmsop();//START
			lnpixelsum=0
		}else if(lnpixelsum>0){
			txtout+='<img src="'+imgsrc(' ',false,st,'')+'" height='+ht+' width='+spwdth+'>';
			lnpixelsum+=spwdth;
		}
		txtout+=txtoutwd;
		lnpixelsum+=wdpixelsum;
	}
	txtout+=tblmscl();//FINISH
	return txtout;
}

function imgsrc(ltrlow,shft,style,pfx){
	if(!pfx){pfx=''}
	cas='low';
	if(shft){cas='cap'}
	img=cas+'-'+ltrlow+'.gif';
	if(pfx=='blank'){pfx='';img='space.gif'}
	if(ltrlow==' '){img='space.gif'}
	if(ltrlow=='.'){img='period.gif'}
	if(ltrlow=='?'){img='quest.gif'}
	if(ltrlow=='!'){img='excl.gif'}
//	if(ltrlow=='blln'){img='blln.gif'}  to be used??? OR use 'wht' for truly white space or 'blank' for ref. to blank.gif
	img=webroot()+'handwriting/images/'+style+'/'+pfx+img
	return img;
}
function webroot(){
	var txt=document.location.href;
	var re=/\/web\//i;
	if(re.test(txt)){txt=txt.split(re)[0]+'/web/'}
	re=/\/familyphonics.com\//i;
	if(re.test(txt)){txt=txt.split(re)[0]+'/FamilyPhonics.com/'}
	return txt;
}
function pg(){
	var txt=document.location.href;
	var re=/\/web\//i;
	if(re.test(txt)){txt=txt.split(re)[1]}
	re=/\/familyphonics.com\//i;
	if(re.test(txt)){txt=txt.split(re)[1]}
	return txt;
}

function preset(size,style,picspace,ntraceable,nstartdot,nblankline,linewidth){
	fm=document.forms.item("wkshtform")
	fm.Sz.value=size;
	fm.St.value=style;
	fm.Picsp.value=picspace;
	fm.Ntr.value=ntraceable;
	fm.Ndt.value=nstartdot;
	fm.Nbl.value=nblankline;
	fm.Wdwrap.value=linewidth;
	showstsample('stsample');
}
function presetrul(rul1,rul2,rul3){
	fm=document.forms.item("wkshtform")
	fm.Rul1.value=rul1;
	fm.Rul2.value=rul2;
	fm.Rul3.value=rul3;
	setdropdowncolor(fm.Rul1);
	setdropdowncolor(fm.Rul2);
	setdropdowncolor(fm.Rul3);
	showstsample('stsample');
}
function setdropdowncolor(objdd){
	objdd.style.color=objdd.options[objdd.options.selectedIndex].style.color;
}
/****** Begin Word Family page construction ******/
function insertsentences(sz){
	digraphs=new Array('th','ch','sh','wh','ng');
	for(i=0;i<sents.length;i++){
		sentar=sents[i].split('\\'); //c/b place in function, create sent objects, etc.  c/b placed in initializesentences routine
		sent=sentar[0]
		for(j=0;j<stwordar.length;j++){
			re=new RegExp('([\\s])('+stwordar[j]+')([\\s,\.\?!;:$])',"gi");
			sent=sent.replace(re,'$1<font color="#808080">$2</font>$3');
			re=new RegExp('^('+stwordar[j]+')([\\s,\.\?!;:$])',"gi");
			sent=sent.replace(re,'<font color="#808080">$1</font>$2');
		}
		for(j=0;j<digraphs.length;j++){
			re=new RegExp('('+digraphs[j]+')',"gi");
			sent=sent.replace(re,'<u>$1</u>');
		}
		if(sent.substr(0,3)=='---'){document.write('<hr>')}
		else{
			if(/<h1>/i.test(sent)){sent=sent.replace(/<h1>/i,'<p class=size'+sz+' style="text-align:center;font-weight:bold;">')}
			else{document.write('<p class=size'+sz+'>')}
			document.write(sent);
			if(sentar[1]){document.write('<br><a href="javascript:;" onmouseover="javascript:showpic(this,'+"'"+sentar[1]+"'"+');return false;" id=showpic1 class=size8>show picture</a>')}
			document.write('</p>');
		}
	}

}

function initstwordar(){
	if(typeof(window['stwordar'])=='undefined'){stwordar=new Array()}
	for(i=0;i<stwords.length;i++){stwordar.push(stwords[i].split('\\')[0])}
}
function initwfwordar(){
	if(typeof(window['wfwordar'])=='undefined'){wfwordar=new Array()}
	for(i=0;i<wfwords.length;i++){
		wfw=wfwords[i].split('\\')[0];
		if(wfw.substr(0,3)!='---'&&wfw.substr(0,3)!='==='){wfwordar.push(wfw)}
	}
}
function wkshtwords(wordarray,wdwrap,sz,st,pfx){

}
function wkshtsentences(sentarray,wdwrap){
	
}
function randomarray(ar,offset){
	if(isNaN(offset)){offset=0}//offset must be between 
	rdm=new Array(59,51,9,93,16,82,94,76,14,2,71,8,31,70,89,56,80,85,37,98,36,65,26,42,83,22,29,91,32,68,63,58,23,66,64,47,38,62,55,74,15,72,86,12,99,49,79,95,52,6,27,92,3,90,88,13,87,60,40,45,17,21,81,24,30,78,33,0,18,75,73,77,50,25,69,53,97,28,35,34,57,61,19,54,41,43,39,20,67,11,1,96,44,5,10,48,84,46,4,7)
	arout=new Array();
	for(i=0;i<rdm.length;i++){
		j=i+offset;
		if(j>=rdm.length){j=j-100}
		if(rdm[j]<ar.length){arout.push(ar[rdm[j]])}
	}
	return arout;
}
function writingassigns(){
	document.write('<b class=size10>Word Lists:</b><br><u>Trace</u> and <u>copy</u> words.');
	wdlist=stwordar.toString().replace(/,/g,', ');
	document.write('<div class=hangind><a href="">Sight Words:</a> '+wdlist+'</div>');
	wdlist=wfwordar.toString().replace(/,/g,', ');
	document.write('<div class=hangind><a href="">New Word-Family Words:</a> '+wdlist+'</div>');
	document.write('<br><br><b class=size10>Spelling Quizes:</b><br><u>Read</u> the words off of this screen, or highlight the word list and print "Selection". Pronounce words clearly and carefully.');
	document.write('<div class=hangind><a href="">Spelling "Quiz" - Presentation Order:</a> '+wdlist+'</div>');
	wdlist=randomarray(wfwordar,4).toString().replace(/,/g,', ');
	document.write('<div class=hangind><a href="">Spelling "Quiz" - "Random" Order:</a> '+wdlist+'</div>');
}
function writingassigns2(){
	first=true;
	sn=2;
	for(i=0;i<sents.length;i++){
		sentar=sents[i].split('\\');
		sent=sentar[0];
		if(sent.substr(0,3)=='---'){
			if(!first){document.write('</div>')}
			first=true;
			if(sent.substr(3,1)=='1'){sn=1}else{sn=2}
		}else if(first){
			first=false;
			document.write('<div class=hangind><a href="">');
			if(/<h1>/i.test(sent)){
				sent=sent.replace(/<h1>/i,'');
				document.write(sent+' (trace only):</a> ');
			}else{
				document.write('Sentence'+pl(sn)+' (trace and copy):</a> '+sent+' ');
			}
		}else{
			document.write(' '+sent);
		}
	}
	document.write('</div>')
}
function setcookie(name,value,days)
{
	if (!days){days=365}
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function getcookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function clearcookie(name)
{
	createCookie(name,"",-1);
}