
var wtid = new Image();
wtid.src = '/inc/webtrack.aspx?x='+screen.width+'&y='+screen.height;

/********************************************************************************
*	STRING OBJECT EXTENDERS
*********************************************************************************
*	Methods:
*		toProperCase()	Converts first character and characters following a space 
*						to uppercase.
*		trim()			Remove leading and trailing whitespace
*		toInteger()		Whole Number or 0
*		toDecimal()		Decimal Number or 0.0
*		reverse()		String in reverse order
*		toCurrency()	Number formated to $0.00
********************************************************************************/
if(typeof String.prototype.toProperCase!='function'){
	String.prototype.toProperCase=function(){
	/* Capitalize any char following a word boundary */
		var b=1;		/* Flag indicating next character is uppercase */
		var o="";		/* return value */
		
		for(var i=0;i<this.length;i++){
			o+=(b)?this.charAt(i).toUpperCase():this.charAt(i).toLowerCase();
			b=!(/\w/.test(this.charAt(i)));
		}
		return o;
	}
}

if(typeof String.prototype.trim!='function'){
	String.prototype.trim=function(){
	/* trim starting and ending whitespace */
		var o=this.valueOf();
		if( /^[\s]+$/ig.test(o) ) return '';
		o = o.replace(/^[\s]/ig, '');
		o = o.replace(/[\s]$/ig,'');
		return o;
	}
}
	
if(typeof String.prototype.toInteger!='function'){
	String.prototype.toInteger=function(){
	/* Remove any non digit */
		var o="";
		for(var i=0;i<this.length;i++){
			o+=(/\d/.test(this.charAt(i)))?this.charAt(i):"";
		}
		return (o=='')?0:o;
	}
}
if(typeof String.prototype.toDigits!='function'){
	String.prototype.toDigits=function(){
	/* Remove any non digit */
		var o="";
		for(var i=0;i<this.length;i++){
			o+=(/\d/.test(this.charAt(i)))?this.charAt(i):"";
		}
		return o;
	}
}
if(typeof String.prototype.toDecimal!='function'){
	String.prototype.toDecimal=function(){
	/*	Remove any non-digit except for a period.
		Any chars after a second period are lost.	*/
		var o="";	/* Return value */
		var d=0;	/*	Number of found decimal points. 
						Used to exit after 2nd on found 	*/

		for(var i=0;i<this.length;i++){
			if(/[\.]/.test(this.charAt(i))){d++}
			if(d>1){return o}
			o+=( /[\d\.]/.test(this.charAt(i)))?this.charAt(i):"";
		}
		return (o=='')?0.0:o;
	}
}

if(typeof String.prototype.reverse!='function'){
	String.prototype.reverse=function(){
	/* Reverse the order of the string */
		var o="";
		for(var i=(this.length-1);i>=0;i--){o+=this.charAt(i);}
		return o;
	}
}

if(typeof String.prototype.toCurrency!='function'){
	String.prototype.toCurrency=function(){
	/* Returns formated number to $##,##0.## */
		var o=''+this.toDecimal();	/* Convert string into floating number format	*/
		if(isNaN(o) || o==0){		/* Quick return and prevent errors				*/
			return '$0.00';
		}	
		
		o=''+Math.round(o*100);		/* Round up to truncate excess decimal places	*/
		var r='', b=0;
		o=o.reverse();				/* For easier digit grouping					*/
		if(o.length==2){o=o+"0";}	/* Add leading zero for value under 1 dollar	*/
		
		for(var i=0;i<o.length;i++){/* Find Group points and add comma				*/
			r+=o.charAt(i);			/* Add each character to return value			*/
			if(i==1){r+="."}		/* Readd decimal point to return value			*/
			if(b){r+=","}			/* check group flag and add comma if true		*/
			b=(						/* Set group flag based on the following:		*/
				(i>2) &&			/* After Decimal								*/
				(i<(o.length-2)) && /* We have room at end							*/
				(i%3==0)			/* This is a group location						*/
			  )?1:0;				/* Set flag to add comma at next iteration		*/
		}
		return "$"+r.reverse();		/* Flip back to proper order and return			*/
	}
}

