var glbTmp = "";
var glbCht = "";
var glbMsg = "";
var glbReq = "";
var glbInp = "";
var glbParams = "";
var glbDest = "";
var glbKeyCode = 0;
var glbFirst = 1;
var glbSID = "";
var glbPID = "";
var glb1stchat = 1;
var glbPaging = 0;  // paging chat by 20's
var glbaG = new Array(99);  // Groupnames
var glbJoin = "";
var glbGroup = "Public";
var glbChatboxTitle = 'z9xbc6 Chat';
var glbLastRead = "";
var glbChatPtr = "";
var glbFixtPtr = "";
var glbTimerID = null;
var glbFrom = "9999";
var gtxtCols = "30";   //  'textarea'
var gtblWidth = "230"; // 'chatbox'

function loginFN() {
	document.getElementById('regmsg').innerHTML = '';
	document.getElementById('passmsg').innerHTML = '';
	document.getElementById('passFrm').innerHTML = '';
document.getElementById("logregFrm").innerHTML = '<form method="post" action="" name="loginForm"><table border="1" cellspacing="0"><tr><td align="center"><table border="0" cellspacing="4" bgcolor="#EAFFCC"><tr><td colspan="2" align="center"><b>Please Log In: <br />Twitter Authentication Soon<br /></b></td></tr><tr><td align="right">Username: </td><td align="left"><input type="text" name="sid" value="" size="15"></td></tr><tr><td align="right">Password: </td><td align="left"><input type="password" name="pid" value="" size="15" onkeypress="codes1(event)"></td></tr><tr><td colspan="2" align="center"><input type="button" name="submet" value="Members Log In" onclick="login2()"></td></tr></table></td></tr></table></form>';
} // submits loginForm to login2() 

function login2() {
	document.getElementById('logmsg').innerHTML = 'Checking Twitter...';
	glbSID = document.loginForm.sid.value;
	glbPID = document.loginForm.pid.value;
	if (glbSID == "" || glbPID == "") {
		document.getElementById('logmsg').innerHTML = 'Please check your entries';
	} else {
		updateCountDown(); // start timer BUT NOT started INSIDE chat() else LOOP
	}
}
function codes1(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if ( KeyID == "13" ) { login2(1); }
}
var H3 = '<select name="choices" style="font-family:Arial; font-size:11px; font-weight:bold;" onchange="javascript:choiceFN(this.options[this.selectedIndex].value)">';
H3 += ' <option value="">OPTIONS:</option>';
H3 += ' <option value="1">Active Members</option>';
H3 += ' <option value="2">All Public Groups</option>';
H3 += ' <option value="4">Create Private Group</option>';
H3 += ' <option value="5">Access Private Group</option>';
H3 += ' <option value="6">Read-Only Texts</option>';
H3 += '</select>';
H3 += '&#160;&#160;&#160;<a href="javascript:request(\'?pubgroups\')" title="All Public groups">';
H3 += 'Public</a>&#160;&#160;<a href="javascript:request(\'?prigroups\')" title="Your Private groups">Private</a>&#160;&#160;';
function choiceFN(c) {
	if (c == '1') request('?active');
	if (c == '2') allPubFN();
	if (c == '4') cregrpFN();
	if (c == '5') grplogFN();
	if (c == '6') readonlyFN();   //rdonlyFN();
}
function getxmlhttp(dest) {
	clearTimeout(glbTimerID);
	document.getElementById("centre").innerHTML = "";
	xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = getxmlhttp2;
    xmlhttp.open("GET", dest);
    xmlhttp.send(null);
}
function getxmlhttp2() {
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		document.getElementById("chatbox").innerHTML = xmlhttp.responseText;
	}
}
function myAcctFN() { getxmlhttp('account.php') }
function readonlyFN() { getxmlhttp('friends.html') }
function allPubFN() { getxmlhttp('allpublic.html') }

