/*
	FMP-IWP.js
	
	(c) Copyright 1999-2000 FileMaker, Inc. All rights reserved.
	
	Modification History:
	1/14/99 	KJJ	Created.
	3/16/00 	KJJ	Extensively modified for use with new js only architecture.
	8/22/00 	RES	Added css based table view support.
	8/30/00	RES	Added performScript method.
	9/15/00	RES	Don't unescape cssTableData either.
	11/2/00	RES	Make field.HandleClick always take you to edit mode, even from table view
				Fixes bug (SCR) 36378
	11/7/00	RES	Make field.HandleClick once again always take you to form view.
*/

/* IWPImg object definition */

function IWPImg()
{
	this.old		=	new Image();
	this.btnR		=	new Image();
	this.btnP		=	new Image();
	this.btnN		=	new Image();
	this.btnCR		=	new Image();
	this.btnR.src	=	"btnR_over.gif";
	this.btnP.src	=	"btnP_over.gif";
	this.btnN.src	=	"btnN_over.gif";
	this.btnCR.src	=	"btnCR_over.gif";
}

/* Animate object definition */

function Animate(color)
{
	this.img			=	new IWPImg();
	this.istyle			=	color;
		
	this.colorobj = function(obj,color)
	{
		this.istyle			=	color;
		this.color1			=	"#FFCC66";
		this.color2			=	"#333300";
		this.color3			=	"#9999CC";
		this.color4			=	"#999999";
		this.color5			=	"#FFCC66";
		this.color6			=	"#C1C185";
		this.defColor		=	"#FFFFFF";
	
		this.checkbrowser = function()
		{
			var result = true;
			if (navigator.appName.indexOf("Netscape") == -1)
			{
				if (navigator.platform.indexOf("Mac") != -1)
				{
					var vers = navigator.appVersion;
					var index = vers.indexOf("MSIE");
					if ( index == -1 )
						index = 0;
					var version = parseFloat(vers.substring(index + 4, vers.length));
					if ( version < 5.0 )
						result = false;
				}
			}
			return result;
		}

		// Find the specified rule in a style sheet
		this.findrule = function(sid,what)
		{
			for ( var i = 0; i < document.styleSheets.length; ++i )
			{
				var sh = document.styleSheets(i);
				for ( var j = 0; j < sh.rules.length; ++j )
				{
					var rl = sh.rules.item(j);
					if ( rl.selectorText == sid || rl.selectorText == ("*" + sid) )
					{
						if ( rl.style[what] != "" )
							return rl;
					}
				}
			}
			return null
		}
		
		// Invert the specified color
		this.invertcolor = function(col)
		{
			if ( col != "" && col != null )
			{
				var len = 6;
				var off = 0xFFFFFF;
				if ( col.length < 7 )
				{
					len = 3;
					off = 0xFFF;
				}
				col = "0x" + col.substring(1, col.length);
				col = Math.abs(col - off);
				col = col.toString(16).toUpperCase();
				if ( col == "NAN" )
					return "";
				while (col.length < len)
					col = "0" + col;
				col = "#" + col;
			}
			return col;
		}
		
		// Child color object
		this.childcolorobj = function(i,c)
		{
			this.index = i;
			this.color = c;
		}
		
		// Invert all colors
		this.sethighlight = function()
		{
			this.bghilitecolor = this.invertcolor(this.bgcolor);
			if ( typeof this.txtcolor != "object" )
				this.txthilitecolor = this.invertcolor(this.txtcolor);
			else
			{
				this.txthilitecolor = new this.childcolorobj(this.txtcolor.index,this.txtcolor.color)
				this.txthilitecolor.color = this.invertcolor(this.txtcolor.color);
			}
		}
		
		// Find text color
		this.findtxtcolor = function(obj)
		{
			var txtcolor = obj.style.color;
			if ( txtcolor == "" )
			{
				if ( obj.className != null && obj.className != "" )
				{
					rl = this.findrule("." + obj.className,"color");
					if ( rl != null )
						txtcolor =  rl.style.color;
				}
				else if ( obj.childNodes != null )
				{
					var cn = obj.childNodes;
					for ( var i = 0; i < cn.length; ++i )
					{
						if ( cn.item(i).style != null )
						{
							var col = cn.item(i).style.color;
							if ( col != "" )
							{
								txtcolor = new this.childcolorobj(i,col);
								break;
							}
						}
					}
				}
			}
			return txtcolor;
		}
		
		
		// Find background color
		this.findbgcolor = function(obj)
		{
			var bgcolor = obj.style.backgroundColor;
			if ( bgcolor == "" )
			{
				var rl = this.findrule("#" + obj.id,"backgroundColor");
				if ( rl != null )
				{
					bgcolor = rl.style.backgroundColor;
				}
			}
			return bgcolor;
		}
		
		this.setoldcolor = function(obj)
		{
			var ocol;
			if ( this.istyle == 1 )
				ocol = this.color1;
			else if ( this.istyle == 2 )
				ocol = this.color2;
			else if ( this.istyle == 3 )
				ocol = this.color3;
			else if ( this.istyle == 4 )
				ocol = this.color4;
			else if ( this.istyle == 6 )
				ocol = this.color5;
			else if ( this.istyle == 7 )
				ocol = this.color6;
			else
				ocol = this.defColor;
			var hcol = this.invertcolor(ocol);
			this.bghilitecolor = ocol;
			this.txthilitecolor = obj.style.color;
			if ( this.txthilitecolor != "" )
			{
				this.txthilitecolor = hcol;
			}
			else if ( obj.childNodes != null )
			{
				var cn = obj.childNodes;
				for ( var i = 0; i < cn.length; ++i )
				{
					if ( cn.item(i).style != null )
					{
						var col = cn.item(i).style.color;
						if ( col != "" )
						{
							this.txthilitecolor = new this.childcolorobj(i,hcol);
							break;
						}
					}
				}
			}
		}
		
		if ( this.checkbrowser() )
		{
			this.bgcolor = this.findbgcolor(obj);
			this.txtcolor =  this.findtxtcolor(obj);

			if ( this.bgcolor == "" && this.txtcolor == "" )
			{
				this.bgcolor = null;
				this.txtcolor = null;
				this.setoldcolor(obj);
			}
			else
			{
				if ( this.bgcolor != "" && this.txtcolor == "" )
					this.txtcolor = this.invertcolor(this.bgcolor);
				this.sethighlight();
			}
		}
		else
			this.setoldcolor(obj);
	}
	
	// set highlight color of an object
	this.on = function(obj)
	{
		if ( obj.bghilitecolor != null )
		{
			obj.style.backgroundColor = obj.bghilitecolor;
			if ( obj.txthilitecolor != null )
			{
				if ( typeof obj.txthilitecolor != "object" )
					obj.style.color = obj.txthilitecolor;
				else
					obj.childNodes.item(obj.txthilitecolor.index).style.color = obj.txthilitecolor.color;
			}
		}
		else
		{
			var col = new this.colorobj(obj,this.istyle);
			
			obj.oldbgcolor = col.bgcolor;
			iwp.debugComment("oldbgcolor",obj.oldbgcolor);
			obj.oldtxtcolor = col.txtcolor;
			iwp.debugComment("oldtxtcolor",obj.oldtxtcolor);
			obj.style.backgroundColor = obj.bghilitecolor = col.bghilitecolor;
			iwp.debugComment("bghilitecolor",obj.bghilitecolor);
			obj.txthilitecolor = col.txthilitecolor;
			if ( typeof col.txthilitecolor != "object" )
			{
				obj.style.color = col.txthilitecolor;
				iwp.debugComment("txthilitecolor",col.txthilitecolor);
			}
			else
			{
				obj.childNodes.item(col.txthilitecolor.index).style.color = col.txthilitecolor.color;
				iwp.debugComment("txthilitecolor",col.txthilitecolor.color);
			}
		}
	}
	
	// Restore original object color
	this.off = function(obj)
	{
		if ( obj != null )
		{
			if ( obj.oldbgcolor != null )
			{
				obj.style.backgroundColor = obj.oldbgcolor;
				if ( obj.oldtxtcolor != null )
				{
					if ( typeof obj.oldtxtcolor != "object" )
						obj.style.color = obj.oldtxtcolor;
					else
						obj.childNodes.item(obj.oldtxtcolor.index).style.color = obj.oldtxtcolor.color;
				}
			}
			else
			{
				obj.style.backgroundColor = "";
				if ( typeof obj.oldtxtcolor != "object" )
					obj.style.color = "";
				else
					obj.childNodes.item(obj.oldtxtcolor.index).style.color = "";
			}
		}
	}
	
	// Swap image source
	this.swap = function(name)
	{
		var obj = document[name];
		if ( obj != null )
		{
			this.img.old.src = document[name].src;
			obj.src = this.img[name].src;
		}
	}

	// Restore image source
	this.restore = function(name)
	{
		var obj = document[name];
		if ( obj != null )
			obj.src = this.img.old.src;
	}
}

/* RangeObj object definition */

