var linHasSql = false;
var linHasSql2 = false;

function linConstruct(section) {
	linBlur = 'lin' + section;
	if (document.getElementById(linBlur)) {
		wblur(linBlur);
	}
	linstr = '?task=showlin&tid=' + section;
	sqlQuery('wlib-js/sqlquery3.php', linstr, handleLinux, 'GET', 'linux');
}

function handleLinux(){
	// if there hasn't been any errors
	if (sqlHttp['linux'].readyState == NORMAL_STATE) {
		
		// split by the divider |
		l0 = sqlHttp['linux'].responseText.split('#!#');
		
		linsqllength = l0.length - 1;

		linHasSql = true;

		drawLinux();
	}
}

function handleLinTitles(){
	// if there hasn't been any errors
	if (sqlHttp['linuxNav'].readyState == NORMAL_STATE) {
		
		// split by the divider |
		l1 = sqlHttp['linuxNav'].responseText.split('#!#');
		
		lin2sqllength = l1.length - 1;

		lin2HasSql = true;

		drawLinuxTitles();
	}
}

function drawLinux(){
	if (linHasSql == true){
		
		var linView = document.getElementById('main');

		while( linView.hasChildNodes() ) {
			linView.removeChild( linView.lastChild );
		}

			linuxH2 = document.createElement('h2');
				linuxH2S1 = document.createElement('span');
				linuxH2S1.innerHTML = 'Linux';
			linuxH2.appendChild(linuxH2S1);
			linView.appendChild(linuxH2);
			//linuxH2.innerHTML= 'Linux';
			
		for (i=0;i<linsqllength;i=i+3){
			linuxId = l0[i];
			linuxName = l0[i+1]; 
			linuxBody = l0[i+2];			
			
			linuxBodyDiv = document.createElement('div');
			//linuxBodyText.id = linuxName;
			linuxBodyDiv.className = 'postbox ' + linuxName;
			
				linuxH3 = document.createElement('h3');
				//linuxH3S1 = document.createElement('span');
				linuxH3.innerHTML = linuxName;
				//linuxH3.appendChild(linuxH3S1);
			linuxBodyDiv.appendChild(linuxH3);

				linuxBodyText = document.createElement('div');
				linuxBodyText.innerHTML = linuxBody;
			linuxBodyDiv.appendChild(linuxBodyText);
			
			linView.appendChild(linuxBodyDiv);
		}
	}
}

function drawLinuxTitles(){
	if (lin2HasSql == true){
		
		linTitle = document.getElementById('titleArea'); //titleArea?
		
		linuxUl = document.createElement('ul');
		linuxUl.id = 'title'; //title?
		
		for (i=0;i<lin2sqllength;i=i+3){
			linSecId = l1[i];
			linSecDate = l1[i+1];
			linSecTitle = l1[i+2];
						
			linuxLi = document.createElement('li');
			linuxLi.id = 'lin' + linSecId;
			//linuxTitle.id = 'inuxTitle';
			
			linuxLi.innerHTML = '<a href="javascript:linConstruct(\'' + linSecId + '\');">' + linSecTitle + '<br /><span>' + linSecDate + '</span></a>';
			linuxUl.appendChild(linuxLi);
		}
		
		//linDiv.appendChild(linuxUl);
		linTitle.appendChild(linuxUl);
	}
}