var tabData = [
	  ['home.php', 'Home', '80']				// 0
	, ['aboutUs', 'About Us', '68']			// 1
	, ['membership', 'Membership', '84']	// 2
	, ['calendar.php', 'Calendar', '70']	// 3
	, ['sponsorship', 'Sponsorship', '85']	// 4
	, ['resources', 'Resources', '76']		// 5
	, ['contactUs.php', 'Contact Us', '78']	// 6
//	, ['contactUs', 'Contact Us', '78']
];

var	html_tab_path = '';
var	img_tab_path = 'tab_images/';
var	totalImages = 3;			// left pane

var	CR = '\n';
//var	CR = '';

var	current_tab = -1;
var	swapTabs = null;
//var	currentBody = null;

/* * * * * */
function	test( value )
{
	alert( value );
}
/* * * * * */
function	getTabName( tabName )
{
	var	i;
	if( (i = tabName.indexOf('.')) == -1 )
		return tabName;
	return tabName.substring(0, i);
}
/* * * * * */
function	getTabPageName( tabName )
{
	var	i;
	if( (i = tabName.indexOf('.')) == -1 )
		return tabName + '.html';
	return tabName;
}
/* * * * * */
function	tabItem( tabData )
{
	var	imageName = getTabName( tabData[0] );
	this.normImage = img_tab_path + 'b_' + imageName + 'Off.gif' ;
	this.activeImage = img_tab_path + 'b_' + imageName + 'On.gif' ;
	this.altImage = img_tab_path + 'b_' + imageName + 'Over.gif' ;
	this.source = getTabPageName( tabData[0] );
	this.title = tabData[1];
	this.width = tabData[2];
}
/* * * * * */
function	drawTabs( doc )
{
	doc.swapTabs = new Array();

	doc.write( '<td><img src="' + img_tab_path + 'b_sides.gif" height="34" width="138"></td> ' + CR );
	doc.write( '<td><img src="' + img_tab_path + 'b_divider.gif" height="34" width="1"></td> ' + CR );

	for( var i = 0; i < tabData.length; i++ )
	{
		doc.swapTabs[i] = new tabItem( tabData[i] );
		doc.write( ' <td id="tab' + i + '"> ' 
			+ ' <a href="javascript:onTabButtonClick('+ i +');" ' 
			+ ' onmouseout="swapTabImg(' + i + ',0);" onmouseover="swapTabImg(' + i + ',1);" ' 
			+ ' > ' 
			+ ' <img id="img' + i + '" src="' + doc.swapTabs[i].normImage + '" '
			+ ' alt="' + doc.swapTabs[i].title + '" ' 
			+ ' title="' + doc.swapTabs[i].title + '" ' 
			+ ' border="0" height="34" width="' + doc.swapTabs[i].width + '"></a></td> '
//			+ ' border="0" height="34" width="120"></a></td> '
			+ CR );
		doc.write( '<td><img src="' + img_tab_path + 'b_divider.gif" height="34" width="1"></td> ' + CR );
	}

	doc.write( '<td><img src="' + img_tab_path + '/b_sides.gif" height="34" width="138"></td> ' + CR );
}
/* * * * * */
function	drawFooterLinks( doc )
{
	var	sep = '';
	for( var i = 0; i < doc.swapTabs.length; i++ )
	{
		doc.write( sep + '<a href="javascript:onTabButtonClick('+ i +');">'
			+ doc.swapTabs[i].title + '</a>' );
		sep = ' | ';
	}
	doc.write( CR );
}
/* * * * * */
function	swapTabImg( i, mouseOver, doc )
{
	if( doc == null )
		doc = document;
	if( i == doc.current_tab )
		return;
	if( mouseOver )
	{
		doc.getElementById('img' + i).src = doc.swapTabs[i].altImage;
	}
	else
	{
		doc.getElementById('img' + i).src = doc.swapTabs[i].normImage;
	}
}
/* * * * * */
function	redrawTab( tab, doc )
{
	if( doc.current_tab == tab )
		return;
		
	var	i;
	if( doc.current_tab >= 0 )
	{
		i = doc.current_tab;
		doc.getElementById('img' + i).src = doc.swapTabs[i].normImage;
	}
//	if( tab != 0 )
	{
		i = tab;
		doc.getElementById('img' + i).src = doc.swapTabs[i].activeImage;
		doc.getElementById('img' + i).blur();		// get rid of dotted frame in Mozilla
	}
	doc.current_tab = tab;
}
/* * * * * */
function	onTabButtonClick( tab, doc )
{
	if( doc == null )
		doc = document;
	redrawTab( tab, doc );
	doc.getElementById('content').src = html_tab_path + doc.swapTabs[tab].source;

//	var	num = Math.floor( Math.random() * totalImages );	
//	document.getElementById('leftImage').src = 'img/leftPane' + num + '.gif';
}
/* * * * * */
function	autoResize( frame )
{
//	return;
	if( navigator.userAgent.indexOf('MSIE') >= 0 )
		frame.height = frame.contentWindow.document.body.scrollHeight;	// IE
	else
		frame.height = frame.contentDocument.height;					// Mozilla
//alert(frame.height);
}
/* * * * * */
/* * * * * */
/* * * * * */
function	launchPopup( ref )
{
	window.open( ref.href, "popup", 'menubar=yes, toolbar=yes, location=yes, scrollbars=yes, status=yes, resizable=yes', false );
}
/* * * * * */
function	launchHttpsPopup( ref )
{
	var	href = ref.href;
	if( href.substr(0, 5).toLowerCase() == 'http:' )
		href = 'https:' + href.substr(5);
//alert(href);
	window.open( href, "popup", 'menubar=yes, toolbar=yes, location=yes, scrollbars=yes, status=yes, resizable=yes', false );
}
/* * * * * */
function	connectHttps()
{
	if( window.location.protocol == 'https:' )
		return;
	if( window.location.protocol == 'file:' )
		return;
	var	newLocation = 'https://' + window.location.host + window.location.pathname + window.location.search;
	window.location = newLocation;
//	checkCookiesEnabled();
}
/* * * * * */
function	verifyEmailAddr( checkemailconfirm )
{
	var	addr = document.getElementById('email').value;

//alert("verify "+addr);

//*
	if( addr == null 
		|| addr.length < 5 )
	{
		alert( 'Enter your email address!');
		return false;
	}

	var	i, j;

	if( checkemailconfirm != null && checkemailconfirm == true )
	{
		var	emailconfirm = document.getElementById('emailconfirm').value;
		if( addr != emailconfirm )
		{
			alert( 'Email address does not match!');
			return false;
		}
	}

	if( (i = addr.indexOf('@')) == -1 
		|| (j = addr.indexOf('@', i + 1)) != -1 
		|| (j = addr.indexOf('.', i + 1)) == -1 
	)
	{
		alert( 'Verify your email address!');
		return false;
	}
	var	badChars = ' *|,\":<>[]{}`\';()&$#%';
	for( i = 0; i < addr.length; i++ )
	{
		if( badChars.indexOf(addr.charAt(i)) != -1 )
		{
			alert( 'Check your email address!');
			return false;
		}
   }
//*/
	return true;
}
/* * * * * */
function	verifyEmail()
{
	if( !verifyEmailAddr() )
		return false;
	var	addr = document.getElementById('email').value;
	var	emailconfirm = document.getElementById('emailconfirm').value;
	var	subj = null;
	if( document.getElementById('subject') != null )
	{
		subj = document.getElementById('subject').value;
		if( subj == null )
			subj = '';
	}
	var	msg = null;
	if( document.getElementById('message') != null )
	{
		msg = document.getElementById('subject').value;
		if( msg == null )
			msg = '';
	}

//*
	if( subj != null && subj.length < 5 )
	{
		alert( 'Have you forgot to type in the subject?');
		return false;
	}
	if( msg != null && msg.length < 5 )
	{
		alert( 'Have you forgot to type in your message text?');
		return false;
	}
//*/

	if( document.getElementById('formSendMail') != null )
	{
		var	action = document.getElementById('formSendMail').action;
	//	var	action = 'js/i.php?oper=webMail' ;
		action += '&officer_name=' + document.getElementById('officer_name').value;
		action += '&email=' + addr;
		action += '&emailconfirm=' + emailconfirm;
		if( subj != null )
			action += '&subject=' + subj;

		if( msg != null )
		{
			action += '&message=';
			for( var i = 0; i < msg.length; i++ )
			{
				var	c;
				if( (c = msg.charAt(i)) == '\n' )
					action += '%0d';
				else
					action += c;
			}
		}

	//alert(action);
	//return false;
		
		document.getElementById('formSendMail').action = action;
	}
	return true;
}
/* * * * * */
function	launchSendMail( ref )
{
	var	name = '';
	name = ref.id;
	// use ref.id as parameter, pass as window.name
	window.open( 'sendMail.html', name, 'width=740, height=670, resizable=yes', false );
}
/* * * * * */
function	show_officer_name( name, i )
{
	var	buffer = '';
	buffer += '<a id="officer_name' + i + '" href="nowhere" onClick="launchSendMail(this); return false;"> ';
	buffer += name;
	buffer += '</a>';
	return buffer;
}
/* * * * * */
function	show_officers( data_array )
{
	var	buffer = '';

	for( var i = 0; i < data_array.length; i++ )
	{
		buffer += '<tr>';
		buffer += '<td align="left" valign="top" class="bodyTextLink">&#8226; ';
		var row = data_array[i];
		var o_name = row[0];
		if( o_name == '' )
			o_name = '&nbsp;'
		var o_title = row[1];

		// use ref.id as parameter to retreive officer name
		buffer += show_officer_name( o_name, i );
		buffer += ', <em>';
		buffer += o_title ;
		buffer += '</em></td> ';
		buffer += '</tr>';
	}

	document.write( buffer );
}
/* * * * * */
function	createLinks( text )
{
	var	i = 0;
	
	while( (i = text.indexOf('http://', i)) != -1 )
	{
		var j = text.indexOf(' ', i);
		if( j == -1 )
			j = text.length;
		var	head = text.substring( 0, i );
		var	link = text.substring( i + 'http://'.length, j );
		var	tail = text.substring( j );
		//	<a href=\'http://cnet.com\' onclick=\'launchPopup(this); return false;\'>cnet.com</a>
		var	realLink = '<a href=\'http://' 
				+ link
				+ '\' onclick=\'launchPopup(this); return false;\'>'
				+ link
				+ '</a>';
		text = head + realLink + tail;
		i += realLink.length;
	}
	return text;
}
/* * * * * */
