/*  Title: AJAX Engine
	Author: Nat
	Version: 1.0
	Note: Modified (and simplified) from KSMX 2.6.0 by Todd Kingham and Jan Jannek
*/

function ajax_call(METHOD, URL, CALLBACK, POST_PARAM) {
	try{
		var req = ( window.XMLHttpRequest ) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ;
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					CALLBACK(req.responseText);
				}
			}
		}
	}catch(e){
	}
	req.open( METHOD , nocache(URL) , true );
	if (METHOD.toUpperCase() == 'POST') {
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	} else {
		POST_PARAM = '';
	}
	req.send(POST_PARAM);
}

function nocache(URL) {
	var d = new Date();
	return URL+'?'+d.getTime();
}

function drawTableRow(strRow, cssStyle) {
	var strOutput;
	var arCol = strRow.split(',');
	
	if (cssStyle != '') {
		strOutput = '<tr style="'+cssStyle+'">';
	} else {
		strOutput = '<tr>';
	}
	
	for (k=0; k < arCol.length; k++) {
		var strTemp = arCol[k];
		if (strTemp.indexOf('@') > 0) {
			strTemp = '<a href="mailto:'+strTemp+'">'+strTemp+'</a>';
		}
		strOutput = strOutput + '<td>' + strTemp + '</td>';
	}
	strOutput = strOutput + '</tr>';
	
	return strOutput;
}

function drawMemberTable(strData) {
	var objDrawArea = document.getElementById('memberTable');
	var objDIVContent = document.getElementById('content');
	var arRow = strData.split("\n");
	var strOutput;
	
	strOutput = '<table width="98%" cellpadding="2" cellspacing="0" align="center" style="border: 1px solid #999999;">';
	strOutput = strOutput + drawTableRow(arRow[0], 'background: #DDEEFF; font-weight: bold;');
	
	for (i=1; i<(arRow.length-1); i++) {
		var strTemp = 'background: #FFFFFF;';
		if (i % 2 == 0) { strTemp = 'background: #EEEEEE;'; }
		strOutput = strOutput + drawTableRow(arRow[i], strTemp);
	}
	
	strOutput = strOutput + '</table>';
	objDrawArea.innerHTML = strOutput;
	
	var IE = document.all;
	if (IE) { 
		objDIVContent.style.height = objDIVContent.clientHeight + 2;
	} else {
		objDIVContent.style.height = (objDIVContent.clientHeight + objDrawArea.clientHeight - 190) + 'px';
	}
}