if(typeof String.prototype.isEmail!='function'){
	String.prototype.isEmail=function(){
	/*Return true if validates to email address format. */
		var o=this.valueOf();
		return /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(o)?true:false;
	}
}

if(typeof String.prototype.isAlphaNumeric!='function'){
	String.prototype.isAlphaNumeric=function(){
	/*Return true if validates to email address format. */
		var o=this.valueOf();
		return /^[a-zA-Z0-9]+$/.test(o)?true:false;
	}
}
if(typeof String.prototype.isNumeric!='function'){
	String.prototype.isNumeric=function(){
	/*Return true if validates to email address format. */
		var o=this.valueOf();
		return /^\d+$/.test(o)?true:false;
	}
}
if(typeof String.prototype.isAlpha!='function'){
	String.prototype.isAlpha=function(){
	/*Return true if validates to email address format. */
		var o=this.valueOf();
		return /^[a-zA-Z]+$/.test(o)?true:false;
	}
}
if(typeof String.prototype.toZip!='function'){
	String.prototype.toZip=function(){
	/*Return true if validates to email address format. */
		var o=this.valueOf();
		o=o.replace(/\D/g,'');
		switch(o.length){
			case 5:return o; break;
			case 9:return ''+o.substring(0,5)+'-'+o.substring(5,9); break;
			default:return o;
		}
	}
}

/********************************************************************
*	MATH OBJECT EXTENDERS
*********************************************************************
*	Methods:
*		pmt(dRPP, dT,dPV)	Calculate amortized payment
*		Arguments:
*			dRPP:	Rate Per Period
*			dT:		Number of Periods
*			dPV:	Present Value/Amount
*
*	NOTE:
*	Math object extended direcly to prevent generic object extension.
********************************************************************/
if(typeof Math.Pmt!='function'){
	/* Extend Math object to include amortization function */
	Math.Pmt=function(dRPP, dT,dPV){
		/* dRPP: Rate Per Period, dT: Number of Periods, dPV: Present Value/Amount */
		var acc=0;
		var b=1+parseFloat(dRPP);
		for (var i=1;i<=parseInt(dT);i++){acc += Math.pow(b,-i);}
		return parseFloat(dPV)/acc;
	}
}

/********************************************************************
*	DATE OBJECT EXTENDERS
*********************************************************************
*	Methods:				Output
*		toShortDate()		MM/DD/YYYY
*		toSortDate()		YYYY-MM-DD
*		toLongDate()		MMMM DD, YYYY
*		toShortTime()		HH:MM AM/PM
*		toLongTime()		HH:MM:SS AM/PM
*		toShortDateTime()	MM/DD/YYYY HH:MM AM/PM
*		toLongDateTime()	MMMM DD, YYYY HH:MM:SS AM/PM
********************************************************************/
if(typeof Date.prototype.toShortDate!='function'){
	Date.prototype.toShortDate=function(){
	/* Output Date As MM/DD/YYYY */
		return ""+(this.getMonth()+1)+"/"+this.getDate()+"/"+this.getFullYear();
	}
}

if(typeof Date.prototype.toSortDate!='function'){
	Date.prototype.toSortDate=function(){
	/* Output Date As YYYY-MM-DD */
		return ""+this.getFullYear()+"-"+this.getDate()+"-"+(this.getMonth()+1);
	}
}

if(typeof Date.prototype.toLongDate!='function'){
	Date.prototype.toLongDate=function(){
	/* Output Date As MMMM DD, YYYY */
	var am=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var ad=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
		return ""+ad[this.getDay()]+", "+(am[this.getMonth()])+" "+this.getDate()+", "+this.getFullYear();
	}
}

if(typeof Date.prototype.toShortTime!='function'){
	Date.prototype.toShortTime=function(){
	/* Output Date As HH:MM AM/PM */
	var o="";
	o+=(this.getHours()>12)?(this.getHours()-12):(this.getHours());
	o+=(this.getMinutes()>9)?":"+this.getMinutes():":0"+this.getMinutes();
	o+=(this.getHours()>12)?" PM":" AM.";
	return o;
	}
}

