var vInterval=5000
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="";
var txtFile="";
var ajaxRequest=""; 
var vajaxRequestType="";
var vTest=0
var vOnline=new Array()
var vOnlinec=0
 
//t=setInterval("fCommunicate()",5000)     
 
	var t="";
	//t=setInterval("tnext()",3000)
	t=setTimeout('tnext()',5000)
 
 
/*
    try { ajaxRequest = new XMLHttpRequest(); vajaxRequestType=1;    }
    catch (e)     {
        try { ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP'); vajaxRequestType=2;  }
        catch (e2)         {
          try {   ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP'); vajaxRequestType=3  }
          catch (e3) {  ajaxRequest = false;   }
        }
     }
*/
 
function tnext() {
 
//alert("Testing site, please wait 10 minutes....");
 
 
 
	if (vT0.toUpperCase()!=document.all.T0.value.toUpperCase()) {
		//document.all.S1.value=""
		dMessage.innerHTML=""
		dOnline.innerHTML=""
		document.all.T1.value=0
		vPC=0
		vBulk=""
		vT0=document.all.T0.value		
	}
	

	
	t0=document.all.T0.value;
	
	vPC=document.all.T1.value;
	
	clearTimeout(t);
	t=setTimeout('tnext()',vInterval)
	//t=setInterval("tnext()",vInterval)
	
	
	
	if (t0 !="") {
	
	
		//ajaxRequest = new XMLHttpRequest(); 
 
		txtFile = ajaxRequest;	
 
		//http://www.411Chat.com
		
		fName="Chat/" + document.all.T0.value + "-" + document.all.TPW.value + vPC + ".txt";		
		//fName="Chat/" + document.all.T0.value + vPC + ".txt";				
 
		
		document.all.T2.value="Attempting to connect...."
		
		document.all.T3.value=vInterval
		
		clearTimeout(tt)		
		

		if (vTest==0){
			txtFile.open("GET", fName, true);
		} else {
			txtFile.open("GET", "http://www.411chat.com/" + fName, true);		
			//alert("http://www.411chat.com/" + fName)			
		}
 
		//alert("Congratulations, your device works with 411Chat.com!")
 
 
 
		txtFile.onreadystatechange = function() {
		
		
  if (txtFile.readyState===4) {  // Makes sure the document is ready to parse.
  
			document.all.T2.value=txtFile.status
 
 
			
  	if (txtFile.status ===200) {
				ot4=t4
				
				vHold=txtFile.responseText;
 
				if (vHold.length>-1) {
				}
 
					var vFrom=vHold.slice(vHold.indexOf('[')+1,vHold.indexOf(']'))
					var vMatch=0
					for (i=1;i<=vOnlinec;i++){
						if (vOnline[i].toUpperCase()==vFrom.toUpperCase()){
							vMatch=1
							i=vOnlinec
						}
					}
					if (vMatch==0){
						vOnlinec=vOnlinec+1
						vOnline[vOnlinec]=vFrom
 
						if (vOnlinec>1){
							for (i=1;i<=vOnlinec-1;i++){
 
								if (vOnline[i].toUpperCase()>vOnline[i+1].toUpperCase()){
									var vTmp=vOnline[i]
									vOnline[i]=vOnline[i+1]
									vOnline[i+1]=vTmp
									i=1
								}
							}
							
						} else {
							vOnlinec=1
							vOnline[vOnlinec]=vFrom
						}
						
						dOnline.innerHTML=""
						
						for (i=1;i<=vOnlinec;i++){
							dOnline.innerHTML=dOnline.innerHTML+"&nbsp;&nbsp;" + vOnline[i] + "<br>"
						}
					}
 
					vHold=vHold.slice(vHold.indexOf(']')+1)
					
					if (vHold.toUpperCase().indexOf('VF=')>-1){
						vF=vHold.slice(0,vHold.indexOf('|'))
 
						vF=vF.slice(vF.toUpperCase().indexOf('vF=')+4)	
 
						vHold=vHold.slice(vHold.toUpperCase().indexOf('|')+1)
					}
					
					if (vF==""){
						var vC="#000000"
					} else {
						var vC=vF
 
					}
					
					//vHold='<p><font face="arial" size="2" color="' + vC + '">' + vHold + '</font><br><font face="arial" size="2" color="red">' + vFrom + '</font><br></p>\n'
					
					vTmp=""
                 vTmp=vTmp+'         <tr>'
                 vTmp=vTmp+'                            <td width="100%">'
                 vTmp=vTmp+'                              <table border="0" width="100%">'
                 vTmp=vTmp+'                                <tr>'
                 vTmp=vTmp+'                                  <td width="100%" bgcolor="#E2E2E2">'
                 vTmp=vTmp+'<font face="arial" size="2" color="' + vC + '">' + vHold + '</font><br><font face="arial" size="2" color="red">' + vFrom + '</font><br>\n'
                 vTmp=vTmp+'                 &nbsp;</td>'
                 vTmp=vTmp+'                                </tr>'
                 vTmp=vTmp+'                              </table>'
                 vTmp=vTmp+'                            </td>'
                 vTmp=vTmp+'                          </tr>'
 
					vHold=vTmp
 
					dMessage.innerHTML=vHold+vBulk
 
 
	
 
					c=document.all.T1.value;
					c=eval(c)+1;				
					document.all.T1.value=c;
					vPC=c // document.all.T1.value				
					clearTimeout(t);
				
					vBulk=vHold + "\n" + vBulk
 
					if (vBulk.length>10000) {
						vBulk=vBulk.slice(0,100000)
					}				
 
					
 
 
					document.all.T3.value="200";
					dMsg.innerText="Loading"				
					t=setTimeout('tnext()',200)
				
		}  else if (dMsg.innerText.length>0) {
		
			dMsg.innerText=""
			t=setTimeout('tnext()',vInterval)
 
	}
  }
}
	txtFile.send(null);
}	
 
}
 
