var ns6 = (navigator.appName=="Netscape" && navigator.appVersion>="5.0");
var ns = (navigator.appName=="Netscape" && navigator.appVersion<"5.0");
var ie = (navigator.appName=="Microsoft Internet Explorer");

// More detailed Browser Detection
   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
// End of Detailed Browser Detection

/*
alert("is_ie="+is_ie+
	"\nis_ie5="+is_ie5+
	"\nis_ie5up="+is_ie5up+
	"\nis_ie5_5="+is_ie5+
	"\nis_ie5_5up="+is_ie5_5up+
	"\nis_ie6="+is_ie6+
	"\nis_nav="+is_nav
	);
*/
/*
is_ie5_5up=false
document.write("agent="+agt+" "+is_major+" "+is_minor+" is_ie="+is_ie+
	" is_ie5="+is_ie5+
	" is_ie5up="+is_ie5up+
	" is_ie5_5="+is_ie5+
	" is_ie5_5up="+is_ie5_5up+
	" is_ie6="+is_ie6+
	" is_nav="+is_nav);
*/
function c(p){window.location = p; return false;}
function csubmit(p){document.all('_dst').value=p;	if (datachanged) document.all('_c').value="1";	document.entryform.submit(); return false;}

var cbutton="";
var datachanged=false;

function cc()
{
	cbutton = "cancel";
}

function deleteGroup()
{


		if (window.confirm('Delete Group?\n\nClick OK to continue and DELETE GROUP.\nClick Cancel to stay on this screen.'))
			return true;
		else
			return false;


}

function scc()
{
	if (datachanged) document.all('_c').value="1";
	if (cbutton=="cancel" && datachanged)
	{
		cbutton="";
		if (window.confirm('Do you wish to leave this screen WITHOUT saving the changes you made?\n\nClick OK to continue WITHOUT saving changes.\nClick Cancel to stay on this screen.'))
			return true;
		else
			return false;
	}
	return true;
}

function scc2()
{
	if (datachanged)
	{
		if (window.confirm('Do you wish to leave this screen WITHOUT saving the changes you made?\n\nClick OK to continue WITHOUT saving changes.\nClick Cancel to stay on this screen.'))
			return true;
		else
			return false;
	}
	return true;
}


function doFieldFocus(control)
{
		control.focus();
}

function initFocus(control)
{
	var ns = (navigator.appName=="Netscape" && navigator.appVersion<"5.0");
	//	Note: Opera does not support onLoad event yet
//	if (!ns)
//		control.focus();
//	if (!ns)
//		document.all(control).focus();
	if (!ns)
	{
		eval("f = document.forms[0]." + control + ";");
		if (f)
			f.focus();
	}
}

function findStyle(style, sheet)
{
	var rules, t, m;
	rules = document.styleSheets[sheet].rules;
	for (t=0; t<rules.length; t++ )
		if (rules.item(t).selectorText==style)
			return t;
	return -1;
}

function setItemStyle( control, style )
{
	var rules, fg, bg, bi, bw, bs, sheet, t, c;

	for(sheet=0;	sheet<document.styleSheets.length;	sheet++)
	{
		t = findStyle(style, sheet)
		if (t>-1)
		{
			rules = document.styleSheets[sheet].rules.item(t).style;
			if (rules.color)
				fg = rules.color;
			if (rules.backgroundColor)
				bg = rules.backgroundColor;
			if (rules.backgroundImage)
				bi = rules.backgroundImage;
			if (rules.borderWidths)
				bw = rules.borderWidths;
			if (rules.borderStyle)
				bs = rules.borderStyle;
		}
	}
	if (!fg)	fg="";
	if (!bg)	bg="";
	if (!bi)	bi="";
	if (!bw)	bw="";
	if (!bs)	bs="";

	control.style.color = fg;
	control.style.backgroundColor = bg;
	control.style.backgroundImage = bi;
	control.style.borderWidths = bw;
	control.style.borderStyle = bs;

	c = control.all.tags("span");
	for (t=0; t<c.length; t++ )
	{
		c[t].style.color = fg;
		c[t].style.backgroundColor = bg;
	}
}

function domouseover(control,style)
{
	setItemStyle( control, style );
}

function domouseout(control, style)
{
	setItemStyle( control, style );
}


function df(control)
{
	control.select();
	df2(control);
}