if(typeof Date.prototype.toLongTime!='function'){
	Date.prototype.toLongTime=function(){
	/* Output Date As HH:MM:SS AM/PM */
	var o="";
	o+=(this.getHours()>12)?(this.getHours()-12):(this.getHours());
	o+=(this.getMinutes()>9)?":"+this.getMinutes():":0"+this.getMinutes();
	o+=(this.getSeconds()>9)?":"+this.getSeconds():":0"+this.getSeconds();
	o+=(this.getHours()>12)?" PM":" AM.";
	return o;
	}
}

if(typeof Date.prototype.toShortDateTime!='function'){
	Date.prototype.toShortDateTime=function(){
	/* Output Date As MM/DD/YYYY */
		return this.toShortDate()+" "+this.toShortTime();
	}
}

if(typeof Date.prototype.toLongDateTime!='function'){
	Date.prototype.toLongDateTime=function(){
	/* Output Date As MM/DD/YYYY */
		return this.toLongDate()+" "+this.toLongTime();
	}
}

//if(typeof Number.prototype.toSource!='function'){
//	Number.prototype.toSource=function(){return this+''}
//}

//if(typeof String.prototype.toSource!='function'){
//	String.prototype.toSource=function(){
//		var str=this;
//		str=str.replace(/\\/g, "\\\\");
//		str=str.replace(/\"/g, "\\\"");
//		str=str.replace(/\n/g, "\\n");
//		str=str.replace(/\r/g, "");
//		return '"'+str+'"';
//	}
//}

//if(typeof Boolean.prototype.toSource!='function'){
//	Boolean.prototype.toSource=function(){return this+'';}
//}

//if(typeof Function.prototype.toSource!='function'){
//	Function.prototype.toSource=function(){return this+'';}
//}

//if(typeof Array.prototype.toSource!='function'){
//	Array.prototype.toSource=function(){
//		var a=this
//		var s1='['
//		if (a.length>0) {
//			for (var i=0;i<a.length;i++) {
//				if ((a[i]+'')=='undefined') {
//					s1+=', '
//					continue;
//				}
//				s1+=a[i].toSource()+(i<a.length-1?',':'')
//			}
//		}
//		s1+=']'
//		return s1
//	}
//}

//if(typeof Object.prototype.toSource!='function'){
//	Object.prototype.toSource=function() {
//		var o=this
//		if (o==null) return 'null'
//		var s1=''
//		for (var item in o) {
//			if (item=="toSource") continue;
//			if (o[item]==null) {
//	//			s1+=item+':null, '
//				continue;
//			}
//			s1+=item+':'+o[item].toSource()+','
//		}
//		s1=s1.substr(0,s1.length-1)
//		s1='{'+s1+'}'
//		return s1
//	}
//}
function swapImage(n,s){
	if( document && document.images && n && document.images[n] && s){
		document.images[n].src=s;
	}
}

// WARNING: Will use form in future
function emlWarn(o){
	var b = new Array();
	var eml = (arguments.length>1)?arguments[0]:o.email;
	var dat = (arguments.length>1)?arguments[1]:o.data;

	b.w("Email Caution\n\n");
	b.w("Please do not include personal or confidential information in your email to ");
	b.w(eml);
	b.w(".\n\n");
	b.w("To send a secure message to Bank of Internet USA:\n");
	b.w("   * Sign into your account.\n");
	b.w("   * Select \"Message Center\" from the services dropdown menu.\n");
	b.w("   * Click Send a Message on the following page.\n\n");
	b.w("Click \"Cancel\" if you do not wish to continue sending message");
	
	if( confirm( b.join('') ) ){
		document.location.href="mailto:"+eml+dat;
	}
}
function clearOnce(fld){if( fld && (! fld.cleared) ){fld.cleared=1;fld.value='';}}