function fsend(){
	dMsg.innerText=""
	var t5="";
	t0=document.all.T0.value; // meeting place
	t5=document.all.TOutgoing.value; // message  
	t3=document.all.T3.value.length
	var vMsg=""
	
	//document.all.T47.value="Ready #1"
	if (document.all.TOutgoing.value.length<1){
		vMsg="Nothing to send!" + "\n"
	}
	
	if (document.all.TName.value.length<1){
		vMsg="Your name is missing!" + "\n"		
	}	
	
	 if (document.all.TPW.value.length<3){
 		alert("Password must be at least 3 characters in length!")
	 	document.all.TPW.focus()
	 	return
	 }		
	
	if (vMsg!="") {
		alert(vMsg)
		vMsg="";
		return;
	}
 
				clearTimeout(t);
				//t=setTimeout("tnext()",vInterval);
				//t=setInterval("tnext()",vInterval)
				t=setTimeout('tnext()',vInterval)
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/\n/,"");
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/#/,"");
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/</,"");
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/>/,"");
				
				str=document.all.TName.value;				
				document.all.TName.value=str.replace(/=/,"");
				
				//str=document.all.TName.value;				
				//document.all.TName.value=str.replace(/+/,"");
				
				str=document.all.TName.value;								
				document.all.TName.value=str.replace(/%/,"");
				
				str=document.all.TName.value;				
				document.all.TName.value=str.replace(/@/,"");
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/&/,"");
				
				str=document.all.TName.value;
				document.all.TName.value=str.replace(/$/,"");
 
	t0=document.all.T0.value;	
 
				str=document.all.T0.value;				
				document.all.T0.value=str.replace(/\n/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/#/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/</,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/>/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/=/,"");
				
				//str=document.all.T0.value;
				//document.all.T0.value=str.replace(/+/,"");
				
				//str=document.all.T0.value;
				//document.all.T0.value=str.replace(/*/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/%/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/@/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/&/,"");
				
				str=document.all.T0.value;
				document.all.T0.value=str.replace(/$/,"");
				
				
 
	if (t0 !="") {	
		if (t5 !=""){
			if (t3 >0){
				//document.all.C1.style.background="#ECECD9"
 
				str=document.all.TOutgoing.value;								
				document.all.TOutgoing.value=str.replace(/\n/g,"~n~");
				
				str=document.all.TOutgoing.value;				
				document.all.TOutgoing.value=str.replace(/&/g,"~u~");
								
				str=document.all.TOutgoing.value;
				document.all.TOutgoing.value=str.replace(/#/g,"~p~");
 
				str=document.all.TOutgoing.value;
				document.all.TOutgoing.value=str.replace(/</g,"~1~");
 
				str=document.all.TOutgoing.value;
				document.all.TOutgoing.value=str.replace(/>/g,"~r~");
 
				str=document.all.TOutgoing.value;
				
				document.all.TOutgoing.value=str.replace(/=/g,"~e~");	
				// D=page number
				// P= password
				
				
 
// great reference to sending files of all kinds with different browsers
// https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest	
 
 
//
//				ajaxRequest = new XMLHttpRequest();
//				
//				
			    try {  ajaxRequest = new XMLHttpRequest();
				    document.all.T47.value="Ready"
   					 }
   					 
				   catch (e)     {
		       try { ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');         
			       document.all.T47.value="Ready"
		       	}
       			catch (e2)   {
				try { ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');          
					document.all.T47.value="Ready"
					}
					
					catch (e3)   {  ajaxRequest = false;   
						document.all.T47.value="Not supported!";
						
			          alert("Sorry, your browser does not seem to be supported.");          
			          
        				}
     				}				
     			}
 
			
 
 
msg1="asp/ReadLong.asp?R=" + document.all.T0.value + "-" + document.all.TPW.value + "&D=" + document.all.T1.value + "&P=" + '' + "&C=" + document.all.TName.value + "&F=" + vOF + "&M=" + document.all.TOutgoing.value
 
		if (vTest==0){
				ajaxRequest.open("GET", msg1, true);
		} else {
				//alert("http://www.411chat.com/" + msg1)
				ajaxRequest.open("GET", "http://www.411chat.com/" + msg1, true);
		}
 
			ajaxRequest.send(null);			
			//alert("Sent it!")				
			document.all.TOutgoing.value="";				
			//clearTimeout(t);
			t=setTimeout("tnext()",2000)
			//tt=setTimeout("tnext()",200)
			//tnext()
			}
			
		}
	}
}
 
 
 
 
 
var vF="#000000"
var tt="";
 
 
 
function fTimer(){
 
	clearTimeout(t)
	vInterval=document.all.D1.value
	t=setTimeout('tnext()',vInterval)
}
 
function fCI(){
	beep
}
 
 
document.all.T47.value="Browser not supported!"
 
 
 
t=setTimeout("tnext()",3000)
 
document.all.T47.value="Ready"
 
 
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>");
 
}
*/
 
