//$Id: BandwidthMonitor.js,v 1.7 2011/07/15 04:43:20 aruljose Exp $
function changeHomeTab(homeDetailTab)
{

    var url = '/network/BandwidthMonitor.jsp?homeDetailTab='+homeDetailTab;
//alert(url);
    getHtml( url , 'showSelectColumn');	
}
function showSelectColumn(html)
{
          	  //showDialog(html,"title=Choose Columns,modal=yes, position=absolute, top=70, left=140, height=150, width=200");
                  //showDialog(html,"closeButton=no, modal=yes, position=relative, top=1, left=75");
                  //alert(html)
                  document.getElementById("summaryPage").innerHTML=html;
}

function setAction(f , value)
{
    f.actionFrom.value = value;
}
function validateBWMonitor()
{
	f = document.hostForm;

        if(document.hostForm.actionFrom.value=="addDevice")
        {
            f.ipOrHost.value = trim(f.ipOrHost.value);
            if(f.ipOrHost.value.length == 0)
            {
                    alert("Please enter an IP address or host name to monitor.");
                    f.ipOrHost.focus();
                    return false;
            }

            if(f.community.value.length == 0)
            {
                    alert("Please enter the community.");
                    f.community.focus();
                    return false;
            }
            var ip = f.ipOrHost.value;
            var parts = ip.split(".");

            if(parts[0].length == 0)
            {
                    alert("Please enter a valid IP address to monitor.");
                    f.ipOrHost.focus();
                    return false;
            }

            if(isNumber(parts[0]))
            {
                    if(!isValidIPAddress(f.ipOrHost.value))
                    {
                            alert("Please enter a valid IP address to monitor.");
                            f.ipOrHost.focus();
                            return false;
                    }
            }
            else
            {
                    if(!isSpecialCharacter(f.ipOrHost.value))
                    {
                            alert("Please enter a hostname without special characters.");
                            f.ipOrHost.focus();
                            return false;
                    }
            }

        }else if(document.hostForm.actionFrom.value=="addInterface")
        {
            if(!checkSelection("addInterface", "Please Select an Interface to add and monitor " ) )
			return false;
            if(eval(document.hostForm.selectAll))
            {
            	document.hostForm.selectAll.checked = false;
            }
       }

	return true;
}
function  modifyBWMonitor(menuItemName,refId,additionalParams,index)
{
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);
    var colInd1  = tblModel.getColumnIndex("BWInterfaces.ID");
    var colInd2  = tblModel.getColumnIndex("BWInterfaces.IFNAME");
    var ifID = tblModel.getValueAt(index,colInd1)
    var ifName = tblModel.getValueAt(index,colInd2)
    document.bandWidthModifyForm.ifID.value = ifID;
    document.bandWidthModifyForm.ifName.value = ifName;
    var tblDomModel = TableModel.getInstance(refId);
    tblDomModel.appendDetails(index,document.getElementById("modifyBWMonitor_div"));      
}

function cancelModifiedAction()
{
   var formDiv = document.getElementById("modifyBWMonitor_div");
   document.getElementById("modifyBWMonitor_container").appendChild(formDiv);
}
function bwMonitorModifiedAction(response,reqOptions)
{
   
   var formDiv = document.getElementById("modifyBWMonitor_div");
   document.getElementById("modifyBWMonitor_container").appendChild(formDiv);
   refreshSubView("BandWithMonitor",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));     
}
function deleteInterface(menuItemName,refId,additionalParams,index)
{
var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);
    var colInd1  = tblModel.getColumnIndex("BWInterfaces.ID");
    var colInd2  = tblModel.getColumnIndex("BWInterfaces.IFNAME");
    var ifID = tblModel.getValueAt(index,colInd1)
    var ifName = tblModel.getValueAt(index,colInd2)
    document.bandWidthModifyForm.ifID.value = ifID;
    document.bandWidthModifyForm.ifName.value = ifName;
    var tblDomModel = TableModel.getInstance(refId);
    //tblDomModel.appendDetails(index,document.getElementById("modifyBWMonitor_div"));      
}
var intervalID = "";
function refreshPage()
{
    window.clearInterval(intervalID);
    refreshSubView("BWSummaryPage",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));     
    intervalID = window.setInterval('refreshPage()',10000);
}

function BWAliasNameModifiedAction()
{
   closeDialog();

   refreshIPMangerView("BWMonitorDataView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
 }
 function modifyIFName(event,refId,index)
 {
    var tblModel = getTableModel(refId);
    var colInd1  = tblModel.getColumnIndex("BWInterfaces.ID");
    var colInd2  = tblModel.getColumnIndex("BWInterfaces.IFNAME");
    var colInd3  = tblModel.getColumnIndex("BandWidthHost.ID");
    var ifID = tblModel.getValueAt(index,colInd1)
    var ifName = tblModel.getValueAt(index,colInd2)
    var HID = tblModel.getValueAt(index,colInd3)
    showURLInDialog('/network/BWModifyifName.jsp?ifID='+ifID+'&ifName='+encodeURIComponent(ifName)+"&HID="+HID,'position=relative,modal=yes,scrollbars=no,title=Modify Interfaces Name');//No I18N
 }
 function editIcon(event)
 {
    alert(event);
 }
 

