//wow! ser/estar,numbers,indirect,verbs,past/present 10:47 AM 12/16/2003
//four major tenses: pres, past, pres subj, imperfect subj 12:35 AM 12/18/2003
//
//Verb list works. I've checked this over for every verb in Appendix 1 of Dos Mundos. 
//Conceivable that there are still minor mistakes, but... 3:34 PM 12/18/2003
//TF, XOptions work 8:05 PM 12/22/2003
//revision 6:03 PM 3/1/2004 more... oi'r lookup fails; add (se) to highlighted nonquiz parts.
//rev 5:19 AM 3/5/2004 variables in verbs
//rev 7:40 AM 3/20/2004 added testdata
//rev 5:13 AM 10/5/2004 added subjunctive quiz; reversed order of i' to 'i in inputs.
//rev 8:46 AM 2/8/2005 vocabulario fuente
//rev 1:13 PM 4/3/2005 fix for Math.max(a,b,c) not on Mac
//rev 6:59 PM 4/4/2005 fix for long listing errors
//rev 8:09 AM 4/7/2005 fix for "to allow" not found when looking up a verb
//rev 10:33 AM 05/20/2005 adding "showtypes"

//startup options

iscsv=true //for option "listallmodels"
wordref="http://www.wordreference.com/es/en/translation.asp?spen="
realdef="http://buscon.rae.es/draeI/SrvltGUIBusUsual?TIPO_BUS=0&LEMA="

s=parent.document.location.search
level=parseInt(s.indexOf("all")>=0?"9999":getfield(s,"level","111"))
isquiz=(s.indexOf("list")<0)
istesting=(s.indexOf("testing")>=0) //shows answers
ilistalltests=(s.indexOf("alltestdata")>=0) //shows all test data
ishowtestdata=(s.indexOf("testdata")>=0)
ishowtypes=(s.indexOf("showtypes")>=0)
issubjunctive=false
ishowyotu=true

checking=getfield(s,"value","")

//numeros
rangefrom=parseInt(getfield(s,"from","1"))
rangeto=parseInt(getfield(s,"to","100"))
isaddsub=(s.indexOf("addsub")>=0)

//vocab temp variable
vocabsource=""
fuente=unescape(getfield(s,"fuente",""))
Vocabsourcelist=new Array()

//verbs
thisverb=unescape(getfield(s,"verb",""))
if(thisverb.indexOf("??")==0){
	thisverb=fixcharuser(prompt("Enter an infinitive, any conjugation of one, or an English infinitive starting with \"to \". Use \"?\" for variable letters and \"^\/$\" to indicate the beginning/end of a word."))
	if(!thisverb)thisverb="hablar"
}
if(thisverb)thisverb=thisverb.replace(/\+/," ")
thismodel=getfield(s,"model","")
if(thismodel.indexOf("?")>=0){
	thismodel=prompt("Enter a model number from 1 to 92.")
	thismodel=parseInt(thismodel)
	if(!thismodel)thismodel=1
}else{
	thismodel=parseInt(thismodel)
}
if(thismodel||thisverb){
	isquiz=false
	level=9999
}
iallowvosotros=(s.indexOf("allowvos")>=0)
ishowvosotros=(s.indexOf("shownovos")<0)
isbynum=(s.indexOf("bynum")>=0)
issorted=(s.indexOf("nosort")<0 && !isbynum)
isnotable=(s.indexOf("notable")>=0) //shows no table--just sentences
isalphabetical=(isnotable || s.indexOf("alpha")>=0)
ishowperson=(s.indexOf("showyo")>=0)
includeallsubj=(s.indexOf("allsubj")>=0)
isbookorder=(s.indexOf("bookorder")>=0)
ilistallmodels=(s.indexOf("listallmodels")>=0)
ilistalldefs=(s.indexOf("listdefs")>=0)
ishowdef=(s.indexOf("shownodef")<0)
s=parent.document.location+""
thetense=getfield(s,"tense",s.indexOf("indexp.htm")>=0?"pastind":"presind")
strtense="str_"+thetense
if(thetense!="presind"&&level==111)level=112

//these may be overridden in js files:
nquest=12
nverbexamples=0
percentQuestion=40
percentNegative=40
percentPastTense=40
percentSubjunctive=75
//docstyle imported from styles.js
//data
Verbs=new Array()
Phrases=new Array()
Models=new Array()
Persons=new Array()
Numeros=new Array()
Palabras=new Array()
Listed=new Array()

Persons["subject"]=new Array("yo","tu'","e'l/ella/usted","nosotros/nosotras","vosotros/vosotras","ellos/ellas/ustedes")
Persons["adjendings"]=new Array("o","o","o/a/a","os/as","os","os/as/os")
Persons["indirectwithprep"]=new Array("mi'","ti'")

Persons["poss-adj"]=new Array("mi","tu","su","nuestro/nuestra","vuestro/vuestra","su")
Persons["reflexive"]=new Array("me","te","se","nos","os","se")
Persons["indirect"]=new Array("me","te","le","nos","os","les")

TenseNames=new Array()
if(isbookorder){
	TenseNames["presind"]="Present Indicative"
	TenseNames["impind"]="Imperfect Indicative" 
	TenseNames["pastind"]="Past Indicative (Preterite)"
	TenseNames["futind"]="Future Indicative" 
	TenseNames["cond"]="Conditional" 
	TenseNames["presubj"]="Present Subjunctive"
	TenseNames["impsubj"]="Imperfect Subjunctive"
  if(includeallsubj){
	TenseNames["impsub-s"]="Imperfect Subjunctive (S-Form)"
	TenseNames["futsubj"]="Future Subjunctive"
  }
	TenseNames["imperative"]="Imperative"
}else if(ishowtypes){
	TenseNames["presind"]="Present Indicative"
	TenseNames["imperative"]="Imperative"
	TenseNames["presubj"]="Present Subjunctive"
	TenseNames["impsubj"]="Imperfect Subjunctive"
  if(includeallsubj){
	TenseNames["impsub-s"]="Imperfect Subjunctive (S-Form)"
	TenseNames["futsubj"]="Future Subjunctive"
  }
	TenseNames["pastind"]="Past Indicative (Preterite)"
	TenseNames["impind"]="Imperfect Indicative" 
	TenseNames["cond"]="Conditional" 
	TenseNames["futind"]="Future Indicative" 
}else{
	TenseNames["presind"]="Present Indicative"
	TenseNames["imperative"]="Imperative"
	TenseNames["presubj"]="Present Subjunctive"
	TenseNames["impsubj"]="Imperfect Subjunctive"
  if(includeallsubj){
	TenseNames["impsub-s"]="Imperfect Subjunctive (S-Form)"
	TenseNames["futsubj"]="Future Subjunctive"
  }
	TenseNames["pastind"]="Past Indicative (Preterite)"
	TenseNames["impind"]="Imperfect Indicative" 
	TenseNames["cond"]="Conditional" 
	TenseNames["futind"]="Future Indicative" 
}

//my four primary tenses and moods:

//present and past indicative
Persons["presind"]=new Array() //lots of irr.
Persons["presind"]["a"]=new Array("o","as","a","amos","a'is","an")
Persons["presind"]["e"]=new Array("o","es","e","emos","e'is","en")
Persons["presind"]["i"]=new Array("o","es","e","imos","i's","en")
Persons["pastind"]=new Array() //lots of irr.
Persons["pastind"]["a"]=new Array("e'","aste","o'","amos","asteis","aron")
Persons["pastind"]["e"]=new Array("i'","iste","io'","imos","isteis","ieron")
Persons["pastind"]["i"]=new Array("i'","iste","io'","imos","isteis","ieron")

//present subjunctive essentially, from present o~a/e, a~e, e~a, i~a (exception in vosotros); lots of irr.
Persons["presubj"]=new Array()
Persons["presubj"]["a"]=new Array("e","es","e","emos","e'is","en")
Persons["presubj"]["e"]=new Array("a","as","a","amos","a'is","an")
Persons["presubj"]["i"]=new Array("a","as","a","amos","a'is","an")

//imperfect subjunctive ra era ra into imperfect; lots of irr.
Persons["impsubj"]=new Array()
Persons["impsubj"]["a"]=new Array("ara","aras","ara","a'ramos","arais","aran")
Persons["impsubj"]["e"]=new Array("iera","ieras","iera","ie'ramos","ierais","ieran")
Persons["impsubj"]["i"]=new Array("iera","ieras","iera","ie'ramos","ierais","ieran")

//derived or simpler types:
specialtypes="imperative,impind,futind,cond,impsub-s,futsubj,gerund,pastpart"

//imperative
noimperatives=",haber,poder,"
//Persons["imperative"]=new Array()
//Persons["imperative"]["a"]=new Array("XX","a","e","emos","ad","en")
//Persons["imperative"]["e"]=new Array("XX","e","a","amos","ed","an")
//Persons["imperative"]["i"]=new Array("XX","e","a","amos","id","an")

//eight imperative irregularites tú form:

imperative_irr=new Array()
imperative_irr["decir"]="di"
imperative_irr["hacer"]="haz"
imperative_irr["ir"]="ve"
imperative_irr["poner"]="pon"
imperative_irr["salir"]="sal"
imperative_irr["ser"]="sé"
imperative_irr["contener"]="contén"
imperative_irr["detener"]="detén"
imperative_irr["entretener"]="entretén"
imperative_irr["obtener"]="obtén"
imperative_irr["tener"]="ten"

imperative_irr["intervenir"]="intervén"
imperative_irr["prevenir"]="prevén"
imperative_irr["venir"]="ven"

imperative_irr["ver"]="ve"


//imperfect indicative ba i' i'
Persons["impind"]=new Array()
Persons["impind"]["a"]=new Array("aba","abas","aba","a'bamos","abais","aban")
Persons["impind"]["e"]=new Array("i'a","i'as","i'a","i'amos","i'ais","i'an")
Persons["impind"]["i"]=new Array("i'a","i'as","i'a","i'amos","i'ais","i'an")
//only these three are irregular:
impind_irr=new Array()
impind_irr["ir"]=new Array("iba","ibas","iba","i'bamos","ibais","iban")
impind_irr["ser"]=new Array("era","eras","era","e'ramos","erais","eran")
impind_irr["ver"]=new Array("vei'a","vei'as","vei'a","vei'amos","vei'ais","vei'an")


//conditional: infinitive+imperfect indicative"

//added to full verb based (same irregularities as cond):
Persons["futind"]=new Array("e'","a's","a'","emos","e'is","a'n")

//from impsubj, just changes in ending:
Persons["impsub-s"]="impsubj:ra~se" 
Persons["futsubj"]="impsubj:ra~re"

//gerund uses stem change for models 1-63 from imperfect subjunctive 1st person
Gerund=new Array()
Gerund["a"]="ando"
Gerund["e"]="iendo"
Gerund["i"]="iendo"
gerund_irr=new Array()
gerund_irr["ir"]="y-"
gerund_irr["erguir"]="irgu"
gerund_irr["decir"]="dic"
gerund_irr["predecir"]="predic"
gerund_irr["maldecir"]="maldic"
gerund_irr["bendecir"]="bendic"
gerund_irr["poder"]="pud"
gerund_irr["venir"]="vin"
gerund_irr["hornear"]="horne"


//past participle is from infinitive with a few model irregularities and a few unique irregularities
PastPart=new Array()
PastPart["a"]="ado"
PastPart["e"]="ido"
PastPart["i"]="ido"
pastpart_irr=new Array() //in models.js
pastpart_irr["maldecir"]=["maldecido",0]
pastpart_irr["bendecir"]=["bendecido",0]

//
People=new Array()
People["e'l"]="{e'l|Esteban|Miguel|Jose'|Jesu's|mi ti'o}"
People["ella"]="{ella|Marisa|Maria|Juanita|mi novia}"
People["ellas"]="{ellas|Marisa y Juanita|Marta y Maria|mis amigas}"
People["ellos"]="{ellos|Esteban y Maria|mis hermanos|mis padres}"
People["nosotros"]="{nosotros|Maria y yo|mi madre y yo}"
pasttimes="{ayer|el {lunes|martes|mie'rcoles|jueves|viernes|sa'bado|domingo|an~o|mes|semana} pasado|anoche|anteayer}"
presenttimes="{hoy|ahora}"

nounclauses_subj="{me gusta|no me parece|no creo|no es verdad|[s] querer|[s] esperar|[s] estar contento|[s] sentir|[s] preferir|[s] temer|[s] tener miedo de|[s] mandar|[s] insistir en|[s] prohibir"
	+"|es necesario|es preciso|es menester|es posible|es imposible|es probable|es bueno|es malo|es mejor|es peor|es la'stima|es raro|es importante|es fa'cil|es difi'cil|es aconsejable|basta|importa|es dudoso|es incierto|no es cierto}"
nounclauses_ind="{es verdad|me parece|es cierto|es evidente|es obvio|[s] creer|[s] estar seguro|no es dudoso|no hay duda|[s] pensar}"
nounclausesused=""