/********************************************************************
*	ARRAY OBJECT EXTENDERS
*	Extended to include buffer related functions.
*********************************************************************
*	Methods:	
*		add(itm)		-	Add item to end of array	
*		removeLast()	-	removes last item in the array
*		removeFirst()	-	removes first item in the array
*		remove(index)	-	index = index of item to remove
*		getIndex(value)	-	value = string to find
*		toString()		-	returns elements as string without delimiter.
*		writeLine(s)	-	add s to the end of the array along with a line break.
*		strSortAsc(i)	-	i = case insensitive; sorts array ascending
*		strSortDesc(i)	-	i = case insensitive; sorts array descending
* ALIASED 
*		write(s)	=>	add
*		w(s)		=>	add
*		writeLn(s)	=>	writeLine
*		wl(s)		=>	writeLine
********************************************************************/
if(typeof Array.prototype.add!='function'){Array.prototype.add = function(itm){this[this.length]=itm;}}
if(typeof Array.prototype.removeLast!='function'){Array.prototype.removeLast = function(){this.length--;}}
if(typeof Array.prototype.removeFirst!='function'){Array.prototype.removeFirst = function(){if( this.length==1 ){this.length--;return;}if( this.length > 1 ){for(var i=1; i<this.length; i++){this[i-1]=this[i];}this.length--;}}}
if(typeof Array.prototype.remove!='function'){Array.prototype.remove = function(index){if( this.length<parseInt(index) ) return;if( this.length > parseInt(index) ){for(index; index<(this.length-1); index++){this[index]=this[index+1];}this.length--;}}}
if(typeof Array.prototype.getIndex!='function'){/* Returns first occurence only; */Array.prototype.getIndex = function(value){for( var i=0;i<this.length;i++){if( this[i]==value ){return i;}}return 0;}}
if(typeof Array.prototype.toString!='function'){Array.prototype.toString = function(){return this.join('');}}
if(typeof Array.prototype.writeLine!='function'){Array.prototype.writeLine = function(s){this[this.length]=s+'\n';}}
if(typeof Array.prototype.strSortAsc!='function'){Array.prototype.strSortAsc = function(i){this.sort( function(a,b){if(i){a=(''+a).toLowerCase();b=(''+b).toLowerCase();}if(a<b){return -1}else if(a>b){return 1}else{return 0;}});}}
if(typeof Array.prototype.strSortDesc!='function'){Array.prototype.strSortDesc = function(i){this.sort( function(a,b){if(i){a=(''+a).toLowerCase();b=(''+b).toLowerCase();}if(a>b){return -1}else if(a<b){return 1}else{return 0;}});}}

/*	Buffer alias extensions	*/
if(typeof Array.prototype.write!='function'){Array.prototype.write = Array.prototype.add;}
if(typeof Array.prototype.w!='function'){Array.prototype.w = Array.prototype.add;}
if(typeof Array.prototype.writeLn!='function'){Array.prototype.writeLn = Array.prototype.writeLine;}
if(typeof Array.prototype.wl!='function'){Array.prototype.wl = Array.prototype.writeLine;}



/**********************************************************************
* Dropdown helpers
*/
function ddAddItems(dd,a, ad){
	for(var i in a){
		ddAddItem(dd,a[i].text,a[i].value,ad);
	}
}
function ddClear(dd){dd.options.length=0;return true;}
function ddAddItem(dd,text,value, ad){
	var oa=dd.options;
	if(! ad){
		for(var i=0;i<dd.options.length;i++){
			if(dd.options[i].value==value && dd.options[i].text==text){return}
		}
	}
	dd.options[dd.options.length]=new Option(text, value);
}
function ddRemoveItem(dd,itm){
	var a=[];
	for(var i=0;i<dd.options.length;i++){
		if( !(dd.options[i].value == itm.value && dd.options[i].text ==itm.text) ){
			a[a.length]=new Option(dd.options[i].text,dd.options[i].value);
		}
	}
	ddClear(dd);
	ddAddItems(dd,a);
}
function ddAutoFill(dd,s,e,np,vp){var a=[];for(var i=s;i<=e;i++){a[a.length]=new Option(np+i,vp+i);}ddAddItems(dd,a);}