function df2(control)
{
	var ns = (navigator.appName=="Netscape" && navigator.appVersion<"5.0");
	var t, sheet, bg, b;
	if (!ns)
	{
		for(sheet=0; sheet<document.styleSheets.length; sheet++)
		{
			t = findStyle(".selectedfield", sheet);
			if (t>-1)
				bg = document.styleSheets[sheet].rules.item(t).style.backgroundColor;
		}
		control.style.backgroundColor = bg;
	}
}

function dbu(control)
{
	control.value = control.value.toUpperCase();
	db(control);
}

function db(control)
{
	var ns = (navigator.appName=="Netscape" && navigator.appVersion<"5.0");
	var t, sheet, bg;
	if (!ns)
	{
		for(sheet=0; sheet<document.styleSheets.length; sheet++)
		{
			t = findStyle(".normalfield", sheet);
			if (t>-1)
				bg = document.styleSheets[sheet].rules.item(t).style.backgroundColor;
		}
		control.style.backgroundColor = bg;
	}
}

function dbCenter(control)
{
	leadZeros(control, 7);
	if (control.value=='0000000')
		control.value='';
	db(control);
}

function dbFund(control)
{
	leadZeros(control, 4);
	if (control.value=='0000')
		control.value='';
	db(control);
}

function dbMoney(control)
{
	formatMoney(control);
	db(control);
}

function dbPhone(control)
{
	var fPhone;
	db( control );
	
	fPhone = control.value;
	fPhone = getPhone(fPhone);
	if (fPhone.length==7)
	{
		fPhone = "704" + fPhone;
	}
	if (fPhone.length==10)
	{
		fPhone = "(" + fPhone.substr(0,3) + ") " + fPhone.substr(3,3) + "-" + fPhone.substr(6,4);
		control.value = fPhone;
	}
}

function dbSSN(control)
{
	var fSSN;
	db( control );
	
	fSSN = getDigits(control.value);
	if (fSSN.length==9)
	{
		fSSN = fSSN.substr(0,3) + "-" + fSSN.substr(3,2) + "-" + fSSN.substr(5,4);
		control.value = fSSN;
	}
}

//============================================================
// General purpose routines below here
//============================================================
function leadZeros(control, n)
{
	var v;
	v = control.value;
	while ( v.length<n )
		v = "0" + v;
	control.value = v;
}

function formatMoney(control)
{
	var v;

	v = control.value;
	v = toNumber(v);
	v = toString(v, 1, 1, 2);
	control.value = v;
}

function roundOff(value, precision)
{
	var num = 0.0;
	var frac = 0.0;
	var whole = 0;
	
	num = value * Math.pow(10, (precision));	//	Move decimal
	whole = Math.round( num );
	frac = (num) - (whole);
	if (frac>=0.5)
		whole += 1;
	num = whole / Math.pow(10,precision);
	return "" + num;									//convert value to string
}

function toNumber(x)
{
	var y, t, z, neg, v=0.0;
	neg=false;
	y="";
	for (t=0; t<x.length; t++ )	
	{
		z=x.substr(t,1);
		if (z=='-')
			neg=true;
		if ( (z>='0' && z<='9') || z=='.' )
			y +=z;
	}
	if (y=="")
		y = "0";
	
	if (neg)
		y='-' + y;
	
	v=-(-parseFloat(y));
	return v;
}

function toString(v, currency, comma, decimals)
{
	var t, x, y;

	y = v;
	y += "";
	t = y.indexOf('.');
	if (t==-1) 
	{
		t = y.length;
		if (decimals>0)
			y += '.';
	}
	for (x=0; x<decimals; x++ )
		y += '0';

	if (decimals>0)
		y = y.substr(0,t+decimals+1);
	else
		y = y.substr(0,t);

	if (y.substr(0,1)=='.')
		y = '0' + y;
	if (y.substr(0,1)=='-' && y.substr(1,1)=='.')
		y = '-0' + y.substr(1,y.length-1);
		
	if (comma)
		for (t-=3;	t>0;	t-=3 )
			if (y.substr(t-1,1)!='-')
				y = y.substr(0,t)+','+y.substr(t,y.length);

	if (currency)	
	{
		if (y.substr(0,1)=='-')
			y = '-$' + y.substr(1,y.length);
		else
			y = '$' + y;
	}
	return y;
}

