var current_tab = 'cube';
var currentTab = 'cube';
var currentLoginTab = 'accntLogin';
var current_DataSearchTab = 'generalinfo';
var current_AdminManageTab = 'adminUser';
var current_DataShopTab = 'shopQueryResults';
var checkoutTab = 'newCustomers';

function switch_tab(_id) {	
	if (_id != current_tab) {
		
		$(_id + 'Link').style.backgroundColor = '#666';
		$(_id + 'Link').style.color = '#fff';
		$(_id).style.display = 'block';
		
		$(current_tab + 'Link').style.backgroundColor = '#333';
		$(current_tab + 'Link').style.color = '#aaa';
		$(current_tab).style.display = 'none';

		current_tab = _id;
	}
}
function switchTab(_id) {	
	if (_id != currentTab) {
		
		$(_id).style.display = 'block';
		
		$(currentTab).style.display = 'none';
		
		currentTab = _id;
	}
}
function switchLoginTab(_id) {	
	if (_id != currentLoginTab) {
		
		$(_id).style.display = 'block';
		$(_id + 'Link').style.fontStyle = "italic";
		
		$(currentLoginTab).style.display = 'none';
		$(currentLoginTab + 'Link').style.fontStyle = "normal";
		
		currentLoginTab = _id;
	}
}
function switchHelpOpt(_id) {
		$(_id).style.display = 'block';
}
function switch_checkoutTab(_id) {
	if (_id != checkoutTab) {
		$(_id).style.display = 'block';
		$(_id + 'Link').style.fontStyle = "italic";
		
		$(checkoutTab).style.display = 'none';
		$(checkoutTab + 'Link').style.fontStyle = "normal";
		
		checkoutTab = _id;
	}
}
function switch_DataSearchTab(_id) {
	if (_id != current_DataSearchTab) {
		$(_id + 'Link').className = 'page-tab-link selected-tab';
		$(_id).className = '';

		$(current_DataSearchTab + 'Link').className = 'page-tab-link';
		$(current_DataSearchTab).className = 'none';

		current_DataSearchTab = _id;
	}
}	
function switch_DataShopTab(_id) {
	if (_id != current_DataShopTab) {
		$(_id + 'Link').className = 'page-tab-link2 selected-tab2';
		$(_id).className = '';

		$(current_DataShopTab + 'Link').className = 'page-tab-link2';
		$(current_DataShopTab).className = 'none';

		current_DataShopTab = _id;
		$('ActiveShopLayer').value = _id;
	}
}
function switch_AdminManageTab(_id) {	
	if (_id != current_AdminManageTab) {
		$(_id).style.display = 'block';
		$(_id + 'Link').style.fontStyle = "italic";
		
		$(current_AdminManageTab).style.display = 'none';
		$(current_AdminManageTab + 'Link').style.fontStyle = "normal";

		current_AdminManageTab = _id;
	}
}	
function companyChanged( ) {
	m_selCompany = $("lstCompany");
	m_selUser = $("lstUser");		
	m_selUser.disabled = false;		
	var m_Company = null;
	m_Company = m_selCompany.value;		
	//select unique areas based on state value		
	location.replace("admin.php?co=" + m_selCompany.value);
}

// text search functions
var mRegionType, mDataType, mState, mCounty, mGoMArea, sid;
function typeChanged() {
	mRegionType = ($('chkOnshore').checked ? 'onshore' : 'offshore');
	mDataType = $('datatype').value;
	new Request({
		url: 'ajax_search.php',
		onSuccess: function(_html){
			if (_html != '') {
				if (mRegionType == 'onshore') {
					$('selState').set('html', _html);
				} else {
					$('selGoMArea').set('html', _html);
				}
			}
		}
	}).send('reqtype=' + (mRegionType=='onshore' ? 'onshore' : 'offshore') + '&datatype=' + mDataType);
}
function toggleRegion(_onoff) {
	if (_onoff == 'onshore') {
		$('selState').disabled = false;
		$('selCounty').disabled = false;
		$('selGoMArea').disabled = true;
	} else {
		$('selState').disabled = true;
		$('selCounty').disabled = true;
		$('selGoMArea').disabled = false;
	}
	typeChanged();
}
function stateChanged( ) {
	mState = $('selState').value;
	new Request({
		url: 'ajax_search.php',
		onSuccess: function(_html){
			if (_html != '') {
				$('selCounty').set('html', _html);
			}
		}
	}).send('reqtype=counties&datatype=' + mDataType + '&st=' + mState);
}
function countyChanged(){
	mCounty = $('selCounty').value;
	mState = ($('chkOnshore').checked!=true?'GOM':m_selState.value);
	sid = ($('sid') ? $('sid').value : '');	
	location.replace("textsearch.php?datatype=" + mDataType + "&st=" + mState + "&ar="+ mCounty + "&sid=" + sid);
}
function gomareaChanged() {
	mGoMArea = $('selGoMArea').value;
	mState = ($('chkOnshore').checked!=true?'GOM':m_selState.value);
	sid = ($('sid') ? $('sid').value : '');	
	location.replace("textsearch.php?datatype=" + mDataType + "&st=" + mState + "&ar="+ mGoMArea + "&sid=" + sid);
}
function selectAll(cbList, bSelect) {
	$each($$('input[type=checkbox]'), function(_n) {
		if (_n.name.match(new RegExp("^" + cbList))) {
			_n.checked = bSelect;
		}
	});	
}
function selectAllSelect(_elem, _onoff) {
	if ($(_elem)) {
		for(var i=0; i<$(_elem).options.length; i++) {
			$(_elem).options[i].selected = _onoff;
		}
	}
}
function selectAllRows(chkbxs) {
	m_selAllRows = $("selAllRows");
	m_selAllRows.checked = true;
	for (var i=0; i<chkbxs.length; i++) 
		chkbxs[i].checked = true;
}