Colors=new Array()
Colors["th"]="#D0D0D0" //topheading
Colors["h"]="#A0A0FF" //heading
Colors["a"]="#A0A0FF" //inf ar
Colors["e"]="#B8B8FF" //inf er
Colors["i"]="#D0D0FF" //inf ir
Colors["xa"]="#FFA0A0" //ar irr
Colors["xe"]="#FFB8B8" //er irr
Colors["xi"]="#FFD0D0" //ir irr


Colors["t0"]="white" //type-0    dorm-
Colors["t1"]="#A0A0FF" //type-1  duerm-
Colors["t2"]="#A0FFA0" //type-2  durm-
Colors["t3"]="#FFA0A0" //type-3  tien-
BLUE=1
GREEN=2
LTBLUE=3

//pop-up window options
woptions="menubar,scrollbars,resizable,alwaysRaised,top=100,left=50,width="+(screen.width>900?950:800)+",height=500"

//array indices
VDEF=2
VEXA=3

//global variables
whatthisis=""	//will be "verbs" "wordpair" etc.
thiswindow=""
thislookup=""
isinitialized=false
ishowedall=false
isirregular=false
ispopup=false
ismultiverb=0
ithisq=-1
x=0
nlink=0
peoplelist="" //so that subjects aren't reused so often

Quizzes=new Array()
Correlation=new Array()
Answered=new Array()
Given=new Array()
Hints=new Array()
Imgs=new Array()  //"Images" is a protected word in IE!
XOptions=new Array()

//--FUNCTIONS---

