var time = 30;
window.onload = function () {	
	move() ;
}
var RefStop = false;

function move() {
	//alert($F('max'))
//		alert($F('max'));
		if (!$('max')) return ;
	
		postStr ="lastrecord="+$F('max');		
		var t="";
			
		new Ajax.Request(base_url+'adminpanel/updatetr', {method:'post', postBody: postStr , onSuccess:getvalue});
	
		timer=setTimeout('move(true)',10000);	
}
function getvalue(t)
{
	resp_text = t.responseText
	if(Trim(resp_text) == "" ) return;

	ks_imei_start=resp_text.indexOf('<KS_IMEIID>');
	ks_imei_end=resp_text.indexOf('</KS_IMEIID>');

	tableid=resp_text.substring(ks_imei_start+11, ks_imei_end);	
	
	var tbl = document.getElementById('imeiinfo_'+tableid);
	var row = tbl.insertRow(1);
	
	xclass = Trim(tbl.rows[4].className)
	
	if ( xclass == 'tdeven' )
		xclass = 'tdeven'

	if ( xclass == 'tdodd' )
		xclass = 'tdodd'
	tbl.rows[2].className=xclass;	
	tbl.rows[2].setAttribute("class",xclass);
	
	row.setAttribute("class",'tdnew')
	row.className = 'tdnew'
	resp_text = Trim(resp_text)
	var i =0;
	mstart=resp_text.indexOf('<MAXID>');
	mend=resp_text.indexOf('</MAXID>');
	mvalue=resp_text.substring(mstart+7, mend);
	

	document.getElementById('max').value=parseInt(Trim(mvalue));
	
	while(true)
	{
		start = resp_text.indexOf('<STD>');
		end = resp_text.indexOf('<ETD>')
		if (start == -1) break;
		td_text = Trim(resp_text.substring((start+5),(end+5)))
		start = end+5
		new_string = Trim(resp_text.substring(start))
		resp_text = new_string;
		// strip td's from row_text 		
		var td1 = row.insertCell(i);	
		//onMouseOver="document.getElementById('tbtooltip<?=$i_tooltip?>').style.display='block'" 
		//onMouseOut="document.getElementById('tbtooltip<?=$i_tooltip?>').style.display='none'"
	//	td1.attachEvent("onMouseOver",imieMyOver(mvalue));		
	//	td1.attachEvent("onMouseOut",imieMyOut(mvalue));	
		td1.setAttribute("align","center")
		td1.innerHTML = td_text	
		td1.innerHTML = td1.innerHTML
		i++;
	}
	

	$F('cnt') = parseInt($F('cnt')) + 1
	
	var row = document.createElement("tr");
	tbl.appendChild(row);
	var tblBody = document.createElement("tbody");
	 tblBody.appendChild(t.responseText);
	 tbl.appendChild(tblBody);
        // appends <table> into <body>
        body.appendChild(tbl);

	var ps = Array(t.responseText);
	for(var i=0;i<ps.length;i++)
	{
		alert(ps[0]);	
	}
	 
      var tblBody = document.createElement("tbody");

        // creating all cells
        for (var j = 0; j < 2; j++) {
            // creates a table row
            var row = document.createElement("tr");

            for (var i = 0; i < 10; i++) {
                // Create a <td> element and a text node, make the text
                // node the contents of the <td>, and put the <td> at
                // the end of the table row
                var cell = document.createElement("td");
                var cellText = document.createTextNode("cell is row "+j+", column "+i);
                cell.appendChild(cellText);
                row.appendChild(cell);
            }

            // add the row to the end of the table body
            tblBody.appendChild(row);
        }

        // put the <tbody> in the <table>
        tbl.appendChild(tblBody);
        // appends <table> into <body>
        body.appendChild(tbl);
	//alert(t.responseText);
	
	//document.getElementById('imeiinfo').style.display='none';
	
}


function imieMyOver(v)
{
	document.getElementById('tbtooltip'+v).style.display='block'
}

function imieMyOut(v)
{
	document.getElementById('tbtooltip'+v).style.display='none'
}


/* Common Functions */
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function Trim( value ) {
	return LTrim(RTrim(value));
}