/************************************************************************
* Sort comparison functions
*/
function stringCompA(a,b){
	if( (''+a) < (''+b) ){return -1}
	else if( (''+a) > (''+b) ){return 1}
	return 0;
}
function stringCompD(a,b){
	return ( stringCompA(a,b) * -1);
}
function numberCompA(a,b){
	a = (''+a).toDecimal();
	b = (''+b).toDecimal();
	if( Number(a) < Number(b) ){return -1}
	else if( Number(+a) > Number(+b) ){return 1}
	return 0;
}
function numberCompD(a,b){
	return ( numberCompA(a,b) * -1);
}
/***************************************************************************
*	Style and flair Related Functions
*	- highlightFields(frm, bg, bgFocus)
*/
function highlightFields(frm, bg, bgFocus){
	if(!document){return}
	if(!document.forms){return}
	for( var f=0; f < frm.elements.length; f++){
		switch( frm.elements[ f ].type ){
			case 'text':		// Treat all of the following the same
			case 'password':
			case 'textarea':
			if( typeof frm.elements[f].onfocus=='function' ){
				frm.elements[f].ff=frm.elements[f].onfocus;
				frm.elements[f].onfocus=function(){
					this.ff();
					var s=this.style||this;
					s.backgroundColor=bgFocus;
				}
			}else{
				frm.elements[f].onfocus=function(){
					var s=this.style||this;
					s.backgroundColor=bgFocus;
				}
			}
			if( typeof frm.elements[f].onblur=='function' ){
				frm.elements[f].fb=frm.elements[f].onblur;
				frm.elements[f].onblur=function(){
					this.fb();
					var s=this.style||this;
					s.backgroundColor=bg;
				}
			}else{
				frm.elements[f].onblur=function(){
					var s=this.style||this;
					s.backgroundColor=bg;
				}
			}
		}		
	}
}


/*
* COOKIES
*/
var cookies={
	add:	function(n,v,e,p,d){
				document.cookie = (n+'='+escape(v)+'; ')+	
					((e && e.toUTCString)?'expires='+e.toUTCString()+'; ':'')+
					(p?'path='+p+'; ':'')+
					(d?'domain='+d+'; ':'');
	},
	remove:	function(n,p,d){
				document.cookie = (n+'=; ')+	
					'expires=Thu, 01-Jan-70 00:00:01 GMT; '+
					(p?'path='+p+'; ':'')+
					(d?'domain='+d+'; ':'');
	},
	read:	function(n){
				var dc=document.cookie;
				if(dc.indexOf(n)> -1){
					var s = (dc.indexOf(n)+1+n.length);
					var e = (dc.indexOf(";", s) > -1)?dc.indexOf(";", s):dc.length;
					return unescape( dc.substring( s, e ) );
				}else{return '???'}
	},
	exists:	function(n){
				return (document.cookie.indexOf(n)> -1); 
	},
	getExp:	function(d){
				var dt=new Date(); 
				dt.setTime( dt.getTime()+(3600000 * 24 * d) ); 
				return dt;
	}
}



/************************************************************************************
*	HTMLElement expando
*	Used for simplified dhtml on ie4+ and dom browsers
*	Credited To: http://www.faqts.com/knowledge_base/view.phtml/aid/5756 
*/
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
		switch(where){
		case 'beforeBegin':	this.parentNode.insertBefore(parsedNode,this); break;
		case 'afterBegin':	this.insertBefore(parsedNode,this.firstChild); break;
		case 'beforeEnd':	this.appendChild(parsedNode); break;
		case 'afterEnd': 
			if(this.nextSibling){this.parentNode.insertBefore(parsedNode,this.nextSibling);}
			else{this.parentNode.appendChild(parsedNode);}
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr){
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr){
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}
function HitTest(o, pt, sz, hOver, hOff){
	if( !HitTest.seed ){HitTest.seed=0;}
	if( !HitTest.items ){HitTest.items=[];}
	this.name='HitTestObject'+(++HitTest.seed);
	
	// EVENTS
	this.onOver = hOver || function(){}
	this.onOut	= hOff || function(){}
	
	// PROPERTIES
	this.obj	= o || null;
	this.point	= pt;
	this.size	= sz;
	this.state	= 0;	// 0=off;1=over;
	
	// METHODS
	this.check	= function( m ){
		var r = false;
		if( m && m.x && m.y ){
			var p = this.point;
			var s = this.size;
			r = ( ( (m.x >= p.x) && (m.y >= p.y) ) && ( ( m.x <= (p.x+s.w)) && ( m.y <= (p.y+ s.h)) ) );
			if( r == true && this.state==0 && typeof this.onOver=='function' ){ this.onOver(this); }
			if( r == false && this.state==1 && typeof this.onOut=='function' ){ this.onOut(this); }
			this.state = (r==true)?1:0;
		}
		return r;
	}
	
	window[this.name]=this;
	HitTest.items[HitTest.items.length]=this;
	return this;
}
function point(x,y){ this.x=(x)?x:0; this.y=(y)?y:0; return this; }
function size(w,h){ this.w=(w)?w:0;	this.h=(h)?h:0;	return this; }

