// JavaScript Document
function rotatingimage(){
return '<img src="images/rotation.gif" alt="working">';
}

function processclearstats(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
document.getElementById('statistics').innerHTML = 'Statistics cleared'
}
}
}
function processaddtxtcode(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
/*alert('1stalert');*/
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
//var oSelect = document.getElementById( 'txtcodelist' );
var nextOptIndex = 0;
var newOpt = document.createElement( 'option' );
var data_array=myajax.responseText.split('|');
if(data_array[0]=='ERROR'){alert(data_array[0] + '-' + data_array[1]);}
else{
		if(data_array[0] > 0){
			newOpt.text = data_array[1];
			newOpt.value = data_array[0];
			newOpt.selected = true;
			//oSelect.options.add( newOpt, nextOptIndex );
			document.getElementById( 'addtxtcode' ).disabled='';
			ajaxpack.getAjaxRequest('include/ajaxfunction.php', 'action=getresponse&tcid=' + data_array[0], processgetresponse, 'txt');
			document.getElementById( 'tcid' ).value = data_array[0];
			window.location = "index.php?page=mytxtcodes&tcid="+data_array[0];
		}
		document.getElementById( 'freetxtcodes' ).value = data_array[2];
		//document.getElementById( 'usedtxtdisp' ).innerHTML = oSelect.length;
}/* end of check for error*/
document.getElementById( 'addtxtcode' ).value='added';
		checkadd();
}
}
}

function processremtxtcode(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
//var oSelect = document.getElementById( 'txtcodelist' );
//var data_array=myajax.responseText.split("|");
//var i;
//for(i=oSelect.options.length-1;i>=0;i--)
//{
//if(oSelect.options[i].value == data_array[0])
//oSelect.remove(i);
//}
//document.getElementById('freetxtcodes').value = data_array[1];
//document.getElementById( 'usedtxtdisp' ).innerHTML = oSelect.length;
//checkadd();
//document.getElementById('removetxtcode').value='remove';
//document.getElementById('removetxtcode').disabled='';
window.location='/index.php?page=mytxtcodes';
}
}
}

function checkadd(){
if(document.getElementById( 'freetxtcodes' ).value > 0 && document.getElementById( 'txtcode' ).value != document.getElementById( 'txtcode' ).defaultValue)
	{document.getElementById( 'addtxtcode' ).disabled='';}
else{document.getElementById( 'addtxtcode' ).disabled='disabled';}
}

function characterCount(field, count, maxchars) {
 if (field.value.length > maxchars) {
  field.value = field.value.substring(0, maxchars);
 } else {
  count.value = maxchars - field.value.length;
 }
}

function selecttxtcode(tcid){document.getElementById('tcid').value=tcid; ajaxpack.getAjaxRequest('include/ajaxfunction.php', 'action=getresponse&tcid=' + tcid, processgetresponse, 'txt');}

function processgetstatistics(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
document.getElementById( 'statistics' ).value = myajax.responseText;
if(myajax.responseText==''){document.getElementById( 'statistics' ).value = '842 statistics show you which txtcodes have been txted, the phone number they were sent from and when they were sent. This feature is enabled when you buy an add-on pack';}
}
}
}

function processgetlookup(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
document.getElementById('lookupbutton').disabled='';
document.getElementById('txtcodelookup').disabled='';
document.getElementById('lookupbutton').value=myajax.responseText;
if(myajax.responseText=='Available'){document.getElementById('lookupbutton').className='button-available';}
else{document.getElementById('lookupbutton').className='button-taken';}
}
}
}
function processbuildgraph(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
document.getElementById('graph').innerHTML = myajax.responseText;
}
}
}
function processsorttxtcode(){
var myajax=ajaxpack.ajaxobj
var myfiletype='txt';
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if(!myajax.responseXML.documentElement){
	var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
	xmlDocument.loadXML(myajax.responseText);
}
else{ xmlDocument = myajax.responseXML.documentElement;}

var txtcodes = xmlDocument.getElementsByTagName('txtcodes')[0].firstChild.data;
var txtoptions = txtcodes[0].getElementsByTagName("txtcode");
var oSelect = document.getElementById( 'txtcodelist' );
var nextOptIndex = 0;
for(var i=0; i<txtoptions.length; i++) { 
 
 var newOpt = document.createElement( 'option' );
newOpt.text = txtoptions[i].firstChild.nodeValue;
newOpt.value = txtoptions[i].getAttribute("id");
oSelect.options.add( newOpt, nextOptIndex )
}
}
}
}
function focuslogin(){
document.getElementById('email').focus()
}