var paste_off = false;

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);

    var nWin = ""
   
// 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;
}

/***********************************************************************************************
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 ***********************************************************************************************
 */
// Declaring valid date character, minimum year and maximum year

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


// Apparently netscape doesn't support background color changing...

function dbDate( control )
{
	var fDate;
	var y = "";
	var z;
	var t;
	var digits;
	
	db( control );
	
	fDate = formatDate(control.value);

        if (fDate != "")
         {
 	   if (isDate(fDate)==true)
           {
	       if (fDate.substr(2,1)=='/' && fDate.substr(5,1)=='/')
	    	{
			control.value = fDate;
			control.style.color = 0x000000;
		} 
       	   }
            else
               {
		//control.focus();	
                control.style.color = 0xff0000;
   	       }
          }
}


function formatDate(fDate)
{
 	var y = "";
	var z;
	var t;
	var digits;

	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);
	}
	return fDate;
}

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 chklen(object, evnt, lenlimit)
{
   if (object.value.length > lenlimit) {
      //alert("This field is limited to " + lenlimit + " characters.  Your input will be trimmed.");
      object.value = object.value.substring (0, lenlimit);
      return false;
   }
   return true;
}

function xclipboardchk(object, event, maxchars)
{
	var copiedtext, sel, allowable, newlen, newtext;

	sel = document.selection.createRange().text;	
	copiedtext=window.clipboardData.getData('Text');
	allowable = maxchars - object.value.length + sel.length - copiedtext.length;	//allowable to fill
	if (allowable <= 0)
	{
		//alert("chars to paste is " + (-allowable) + " too long");
		newlen = copiedtext.length - (-allowable);
		window.clipboardData.setData('Text', (copiedtext.substring (0, newlen)));
		newtext=window.clipboardData.getData('Text');
		//alert("clipboard now contains: " + newtext);
	}
}

function clipboardchk(object, event, maxchars)
{
	var copiedtext, sel, allowable, newlen, newtext;

	sel = document.selection.createRange().text;	
	copiedtext=window.clipboardData.getData('Text');
	allowable = maxchars - object.value.length + sel.length - copiedtext.length;	//allowable to fill
	if (allowable <= 0)	//Sorry, no room to paste the whole string
	{
		//alert("chars to paste is " + (-allowable) + " too long");
		newlen = copiedtext.length - (-allowable);
		//window.clipboardData.setData('Text', (copiedtext.substring (0, newlen)));
		newtext=copiedtext.substring (0, newlen);
		//alert("New text: " + newtext);
		//alert("Selection is " + document.selection.createRange().text);
		document.selection.createRange().text = newtext;
		//alert("Selection is now " + document.selection.createRange().text);		
		paste_off = true;
	}
	else return true;
}

function checkpaste()
{
	if (paste_off)
	{
		paste_off = false;
		return event.returnValue = false;
	}
}

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('<html><LINK href="../glb/look.css" rel=Stylesheet><body>');

	document.write('<html>')
	document.write('<LINK href="../glb/lookweb.css" rel=Stylesheet>');
	document.write('<LINK href="../glb/look.css" rel=Stylesheet>');
	document.write('<body>')

	document.write(sWinHTML);

	document.write('<hr>')
	document.write('(Printed from www.charmeck.org on ' + FormatPrintDate() + ')')

	document.write('</body></html>');
	document.close();
	focus();
}

/**********************************************************************
HTML CALENDAR CONTROL
copyright (c) 2001 The Ashley Group, Ltd.
ALL RIGHTS RESERVED
**********************************************************************

Created By:     Patrick Milliken
Creation Date:  5/15/2001

Purpose:        The Calendar Control is a pop-up calendar that writes
				a user-selected date back to a specified text box on
				the calling form. The calling form opens a pop-up
				window, then this code dynamically writes the calendar
				HTML to the window. No separate Calendar.HTM exists
				for this control.

Modified By:    Patrick Milliken
Last Mod Date:  6/11/2001

**********************************************************************/

/*--------------------------------------------------------------
 Declare and initialize global variables
----------------------------------------------------------------*/
var ActiveDate
var theMonth
var theDate
var theYear
var theFirst
var firstDay

