psiType = PAT;

var menuIdArray = ["modifyTable", "", "", "", "", ""];
var MENU_NUM = 6;

function modifyTable()
{
	actionType = SET;
	operation = OPER_TABLE;
	displayParam();
	$("#editInfo").modal();
}

function displayParam() 
{
	var rowData;
	var data;
	var response;
	var xmlHttp = GetHTTPObject();

	xmlHttp.open("GET", "/goform/formEMR30?type=" + psiType + "&cmd=" + GET + "&language=" + language 
		+ "&slotNo=" + slotNo + "&id=" +id + "&ran=" + Math.random(), true);
	xmlHttp.onreadystatechange = function()
	{
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
		{
			response = AjaxStrDeal(xmlHttp.responseText);
			data = response.split(FIRST_DELIMITER);
			if(data != "")
			{
				if(data[0] == 0)
				{
					$("#networkInfo").prop("checked", false);
				}
				else if(data[0] == 1)
				{
					$("#networkInfo").prop("checked", true);
				}
				$("#streamId").val(data[1]);
				$("#versionNumber").val(data[2]);
				refreshFlag = true;		
			}			
		}
	}
	xmlHttp.send(null);	
}

function editPageApply()
{
	var data;
	var response;
	var xmlHttp = GetHTTPObject();
	
	if(paramCheck() == false)
	{
		return;
	}
	
	data = "type=" + psiType + "&cmd=" + SET + "&language=" + language + "&slotNo=" + slotNo + "&id=" + id + "&operation=" + operation + "&setString=";
	data += generateData();
	
	xmlHttp.open("POST", "/goform/formEMR30", true)
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", data.length);

	xmlHttp.onreadystatechange = function()
	{
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
		{
			$.modal.close();
			response = parseInt(AjaxStrDeal(xmlHttp.responseText), 10);
			if(response == RETURN_OK)
			{
				if(language == ENGLISH)
				{
					alert("Set Successfully!");
				}
				else
				{
					alert("设置成功！");
				}
			}
			else
			{
				alert(returnError[language][response]);
			}
			self.location.reload(true);
		}
	}
	xmlHttp.send(data);
}

function paramCheck()
{
	var returnFlag;
	if(operation == OPER_TABLE)
	{
		returnFlag = ValidateParam($("#streamId"), "INT_DEC", 0, 65535 , "<Transport Stream ID>", "<传送流ID>", language);
		if(returnFlag == false)
		{
			return false;
		}
		returnFlag = ValidateParam($("#versionNumber"), "INT_DEC", 0, 31 , "<Version Number>", "<版本号>", language);
		if(returnFlag == false)
		{
			return false;
		}
	}
	return true;
}

function generateData()
{
	var data;
	if(operation == OPER_TABLE)
	{
		if($("#networkInfo").prop("checked"))
		{
			data = 1;
		}
		else
		{
			data = 0;
		}
		data += FIRST_DELIMITER + $("#streamId").val() + FIRST_DELIMITER + $("#versionNumber").val();
	}
	return data;
}