// ajaxRequest
 
				ajaxRequest = new XMLHttpRequest();
				
				
			    try {  ajaxRequest = new XMLHttpRequest();
				    document.all.T47.value="Ready"
   					 }
   					 
				   catch (e)     {
		       try { ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');         
			       document.all.T47.value="Ready"
		       	}
       			catch (e2)   {
				try { ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');          
					document.all.T47.value="Ready"
					}
					
					catch (e3)   {  ajaxRequest = false;   
						document.all.T47.value="Not supported!";
						
			          alert("Sorry, your browser does not seem to be supported.");          
			          
        				}
     				}				
     			}
 
 
 
/*
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP.5.0");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				//return false;
			}
		}
	}
	
if (!ajaxRequest && typeof XMLHttpRequest!='undefined') {
	try {
		ajaxRequest = new XMLHttpRequest();
	} catch (e) {
		ajaxRequest=false;
	}
}
if (!ajaxRequest && window.createRequest) {
	try {
		ajaxRequest = window.createRequest();
	} catch (e) {
		ajaxRequest=false;
	}
} 
*/
 
var inField, e
var vOF="#000000"
 
 
function fKeyPress(inField,e){
 
    var charCode;
	if (e && e.which){
		charCode=e.which;
	} else if(window.event){
		e=window.event;
		charCode=e.keyCode;
	}
	if(charCode==13){
		fsend()
	}
}
function fOutgoing(n){
	vOF=n
}
 
TName.focus();
 
vTest=0
