/*		function backToTop()
			http://web-graphics.com/mtarchive/001659.php
			The cool BackToTop Javascript for smooth scrolling back
			to the top of a page was written by David Lindquist.
--------------------------------------------------------------------- */
function btt_install( ) {
 if( !document.getElementsByTagName ) { return; }
 var a, i = 0;
 while(( a = document.getElementsByTagName( 'a' )[i++] )) {
  if( '#top' == a.getAttribute( 'href' )) {
   a.onclick = function() { backToTop(); return false; }
  }
 }
}

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
    return false;
}


/*		function extTarget( )
			JM & AP
			r5 - 2007/11/10

			changes target on external links
			so that they open in a new window
			now takes into account presence of subdomains
--------------------------------------------------- */
function extTarget() {

	var n = '';
	//		get window information
	var w = window.location.hostname;
	var t = w.split( '.' );		
	//		do we have a subdomain
	if(( 'com' == t[t.length -1] ) && ( t.length >= 3 )) { t[0] = ''; }
	w = t.join( '.' );

	var a = document.links;
	for( var i = 0; i < a.length; i++ ) {
		n = a[i].hostname;
		t = n.split( '.' );
		if(( 'com' == t[t.length -1] ) && ( t.length >= 3 )) { t[0] = ''; }
		n = t.join( '.' );
		if(( '' != n ) && ( n != w )) { a[i].target = '_blank'; }
	}
}



function getElementsByClass( theClass ) {
	var c,i,j;
	var els = new Array( );
	var es  = document.getElementsByTagName( '*' );

	//		getElement by class name
	for( i = 0,j = 0; i < es.length; i++ ) {
		c = ' ' +es[i].className +' ';
		if( c.indexOf( ' ' +theClass +' ' ) != -1 ) { els[j++] = es[i]; }
	}
	return els;
}


/*		TABS
----------------------------------------------------------------------	*/

var tflag = 0;

function doTab() {

	//	var ee  = this.parentNode;
	//	var len = ee.childNodes.length;
	var len = tflag;

	var num = this.id;
	num = num.substring( num.length -1 );
	var t = '';
	var p;

	//		hide
	for( var i = 0; i < len; i++ ) {
		t = 'pane' +( i +1 );
		p = document.getElementById( t );
		p.style.display = 'none';
		p.style.visibility = 'hidden';
		t = 'tab' +( i +1 );
		p = document.getElementById( t );
		p.className = 'tab';
/*		p.style.backgroundColor = '#ccc';	*/
	}
	//	show
	t = 'pane' +num;
	p = document.getElementById( t );
	p.style.display    = 'block';
	p.style.visibility = 'visible';
	t = 'tab' +num;
	p = document.getElementById( t );
	p.className += ' selected';
/*	p.style.backgroundColor = '#fff';	*/

	return false;
}

function tabMouseOver() {

	var num = this.id;
	var bg  = document.getElementById( num ).style.backgroundColor;

	if(( bg != 'rgb(255, 255, 255)' ) && ( bg != '#fff' ))  {
		document.getElementById( num ).style.backgroundColor = '#eee';
	}
}

function tabMouseOut() {
	var num = this.id;
	var bg  = document.getElementById( num ).style.backgroundColor;

	if(( bg != 'rgb(255, 255, 255)' ) && ( bg != '#fff' ))  {
		document.getElementById( num ).style.backgroundColor = '#ccc';
	}
}


function tabs_install() {

	var e = getElementsByClass( 'tab' );
	tflag = e.length;

	if( 0 == tflag ) { return; }
	for( var i = 0; i < tflag; i++ ) {
		e[i].onclick = doTab;
/*		e[i].onmouseover = tabMouseOver;	*/
/*		e[i].onmouseout = tabMouseOut;	*/
	}
	//		impose colors...
/*	e[0].style.backgroundColor = '#fff';	*/
/*	e[1].style.backgroundColor = '#ccc';	*/
}



/*		function popUpWnd( theURL,wndType )

			launches a popup window
			theURL  -> page to display in the window
			wndType -> the type of popup window to display

			from: http://www.accessify.com/tutorials/the-perfect-pop-up.asp
			r2 - 2005/10/13
------------------------------------------- */
function popUpWnd( theURL,width,height ) {

	var strOptions = '';
	var myWidth    = 1 *width;
	var myHeight   = 1 *height;

	if( 0 == myWidth  ) { myWidth  = 400; }
	if( 0 == myHeight ) { myHeight = 400; }

	strOptions = 'width='+myWidth+',height='+myHeight+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
	zoom = window.open( theURL,'popup',strOptions );
	if( zoom.window.focus ) { zoom.window.focus(); }

}





/*		This script and many more are available free online at
			The JavaScript Source!! http://javascript.internet.com
			Written by Steve - http://jsmadeeasy.com/

			Need to add this sort of thing to field...

    	<input type="text" class="fld" id="myInTxt" name="toto" maxlength="100" size="60"
    	onKeyUp="charCntr('myInTxt','myOutText','{CHAR} characters left.',100);">
    	<br>
    	<span id="myOutText" class="minitext">100 characters left.</span>

*/

//		character counter
function charCntr( inFld,out,displayTxt,maxChars ) {
	
	var i = document.getElementById( inFld );
	var o = document.getElementById( out );
	
	var maxLength = maxChars -i.value.length;
	if( 0 >= maxLength ) {
		maxLength  = 0;
		displayTxt = '<div class="red charCntr"> '+displayTxt+' </div>';
		i.value = i.value.substr( 0,maxChars );
		o.innerHTML = displayTxt.replace( '{CHAR}',maxLength );
	} else {
		o.innerHTML = displayTxt.replace( '{CHAR}','<span class="blue">' +maxLength+ '</span>' );
	}
}


function checkAll( theForm ) {
	var f = document.forms[theForm];
	for( i = 0; i < f.length; i++ ) {
		if( 'checkbox' == f[i].type ) {
			f[i].checked = true;
		}
	}
}

function checkNone( theForm ) {
	var f = document.forms[theForm];
	for( i = 0; i < f.length; i++ ) {
		if( 'checkbox' == f[i].type ) {
			f[i].checked = false;
		}
	}
}



//		block submit button once clicked...
function BlockBtn( theForm,theName,theMessage ) {

	if( 'submit' == theName ) {
		var els = getElementsByClass( 'submit' );
		var p;
		if( els.length == 0 ) { return; }
		for( i = 0; i < els.length; i++ ) {
			els[i].style.visibility = 'hidden';
		}
	} else {
		var n = theForm.elements[theName];
		n.disabled = true;
	}
}

