function sectorView(sector_name,one_two){
	var industryInform = $('#industry_inform_a')[0];
	var closeLink = $('#industry_inform_b')[0];
	var industryTables = document.getElementById('industry_tables').getElementsByTagName('div');
	if (sector_name.length > 0){
		industryInform.style.display = 'none';
		closeLink.style.display = 'block';
		var sector_id = 'js_' + sector_name.replace(/\//g,'').replace(/  /g,' ').replace(/ /g,'_');
		// clean out sector id 
		if (one_two == 1)
		{
			var industryTables = document.getElementById('industry_tables').getElementsByTagName('div');
		}
		else if (one_two == 2){
			var industryTables = document.getElementById('industry_tables_two').getElementsByTagName('div');
		}
		// loop possible sector divs. hide non match. show match
		for (var i = 0;industryTables.length>i;i++){
			if (industryTables[i].id == sector_id){
				industryTables[i].style.display = 'block';
			}
			else {
				industryTables[i].style.display = 'none';
			}
		}
	}
	else {
		industryInform.style.display = 'block';
		closeLink.style.display = 'none';
		for (var i = 0;industryTables.length>i;i++){
			industryTables[i].style.display = 'none';
		}
	}
}

function pageSectorView(sector_num,offset){
	var sectorTable  = $('#js_sector_' + sector_num)[0];
	// get all the table rows
	var tableRows = sectorTable.getElementsByTagName('tr');
	var rows2kill = tableRows.length -1;
	var bLink = $('#b_link_'+sector_num)[0];
	var nLink = $('#n_link_'+sector_num)[0];
	var bOffset = 1;
	var nOffset = 1;
	var thisRow = '';
	//for(var i=0;rows2kill>i;i++){
		// sectorTable.removeChild(tableRows[1]);
	//}
	$.get("http://10.10.10.12/sites/portfoliokeeper_new_com/sector_company.cfm?sector_num="+sector_num+'&offset='+offset,function(data){
		// parse returned json
		var query = eval('('+data+')');
		for (var i = 0;10 > i;i++){
			if ( sectorTable.rows[i+1] ){
				thisRow = sectorTable.rows[i+1];
			}
			else {
				thisRow = sectorTable.insertRow(-1);
				thisRow.insertCell(-1);
				thisRow.insertCell(-1);
			}
			if (query.DATA.COMPANY[i]){
				
				thisRow.cells[0].innerHTML = query.DATA.COMPANY[i];
				thisRow.cells[1].innerHTML = query.DATA.SYMBOL[i];
			}
			else {
				thisRow.cells[0].innerHTML = '';
				thisRow.cells[1].innerHTML = '';	
			}
		}
		// loop on the record count
		//for (var i = 0; query.ROWCOUNT > i; i++){
			// make a new row, populate w/ company information
		//	var thisRow = sectorTable.insertRow(-1)
			//var company = thisRow.insertCell(-1);
		//	var symbol = thisRow.insertCell(-1);
		//	company.innerHTML = query.DATA.COMPANY[i];
		//	symbol.innerHTML = query.DATA.SYMBOL[i];
		//}
		// determine the back & next links
		if (query.DATA.TOTALRECORDS[1] > 10){
			if (offset >= 11){
				bOffset = offset - 10;
			}
			if (offset + 10 >= query.DATA.TOTALRECORDS[1]){
				nOffset = offset;
			}
			else {
				nOffset  = offset  + 10;	
			}
		}
		// set the offset links
		bLink.onclick = function(){pageSectorView(sector_num,bOffset)};
		nLink.onclick = function(){pageSectorView(sector_num,nOffset)};
	});
}

function hideSectors(){
	var closeLink = $('#industry_inform_b')[0];
	closeLink.style.display = 'none';
}