function RangeObj(obj)
{
	this.delim		=	"-";
	this.eName		=	"range";
	this.jdelim		=	"%u30FC";
	this.max		=	"-max";
	this.skip		=	"-skip";
	if ( obj != null )
	{
		this.icount		=	parseInt(obj.count);
		this.ifound		=	parseInt(obj.found);
		this.imax		=	parseInt(obj.max);
		this.irecnum	=	parseInt(obj.recnum);
		this.iskip		=	parseInt(obj.skip);
	}
	
	// Update range value
	this.update = function(input,wantRange)
	{
		if ( input != null && input.elements.length > 0 )
		{
			if ( wantRange == true )
			{
				beg = this.iskip + 1;
				if ( this.icount < beg )
					beg = this.icount;
				end = this.imax + this.iskip;
				if ( this.icount < end )
					end = this.icount;
				if ( this.ifound < (end - beg + 1) )
					end = beg + this.ifound - 1;
				input.elements[this.eName].value = beg + this.delim + end;
			}
			else
				input.elements[this.eName].value = this.irecnum;
		}
	}
	
	// Find selected range
	this.show = function(form,input,isRange)
	{
		if ( form != null && input != null && isRange != null )
		{
			var gerpy = 1;
			if (isRange == true )
			{
				if (document.charset == "shift_jis")
				{
					segments = escape(input.elements[this.eName].value);
					if ( segments.indexOf(this.jdelim) > -1 )
						segments = segments.split(this.jdelim);
					else
						segments = segments.split(this.delim);
					for ( var i = 0; i < segments.length; ++i )
						segments[i] = this.normalize(unescape(segments[i]));
				}
				else
					segments = input.elements[this.eName].value.split(this.delim);
				if ( parseInt(segments[0]).toString() != "NaN" )
				{
					var skip = Math.max(0, segments[0] - 1);
					var cnt = Math.max(1, this.icount - 1);
					if ( skip > cnt ) skip = cnt;
				
				//	RES Fix #38095 make sure min of 1
					if (form.elements[this.skip] != null)
						form.elements[this.skip].value = Math.max(0, skip);
					if ( parseInt(segments[1]).toString() != "NaN" )
						gerpy = segments[1] - skip;
					if ( gerpy > 0 )
					{
						if ( gerpy > ++cnt ) gerpy = cnt;
					
					//	RES Fix #38095 make sure min of 1
						if (form.elements[this.max] != null)
							form.elements[this.max].value = Math.max(1, gerpy);
						iwp.addurldata(form);
						form.submit();
					}
					else
						this.update(input,true);
				}
				else
					this.update(input,true);
			}
			else
			{
				gerpy = this.normalize(input.elements[this.eName].value);
				if ( parseInt(gerpy).toString() != "NaN" )
				{
					gerpy = parseInt(gerpy) - 1;
					if ( gerpy >= 0 )
					{
						var cnt = this.icount - 1;
						if ( gerpy > cnt ) gerpy = cnt;
						form.elements[this.skip].value = Math.max(0, gerpy);
						form.elements[this.max].value = 1;
						iwp.addurldata(form);
						form.submit();
					}
					else
						this.update(input,false);
				}
				else
					this.update(input,false);
			}
		}
		return false;
	}
	
	// Normalize J number
	this.normalize = function(str)
	{
		var newStr = "";
		if ( str != null )
		{
			if (document.charset == "shift_jis")
			{
				str = escape(str);
				for ( var i = 0; i < str.length; i++ )
				{
					if 	( (i != str.length - 1) && (str.charAt(i) == "%") )
					{
						newStr += this.convertJ(str.substring(i, i + 6));
						i += 5;
					}
					else
						newStr += str.charAt(i);
				}
			}
			else
				newStr = str;
		}
		return newStr;
	}

	// Convert J number
	this.convertJ = function(num)
	{
		if (num == "%uFF10")
			return "0";
		else if (num == "%uFF11")
			return "1";
		else if (num == "%uFF12")
			return "2";
		else if (num == "%uFF13")
			return "3";
		else if (num == "%uFF14")
			return "4";
		else if (num == "%uFF15")
			return "5";
		else if (num == "%uFF16")
			return "6";
		else if (num == "%uFF17")
			return "7";
		else if (num == "%uFF18")
			return "8";
		else if (num == "%uFF19")
			return "9";
		else
			return "0";
	}
}

/* IWPHelp object definition */

function IWPHelp()
{
	this.delrec		=	"deleting";
	this.edit		=	"editing";
	this.form		=	"form";
	this.newrec		=	"adding";
	this.search		=	"searching";
	this.sort		=	"sorting";
	this.table		=	"table";
	this.fhelp		=	"~HelpCSS.htm#";
}


/* IWPConst object definition */

function IWPConst()
{
	this.css				=	"css.htm";
	this.db					=	"-db";
	this.del				=	"-delete";
	this.edit				=	"-edit";
	this.find				=	"-find";
	this.findall			=	"-findall";
	this.format				=	"-format";
	this.iwpdata			=	"-iwpdata";
	this.layid				=	"-layid";
	this.lop				=	"-lop";
	this.max				=	"-max";
	this.mode				=	"-mode";
	this.mshack				=	"-mshack";
	this.newrec				=	"-new";
	this.op					=	"-op";
	this.id					=	"-recid";
	this.skip				=	"-skip";
	this.sortfld			=	"-sortfield";
	this.sortord			=	"-sortorder";
	this.tok0				=	"-token.0";
	this.tok1				=	"-token.1";
	this.tok2				=	"-token.2";
	this.txt				=	"txt.htm";
	this.view				=	"-view";
	this.cdel				=	"delete";
	this.cedit				=	"edit";
	this.cform				=	"formvw";
	this.fmp				=	"FMPro?";
	this.fmpjs				=	"FMPJS?";
	this.cnew				=	"new";
	this.csearch			=	"search";
	this.csort				=	"sort";
	this.csort2				=	"sort2";
	this.ctable				=	"tablevw";
	this.home				=	"/";
	this.one				=	"1";
	this.sreq				=	"sort";
	this.freq				=	"find";
	this.modetable			=	"table";
	this.modesrch			=	"search";
	this.modesort			=	"sort";
	this.modeedit			=	"edit";
	this.modeform			=	"browse";
	this.modenew			=	"new";
	this.dash				=	"-";
}

/* IWPLinks object definition */

function IWPLinks()
{
	var c = iwp.con;
	var n = iwp.nav;
	if ( c != null && n != null )
	{
		var db = n.db.url;
		var type = c.css;
		if ( iwp.textonly )
			type = c.txt;
		c.fdel		=	c.cdel + type;
		c.fedit		=	c.cedit + type;
		c.fform		=	c.cform + type;
		c.fnew		=	c.cnew + type;
		c.fsearch	=	c.csearch + type;
		c.fsort		=	c.csort + type;
		c.fsort2	=	c.csort2 + type;
		c.ftable	=	c.ctable + type;
		this.current	=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,n.format,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,n.mode,c.sreq,c.freq,c.lop,n.lop,c.dash + n.action);
		this.delrec		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fdel,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.tok2,n.id,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.delrec2	=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fform,c.max,n.max,c.tok0,n.tok0,c.tok1,n.tok1,c.id,n.tok2,c.mode,c.modeform,c.sreq,c.freq,c.lop,n.lop,c.del);
		this.edit		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fedit,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modeedit,c.id,n.id,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.findall	=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,n.format,c.max,n.max,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,n.mode,c.sreq,c.findall);
		this.findall2	=	new Array(c.fmpjs,c.db,db,c.layid,n.tableid,c.format,c.ftable,c.max,n.tokmax,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modetable,c.sreq,c.findall);
		this.first		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,n.format,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,n.mode,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.form		=	new Array(c.fmpjs,c.db,db,c.layid,n.formid,c.format,c.fform,c.max,c.one,c.skip,n.skip,c.tok0,n.tokmax,c.tok1,n.tok1,c.mode,c.modeform,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.home		=	new Array(c.home);
		this.last		=	this.first;
		this.newrec		=	new Array(c.fmpjs,c.db,db,c.layid,n.formid,c.format,c.fnew,c.max,n.max,c.skip,n.skip,c.tok0,n.tokmax,c.tok1,n.tok1,c.mode,c.modenew,c.sreq,c.freq,c.lop,n.lop,c.view);
		this.next		=	this.first;
		this.previous	=	this.first;
		this.reclink	=	new Array(c.fmpjs,c.db,db,c.layid,n.formid,c.format,c.fform,c.max,c.one,c.skip,n.skip,c.tok0,n.max,c.tok1,n.tok1,c.mode,c.modeform,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.refresh	=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fform,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modeform,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.search		=	new Array(c.fmpjs,c.db,db,c.layid,n.searchid,c.format,c.fsearch,c.max,n.max,c.skip,n.skip,c.tok0,n.tokmax,c.tok1,n.tok1,c.mode,c.modesrch,c.sreq,c.freq,c.lop,n.lop,c.view);
		this.sort		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fsort,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modesort,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.sort2		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.fsort2,c.max,n.max,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modesort,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.table		=	new Array(c.fmpjs,c.db,db,c.layid,n.tableid,c.format,c.ftable,c.max,n.tokmax,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modetable,c.sreq,c.freq,c.lop,n.lop,c.find);
		this.table2		=	new Array(c.fmpjs,c.db,db,c.layid,n.layid,c.format,c.ftable,c.max,n.tokmax,c.skip,n.skip,c.tok0,n.tok0,c.tok1,n.tok1,c.mode,c.modetable,c.sreq,c.freq,c.lop,n.lop,c.find);
	}
}

// Create error strings
function IWPErrors()
{
	// Insert components into text string
	this.paramtext = function(dest,c1,c2)
	{		
		var output = "";
		if ( dest != null )
		{
			output += this.replaceparm(dest,c1,1);
			output += this.replaceparm(dest,c2,2);
		}
		return output;
	}
	
	this.replaceparm = function(dest,src,i)
	{
		var index = dest.indexOf("^" + i);
		if ( index > -1 )
		{
			if ( src == null )
				src = "";
			return ( dest.substring(0, index) + src + dest.substring(index + 2, dest.length) );						
		}
		else
			return "";
	}
	var iwp = window.iwp;
	if ( iwp != null )
	{
		var nav = window.iwp.nav;
		var c = window.iwp.errstrings;
		if ( nav != null && c != null )
		{
			this.e5		= c.err5;
			this.e10	= c.err10;
			this.e100	= this.paramtext( c.err100, nav.db.none );
			this.e101	= c.err101;
			this.e105	= this.paramtext ( c.err105, (nav.lay.none == "") ? nav.layid : nav.lay.none );
			this.e200	= this.paramtext ( c.err200, nav.laction );
			this.e301	= this.paramtext ( c.err301, (nav.action == "delete") ? c.err301a : c.err301b );
			this.e401	= ( (nav.count == 0) ? c.err401a : c.err401b ) + this.paramtext( (nav.count == 0) ? c.err401c : c.err401d, nav.db.none );
			this.e509	= this.paramtext ( c.err509, nav.errfld );
			this.e950	= c.err950;
			this.eEntry	= this.paramtext ( c.errEntry, (nav.action == "new") ? c.errEntry1 : c.errEntry2 );
			this.e500	= this.Entry + this.paramtext ( c.err500, nav.errfld );
			this.e501	= this.Entry + this.paramtext ( c.err501, nav.errfld );
			this.e502	= this.Entry + this.paramtext ( c.err502, nav.errfld );
			this.e503	= this.Entry + this.paramtext ( c.err503, nav.errfld );
			this.e504	= this.Entry + this.paramtext ( c.err504, nav.errfld );
			this.e505	= this.Entry + this.paramtext ( c.err505, nav.errfld );
			this.e506	= this.Entry + this.paramtext ( c.err506, nav.errfld );
			this.e506	= this.Entry + this.paramtext ( c.err506, nav.errfld );
			this.e507	= this.Entry + this.paramtext ( c.err507, nav.errfld );
			this.e510	= c.err510;
			this.e953	= this.Entry + this.paramtext ( c.err953, nav.errfld, nav.errlay );
			this.e1000	= c.err1000;
			this.def	= this.paramtext ( c.errDefault, nav.err );
		}
	}
}

/* IWPObj object definition */