/*--------------------------------------------------------------
 Build the HTML for the calendar based on the date argument then
 write the HTML to the pop-up window.
----------------------------------------------------------------*/
function doCalendar(ActiveDate)
	{
	Today = new Date()
	theDate = ActiveDate.getDate()
	theMonth = ActiveDate.getMonth() + 1
	theYear = ActiveDate.getFullYear()
	FOM = new Date(theMonth + '/1/' + theYear)
	firstDay = FOM.getDay()
	lastDay = getLastDay(theMonth, theYear)
	ColWidth = 35
	
	// Build the Header.
	
	HTML = '<html><head><title>Calendar</title>'
		+ '<link rel="stylesheet" href="cal_htm.css" type="text/css">'
		+ '<style type="text/css">a {text-decoration:none;} a:hover {color:#CC0000; text-decoration:underline;}</style></head>'
		+ '<body bgcolor="#000000" text="#000000" link="#000066" vlink="#000066" '
		+ 'alink="#CC0000" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">'
		+ '<form action="calendar.htm" method="post" name="frmForm">'
		+ '<table border="0" cellspacing="1" cellpadding="1" align="center">'
		+ '<tr>'
		+ '<td colspan="7" bgcolor="#003399">'
		+ '<table width="100%" border="0" cellspacing="0" cellpadding="0" height="16">'
		+ '<tr>'
		+ '<td align="left" valign="middle" width="25%" nowrap bgcolor="FFFF00">'
		+ '<a href="javascript:opener.changeYear(\'' + ActiveDate + '\', -1)" title="Go To Last Year"><span class="HeaderCell">&lt;&lt;</span></a><span class="HeaderCell">&nbsp;&nbsp;</span>'
		+ '<a href="javascript:opener.changeMonth(\'' + ActiveDate + '\', -1)" title="Go To Last Month"><span class="HeaderCell">&lt;</span></a></td>'
		+ '<td align="center" valign="middle" bgcolor="FFFF00">'
		+ '<span class="HeaderCell">' + returnMonth(theMonth) + ' ' + theYear + '</span></td>'
		+ '<td align="right" valign="middle" width="25%" nowrap bgcolor="FFFF00">'
		+ '<a href="javascript:opener.doToday()" title="Go To Today"><span class="HeaderCell">^</span></a><span class="HeaderCell">&nbsp;&nbsp;</span>'
		+ '<a href="javascript:opener.changeMonth(\'' + ActiveDate + '\', 1)" title="Go To Next Month"><span class="HeaderCell">&gt;</span></a><span class="HeaderCell">&nbsp;&nbsp;</span>'
		+ '<a href="javascript:opener.changeYear(\'' + ActiveDate + '\', 1)" title="Go To Next Year"><span class="HeaderCell">&gt;&gt;</span></a></td>'
        + '</tr>'
		+ '</table>'
		+ '</td>'
		+ '</tr>'
		+ '<tr>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>S</b></span></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>M</b></font></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>T</b></span></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>W</b></span></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>T</b></span></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>F</b></span></th>'
		+ '<th width="' + ColWidth + '" bgcolor="#CCCCCC" align="center"><span class="BodyCell"><b>S</b></span></th>'
		+ '</tr>'
	
	// Build the Body.

	HTML += '<tr align="center" valign="middle">'
	
	for (i = 1; i <= 5; i++)
		{
		for (j = 1; j <= 7; j++)
			{
			theDay = (j + ((i - 1) * 7) - firstDay)
			if (theDay < 1 && firstDay + lastDay > 35)
				{
				theDay = (35 - firstDay) + j
				}
			if (theDay < 1 || theDay > lastDay)
				HTML += '<td width="' + ColWidth + '" height="22" bgcolor="#CCCCCC">&nbsp;</td>'
			else
				{
				if (theMonth + "/" + theDay + "/" + theYear == getDate(UserDate) && getDate(UserDate) != getDate(Today))
					HTML += '<td width="' + ColWidth + '" height="22" bgcolor="#FFFFFF"><span class="UserDate">' + theDay + '</span></td>'
				else
					{
					HTML += '<td width="' + ColWidth + '" height="22" width="27" bgcolor="#FFFFFF"><a href="javascript:opener.ReturnValue(\'' + theMonth + "/" + theDay + "/" + theYear + '\')">'
					if (theMonth == Today.getMonth() + 1 && theDay == Today.getDate() && theYear == Today.getFullYear())
						HTML += '<span class="Today">' + theDay + '</span></a></td>'
					else
						HTML += '<span class="BodyCell">' + theDay + '</span></a></td>'
					}
				}
			}
		if (i != 5)
			HTML += '</tr><tr align="center" valign="middle">'
		}
	
	// Build the Footer.
	
	HTML += '</tr></table>'
		+ '<table width="100%" bgcolor="#FFFF00" cellpadding="3" cellspacing="0" border="0">'
		+ '<tr><td align="center" valign="middle" bgcolor="FFFF00">'
		//+ '<span class="Address"><a href="http://www.ashleygrp.com" target="_blank">&copy; 1996-2001</span>'
		//+ '<span class="Address">The Ashley Group, Ltd.</span></a>'
		+ '</td></tr></table>'
		+ '<input type="hidden" name="ActiveDate" value="' + ActiveDate + '">'
		+ '</form></body></html>'
	
	// Write the complete HTML to the pop-up window.
	
	nWin.document.open("text/html")
	nWin.document.write(HTML)
	nWin.document.close()
	}
	
/*--------------------------------------------------------------
 Return a date formatted as MM/DD/YYYY.
----------------------------------------------------------------*/
function getDate(DateVal)
	{
	return((DateVal.getMonth() + 1) + "/" + DateVal.getDate() + "/" + DateVal.getFullYear())
	}
	