function MouseTracker( onmousemove ){
	var d = document;
	var m = MouseTracker;
	if( !m.point ){m.point=new point(0,0)}
	
	m.onMouseMove = onmousemove || function(){};
	
	m.getMousePos  = function(e){
		var d = document;
		var m = MouseTracker;
		var ht = HitTest;
		if( d.all && event && m.point){
			m.point.x = event.clientX+((d && d.body && d.body.scrollLeft)?d.body.scrollLeft:0);
			m.point.y = event.clientY+((d && d.body && d.body.scrollTop)?d.body.scrollTop:0);
		}else if( e && (e.pageX || e.pageY) && m.point){
			m.point.x = parseInt(e.pageX);
			m.point.y = parseInt(e.pageY);
		}
		if( m.point && typeof ht=='function' && ht.items && ht.items.length ){
			for( var i=0; i<ht.items.length; i++){
				ht.items[i].check( m.point );
			}
		}
		if( m.point && typeof m.onMouseMove=='function' ){ m.onMouseMove(m.point); }
	}
	
	// Event Tracking initialization
	if( d && d.captureEvents ){ d.captureEvents( Event.MOUSEMOVE ); }

	// Play nice with other objects by chaining event.
	// Always check for event handler prior to assignment
	if( typeof d.onmousemove=='function' ){
		m.mm = d.onmousemove;
		d.onmousemove = function(e){
				m.mm(e);
				m.getMousePos(e)
			};
	}else{
		d.onmousemove = m.getMousePos;
	}
}
function replaceClass(el, oc, nc){
	if( el && el.className && el.className.length && oc && nc ){
		var a = (''+el.className).split(' ');
		for( var i=0;i<a.length;i++){
			if(a[i]==oc){a[i]=nc}
		}
		el.className=a.join(' ');
	}
	
}
function addClass(el, c){
	if( el ){
		if( ! el.className ){el.className='';}
		var a = (''+el.className).split(' ');
		// Verify class not already present.
		var fnd = 0;
		for( var i=0;i<a.length;i++){if(a[i]==c){fnd=1;}}
		if(fnd==0) el.className=c+' '+a.join(' ');
	}
}
function removeClass(el, c){
	if( el && el.className ){
		var a = (''+el.className).split(' ');
		var fnd = 0;
		for( var i=0; i<a.length; i++ ){
			if( a[i]==c )a[i]='';
		}
		el.className=a.join(' ').replace('  ',' ');
	}
}
function hasClass(el, c){
	if(!(el||c))return false;
	if(! el.className )return false;
	var a = (''+el.className).split(' ');
	for( var i=0;i<a.length;i++){if(a[i]==c){return true;}}
	return false
}

if(typeof window.gE!='function'){
	window.gE = function(id){
		var d = document;
		if( d && d.getElementById ){
			return d.getElementById(id);
		}else if(d && d.all){
			return d.all[id];
		}else if( d && d.layers ){
			return d.layers[id];
		}
	}
}
if(typeof window.wL!='function'){
	window.wL = function(id, txt){
		var d = document;
		if( d.getElementById && d.getElementById(id) ){
			d.getElementById(id).innerHTML=txt;
		}else if(d.all){
			d.all[id].innerHTML=txt;
		}else if(d.layers){
			with(d.layers[id].document){
				open();write(txt);close();
			}
		}
	}
}