// Apparently netscape doesn't support background color changing...
function dbDate( control )
{
	var fDate;
	var y = "";
	var z;
	var t;
	var digits;
	
	db( control );
	
	fDate = control.value;
	
	digits = 0;
	for (t=0; t<fDate.length; t++ )	
	{
		z=fDate.substr(t,1);
		if ( z>='0' && z<='9' )
		{
			y +=z;
			digits++;
		} else
		{
			if (digits==1)
				y = y.substr(0,y.length-1) + '0' + y.substr(y.length-1,1);
			digits = 0;
		}
	}
	if (digits==1)
		y = y.substr(0,y.length-1) + '0' + y.substr(y.length-1,1);
	digits = 0;

	fDate = y;
	
	if (fDate.length==5)
		fDate = '0' + fDate;
	if (fDate.length==7)
		fDate = '0' + fDate;
	if (fDate.length==6)
	{
		//	Assuming current century
		var fNow = new Date();
		var c = parseInt(fNow.getFullYear()/100);
		var y = fNow.getFullYear() % 100;
		if ( (-(-fDate.substr(4,2)) > (y - -20)) && (-(-fDate.substr(4,2))>19))
			c--;
		c += "";
		while (c.length<2)
			c = '0' + c;
		fDate = fDate.substr(0,4) + c + fDate.substr(4,2);
	}
	if (fDate.length==8)
	{
		fDate = fDate.substr(0,2) + '/' + fDate.substr(2,2) + '/' + fDate.substr(4,4);
	}
	if (fDate.substr(2,1)=='/' && fDate.substr(5,1)=='/')
	{
		control.value = fDate;
		control.style.color = 0x000000;
	} else
	{
		control.style.color = 0xff0000;
	}
}


function getIndex(control) 
{
	var i;
	for (i=0; i<control.form.length; i++ )
		if (control.form[i] == control)
			return i;
	return -1;
}

function doKey(event, control)
{
	var i, i2, i3;
	if (ie)
	{
		if (event.keyCode==13)	
		{
			i = getIndex(control);
			i2 = (i+1) % control.form.length;
			if (control.form[i].name!=control.form[i2].name && control.form[i2].tagName=='INPUT')
			{
				if (control.form[i2].type=='radio')
				{
					// Moved onto a radio button, find selected
					i3 = i2;
					while (control.form[i3].name==control.form[i2].name)
					{
						if (control.form[i3].checked)
						{
							i2 = i3;
							break;
						}
						i3 = (i3+1);
						if (i3>=control.form.length)
							break;
					}
				}
			} else if (control.form[i].tagName=='INPUT')
			{
				if (control.form[i].type=='radio')
				{
					// On a radio button, find control after
					i3 = i2;
					while (control.form[i3].name==control.form[i2].name)
					{
						i3 = (i3+1);
						if (i3>=control.form.length)
							break;
					}
					i2 = (i3 % control.form.length);
				}
			}
//			input.form[(getIndex(control) % input.form.length].focus();
			control.form[i2].focus();
//			control.focus();
			event.keyCode=0;
		}
	}
	return true;
}

function doKeyL(event, control, maxchars)
{
	var sel;
	if (ie)
	{
		sel = document.selection.createRange().text;
		if ((event.keyCode>=32 || event.keyCode==13) && control.value.length==maxchars && sel.length==0)
			event.keyCode=0;
	}
	if (ns)
	{
		sel = document.getSelection();
		if ((event.which>=32 || event.which==13) && control.value.length==maxchars && sel.length==0)
			event.which=0;
	}
}
function doKey2(event, control)
{
	if (ie || ns6)
	{
		if (event.keyCode==13)	{
			control.focus();
			event.keyCode=0;
		}
	}
	if (ns)
	{
		if (event.which==13)	{
			control.focus();
			event.which = 0;
		}
	}
}

function getDigits(stringValue)
{
	var t;
	var z;
	var v;

	v = "";
	for (t=0; t<stringValue.length; t++ )	
	{
		z = stringValue.substr(t,1);
		if ( z>='0' && z<='9' )
		{
			v +=z;
		}
	}
	return v;
}

function getPhone(stringValue)
{
	var t;
	var z;
	var v;
	var i;

	i = "" + stringValue;
	i.toLowerCase();

	v = "";
	for (t=0; t<i.length; t++ )	
	{
		z = i.substr(t,1);
		switch(z)
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	v += "" + z; break;
			case 'a':
			case 'b':
			case 'c':	v += "2";	break;
			case 'd':
			case 'e':
			case 'f':	v += "3";	break;
			case 'g':
			case 'h':
			case 'i':	v += "4";	break;
			case 'h':
			case 'k':
			case 'l':	v += "5";	break;
			case 'm':
			case 'n':
			case 'o':	v += "6";	break;
			case 'p':
			case 'r':
			case 's':	v += "7";	break;
			case 't':
			case 'u':
			case 'v':	v += "8";	break;
			case 'w':
			case 'x':
			case 'y':	v += "9";	break;
		}
	}
	return v;
}