/*--------------------------------------------------------------
 Handle a click on the last or next month links.
----------------------------------------------------------------*/
function changeMonth(ActiveDate, offset)
	{
	ActiveDate = new Date(ActiveDate)
	theMonth = ActiveDate.getMonth() + (1 + offset)
	theYear = ActiveDate.getFullYear()
	if (theMonth < 1)
		{
		theMonth = 12
		theYear--
		}
	else if (theMonth > 12)
		{
		theMonth = 1
		theYear++
		}
	ActiveDate = new Date(theMonth + '/' + ActiveDate.getDate() + '/' + theYear)
	doCalendar(ActiveDate)
	}

/*--------------------------------------------------------------
 Handle a click on the last or next year links.
----------------------------------------------------------------*/
function changeYear(ActiveDate, offset)
	{
	ActiveDate = new Date(ActiveDate)
	theMonth = ActiveDate.getMonth() + 1
	theYear = ActiveDate.getFullYear() + (1 * offset)
	ActiveDate = new Date(theMonth + '/' + ActiveDate.getDate() + '/' + theYear)
	doCalendar(ActiveDate)
	}
	
/*--------------------------------------------------------------
 Handle a click on the Go To Today link.
----------------------------------------------------------------*/
function doToday()
	{
	ActiveDate = new Date()
	doCalendar(ActiveDate)
	}

/*--------------------------------------------------------------
 Return the last day of the month for the specified month and
 year (note the leap year calculation).
----------------------------------------------------------------*/
function getLastDay(theMonth, theYear)
	{
	if (theMonth != 2)
		{
		if (theMonth == 4 || theMonth == 6 || theMonth == 9 || theMonth == 11)
			return(30)
		else
			return(31)
		}
	else
		{
		if (theYear % 4 > 0)
			return(28)
		else if (theYear % 100 > 0)
			return(29)
		else if (theYear % 4 == 0)
			return(29)
		else
			return(28)
		}
	}
	
/*--------------------------------------------------------------
 Return the name of the month based on the month's numeric
 value.
----------------------------------------------------------------*/
function returnMonth(theMonth)
	{
	if (theMonth == 1)
		return('January')
	else if (theMonth == 2)
		return('February')
	else if (theMonth == 3)
		return('March')
	else if (theMonth == 4)
		return('April')
	else if (theMonth == 5)
		return('May')
	else if (theMonth == 6)
		return('June')
	else if (theMonth == 7)
		return('July')
	else if (theMonth == 8)
		return('August')
	else if (theMonth == 9)
		return('September')
	else if (theMonth == 10)
		return('October')
	else if (theMonth == 11)
		return('November')
	else if (theMonth == 12)
		return('December')
	}

/*--------------------------------------------------------------
 When a user clicks on a day of the month, write the date value
 back to the specified text box on the calling form.
----------------------------------------------------------------*/
function ReturnValue(theDate)
   {
    /*------------------------------------------------------------------
	// Modified theDate - PL 5/17/04
	// Get The Month
	//pos=theDate.indexOf("/")
	//if (pos<2) { mon = theDate.substr(0,pos);
    //			mon = '0' + mon
    //	}
	// Get the Day
    //	da = theDate.substr(pos + 1,2)
    //	if (da.indexOf("/") > 0) { 
    //		ida = da.indexOf("/")
    //		da = da.substr(0,ida)
    //		if (da.length < 2) { da = '0' + da }
    //	}
    // Get the Year	
    //	last = theDate.lastIndexOf("/")
    //	yer = theDate.substr(last + 1, theDate.Length)
    //	
	// Format the Date	
    //	theDate = mon + '/' + da + '/' + yer   */
    
    // Modified 05/27/2004 -commented out 5/17/04 modification and just called the formatDate function
    // Note : Internet Apps using Infrastructure form element is 1, but for internal apps it is 0.    
    theDate = formatDate(theDate)
	document.forms[0].elements[ReturnEl].value = theDate
	CloseNWin()
   }   



function showCalendar(elName, cTop, cLeft)
	{
	Height = 170
	Width = 245
	Top = 0
	Left = 0
	
	Top = cTop
	Left = cLeft
	if (nWin == "")
		{
		nWin = window.open("", "Calendar", "height=" + Height + ",width=" + Width 
			+ ",top=" + Top + ",left=" + Left + ",status=no,toolbar=no,menubar=no,"
			+ "location=no,resizable=no,scrollbars=no")
		nWin.opener = window
		}
	else
		{
		CloseNWin()
		showCalendar(elName)
		}	
	ReturnEl = elName
	//el = document.forms["FormName"].elements[elName]
        // Note : Internet Apps using Infrastructure form element is 1, but for internal apps it is 0.    	
	el = document.forms[0].elements[elName]
	UserDate = new Date(el.value)
	if (isNaN(UserDate)) UserDate = new Date()
	datNow = new Date(UserDate)
	doCalendar(datNow)
	}
	
function CloseNWin()
	{
	if (nWin != "")
		{
		nWin.close()
		nWin = ""
		}
	}
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)
}


