var A_ids = new Array();
var A_phrase = new Array();
var A_message = new Array();
var A_mastercard = new Array();
var A_client_contact = new Array();
var A_members = new Array();

var idIndex = -1;

function FullScreen () {
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
}

function FillArrays() {
	FullScreen();
	var b_InMessageForms = false;
	tbls = document.getElementsByTagName('TABLE');
	for (i = 0; i < tbls.length; i++) {
		c1 = tbls[i].rows[0].cells[0].innerText;
		// alert(i + " : " + c1 + " : " + idIndex + " : " + tbls[i].outerHTML);
		if (c1 == 'Client ID') {
			 b_InMessageForms = false;
			 c2 = tbls[i].rows[2].cells[0].innerText;
			 idIndex++;
			 A_ids[idIndex] = c2;
			 A_phrase[idIndex] = tbls[i].rows[2].cells[4].innerText;
		}
		else if (c1.length > 7 && c1.substring(0,7) == 'Client ') {
			c2 = c1.substring(7);
			currentIdIndex = idIndex;
			
			myInt = parseInt(c2);
			if (isNaN(myInt)) {
				if (b_InMessageForms == true) 
					A_message[idIndex].innerHTML +=  tbls[i].outerHTML;
			} else {		
				idIndex++;
				A_ids[idIndex] = c2;
				A_phrase[idIndex] = tbls[i].rows[6].cells[1].innerText;
				b_InMessageForms = false;
			}	
		}
		else if (c1 == 'Locates') {
			 b_InMessageForms = false;
		}
		else if (b_InMessageForms == true) {
			A_message[idIndex].innerHTML +=  tbls[i].outerHTML;
		}
		else if (c1 == 'Message Slips') {
			 A_message[idIndex] = tbls[i];
		}
		else if (c1 == 'Message Forms') {
			 A_message[idIndex] = document.createElement("<span id=msg" + idIndex + "></span>");
			 A_message[idIndex].innerHTML = tbls[i].outerHTML;
			 b_InMessageForms = true;
		}
		else if (c1 == 'Mastercards') {
			 A_mastercard[idIndex] = tbls[i];
		}
		else if (c1 == 'Contact Information') {
			 A_client_contact[idIndex] = tbls[i];
		}
		else if (c1 == 'Members') {
			 A_members[idIndex] = tbls[i];
		}
	}

	document.all.txtID.value = A_ids[0];
	doClick();
}


function SetInnerHTML(doc_obj, array_obj) {
	if (array_obj)
		doc_obj.innerHTML = sDiv + array_obj.outerHTML + '</div>';
	else
		doc_obj.innerHTML = sDiv + '</div>';
}

function ShowElement() {
	document.all.clientid.innerText = A_ids[i];
	document.all.OriginalScreen.style.display="none";
	document.all.mainTable.style.display="inline";
	document.all.phrase.innerText = " C | " + A_phrase[i];
	w = (screen.availWidth / 2) - 30 ;
	h = (screen.availHeight / 2) - 145;
	sDiv =  '<div STYLE="width: ' + w + 'px; height: ' + h + '; overflow: auto;">';
	SetInnerHTML(document.all.mastercards,A_mastercard[i]);
	SetInnerHTML(document.all.messageslips,A_message[i]);
	SetInnerHTML(document.all.clientcontact,A_client_contact[i]);
	SetInnerHTML(document.all.members,A_members[i]);	
}

function FindIndex(v) {
	i = 0;
	while (A_ids[i] != v && i < A_ids.length)
		i++;

	if (A_ids[i] != v)   // not found
	   return -1;

	return i;   		 // found
}

function doClick() {
	i = FindIndex(document.all.txtID.value);
	if (i > -1)
		ShowElement(i)
	else
		alert("Client ID " + document.all.txtID.value + " not found");

	document.all.txtID.focus();
	document.all.txtID.select();
	return;
}


function AlterBody() {	
	document.body.innerHTML = '<table border=2 bordercolor="gray" width="100%" height="80%" id="mainTable" style="display:none; margin-left:-10; margin-top:-15">' + 
		'<tr height="3%"><td colspan=4 id="phrase"></td></tr>' +	
		'<tr height="3%"><td colspan=2 width="50%">&nbsp;</td><td colspan=2 width="50%"><center>Trk         Msg 0     Ifm : 0     ID  <span id=clientid></span></center></td></tr>' +	
		'<tr height="35%"><td valign="top"  width="50%" colspan=2 id="clientcontact"></td><td valign="top"  width="50%" colspan=2 id="members"></td></tr>' +	
		'<tr height="35%"><td valign="top"  width="50%" colspan=2 id="mastercards"></td><td valign="top"  width="50%" colspan=2 id="messageslips"></td></tr>' +	
		'<tr height="3%"><td width="60%" colspan=3>&nbsp;</td><td width="40%">&nbsp;</td></tr>' +	
		'<tr height="5%"><td width="100%" colspan=4>Enter client ID : <input type=text id="txtID" onKeyDown="if(event.keyCode==13) doClick();"><input type="button" value="Search" onclick="doClick()"  ></td></tr>' +	
		'</table>' +	
		'<div id="OriginalScreen">' +					  
			document.body.innerHTML + 
		'</div>';	
}