function updateCountDown() {  // clearTimeout(glbTimerID)
    chat();	
	glbTimerID = setTimeout("updateCountDown()",2000000); // 20-second chat refresh
}
function chat0 () {  // dbl-click message refresh
	mention(); // searches Twitter and sets up the above glb's
	chat3();
}
function chat() {
	glbPaging = 0;
	if (glb1stchat == 1) { 
		glb1stchat = 0; 
		document.getElementById('logregFrm').innerHTML = "";
		document.getElementById('logmsg').innerHTML = "";
		glbMsg = "";
	} else { 
		glbMsg = document.chatForm.chatin.value; 
	}
		//glbCht = "";  // the chat messages
		//glbMsg = "";  // the chat comments/prompts
		//glbInp = "";  // the input box
	twitFN(); // post any message --- index.html
	mention(); // searches Twitter for any new msgs
	glbCht = glbMsg+'<br />'+glbCht;
	chat3();
}

function chat3() {
	//if (glbMsg != "") glbMsg += "<br /><br />";
	
var H5  = '<br /><span style=\"color:#CC0000; font-size:14px; font-weight:bold;\">&#160;&#160;'+glbChatboxTitle;
H5 += '</span>&#160;&#160;&#160;&#160;<div id=\'ctr2\' style="display:inline;">(250)</div><br />';
H5 += '<textarea id="msg" name="chatin" rows="2" cols="'+gtxtCols+'"';
H5 += ' onDblClick="chat0()" onkeypress="codes(event)" onkeyup=';
H5 += '"document.getElementById(\'ctr2\').innerHTML = \'(\'+(250-document.chatForm.chatin.value.length)+\')\';">'
H5 += '</textarea><br />';
H5 += '<span style="color:#CC0000; font-weight:bold;">To REFRESH</span> the chat box, double-click above<br />';
H5 += '<span style="color:#CC0000; font-weight:bold;">To POST</span> a chat message, press Enter</span>';

var H6 = '<table width="'+gtblWidth+'" border="1"><tr><td>'+glbCht+'</td></tr></table>';

	document.getElementById('fixed').innerHTML = H5;  //H3+H5;
	document.getElementById('chatbox').innerHTML = H6;
	document.chatForm.chatin.value = glbInp;
	document.chatForm.chatin.focus();  // Sorry about IE8, too bad
}

function grplogFN() {
	clearTimeout(glbTimerID);  // stop the timer
	glbMsg = "Please enter a Private GROUPNAME and PASSWORD above.";
	glbMsg += "&#160;&#160;&#160;DAYS-OLD controls how many messages are displayed (0=UnRead)";
	glbInp = "[Group Access]:Groupname= Password= Days-Old=";
	chat3();
}
function joinFN(grp,frm) {
	glbGroup = grp;
	glbFrom = frm;
	glbChatboxTitle = glbGroup + " chat ";
	glbMsg = "";
	glbTmp = "";
	updateCountDown();
}
function codes(e) {
	var KeyID = (window.event)? event.keyCode : e.keyCode;
	if ( KeyID == "13" ) { updateCountDown(); } else { clearTimeout(glbTimerID); }
}
document.write('<fieldset>');
document.write('<div id="logo1">&#160;&#160;Chat via Twitter</div>');
document.write('<div id="logregFrm"></div>');
document.write('<div id="logmsg"></div>');
document.write('<div id="regmsg"></div>');
document.write('<div id="passFrm"></div>');
document.write('<div id="passmsg"></div>');
document.write('<div id="message"></div>');
document.write('<form name="chatForm">');
document.write('<div id="fixed"></div>');
document.write('<div id="centre"></div>');
document.write('<div id="chatbox"></div></form></fieldset><br />');
//document.write('<div id="footer">&#160;&#160;&#160;&#160;&#160;&#160;');
//document.write('<a href="http://www.qviews.net" target="_blank">&copy; Qviews 2009</a></div></fieldset>');
