var SCRAMBLE_RF = 57;
var card_index;//a
var port_index;//b
var global_rf_index;//a/b
var language;
var userName;
var channelNum;

window.onload = function()
{
	var args = getArgs();
	userName = args["userName"];	
	var group = args["group"];
	
	language = document.getElementById("language").value;
	var nodeId = args["nodeId"];
	if(nodeId == null)
	{
		nodeId = parent.curTree.getSelectedNodes()[0].id;
	}
	var str = nodeId.toString();
	var len = str.length;
	var cardVal = Math.pow(10, (len - 1));
	var portVal = Math.pow(10, (len - 2));
	card_index = parseInt(nodeId /cardVal) - 3;
	port_index = parseInt((nodeId %cardVal)/portVal);

	global_rf_index = card_index + "/" + port_index;
	
	PageLoadHandler();
}

function displayParam()
{
	var data;
	var rowNum;
	var length;
	var response;
	var singleChannelInfo;
	var channelIndex;
	var xmlHttp = getHTTPObject();
	
	xmlHttp.open("GET", "/goform/formIPQAM?type=" + SCRAMBLE_RF + "&cmd=" + GET + "&language=" + language + "&RFPort=" + global_rf_index + "&ran=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
		{
			response = AjaxStrDeal(xmlHttp.responseText);			
			if(response == "")
			{
				channelNum = 0;
			}
			else
			{
				data = response.split(FIRST_DELIMITER);
				channelNum = data.length;
			}
			rowNum = channelNum/4;
			DrawTableRow("dataTable", "dataRow", "CaseRow", rowNum);
			for(var i = 0; i < channelNum; i++)
			{
				var curRowNum = parseInt(i/4) + 1;
				singleChannelInfo = data[i].split(SECOND_DELIMITER);
				if((i + 1)%4 == 1)
				{
					$("#firstColChan" + curRowNum).html(singleChannelInfo[0]);
					$("#firstColStatus" + curRowNum).html(singleChannelInfo[1]);
				}
				else if((i + 1)%4 == 2)
				{
					$("#secondColChan" + curRowNum).html(singleChannelInfo[0]);
					$("#secondColStatus" + curRowNum).html(singleChannelInfo[1]);
				}
				else if((i + 1)%4 == 3)
				{
					$("#thirdColChan" + curRowNum).html(singleChannelInfo[0]);
				    $("#thirdColStatus" + curRowNum).html(singleChannelInfo[1]);
				}
				else if((i + 1)%4 == 0)
				{
					$("#fourthColChan" + curRowNum).html(singleChannelInfo[0]);
					$("#fourthColStatus" + curRowNum).html(singleChannelInfo[1]);
				}												
			}
			refreshFlag = true;
		}
	}
	xmlHttp.send(null);
}


function PageLoadHandler()
{
	document.body.style.cursor = "wait";
	window.status = "Retrieving data, please wait...";
	displayParam();
	document.body.style.cursor = "auto";
	window.status = "Done";
}

function pageRefresh()
{
	PageLoadHandler();
}