function displaySectionBelowInt( targetID, value, minValue){
	var t = window.gE(targetID);
	var v = (value+'').toInteger();
	var m = (minValue+'').toInteger();
	v = (v)?v:0;
	m = (m)?m:0;
	if(t){
		if( Number(v) < Number(m) )	{ removeClass(t,'collapsed')	}
		else		{ addClass(t,'collapsed')	}	
	}
}

function doTab(ctlId, tabId, bodyId, defT, defTB){
	var p = window.gE(ctlId);
	var t = window.gE(tabId);
	var b = window.gE(bodyId);
	
	if( p ){
		if( ! (p.tabselected || p.tabbodyselected )){
			p.tabselected = window.gE(defT);
			p.tabbodyselected = window.gE(defTB);
		}
		if( p.tabselected && p.tabbodyselected ){ 
			replaceClass( p.tabselected, 'tabselected','tab');
			replaceClass( p.tabbodyselected, 'tabbody','tabbodyhidden');
		}
		p.tabselected = t;
		p.tabbodyselected = b;
		if( p.tabselected && p.tabbodyselected ){ 
			replaceClass( p.tabselected, 'tab','tabselected');
			replaceClass( p.tabbodyselected, 'tabbodyhidden','tabbody');
		}
	}
}

function doExpandCollapse(el, TargID){
	if( el && TargID && el.className && document && document.getElementById && document.getElementById(TargID) ){
		var vis = (hasClass(el,'collapse')==true)?false:true;
		var tel = document.getElementById(TargID);
		var b = hasClass(tel, 'expanded');
		
		if( hasClass(tel, 'expanded') == true ){
			removeClass(tel,'expanded')
			addClass(tel,'collapsed')
			
			removeClass(el,'collapse')
			addClass(el,'expand')
		}else{
			removeClass(tel,'collapsed')
			addClass(tel,'expanded')
			
			removeClass(el,'expand')
			addClass(el,'collapse')
		}
	}
}

/* Use this for attaching events to allow user overrides */
function addHandler(evt, obj, handler){
	if( evt && obj && typeof handler=='function' ){
		if( obj.addEventListener ){
			obj.addEventListener(''+evt.toLowerCase(), handler, false); 
		}else if( obj.attachEvent ){
			obj.attachEvent('on'+evt.toLowerCase(), handler);
		}
	}
}

function getEventSrc(e){
	if( e && e.target) return  e.target;
	else if( window && window.event ) return window.event.srcElement;
	else return null;
}