function addlink(swhat,stext,sclass){
	sclass=(arguments.length<3?"":" class="+sclass)
	nlink=(nlink+1)%1000
	Listed[nlink]=swhat
	stext=fixchar(stext)
	if(swhat.indexOf("ALERT:")==0)return "<a href=\"javascript:alert('"+swhat.split(":")[1].replace(/\"/g,"'").replace(/\'/g,"\\'").replace(/\n/g,"\\n")+"')\">"+stext+"</a>"
	if(swhat.indexOf("TIP:")==0)return "<a title=\""+swhat.split(":")[1].replace(/\"/g,"'").replace(/\'/g,"\\'").replace(/\n/g,"\\n")+"\">"+stext+"</a>"
	return (ispopup?stext:"<a"+sclass+" href=javascript:parent.Q_code.showlink("+nlink+")>"+stext+"</a>")
}

function checkall(iskeypress,iquiz){
	if(!isinitialized)return
	for (var i=0;i<Correlation.length;i++){
		if(Correlation[i]==iquiz)ithisq=i
		checktext(Correlation[i],0,iskeypress)	
	}
	if(!iskeypress)checkscore()
}

function checkscore(){
	var n=0
	var nanswered=0
	for(var i=0;i<Correlation.length;i++){
		if(Answered[i+1])nanswered++
		if(Answered[i+1]==1)n++
	}
	if(nanswered==0){
		if(1||confirm("Do you want to see all the answers?"))doreset(1,1)
	}else{
		doreset(0,0)		
		if(!ishowedall)alert((n==nanswered && n>8?"Excellent!\n\n":"")+"You got "+n+" right out of the "+nanswered+" you answered.")
	}
}

function checktext(n,ialert,iskeypress){
	if(!isinitialized||istesting)return
	var isimagepress=(iskeypress==2)
	if(isimagepress)iskeypress=1
	var t=parent.Q_test.document.info["q"+n]
	var v=fixchar(t.value).replace(/\ /g,"").toLowerCase()
	var a=Quizzes[n].replace(/\ /g,"").toLowerCase()
	if(v=="" && !iskeypress){
		//skip if blank and checking all
	}else if(v==a){
		if(v!="" && !Answered[n])Answered[n]=1
		if(isimagepress || !Given[n]){
			parent.Q_test.document.images["i"+n].src="../js/ok.gif"
			t.value=Quizzes[n]
			Imgs[n]="ok"
		}
	}else{
		if(ialert && (v=="" || 1 ||confirm("Esa contesta es falsa. ¿Quieres mirar la contesta ciertas?"))){
			t.value=Quizzes[n]
			Given[n]=true
		}
		if(v!=""||!iskeypress||v==""&&isimagepress){
			parent.Q_test.document.images["i"+n].src="../js/x.gif"
			Imgs[n]="x"
			if(!Answered[n])Answered[n]=-1
		}
	}
}

function clearvariables(){
	if(istesting)return
	var n=0
	var init=isinitialized
	isinitialized=false
	for(var i=0;i<Correlation.length;i++){
		n=Correlation[i]
		parent.Q_test.document.info["q"+n].value=(istesting?Quizzes[n]:"")
		parent.Q_test.document.images["i"+n].src="../js/q.gif"
		Imgs[n]="q"
	}
	isinitialized=init
}

function conj(verb,model,type,person,isnegative){

	//model 1-92 or -1 means normal
	//type "presind" "pastind" etc
	//person 0-5
	var s=""
	var S=new Array()
	var sext=""
	var sindirect=(0 && verb.indexOf("(se)")>=0?"(se)":"")
	var verbinf=verb.split("(")[0].split("[")[0]
	var prefix=""
	var verb0=verb

	if(type=="therule")return getmodelrule(model)
	if(type=="define")return Verbs[verb][VDEF]
	if(Models[model] && Models[model].n>63){ //highly irregular set
		ipt=verbinf.indexOf(Models[model].example)
		if(ipt>0){
			prefix=verbinf.substring(0,ipt)
			verbinf=verbinf.substring(ipt,verbinf.length)
			verb=verb.substring(ipt,verb.length)
		}
	}
	var ipt=verbtypept(verbinf)
	if(ipt<0)return ""
	var sconj=verb.charAt(ipt)
	var sroot=verb.substring(0,ipt)
	var verbending=verbinf.substring(ipt,verbinf.length)
	var conjverb=sroot
	var type0=type
	var sbase=sroot
	var iremovech=0
	isirregular=false
	//skipping indirect stuff here


 if(specialtypes.indexOf(type)>=0){
	if(type=="futind"||type=="cond"){
		if(model>=0 && Models[model].condstem){
			verbinf=Models[model].condstem
			isirregular=true
		}
		conjverb=verbinf+(type=="futind"?Persons["futind"][person]:Persons["impind"]["i"][person])
		return prefix+conjverb
	}else if(type=="gerund"){
		if(person!=0)return ""
		if(gerund_irr[verbinf]){
			conjverb=gerund_irr[verbinf]+"+"
			isirregular=true
		}else if(model>=0 && Models[model].stemchange){
			conjverb=conjfix(conjverb,Models[model].stemchange)
			isirregular=true
		}else{
			if("aeiou".indexOf(conjverb.substring(conjverb.length-1,conjverb.length))>=0){
				conjverb+="y-" //but not hornear...
				isirregular=true
			}
			conjverb+="+"
		}
		conjverb=conjaddext(conjverb,Gerund[sconj])
		return prefix+conjverb
	}else if(type=="pastpart"){
		if(person!=0)return ""
		if(pastpart_irr[verbinf]){
			conjverb=pastpart_irr[verbinf][0]
			isirregular=true
			return prefix+conjverb
		}else if(model>=0 && Models[model].pastpstemchange && Models[model].pastpstemchangerules.indexOf("!"+verbinf)<0){
			conjverb=conjfix(conjverb,Models[model].pastpstemchange)
			isirregular=true
		}else{
			s=verbinf+"|"
			for(var i in pastpart_irr){if(pastpart_irr[i][1]){//is model
				ipt=s.indexOf(i+"|")
				if(ipt>=0){
					conjverb=conjverb.substring(0,ipt)+pastpart_irr[i][0]
					isirregular=true
					return prefix+conjverb
				}
			}}
			conjverb+="+"
		}
		s=(verbending=="i'r"?"i'd[o]":PastPart[sconj])
		conjverb=conjaddext(conjverb,s)
		return prefix+conjverb
	}else if(type=="impind"){
		if(impind_irr[verbinf]){
			conjverb=impind_irr[verbinf][person]
			isirregular=true
			return prefix+conjverb
		}
		conjverb+=Persons["impind"][sconj][person]
		return prefix+conjverb
	}else if(type=="impsub-s"||type=="futsubj"){
		type="impsubj"
	}else if(type=="imperative"){
		if(person==0||noimperatives.indexOf(","+verbinf+",")>=0)return ""
		if(!isnegative && person==4){
			conjverb=verbinf.substring(0,verbinf.length-1)+"d"
			return prefix+conjverb
		}else if(!isnegative && person==1 && imperative_irr[verb0]){
			conjverb=imperative_irr[verb0]
			isirregular=true
			return conjverb
		}else if(!isnegative && person==1 && imperative_irr[verbinf]){
			conjverb=imperative_irr[verbinf]
			isirregular=true
			return prefix+conjverb
		}else if(!isnegative && person==1){
			type="presind"
			iremovech=1
		}else{
			type="presubj"
		}
		type0=type
	}
 }


	if(model>=0&&!Models[model]["ok_"+type])fixmodel(model,type)
	s=(model<0?"":Models[model][type][person])
	isirregular=(model>=0 && Models[model][type][person])
	if(!s)s=""
	sext=Persons[type][sconj][person]
	if(s.indexOf("~")>=0){
		S=s.split("/")
		s=""
		for(var i=0;i<S.length;i++)s+="/"+conjfix(conjverb,S[i])
		conjverb=s.substring(1,s.length)
	}else if(s){
		conjverb=s
	}else{
		conjverb+="+"
	}
	conjverb=conjaddext(conjverb,sext)

	if(type!=type0){
		//impsub-s or futsubj
		s=(type0=="impsub-s"?"se":"re")
		ipt=conjverb.lastIndexOf("ra")
		conjverb=conjverb.substring(0,ipt)+s+conjverb.substring(ipt+2,conjverb.length)
	}

	if(iremovech)conjverb=conjverb.substring(0,conjverb.length-1)
	return prefix+conjverb
}

function conjaddext(s,e){
	return s.replace(/\+/g,e).replace(/\-i/,"").replace(/\-/,"")
}

function conjfix(verb,fromto){
	var sending="+"
	var ipt=0
	var sout=""
	var S=new Array()
	var F=fromto.split(",")
	for(var i=0;i<F.length;i++){//nec. for #50 forzar presubj
		fromto=F[i]
		if(fromto.indexOf("+")>0){//new ending
			S=fromto.split("+")
			fromto=S[0]
			sending=S[1]+(S.length==3?"+":"")
		}
		S=fromto.split("~")
		if(S.length==2){
			if(S[1].indexOf("-i")>=0){//reduced ending
				S[1]=S[1].split("-")[0]
				sending="-+"
			}
			if(S[0]){
				ipt=verb.lastIndexOf(S[0])
				if(ipt>=0)verb=verb.substring(0,ipt)+S[1]+verb.substring(ipt+S[0].length,verb.length)
			}
		}
	}
	return verb+sending
}

function createwindow(s){
 newwin=window.open("",thiswindow,woptions)
 newwin.document.open()
 newwin.document.write("<html><head>"+(isnn4?"":docstyle)+"</head><body>"+s+"<center><a href=javascript:close()>close</a></center></body></html>")
 newwin.document.close()
}

function createverb(verb){
	//although models don't come in with (se), newVerb() or just first use with [nn] might add that
	//sets Verbs[verb], so model=Verbs[verb][0]-1
	if(Verbs[verb])return verb
	var S=(verb+"[0").split("[")	//acostar(se)[31]
	var v1=S[0]			//acostar or acostar(se) (for return only)
	var i=parseInt(S[1])		//31
	var v2=v1.split("(")[0]	//acostar
	var v2se=v2+"(se)"		//acostar(se)
	if(Verbs[v1]||Verbs[v2]||Verbs[v2se])return v1
	if(!i){
		for(var i=0;i<Models.length;i++){
			for(var j=0;j<Models[i].Vlist.length;j++){
				if(Models[i].Vlist[j]==v2||Models[i].Vlist[j]==v2se){
					j=-1
					break
				}
			}
			if(j==-1)break
		}
		i=(j==-1?i+1:-1)
	}
	newV(v2,i)
	newV(v2se,i)
	return v1
}

function doinit(){
	var s=""
	if(top==self)location="index.htm"
	isinitialized=false
	if(checking){
		isalphabetical=true
	}
	if(isquiz){
		s="showquiz_"+whatthisis+"(0)"
	}else{
		s="showlist_"+whatthisis+"(0)"
	}
	setTimeout(s,100)
	isinitialized=true
}

function doreset(isall,ishowall){
	var n=0
	isintitialized=false
	for(var i=0;i<Correlation.length;i++){
		n=Correlation[i]
		if(Answered[n]==-1||isall){
			parent.Q_test.document.images["i"+n].src="../js/q.gif"
			parent.Q_test.document.info["q"+n].value=(ishowall?Quizzes[n]:"")
			Answered[n]=0
			Imgs[n]="q"
			Given[n]=(ishowall?1:0)
		}
	}
	if(isall)ishowedall=false
	if(isall && ishowall)ishowedall=true
	isintitialized=true
}

function dowrite(sout){
	var d=parent.Q_test.document
	d.open()
	if(!isnn4)d.write(docstyle)
	if(isie4)sout="<body onkeypress=parent.Q_code.keyevent()>"+sout+"</body>"
	d.write(sout)
	d.close()
	if(isnn4){
		d.captureEvents(Event.KEYPRESS)
		d.onkeypress=keyevent
	}
	if(isnn6){
		d.captureEvents(Event.KEYPRESS)
		d.onkeypress=keyevent
	}
}

function findinfinitive(sform){
	var i0=0
	var s=""
	var verb=""
	var cverb=""
	var i=sform.indexOf("ndo")
	var isgerund=(i>=0 && i==sform.length-3)
	var isenglish=(sform.indexOf("to ")==0)
	var sending=sform.charAt(sform.length-1)
	var endsino=(sending=="o")
	var pmax=(endsino?0:6)
	if(Verbs[sform]||sform.indexOf("[")>=0||sform.indexOf("(")>=0)return sform
	//check more common first
	if(isenglish){
		for (var v in Verbs){if(Verbs[v][VDEF] && Verbs[v][VDEF]==sform){
				thislookup=v
				return v
		}}
		return ""
	}
	var s=sform.substring(sform.length-2,sform.length)
	if(s=="er"||s=="ar"||s=="ir")return sform
	if(s=="ír")return sform.replace(/ír/g,"i'r")
	if(isgerund){
		for(var i=Models.length-1;i>=0;i--){
			for(var j=0;j<Models[i].Vlist.length;j++){
				verb=Models[i].Vlist[j]
				cverb=conj(verb,i,"gerund",0,0)
				if(sform==cverb)return verb
			}
		}
		return ""
	}
	if(endsino){
		s=sform.substring(0,sform.length-1)+"[o]"
		for(var i=Models.length-1;i>=0;i--){
			for(var j=0;j<Models[i].Vlist.length;j++){
				verb=Models[i].Vlist[j]
				cverb=conj(verb,i,"presind",0,0)
				if(sform==cverb)return verb
				cverb=conj(verb,i,"pastpart",0,0)
				if(s==cverb){
					thislookup=s
					return verb
				}
			}
		}
		return ""
	}
	for(var t in TenseNames){
		for(var p=0;p<6;p++){if(p!=4||ishowvosotros){
			i=(Persons[t] && Persons[t]["a"])
			s=(i?Persons[t]["a"]+","+Persons[t]["e"]+","+Persons[t]["i"]+",":"")
			i0=(i && s.indexOf(sending+",")<0?64:0)
			for(var i=Models.length-1;i>=i0;i--){
				for(var j=0;j<Models[i].Vlist.length;j++){
					verb=Models[i].Vlist[j]
					cverb=conj(verb,i,t,p,0)
					if(sform==cverb||cverb.indexOf("/")>=0&&("/"+cverb+"/").indexOf("/"+sform+"/")>=0)return verb
				}
			}
		}}
	}
	return sform
}

function fixadjectives(s,ip,ipo){
	var S=new Array()
	var x=""
	s=s.replace(/\[os\]/,"[o]").replace(/\[as\]/,"[a]")
	if(s.indexOf("[o]")>=0){
		S=Persons["adjendings"][ip].split("/")
		x=S[ipo]
		s=s.replace(/\[o\]/,x)
	}

	if(s.indexOf("[s]")>=0){
		S=Persons["adjendings"][ip].split("/")
		x=S[ipo]
		x=(x.indexOf("s")>=0?"s":"")
		s=s.replace(/\[s\]/,x)
	}
	if(s.indexOf("[a]")>=0){
		S=Persons["adjendings"][ip].split("/")
		if(S[ipo]=="o")S[ipo]=""
		x=S[ipo].replace(/o/,"e")
		x+=(x.indexOf("s")>=0?"s":"")
		s=s.replace(/\[a\]/,x)
	}
	return s
}

function fixchar(s,ishtml){
	//in spreadsheet templates, the accents are AFTER the character
	if(arguments.length<2)ishtml=0
	s=s.replace(/u\'/g,"<u>ú</u>")
	s=s.replace(/o\'/g,"<u>ó</u>")
	s=s.replace(/i\'/g,"<u>í</u>")
	s=s.replace(/e\'/g,"<u>é</u>")
	s=s.replace(/a\'/g,"<u>á</u>")
	s=s.replace(/n\~/g,"ñ")
	s=s.replace(/U\'/g,"<u>Ú</u>")
	s=s.replace(/O\'/g,"<u>Ó</u>")
	s=s.replace(/I\'/g,"<u>Í</u>")
	s=s.replace(/E\'/g,"<u>É</u>")
	s=s.replace(/A\'/g,"<u>Á</u>")
	s=s.replace(/N\~/g,"Ñ")
	s=s.replace(/u\:/g,"<u>ü</u>")
	s=s.replace(/U\:/g,"<u>Ü</u>")
	s=s.replace(/\?\?/g,"¿")
	s=s.replace(/\!\!/g,"¡")
	if(!ishtml)s=s.replace(/\/u/g,"u").replace(/\<u\>/g,"")
	return s
}

function fixcharuser(s,ishtml){
	//for user input, the accents are BEFORE the character, like the international keyboard
	if(arguments.length<2)ishtml=0
	s=s.replace(/\'u/g,"<u>ú</u>")
	s=s.replace(/\'o/g,"<u>ó</u>")
	s=s.replace(/\'i/g,"<u>í</u>")
	s=s.replace(/\'e/g,"<u>é</u>")
	s=s.replace(/\'a/g,"<u>á</u>")
	s=s.replace(/\~n/g,"ñ")
	s=s.replace(/\'U/g,"<u>Ú</u>")
	s=s.replace(/\'O/g,"<u>Ó</u>")
	s=s.replace(/\'I/g,"<u>Í</u>")
	s=s.replace(/\'E/g,"<u>É</u>")
	s=s.replace(/\'A/g,"<u>Á</u>")
	s=s.replace(/\~N/g,"Ñ")
	s=s.replace(/\:u/g,"<u>ü</u>")
	s=s.replace(/\:U/g,"<u>Ü</u>")
	s=s.replace(/\?\?/g,"¿")
	s=s.replace(/\!\!/g,"¡")
	if(!ishtml)s=s.replace(/\/u/g,"u").replace(/\<u\>/g,"")
	return s
}

function fixcharnot(s){
	s=s.replace(/\ü/g,"u:")
	s=s.replace(/\ú/g,"u'")
	s=s.replace(/\ó/g,"o'")
	s=s.replace(/\í/g,"i'")
	s=s.replace(/\é/g,"e'")
	s=s.replace(/\á/g,"a'")
	s=s.replace(/\ñ/g,"n~")
	return s
}

function fixmodel(i,type){
	var slast=""
	if(!Models[i][type]){
		Models[i]["ok_"+type]=true
		return
	}
	for(var p=0;p<6;p++){
		if(Models[i][type][p]=="-")Models[i][type][p]=slast
		if(Models[i][type][p]=="0")Models[i][type][p]=Models[i][type][0]
		if(Models[i][type][p])slast=Models[i][type][p]
	}	
	Models[i]["str_"+type]=Models[i][type].join(";")
	Models[i]["ok_"+type]=true
}

function fixsubject(s,isquiz){
	s=s.replace(/yo me/,"me").replace(/yo no me/,"no me").replace(/tu\' te/,"te").replace(/nosotros nos/,"nos")
	if(!isquiz)s=s.replace(/yo no /,"no ").replace(/tu\' no /,"no ").replace(/nosotros no/,"no ")
	return s
}

function fixtext(n){
	var t=parent.Q_test.document.info["q"+n]
	var v=fixcharuser(t.value)
	if(v!=t.value)t.value=v
}

//getexample() options
OPT_NEGATE=0x1
OPT_QUEST=0x2
OPT_NOPLURAL=0x4
OPT_NOSINGULAR=0x8
OPT_NOPRONOUNSUBJECT=0x10
OPT_FORCESUBJUNCTIVE=0x20

function getexample(hint,verb,model,iquiz,sentence,ioptions,nsize){

	//the magic occurs here

	// see notes.txt for details of flags

	sentence=setoptions(sentence)
	if(sentence.indexOf("?")<0 && sentence.indexOf("!")<0 && sentence.indexOf(".")<0)sentence+="."

	var isnegative=ioptions & OPT_NEGATE
	var isquestion=ioptions & OPT_QUEST

	// disallow negation sometimes
	if(sentence.indexOf("[nono]")>=0)isnegative=false
	
	var S=new Array()
	var I=new Array(0,0)
	var i=0
	var x=""
	var cverb=""
	var sq=""
	var sleft=""
	var isanswerbox=(hint.indexOf("ANSWER")==0)
	var isverb=(hint.indexOf("VERB")==0)

	var subject=(sentence.indexOf("[nosubj]")>=0||sentence.indexOf("[1]")>=0||sentence.indexOf("[2]")>=0?"":getperson(I,0,ioptions))

	var ithisperson=I[0]
	var ithispersonoption=I[1]
	var reflexivepronoun=(verb.indexOf("(se)")>0?Persons["reflexive"][ithisperson]:"")
	// disallow question sometimes
	if(ithisperson==0||ithisperson==3||sentence.indexOf("!!")==0||sentence.indexOf("[noquest]")>=0)isquestion=false

	//check for hint
	S=(hint+"?").split("?")
	Hints[iquiz]=S[1]

	//check for special components

	//single subject already given
	if(sentence.indexOf("[1]")>=0){
		ithisperson=2
		sentence=sentence.replace(/\[1\]/,"")
	}

	//plural subject already given
	if(sentence.indexOf("[2]")>=0){
		ithisperson=5
		sentence=sentence.replace(/\[2\]/,"")
	}
	if(subject)peoplelist+=";"+subject+";"

	//answerbox means answer to be provided directly (e.g. numero)
	//otherwise we need to conjugate now that we have ithisperson
	//adding "[noconj]" means we probably don't have a verb here.
	if(isanswerbox){
		cverb=verb
		hint=(Hints[iquiz].length?"<a href=javascript:parent.Q_code.showhint("+iquiz+")>hint</a>":"")
	}else{
		cverb=(sentence.indexOf("[noconj]")<0?conj(verb,model,thetense,ithisperson,isnegative):verb)
		if(isverb)hint=verb
		//if(cverb!=verb)hint=hint.replace(/\(se\)/g,"").split("(")[0]	//remove (se) in hint
		if(isverb && iquiz)hint=addlink("POPUPVERB:"+verb,hint)
	}

	//check for variable adjectivial endings [o], [os], [a], [as], and [s]
	sentence=fixadjectives(sentence,ithisperson,ithispersonoption)

	//indirect object; should be used with [1] or [2]
	if(sentence.indexOf("[i]")>=0){
		x=subject
		while(x==subject)x=getperson(I,1,0)
		s=Persons["indirect"][I[0]]
		if(sentence.indexOf("[ip]")<0){
			sleft=s+"_"
		}else{
			sentence=sentence.replace(/\[ip\]/,s)
		}
		peoplelist+=";"+x+";"
		x=x.replace(/ y /," y a ").replace(/ y a yo/," y a mi'")
		sentence=sentence.replace(/\[i\]/,x)
	}
	//possessive adjective
	if(sentence.indexOf("[pa]")>=0){
		s=Persons["poss-adj"][ithisperson]
		sentence=sentence.replace(/\[pa\]/,s)
	}

	//reflexive (indirect pronoun added here as well)
	if(sentence.indexOf("r*")>=0){
		s=Persons["reflexive"][ithisperson]
		sleft=s+"_"+sleft
		sentence=sentence.replace(/r\*/,"*")
		reflexivepronoun=""
	}

	if(reflexivepronoun && !iquiz){
		sleft=reflexivepronoun+"_"+sleft
		reflexivepronoun=""	
	}

	//add time indication

	if(thetense=="pastind" && sentence.indexOf("[time]")<0){
		i=(sentence.indexOf("??")==0||sentence.indexOf("!!")==0?2:0)
		sentence=sentence.substring(0,i)+"[time] "+sentence.substring(i,sentence.length)
	}
	if(sentence.indexOf("[time]")>=0){
		x=setoptions(thetense=="pastind"?pasttimes:presenttimes)
		sentence=sentence.replace(/\[time\]/,x)
	}

	//negation (might work...)
	if(isnegative){
		if(sentence.indexOf("[no]")>=0){
			sentence=sentence.replace(/\[no\]/,"no")
		}else{
			reflexivepronoun="no"+(reflexivepronoun?" "+reflexivepronoun:"")
		}
	}

	//remove flags and comments
	sentence=noflags(sentence)

	//add subject
	x="*"
	if(reflexivepronoun)x=reflexivepronoun+" "+x
	x=(isquestion?x+(subject?" "+subject:""):(subject?subject+" ":"")+x)
	sentence=sentence.replace(/\*/,x)
	sq=sleft+cverb
	sq=fixadjectives(fixchar(sq).replace(/\ /g,"").replace(/\_/g," "),ithisperson,ithispersonoption)

	sentence=getexamplesentence(sentence,sq,iquiz,hint,nsize,isanswerbox,isquestion)
	return sentence
}

function getexample2(iquiz,sentence,ioptions,nsize){

	sentence=setoptions(sentence)

	var stest=""
	var isnegative=ioptions & OPT_NEGATE
	var isquestion=ioptions & OPT_QUEST
	var isnoplural=(ioptions && OPT_NOPLURAL || sentence.indexOf("[noplural]")>=0)
	var isnosingular=(ioptions && OPT_NOSINGULAR || sentence.indexOf("[nosingular]")>=0)
	if(isnoplural)ioptions=ioptions | OPT_NOPLURAL
	if(isnosingular)ioptions=ioptions | OPT_NOSINGULAR
	var isnopronounsubj=(ioptions && OPT_NOPRONOUNSUBJECT || sentence.indexOf("[nopronounsubj]")>=0)
	if(isnopronounsubj)ioptions=ioptions | OPT_NOPRONOUNSUBJECT
	var isTF=(sentence.indexOf("TF:")>=0)

	// disallow negation sometimes
	if(sentence.indexOf("[nono]")>=0)isnegative=false
	
	var S=new Array()
	var I=new Array()
	var i=0
	var x=0

	var subject=""
	var verb=""
	var cverb=""
	var ithisperson=0
	var ithispersonoption=0
	var model=0
	var hint=""
	var no
	var ipt=0
	var IP=1
	var IPO=2
	var PRO=3
	var RPRO=4
	var VERBS=5
	var Subjectinfo=new Array() //[subj,ip,ipo,pron,reflxpron,[verbarray])
	var sq=""

	//no implied subjects yet

	for(var i=1;i<5;i++){
		ipt=sentence.indexOf("[S"+i+"]")
		if(ipt<0)break
		subject=getperson(I,0,ioptions)
		ithisperson=I[0]
		ithispersonoption=I[1]
		s=Persons["subject"][ithisperson].split("/")[ithispersonoption]
		Subjectinfo[i]=new Array(subject,ithisperson,ithispersonoption,s,Persons["reflexive"][ithisperson],[])
		peoplelist+=";"+subject+";"

		if(sentence.indexOf("[o"+i+"]")>=0||sentence.indexOf("[os"+i+"]")>=0||sentence.indexOf("[a"+i+"]")>=0||sentence.indexOf("[as"+i+"]")>=0||sentence.indexOf("[s"+i+"]")>=0){
			sentence=strsub(sentence,"[o"+i+"]","[o]")
			sentence=strsub(sentence,"[a"+i+"]","[a]")
			sentence=strsub(sentence,"[os"+i+"]","[o]")
			sentence=strsub(sentence,"[as"+i+"]","[a]")
			sentence=strsub(sentence,"[s"+i+"]","[s]")
			sentence=fixadjectives(sentence,ithisperson,ithispersonoption)
		}

		for(ipt=0;ipt<sentence.length;ipt++){
			if(sentence.substring(ipt,ipt+4)=="[V"+i+":"){
				verb=getexampleinfo(sentence,ipt+4,"]")
				s=createverb(verb)
				model=Verbs[s][0]-1
				if(!Subjectinfo[i])alert("getexample failed: No subject for verb"+i)
				cverb=conj(s,model,thetense,Subjectinfo[i][IP],isnegative)
				Subjectinfo[i][VERBS][verb]=cverb
			}
		}
	}		

	//add time indication not implemented

	//negation not implemented

	//add all variables
	for(var i=1;i<5;i++){
		ipt=sentence.indexOf("[S"+i+"]")
		if(ipt<0)break
		sentence=strsub(sentence,"[S"+i+"]","["+Subjectinfo[i][0]+"]")
		sentence=strsub(sentence,"[P"+i+"]","["+Subjectinfo[i][PRO]+"]")
		sentence=strsub(sentence,"[R"+i+"]","["+Subjectinfo[i][RPRO]+"]")
		S=Subjectinfo[i][VERBS]
		for(verb in S)sentence=strsub(sentence,"[V"+i+":"+verb+"]","["+S[verb]+"]")
	}

	//get sq variable
	ipt=sentence.indexOf("*[")
	if(isTF){
		sentence="* "+sentence.replace(/\@/g,"")
		ipt=sentence.indexOf("TF:")+1
		s="//"
	}else if(ipt>=0){
		s="]"
	}else{
		s="@"
		ipt=sentence.indexOf("*@")
	}
	if(ipt<0)alert("getexample2 failed; no *[ or in "+sentence)
	sq=getexampleinfo(sentence,ipt+2,s)
	if(isTF)sq=(eval(sq)?"cierto":"falso")

	//remove flags and comments
	sentence=noflags(sentence)

	sentence=strsub(sentence,"["+sq+"]","")
	sentence=strsub(sentence,"@"+sq+"@","").replace(/\[|\]|\@/g,"")

	sentence=getexamplesentence(sentence,sq,iquiz,hint,nsize,0,isquestion)
	return sentence+"<br>"+stest
}

function getexamplebox(iquiz,nsize){
	var s="&nbsp;&nbsp;<input name=q"+iquiz+" type=text size="+nsize+" value=\"\" onfocus=parent.Q_code.checkall(1,"+iquiz+") onchange=\"parent.Q_code.setTimeout('fixtext("+iquiz+")',10)\" onkeypress=\"parent.Q_code.setTimeout('fixtext("+iquiz+")',10)\">"
	s+="<a href=\"javascript:parent.Q_code.checktext("+iquiz+",1,2)\"><img name=i"+iquiz+" border=0 src=../js/q.gif height=16 width=16></a>"
	return s
}

function getexampleinfo(s,ipt,ch){
	return s.substring(ipt,s.length).split(ch)[0]
}

function getexamplesentence(sentence,sq,iquiz,hint,nsize,isanswerbox,isquestion){
	var i=0

	//fix subject "yo no" "yo me" etc.
	sentence=fixsubject(sentence,iquiz)

	//capitalize first letter
	i=sentence.indexOf("*")
	if(sentence.indexOf(". *")>=0 || i==0||i==2 &&(sentence.charAt(0)=="!"||sentence.charAt(0)=="?")){
		sq=ucase(sq,0)
	}else{
		sentence=ucase(sentence,(sentence.indexOf("??")==0||sentence.indexOf("!!")==0?2:0))
	}

	for(i=0;i<sentence.length;i++){
		if(sentence.substring(i,i+2)==". "){
			sentence=ucase(sentence,i+2)
		}
	}
	sentence=ucase(sentence,0)

	//add input box
	if(iquiz && !istesting){
		Quizzes[iquiz]=fixchar(sq)
		sq=getexamplebox(iquiz,nsize)
		if(isanswerbox){
			sq="</td><td>"+sq+hint
			hint=""
		}
	}else{
		sq="<b>"+sq+"</b>"
	}
	
	//add variable
	sentence=sentence.replace(/\*/,sq)

	//add question marks if needed (assumes . at end already)
	if(isquestion && sentence.indexOf("?")<0)sentence="??"+sentence.substring(0,sentence.length-1)+"?"

	//format quiz 
	if(iquiz)sentence="&nbsp;&nbsp;</td><td valign=top>"+sentence

	//add hint if needed
	if(iquiz&&hint)sentence="&nbsp;&nbsp;"+hint+sentence

	return fixchar(sentence)
}

function getmodelrule(i){
	var s=Models[i].rule
	s=s.replace(/\,/g,"; ").replace(/\?/g," in some tenses and persons")
	s=s.replace(/\~/g," to ").replace(/\|/g," before ").replace(/\&/g," and ")
	s=s.replace(/\'\'/,"SS").replace(/\'/g,"'SS").replace(/SS/g," in stressed syllables")
	return s
}

function getmodelverblist(model,notthis){
	var sout=""
	var n=0
	var verb=""
	for(var i=0;i<Models[model].Vlist.length;i++){
		verb=Models[model].Vlist[i]
		if(verb.indexOf("(se)")<0 && verb!=notthis){
			sout+=((++n)%10==0?"<br>":" ")+addlink("TOVERB:"+escape(verb),fixchar(verb))
		}
	}
	if(sout!="")sout=" </td><td colspan=6>(see also "+sout+" )</td>"
	return sout
}

function getperson(I,isindirect,ioptions){

	//also sets I[0], I[1]: 
	//ithisperson (0-5), ithispersonoption (0-2, index into x/y/z)
	var subject=""
	var p=0
	var sperson=""
	var S=new Array()
	var ip=0
	var ipo=0
	var i=0
	var slist="/"+Persons["subject"].join("/")+"/"
	var isnoplural=ioptions & OPT_NOPLURAL
	var isnosingular=ioptions & OPT_NOSINGULAR
	var isnopronouns=ioptions & OPT_NOPRONOUNSUBJECT

	while(subject=="" || i++<100 && peoplelist.indexOf(";"+subject+";")>=0){
		ip=-1
		while(ip<0
		||isnopronouns && (ip==0||ip==1||ip==4)  //yo,tu,vosotros
		||isnoplural && ip>2
		||isnosingular && ip<3
		||!iallowvosotros && ip==4
		)ip=rand(6)
		sperson=Persons["subject"][ip]
		S=sperson.split("/")
		ipo=-1
		while(ipo<0|| isnopronouns && slist.indexOf("/"+subject+"/")>=0){
			ipo=rand(S.length)
			subject=S[ipo]
			if(People[subject])subject=setoptions(People[subject])
		}

		if(isindirect){
			if(Persons["indirectwithprep"][ip])subject=Persons["indirectwithprep"][ip]
		}
	}

	I[0]=ip
	I[1]=ipo
	return subject
}

function getverbexample(verb,model,iquiz){
	var i=(issubjunctive?0:thetense=="presubj"?3:thetense=="impsubj"?2:thetense=="pastind"?1:thetense=="presind"?0:-1)
	if(i<0)return ""
	i+=VEXA
	var s=Verbs[verb][i]
	if(!s && thetense=="pastind")s=Verbs[verb][VEXA]
	if(!s)return ""
	var isquestion=(!issubjunctive && randP(percentQuestion)?OPT_QUEST:0)
	var isnegative=(randP(percentNegative)?OPT_NEGATE:0)
	var spresubj=""
	var spre=""
	var spreverb=""
	var I=new Array()
	if(issubjunctive){
		settense(iquiz && !randP(percentSubjunctive)?"presind":"presubj")
		while(spre==""|| nounclausesused.indexOf("|"+spre+"|")>=0)spre=setoptions(thetense=="presubj"?nounclauses_subj:nounclauses_ind)
		nounclausesused+="|"+spre+"|"
		if(spre.indexOf("[s] ")==0){
			spre=spre.substring(4,spre.length)
			spreverb=spre.split(" ")[0]
			spre=spre.substring(spreverb.length+1,spre.length)
			spresubj=getperson(I,0,0)
			if(!Verbs[spreverb])alert(spreverb+" "+spre)
			spre=spresubj+" "+conj(spreverb,Verbs[spreverb][0]-1,"presind",I[0],0)+" "+spre
		}
		s=spre+" que "+s
	}
	return getexample("VERB",verb,model,iquiz,s,isnegative+isquestion,20)
}

function getverblistcell(verb,i,thetense,p){
	var sc=(i>=0?Models[i].sconj:verb.charAt(verbtypept(verb)))
	var reflexivepronoun=(verb.indexOf("(se)")>0?Persons["reflexive"][p]+" ":"")
	var cverb=reflexivepronoun+conj(verb,i,thetense,p,0).replace(/s\//g,"s/ ")
	var itype=0
	var isverb=(cverb!="")
	var n=i+1
	var isspecial=(n>=64)
	var itype2=GREEN
	var stypeyo=";65;66;67;69;71;73;75;76;78;79;81;82;83;84;85;88;89;92;" //unique yo, others regular
	var stypeyotu=";87;90;"		//tener.. unique yo, others irregular
	var stypeother=";68;74;86;91;"
	var stypenoblue=" ;64;"
	var stypenogreen=";31;32;47;48;49;50;51;52;53;54;57;58;59;60;  ;65;67;75;76;81;82;84;89;92;"
	var stypegreenisblue=";34;56;"
	var isgreenblue=(stypegreenisblue.indexOf(";"+n+";")>=0)

	var isyo=(stypeyo.indexOf(";"+n+";")>=0)
	var isyotu=(stypeyotu.indexOf(";"+n+";")>=0)
	var isnoblue=(stypenoblue.indexOf(";"+n+";")>=0)
	var isnogreen=(stypenogreen.indexOf(";"+n+";")>=0)
	var isother=(stypeother.indexOf(";"+n+";")>=0)
	var isregpastsubj=(n==80) //querer
	var isregpressubj=(n==77||n==80) //poder,querer
	var isspecialpr3p=(n==72) //haber
	var isnotspecialpr3p=(n==70) //erguir
	var isnofullpast=(n==70) //erguir
	if(ishowtypes && !isother && isverb){
		itype=(isnoblue?0:BLUE) //irr present
		if(thetense=="pastind"){
		 	itype=0
		 	if(p==2||p==5||isspecial && !isnofullpast)itype=GREEN
		}else if(thetense=="presubj"){
			if(!isspecial && (p==3||p==4))itype=GREEN
			if(isregpressubj && (p==3||p==4))itype=0
		}else if(thetense=="imperative"){
			if(p==4)itype=0
			if(p==3)itype=(isspecial?BLUE:GREEN)
			if(itype==0)itype2=(isnoblue?0:BLUE)
			if(isregpastsubj && (p==3||p==4)){
				itype=0
				itype2=0
			}
		}else if(thetense=="gerund"){
			itype=(isspecial && !gerund_irr[verb]?0:GREEN)
		}else if(thetense=="impsubj"){
			itype=GREEN //irr past 
		}else if(thetense=="presind"){
			if(p!=0 && isyo)itype=0
			if(p!=0 && isyotu)itype=LTBLUE
			if(p==3 &&(!isspecialpr3p)||p==4)itype=0
			if(p==3 && isnotspecialpr3p)itype=0
		}else if(thetense=="impind"||thetense=="pastpart"){
			itype=0
		}else if(thetense=="futind"||thetense=="cond"){
			itype=(Models[i].condstem?LTBLUE:0)
		}
		if(isnoblue && itype==BLUE)itype=0
		if(isnogreen && itype==GREEN)itype=0
		if(isgreenblue && itype==BLUE)itype=GREEN

	}
	if(thislookup && cverb==thislookup)cverb="<font color=red>"+cverb+"</font>"
	if(isverb && thetense=="imperative" && (p==1||p==4))cverb+="<br>&nbsp;no "+reflexivepronoun+conj(verb,i,thetense,p,1).replace(/s\//g,"s/ ")
	cverb=" <b>"+fixchar(cverb.replace(/\[o\]/,"o/a"),1)+"</b>"
	if(isverb && ishowperson && thetense!="gerund" && thetense!="pastpart")cverb=Persons["subject"][p].replace(/ustedes/,"uds.").replace(/usted/,"ud.")+reflexivepronoun+cverb
	cverb="&nbsp;"+cverb+"&nbsp;"
	if(ishowtypes && !isother && isverb && thetense=="imperative"){
		if(p==4){
			cverb="<table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor="+Colors["t0"]+">"+cverb.replace(/\<br\>/,"</b></td></tr><tr><td bgcolor="+Colors["t"+itype2]+"><b>&nbsp;")+"</td></tr></table>"
			itype=0
		}
		if(p==1 && isyo){
			cverb="<table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor="+Colors["t0"]+">"+cverb.replace(/\<br\>/,"</b></td></tr><tr><td bgcolor="+Colors["t"+BLUE]+"><b>&nbsp;")+"</td></tr></table>"
			itype=0
		}
		if(p==1 && isyotu){
			cverb="<table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor="+Colors["t"+LTBLUE]+">"+cverb.replace(/\<br\>/,"</b></td></tr><tr><td bgcolor="+Colors["t"+BLUE]+"><b>&nbsp;")+"</td></tr></table>"
			itype=0
		}
	}
	s="<td"+(ishowtypes && !isother?" bgcolor="+Colors["t"+itype]:isirregular?" bgcolor="+Colors["x"+sc]:"")+" valign=top>"+cverb+"</td>"

	return s
}

function initdivs(){
	isnn4=(document.layers?true:false)
	isie4=(document.all?true:false)
	isnn6=(!isie4 && document.getElementById?true:false)
	if(!isnn4 && !isie4 && !isnn6)alert("This page may not work properly with your browser.")
}initdivs()

function keyevent(e){
	var i=""
	var s=""
	if(!isinitialized)return
	if(istesting || !isquiz)return
	if(isie4)e=parent.Q_test.event
	if(e.keyCode==13){
		parent.Q_code.checkall(1,-1)
		i="q"+Correlation[ithisq+1]
		if(parent.Q_test.document.info[i]){
			if(Imgs[Correlation[ithisq]]=="ok")parent.Q_test.document.info[i].focus()
		}else{
			parent.Q_code.checkall(0,-1)		
		}
	}
	//	for(a in e){if((a+"").indexOf("ur")>=0)s+=a+" "+event[a]+"\n"}
	// alert(s)
}

function newDef(phrase,def,sentence){
	if(!phrase)return
	if(!def){
		vocabsource=phrase
		Vocabsourcelist[Vocabsourcelist.length]=phrase
		return
	}
	if(fuente && vocabsource.indexOf(fuente)<0)return
	var n=Phrases.length
	Phrases[n]=new Array(phrase,def,sentence,vocabsource)
}

function newModel(n,example,stemchange,rule,presind,presubj,pastind,impsubj){
	var i=Models.length
	Models[i]=new Array()
	Models[i].n=n
	Models[i].Vlist=new Array(example)
	Models[i].example=example
	Models[i].sconj=example.charAt(verbtypept(example))
	Models[i].pastpstemchangerules=""
	if(stemchange.indexOf("pp|")>=0){
		var S=stemchange.split("|")
		Models[i].pastpstemchange=S[1]
		if(S[2])Models[i].pastpstemchangerules=S[2]
	}else{
		Models[i].condstem=stemchange
	}
	Models[i].rule=rule

	Models[i]["str_presind"]=fixchar(presind)
	Models[i]["str_pastind"]=fixchar(pastind)
	Models[i]["str_impsubj"]=fixchar(impsubj)
	Models[i]["str_presubj"]=fixchar(presubj)

	Models[i]["ok_presind"]=(presind.indexOf(";-;")<0&&presind.indexOf("0")<0)
	Models[i]["ok_pastind"]=(pastind.indexOf(";-;")<0&&pastind.indexOf("0")<0)
	Models[i]["ok_impsubj"]=(impsubj.indexOf(";-;")<0&&impsubj.indexOf("0")<0)
	Models[i]["ok_presubj"]=(presubj.indexOf(";-;")<0&&presubj.indexOf("0")<0)
	
	Models[i]["presind"]=presind.split(";")
	Models[i]["pastind"]=pastind.split(";")
	Models[i]["impsubj"]=impsubj.split(";")
	Models[i]["presubj"]=presubj.split(";")

	Models[i].stemchange=(n>63?"":Models[i]["impsubj"][0])
	Models[i].isrelevant=true
}

function newNumero(scuen,n,sord){
	Palabras[""+n]=new Array(n,scuen.replace(/\ /g,"_"),sord)
	Numeros[scuen]=n
}

function newPP(verb,pp,ismodel,model){
	pastpart_irr[verb]=new Array(pp,(ismodel=="x"))
}

function newPhrase(verb,level,phrase){
	var n=Phrases.length
	Phrases[n]=new Array((verb?createverb(verb):""),level,phrase)
}

function newV(verb,model){
	newVerb(verb,model,0,"","")
}

function newVerb(verb,model,level,def,example){
	if(Verbs[verb])return
	Verbs[verb]=new Array(model,level,def,example)

	//note: (Verbs[verb][0]-1) is the index into Models provided Models is not sorted.
	if(verb.indexOf("(se)")>=0)newVerb(verb.split("(")[0],model,level,"REFLEXIVEONLY","")
	model--
	if(model<0)return
	for(var i=0;i<Models[model].Vlist.length;i++){
		if(Models[model].Vlist[i]==verb)return
	}
	Models[model].Vlist[i]=verb
}

function newX(){
	var n=XOptions.length
	XOptions[n]=new Array()
	for(var i=0;i<arguments.length;i++)XOptions[n][i]=arguments[i]
}

function noflags(s){
	return s.replace(/\[nopast\]|\[noconj\]|\[noquest\]|\[nosubj\]|\[nono\]|\[no\]/,"").split("//")[0]
}

function numero(n){
	if(n==0)return "cero"
	var ntemp=n
	var n1=0
	S=new Array()
	n=0
	while(ntemp>0){
		n1=numlargest(ntemp)
		S[S.length]=(S.length>0 && Numeros[n1]<10?"y_":"")+n1
		ntemp-=Numeros[n1]
	}
	return S.join("_").replace(/ciento\_y/,"ciento").replace(/cientos\_y/,"cientos").replace(/\ /g,"_")
}

function numlargest(n){
	var ilast="cero"
	for(var i in Numeros){
		if(Numeros[i]>n)break
		ilast=i
	}
	return ilast
}

function rand(n){
	return randx_y(0,n-1)
}

function rand0_n(n){
	return randx_y(0,n)
}

function rand1_n(n){
	return randx_y(1,n)
}

function rand2(t1,t2){
	return (t2-t1)*Math.random()+t1
}

function randP(p){
	return (rand(100)>100-p)
}

function randx_y(x,y){
	return Math.floor(Math.random()*(y-x+1)+x)
}

function randx_y_not(x,y,j){
	var k=j
	while(k==j)k=Math.floor(Math.random()*(y-x+1)+x)
	return k
}

function scramble(A){
	var i1=0
	var i2=0
	var s=""
	for(var i=0;i<1000;i++){
		i1=rand(A.length)
		i2=rand(A.length)
		if(i1!=i2){
			s=A[i1]
			A[i1]=A[i2]
			A[i2]=s
		}
	}
}

function setmodel(n){
	if(!n)thismodel=0
	thismodel=n
	thisverb=""
	for(var i=0;i<Models.length;i++){
		Models[i].isrelevant=(!thismodel||Models[i].n==thismodel)
	}
}

function setoptions(sentence){
	var soptions=""
	var S=new Array()
	var i=sentence.indexOf("}")
	var j=0
	var i1=0
	while(i>=0){
		soptions=sentence.substring(0,i)
		i1=soptions.lastIndexOf("{")
		soptions=soptions.substring(i1+1,i)
		S=soptions.split("|")
		j=rand(S.length)
		sentence=sentence.substring(0,i1)+S[j]+sentence.substring(i+1,sentence.length)
		i=sentence.indexOf("}")
	}
	return sentence
}

function settense(t){
	thetense=t
	strtense="str_"+t
}

function showhint(n){
	alert(Hints[n])
}

function showinfo(){
	var s=""
	if(isquiz){
		s="<p>Type in your answers in the boxes provided. To add a diacritical mark, type it before the letter. For example, for é, type 'e, for ñ, type ~n, and for ü type :u. <br>"
		s+=(isnn4?"":"Press ENTER to go to the next question. ")
		s+="To check an answer, click on the image just to the right of the input box. "
		s+="<a href=\"javascript:doreset(0,0)\">Reset Errors</a> "
		s+="<a href=\"javascript:doreset(1,0)\">Reset All</a> "
		s+="<a href=\"javascript:checkall(0,-1)\">Check All</a> "
		s+="<a href=\"javascript:document.location=document.location\">New Quiz</a> "
	}else if(whatthisis==""||whatthisis=="verbs"){
		s="<p>Numbers refer to model reference numbers given in VOX Compact Spanish and English Dictionary, 2nd Ed. (McGraw Hill, 1994). "
		if(!isnotable && !ilistalldefs)s+="<br>Accented letters are underlined for emphasis only."
	}
	document.write(s)
}

function showlink(n){
	var thismodel0=thismodel
	var thisverb0=thisverb
	var isquiz0=isquiz
	var ilistalldefs0=ilistalldefs
	var ilistalltests0=ilistalltests
	var thisinfo=Listed[n]
	var S=thisinfo.split(":")
	isquiz=0
	ilistalldefs=0
	ilistalltests=0
	isnotable=0
	ismultiverb=0
	if(whatthisis=="verbs")Models.sort(sortm2)
	ispopup=(S[0].indexOf("POPUP")==0)
	if(S[0]=="TOVERB"||S[0]=="POPUPVERB"){
		thismodel=0
		thisverb=unescape(S[1])
		thiswindow=(ispopup?"W"+rand(100000):"")
		showlist_verbs(1)
	}else if(S[0]=="TOMODEL"||S[0]=="POPUPMODEL"){
		level=9999
		if(thetense!="presind" && thetense!="pastind")thetense="presind"
		settense(thetense)
		setmodel(parseInt(S[1]))
		thiswindow="BUFFER"
		buffer=""
		//if(!thismodel|| thismodel && Models[thismodel-1].Vlist.length>1){
			showlist_verbs(1)
		//}
		//if(thismodel){
		//	thisverb=(S[2]?S[2]:Models[thismodel-1].Vlist[0])
		//	thismodel=""
		//	showlist_verbs(1)
		//}
		if(ispopup){
			thiswindow="W"+rand(100000)
			createwindow(buffer)
		}else{
			thiswindow=""
			dowrite(buffer)
		}
	}
	if(thiswindow){
		thismodel=thismodel0
		thisverb=thisverb0
		isquiz=isquiz0
		ilistalldefs=ilistalldefs0
		ilistalltests=ilistalltests0
		thiswindow=""
		ispopup=false
	}
}

function showlist_ayudar(){
	var sout="<table align=center width=600>"
	var c=""
	var s=""
	isquiz=false
	if(issorted)Phrases=Phrases.sort(sorta0)
	for(var i=0;i<Phrases.length;i++){
		c=Colors[(i%2?"e":"i")]
		s=Phrases[i][2].replace(/\*/,"*@"+Phrases[i][0].split("(")[0]+"@")
		s=s.replace(/\[/,"*@").replace(/\]/,"@")
		s=getexample2(0,s,0,0)
		sout+="\n<tr><td nowrap valign=top bgcolor="+c+">"+addlink("ALERT:"+Phrases[i][1],Phrases[i][0])+"</td><td bgcolor="+c+">"+s+"</td></tr>"
	}
	sout+="</table>"
	dowrite(sout)
}

function showquiz_ayudar(){
	showlist_ayudar()
}

function showlist_vocab(){
	var sout="<table align=center width=600>"
	var c=""
	var s=""
	var n=0
	isquiz=false
	var w=""
	if(issorted)Phrases=Phrases.sort(sorta0)

	for(var i=0;i<Phrases.length;i++){
		c=Colors[(i%2?"e":"i")]
		w=Phrases[i][0].split("(")[0]
		s=Phrases[i][2].replace(/\*/,"*@"+w+"@")
		s=s.replace(/\[/,"*@").replace(/\]/,"@")
		if(s.indexOf("@")<0 && s.indexOf(w)>=0)s=s.substring(0,s.indexOf(w))+"*@"+w+"@"+s.substring(s.indexOf(w)+w.length,s.length)
		s=getexample2(0,s,0,0)
		sout+="\n<tr>"
		+"<td bgcolor="+c+" valign=top>"+(++n)+".</td>"
		+"<td nowrap valign=top bgcolor="+c+"><b>&nbsp;"+addlink("TIP:"+Phrases[i][1],Phrases[i][0])+"&nbsp;</b></td>"
		+"<td bgcolor="+c+">"+s+"</td>"
		+"<td nowrap valign=top bgcolor="+c+">&nbsp;"+addlink("TIP:"+Phrases[i][3],"fuente")+"&nbsp;</td>"
		+"</tr>"
	}
	sout+="</table>"
	dowrite(sout)
}

function showquiz_vocab(){
	showlist_vocab()
}

function showlist_national(){
	var sout="<table align=center>"
	var sh="th"
	var c=""
	var sopt=""
	for(var i=1;i<XOptions.length;i++){
		sout+="\n<tr>"
		c=Colors[(i==0?"xi":i%2?"e":"i")]
		for(var j=0;j<XOptions[i].length;j++){
			sopt=XOptions[i][j]
			if(sopt.charAt(0)!="("){
				sopt=setoptions(fixchar(sopt,1).replace(/\[o\]/,"o/a").replace(/\[a\]/,"/a").replace(/\[os\]/,"os/as").replace(/\[as\]/,"es/as"))
				sout+="<"+sh+" bgcolor="+c+" width=100>"+sopt+"</"+s+">"
			}
		}
		sout+="</tr>"
		sh="td"
	}
	sout+="</table>"
	dowrite(sout)
}

function showlist_numeros(){
	var sout="<center>"
	var S=new Array()
	for(var i in Palabras){
		S[S.length]="<td width=25></td><td width=25><b>"+fixchar(Palabras[i].join("</b></td><td width=100><b>"))+"</b></td>"
	}
	sout+=tabulatecolumns(S,3)
	sout+="</center>"
	sout=sout.replace(/\[o\]/g,"o/a").replace(/\_/g," ")
	dowrite(sout)
}

function showlist_verbs(istomodel){

	if(ilistallmodels)return showlist_verbsall()
	if(ilistalltests)return showlist_alltests()
	if(ilistalldefs)return showlist_verbsdef()
	if(thismodel)setmodel(thismodel)
	if(issorted && !thisverb && !thismodel && !ilistallmodels)Models=Models.sort(sortm)
	ismultiverb=(thisverb.match(/\?|\$|\^|\*|\//)!=null)
	var verb=""
	var sout="<table width="+Math.min(screen.width,900)+">"
	var i=0
	var isreg=0
	var s=""
	var slast="xadf"
	var n=0
	var S=new Array()
	S[0]=new Array()
	var P=new Array()
	var cverb=""
	var fcverb=""
	var sconj=""
	var sending=""
	var stail=""
	var sparticiples=""
	var STenses=new Array()
	var isnewwin=ispopup//(thiswindow.charAt(0)=="W")
	var v0=""
	var isnotfound=false
	var nlast=-1
	if(ismultiverb){
		P=(thisverb+"//"+thetense).split("//")
		stail=" verbs of the type "+P[0]+"</td></tr>"
		thisverb=P[0].replace(/\*/,"(?+)")
		thetense=P[1]
		STenses=new Array(thetense)
		r=new RegExp(thisverb.replace(/\?/,"[a-z]"))
		n=-1
		for(var i=0;i<Models.length;i++){if(Models[i].isrelevant){
			for(var j=0;j<Models[i].Vlist.length;j++){
				verb=Models[i].Vlist[j]
				if(verb.match(r)){
					if(level==9999||Verbs[verb]&& Verbs[verb][1]!=0 && Verbs[verb][1]<=level){
						s=Models[i][strtense]
						slast=s
						n++
						S[n]=new Array()
						S[n][S[n].length]=new Array(verb,i,Models[i].n)
						if(!v0)v0=verb
					}
				}
			}
		}}
		if(S)S=S.sort()
		stail="\n<tr><td colspan=7 align=center>&nbsp;<p>"+(n+1)+stail

	}else if(thisverb){
		thislookup=thisverb
		thisverb=findinfinitive(thislookup)
		verb=createverb(thisverb)
		sconj=verb.charAt(verbtypept(verb))
		fcverb=fixchar(verb)
		i=Verbs[verb][0]-1
		S[0][0]=new Array(verb,i,(i<0?0:Models[i].n))

		s=(i>=0?"["+Models[i].n+"]":"")
		if(!isnewwin)s=(i>=0?addlink("TOMODEL:"+Models[i].n,s):"")

		if(fcverb==""){
			s+="&nbsp;&nbsp;<b>\""+thislookup+"\"</b>"
		}else{
			s+="&nbsp;&nbsp;<b>"+fcverb+"</b>"
			s+="<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
			+"<a target=_blank href="+realdef+fcverb+">REAL</a>"
			+"&nbsp;&nbsp;<a target=_blank href="+wordref+fcverb+">más...</a>"

			if(!isnewwin)s+="&nbsp;&nbsp;"+(i<91?addlink("TOVERB:"+escape(Models[i+1].Vlist[0]),"next"):"")
		}
		isreg=(i==-1)
		if(i<0 && !isreg){
			s+="</td><td colspan=6><i>was not found in this verb database. If you believe it to be irregular and you know its model<br> number from the VOX dictionary, you can add that number in brackets after the verb,<b> as, for example, producir[46].</i>"
			isnotfound=true
			sending=verb.substring(verbtypept(verb),verb.length)
		}else if(i>=0){
			s+=getmodelverblist(i,verb)
		}
		sout+="\n<tr><td valign=top>"+s+"</td></tr>"
		if(!isnotfound){//don't show  || isnotfound && "ar,er,ir,i'r,".indexOf(sending+",")>=0){
			if(ishowyotu){
				if(ishowtypes)sout+="\n<tr><td></td><th>yo</th><th>tú</th><th>él/ella/usted</th><th>ellos(as)/ustedes</th><th>vosotros</th><th>nosotros</th></tr>"
			}
			sparticiples="\n<tr>"+showlist_verbshtml(S,sconj,isnewwin,"gerund")+showlist_verbshtml(S,sconj,isnewwin,"pastpart")+"</tr>"
			if(!ishowtypes){
				sout+=sparticiples
				if(!ishowtypes)sout+="\n<tr><td></td><th>yo</th><th>tú</th><th>él/ella/usted</th><th>nosotros</th><th>vosotros</th><th>ellos(as)/ustedes</th></tr>"
			}
			if(i>=0 && Models[i].rule)stail=showlist_verbshtml(S,sconj,isnewwin,"therule")
			if(ishowdef && !isnotfound){
				stail+=showlist_verbshtml(S,sconj,isnewwin,"define")
				stail+=showlist_verbshtml(S,sconj,isnewwin,"anexample")
			}
			for(var i in TenseNames)STenses[STenses.length]=i
		}
	}else{

		STenses=new Array(thetense)
		n=-1
		for(var i=0;i<Models.length;i++){if(Models[i].isrelevant){
			for(var j=0;j<Models[i].Vlist.length;j++){
				verb=Models[i].Vlist[j]
				if(Verbs[verb][VDEF]!="REFLEXIVEONLY"&&(!checking||checking && checking.indexOf(verb)>=0)){
					if(level==9999||Verbs[verb]&& Verbs[verb][1]!=0 && Verbs[verb][1]<=level){
						s=Models[i][strtense]
						if(isbynum && Models[i].n!=nlast || issorted && s!=slast && !isalphabetical){
							slast=s
							nlast=Models[i].n
							n++
							S[n]=new Array()
						}
						if(n<0)n=0
						S[n][S[n].length]=new Array(verb,i,Models[i].n)
						if(!v0)v0=verb
					}
				}
			}
		}}
		if(thismodel && !isnewwin)stail="\n<tr><td colspan=7 align=center>&nbsp;<p>"+addlink("TOVERB:"+escape(v0),"full conjugation of "+fixchar(v0))+"</td></tr>"
//for pop-up show one full conjugation?			for(var i in TenseNames){STenses[STenses.length]=i
	}

	for(var its=0;its<STenses.length;its++){
		sout+=showlist_verbshtml(S,sconj,isnewwin,STenses[its])
		if(ishowtypes && its==4)sout+="<tr><td></td><td colspan=6 bgcolor="+Colors["th"]+">&nbsp;</td></tr>"+sparticiples
	}
	sout+=stail
	sout+="</table>"
	if(thiswindow=="BUFFER"){
		buffer+=sout
	}else if(thiswindow){
		createwindow(sout)
	}else{
		dowrite(sout)
	}
}

function showlist_verbsall(){
	var verb=""
	var sout=(iscsv?"<pre>":"<table>")
	var S=new Array()
	S[0]=new Array()
	for(var i=0;i<Models.length;i++){
		verb=Models[i].Vlist[0]
		thisverb=verb
		sconj=verb.charAt(verbtypept(verb))

		S[0][0]=new Array(verb,i,Models[i].n)
		for(var its in TenseNames)sout+=showlist_verbshtml(S,sconj,false,its,iscsv)
		sout+=showlist_verbshtml(S,conj,false,"gerund",iscsv)
		sout+=showlist_verbshtml(S,conj,false,"pastpart",iscsv)
		sout+=showlist_verbshtml(S,conj,false,"therule",iscsv)
		sout+=showlist_verbshtml(S,conj,false,"define",iscsv)
		sout+=(iscsv?"\n":"\n<tr><td colspan=7><hr></td></tr>")
	}
	sout+=(iscsv?"</pre>":"</table>")
	dowrite(sout)
}

function showlist_verbscsv(S,sconj,isnewwin){
	var verb=""
	var cverb=""
	var sout=""
	var i=0
	var p1=6
	var s=""
	sout=""
	for(var si=0;si<S.length;si++){
		i=S[si][0][1]
		if(i>=0 && !Models[i]["ok_"+thetense])fixmodel(i,thetense)
		for(var j=0;j<S[si].length;j++){
			i=S[si][j][1]
			verb=S[si][j][0]
			s=verb+"~"+thetense+"~                   "
			s=s.substring(0,25)
			sout+=s+","+(i+1)
			p1=(thetense=="define"||thetense=="therule"||thetense=="gerund"||thetense=="pastpart"?1:6)
			for(var p=0;p<p1;p++){
				sout+=","+fixchar(conj(verb,i,thetense,p),0)
			}
		}
	}
	return sout+"\n"
}

function showlist_verbsdef(){
	var S=new Array()
	var s=""
	var i=0
	var n=0
	for (var v in Verbs){if(Verbs[v][VDEF] && Verbs[v][VDEF]!="REFLEXIVEONLY" && Verbs[v][VDEF]!=""){
		if(level==9999||Verbs[v][1]!=0 && Verbs[v][1]<=level){
			n++
			s=fixchar(v)
			i=Verbs[v][0]
			S[S.length]="<td valign=top align=right>"+(i?addlink("POPUPMODEL:"+i+":"+s,"["+i+"]","red"):"")+"</td><td valign=top>"+addlink("POPUPVERB:"+v,s,"blue")+"</td><td>"+Verbs[v][VDEF]+"&nbsp;&nbsp;</td>"
		}
	}}
	s="<a target=_top href=index.htm?listdefs_level=111>Spanish 111</a> "
	s+="<a target=_top href=index.htm?listdefs_level=112>Spanish 112</a> "
	s+="<a target=_top href=index.htm?listdefs_all>all</a> <p>"
	s+="<h3>"+(level==9999?"All Verbs":level==111?"Verbs for Spanish 111":"Verbs for Spanish 112")+" ("+n+")</h3>"
	s+=tabulatecolumns(S,3)
	dowrite(s)
}

function showlist_verbshtml(S,sconj,isnewwin,thistense,iscommas){
	settense(thistense)
	if(arguments.length==5&&iscommas)return showlist_verbscsv(S,sconj,isnewwin)
	var verb=""
	var cverb=""
	var sout=""
	var i=0
	var s=""
	var sline=""
	var sc=""
	var td=""
	var si=0
	var sa=""
	var sexample=""
	var sx=""
	var sperson=""
	var isnegative=false
	var isquestion=false
	var P=new Array()
	var n=0
	s=(thisverb||ilistallmodels?"":"&nbsp;<p>")
	if(!isnewwin && thismodel){
		sa="<h3>["+thismodel+"]</h3>"
		if(thismodel!=1)sa+=addlink("TOMODEL:"+(thismodel-1),"prev")
		if(thismodel!=Models.length)sa+=" "+addlink("TOMODEL:"+(thismodel+1),"next")
		sa+=" "+addlink("TOMODEL:0","all")
		sconj=Models[thismodel-1].sconj
	}

	if(isnotable)sa="</td><td>"
	if(TenseNames[thetense])sout+="\n<tr><td>"+sa+"</td><th colspan=6 bgcolor="+Colors["th"]+">"+s+TenseNames[thetense]+"</th></tr>"
	if(!isnotable && !thisverb &&!ilistallmodels){
		td="<th bgcolor="+Colors["th"]+">"
		sout+="\n<tr><td></td>"+td+fixchar(Persons["subject"].join("</th>"+td),1)+"</th></tr>"
		for(var si=0;si<3;si++){
			sa="aei".charAt(si)
			if((!thisverb&&!thismodel||sa==sconj) && Persons[thetense]){
				td="<th bgcolor="+Colors[sa]+">"
				sout+="\n<tr>"+td+"-"+sa+"r"+"</th>"+td+fixchar(Persons[thetense][sa].join("</th>"+td),1)+"</th></tr>"
			}
		}
	}
	for(var si=0;si<S.length;si++){
		i=S[si][0][1]
		if(i>=0 && !Models[i]["ok_"+thetense])fixmodel(i,thetense)
		s=(i>=0?Models[i][strtense]:"")
		if(!s)s=";;;;;;"
		if(!isnotable && (issorted||isbynum) && !isalphabetical && !thisverb &&!ilistallmodels){
			sout+="\n<tr><td colspan=7><hr></td></tr>"
			P=s.split(";")
			for(var p=0;p<6;p++){
				if(P[p]!="" && P[p].indexOf("~")<0)P[p]=""
			}
			if(!ishowvosotros)P[4]="X"
			s="\n<tr><td></td><td>"+P.join("</td><td>")+"</td></tr>"
			s=s.replace(/\<td\>X\<\/td\>/,"")
			s=s.replace(/\>\~/g,">").replace(/\~/g,"-->").replace(/\<td\>\<\/td\>/g,"<td ></td>").replace(/\<td\>/g,"<td bgcolor="+Colors["h"]+">")
			sout+=fixchar(s,1)
		}
		if(issorted||isalphabetical)S[si]=S[si].sort(sortv)
		sexample=""
		for(var j=0;j<S[si].length;j++){
			i=S[si][j][1]
			verb=S[si][j][0]
			if(!isnotable){
				if(thisverb){
					if(thetense=="gerund")return "<td></td><td colspan=2 align=right bgcolor="+Colors["th"]+"><b>Present Participle:&nbsp;&nbsp;&nbsp;estar&nbsp;+</b></td>"+getverblistcell(verb,i,"gerund",0)
					if(thetense=="pastpart")return "<td colspan=2 align=right bgcolor="+Colors["th"]+"><b>Past Participle:&nbsp;&nbsp;&nbsp;haber&nbsp;+</b></td>"+getverblistcell(verb,i,"pastpart",0).replace(/\/a/,"")
					if(thetense=="therule")return "\n<tr><td align=right>rule:</td><td colspan=6>"+getmodelrule(i)+"</td></tr>"
					if(thetense=="define")return "\n<tr><td align=right>"
					+" definition:</td><td colspan=6>"+Verbs[verb][VDEF]+"</td></tr>"
					if(thetense=="anexample"){
						sout=""
						if(ishowtestdata)sout+=testdata(verb,i,isnewwin)

						if(!Verbs[verb][VEXA])return sout
						settense("presind")
						sout="\n<tr><td align=right>example:</td><td colspan=6>"+getverbexample(verb,i,0)+"</td></tr>"+sout
						return sout
					}
				}
			}
			if(i>=0){
				sc=Models[i].sconj
				sline="["+Models[i].n+"]"
				if(ismultiverb && !isnewwin)sline=addlink("POPUPMODEL:"+Models[i].n+":"+verb,sline,"red")
			}else{
				sc=verb.charAt(verbtypept(verb))
				sline=""
			}
			s=fixchar(verb)
			if(isnotable){
				if(Verbs[verb]&&Verbs[verb][VEXA]){
					sexample+="<td valign=top align=right>"+(i?addlink("POPUPMODEL:"+Models[i].n+":"+verb,sline,"red"):"")+"</td><td valign=top>"+addlink("POPUPVERB:"+verb,s,"blue")+"</td>"
					+"<td colspan=6>"+getverbexample(verb,i,0)+"</td></tr>"
				}
			}else{
				if((!isnotable||Verbs[verb][VEXA]) && !isnewwin && !thisverb &&!ilistallmodels)sline=addlink("TOVERB:"+escape(verb),sline)
				if(Verbs[verb][VDEF])s=addlink("ALERT:"+s+"\n\n"+Verbs[verb][VDEF],"<font color=black>"+s+"</font>")
				sline="\n<tr><td bgcolor="+Colors[sc]+">"+sline+" <b>"+s+"&nbsp;&nbsp;</b></td>"
				for(var p=0;p<6;p++){if(p!=4||ishowvosotros){
					sline+=getverblistcell(verb,i,thetense,(ishowtypes && p>2?8-p:p))
				}}
				sout+=sline+"</tr>"
				if(Verbs[verb]&&Verbs[verb][VEXA]){
					for(k=0;k<(thisverb?nverbexamples:1);k++){
						sx="\n<tr><td></td><td colspan=6><font color=blue>"+getverbexample(verb,i,0)+"</font></td></tr>"
						if(sexample.indexOf(sx)<0)sexample+=sx
					}
				}


			}
		}
		sout+=sexample
	}


	return sout
}

function showquiz_indirect(){
	peoplelist=""
	var verb=""
	var sout="<form name=info action=\"javascript:;\"><table>"
	var S=new Array()

	var n=0
	var s=""
	var ipt=0
	var isnegative=false
	var isquestion=false
	var Slist=new Array()
	var phrase=0
	while(n<nquest){
		for(var i=0;i<Phrases.length;i++){
			if(level==9999||Phrases[i][1]<=level){
				if(checking==""||checking==Phrases[i][0])Slist[n++]=i
			}
		}
	}
	scramble(Slist)
	for(var i=0;i<nquest;i++){
		n=i+1
		Correlation[i]=n
		Answered[n]=false
		Given[n]=false
		Imgs[n]="q"
		phrase=Slist[i]
		verb=Phrases[phrase][0]//gustar or otherwise
		ipt=Verbs[verb][0]-1
		s=Phrases[phrase][2]
		if(level>111)thetense=(s.indexOf("[nopast]")<0 && randP(percentPastTense)?"pastind":"presind")
		isquestion=(randP(percentQuestion)?OPT_QUEST:0)
		isnegative=(randP(percentNegative)?OPT_NEGATE:0)
		s=getexample(verb,verb,ipt,n,s,isnegative+isquestion,20)
		sout+="\n<tr><td valign=top>"+n+".<br>&nbsp;</td><td valign=top>"+s+"</td></tr>"
	}
	sout+="</table></form>"
	dowrite(sout)
	setTimeout("clearvariables();parent.Q_test.document.info.q"+Correlation[0]+".focus()",100)
}

function showquiz_directions(){
	showquiz_optionlist()
}

function showquiz_national(){
	showquiz_optionlist()
}

function showquiz_subjuntivo(){
	issubjunctive=true
	showquiz_verbs()
}

function showlist_subjuntivo(){
	issubjunctive=true
	showlist_verbs()
}

function showquiz_optionlist(){
	peoplelist=""
	var verb=""
	var sout="<form name=info action=\"javascript:;\"><table>"
	var S=new Array()

	var n=0
	var s=""
	var slist=";"
	var tries=0
	var isnegative=false
	var isquestion=false
	var Slist=new Array()
	var opt1=0
	var opt2=0
	var j=0
	var k=999
	var get2=0
	var scode=""
	var checktries= (XOptions.length*Phrases.length<nquest)
	while(n<nquest){
		for(var i=0;i<Phrases.length;i++){if(level==9999||Phrases[i][1]<=level){
			s=Phrases[i][2]
			get2=(s.indexOf("[X2:")>=0)
			j=randx_y(1,XOptions.length-1)
			scode=(XOptions[0][0]=="Code"?XOptions[j][0]:"")
			if(Phrases[i][0]!=""&&Phrases[i][0].indexOf(scode)<0)j=-1
			if(get2){
				k=randx_y_not(1,XOptions.length-1,j)
				scode=(XOptions[0][0]=="Code"?XOptions[k][0]:"")
				if(Phrases[i][0]!=""&&Phrases[i][0].indexOf(scode)<0)k=-1
			}else{
				k=9999
			}
			if(j>=0 && k>=0){
					s=i+";"+j+";"+(get2?k+";":"")
					if(!checktries||slist.indexOf(";"+s)<0){
						Slist[n++]=s
						slist+=s
					}else if(++tries>100){
						slist=";"
						tries=0
					}
			}
		}}
	}
	scramble(Slist)

	for(var i=0;i<nquest;i++){
		n=i+1
		Correlation[i]=n
		Answered[n]=false
		Given[n]=false
		Imgs[n]="q"
		S=Slist[i].split(";")
		s=Phrases[parseInt(S[0])][2]
		opt1=parseInt(S[1])
		if(get2){
			opt2=parseInt(S[2])
			for(var j=0;j<XOptions[opt1].length;j++){
				s=strsub(s,"[X1:"+XOptions[0][j]+"]","@"+XOptions[opt1][j].replace(/\]/g,"1]")+"@")
				s=strsub(s,"[X2:"+XOptions[0][j]+"]","@"+XOptions[opt2][j].replace(/\]/g,"1]")+"@")
			}
		}else{
			for(var j=0;j<XOptions[opt1].length;j++)s=strsub(s,"["+XOptions[0][j]+"]","@"+XOptions[opt1][j].replace(/\]/g,"1]")+"@")
		}
		thetense="presind"
		s=getexample2(n,s,0,(s.indexOf("TF:")>=0?6:20))
		sout+="\n<tr><td valign=top>"+n+".<br>&nbsp;</td><td valign=top>"+s+"</td></tr>"
	}
	sout+="</table></form>"
	dowrite(sout)
	setTimeout("clearvariables();parent.Q_test.document.info.q"+Correlation[0]+".focus()",100)
}

function showquiz_numeros(){
	peoplelist=""
	var sout="<form name=info action=\"javascript:;\">"
	var S=new Array()

	var n=0
	var s=""
	var ipt=0
	var i1=0
	var i2=0
	var ia=0
	var range0=(rangefrom?rangefrom:0)
	var range1=(rangeto?rangeto:1000)
	var isminus=false
	var r1=range1
	var r0=range0
	var isnegative=false
	var isquestion=false
	var Slist=new Array()
	var answerlist=""
	scramble(Slist)
	for(var i=0;i<nquest;i++){
		n=i+1
		Correlation[i]=n
		Answered[n]=false
		Given[n]=false
		Imgs[n]="q"
		ia=-1
		while(ia<0||answerlist.indexOf(";"+ia+";")>=0){
			i1=randx_y(r0,r1)
			if(isaddsub)i2=randx_y(r0,r1)
			isminus=(i2<=i1)
			ia=(isminus?i1-i2:i1+i2)
		}
		answerlist+=";"+ia+";"
		if(isaddsub){
			s="??Cua'nto es "+i1+(isminus?" menos ":" ma's ")+i2+"? *[nosubj]"
			s=getexample("ANSWER"+"?"+i1+(isminus?" - ":" + ")+i2+" = "+ia,numero(ia),0,n,s,0,30)
		}else{
			s="??Co'mo escribes "+ia+"? *[nosubj]"
			s=getexample("ANSWER",numero(ia),0,n,s,0,40)
		}
		S[S.length]="<td valign=top>"+n+".<br>&nbsp;</td><td valign=top>"+s+"</td><td width=25></td>"
	}
	sout+=tabulatecolumns(S,(isaddsub?1:2))
	sout+="</form>"
	dowrite(sout)
	setTimeout("clearvariables();parent.Q_test.document.info.q"+Correlation[0]+".focus()",100)
}

function showquiz_verbs(){
	peoplelist=""
	var verb=""
	var sout="<form name=info action=\"javascript:;\"><table>"
	var S=new Array()

	var n=0
	var s=""
	var Slist=new Array()
	var model=0
	var isnegative=false
	var isquestion=false

	while(n<nquest){
		for(var i=0;i<Models.length;i++){if(Models[i].isrelevant){
			for(var j=0;j<Models[i].Vlist.length;j++){
				verb=Models[i].Vlist[j]
				if(Verbs[verb]&&Verbs[verb][VEXA]
				 &&(!checking||checking && checking.indexOf(verb)>=0)
				 &&(level==9999||Verbs[verb][1]!=0&&Verbs[verb][1]<=level)
				 &&(thetense!="pastind"||Verbs[verb][VEXA].indexOf("[nopast]")<0)
				 &&(!issubjunctive||Verbs[verb][VEXA].indexOf("??")<0&&Verbs[verb][VEXA].indexOf("!!")<0)
				)Slist[n++]=i+";"+j
			}
		}}
	}
	scramble(Slist)
	for(var i=0;i<nquest;i++){
		n=i+1
		Correlation[i]=n
		Answered[n]=false
		Given[n]=false
		Imgs[n]="q"
		S=Slist[i].split(";")
		model=parseInt(S[0])
		j=parseInt(S[1])
		verb=Models[model].Vlist[j]
		s=getverbexample(verb,model,i+1)
		sout+="\n<tr><td valign=top>"+n+".<br>&nbsp;</td><td valign=top>"+s+"</td></tr>"
	}
	sout+="</table></form>"
	dowrite(sout)
	setTimeout("clearvariables();parent.Q_test.document.info.q"+Correlation[0]+".focus()",100)
}

function showquiz_wordpair(){
	peoplelist=""
	var verb=""
	var sout="<form name=info action=\"javascript:;\"><table>"
	var S=new Array()

	var n=0
	var s=""
	var ipt=0
	var isnegative=false
	var isquestion=false
	var Slist=new Array()
	var wordpair="/"
	for(var i=0;i<Phrases.length;i++){
		if(level==9999||Phrases[i][1]<=level){
			verb=Phrases[i][0]		
			if(wordpair.indexOf("/"+verb+"/")<0)wordpair+=verb+"/"
		}
	}
	wordpair=wordpair.substring(1,wordpair.length-1)
	while(n<nquest){
		for(var i=0;i<Phrases.length;i++){
			if(level==9999||Phrases[i][1]<=level)Slist[n++]=i
		}
	}
	scramble(Slist)
	for(var i=0;i<nquest;i++){
		n=i+1
		Correlation[i]=n
		Answered[n]=false
		Given[n]=false
		Imgs[n]="q"
		verb=Phrases[Slist[i]][0]
		ipt=Verbs[verb][0]-1
		s=Phrases[Slist[i]][2]
		if(level>111)thetense=(s.indexOf("[nopast]")<0 && randP(percentPastTense)?"pastind":"presind")
		isquestion=(randP(percentQuestion)?OPT_QUEST:0)
		isnegative=(randP(percentNegative)?OPT_NEGATE:0)
		s=getexample(wordpair,verb,ipt,n,s,isnegative+isquestion,20)
		sout+="\n<tr><td valign=top>"+n+".<br>&nbsp;</td><td valign=top>"+s+"</td></tr>"
	}
	sout+="</table></form>"
	dowrite(sout)
	setTimeout("clearvariables();parent.Q_test.document.info.q"+Correlation[0]+".focus()",100)
}

function showtop(what){
	whatthisis=what
	var s="<table>\n<tr><td>"
	if(what=="verbs"){
		s+="Present Indicative:</td>"
		+" <td>"
		+" <a target=_top href=index.htm?list>Spanish 111 list</a>"
		+" <a target=_top href=index.htm>Spanish 111 quiz</a>"
		+" </td><td>"
		+" <a target=_top href=index.htm?listlevel=112>Spanish 112 list</a>"
		+" <a target=_top href=index.htm?level=112>Spanish 112 quiz</a>"
		+" </td><td>"
		+" <a target=_top href=index.htm?listall>full list</a>"
		+" <a target=_top href=index.htm?listallnotable>examples</a>"
		+" </td><td bgcolor=#F0F0F0>"
		+" <a target=_top href=index.htm?listverb=??"+(ishowtypes?"&showtypes":"")+">look up a verb</a>"
		+" <a target=_top href=index.htm?listdefs>definitions</a>"
		+" </td></tr>"
		+" \n<tr><td>Past Indicative:</td>"
		+" <td>"
		+" </td><td>"
		+" <a target=_top href=indexp.htm?listlevel=112>Spanish 112 list</a>"
		+" <a target=_top href=indexp.htm?level=112>Spanish 112 quiz</a>"
		+" </td><td>"
		+" <a target=_top href=indexp.htm?listall>full list</a>"
		+" <a target=_top href=indexp.htm?listallnotable>examples</a>"
		+" </td><td bgcolor=#F0F0F0>"
		+" <a target=_top href=index.htm?listmodel=??"+(ishowtypes?"&showtypes":"")+">list a model by number</a>"
	}else if(what=="subjuntivo"){
		s+="Present Subjunctive:</td>"
		+" <td>"
		+" <a target=_top href=index.htm>quiz</a>"
		+" <a target=_top href=index.htm?listall>full list</a>"
		+" <a target=_top href=index.htm?listallnotable>examples</a>"
		+" </td><td bgcolor=#F0F0F0>"
		+" <a target=_top href=index.htm?listverb=??>look up a verb</a>"
		+" <a target=_top href=index.htm?listdefs>definitions</a>"
/*
		+" </td></tr>"
		+" \n<tr><td>Imperfect Subjunctive:</td>"
		+" <td>"
		+" </td><td>"
		+" <a target=_top href=indexp.htm?listlevel=112>Spanish 112 list</a>"
		+" <a target=_top href=indexp.htm?level=112>Spanish 112 quiz</a>"
		+" </td><td>"
		+" <a target=_top href=indexp.htm?listall>full list</a>"
		+" <a target=_top href=indexp.htm?listallnotable>examples</a>"
*/
		+" </td><td bgcolor=#F0F0F0>"
		+" <a target=_top href=index.htm?listmodel=??>list a model by number</a>"
	}else if(whatthisis=="wordpair"){
		s+=" <a target=_top href=index.htm>Spanish 111 quiz</a>"
		+" <a target=_top href=index.htm?level=112>Spanish 112 quiz</a>"
	}else if(whatthisis=="numeros"){
		s+=" <a target=_top href=index.htm?from=1,to=100>Numbers 1-100 Quiz</a>"
		+" <a target=_top href=index.htm?from=1700,to=2050>Calendar Year Quiz</a>"
		+" <a target=_top href=index.htm?addsub>Numbers 1-100 Addition and Subtraction Quiz</a>"
		+" <a target=_top href=index.htm?list>Numbers List</a>"
	}else if(whatthisis=="indirect"){
		s+=" Enter both a reflexive pronoun and the correct conjugation of the indicated verb. For example: <b>me gusta</b>"
	}else if(whatthisis=="national"){
		s+=" <a target=_top href=index.htm?value=SA>South America</a>"
		+" <a target=_top href=index.htm?value=CA>Central America</a>"
		+" <a target=_top href=index.htm?value=EU>Europe</a>"
		+" <a target=_top href=index.htm?value=AS>Asia</a>"
		+" <a target=_top href=index.htm>World</a>"
		+" <a target=_top href=index.htm?list>List All</a>"
		s+=" Enter a country name, a nationality, or a language, as appropriate."
	}else if(whatthisis=="directions"){
		s+=" <a target=_top href=http://www.guiadelmundo.com/continentes/south_america/mapa.html>Mapa de America del Sur</a>"
		+" <a target=_top href=http://www.guiadelmundo.com/continentes/central_america/mapa.html>Mapa de Centroamerica</a>"
		s+=" Answer <b>Cierto</b> or <b>Falso</b> as appropriate."

	}else if(whatthisis=="vocab"){
		s+='This is just the list of words I didn\'t recognize while reading.<p><select onchange=getvocabsource(value)><option value="-1">SELECT A SOURCE</option>'
		Vocabsourcelist.sort()
		for(var i=0;i<Vocabsourcelist.length;i++){
			s+="<option value="+i+(fuente && Vocabsourcelist[i].indexOf(fuente)>=0?" selected":"")+">"+Vocabsourcelist[i]+"</option>"
		}
		s+="</select>"
	}else if(whatthisis=="ayudar"){

	}
	s+=" </td></tr></table>"
	document.write(s)
}

function getvocabsource(n){
	n=parseInt(n+"")
	var s=(n>=0?"?fuente="+Vocabsourcelist[n]:"")
	parent.location="index.htm"+s
}

function sortm(a,b){
	if(!a.isrelevant) return -1
	if(!b.isrelevant) return 1
	var sa=(a[strtense]?a[strtense].replace(/\;/g,"a"):"")
	var sb=(b[strtense]?b[strtense].replace(/\;/g,"a"):"")
	if(sa.indexOf("~")<0 && sb.indexOf("~")>=0)return 1
	if(sa.indexOf("~")>=0 && sb.indexOf("~")<0)return -1
		if(sa.indexOf("~")>=0){
		if(sa>sb)return 1
		if(sa<sb)return -1
	}else{
		if(a.sconj>b.sconj)return 1
		if(a.sconj<b.sconj)return -1
		if(a.Vlist[0]>b.Vlist[0])return 1
		if(a.Vlist[0]<b.Vlist[0])return -1
	}
	return 0

}

function sortm2(a,b){
	return (a.n<b.n?-1:a.n>b.n?1:0)
}

function sortv(a,b){
	var sconja=Models[a[1]].sconj
	var sconjb=Models[b[1]].sconj
	if(!isalphabetical){
		if(sconja>sconjb)return 1
		if(sconja<sconjb)return -1
	}
	return(a[0]>b[0]?1:a[0]<b[0]?-1:0)
}

function sorta0(a,b){
	return(a[0]>b[0]?1:a[0]<b[0]?-1:0)
}

function strsub(ssub,ch1,ch2){
 if (ssub.length==0) return ""
 if (ch1.length==0 || ch2.length>0 && ch2.indexOf(ch1)>=0) return ssub
 var s=ssub
 var i=s.indexOf(ch1)
 while (i>=0){
  s=s.substring(0,i) + ch2 + s.substring(i+ch1.length,s.length)
  i=s.indexOf(ch1)
 }
 return s
}

function tabulatecolumns(S,ncol){
	var sout="<table>"
	var n=Math.floor(S.length/ncol-.5)
	for(var i=0;i<=n;i++){
		sout+="\n<tr>"
		for(var j=0;j<ncol;j++){
			sout+=(S[i+(n+1)*j]?S[i+(n+1)*j]:"")
		}
		sout+="</tr>"
	}
	sout+="</table>"
	return sout
}

function ucase(s,n){
	return s.substring(0,n)+s.charAt(n).toUpperCase()+s.substring(n+1,s.length)
}

function verbtypept(v){
	v=v.split("(")[0].replace(/\'/g,"")
//note:Mac version doesn't allow three parameters
	return Math.max(Math.max(v.lastIndexOf("ar"),v.lastIndexOf("er")),v.lastIndexOf("ir"))
}

var TestArray=new Array(
	 [["presind",3],["pastind",3]]
//	,[["presind",4],["pastind",4]]
	,[["presind",0],["pastind",0]]
	,[["presind",1],["pastind",1]]
	,[["presind",2],["pastind",2]]
	,[["presind",5],["pastind",5]]
	)

function testdata(verb,imodel,isnewwin){
	var sout="<table border><tr><td width=120></td><td width=120></td></tr>"
	var sline=""
	var s=""
	if(imodel<0){
		s=fixchar(verb)
	}else{
		s="["+Models[imodel].n+"]"
		if(!isnewwin)s=addlink("POPUPMODEL:"+Models[imodel].n+":"+verb,s,"red")
		s+=" "+fixchar(verb)
		var l=Models[imodel].Vlist.length
		s+=" ("+(l>1?"<a href=\"javascript:alert('"+fixchar(Models[imodel].Vlist.join(", "))+"')\">"+l+"</a>":l)+")"
	}
	sout+="<tr><th colspan=2 class=table1>"+s+"</th></tr>"

	for(var i=0;i<TestArray.length;i++){
	 sline="\n<tr>"
	 for(var j=0;j<TestArray[i].length;j++){
		settense(TestArray[i][j][0])
		sline+=getverblistcell(verb,imodel,thetense,TestArray[i][j][1])
	 }
	 sline+="</tr>"
	 sout+=sline
	}
	sout+="</table>"
	return sout
}

function showlist_alltests(){
	var verb=""
	var sout="<table><tr>"
	sout+="<td nowrap align=center valign=top>"+testdata("haber",-1,0)+"</td>"
	sout+="<td nowrap align=center valign=top>"+testdata("comer",-1,0)+"</td>"
	sout+="<td nowrap align=center valign=top>"+testdata("vivir",-1,0)+"</td>"
	for(var i=0;i<Models.length;i++){
		verb=Models[i].Vlist[0]
 		if(i%3==0)sout+="</tr><tr>"
		sout+="<td nowrap align=center valign=top>"+testdata(verb,i,0)+"</td>"
	}
	sout+="</tr></table>"
	dowrite(sout)
}
