var xmlhttp=false;
var vInterval=4000
var t=0;
var t0=""
var t4=""
var ot4=""
var vHold="";
var c=0;
var fName=""
var vPC=0
var vBulk=""
var vLast=""
var vFont="Yellow"
var vT0="";
var msg1="";


try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

 } catch (e) {
  try {
  
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  } catch (E) {
   //xmlhttp = false;
   //  alert("try neither")
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
} 
var txtMsg= xmlhttp;
var txtFile = xmlhttp;


function tnext() {
	if (vT0.toUpperCase()!=T0.value.toUpperCase()) {
		S1.value=""
		T1.value=0
		vPC=0
		vBulk=""
		vT0=T0.value		
	}
	t0=T0.value;
	vPC=T1.value;
	clearTimeout(t);
	t=setTimeout("tnext()",vInterval);
	
	if (t0 !="") {
	
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

 } catch (e) {
  try {
  
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  } catch (E) {
   //xmlhttp = false;
   //  alert("try neither")
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
} 

var txtFile = xmlhttp;	
		
		fName="http://www.411Chat.com/Chat/" + T0.value + vPC + ".txt";		
		
		//var txtFile = new xmlhttp // XMLHttpRequest();
		
		T2.value="Attempting to connect...."
		
		T3.value=vInterval
		

		
		txtFile.open("GET", fName,true);
		
		//alert("Congratulations, your device works with 411Chat.com!")


		txtFile.onreadystatechange = function() {
		
		
  if (txtFile.readyState===4) {  // Makes sure the document is ready to parse.
  
			T2.value=txtFile.status

  	if (txtFile.status ===200) {
  				
				ot4=t4
				vHold=txtFile.responseText;
				if (vHold.toUpperCase().indexOf("VF=")>-1) {
					vHold=vHold.slice(0,vHold.toUpperCase().indexOf("VF=")) + vHold.slice(vHold.toUpperCase().indexOf("VF=")+3)
				}
				/*if (vHold.toUpperCase().indexOf("|")>-1) {
					vHold=vHold.slice(1,vHold.toUpperCase().indexOf("]")) + " " + vHold.slice(vHold.toUpperCase().indexOf("|")+1)
				}*/				
				
				if (vHold.toUpperCase().indexOf("|")>-1) {
					vHold=vHold.slice(vHold.toUpperCase().indexOf("|")+1,vHold.length-2) + " - " + vHold.slice(1,vHold.toUpperCase().indexOf("]"))
				}				
				
				c=T1.value;
				c=eval(c)+1;				
				T1.value=c;
				vPC=T1.value				

				clearTimeout(t);
				
				
				if (vLast==vHold){
					t=setTimeout("tnext()",vInterval);	
					T3.value=vInterval;
					//dMsg.innerHTML=""
					return;
				} else {				
				
					vLast=vHold
					vBulk=vHold + "\n" + vBulk

					if (vBulk.length>1000) {
						vBulk=vBulk.slice(0,1000)
					}				
					S1.value=vBulk													
					t=setTimeout("tnext()",250);
					T3.value="250";
					dMsg.innerText="Loading"
				}
		}  else if (dMsg.innerText.length>0) {
		dMsg.innerText=""
	}
  }
}
	txtFile.send(null);
}	

}

function fsend(){
	var t5="";
	t0=T0.value; // meeting place
	t5=T4.value; // name
	t3=T3.value.length
	var vMsg=""
	
	if (T4.value.length<1){
		vMsg="Nothing to send!" + "\n"
	}
	
	if (TName.value.length<1){
		vMsg="Your name is missing!" + "\n"		
	}	
	
	if (vMsg!="") {
		alert(vMsg)
		vMsg="";
		return;
	}

				clearTimeout(t);
				t=setTimeout("tnext()",vInterval);
				str=TName.value;
				TName.value=str.replace(/\n/,"");
				
				str=TName.value;
				TName.value=str.replace(/#/,"");
				
				str=TName.value;
				TName.value=str.replace(/</,"");
				
				str=TName.value;
				TName.value=str.replace(/>/,"");
				
				str=TName.value;				
				TName.value=str.replace(/=/,"");
				
				//str=TName.value;				
				//TName.value=str.replace(/+/,"");
				
				str=TName.value;								
				TName.value=str.replace(/%/,"");
				
				str=TName.value;				
				TName.value=str.replace(/@/,"");
				
				str=TName.value;
				TName.value=str.replace(/&/,"");
				
				str=TName.value;
				TName.value=str.replace(/$/,"");

	t0=T0.value;	

				str=T0.value;				
				T0.value=str.replace(/\n/,"");
				
				str=T0.value;
				T0.value=str.replace(/#/,"");
				
				str=T0.value;
				T0.value=str.replace(/</,"");
				
				str=T0.value;
				T0.value=str.replace(/>/,"");
				
				str=T0.value;
				T0.value=str.replace(/=/,"");
				
				//str=T0.value;
				//T0.value=str.replace(/+/,"");
				
				//str=T0.value;
				//T0.value=str.replace(/*/,"");
				
				str=T0.value;
				T0.value=str.replace(/%/,"");
				
				str=T0.value;
				T0.value=str.replace(/@/,"");
				
				str=T0.value;
				T0.value=str.replace(/&/,"");
				
				str=T0.value;
				T0.value=str.replace(/$/,"");
				

	if (t0 !="") {	
		if (t5 !=""){
			if (t3 >0){
				//C1.style.background="#ECECD9"
				//var txtMsg = new XMLHttpRequest();
				
				//txtMsg=xmlhttp;

				str=T4.value;								
				T4.value=str.replace(/\n/g,"~n~");
				
				str=T4.value;				
				T4.value=str.replace(/&/g,"~u~");
								
				str=T4.value;
				T4.value=str.replace(/#/g,"~p~");

				str=T4.value;
				T4.value=str.replace(/</g,"~1~");

				str=T4.value;
				T4.value=str.replace(/>/g,"~r~");

				str=T4.value;
				
				T4.value=str.replace(/=/g,"~e~");	
				// D=page number
				// P= password
				
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

 } catch (e) {
  try {
  
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  } catch (E) {
   //xmlhttp = false;
   //  alert("try neither")
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
} 
var txtMsg= xmlhttp;
				

				msg1="http://www.411Chat.com/asp/ReadLong.asp?R=" + T0.value + "&D=" + T1.value + "&P=" + '' + "&C=" + TName.value + "&F=" + '' + "&M=" + T4.value
				//msg1="http://www.411Chat.com/asp/ReadLong.asp?R=" + T0.value + "&D=" + T1.value + "&P=" + '' + "&C=" + TName.value + "&F=" + vFont + "&M=" + T4.value
				txtMsg.open("GET", msg1, true);
				txtMsg.send(null);	
				T4.value="";				
				clearTimeout(t);
				t=setTimeout("tnext()",1000);
			}
			
		}
	}
}
function fTimer(){
	vInterval=D1.value
}

function fCI(){
	beep
}

T1.value=0
t=setTimeout("tnext()",3000)
dMsg.innerHTML=""

//alert("Congratulations, your device works with 411Chat.com!")
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
document.write("Browser name: "+ browser);
document.write("<br>" + "Browser version: "+ version + "<br>");
if (browser.toUpperCase()=="OBIGO") {
document.write ("Sprint<BR>");
document.write ("Mobile<BR>")
} else if (browser.toUpperCase()=="OPERA") {
document.write ("Mobile<BR>");
}