function IWPObj()
{
	// Display alert only if in debug mode.
	this.debugAlert = function(txt)
	{
		if( this.debug == true )
			alert(txt);
	}

	// Display comment if in debug mode.
	this.debugComment = function(comment,output)
	{
		if ( comment != null )
			this.debugAlert(comment + ' = "' + output + '"');
	}

	// Write out the specified data an display if in debug mode
	this.writeit = function(comment,output)
	{
		this.debugComment(comment,output);
		if ( output != null && ! this.redir && ! this.nav.err  )
			document.write(output);
	}
	
	// Draw appropriate curve image
	this.drawcurve = function()
	{
		if ( this.nav != null && ! this.redir )
		{
			var style = this.nav.style;
			if ( style > 1 && style < 5 )
			{ // 4=Neutral.css, 3=Purple.css, 2=Wheat.css
				var img, gif;
				if ( style == 2 )		{ img = "3"; gif = "W"; }
				else if ( style == 3 )	{ img = "2"; gif = "P"; }
				else					{ img = "1"; gif = "N"; }
				var output = '<DIV ID="Img' + img + '"><IMG SRC="curve' + gif +
							'1.gif" WIDTH="132" HEIGHT="70" BORDER="0" HSPACE="0" VSPACE="0"></DIV>';
				this.writeit("drawcurve",output);
			}
		}
	}
	
	// Draw appropriate image buttons
	this.drawbuttons = function(isRange)
	{
		if ( this.nav != null && ! this.redir )
		{
			var style = this.nav.style;
			if ( style > 0 && style < 5 )
			{ // 4=Neutral.css, 3=Purple.css, 2=Wheat.css, 1=Classic.css
				var output = "";
				if ( style == 1 )
					output = '<DIV ID="BtnCR1"><IMG SRC="btnCR_up.gif" NAME="btnCR" WIDTH="23" HEIGHT="16" BORDER="0" HSPACE="0" VSPACE="0" ONCLICK="range.show(rangeForm,rangeInput,' + isRange + ')" ONMOUSEOVER="anim.swap(\'btnCR\')" ONMOUSEOUT="anim.restore(\'btnCR\')"></DIV>';
				else
					output = '<DIV ID="BtnR1"><IMG SRC="btnR_up.gif" NAME="btnR" WIDTH="15" HEIGHT="15" BORDER="0" HSPACE="0" VSPACE="0" ONCLICK="range.show(rangeForm,rangeInput,' + isRange + ')" ONMOUSEOVER="anim.swap(\'btnR\')" ONMOUSEOUT="anim.restore(\'btnR\')"></DIV>';
					
				output += '<DIV ID="BtnP1" CLASS="BtnStyle1" ONCLICK="iwp.go(\'previous\')"><IMG SRC="btnP_up.gif" NAME="btnP" WIDTH="15" HEIGHT="15" BORDER="0" HSPACE="0" VSPACE="0" ONMOUSEOVER="anim.swap(\'btnP\')" ONMOUSEOUT="anim.restore(\'btnP\')"></DIV>' +
							'<DIV ID="BtnN1" CLASS="BtnStyle1" ONCLICK="iwp.go(\'next\')"><IMG SRC="btnN_up.gif" NAME="btnN" WIDTH="15" HEIGHT="15" BORDER="0" HSPACE="0" VSPACE="0"  ONMOUSEOVER="anim.swap(\'btnN\')" ONMOUSEOUT="anim.restore(\'btnN\')"></DIV>';
				this.writeit("drawbuttons",output);
			}
		}
	}
	
	// Write out the specified data to a new window
	this.dump = function(slotName) 
	{
		if ( slotName != null )
		{
			var newWindow = window.open();
			newWindow.document.write('iwp.' + slotName + ' = ' + '<TEXTAREA ROWS=50 COLS=100>' + (this[slotName]) + '</TEXTAREA>');
		}
	}			

	// Array of search values
	this.searchvals = function()
	{
		this.lt			= new Object();
		this.lt.none	= "<";
		this.lt.html	= "&lt;";
		this.lte		= new Object();
		this.lte.none	= "<=";
		this.lte.html	= "&lt;=";
		this.gt			= new Object();
		this.gt.none	= ">";
		this.gt.html	= "&gt;";
		this.gte		= new Object();
		this.gte.none	= ">=";
		this.gte.html	= "&gt;=";
		this.equ		= new Object();
		this.equ.none	= "=";
		this.equ.html	= this.equ.none;
		this.rng		= new Object();
		this.rng.none	= "...";
		this.rng.re		= "\\.\\.\\.";
		this.rng.html	= this.rng.none;
		this.dup		= new Object();
		this.dup.none	= "!";
		this.dup.html	= this.dup.none;
		this.td			= new Object();
		this.td.none	= "//";
		this.td.re		= "\\/\\/";
		this.td.html	= this.td.none;
		this.inv		= new Object();
		this.inv.none	= "?";
		this.inv.re		= "\\?";
		this.inv.html	= this.inv.none;
		this.ch			= new Object();
		this.ch.none	= "@";
		this.ch.html	= this.ch.none;
		this.wld		= new Object();
		this.wld.none	= "*";
		this.wld.re		= "\\*";
		this.wld.html	= this.wld.none;
		this.ltr		= new Object();
		this.ltr.none	= '"';
		this.ltr.html	= this.ltr.none;
		this.ex			= new Object();
		this.ex.none	= "==";
		this.ex.html	= this.ex.none;
	}

	// Handle onFocus event for a field
	this.handleFocus = function(field)
	{
		//field.rect = {top, left, bottom, right}
		if ( ( field != null) && ( document.all.SearchMenu != null ) )
		{
			var menu = document.all.SearchMenu.style;
			//menu.left = field.rect.left;
			menu.left = field.rect.right;
			//menu.top = field.rect.bottom;
			menu.top = field.rect.top;
			menu.visibility = "visible";
			field.focusFlag = true;
		}
	}
	
	// Handle onBlur event for a field
	this.handleBlur = function(field) 
	{
		if ( field != null )
		{
			var oldval = field.value;
			if ( this.curval != null )
			{
				if ( this.svals == null )
					this.svals = new this.searchvals();
				if ( this.curval == "ltr" )
					field.value = this.svals[this.curval].none + field.value + this.svals[this.curval].none;
				else if ( this.curval == "rng" )
					field.value = field.value + this.svals[this.curval].none;
				else
					field.value = this.svals[this.curval].none + " " + field.value;
				this.curval = null;
				field.focus();
			}
			else
				field.focusFlag = null;
			if ( this.validatesymbols(field) == false )
			{
				if ( field.value == oldval )
					field.value = "";
				else
					field.value = oldval;
			}
			if ( document.all.SearchMenu != null )
				document.all.SearchMenu.style.visibility = "hidden";
		}
	}
	
	this.validatesymbols = function(field)
	{
		if ( this.svals != null && field != null )
		{
			var matches, re;
			var count = new Array();
			var total = 0;
			if ( field.lastval != field.value )
			{
				field.lastval = field.value;
				for ( var i in this.svals )
				{
					if ( this.svals[i].re != null )
						re = new RegExp(this.svals[i].re,"g");
					else
						re = new RegExp(this.svals[i].none,"g");
					matches = field.value.match(re);
					if ( matches != null )
					{
						if ( i == "ltr" )
							count[i] = (matches.length/2);
						else
							count[i] = matches.length;
					}
					else
						count[i] = 0;
					total += count[i];
				}
				// Adjust for duplicate chars
				total -= count["lte"] * 2;
				total -= count["gte"] * 2;
				total -= count["ex"] * 2;
				if ( total > 1 )
					return this.checkerrs(1000,true);
			}
		}
		return true;
	}
	
	// Toggle the menu visibility
	this.toggleMenu = function(field)
	{
		if ( document.all.SearchMenu != null )
		{
			if ( field.focusFlag != null )
			{
				var st = document.all.SearchMenu.style;
				if ( st.visibility == "hidden" )
					st.visibility = "visible";
				else if ( ! field.focusFlag )
					st.visibility = "hidden";
				field.focusFlag = false;
			}
		}
	}
	
	this.menusym = function(what)
	{
		var result = "";
		if ( what != null )
		{
			if ( this.svals == null )
				this.svals = new this.searchvals();
			result = this.svals[what].html;
			if ( what == "ltr" )
				result += result;
		}
		return result;
	}
	
	// Set the value and highlight the object;
	this.select = function(obj,val)
	{
		if ( obj != null )
		{
			obj.style.backgroundColor = "#333";
			if ( obj.childNodes != null )
			{
				var nodes = obj.childNodes;
				for ( var i = 0; i < nodes.length; ++i )
				{
					if ( nodes.item(i).style != null )
						nodes.item(i).style.color = "#FFF";
				}
			}
			this.curval = val;
		}
	}
			
	// Clear the value and unhighlight the object;
	this.unselect = function(obj)
	{
		if ( obj != null )
		{
			obj.style.backgroundColor = "#CCC";
			if ( obj.childNodes != null )
			{
				var nodes = obj.childNodes;
				for ( var i = 0; i < nodes.length; ++i )
				{
					if ( nodes.item(i).style != null )
						nodes.item(i).style.color = "#000";
				}
			}
			this.curval = null;
		}
	}

	//field.rect = {top, left, bottom, right}
	
	// Handle onClick event for a field
	this.handleClick = function(field)
	{
		var nav = this.nav
		if ( field != null && nav != null )
		{
			this.nav.skip += field.recordNumber;
			if ( this.nav.mode == "table" )
				this.go('form');
			else
				this.go('edit');
		}
		return false;
	}
	
	// Handle MouseOver event for a field
	this.handleMouseOver = function(field)
	{
		window.status = "handleMouseOver";
		if ( ( field != null) )
		{
			if (this.debug == true)
			{
				window.status = "handleMouseOver " + field.fieldName;
			}
		}
	}
	
	// Handle MouseOut event for a field
	this.handleMouseOut = function(field)
	{
		if ( ( field != null) )
		{
			if (this.debug == true)
			{
				window.status = "handleMouseOut " + field.fieldName;
			}
		}
	}
		
	/*	Perform a multi step script.  Only 3 steps are supported.  See ScriptDictionary::ParseScript for
		source.
		
		scriptState = {prompt: iwp.getGotoRecordNumber(), mode: <'edit'|'sort'|'find'>, 
		layout: escape(layoutName), recordNumber: <n>, action: <'findall'|'iwp.submitedit()'>}
	
		Algorithm:
		
		1. Any info should be filled in from the mode, layout, or record number (only if this
		hasn't been set by the prompt).  

		2. If there's a prompt it should get called to get info from the user.  At present 
		the only one being used is for getting the record number for goto record number.

		3. If there's an action, call it, otherwise a refresh should
		result in the new state being established.

		The action allows you to submit a find request or submit a modified record, then go to some result
		screen.
	*/
	this.performScript = function(ss)
	{
		if ( ss != null && this.checkprivs(ss.mode) )
		{
			var cont = true;
			var tmp = null;
			if (ss.prompt != null && ss.prompt != "" )
			{
				this.debugComment("ss.prompt",ss.prompt);
				cont = eval(ss.prompt);
			}
			else if (ss.recordNumber != null && ss.recordNumber != "" )
			{
				this.debugComment("ss.recordNumber",ss.recordNumber);
				if ( ! iwp.setskip(ss.recordNumber) )
					tmp = ss.recordNumber - 1;
			}
			if ( cont )
			{
				if ( tmp != null )
					this.updateparam("skip",tmp);
				if ( ss.layout != null && ss.layout != "" )
				{
					this.debugComment("ss.layout",ss.layout);
					this.updateparam("layid",ss.layout);
					this.updateparam("tok1",ss.layout);
				}
				if ( ss.mode != null && ss.mode != "" )
				{
					this.debugComment("ss.mode",ss.mode);
					this.setmode(ss.mode);
				}
				if ( ss.action != null && ss.action != "" )
				{
					this.debugComment("ss.action",ss.action);
					eval(ss.action);
				}
				else
				{
					if ( ss.mode != null && ss.mode == "sort2" )
						this.opensort2();
					else
						iwp.go( "current" );
				}
			}
		}
	}
	
	this.findall = function()
	{
		this.go("findall");
	}
	
	this.delrec = function(wantDialog)
	{
		var nav = this.nav;
		if ( nav != null )
		{
			if ( this.checkprivs("delete") )
			{
				if ( wantDialog )
					this.go("delrec");
				else
				{
					nav.tok2 = nav.id;
					this.go("delrec2");
				}
			}
		}
	}

	// Updates a parameter in a form and iwp.nav
	this.updateparam = function(code,val)
	{
		if ( code != null )
		{
			this.debugComment("updateparam code",code);
			this.debugComment("updateparam value",val);
			if ( this.nav != null )
				this.nav[code] = val;
			var oForm = document.IWPForm;
			this.debugComment("oForm",oForm);
			if ( oForm != null )
			{
				var con = this.con[code];
				this.debugComment("con",con);
				if ( con != null )
				{
					var elem = oForm.elements[con];
					this.debugComment("elem",elem);
					if ( elem != null )
					{
						elem.value = val;
						this.debugComment("elem.value set",elem.value);
					}
				}
			}
		}
	}
	
	// Sets the mode and format file
	this.setmode = function(mode)
	{
		var nav = this.nav
		if ( mode != null && nav != null )
		{
			if ( mode == "cycle" )
			{
				if ( nav.mode == "browse" )
					mode = "table";
				else if ( nav.mode == "table" )
					mode = "browse";
				else
					return;
			}
			nav.oldmode = nav.mode;
			this.updateparam("mode",mode);
			this.updateparam("max","1");
			if ( mode == "new" )
				this.updateparam("format","newcss.htm");
			else if ( mode == "table" )
			{
				this.updateparam("format","tablevwcss.htm");
				this.updateparam("max",nav.tok0);
			}
			else if ( mode == "search" )
			{
				// Set layout to form layout in blank style if no layout specified
				if ( ( nav.layid == "" || nav.layid == 255 ) && nav.style == 9 )
					nav.layid = nav.formid;
				this.updateparam("format","searchcss.htm");
			}
			else if ( mode == "sort" )
				this.updateparam("format","sort2css.htm");
			else if ( mode == "edit" )
				this.updateparam("format","editcss.htm");
			else if ( mode == "browse" )
			{
				// Begin - Special case for bug 38364
				var con = this.con;
				if ( ( con.dash + nav.action ) == con.view )
					nav.action = "find";
				// End - Special case for bug 38364
				this.updateparam("format","formvwcss.htm");
			}
		}
	}
	
	this.checkprivs = function(mode)
	{
		var allowed = true;
		var nav = iwp.nav;
		if ( mode != null && nav != null )
		{
			if (	( ! nav.cannew && mode == "new" ) ||
					( ! nav.canedit && mode == "edit" ) ||
					( ! nav.candelete && mode == "delete" ) )
			{
				var oldact = nav.laction;
				if ( this.strings != null && this.errstrings != null )
				{
					if ( mode == "new" )
						nav.laction = this.errstrings.errEntry1;
					else if ( mode == "sort" || mode == "sort2" )
						nav.laction = this.strings.sort;
					else if ( mode == "edit" )
						nav.laction = this.errstrings.err301b;
					else if ( mode == "delete" )
						nav.laction = this.errstrings.err301a;
					else
						nav.laction = "";
				}
				else
					nav.laction = "";
				this.checkerrs(200);
				nav.laction = oldact;
				allowed = false;
			}
			else if ( ! nav.cansort && (mode == "sort" || mode == "sort2" ) )
				allowed = false;
			// Begin - Special case for bug 38365
			else if ( nav.mode == "new" && mode == "delete" )
				allowed = false;
			// End - Special case for bug 38365
		}
		return allowed;
	}
	
	//	Hide, show, or toggle the status area
	this.changeStatusArea = function(code)
	{
		if (this.debug == true)
		{
			window.status("changeStatusArea");
		}
		if (code != null) 
		{
			if (code == 'hide')
			{
			}
			else if (code == 'show')
			{
			}
			else if (code == 'toggle')
			{
			}
		}
	}
	
	// Check for compatable browser
	//		this.client.platform: 0 = Mac, 1 = Win, 2 = other
	//		this.client.browser: 0 = IE, 1 = Netscape, 2 = other
	//		this.client.version: browser version
	this.check = function()
	{
		this.debugAlert("Navigator values: appVersion = " + navigator.appVersion + ", appName = " + navigator.appName + ", platform = " + navigator.platform);
		var client = this.client;
		if (navigator.platform.indexOf("Mac") != -1)
			client.platform = 0;
		else if (navigator.platform.indexOf("Win") != -1)
			client.platform = 1;
		else
			client.platform = 2;
		client.version = parseFloat(navigator.appVersion);
		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			client.browser = 0;
			var vers = navigator.appVersion;
			var index = vers.indexOf("MSIE");
			if ( index == -1 )
				index = 0;
			client.version = parseFloat(vers.substring(index + 4, vers.length));
			if ( client.version < 4.0 && ! this.textonly )
			{
				this.debugAlert("Wrong browser - redirecting");
				this.redir = true;
				this.setformat( client.version < 3.0 );
			}
		}
		else if (navigator.appName.indexOf("Netscape") != -1)
		{
			client.browser = 1;
			if ( client.version < 5.0 && ! this.textonly )
			{
				this.debugAlert("Wrong browser - redirecting");
				this.redir = true;
				this.setformat( client.version < 3.0 );
			}
		}
		else
			client.browser = 2;
		this.debugAlert("Client values: version = " + this.client.version + ", browser = " + this.client.browser + ", platform = " + this.client.platform);
	}
	
	this.setformat = function(isClassic)
	{
		var n = this.nav;
		var c = this.con;
		if ( n != null && c != null )
		{
			var suff = c.txt;
			if ( isClassic )
				suff = ".htm";
			var file = n.format;
			if ( file.indexOf(c.cdel) != -1 )
				n.format = c.cdel + suff;
			else if ( file.indexOf(c.cedit) != -1 )
				n.format = c.cedit + suff;
			else if ( file.indexOf(c.cform) != -1 )
				n.format = c.cform + suff;
			else if ( file.indexOf(c.cnew) != -1 )
				n.format = c.cnew + suff;
			else if ( file.indexOf(c.csearch) != -1 )
				n.format = c.csearch + suff;
			else if ( file.indexOf(c.csort) != -1 )
				n.format = c.csort + suff;
			else if ( file.indexOf(c.ctable) != -1 )
				n.format = c.ctable + suff;
		}
	}

	// Go to another layout
	this.gotolay = function(lay)
	{
		if ( lay != null )
		{
			this.nav.tok1 = lay;
			this.nav.formid = this.nav.tok1;
			var url = this.build("form");
			window.location=url;
		}
	}

	// Build url
	this.build = function(code)
	{
		this.debugComment("build code",code);
		if ( code != null )
		{
			var url		= "";
			var links	=	new IWPLinks();
			this.debugComment("build links",links);
			if ( code == this.ctoggle )
			{
				if ( this.nav.format.toLowerCase().indexOf(this.ohelp.table) > -1 )
					key = links[this.ohelp.form];
				else
					key = links[this.ohelp.table];
			}
			else
				key = links[code];
			url += key[0];
			for ( var i = 1; i < key.length; ++i )
			{
				if ( key[i] == this.con.sreq )
				{
					for ( var j in this.nav[key[i]] )
					{
						url += this.con.sortfld + this.equ + this.nav[key[i]][j].name.url + this.amp;
						url += this.con.sortord + this.equ + this.nav[key[i]][j].order.url + this.amp;
					}
				}
				else if ( key[i] == this.con.freq )
				{
					for ( var j in this.nav[key[i]] )
					{
						url += this.con.op + this.equ + this.nav[key[i]][j].op + this.amp;
						url += this.nav[key[i]][j].name.url + this.equ + this.nav[key[i]][j].value.url + this.amp;
					}
				}
				else
				{
					var name = key[i++];
					var value = key[i];
					if (  i < key.length && value != "" )
						url += name + this.equ + value + this.amp;
					else if ( i == key.length )
						url += name;
				}
			}
			return url;
		}
	}

	// Calculates the correct skip value
	this.setskip = function(code)
	{
		var nav = this.nav;
		if ( code != null && nav != null )
		{
			var tmp = null;
			var rng = window.range;
			if (code == this.cfirst)
				tmp = 0;
			else if (code == this.clast)
			{
				if ( rng.imax < rng.icount )
					tmp = rng.icount - rng.imax;
			}
			else if (code == this.cprev)
			{
				tmp = rng.iskip - rng.imax;
				if ( tmp < 0 )
					tmp = 0;
			}
			else if (code == this.cnext)
			{
				tmp = rng.iskip;
				if ( rng.iskip + rng.imax < rng.icount )
					tmp += rng.imax;
			}
			else if( nav.action == "new" )
				tmp = nav.count;
			if ( tmp != null )
			{
				nav.skip = tmp;
				return true;
			}
		}
		return false;
	}
	
	// Set window location
	this.go = function(code,skip,win)
	{
		var nav = this.nav;
		if ( code != null && nav != null )
		{
			if ( skip != null )
				nav.skip = skip;
			this.setskip(code);
			if ( nav.tok1 != "" )
				//nav.layf.url = nav.tok1;
				nav.formid = nav.tok1;
			if ( nav.mode == this.con.modetable && code == "findall" )
				nav.max = this.defmax;
			var url = this.build(code);
			if ( url != "" )
			{
				this.debugComment("url",url);
				if ( win != null )
					win.location = url;
				else
					window.location = url;
			}
		}
	}
	
	// Set search layout to form layout in blank style if no layout specified
	this.gotosearch = function()
	{
		var nav = this.nav;
		if ( nav != null )
		{
			if ( ( nav.searchid == "" || nav.searchid == 255 ) && nav.style == 9 )
				nav.searchid = nav.formid;
			this.go("search");
		}
	}
	
	// Calculates the correct record number
	this.calcrecnum = function(num)
	{
		var nav = this.nav;
		if ( num != null && nav != null )
		{
			--num;
			if ( num > (nav.count - 1) )
				num = nav.count - 1;
			else if ( num < 0 )
				num = 0;
			return num;
		}
		else
			return null;
	}
	
	// Go to a record by number
	this.gotoRecordNumber = function(num)
	{
		var nav = this.nav;
		if ( num != null && nav != null )
		{
			//	build the default url
			num = this.calcrecnum(num);
			if ( num != null )
			{
				nav.skip = num;
				window.location = this.build(this.cfirst);
			}
		}
	}

	// Go to a record by number
	this.gotoRecordNumberWithPrompt = function(number)
	{
		var nav = this.nav;
		var str = this.strings;
		if ( number != null && nav != null && str != null )
		{
			//	get the number from the user
			var num = prompt(str.gotoRec, number);
			num = this.calcrecnum(num);
			if ( num != null )
			{
				nav.skip = num;
				window.location = this.build(this.cfirst);
				return true;
			}
		}
	}
	
	// Get record number to go to from user
	this.getGotoRecordNumber = function(number)
	{
		var nav = this.nav;
		var str = this.strings;
		if ( number != null && nav != null && str != null )
		{
			//	get the number from the user
			var num = prompt(str.gotoRec, number);
			num = this.calcrecnum(num);
			if ( num != null )
			{
				nav.skip = num;
				return true;
			}
		}
		return false;
	}

	// Go to one of the sort views depending on style
	this.gotosort = function()
	{
		if ( this.nav != null && this.checkprivs("sort") )
		{
			if ( this.nav.style == 9 ) // Blank style
				this.opensort2();
			else
				this.go("sort");
		}
	}
	
	// Opens blank style sort window
	this.opensort2 = function()
	{
		var win = window.open("","IWPSort","alwaysraised=yes,top=20,left=20,height=265,width=502,location=no,menubar=no,directories=no,resizable=no,scrollbars=no,status=no,toolbar=no,titlebar=no");
		this.go("sort2",null,win);
	}

	// Open help window
	this.help = function(code)
	{
		if ( code != null )
		{
			var anchor = this.ohelp[code];
			var url = this.local(this.ohelp.fhelp);
			win = window.open("","IWPHelp","top=20,left=20,height=460,width=620,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,");
			win.location = url + anchor;
		}
	}

	// Insert language char
	this.local = function(str)
	{
		var result = "";
		if ( str != null )
		{
			if ( str.indexOf(this.delim) > -1 )
			{
				segments = str.split(this.delim);
				if ( segments[0] != "" )
					result = segments[0];
				for( i = 1; i < segments.length; ++i )
					result += this.nav.lang + segments[i];
			}
			else
				result = str;
		}
		return result;
	}

	// Submit form
	this.submit = function()
	{
		oForm = document.IWPForm;
		if ( oForm != null )
		{
			if( this.addurldata(oForm) )
				oForm.submit();
		}
		return false;
	}
	
	this.addurldata = function(oForm)
	{
		var result = false;
		if ( oForm != null )
		{
			var theAction = "FMPJS?";
			var fel = oForm.elements;
			var noedit = false;
			var mode = this.nav.mode;
			if ( this.nav.oldmode != null )
				mode = this.nav.oldmode;
			if( mode != "edit" && mode != "new" )
				noedit = true;
			else
				theAction = "FMPro?";
			if ( fel != null )
			{
				for ( var i = 0; i < fel.length; ++i )
				{
					var elem = fel[i];
					// This rather complex test excludes the hidden emtpy element used to clear checkboxes
					if ( ( fel[i].type == "hidden" && ( elem.value.length > 0 || elem.name.substring(0,1) == this.con.dash ) ) || noedit )
					{
						this.debugAlert("type = " + elem.type + ", checked = " + elem.checked);
						if( ( elem.type != "radio" && elem.type != "checkbox" ) || elem.checked == true )
						{
							var val = elem.value;
							this.debugAlert("val = " + val);
							if ( val == "" && elem.options != null )
							{
								var opts = elem.options;
								for ( var j = 0; j < opts.length; ++j )
								{
									this.debugAlert("selected = " + opts[j].selected);
									if ( opts[j].selected )
									{
										val = opts[j].text;
										break;
									}
								}
							}
							if ( val == null )
							{
								// Hack for Netscape
								for ( var j = 0; j < elem.length; ++j )
								{
									this.debugAlert("selected = " + elem[j].selected);
									if ( elem[j].selected )
									{
										val = elem[j].value;
										break;
									}
								}
							}
							var nvp = escape(elem.name) + this.equ + escape(val) + this.amp;
							this.debugAlert("element " + i + " = " + nvp);
							theAction += nvp;
						}
					}
				}
				oForm.action = theAction.substring(0,theAction.length-1);
				this.debugAlert("action = " + oForm.action);
				result = true;
			}
		}
		return result;
	}

	// Get the div containing the layout
	this.getLayoutDiv = function()
	{
		return document.all["Data1"];
	}

	// Write the specified string to the document
	this.write = function(stringID)
	{
		if ( this.strings != null )
			this.writeit("write",this.strings[stringID]);
	}
	
	// Write out the title of the document
	this.writettl = function(which)
	{
		this.checkerrs();
		if ( which != null )
		{
			var nav = this.nav;
			if ( nav != null && this.strings != null )
			{
				window.anim = new Animate(nav.style);
				window.range = new RangeObj(nav);
				this.writeit("writettl","<TITLE>" + this.strings[which] + " - " + nav.db.html + "</TITLE>");
			}
		}
	}
	
	// Write out delete message
	this.writedelmssg = function()
	{
		if ( this.strings != null && this.nav != null )
			this.writeit("writedelmssg",this.strings.currec + "<BR><BR>" + this.strings.delmssg);
	}
	
	// Write database name
	this.writedb = function()
	{
		if ( this.nav != null )
			this.writeit("writedb",this.nav.db.html);
	}
	
	// Write out the range message for CSS edit
	this.writeedcss = function()
	{
		var c = this.strings;
		var n = this.nav;
		if ( c != null && n != null )
			this.writeit("writeedcss",c.record + c.colon + n.recnum + "<BR>" + c.totalrecs + c.colon + n.count);
	}
	
	// Write range message for CSS form
	this.writeformcss = function()
	{
		var c = this.strings;
		var n = this.nav;
		if ( c != null && n != null )
			this.writeit("writeformcss",c.viewing + c.colon + n.recnum + c.of + n.found + c.ofj);
	}
	
	// Write record matches for CSS table
	this.writematches = function()
	{
		var c = this.strings;
		var n = this.nav;
		if ( c != null && n != null )
			this.writeit("writematches",c.matches + ' ' + n.found + c.of + n.count);
	}

	// Write records to sort for CSS sort
	this.writerectosort = function()
	{
		if ( this.strings != null )
			this.writeit("writerectosort",this.strings.rectosort + this.strings.colon + this.nav.found);
	}

	// Write total records message
	this.writetotal = function(br)
	{
		if ( this.strings != null )
		{
			var output = this.strings.totalrecs + this.strings.colon + iwp.nav.count;
			if ( br )
				output += '<BR>';
			this.writeit("writetotal",output);
		}
	}

	// Write viewing record message
	this.writeviewing = function(which)
	{
		if ( which != null )
		{
			var c = this.strings;
			var n = this.nav;
			var first, second;
			if ( c != null && n != null )
			{
				if ( which == "form" )
				{
					first = n.recnum;
					if ( n.find.length == 0 )
						second = n.count;
					else
						second = n.found;
				}
				else // Table
				{
					first = n.found;
					second = n.count;
				}
				this.writeit("writeviewing-" + which,c.viewingrec + first + c.of + second + c.ofj);
			}
		}
	}

	// Get the status of the next link visibility
	this.nextstat = function()
	{
		var flag = false;
		var nav = this.nav;
		if ( nav != null )
		{
			if ( nav.mode == this.con.modeform )
			{
				if ( nav.find.length == 0 )
					flag = nav.recnum < nav.count;
				else
					flag = nav.recnum < nav.found;
			}
			else if ( nav.mode == this.con.modetable )
				flag = (iwp.nav.recnum + iwp.nav.max - 1) < iwp.nav.found;
		}
		return flag;
	}

	// Write next or previous link for text only
	this.navtxt = function(which)
	{
		var str = null;
		if ( which == "previous" && this.nav.recnum > 1 )
			str = this.strings.prev;
		else if ( which == "next" && this.nextstat() )
			str = this.strings.next;
		if( str != null )
		{
			this.writeit("navtxt-" + which,'<A HREF="javascript:iwp.go(\'' + which + '\')"><FONT SIZE="-1" ' +
				'FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif"  COLOR="#000000">' + str + '</FONT></A>');
		}
	}
		
	// Write the specified link for text only
	this.linktxt = function(which,height)
	{
		var str = null;
		if ( which == "newrec" && this.nav.cannew == 1 )
			str = this.strings.newrec;
		else if ( which == "edit" && this.nav.canedit == 1 )
			str = this.strings.edrec;
		else if ( which == "delrec" && this.nav.candelete == 1 )
			str = this.strings.delrec;
		else if ( which == "sort" && this.nav.cansort == 1 )
			str = this.strings.sort;
		if ( str != null )
		{
			var output = '<TR><TD WIDTH=10>&nbsp;</TD><TD ALIGN="center" NOWRAP HEIGHT="20" BGCOLOR="#99CC99" WIDTH="95">' +
				'<P><A HREF="javascript:iwp.go(\'' + which + '\')"><FONT SIZE="-1" FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif">' + str +
				'</FONT></A></P></TD><TD WIDTH="10">&nbsp;</TD></TR>';
			if ( height > 0 )
				output += '<TR><TD HEIGHT="' + height + '" COLSPAN="3"></TD></TR>';
			this.writeit("linktxt-" + which,output);
		}
	}

	// Write basic input tag
	this.writeintag = function(fn,fv)
	{
		if ( fn != null && fv != null )
			this.writeit("writeintag",'<INPUT TYPE="hidden" NAME="' + fn + '" VALUE="' + fv + '">');
	}
		
	// Write the specified form input tag
	this.writeinput = function(fn)
	{
		if ( fn != null )
		{
			var c = this.con;
			var n = this.nav
			var fv = "";
			if ( c != null && n != null )
			{
				if ( c[fn] == c.db )
					fv = n[fn].none;
				else if ( c[fn] == c.skip )
					fv = n.count;
				else if ( fn == "max0" )
				{
					fv = n.tok0;
					fn = "max";
				}
				else
					fv = n[fn];
				this.writeintag(c[fn],fv);
			}
		}
	}

	// Write the form input tags for sort state
	this.writesorttags = function()
	{
		if ( this.nav != null )
		{
			var s = this.nav.sort;
			var c = this.con;
			if ( s != null && c != null )
			{
				for ( var i in s )
				{
					this.writeintag(c.sortfld,s[i].name.none);
					this.writeintag(c.sortord,s[i].order.none);
				}
			}
		}
	}
	
	// Write the form input tags for find state
	this.writefindtags = function()
	{
		if ( this.nav != null && this.con != null )
		{
			var f = this.nav.find;
			var op = this.con.op;
			if ( f != null && op != null )
			{
				this.writeinput("lop");
				for ( var i in f )
				{
					this.writeintag(op,f[i].op);
					this.writeintag(f[i].name.none,f[i].value.none);
				}
			}
		}
	}
	
	// Write the input tags for edit view
	this.writeeditinput = function()
	{
		this.writeinput("db");
		this.writeinput("layid");
		this.writeinput("tok0");
		this.writeinput("tok1");
		this.writeinput("id");
		this.writesorttags();
	}
	
	// Write the input tags for range form
	this.writerangeinput = function()
	{
		this.writeinput("db");
		this.writeinput("layid");
		this.writeinput("tok0");
		this.writeinput("tok1");
		this.writeinput("max");
		this.writesorttags();
		this.writefindtags();
	}
	
	// Write the input field for range form
	this.writerangefield = function()
	{
		if ( this.nav != null && ! this.redir )
		{
			var style = this.nav.style;
			if ( style > 0 && style < 5 )
			{ // 4=Neutral.css, 3=Purple.css, 2=Wheat.css, 1=Classic.css
				var output = '<INPUT TYPE="text" NAME="range" SIZE=5 CLASS="InputStyle1">';
				this.writeit("writerangefield",output);
			}
		}
	}

	// Write the input tags for new view
	this.writenewinput = function()
	{
		this.writeinput("db");
		this.writeinput("layid");
		this.writeinput("tok0");
		this.writeinput("tok1");
		this.writeinput("skip");
		this.writesorttags();
	}
	
	// Write the input tags for sort view
	this.writesortinput = function()
	{
		this.addsortinfo();
		this.writeinput("db");
		this.writeinput("layid");
		this.writeinput("tok0");
		this.writeinput("tok1");
		this.writeinput("max0");
		this.writefindtags();
	}
	
	// Write the input tags for search view
	this.writesearchinput = function()
	{
		this.writeinput("db");
		this.writeinput("layid");
		this.writeinput("tok0");
		this.writeinput("tok1");
		this.writeinput("max0");
		this.writesorttags();
	}
	
	// Write out the appropriate search data for CSS
	this.writesearchdata = function()
	{
		var str = this.strings;
		if ( str != null )
		{
			var output = '<DIV ID="Info4" CLASS="InfoStyle3"><INPUT TYPE="radio" NAME="-lop" VALUE="and" CHECKED></DIV>' +
			'<DIV ID="Info10" CLASS="InfoStyle3"><SPAN>' + str.and + '</SPAN></DIV><DIV ID="Info11" CLASS="InfoStyle3">' +
			'<INPUT TYPE="radio" NAME="-lop" VALUE="or"></DIV><DIV ID="Info12" CLASS="InfoStyle3"><SPAN>' + str.or + 
			'</SPAN></DIV>';
			
			if ( this.layoutData == null )
			{
				output += '<DIV ID="Lbl1" CLASS="InfoStyle4"><SPAN>' + str.field + '</SPAN></DIV><DIV ID="Lbl2" CLASS="InfoStyle4">' +
				'<SPAN>' + str.type + '</SPAN></DIV><DIV ID="Lbl3" CLASS="InfoStyle4"><SPAN>' + str.criteria + '</SPAN></DIV>';
				this.writesearchhtml();
			}
			else
				this.writesearchcss();
			this.writeit("writesearchdata",output);
		}
	}

	// Write out or search field select statement
	this.writesearchhtml = function()
	{
		var flds = this.table;
		var str = this.strings;
		if ( flds != null && str != null )
		{
			var output = '<DIV ID="Data3" CLASS="DataStyle1"><TABLE BORDER="0" SPACING="4">';
			for ( i in flds )
			{
				if (this.textonly)
					output += '<TR><TD NOWRAP><FONT SIZE="-1" FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif">' + flds[i].fieldname +
						'</FONT></TD><TD WIDTH="10">&nbsp;</TD><TD><SELECT NAME="-op">';
				else
					output += '<TR><TD WIDTH="130">' + flds[i].fieldname + '</TD>' +
						'<TD WIDTH="160"><SELECT NAME="-op" SIZE="1">';
				output += '<OPTION SELECTED VALUE="bw">' + str.begins +
					'<OPTION VALUE="cn">' + str.contains +
					'<OPTION VALUE="ew">' + str.ends +
					'<OPTION VALUE="eq">' + str.equ +
					'<OPTION VALUE="gt">' + str.gt +
					'<OPTION VALUE="gte">' + str.gte +
					'<OPTION VALUE="lt">' + str.lt +
					'<OPTION VALUE="lte">' + str.lte +
					'<OPTION VALUE="neq">' + str.neq + '</SELECT></TD>';
				if (this.textonly)
					output += '<TD WIDTH="10">&nbsp;</TD>';
				output += '<TD ' + flds[i].fieldwidth + '><INPUT TYPE="TEXT" NAME="' +
					flds[i].fieldname + '" VALUE="" SIZE="60"></TD></TR>';
			}
			output += '</TABLE></DIV>';
			this.writeit("writesearchhtml",output);
		}
	}				
				
	// Write the layoutData string to the document
	this.writesearchcss = function()
	{
		var str = this.strings;
		var nav = this.nav;
		if ( this.layoutData != null &&  nav != null && str != null )
		{
			var output = '<DIV ID="Data1" CLASS="DataStyle1">' + this.layoutData + '<DIV ID="SearchMenu"><DIV ID="Shadow"></DIV>' +
			'<DIV ID="OuterBorder"></DIV><DIV ID="TLBorder"></DIV><DIV ID="BRBorder"></DIV><DIV ID="SearchBG"><DIV ID="Item_ttl" CLASS="MenuStyle2">' +
			str.opser + '</DIV>' + '<DIV ID="Item_lt" ONMOUSEOVER="iwp.select(this,\'lt\')" ONMOUSEOUT="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('lt') + '</DIV>' + '<DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.lt + '</DIV></DIV><DIV ID="Item_lte" ONMOUSEOVER="iwp.select(this,\'lte\')" ONMOUSEOUT="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('lte') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.lte + '</DIV></DIV><DIV ID="Item_gt" onMouseOver="iwp.select(this,\'gt\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('gt') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.gt + '</DIV></DIV>' + '<DIV ID="Item_gte" onMouseOver="iwp.select(this,\'gte\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('gte') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.gte + '</DIV></DIV><DIV ID="Item_equ" ONMOUSEOVER="iwp.select(this,\'equ\')" ONMOUSEOUT="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('equ') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.equ + '</DIV></DIV><DIV ID="Item_rng" onMouseOver="iwp.select(this,\'rng\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('rng') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.rng + '</DIV></DIV><DIV ID="Item_dup" onMouseOver="iwp.select(this,\'dup\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('dup') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.dup + '</DIV></DIV><DIV ID="Item_td" onMouseOver="iwp.select(this,\'td\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('td') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.td + '</DIV></DIV><DIV ID="Item_inv" onMouseOver="iwp.select(this,\'inv\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('inv') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.inv + '</DIV></DIV><DIV ID="Item_ch" onMouseOver="iwp.select(this,\'ch\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('ch') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.ch + '</DIV></DIV><DIV ID="Item_wld" onMouseOver="iwp.select(this,\'wld\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('wld') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.wld + '</DIV></DIV><DIV ID="Item_ltr" onMouseOver="iwp.select(this,\'ltr\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('ltr') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.ltr + '</DIV></DIV><DIV ID="Item_ex" onMouseOver="iwp.select(this,\'ex\')" onMouseOut="iwp.unselect(this)">' +
			'<DIV ID="ItemSymbol" CLASS="MenuStyle1">' + this.menusym('ex') + '</DIV><DIV ID="ItemText" CLASS="MenuStyle1">' +
			str.ex + '</DIV></DIV></DIV></DIV></DIV>';
			this.writeit("writesearchcss",output);
		}
	}
	
	// Write the layoutData string to the document
	this.writelaydata = function()
	{
		if ( this.layoutData != null )
			this.writeit("writelaydata",this.layoutData);
	}
	

	// Show next/prev buttons if right context
	this.shownextprev = function()
	{
		var nav = this.nav;
		if ( nav != null )
		{
			if (nav.uistate == 1 && nav.style < 7)
			{
				if ( nav.recnum > 1 )
				{
					var plink = document.all.PLink1;
					var pbtn = document.all.BtnP1;
					if ( plink != null )
						plink.style.visibility = "visible";
					if ( pbtn != null && nav.style < 6 )
						pbtn.style.visibility = "visible";
				}
				if ( this.nextstat() )
				{
					var nlink = document.all.NLink1;
					var nbtn = document.all.BtnN1;
					if ( nlink != null )
						nlink.style.visibility = "visible";
					if ( nbtn != null && nav.style < 6 )
						nbtn.style.visibility = "visible";
				}
			}
		}
	}

	// Add sort field options to specified select object
	this.addsortfieldops = function(obj)
	{
		var sel = document.all[obj];
		if ( sel != null )
		{
			if ( this.strings != null )
					sel.options[0] = new Option(this.strings.none);
			if ( this.sort != null )
			{
				var vals = this.sort.compansortfields;
				var st = 1;
				var ln = vals.length + st;
				for ( var i = st; i < ln; ++i )
					sel.options[i] = new Option(vals[i-st],vals[i-st]);
			}
		}
	}
	
	// Add sort order options to specified select object
	this.addsortorderops = function(obj)
	{
		var sel = document.all[obj];
		if ( sel != null )
		{
			if ( this.strings != null )
			{
				sel.options[0] = new Option(this.strings.ascend,this.ascend);
				sel.options[1] = new Option(this.strings.descend,this.descend);
			}
			if ( this.sort != null )
			{
				var vals = this.sort.valuenames;
				var st = 2;
				var ln = vals.length + st;
				for ( var i = st; i < ln; ++i )
					sel.options[i] = new Option(vals[i-st],'custom=' + vals[i-st]);
			}
		}
	}

	// Add all sort options to select objects
	this.addsortinfo = function()
	{
		this.addsortfieldops("Fld1");
		this.addsortfieldops("Fld2");
		this.addsortfieldops("Fld3");
		this.addsortfieldops("Fld4");
		this.addsortorderops("Fld5");
		this.addsortorderops("Fld6");
		this.addsortorderops("Fld7");
		this.addsortorderops("Fld8");
	}

	// Write out sortfield select statement -- for fern green
	this.writesort = function()
	{
		var output = '<SELECT NAME="-sortfield" SIZE="1">';
		output += '<OPTION VALUE="">' + this.strings.none;
		var fields = this.sort.compansortfields;					
		for ( var i in fields )
			output += '<OPTION VALUE="' + fields[i] + '">' + fields[i];
		output += '</SELECT>';
		this.writeit("writesort",output);
	}
	
	// Write out sortorder select statement -- for fern green
	this.writevalues = function()
	{
		var output = '<SELECT NAME="-sortorder" SIZE="1">';
		output += '<OPTION VALUE="ascend">' + this.strings.ascend;
		output += '<OPTION VALUE="descend">' + this.strings.descend;
		var values = this.sort.valuenames;					
		for ( var i in values )
			output += '<OPTION VALUE="' + 'custom=' + values[i] + '">' + values[i];
		output += '</SELECT>';
		this.writeit("writevalues",output);
	}

	// Sort table view by field name specified
	this.sortTableByFieldName = function(fld)
	{
		if( this.debug == true )
			window.status = "sortTableByFieldName: " + fld;
		var nav = this.nav;
		if ( fld != null && nav != null )
		{
			var ord = this.ascend;
			var oldord = null;
			if ( nav.sort != null ) 
			{
				if ( nav.sort.length != 0 )
				{
					if (nav.sort[0].name.url == fld.toLowerCase() )
						oldord = nav.sort[0].order.url;
				}
			}
			if ( oldord != null )
			{
				if ( oldord == this.ascend )
					ord = this.descend;
			}
			nav.sort = new Array();
			nav.sort[0] = new Object();
			nav.sort[0].name = new Object();
			nav.sort[0].name.url = fld;
			nav.sort[0].order = new Object();
			nav.sort[0].order.url = ord;
			if ( nav.tableid == null || nav.tableid == "" )
				nav.tableid = nav.layid;
			iwp.go("table");
		}
	}

	// Write out our sort state
	this.sortstate = function()
	{
		if ( this.nav != null && this.strings != null )
		{
			var output;
			if ( this.nav.issorted == 1 )
			{
				output = this.strings.sorted;
				if ( this.textonly )
				{
					output += " (";
					for ( var i in this.nav.sort )
						output += this.nav.sort[i].name.html + this.nbsp;
					output = output.substring(0, output.length - this.nbsp.length) + ")";
				}
			}
			else
				output = this.strings.unsorted;
			this.writeit("sortstate",output);
		}
	}
	
	// Write out our field names for table view
	this.getfieldnames = function()
	{
		var output = "";
		var flds = this.table;
		if ( flds != null )
		{
			for ( var i in flds )
			{
				output += '<TH WIDTH="10">&nbsp;</TH><TH ' +
				flds[i].fieldwidth + ' ALIGN="left" VALIGN="top">' +
				flds[i].fieldname + '</TH>';
			}
		}
		return output;
	}
	
	// Write out our record data for table view
	this.getrecorddata = function()
	{
		var output = "";
		if ( this.table != null && this.nav != null )
		{
			var len = this.table[0].fieldoutput.length;
			var flds = this.table;
			for ( var i = 0; i < len; ++i )
			{
				output += '<TR><TD WIDTH="26">';
				if (this.textonly)
					output += '<A HREF="javascript:iwp.go(\'reclink\',' + (i + this.nav.skip) + ')">' +
					(i + this.nav.skip + 1) + '</A></TD>';
				else
					output += '<DIV ID="BtnT1" CLASS="BtnStyle5" ' +
					'onClick="iwp.go(\'reclink\',' + (i + this.nav.skip) + ')" onMouseOver="anim.on(this)" ' +
					'onMouseOut="anim.off(this)"><SPAN>' + (i + this.nav.skip + 1) + '</SPAN></DIV></TD>';
				for ( var j in flds )
				{
					output += '<TD WIDTH="10">&nbsp;</TD><TD ' +
					flds[j].fieldwidth + ' CLASS="DataStyle1"><FORM>' +
					flds[j].fieldoutput[i] + '</FORM></TD>';
				}
				output += '</TR>';
			}
		}
		return output;
	}

	// Write HTML based table data for css style
	this.writehtmltable = function()
	{
		var output = "";
		if ( this.table != null )
		{
			output = '<DIV ID="Data2" CLASS="DataStyle1">' +
			'<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" CLASS="DataStyle1">' +
			'<TR><TH WIDTH="26">&nbsp;</TH>' + this.getfieldnames() + '</TR><TR><TD HEIGHT="10">' +
			'&nbsp;</TD></TR>' + this.getrecorddata() + '</TABLE></DIV>';
		}
		else if (this.cssTableData != null)
		{
			output = '<DIV ID="Data1" CLASS="DataStyle1">' + 
			this.cssTableData + '</DIV>';
		}
		this.writeit("writehtmltable",output);
	}
	
	// Write out our record data for form view
	this.writeformdata = function()
	{
		var flds = this.table;
		var output = "";
		if ( flds != null && this.nav != null )
		{
			for ( var i in flds )
			{
				if ( this.nav.format.toLowerCase().indexOf("form") > -1 )
				{
					output += '<P><FONT SIZE="-1" FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif" COLOR="#000000"><B>' + flds[i].fieldname +
						':</B><BR>' + flds[i].fieldoutput[0] + '</FONT></P>';
				}
				else
				{
					output += '<TR><TD VALIGN="top" NOWRAP><FONT SIZE="-1" FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif"><B>' + flds[i].fieldname +
						'</B></FONT></TD><TD WIDTH="5">&nbsp;</TD><TD ' + flds[i].fieldwidth + '><FONT SIZE="-1" FACE="‚l‚r ‚oƒSƒVƒbƒN, Osaka, Verdana, Arial, Helvetica, sans-serif"><B>';
					if ( flds[i].fieldoutput != null )
						output +=  flds[i].fieldoutput[0];
					else
						output += '<INPUT TYPE="text" NAME="' + flds[i].fieldname + '" VALUE="" SIZE="60">';
					output += '</B></FONT></TD></TR><TR><TD COLSPAN="3"><HR SIZE="1" NOSHADE></TD></TR>';
				}
			}
			this.writeit("writeformdata",output);
		}
	}

	// Write script tag to get navigation data
	this.getiwpdata = function()
	{
		var c = this.con;
		this.url = "FMPro" + window.location.search;
		// Set some flags for later use
		var test = window.location.search.toLowerCase();
		if ( test.indexOf(c.txt) > -1 )
			this.textonly = true;
		if ( test.indexOf(c.del) > -1)
			this.redir = true;
		if ( test.charAt(test.length - 1) != this.equ )
			this.url += this.equ;
		if ( test.indexOf(c.edit) > -1 || test.indexOf(c.newrec) > -1 )
			this.url += this.amp + c.find + this.equ;
		this.url += this.amp + c.iwpdata;
		var output = '<SCRIPT LANGUAGE="javascript" SRC="' + this.url + '"></SCRIPT>';
		this.debugComment("getiwpdata",output);
		document.write(output);
	}
		
	// Set up the iwp environment
	this.iwpsetup = function(isCSS,needsLaySS)
	{
		// Set the window name so we can target it from other windows (Sort2CSS.htm)
		if ( window.name == "" || window.name == null )
			window.name = "IWPMain";
		var nav = this.nav;
		if ( nav != null )
		{
			var output = "";
			if ( nav.lang == "J" ) // Set encoding if Japanese
				output += '<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=shift_jis">';
			output += '<SCRIPT LANGUAGE="javascript" SRC="' + nav.lang + 'Strings.js"></SCRIPT>';
			if ( ! this.redir )
			{
				if ( isCSS && nav.err == 0 )
				{
					this.check();
					output += '<LINK REL="stylesheet" TYPE="text/css" HREF="' + nav.ssname + '">';
					if ( needsLaySS && nav.layid.length > 0 )
						output += '<LINK REL="stylesheet" TYPE="text/css" HREF="FMPro?-db=' + nav.db.url + '&-mode=' + nav.mode + '&-layoutstylesheet=' + nav.layid + '">';
				}
			}
			this.debugComment("iwpsetup",output);
			document.write(output);
		}
	}
	
	// Check for any error and report
	this.checkerrs = function(err,wantConf)
	{
		var nav = this.nav;
		var goback = false;
		if ( nav != null )
		{
			if ( err == null )
			{
				err = nav.err;
				goback = true;
			}
			this.debugAlert("checkerrs: error = " + err + ", wantConf = " + wantConf + ", goback = " + goback);
			if ( err != 0 )
			{
				var errors = new IWPErrors();
				var output = "";
									
				var erref = "e" + err;
				output = errors[erref];
				if ( output == null )
					output = errors.def;
				this.debugAlert("error = " + err + " count = " + nav.count);
				if ( output != null )
				{
					if ( wantConf == true )
						return confirm(output);
					else
						alert(output);
				}
				if ( goback )
				{
					if ( err == 401 && nav.count == 0 )
					{
						this.debugAlert("cannew = " + nav.cannew);
						if ( nav.cannew )
							this.go("newrec");
						else
							this.go("home");
					}
					else if ( err == 100 )
						this.go("home");
					else
						history.back();
				}
			}
			else if ( this.redir )
			{
				if ( ( this.con.dash + nav.action ) == this.con.del )
				{
					nav.find = "";
					nav.action = this.con.freq;
				}
				this.go("current");
			}

		}
	}
	
	this.setupsortdlog = function()
	{
		var sflds = this.sort.compansortfields;
		var svals = this.sort.valuenames;
		var doc = document.all;
		var dlg = doc.Dlog2;
		var str = this.strings;
		var nav = window.iwp.nav;
		
		if ( dlg != null && str != null )
		{
			dlg.s1active		= null;
			dlg.s1				= doc.Sel1;
			dlg.s2				= doc.Sel2;
			dlg.s3				= doc.Sel3;
			dlg.movebtn			= doc.Btn25;
			dlg.decbtn			= doc.dbtn;
			dlg.custbtn			= doc.cbtn;
			dlg.ascbtn			= doc.abtn;
			dlg.clrbtn			= doc.Btn24;
			dlg.srtbtn			= doc.Btn26;
			dlg.usrtbtn			= doc.Btn27;
			dlg.hlpbtn			= doc.Img4;
			dlg.hlpbtn.file		= "SortHelp.htm";
			dlg.hlpbtn.on		= new Image();
			dlg.hlpbtn.on.src	= "sorthelp_on.gif";
			dlg.btnwidth1		= "106px";
			dlg.btnwidth2		= "105px";
			dlg.s1.firstclick	= false;
						
			dlg.srtbtn.submit = dlg.usrtbtn.submit = function()
			{
				if (nav != null )
				{
					nav.sort = new Array();
					if ( this.id == dlg.srtbtn.id )
					{
						var src = dlg.s2.options;
						for ( i = 0; i < src.length; ++i )
						{
							nav.sort[i] = new Object();
							nav.sort[i].name = new Object();
							nav.sort[i].name.url = escape(src[i].rtext);
							nav.sort[i].order = new Object();
							nav.sort[i].order.url = escape(src[i].value);
						}
					}
					iwp.go("table2",null,window.opener);
					window.close();
				}
			}
			
			dlg.moveitems = function()
			{
				if ( this.s1active == true )
				{
					var src = this.s1.options;
					var dest = this.s2.options;
					var cnt = 0;
					for ( var i = 0; i < src.length; ++i )
					{
						if ( src[i].selected )
						{
							if ( src[i].dupcheck(dest) )
							{
								src[i].selected = false;
								var tmp = this.makeoption(src[i].text,src[i].value);
								tmp.setinfo();
								dest[dest.length] = tmp;
								++cnt;
							}
						}
					}
					if ( cnt > 0 )
					{
						this.s1.blur();
						this.s2.handlefocus();
					}
				}
				else if ( this.s1active == false )
					this.clear( false );
			}

			dlg.s1.unselect = dlg.s2.unselect = function ()
			{
				for ( var i = 0; i < this.options.length; ++i ) this.options[i].selected = false;
			}
			
			dlg.s1.selectcount = dlg.s2.selectcount = function ()
			{
				var cnt = 0;
				for ( var i = 0; i < this.options.length; ++i ) 
				{
					if ( this.options[i].selected ) ++cnt;
				}
				return cnt;
			}

			dlg.clear = function( all )
			{	
				var src = this.s2.options;
				
				if( all )
				{
					for ( var i = 0; i < src.length; ++i ) src[i--] = null;
				}
				else
				{
					for ( var i = 0; i < src.length; ++i )
					{
						if ( src[i].selected )
							src[i--] = null;
					}
				}
				this.s1.unselect();
				this.s2.unselect();
				dlg.s1active = null;
				this.disablesortradios(true);
				this.clearsortbuttons();
				this.s1.firstclick = false;
			}

			dlg.s1.handlefocus = dlg.s2.handlefocus = function()
			{
				var olist, txt;
				if ( this.id == dlg.s1.id )
				{
					dlg.s1active = true;
					olist = dlg.s2;
					txt = str.move;
					if (this.firstclick == false )
					{
						dlg.ascbtn.checked = true;
						this.firstclick = true;
					}
				}
				else
				{
					dlg.s1active = false;
					olist = dlg.s1;
					txt = str.clear;
				}
				this.selections = this.selectcount();
				olist.selections = 0;
				olist.unselect();
				if( this.selections > 0 )
				{
					dlg.disablesortradios(false);
				}
				dlg.movebtn.value = txt;
				// Hack for IE 4.5
				if ( iwp.client.browser == 0 && iwp.client.version == 4.5 && iwp.client.platform == 0 )
				{
					dlg.movebtn.style.width = dlg.btnwidth1;
					dlg.movebtn.style.width = dlg.btnwidth2;
				}
				this.focus();
			}

			dlg.s2.setsortorder = function()
			{				
				if ( dlg.s1active == false )
				{
					for ( var i = 0; i < this.options.length; ++i )
					{
						if(this.options[i].selected)
							this.options[i].setinfo();
					}
				}
			}

			dlg.s2.updatesortstate = function()
			{
				if ( dlg.s1active == false )
				{
					var s2 = this.options;
					var sel = new Array();
					for ( var i = 0, j = 0; i < s2.length; ++i )
					{
						if ( s2[i].selected )
							sel[j++] = s2[i];
					}
					if ( sel.length > 0 )
					{
						var cval = sel[0].value;
						for ( var i = 1; i < sel.length; ++i )
						{
							if ( sel[i].value != cval )
							{
								dlg.clearsortbuttons();
								return;
							}
						}
						sel[0].updatesortbuttons();
					}
				}
			}
			
			dlg.clearsortbuttons = function()
			{
				this.ascbtn.checked = false;
				this.decbtn.checked = false;
				this.custbtn.checked = false;
			}

			dlg.disablesortradios = function(dis)
			{
				if ( dis != null )
				{
					this.ascbtn.disabled = dis;
					this.decbtn.disabled = dis;
					this.custbtn.disabled = dis;
					this.updatebuttons();
				}
			}
			
			dlg.updatebuttons = function()
			{
				var s1len = this.s1.options.length;
				var s2len = this.s2.options.length;
				
				if ( s1len > 0 && this.s1active != null && ( this.s1.selections > 0 || this.s2.selections > 0) )
					this.movebtn.disabled = false;
				else
					this.movebtn.disabled = true;
				if ( s2len > 0 )
				{
					this.clrbtn.disabled = false;
					this.srtbtn.disabled = false;
				}
				else
				{
					this.clrbtn.disabled = true;
					this.srtbtn.disabled = true;
				}
			}
			
			dlg.makeoption = function(txt,val)
			{
				var op = new Option();
				op.value = val;
				op.text = txt;
				op.rtext = txt;

				op.setinfo = function()
				{
					var sortstring;
					if ( dlg.decbtn.checked )
					{
						this.value = dlg.decbtn.value;
						sortstring = str.hintd;
					}
					else if ( dlg.custbtn.checked )
					{
						var vals = dlg.s3.options;
						for ( var i = 0; i < vals.length; ++i )
						{
							if ( vals[i].selected )
							{
								this.value = vals[i].value;
								break;
							}
						}
						sortstring = str.hintc;
					}
					else
					{
						this.value = dlg.ascbtn.value;
						sortstring = str.hinta;
					}
					this.text = sortstring + " " + this.rtext;
					this.selected = true;
				}

				op.initinfo = function()
				{
					var sortstring;
					if ( this.value == dlg.ascbtn.value )
						sortstring = str.hinta;
					else if ( this.value == dlg.decbtn.value )
						sortstring = str.hintd;
					else
						sortstring = str.hintc;
					this.text = sortstring + " " + this.rtext;
				}

			//	alert user that a duplicate field is in a sort list
				op.dupcheck = function(dest)
				{
					var result = true;
					for ( var i = 0; i < dest.length; ++i )
					{
						if ( this.text == dest[i].rtext )
						{
							alert(str.duperr);
							result = false;
							break;
						}
					}
					return result;
				}

				op.updatesortbuttons = function()
				{
					if ( this.value == dlg.ascbtn.value )
						dlg.ascbtn.checked = true;
					else if ( this.value == dlg.decbtn.value )
						dlg.decbtn.checked = true;
					else
						dlg.custbtn.checked = true;
				}

				return op;
			}
			
			dlg.hlpbtn.swap = function()
			{
				if ( this.off == null )
				{
					this.off = new Image();
					this.off.src = this.src;
				}
				if ( this.on != null )
					this.src = this.on.src;
			}

			dlg.hlpbtn.restore = function()
			{
				if ( this.off != null )
					this.src = this.off.src;
			}

			dlg.hlpbtn.showhelp = function()
			{
				var lang = iwp.nav.lang;
				if ( lang != null )
				{
					win = window.open("","IWPHelp","top=20,left=20,height=460,width=620,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,");
					win.location = lang + this.file;
				}
			}
			
			dlg.movebtn.value = str.move;
			dlg.clrbtn.value = str.clearall;
			dlg.srtbtn.value = str.sort;
			dlg.usrtbtn.value = str.unsort;
			// Hack for IE 4.5
			if ( iwp.client.browser == 0 && iwp.client.version == 4.5 && iwp.client.platform == 0 )
			{
				dlg.movebtn.style.width = dlg.btnwidth1;
				dlg.clrbtn.style.width = dlg.btnwidth1;
				dlg.srtbtn.style.width = dlg.btnwidth1;
				dlg.usrtbtn.style.width = dlg.btnwidth1;
				dlg.movebtn.style.width = dlg.btnwidth2;
				dlg.clrbtn.style.width = dlg.btnwidth2;
				dlg.srtbtn.style.width = dlg.btnwidth2;
				dlg.usrtbtn.style.width = dlg.btnwidth2;
			}
			dlg.disablesortradios(true);
			for ( var i = 0; i < sflds.length; ++i )
				dlg.s1.options[i] = dlg.makeoption(sflds[i],sflds[i]);
			if (nav != null )
			{
				var srt = nav.sort;
				var dest = dlg.s2.options;
				for ( var i = 0; i < srt.length; ++i )
				{
					var tmp = dlg.makeoption(srt[i].name.none,srt[i].order.none);
					tmp.initinfo();
					dest[i] = tmp;
				}
			}
			if ( svals.length == 0 )
				dlg.s3.options[0] = new Option(str.nolists);
			else
			{
				for ( var i = 0; i < svals.length; ++i )
					dlg.s3.options[i] = new Option(svals[i],dlg.custbtn.value + svals[i]);
			}
		}
	}

	// IWP Constants
	this.cfirst		=	"first";
	this.clast		=	"last";
	this.cnext		=	"next";
	this.cprev		=	"previous";
	this.ctoggle	=	"toggle";
	this.defmax		=	"25";
	this.delim		=	"~";
	this.amp		=	"&";
	this.equ		=	"=";
	this.nbsp		=	"&nbsp;";
	this.textonly	=	false;
	this.redir		=	false;
	this.ascend		=	"ascend";
	this.descend	=	"descend";
	this.ohelp		=	new IWPHelp();
	this.nav		=	new Object();
	this.con		=	new IWPConst();
	this.client		=	new Object();
	
	this.debug		=	false;
}

// Create Objects

if ( window.iwp == null )
	iwp = new IWPObj();
	
iwp.getiwpdata();