var menuList = new Array();
var interval;

function selection(item, menu, subMenu, style)
{
	this.item = item;
	this.menu = menu;
	this.subMenu = subMenu;
	this.style = style;
}

function getRealLeft(obj) {
	xPos = obj.offsetLeft;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getRealTop(obj) {
	yPos = obj.offsetTop;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function hideSubMenuFrom(level)
{
	var obj;
	while(menuList.length>level)
	{
		obj = menuList[menuList.length-1];
		if (is_ie && !is_ie5_5up) {
			menuList.length = menuList.length-1 //simulate pop for ie5
		} else {
			menuList.pop();
		}
		domouseout(obj.item, '.'+obj.style);
		if (obj.subMenu!=null)
			obj.subMenu.style.visibility = 'hidden';
	}
}

function findSubMenu(subMenu)
{
	for (t=0;	t<menuList.length;	t++ )
		if (menuList[t].subMenu==subMenu)
			return t;
	return -1;
}

function findMenu(menu)
{
	for (t=0;	t<menuList.length;	t++ )
		if (menuList[t].menu==menu)
			return t;
	return -1;
}

function showMenu(item, menuName, subMenuName, normalStyle, highlightStyle)
{
	var subMenu, menu, level, menuSelection;
 
	if (subMenuName!='')
		subMenu=eval('document.all.'+subMenuName);
	else
		subMenu = null;

	if (menuName!='')
		menu = eval('document.all.'+menuName);
	else
		menu = null

	level = findSubMenu(menu);
	hideSubMenuFrom(level+1);

	level = findMenu(menu);
	if (level==-1) {
		//push pop doesn't work on ie5
		if (is_ie && !is_ie5_5up) {
			menuSelection  = new selection(item, menu, subMenu, normalStyle);
			level=level+1;
			menuList[level] = menuSelection;
		} else {
			menuList.push( new selection(item, menu, subMenu, normalStyle) );
		}
	}
	level = findMenu(menu);

	domouseout( menuList[level].item, '.'+menuList[level].style );
	menuList[level].item = item;
	if (menuList[level].subMenu!=null)
		menuList[level].subMenu.style.visibility = 'hidden';
	menuList[level].subMenu = subMenu;
	menuList[level].style = normalStyle;

	domouseover(item,'.'+highlightStyle);

	if (subMenu!=null)
	{
		subMenu.style.left = getRealLeft(item) + item.offsetWidth+4;
		subMenu.style.top = getRealTop(item)-10;
		subMenu.style.visibility = 'visible';
	}

}

function closeMenu()
{
	hideSubMenuFrom(0);
}

function leftMenu()
{
	interval = setInterval("closeMenu()", 500);
}

function enterMenu()
{
	clearInterval(interval);
}

function passback(id,entered,display)
{
   if (window.opener && !window.opener.closed) 
   {
		if (document.entryform.fv.value!='')
		{
			obj = eval('window.opener.document.entryform.'+document.entryform.fv.value)
			if (obj)
			{
				obj.value = id
			}
		}
		if (document.entryform.fd.value!='')
		{
			obj = eval('window.opener.document.entryform.'+document.entryform.fd.value)
			if (obj)
			{
				obj.value = display
			}
		}
		if (document.entryform.fe.value!='')
		{
			obj = eval('window.opener.document.entryform.'+document.entryform.fe.value)
			if (obj)
			{
				obj.value = entered
				obj.focus();
			}
		}
		window.close();
   }
}

function selectclose()
{
	if (window.opener && !window.opener.closed) 
	{
		if (document.entryform.fe.value!='')
		{
			obj = eval('window.opener.document.entryform.'+document.entryform.fe.value)
			if (obj)
				obj.focus();
		}
		window.close();
	}
}

function select(control,link,store,enter,display,width,height)
{
	var newWin, left, top;
	store = escape(''+store);
	enter = escape(''+enter);
	display = escape(''+display);
	value = escape(''+control.value);
	left = (screen.availWidth-width)/2;
	top = (screen.availHeight-height)/2;
	newWin=open(link+'&fv='+store+'&fe='+enter+'&fd='+display+'&ve='+value,'_select','resizable=no,width='+width+',height='+height+',left='+left+',top='+top);
}

//---------------------------------------------------
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
	var i;
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	for (i=0; i<selLength; i++)
	{
		if (theSel.options[i].value==theValue)
			break;
	}
	//	If not in list add it
	if(i==theSel.length)
		theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{	
	var selLength = theSel.length;
	for(i=theSel.length-1; i>=0;	i--)
	{
		if(theSel.options[i].selected)
			theSel.options[i] = null;
	}
}

function moveOptions(theSelFrom, theSelTo)
{
	var selLength = theSelFrom.length;
	var i;
	
	// Find the selected Options and add to the To select
	for(i=0; i<selLength;	i++)
	{
		if(theSelFrom.options[i].selected)
		{
			addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value);
		}
	}
	if(NS4) history.go(0);
}

function selectAll(list)
{
	var i;
	for (i=0;	i<list.options.length;	i++)
		list.options[i].selected = true;
}


function mainmenu(loc) {
	var vWidth, vHeight, appWindow;
	if (screen.availWidth>800)
	{
		vWidth=775;
		vHeight=527;
	}
	else
	{
		vWidth=screen.availWidth-10;
		vHeight=screen.availHeight-50;
	}

	var appWindow = window.open(loc,"_blank",
						"scrollbars,status, width="+vWidth+",height="+vHeight+
						",top=1,left=1,resizable=no,location=no,fullscreen=no");

	//11/7/2002 Scott Snedecor
	//          Rather than re-size the window from which they launched SBE,
	//	    we return it to the previous page. This gives the illusion
	//	    that they never left that page.
	//window.moveTo(0,0);
	//window.resizeTo(vWidth,vHeight);

       if (history.length > 0 ) {
	  history.back(-1);
	 }
       else {
	 window.moveTo(1,1);
	 window.resizeTo(vWidth,vHeight);
	 window.location = "restart.asp"
	}
}

function FormatPrintDate()
// Formats the date as Wednesday, December 3, 2003 
// (esp. for printing on printer-friendly page)
{
	var a,b,c,d,e,f;
	var d = new Date();
	a = d.getMonth()+1;

	e = d.getDay()+1;
	if(e ==1) {
	f = "Sunday"
	}
	else if(e ==2) {
	f = "Monday"
	}
	else if(e ==3) {
	f = "Tuesday"
	}
	else if(e ==4) {
	f = "Wednesday"
	}
	else if(e ==5) {
	f = "Thursday"
	}
	else if(e ==6) {
	f = "Friday"
	}
	else if(e ==7) {
	f = "Saturday"
	}

	if (a==1) {
	b = "January"
	}
	else if(a==2) {
	b = "February"
	}
	else if(a==3) {
	b = "March"
	}
	else if(a==4) {
	b = "April"
	}
	else if(a==5) {
	b = "May"
	}
	else if(a==6) {
	b = "June"
	}
	else if(a==7) {
	b = "July"
	}
	else if(a==8) {
	b = "August"
	}
	else if(a==9) {
	b = "September"
	}
	else if(a==10) {
	b = "October"
	}
	else if(a==11) {
	b = "November"
	}
	else if(a==12) {
	b = "December"
	}

	c = d.getDate();
	d = d.getYear();

	return (f+", " +b +" " +c + ", " +d)
}


function PrintThisPage()
// Produces printer-friendly page
{
	var sOption="tollbar=yes,location=no,directories=yes,menubar=yes,";
	sOption+="scrollbars=yes,width=750,height=600,left=100,top=25";

	var sWinHTML=document.getElementById('contentstart').innerHTML;

	document.open();
	document.write('<html><LINK href="../glb/lookweb.css" rel=Stylesheet><body>');
	document.write('<input type=button style="width:88px;" value="Print" onClick="javascript:window.print()"> ')
	document.write('<input type=button style="width:88px;" value="Back" onClick="javascript:history.back()">')
	document.write('<hr>')
	document.write(sWinHTML);

	document.write('<hr>')
	document.write('(Printed from www.charmeck.org on ' + FormatPrintDate() + ')')

	document.write('<SCRIPT>window.print()</SCRIPT>');
	document.write('</body></html>');
	document.close();
	focus();
}