function __setHover(el, state){
	var t='';
	if(el && state!=null){
		if(el.type){t= (''+el.type).replace(/[-]/g,'');}
		if(t.length==0 && el.tagName){t=el.tagName.toLowerCase();}

		if( state==1 ){	addClass(el,t+'Hover'); }
		else{ removeClass(el,t+'Hover'); }
		//document.title=el.className;
	}
	return true;
}
function __setSelect(el, state){
	var t='';
	if(el.type){t= (''+el.type).replace(/[-]/g,'');}
	if( state==1 ){	addClass(el,t+'Selected'); }
	else{ removeClass(el,t+'Selected'); }
	return true;
}
function __hoverOff(e){ __setHover( getEventSrc(e),0 ); }
function __hoverOver(e){ __setHover( getEventSrc(e),1 ); }
function __fieldFocus(e){ __setSelect( getEventSrc(e),1 ); }
function __fieldBlur(e){ __setSelect( getEventSrc(e),0 ); }
function __phone(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		var s = (''+el.value).replace(/\D/g,'');
		switch(s.length){
			case 7:
			el.value=s.substring(0,3)+'-'+s.substring(3,7)
			break;

			case 10:
			el.value='('+s.substring(0,3)+') '+s.substring(3,6)+'-'+s.substring(6,10);
			break;
			
			case 11:
			el.value=s.substring(0,1)+' '+'('+s.substring(1,4)+') '+s.substring(4,7)+'-'+s.substring(7,11);
			break;
			
			case 12:
			el.value=s.substring(0,2)+' '+'('+s.substring(2,5)+') '+s.substring(5,8)+'-'+s.substring(8,12);
			break;
			
			case 13:
			el.value=s.substring(0,3)+' '+'('+s.substring(3,6)+') '+s.substring(6,9)+'-'+s.substring(9,13);
			break;
			
			case 14:
			el.value=s.substring(0,4)+' '+'('+s.substring(4,7)+') '+s.substring(7,10)+'-'+s.substring(10,14);
			break;
			
			default:
			el.value=s;
		}
	}
}
function __ssn(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		var s = (''+el.value).replace(/\D/g,'');
		switch(s.length){
			case 9:
			el.value=s.substring(0,3)+'-'+s.substring(3,5)+'-'+s.substring(5,9);
			break;
			
			default:
			el.value=s;
		}
	}
}
function __zip(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		el.value=(''+el.value).toZip();
	}
}
function __money(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		el.value=(''+el.value).toCurrency();
	}
}
function __integer(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		el.value=(''+el.value).toInteger();
	}
}
function __digits(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		el.value=(''+el.value).toDigits();
	}
}
function __numberlist(e){
	var el=getEventSrc(e);
	if( el && el.type && el.value ){
		var s = (''+el.value);
		s = s.replace(/[^\d\;\:\,\ \-]/g,'');
		s = s.replace(/[\:\,\ \-]/g,';');
		s = s.replace(/[\;\;]/g,';');
		el.value=s;
	}
}
function __nohtml(e){
	var el=getEventSrc(e);
		var s = (''+el.value);
		s = s.replace(/[\<][^\>]+[\>]/g,'');
		//s = s.replace(/[\>]/g,'&gl;');
		el.value=s;

}
function autoFormatForm(a){
	if( a && a.length ){
		for(var i=0;i<a.length;i++){
			switch( a[i].type ){
				case 'text': 
				case 'textarea':
				case 'password':
				case 'file':
				if( hasClass(a[i], 'phone') ){ addHandler( 'blur', a[i], __phone ); }
				if( hasClass(a[i], 'zip') ){ addHandler( 'blur', a[i], __zip ); }
				if( hasClass(a[i], 'ssn') ){ addHandler( 'blur', a[i], __ssn ); }
				if( hasClass(a[i], 'money') ){ addHandler( 'blur', a[i], __money ); }
				if( hasClass(a[i], 'integer') ){ addHandler( 'blur', a[i], __integer ); }
				if( hasClass(a[i], 'digits') ){ addHandler( 'blur', a[i], __digits ); }
				if( hasClass(a[i], 'numberlist') ){ addHandler( 'blur', a[i], __numberlist ); }
				if( hasClass(a[i], 'nohtml') ){ addHandler( 'keyup', a[i], __nohtml ); }
				if( hasClass(a[i], 'nohtml') ){ addHandler( 'blur', a[i], __nohtml ); }
				addClass( a[i], 'flat' );
				addClass( a[i], 'txt' );
				break;
				
				case 'radio':
				addClass( a[i], 'rb' );
				break;
				
				case 'checkbox':
				addClass( a[i], 'ck' );
				break;
				
				case 'select-one':
				case 'select-multiple':
				addClass( a[i], 'flat' );
				addClass( a[i], 'dd' );
				//for(var o=0;o<a[i].options.length;o++){
				//	addClass(a[i].options[o],((o%2==0)?'even':'odd'))
				//}
				break;
				
				case 'button':
				addClass( a[i], 'flat' );
				addClass( a[i], 'btn' );
				break;
				
				case 'submit':
				case 'reset':
				addClass( a[i], 'flat' );
				addClass( a[i], 'btn' );
				addClass( a[i], 'go' );
				break;
			}
			addHandler( 'mouseover', a[i], __hoverOver )
			addHandler( 'mouseout', a[i], __hoverOff )
			addHandler( 'focus', a[i], __fieldFocus )
			addHandler( 'blur', a[i], __fieldBlur )
		}
	}	
}

function initForms(){
	var d=document;

	if(d.forms && d.forms.length>0){
		for( var i=0;i<d.forms.length;i++){
			if( hasClass(d.forms[i],'autohighlight') || hasClass(d.forms[i],'autoformat'))	autoFormatForm(d.forms[i].elements);
		}
	}
}
addHandler( 'load',window,initForms )
