//$Id: switchPortMapper.js,v 1.32 2009/02/24 07:06:56 karuppannan Exp $
function validateSPMInput(f)
{
    var version12 = f.snmpV1rV2Id.checked;
    var version3 = f.snmpV3Id.checked;
        var switchIP;
	var switchComm;
	//var routerIP;
	//var routerComm;
        var groupName;
        f.sysDetails.value = f.sysDetails.checked;
        if(f.actionFrom.value == 'modifySwitch')
	{
       
                switchIP = f.switchIPToModify;
		switchComm = f.switchCommunityToModify;
		//routerIP = f.routerIPToModify;
		//routerComm = f.routerCommunityToModify;

	}else if(f.actionFrom.value == 'csvModifySwitch' || f.actionFrom.value == 'modifySwitch' )
	{
		switchIP = f.switchIPToModify;
		switchComm = f.switchCommunityToModify;
		//routerIP = f.routerIPToModify;
		//routerComm = f.routerCommunityToModify;
                
	}
	else	
	{
          	switchIP = f.switchIP;
		switchComm = f.switchCommunity;
		//routerIP = f.routerIP;
		//routerComm = f.routerCommunity;
	}

        switchIP.value = trim(switchIP.value);
	switchComm.value = trim(switchComm.value);
	//routerIP.value = trim(routerIP.value);
	//routerComm.value = trim(routerComm.value);

	if(switchIP.value.length == 0)
	{
		alert("Please enter an IP address or host name of a switch.");
		switchIP.focus();
		return false;
	}
	if(version12 && switchComm.value.length == 0)
	{
		alert("Please enter the community for switch.");
		switchComm.focus();
		return false;
	} else if (version3) {
           /* var userName = f.username.value;
            if(userName.length == 0) {
                alert("Please enter username.");
                return false;
            }
            
            var authField = document.getElementById("authID");
            var authPass = document.getElementById("authPassID").value;
                if(authField.value != 'none') {
                    if(authPass.length == 0) {
                        alert("Authentication password cannot be empty.");
                        return false;
                    }
                    var privField = document.getElementById("privID");
                    var privPass = document.getElementById("privPassID").value;
                    if(privField.value != 'none' && privPass.length == 0) {
                        alert("Encryption password cannot be empty.");
                        return false;
                    }
                }*/
                return snmpV3Validation(f);
        }
         
	var ip = switchIP.value;
	var parts = ip.split(".");

	if(parts[0].length == 0)
	{
		alert("Please enter a valid IP address.");
		switchIP.focus();
		return false;
	}
        
	if(isNumber(parts[0]))
	{
		if(!isValidIPAddress(switchIP.value))
		{
			alert("Please enter a valid IP address.");
			switchIP.focus();
			return false;
		}
	}
	else
	{
		if(!isSpecialCharacter(switchIP.value))
		{
			alert("Please enter a valid IP address.");
			switchIP.focus();
			return false;
		}
	}
        /*
	if(routerIP.value.length != 0)
	{
		if(routerComm.value.length == 0)
		{
			alert("Please enter the community for router.");
			routerComm.focus();
			return false;
		}
	}

	if(routerComm.value.length != 0)
	{
		if(routerIP.value.length == 0)
		{
			alert("Please enter IP address or host name of a router.");
			routerIP.focus();
			return false;
		}
	}
        
	var ip = routerIP.value;
	var parts = ip.split(".");
	if(isNumber(parts[0]))
	{
		if(!isValidIPAddress(routerIP.value))
		{
			alert("Please enter a valid IP address.");
			routerIP.focus();
			return false;
		}
	}
	else
	{
		if(!isSpecialCharacter(routerIP.value))
		{
			alert("Please enter a valid IP address.");
			routerIP.focus();
			return false;
		}
	}
        */
	return true;
}
function checkStatus()
{
	var scanStatus = "";
	if(document.hostForm.switchID != undefined){
	if(document.hostForm.switchID.length != undefined){
	for(var k=0;k<document.hostForm.switchID.length;k++)
	{
		if(document.getElementById(document.hostForm.switchID[k].value+"statusVal").value == '1')
		{
			scanStatus = "true";
			break;
		}
	}
	}
	else
	{
		if(document.hostForm.switchID !=  undefined)
		{
			if(document.getElementById(document.hostForm.switchID.value+"statusVal").value == '1')			      {
				scanStatus = "true";
			}
		}
	}
	}
	if(scanStatus == "true")
	{
		intervalID = window.setInterval('getStatus()',8000);

	}
}
	
function getStatus()
{
	var action = "switchStatus";
	var selectedSwitchList = "";
	if(document.hostForm.switchID.length != undefined)
	{
	for(var k=0;k<document.hostForm.switchID.length;k++)
	{
		if(document.getElementById(document.hostForm.switchID[k].value+"statusVal").value == '1')
		{
			if(selectedSwitchList!='')selectedSwitchList+=",";
			selectedSwitchList+=document.hostForm.switchID[k].value;

		}
	}
	}
	else
	{
		if(document.hostForm.switchID !=  undefined)
		{
			if(document.getElementById(document.hostForm.switchID.value+"statusVal").value == '1')			      {
				selectedSwitchList = document.hostForm.switchID.value;
			}
		}
		
	}
	if(selectedSwitchList!=''){
		update(action, selectedSwitchList);
	}
	else {
		window.clearInterval(intervalID);
	}	
}
function showInputTable(value)
{
   
	var element;
        if (value=='add')
	{
		document.getElementById("modifyswitch").className = 'hide';
		document.hostForm.actionType.value="add";
		element=document.getElementById("inputTable");
		element.className = '';
		//document.hostForm.add.disabled=true;
        	//document.hostForm.add.className= "buttonDisabled";
	}
	if(value == 'addcancel')
	{
		element=document.getElementById("inputTable");
		element.className='hide';
		//document.hostForm.add.disabled=false;
                //document.hostForm.add.className= "Button";
	}
	if(value == 'modifycancel')
	{
                document.getElementById('showLink').style.visibility="hidden";
                //alert(document.getElementById('showLink').style.visibility)
                showAddLink();
		element=document.getElementById("modifyswitch");
		element.className='hide';
		//document.hostForm.add.disabled=false;
                //document.hostForm.add.className= "Button";
	}
	if(value == 'delete')
	{
		document.hostForm.actionType.value="delete";
		setAction("delete");	
	}
}
function spmSearchAction(action)
{
   
    if(document.hostForm.enterSearch.value == "no")
    {
        document.hostForm.actionFrom.value=action;
        setAction(action);
    }
}
function modify(configID , switchip, switchcomm, routerip, routercomm)
{	
        showAddLink();
       	document.hostForm.configID.value = configID;    
	document.getElementById("inputTable").className = 'hide';
	document.hostForm.actionType.value="modify";
	element=document.getElementById("modifyswitch");
	element.className='';
	//document.hostForm.add.disabled=true;
        //document.hostForm.add.className= "buttonDisabled";

	document.hostForm.switchIPToModify.value= switchip;
	document.hostForm.switchCommunityToModify.value=switchcomm;
	document.hostForm.routerIPToModify.value=routerip;
	document.hostForm.routerCommunityToModify.value=routercomm;
}
function deleteSwitch(configID, switchip)
{
	document.hostForm.configID.value = configID;
	if(confirm("Are you sure you want to delete "+switchip+ " switch?" ))
	{
		setAction('deleteSwitch');
	}
}
function setAction(action)
{
        if(action == 'modifySwitch' || action == 'deleteSwitch')
            {
                document.hostForm.actionFrom.value=action;
            
            }else if(action == 'addSwitchInput'){
                document.subnetAddForm.actionFrom.value=action;
                addNewSwitch(document.subnetAddForm);
	}
	else if(action == 'refrsh' || action == "refreshSelectedSwitch")
	{
		checkSelection(action);
	}
	
}
var req1;
function update1(actionFrom, switchList)
{
	var url = '/SwitchPortMapper.do?actionFrom='+actionFrom+'&selectedSwitch='+switchList+'&uid='+new Date().getTime();
	if(window.XMLHttpRequest)
	{
		req1 = new XMLHttpRequest();
		req1.onreadystatechange = processReqChange;
		req1.open("GET", url, true);
		req1.send(null);
	}
	else if(window.ActiveXObject)
        {
                isIE = true;
                req1 = new ActiveXObject("Microsoft.XMLHTTP");
                if(req1)
                {
			req1.onreadystatechange = processReqChange;
			req1.open("GET", url, true);
                        req1.send(null);
		}
	}
} 
var intervalID = "";
function processReqChange(){
	if(req1.readyState == 4)
	{
		if (req1.status == 200)
		{
			intervalID = window.setInterval('getStatus()',8000);

		}
	}
}

function update(actionFrom, switchList)
{
var req;
	var url = '/SwitchPortMapper.do?actionFrom='+actionFrom+'&selectedSwitch='+switchList+'&uid='+new Date().getTime();
	if(window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.open("GET", url, true);
                req.send(null);
		req.onreadystatechange = function() {
				if (req.readyState == 4)
				{
					if (req.status == 200)
					{
						var x = req.responseXML.getElementsByTagName('switchInfo');
						for(var i=0;i<x.length;i++)
						{
							if((x[i].getAttribute("status")) == 2)
							{
								document.getElementById(x[i].getAttribute("switchID")+"modify_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"modify_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"delete_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"delete_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").src = "/images/up.gif";
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").title = "Completed";
								document.getElementById(x[i].getAttribute("switchID")+"lastScanned").innerHTML = x[i].getAttribute("lastScanned");	
								document.getElementById(x[i].getAttribute("switchID")+"statusVal").value = x[i].getAttribute("status");	
							}
							else if(x[i].getAttribute("status") == 3){

								document.getElementById(x[i].getAttribute("switchID")+"modify_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"modify_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"delete_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"delete_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").src = "/images/down.gif";	
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").value = "Incomplete";
								document.getElementById(x[i].getAttribute("switchID")+"statusVal").value = x[i].getAttribute("status");	
							}
						}
					}
					else
					{
						alert("There was a problem");
					}
				}
			}; 
	}
	else if(window.ActiveXObject)
        {
                isIE = true;
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if(req)
                {
			req.onreadystatechange = function() {
				if (req.readyState == 4)
				{
					if (req.status == 200)
					{
						var x = req.responseXML.getElementsByTagName('switchInfo');
						for(var i=0;i<x.length;i++)
						{
							if((x[i].getAttribute("status")) == 2)
							{
								document.getElementById(x[i].getAttribute("switchID")+"modify_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"modify_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"delete_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"delete_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").src = "/images/up.gif";
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").title = "Completed";
								document.getElementById(x[i].getAttribute("switchID")+"lastScanned").innerHTML = x[i].getAttribute("lastScanned");	
								document.getElementById(x[i].getAttribute("switchID")+"statusVal").value = x[i].getAttribute("status");	

							}
							else if(x[i].getAttribute("status") == 3){

								document.getElementById(x[i].getAttribute("switchID")+"modify_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"modify_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"delete_enable").className='show';
								document.getElementById(x[i].getAttribute("switchID")+"delete_disable").className='hide';
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").src = "/images/down.gif";	
								document.getElementById(x[i].getAttribute("switchID")+"statusImg").value = "Incomplete";
								document.getElementById(x[i].getAttribute("switchID")+"statusVal").value = x[i].getAttribute("status");	


							}
						}

					}
					else
					{
						alert("There was a problem");
					}
				}


			}; 
		req.open("GET", url, true);
                req.send();
		}
	}
}

function checkSelection(action){
	var status = false;
	var selectedSwitch = "";
/*
        for(var i=0;i<document.hostForm.switchID.length;i++)
        {
                if(document.hostForm.switchID[i].checked)
                {
			if(selectedSwitch!='')selectedSwitch+=",";
			selectedSwitch+=document.hostForm.switchID[i].value;

			document.getElementById(document.hostForm.switchID[i].value+"modify_enable").className='hide';
                	document.getElementById(document.hostForm.switchID[i].value+"modify_disable").className='show';
			document.getElementById(document.hostForm.switchID[i].value+"delete_enable").className='hide';
                	document.getElementById(document.hostForm.switchID[i].value+"delete_disable").className='show';
			document.getElementById(document.hostForm.switchID[i].value+"statusImg").src = "/images/loading_img.gif";	
			document.getElementById(document.hostForm.switchID[i].value+"statusImg").title = "In Progress";
			document.getElementById(document.hostForm.switchID[i].value+"statusVal").value = "1";

			status = true;	
                }
	}
*/
        for(var i=0;i<document.getElementsByName("switchID").length;i++)
        {
                
                if(document.getElementsByName("switchID")[i].checked)
                {
			if(selectedSwitch!='')selectedSwitch+=",";
			selectedSwitch+=document.getElementsByName("switchID")[i].value;

			document.getElementById(document.getElementsByName("switchID")[i].value+"modify_enable").className='hide';
                	document.getElementById(document.getElementsByName("switchID")[i].value+"modify_disable").className='show';
			document.getElementById(document.getElementsByName("switchID")[i].value+"delete_enable").className='hide';
                	document.getElementById(document.getElementsByName("switchID")[i].value+"delete_disable").className='show';
			document.getElementById(document.getElementsByName("switchID")[i].value+"statusImg").src = "/images/loading_img.gif";	
			document.getElementById(document.getElementsByName("switchID")[i].value+"statusImg").title = "In Progress";
			document.getElementById(document.getElementsByName("switchID")[i].value+"statusVal").value = "1";

			status = true;	
                }
	}
	if(selectedSwitch != ''){
		update1(action, selectedSwitch);
	}
        
	if(!status)
        {
                alert("Please select the Switch to refresh");
                return false;
        }
        return true;
}

function isValidIPAddress(ipaddr)
{
        var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
        if (re.test(ipaddr))
        {
                var parts = ipaddr.split(".");
                if (parts.length < 4)
                {
                        return false;
                }
                if (parseInt(parseFloat(parts[0])) == 0)
                {
                        return false;
                }
                for (var i=0; i<parts.length; i++)
                {
                        if (parseInt(parseFloat(parts[i])) > 255) { return false; }
                }
                return true;
        } else
        {
                return false;
        }
}

function enterKeySearch(val , value , ev)
{
        if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(window.event.keyCode == 13)
		{
			document.hostForm.actionFrom.value = value;
			document.hostForm.enterSearch.value = "yes";
                        setAction(value);
		}
	}
	else if(navigator.appName == "Netscape")
	{
		if(ev.which == 13)
		{
			document.hostForm.actionFrom.value = value;
			document.hostForm.enterSearch.value = "yes";
                        setAction(value);
		}
	}
        return false;
}

function selectAllSwitch()
{
        var status = document.hostForm.selectAll.checked;

        if(!eval("document.hostForm.switchID.length"))
        {
                document.hostForm.switchID.checked = status;
                ToggleStyle(document.hostForm.switchID, status);
        }
        else
        {
                var len = document.hostForm.switchID.length;
                for(var i=0; i<len; i++)
                {
                        document.hostForm.switchID[i].checked = status;
                        ToggleStyle(document.hostForm.switchID[i], status);
                }
        }


}

function Toggle(e)
{
        ToggleStyle(e);
        if (e.checked)
        {
                document.hostForm.selectAll.checked = AllChecked();
        }
        else
        {
                document.hostForm.selectAll.checked = false;
        }
}

function AllChecked()
{
        ml = document.hostForm.switchID;
        len = ml.length;
        for(var i = 0 ; i < len ; i++)
        {
                if (!ml[i].checked)
                {
                        return false;
                }
        }
        return true;
}

function ToggleStyle(e, status)
{
        var r = null;
        if (e.parentNode && e.parentNode.parentNode)
        {
                r = e.parentNode.parentNode;
        }
        else if (e.parentElement && e.parentElement.parentElement)
        {
                r = e.parentElement.parentElement;
        }
        if (r)
        {
                if (r.className == "oddRow")
                {
                        r.className = "selectedRowOdd";
                }
                else if(r.className == "selectedRowOdd" & !status)
                {
                        r.className = "oddRow";
                }
                else if (r.className == "evenRow")
                {
                        r.className = "selectedRowEven";
                }
                else if(r.className == "selectedRowEven" & !status)
                {
                        r.className = "evenRow";
                }
        }
}
//Policy days saving action doing here 

function cancelModifiedAction()
{
   var addGroupElem = document.getElementById("addNewGroupID");
   if(addGroupElem.style.display == "block")
   {
        ShowNewGroupConfigField();
    }
   var formDiv = document.getElementById("modifySPMCSVInput_div");
   document.getElementById("modifySPMCSVInput_container").appendChild(formDiv);

}
function inputFieldAutoRefreshStop()
{
    window.clearInterval(switchRefreshIntervalID);   
    //window.clearInterval(csvImportingIntervalID);
}

function modifySwitchInputValues(menuItemName,refId,additionalParams,index)
{
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);

    var colInd1  = tblModel.getColumnIndex("SPMInputConfig.CONFIG_ID");
    var colInd2  = tblModel.getColumnIndex("SPMInputConfig.SWITCHNAME");
    var colInd3  = tblModel.getColumnIndex("SPMInputConfig.SWITCH_COMMUNITY");
    var colInd7  = tblModel.getColumnIndex("SPMInputConfig.SNMPSWEEPENABLED");
    var colInd5  = tblModel.getColumnIndex("GroupTaskName.TASK_NAME");
    var colInd6  = tblModel.getColumnIndex("GroupTaskName.TASK_ID");
     var colInd8  = tblModel.getColumnIndex("SPMInputConfig.SYSDETAILS");
    
    var configID = tblModel.getValueAt(index,colInd1)
    var switchName = tblModel.getValueAt(index,colInd2)
    var switchCommunity = tblModel.getValueAt(index,colInd3)
    var groupID = tblModel.getValueAt(index,colInd6)
     var groupName = tblModel.getValueAt(index,colInd5)
     var pingSweepEnabled = tblModel.getValueAt(index,colInd7)
     var sysDetails =tblModel.getValueAt(index,colInd8)
    
     var singleSwitch = 'singleSwitch';
    /*document.subnetInputForm.CONFIG_ID.value = configID;
    document.subnetInputForm.groupName.value = groupName;
    alert(groupName);
    document.subnetInputForm.groupID.value = groupID;
    document.subnetInputForm.switchIPToModify.value = switchName;
    document.subnetInputForm.switchCommunityToModify.value = switchCommunity;
    document.subnetInputForm.actionFrom.value="modifySwitch"; */
  //  alert(groupName + " grouID " + groupID + "pingSweepEnabled...." + pingSweepEnabled);
    //window.parent.document.getElementById("statusImage1").src = "/images/spacer.gif";

    //var tblDomModel = TableModel.getInstance(refId);
   // alert(refId);
     /*var url = '/SPMCsvModify.do?actionFrom=getGroupList&refId='+refId+'&index='+index+'&uid='+new Date().getTime();
     
     sendRequestForgetGroupList(url);
    inputFieldAutoRefreshStop();*/
    
    //tblDomModel.appendDetails(index,document.getElementById("modifySPMCSVInput_div")); ?device='+switchName+'&commun='+switchCommunity +'&pingSweepEnabled='+pingSweepEnabled
    showURLInDialog('/network/SPMCommonModifyInput.jsp?switchID='+configID+'&editFrom='+singleSwitch+'&selectedGroupID='+groupID+'&selectedSwitchName='+switchName+'&switchCommunity='+switchCommunity+'&pingSweepEnabled='+pingSweepEnabled+'&sysDetails='+sysDetails,'position=relative,modal=yes,width=520,scrollbars=no,title=Edit Switch');

}

function sendRequestForgetGroupList(url){
    
        if (window.XMLHttpRequest)
        {
                getGroupListReq = new XMLHttpRequest();
                getGroupListReq.onreadystatechange = getGroupListReqChange;
                getGroupListReq.open("GET", url, true);
                getGroupListReq.send(null);
        }
        else if (window.ActiveXObject)
        {
                isIE = true;
                getGroupListReq = new ActiveXObject("Microsoft.XMLHTTP");
                if (getGroupListReq)
                {
                        getGroupListReq.onreadystatechange = getGroupListReqChange;
                        getGroupListReq.open("GET", url, true);
                        getGroupListReq.send(null);
                }
        }
}
var getGroupListReq;
function getGroupListReqChange() 
{
	if (getGroupListReq.readyState == 4) 
	{
           
		if (getGroupListReq.status == 200) 
                {
                    var stat = trim(getGroupListReq.responseText);
                    //document.getElementById("groupName").value=gName;
                        var gId = document.subnetInputForm.groupID.value;
                        var x = getGroupListReq.responseXML.getElementsByTagName('groupNameList');
                       
                       var refIdObj = getGroupListReq.responseXML.getElementsByTagName('refId');
                        var refIdValue = refIdObj[0].getAttribute("refIDValue");
                        var indexObj = getGroupListReq.responseXML.getElementsByTagName('index');
                        var indexValue = indexObj[0].getAttribute("indexValue");
                       document.getElementById("addGroupNameID").innerHTML=" ";
                     
                        for(var i=0 ; i< x.length ; i++)
                        {
                             var switchIDValue = x[i].getAttribute("groupID");
                            var switchNameValue= x[i].getAttribute("groupName");
                            if(switchIDValue == gId)
                            {
                                document.subnetInputForm.addGroupNameID.options[document.subnetInputForm.addGroupNameID.options.length] = new Option(switchNameValue ,switchIDValue,  true, true);

                            }else
                            {
                                document.subnetInputForm.addGroupNameID.options[document.subnetInputForm.addGroupNameID.options.length] = new Option(switchNameValue , switchIDValue ,  true, false);	
                            }
                        }
                        var tblDomModel = TableModel.getInstance(refIdValue);
                        tblDomModel.appendDetails(indexValue,document.getElementById("modifySPMCSVInput_div")); 
                   //subnetInputForm
                }
	}


}

function modifyCSVInputValues(menuItemName,refId,additionalParams,index)
{
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);

    var colInd1  = tblModel.getColumnIndex("CSVSPMInputConfig.CONFIG_ID");
    var colInd2  = tblModel.getColumnIndex("CSVSPMInputConfig.SWITCHNAME");
    var colInd4  = tblModel.getColumnIndex("CSVSPMInputConfig.SNMPSWEEPENABLED");
    var colInd3  = tblModel.getColumnIndex("CSVSPMInputConfig.SWITCH_COMMUNITY");
    var colInd5  = tblModel.getColumnIndex("GroupTaskName.TASK_NAME");
    var colInd6  = tblModel.getColumnIndex("GroupTaskName.TASK_ID");
    
    var configID = tblModel.getValueAt(index,colInd1)
    var switchName = tblModel.getValueAt(index,colInd2)
    var switchCommunity = tblModel.getValueAt(index,colInd3)
    var pingSweepEnabled = tblModel.getValueAt(index,colInd4)
    var groupID = tblModel.getValueAt(index,colInd6)
    var groupName = tblModel.getValueAt(index,colInd5)

    var CSVSwitch = 'CSVSwitch';
    document.subnetInputForm.CONFIG_ID.value = configID;
    document.subnetInputForm.groupName.value = groupName;
    document.subnetInputForm.groupID.value = groupID;
    document.subnetInputForm.switchIPToModify.value = switchName;
    document.subnetInputForm.switchCommunityToModify.value = switchCommunity;
    //document.subnetInputForm.routerIPToModify.value = routerName;
    //document.subnetInputForm.routerCommunityToModify.value = routerCommunity;
    //document.subnetInputForm.groupNameID.value = groupName;

    document.subnetInputForm.actionFrom.value="modifyCSVSwitch";
  // window.parent.document.getElementById("statusImage1").src = "/images/spacer.gif";

    // var url = '/SPMCsvModify.do?actionFrom=getGroupList&refId='+refId+'&index='+index+'&uid='+new Date().getTime();
    // sendRequestForgetGroupList(url);
     
  showURLInDialog('/network/SPMCommonModifyInput.jsp?switchID='+configID+'&selectedGroupID='+groupID+'&editFrom='+CSVSwitch+'&selectedSwitchName='+switchName+'&switchCommunity='+switchCommunity+'&pingSweepEnabled='+pingSweepEnabled+'&sysDetails=1','position=relative,modal=yes,width=520,scrollbars=no,title=Edit Switch');

    //var tblDomModel = TableModel.getInstance(refId);
    //tblDomModel.appendDetails(index,document.getElementById("modifySPMCSVInput_div")); 
}

function showCSVimport() {

   var switchSettingElem = document.getElementById('importCSVID');
   document.ImportForm.actionFrom.value='cancel';
   if(switchSettingElem.style.visibility =="hidden") {
       switchSettingElem.style.visibility="visible";
   } else {
       switchSettingElem.style.visibility="hidden";
   }
   
}
function showImportCSVInfo()
{
	showImportCSVInfo("/html/spmInputCSVFormat.html");
        
}
function showImportCSVInfo(path)
{
	newwin=window.open(path);
        
}
function validateModify(f)
{
    if(f.actionFrom.value == "addNewGroupMod")
        {
           f.actionFromold.value="modifySwitch";     
            return false;    
        }else
        {
    
            f.actionFrom.value ="modifySwitch";

            return validateCSVInput(f);
        }
}
function validateCSVModify(f)
{
       if(f.actionFrom.value == "addNewGroupMod")
        {
            f.actionFromold.value="csvModifySwitch";
            return false;    
        }else
        {
            f.actionFrom.value ="csvModifySwitch";
            return validateCSVInput(f);
        }
}
function validateCSVInput(f){
    if(f.actionFromTemp.value == "addNewGroupName")
    {
        validateAndAddNewGroup(f)
        return false;

    }else if(f.actionFromTemp.value == "cancelNewGroupField")
    {
        return false;

    }else if(!validateSPMInput(f))
    {
        return false;
    }
    return true;
}
var groupConfigReq;
var formName; 
function validateAndAddNewGroup(f){
    formName = f;
    
    var gName = trim(f.newGroupName.value)
    if(gName.length == 0 )
    {
        alert("Please Enter new group name ");
        f.newGroupName.focus();

    }else
    {
         var url = '/SPMCsvModify.do?actionFrom=addNewGroup&newGroupName='+gName+'&uid='+new Date().getTime();
         sendRequestForAjaxUpdate(url,addNewGroupNameResponse)
    }
    
}
function addNewGroupNameResponse()
{
    if (groupConfigReq.readyState == 4) 
	{
            
		if (groupConfigReq.status == 200) 
                {
                    var responseTxt = trim(groupConfigReq.responseText);
                    if(responseTxt == "true")
                    {
                        //updateState("SPMAddView","addGroupNameID",sritchDir ,true);
                        refreshStatusView("SPMAddView");

                    }else
                    {
                         document.getElementById("groupErrorMssg").innerHTML=responseTxt;
                         formName.newGroupName.focus();
                    }
                    
                }       
	} 
}
function sendRequestForAjaxUpdate(url,onChangeMethod)
{
        isBlockedAction = true;

        if (window.XMLHttpRequest)
        {
                groupConfigReq = new XMLHttpRequest();
                groupConfigReq.onreadystatechange = onChangeMethod;
                groupConfigReq.open("GET", url, true);
                groupConfigReq.send(null);
        }

        else if (window.ActiveXObject)
        {
                isIE = true;
                groupConfigReq = new ActiveXObject("Microsoft.XMLHTTP");
                if (groupConfigReq)
                {
                        groupConfigReq.onreadystatechange = onChangeMethod;
                        groupConfigReq.open("GET", url, true);
                        groupConfigReq.send();
                }
        }
}

function validateInputSPM(f)
{
    
    if(f.actionFromTemp.value == "addNewGroupName")
    {
        validateAndAddNewGroup(f)
        return false;

    }else if(f.actionFromTemp.value == "cancelNewGroupField")
    {
        return false;

    }else 
    {
        var valResult = validateSPMInput(f);
        if(!valResult)
         {   
            return false;
         }   
    }
    return true;
}

function validateImport()
{
    var button = document.ImportForm.actionFrom.value
    if(button == "importCSVInput")
    {
        var path = trim(document.ImportForm.csvPath.value)
        if(path.length == 0)
        {
               alert("Select a CSV file ");
               return false;
        }else
        {
            var splitFile = path.split(".");
            var fileType = splitFile[splitFile.length - 1];
            if( fileType == 'csv' || fileType == 'CSV')
            { 
              return true;
            }else
            {
                 alert("Please Select a \".CSV\" file ");
               return false;
             }
            
            return true;
        }
        
    }
    return false;
}

//Refresh Importing View
var csvImportingIntervalID;
var importRefreshView;
var csvImportingSPMIntervalID;
function refreshCSVImportSummaryview(status)
{

  window.clearInterval(csvImportingIntervalID);  
  window.clearInterval(csvImportingSPMIntervalID);    
  if(status == "true")
  {
        csvImportingIntervalID = window.setInterval("refreshCSVImportSummary()", 10000);
        csvImportingSPMIntervalID = window.setInterval("refreshCSVSPMImportSummary()", 9000);

  }else
  {
     window.clearInterval(csvImportingIntervalID);  
     window.clearInterval(csvImportingSPMIntervalID);    
  }

  
}
function refreshCSVSPMImportSummary()
{
       refreshStatusView(document.hostForm.currentViewName.value);
        window.clearInterval(csvImportingSPMIntervalID);    
}

function refreshCSVImportSummary()
{
   refreshStatusView("SPMCsvImportSummaryView");
    window.clearInterval(csvImportingIntervalID);    
}

/*
function refreshCurrentView(status ,currentView)
{
    window.clearInterval(csvImportingIntervalID);
    if(status == 'true')
    {   
        importRefreshView = currentView;
        csvImportingIntervalID = window.setInterval("refreshImportView()",30000);

    }else
    {
        window.clearInterval(csvImportingIntervalID);
    }

   
}
function refreshImportView()
{
    renderViewCurrentView("SPMCsvImportSummaryView.cc" , "csvImportSummary");
    //renderView(importRefreshView);
    //refreshImportView("SPMCsvImportSummaryView")
    refreshStatusView(importRefreshView)
}
*/

var switchRefreshIntervalID;
function checkRefreshSwitchStatus(scanningStatus , isScanningStatus)
{
	window.clearInterval(switchRefreshIntervalID);
	if(scanningStatus == 'true' )
	{
		switchRefreshIntervalID = window.setInterval("refreshStatusView('SPMInputView')",30000);
		return;
	}else if(isScanningStatus == "true"){
		switchRefreshIntervalID = window.setInterval("refreshStatusView('SPMInputView')",3000);
		return;
	}else{
		window.clearInterval(switchRefreshIntervalID);
	}
}


function refreshStatusView(viewName)
{
    
    refreshSubView(viewName,false,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false})); 
}

function viewGroupSummary(menuItemName,refId,additionalParams,index)
{
    refreshStatusView("SPMScanning")
    var tblModel = getTableModel(refId);
    var colInd2  = tblModel.getColumnIndex("GroupTaskName.TASK_ID");
    var groupID = tblModel.getValueAt(index,colInd2)
    window.SELECTED_GROUP_ID = groupID;
    window.NO_MCK_PDF='no';
    window.clearInterval(switchRefreshIntervalID);
    window.SPM_CURRENT_TAB='SPM_SUMMARY';
    window.SPM_VIEW='SPMSummaryLayoutView.cc?groupNameID'+window.SELECTED_GROUP_ID;    
    document.hostForm.selectedSwitchTab.value="summaryInfoTab";
    renderView("SPMSummaryLayoutView.cc")
    document.hostForm.currentViewName.value =  "SPMSummaryLayoutView";
    ShowTab('switchSummary');
    renderView("SPMSummaryLayoutView.cc?groupNameID="+groupID);
    HideTab('switchConfig');
    HideTab('switchAlert');
    HideTab('switchHistory');
    HideTab('groupConfigTab');
    HideTab('routers');
    refreshSPMMAINView();
    refreshStatusView("SPMScanning")
}
function showAddFeildSPM(choice)
{
     showInputFeildSPM(choice);
     ShowInputField();
 }

//Input Tab Chooser
function showInputFeildSPM(choice)
{
    showInputFeildSPM(choice , "true")
}
function showInputFeildSPM(choice , isClose)
{
    var addSubnetLinkElem = document.getElementById("spmInputTable");
    if(addSubnetLinkElem.style.display == "block" && isClose == "true")
    {
         ShowInputField();
    }
    
      refreshStatusView("SPMScanning")
      refreshSPMMAINView();
       
 //   window.document.getElementById("errorAnchor").innerHTML="";
    window.NO_MCK_PDF='no';
    window.clearInterval(switchRefreshIntervalID);
    
    if(choice == 'switchSummary'){
            
            
            window.SPM_CURRENT_TAB='SPM_SUMMARY';
            window.SPM_VIEW='SPMSummaryLayoutView.cc?groupNameID'+window.SELECTED_GROUP_ID;    
        
            document.hostForm.selectedSwitchTab.value="summaryInfoTab";
            renderView("SPMSummaryLayoutView.cc")
            document.hostForm.currentViewName.value =  "SPMSummaryLayoutView";
            ShowTab('switchSummary');
            HideTab('switchConfig');
            HideTab('switchAlert');
            HideTab('switchHistory');
            HideTab('groupConfigTab');
            HideTab('routers');
            HideTab('reports');
            HideTab('audit');
            
            
    }else if(choice == 'switchConfig')
    {
            window.SPM_CURRENT_TAB='SPM_SUMMARY';
            window.SPM_VIEW='SPMInputView.cc?&groupNameID='+window.SELECTED_GROUP_ID;
            
            document.hostForm.selectedSwitchTab.value="switchConfigurationTab";
            renderView("SPMInputLayoutView.cc")
            document.hostForm.currentViewName.value = "SPMInputView";
            ShowTab('switchConfig');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchHistory');
            HideTab('groupConfigTab');
            HideTab('routers');
            HideTab('reports');
            HideTab('audit');
            
    }else if(choice == 'switchHistory')
    {
             window.SPM_CURRENT_TAB='SPM_SUMMARY';
            window.SPM_VIEW='SPMHistory.cc?&groupNameID='+window.SELECTED_GROUP_ID
            
            document.hostForm.selectedSwitchTab.value="switchHistoryTab";
            renderView("SPMHistory.cc")
            document.hostForm.currentViewName.value = "SPMHistory";
            ShowTab('switchHistory');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchConfig');
            HideTab('groupConfigTab');
            HideTab('routers');
            HideTab('reports');
            HideTab('audit');

    }else if(choice == 'groupConfigTab')
    {
            window.SPM_CURRENT_TAB='SPM_SUMMARY';
            window.SPM_VIEW='SPMGroupNameConfig.cc?&groupNameID='+window.SELECTED_GROUP_ID

            document.hostForm.selectedSwitchTab.value="groupConfigTab";;
            renderView("SPMGroupNameConfig.cc")
            document.hostForm.currentViewName.value = "SPMGroupNameConfig";
            ShowTab('groupConfigTab');
            HideTab('switchHistory');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchConfig');
            HideTab('routers');
            HideTab('reports');
            HideTab('audit');

    }else if(choice == 'routers') {
            document.hostForm.selectedSwitchTab.value="routers";;
            renderView("RouterListView.cc")
            document.hostForm.currentViewName.value = "RouterListView";
            ShowTab('routers');
            HideTab('switchHistory');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchConfig');
            HideTab('groupConfigTab');
            HideTab('reports');
            HideTab('audit');
            

    }  else if(choice == 'switchAlert') {
            window.SPM_CURRENT_TAB='SPM_SUMMARY';
            window.SPM_VIEW='SPMAlerts.cc?&groupNameID='+window.SELECTED_GROUP_ID

            document.hostForm.selectedSwitchTab.value="switchAlertTab";
            renderView("SPMAlerts.cc")
            document.hostForm.currentViewName.value = "SPMAlerts";
            ShowTab('switchAlert');
            HideTab('switchSummary');
            HideTab('switchConfig');
            HideTab('switchHistory');
            HideTab('groupConfigTab');
            HideTab('routers');
             HideTab('reports');
             HideTab('audit');
    } else if(choice == 'reports') {
            document.hostForm.selectedSwitchTab.value="reports";
            renderView("SPMReport.cc")
            document.hostForm.currentViewName.value = "SPMReport"; 
            ShowTab('reports');
            HideTab('routers');
            HideTab('switchHistory');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchConfig');
            HideTab('groupConfigTab');
            HideTab('audit');
    } else if(choice == 'audit') {
            document.hostForm.selectedSwitchTab.value="audit";
            renderView("AuditView.cc?auditFor=SWITCH_PORT_MAPPER")
            document.hostForm.currentViewName.value = "AuditView"; 
            ShowTab('audit');
            HideTab('routers');
            HideTab('switchHistory');
            HideTab('switchSummary');
            HideTab('switchAlert');
            HideTab('switchConfig');
            HideTab('groupConfigTab');
            HideTab('reports');
    }
    //alert("211");
  //  refreshSubView("RouterNotAddedView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:true}));
    refreshSubView("SPMNoSwitchAdded",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
    refreshSPMRouter(250);
}

function showSPMResult(choice , switchID , importField )
{
        selectedSwitch = document.hostForm.selectedSwitch.value;
        document.hostForm.selectedSwitchResult.value=choice;
        window.NO_MCKCLENT_PDF='yes';
        window.NO_MCK_PDF = 'true';
        window.SPM_CURRENT_TAB='SPM_SUMMARY';
       //alert(switchID);
        window.SPM_VIEW='SPMSwitchResultExportView.cc?switchID='+switchID;
        var url;
        closeCSVImportSettings();  
        if(choice == 'switchResultHistory')
        {
               var switchName = document.hostForm.switchName.value;
               url = "SPMHistoryView.cc?&switchIP="+selectedSwitch+"&switchDir="+switchName+"&selectedSwitch="+selectedSwitch+"&isTab=true";
               
               
        }else if(choice == 'switchAlerts'){
            
                url = "SPMSwitchAlertTableView.cc?&switchIP="+selectedSwitch+"&selectedSwitch="+selectedSwitch +"&isTab=true";
                window.SPM_VIEW="SPMSwitchAlertTableView.cc?&switchIP="+selectedSwitch;
                
        }else{
        
                var search = document.hostForm.search.value;                
                url = "/SPMSwitchResultView.cc?switchIP="+selectedSwitch+"&selectedSwitch="+selectedSwitch+"&search="+search+"&isTab=true";               
                
    }    
    renderViewSPMResultView( url , "switchResultID" , importField);
    window.clearInterval(intervalID);
    
}
function renderViewSPMResultView(viewName , localVar , importField)
{
    var myAnonFunction = function(response,reqOptions)
    {        
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
       checkSPMResultStatus();
       if(importField)
       {
               showSwitchSettings();
       }
       
    };
    AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});

}
function closeCSVImportSettings() {

   var switchSettingElem = document.getElementById('csvTableID');
   if(switchSettingElem.style.visibility =="visible") {
        
       switchSettingElem.style.visibility="hidden";
       
   }
   
}

function viewSwitchName(menuItemName,refId,additionalParams,index)
{
    var tblModel = getTableModel(refId);
    var colInd2  = tblModel.getColumnIndex("SPMInputConfig.SWITCHNAME");
    var switchName = tblModel.getValueAt(index,colInd2)
    renderView("SPMHistoryView.cc?switchDir="+switchName);
}

function viewSwitchResult(menuItemName,refId,additionalParams,index)
{
    var tblModel = getTableModel(refId);
    var colInd1  = tblModel.getColumnIndex("SPMInputConfig.CONFIG_ID");
    var colInd2  = tblModel.getColumnIndex("SPMInputConfig.SWITCHNAME");
    
     var configID = tblModel.getValueAt(index,colInd1)
     var switchName = tblModel.getValueAt(index,colInd2)
    renderView("SPMResultView.cc?selectedSwitch="+configID);
}

function viewSwitchHistory(sritchDir)
{
    updateState("SPMHistoryTableView","switchDir",sritchDir ,true);
    refreshSubView("SPMHistoryTableView");
}
function renderView(viewName)
{
    var localVar = "tt";
    renderViewCurrentView(viewName , localVar)
}
function renderViewCurrentView(viewName , localVar)
{
    
    var myAnonFunction = function(response,reqOptions)
    {        
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
    };
    AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});

}

function ShowTab(divId)
{
	var id = document.getElementById(divId);
	id.style.display = "block";
}
function HideTab(divId){
	var id = document.getElementById(divId);
	id.style.display = "none";
}
function ShowAddNewSwitch()
{
      var  url = '/SwitchPortMapper.do?actionFrom=enbleInputField&uid='+new Date().getTime();
      updateStaus(url); 
      showInputFeildSPM('switchConfig');
      
}

function SPMInputcloseIcon()
{
   var addGroupElem = document.getElementById("groupAddDiv");
   if(addGroupElem.style.display == "block")
   {
        ShowGroupConfigField();
    }
   ShowInputField();
}
function ShowInputField()
{  
   window.document.getElementById("SPMErrorAnchor11").innerHTML=""; 
   var addSubnetLinkElem = document.getElementById("spmInputTable");
   var url; 
   if(addSubnetLinkElem.style.display =="none") {
        if(document.hostForm.currentViewName.value != "SPMInputView")
        {
            showInputFeildSPM('switchConfig');
        }    
        addSubnetLinkElem.style.display="block";
        url = '/SwitchPortMapper.do?actionFrom=enbleInputField&uid='+new Date().getTime();
      
    }else{
   
       addSubnetLinkElem.style.display="none";
       url = '/SwitchPortMapper.do?actionFrom=hideInputField&uid='+new Date().getTime();
      
   }
   updateStaus(url);
}

function updateStaus(url){
    
        if (window.XMLHttpRequest)
        {
                req2 = new XMLHttpRequest();
                req2.onreadystatechange = processReqChange2;
                req2.open("GET", url, true);
                req2.send(null);
        }
        else if (window.ActiveXObject)
        {
                isIE = true;
                req2 = new ActiveXObject("Microsoft.XMLHTTP");
                if (req2)
                {
                        req2.onreadystatechange = processReqChange2;
                        req2.open("GET", url, true);
                        req2.send(null);
                }
        }
}
var req2;
function processReqChange2() 
{
	if (req2.readyState == 4) 
	{
		if (req2.status == 200) 
                {
                    var stat = trim(req2.responseText);
                }
	}


}


//end

function importCSV(f ,action)
{
    //document.ImportForm.selectedSwitchTab.value = "switchConfigurationTab";
    f.actionFrom.value=action;
    
}

function csvModifiedAction(response,reqOptions)
{
 //  var formDiv = document.getElementById("modifySPMCSVInput_div");
//   document.getElementById("modifySPMCSVInput_container").appendChild(formDiv);
   refreshSubView("CSVSPMInputView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   closeDialog();
}

function modifiedAction(response,reqOptions)
{
 //  var formDiv = document.getElementById("modifySPMCSVInput_div");
  // document.getElementById("modifySPMCSVInput_container").appendChild(formDiv);
   refreshSubView("SPMInputView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));     
    closeDialog();
}
function validateSPM()
{

    var button = document.hostForm.actionFrom.value
    if(button == "ConnectedIPInSPM")
    {
          return true;  
    }else if(button == "importCSVInput")
    {
        var path = trim(document.hostForm.csvPath.value)
        if(path.length == 0)
        {
               alert("Select a CSV file ");
               return false;
        }else 
        {

            return true;
        }
        
    }
    if(document.hostForm.actionFromTemp.value == 'cancel')
    {
        return false;
    }
    return false;
}
function setValue(action)
{
        document.hostForm.actionFrom.value=action;
        document.hostForm.submit();
}

function showPass(val,divId,hideID) {
      
       window.document.getElementById("errorAnchor").innerHTML="";
       //window.document.getElementById("resultAnchor").innerHTML="";
       
        document.hostForm.actionFromTemp.value = val;
        
        var showElem = document.getElementById(divId);
        var hideElem = document.getElementById(hideID);
       
        if(hideElem.style.visibility =="visible")
        {
            hideElem.style.visibility="hidden";
        }
        if(showElem.style.visibility =="hidden")
        {
                
                showElem.style.visibility="visible";
	        if(divId == "alertDiv")
                {
                        var value = "getAlertStatus";
			var url = '/SwitchPortMapper.do?&actionFrom=alertStatus&action='+val+'&uid='+new Date().getTime();
                        persistVal(url);
                    
                }else
                {
                      
                    var url = '/SwitchPortMapper.do?&actionFrom='+val+'&uid='+new Date().getTime();
                    persist(url);
                }
        }
        else
        {
                if(val == "cancel")
                {

        		 showElem.style.visibility="hidden";
                        
		}
		else{
		 if(divId == "alertDiv")
                {
                    if(val=="sendAlerts" || val =="stopAlerts")
                    {
                        var value = "getAlertStatus";
			var url = '/SwitchPortMapper.do?&actionFrom=alertStatus&action='+val+'&uid='+new Date().getTime();
                        persistVal(url);
                    }
                }

                showElem.style.visibility="hidden";
		}
        }
        
}
var button;

function persistVal(url)
{
        button =document.hostForm.actionFromTemp.value;    
        if (window.XMLHttpRequest)
        {
                req2 = new XMLHttpRequest();
                req2.onreadystatechange = processReqChange2;
                req2.open("GET", url, true);
                req2.send(null);
        }
        else if (window.ActiveXObject)
        {
                isIE = true;
                req2 = new ActiveXObject("Microsoft.XMLHTTP");
                if (req2)
                {
                        req2.onreadystatechange = processReqChange2;
                        req2.open("GET", url, true);
                        req2.send(null);
                }
        }
}
function processReqChange2() 
{
	if (req2.readyState == 4) 
	{
		if (req2.status == 200) 
                {
                    var stat = trim(req2.responseText);
                    
                    if(button == "sendAlerts")
                    {
                        showPass("sendAlerts", "alertDiv" ,"passwordchange");
                    }
                    else if(button == "stopAlerts")
                    {
                        showPass("stopAlerts", "alertDiv", "passwordchange");

                    }else if(button == "getAlertStatus")
                    {
                        var x = req2.responseXML.getElementsByTagName('alertStatus');

                        if(x[0].getAttribute("SoundOption") == "1")
                        {
                            
                            document.hostForm.selectSound.checked = true;
                        }else
                        {
                            document.hostForm.selectSound.checked = false;
                        }
                        
                        if(x[0].getAttribute("EmailOption") == "1")
                        {
                            
                            document.hostForm.emailID.checked = true;
                            document.hostForm.toAdd.disabled=false;

                        }else
                        {
                            document.hostForm.emailID.checked = false;
                            document.hostForm.toAdd.disabled=true;
                        }
                        document.getElementById("toAdd").value=x[0].getAttribute("ToAddress");
                      }
		}       
		else
                {
			//alert("There was a problem retrieving the XML data:\n" +req.statusText);
                 }
	}


}

var req;

function saveValue(f,value)
{
        document.hostForm.actionFromTemp.value=value;
        var passwordchangeElem = document.getElementById('passwordchange');
        //window.document.getElementById("errorAnchor").innerHTML="";
        //window.document.getElementById("resultAnchor").innerHTML="";
        if(f.days.value.length == 0)
        {
                window.document.getElementById("errorAnchor").innerHTML="Please enter the Number of Days value.";
                f.days.focus();
                return false;
        }
        if(parseInt(f.days.value)  != f.days.value)
        {
                window.document.getElementById("errorAnchor").innerHTML="Number fo days value should be an integer.";
                f.days.focus();
                return false;
        }
        if(f.days.value < 1 || f.days.value > 299)
        {
                window.document.getElementById("errorAnchor").innerHTML="Number of days value should be between 1 a nd 299.";
                f.days.focus();
                return false;
        }
        setResolveDNS();
        setExcluteTrunkPort();
        var excludeTrunkPort = window.document.getElementById("excludeTrunkPorts").value;
        var daysVal = f.days.value;
        var resolveDNSVal = f.resolveDNS.value;
        var url = '/SwitchPortMapper.do?&actionFrom='+value+'&days='+daysVal+'&resolveDNS='+resolveDNSVal+'&excludeTrunkPort='+excludeTrunkPort+'&uid='+new Date().getTime();
        persist(url);
}

function persist(url)
{

        if (window.XMLHttpRequest)
        {
                req = new XMLHttpRequest();
                req.onreadystatechange = processReqChangeDay;
                req.open("GET", url, true);
                req.send(null);
        }

        else if (window.ActiveXObject)
        {
                isIE = true;
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req)
                {
                        req.onreadystatechange = processReqChangeDay;
                        req.open("GET", url, true);
                        req.send();
                }
        }
}
function setExcluteTrunkPort()
{
    if(window.document.getElementById("excludeTrunkPort").checked)
    {
        window.document.getElementById("excludeTrunkPort").value = "true";
    }
    else
    {
                window.document.getElementById("excludeTrunkPort").value = "false";
    }
}

function setResolveDNS()
{
    if(window.document.getElementById("resolveDNS").checked)
    {
        window.document.getElementById("resolveDNS").value = "true";
    }
    else
    {
                window.document.getElementById("resolveDNS").value = "false";
    }
    
}
function setIfIndex()
{   
   if(window.document.getElementById("ifIndex").checked)
    {
        window.document.getElementById("ifIndex").value = "true";
    }
    else
    {
                window.document.getElementById("ifIndex").value = "false";
    }
    
}
var daysValue;
function processReqChangeDay()
{
       // window.document.getElementById("errorAnchor").innerHTML="";
       // window.document.getElementById("resultAnchor").innerHTML="";
        if (req.readyState == 4) 
	{
	
		if (req.status == 200) 
                {
                    var action = trim(document.hostForm.actionFromTemp.value);
                    if(action == "showDays")
                    {
                        
                        var x = req.responseXML.getElementsByTagName('SPMSettings');;
                        var resolveDNSValue = trim(x[0].getAttribute("resolveDNS"));
                        var daysValue= trim(x[0].getAttribute("noOfDays"));
                        var excludeTrunkPort= x[0].getAttribute("isExcludeTrunkPort");

                        if(parseInt(daysValue)  == daysValue)
                        {
                            window.document.getElementById("days").value=daysValue;
                        }
                        else
                        {
                            window.document.getElementById("days").value="";
                        }
                        if(resolveDNSValue == 'true')
                        {
                            window.document.getElementById("resolveDNS").checked = true;
                        }
                        else
                        {
                            window.document.getElementById("resolveDNS").checked = false;
                        }
                        if(excludeTrunkPort == 'true')
                        {
                            window.document.getElementById("excludeTrunkPorts").checked = true;
                        }
                        else
                        {
                            window.document.getElementById("excludeTrunkPorts").checked = false;
                        }

                        setResolveDNS();
                        setExcluteTrunkPort();
                            
                    }
                    else if(action == "saveDays")
                    {
                        var result = trim(req.responseText);
                        if(result=="Success")
                        {
                            //window.document.getElementById("resultAnchor").innerHTML="Available policy days updated";
                            showPass("cancel" , "passwordchange" ,"alertDiv" );
                        }
                        else
                        {
                            window.document.getElementById("errorAnchor").innerHTML="Available policy days update Failed";
                        }
                    }else if(action == "stopImportScanning")
                    {
                        var currentPage =document.hostForm.inProgressPage.value;
                        if(currentPage == "mainPage")
                        {
                            refreshSubView("SPMCsvImportSummaryView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
                        }else
                        {
                            refreshSubView("SPMCsvLayoutView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
                        }
                    }else if(action == "stopScanning")
                    {
                       
                            refreshSubView("SPMInputView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
                    }

                 }       
		else
                {  
			alert("There was a problem retrieving the XML data:\n" +req.statusText);
		}
	}
}

function stopScanningInprogress(value)
{
    var url = '/SwitchPortMapper.do?&actionFrom='+value+'&uid='+new Date().getTime();
    document.hostForm.actionFromTemp.value = value;
    persist(url);
}
function showAddLink() {
     
        var passwordchangeElem = document.getElementById('showLink');
        passwordchangeElem.style.visibility 
    if(passwordchangeElem.style.visibility =="hidden") {
           passwordchangeElem.style.visibility="visible";
      
   } else {
       passwordchangeElem.style.visibility="hidden";
   }
   
}

function setAlertStatus(value)
{
	var request;
	var toAddress = document.hostForm.toAdd.value;
	var soundOption = document.hostForm.selectSound.checked; 
	var soundFile = document.hostForm.soundFile.value; 
        var mailOption = document.hostForm.emailID.checked; 
             
	var url;	
	if(value == "sendAlerts")
	{
	
		if(mailOption == true)
                {
                    toAdd1 = toAddress.split(",");
                    for(var i = 0 ; i< toAdd1.length ; i++)
                    {
                        if(!validateEmail(toAdd1[i]))
                        {
                            return false;
                        }
                    }
                }
                

		url = '/SwitchPortMapper.do?action='+value+'&actionFrom=alertStatus&toAddress='+toAddress+'&soundOption='+soundOption+'&soundFile='+soundFile+'&mailOption='+mailOption;
	}else if(value == "stopAlerts")
	{
		url = '/SwitchPortMapper.do?actionFrom='+actionFrom+'&toAddress='+toAddress+'&soundOption='+soundOption+'&soundFile='+soundFile+'&alertStatus='+stop+'&mailOption='+mailOption;
	}
	if(window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
		request.open("GET", url, true);
		request.send(null);
		request.onreadystatechange = function() {
			if (request.readyState == 4)
			{
				if (request.status == 200)
				{
				        showPass("cancel", "alertDiv", "passwordchange");
				}
				else
				{
					alert("There was a problem");
				}
			}
		}; 
	}
	else if(window.ActiveXObject)
	{
		isIE = true;
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if(request)
		{
			request.onreadystatechange = function() {
				if (request.readyState == 4)
				{
					if (request.status == 200)
					{
						showPass("cancel", "alertDiv", "passwordchange");
					}
					else
					{
						alert("There was a problem");
					}
				}


			}; 
			request.open("GET", url, true);
			request.send();
		}
	}	

}
var moving=false
var IE=document.all
function Dragnow(e,id)
{
    divID = id;
    curposx=(IE ? event.clientX : e.pageX) // Cursorx Start Position
    curposy=(IE ? event.clientY : e.pageY) // Cursory Start Position
    objectx=parseInt(document.getElementById(id).style.left) // Objectx Start Position
    objecty=parseInt(document.getElementById(id).style.top) // Objecty Start Position
    moving=true
    document.onmousemove=Moveto
}
var divID ;
function Moveto(e )
{
    xx=(IE ? event.clientX : e.pageX)
    yy=(IE ? event.clientY : e.pageY)
    if (moving==true)
    {
        document.getElementById(divID).style.left = xx-(curposx-objectx)
        document.getElementById(divID).style.top=yy-(curposy-objecty)
        return false
    }
}

function scheduleWindow(linkParams)
{
        showInputFeildSPM('routers');
        if (navigator.appName == 'Netscape')
        {
                newwin=window.open("/network/SPMScheduler.jsp?"+linkParams,"Schedule","resizable=yes,screenX=300,screenY=250,scrollbars=no,toolbar=no,width=500,height=325","centre");
        }
        else
        {
                newwin=window.open("/network/SPMScheduler.jsp?"+ linkParams,"Schedule","resizable=yes,scrollbars=yes,toolbar=no,width=500,height=325","centre");
        }
}
function clearField(f)
{
    f.SEARCH_VALUE.value="";
}

function addNewGroup()
{
    window.open("/network/SPMGroupConfig.jsp?&actionFrom=addGroupName&selectedSwitchTab=switchConfigurationTab" ,"Add New Group","resizable=yes,screenX=300,screenY=250,scrollbars=yes,toolbar=no,width=600,height=400","centre");
}


function addNewSwitch(f)
{
    
    f.actionFrom.value = "addSwitchInput";
    if(!validateInputSPM(f))
    {
        return false;
    }
    window.document.getElementById("SPMErrorAnchor11").innerHTML = "<img   src=/images/loading_img.gif border=0 ><span class=greentxt> Adding the switch, Please wait </span>";
   // window.parent.document.getElementById("SPMstatusImage1").src = "/images/loading_img.gif";
    var switchIP = f.switchIP.value;
    var switchCommunity  = f.switchCommunity.value;
    var addGroupNameID = document.subnetAddForm.addGroupNameID.value;
    var url = '/SPMCsvModify.do?actionFrom=addSwitchInput&switchIP='+switchIP+'&switchCommunity='+switchCommunity+'&addGroupNameID='+addGroupNameID+'&uid='+new Date().getTime();
    sendRequestForAddSwitch(url);
    return false;
    
}
var SPMajaxRequest;
function sendRequestForAddSwitch(url)
{
        button =document.hostForm.actionFromTemp.value;    
        if (window.XMLHttpRequest)
        {
                SPMajaxRequest = new XMLHttpRequest();
                SPMajaxRequest.onreadystatechange = ajaxResponseChane;
                SPMajaxRequest.open("GET", url, true);
                SPMajaxRequest.send(null);
        }
        else if (window.ActiveXObject)
        {
                isIE = true;
                SPMajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                if (SPMajaxRequest)
                {
                        SPMajaxRequest.onreadystatechange = ajaxResponseChane;
                        SPMajaxRequest.open("GET", url, true);
                        SPMajaxRequest.send(null);
                }
        }
        return false;
}

function ajaxResponseChane()
{
    if (SPMajaxRequest.readyState == 4) 
	{
	
		if (SPMajaxRequest.status == 200) 
                {
                    
                    var responseTxt = trim(SPMajaxRequest.responseText);
                    //window.parent.document.getElementById("SPMstatusImage1").src = "/images/spacer.gif";
                    if(responseTxt == 'true')
                    {
                        window.document.getElementById("SPMErrorAnchor11").innerHTML="<span class=greentxt>Sucessfully added</span>";
                        document.subnetAddForm.switchIP.value = "";
                        showInputFeildSPM('switchConfig' , "false");
                        refreshStatusView(document.hostForm.currentViewName.value);
                        refreshSPMSwitch(100)
                        refreshSPMRouter(500);
 
                    }else
                    {
                         window.document.getElementById("SPMErrorAnchor11").innerHTML="<span class=redtxtbold>"+responseTxt+"</span>";    
                    }    
                }       
		else
                {  
			alert("There was a problem retrieving the XML data:\n" +SPMajaxRequest.statusText);
		}
	}
}
var SPMrefreshIntervalID;
function refreshSPMRouter(value)
{
 window.clearInterval(SPMrefreshIntervalID);
 SPMrefreshIntervalID = window.setInterval('refreshSPMRouterView()', value );
}
function refreshSPMRouterView()
{
         window.clearInterval(SPMrefreshIntervalID);
         refreshSubView("RouterNotAddedView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:true}));
}

var SPMNoSwitchrefreshIntervalID;
function refreshSPMSwitch(value)
{
 window.clearInterval(SPMNoSwitchrefreshIntervalID);
 SPMNoSwitchrefreshIntervalID = window.setInterval('refreshSPMSwitchView()', value );
}
function refreshSPMSwitch()
{
         window.clearInterval(SPMNoSwitchrefreshIntervalID);
         refreshSubView("SPMNoSwitchAdded",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:true}));
}

function setSPMActionValue(f,action)
{
    f.actionFrom.value = action;
    ShowInputField();
}

 function saveNewGroupConfigValue(f,actionFromValue)
{
   // window.document.getElementById("SPMGroupErrorAnchor11").innerHTML="";
    var newGroupName = trim(f.GROUP_NAME.value);
    if(newGroupName.length == 0)
    {
        alert("Please enter Group Name")
        return false;
    }
    f.actionFrom.value = actionFromValue;   
    var adminStatus = f.adminStatus.value
    var SCHEDULE_TYPE = f.SCHEDULE_TYPE.value;
    var HOURLY_START_TIME_HOUR = f.HOURLY_START_TIME_HOUR.value;
    var HOURLY_START_TIME_MIN = f.HOURLY_START_TIME_MIN.value;
    var HOURLY_INTERVAL = f.HOURLY_INTERVAL.value;
    var url = '/SPMCsvModify.do?actionFrom='+actionFromValue+'&GROUP_NAME='+newGroupName+'&adminStatus='+adminStatus+'&SCHEDULE_TYPE='+SCHEDULE_TYPE+'&HOURLY_START_TIME_HOUR='+HOURLY_START_TIME_HOUR+'&HOURLY_START_TIME_MIN='+HOURLY_START_TIME_MIN+'&HOURLY_INTERVAL='+HOURLY_INTERVAL+'&uid='+new Date().getTime();
    sendRequestForAddGroup(url,f);
    return false;
}
var ajaxGroupRequest;
var groupForm;

function sendRequestForAddGroup(url,f)
{
       groupForm = f;
      
        //button =document.hostForm.actionFromTemp.value; 
        
        if (window.XMLHttpRequest)
        {
                ajaxGroupRequest = new XMLHttpRequest();
                ajaxGroupRequest.onreadystatechange = ajaxResponseChane1;
                ajaxGroupRequest.open("GET", url, true);
                ajaxGroupRequest.send(null);
        }
        else if (window.ActiveXObject)
        {
                isIE = true;
                ajaxGroupRequest = new ActiveXObject("Microsoft.XMLHTTP");
                if (ajaxGroupRequest)
                {
                        ajaxGroupRequest.onreadystatechange = ajaxResponseChane1;
                        ajaxGroupRequest.open("GET", url, true);
                        ajaxGroupRequest.send(null);
                }
        }
}
function ajaxResponseChane1()
{
    if (ajaxGroupRequest.readyState == 4) 
	{
	
		if (ajaxGroupRequest.status == 200) 
                {
                    
                    //alert(ajaxGroupRequest.responseText);
                    var statusObj = ajaxGroupRequest.responseXML.getElementsByTagName('status');
                    var status = trim(statusObj[0].getAttribute("result"));
                    if(status == 'true')
                    {
                                             
                        var gIDObj = ajaxGroupRequest.responseXML.getElementsByTagName('selectGroupID');
                        var gId = gIDObj[0].getAttribute("sGroupID");
                        var gNameObj = ajaxGroupRequest.responseXML.getElementsByTagName('selectGroupName');
                        var gName = gNameObj[0].getAttribute("sGroupName");
                        
                        document.getElementById("groupName").value=gName;
                        
                       //document.getElementById("addGroupNameID").innerHTML=" ";
                        
                        var x = ajaxGroupRequest.responseXML.getElementsByTagName('groupNameList');
                        
                        if(groupForm.actionFrom.value == "addNewGroupMod")
                        {
                            groupForm.addGroupNameID.innerHTML="";
                            for(var i=0 ; i< x.length ; i++)
                            {
                                var switchIDValue = x[i].getAttribute("groupID");
                                var switchNameValue= x[i].getAttribute("groupName");
                                if(switchIDValue == gId)
                                {
                                    groupForm.addGroupNameID.options[groupForm.addGroupNameID.options.length] = new Option(switchNameValue ,switchIDValue,  true, true);

                                }else
                                {
                                    groupForm.addGroupNameID.options[groupForm.addGroupNameID.options.length] = new Option(switchNameValue , switchIDValue ,  true, false);	
                                }
                            }

                            groupForm.actionFrom.value = groupForm.actionFromold.value;
                            ShowNewGroupConfigField();
                            
                        }else
                        {
                            document.subnetAddForm.addGroupNameID.innerHTML="";
                            for(var i=0 ; i< x.length ; i++)
                            {
                                var switchIDValue = x[i].getAttribute("groupID");
                                var switchNameValue= x[i].getAttribute("groupName");
                                if(switchIDValue == gId)
                                {
                                    document.subnetAddForm.addGroupNameID.options[document.subnetAddForm.addGroupNameID.options.length] = new Option(switchNameValue ,switchIDValue,  true, true);

                                }else
                                {
                                    document.subnetAddForm.addGroupNameID.options[document.subnetAddForm.addGroupNameID.options.length] = new Option(switchNameValue , switchIDValue ,  true, false);	
                                }
                            }
                            ShowGroupConfigField();
                        }  

                   }else
                   {
                        var Message = ajaxGroupRequest.responseXML.getElementsByTagName('Message');
                        var result = trim(Message[0].getAttribute("msg"));   
                        if(groupForm.actionFrom.value == "addNewGroupMod")
                        {
                               window.document.getElementById("SPMGroupErrorAnchor").innerHTML="<span class=redtxtbold>"+result+"</span>";    
                        }else
                        {
                            window.document.getElementById("SPMGroupErrorAnchor11").innerHTML="<span class=redtxtbold>"+result+"</span>";    
                        }        
                   }

                }       
		else
                {  
			alert("There was a problem retrieving the XML data:\n" +ajaxGroupRequest.statusText);
		}
	}
}
function ShowGroupConfigField()
{ 
   
   window.document.getElementById("SPMErrorAnchor11").innerHTML=""; 
   var addSwitchElem = document.getElementById("swicthConfigDiv");
   var addGroupElem = document.getElementById("groupAddDiv");
   if(addSwitchElem.style.display =="none") {

        window.document.getElementById("SPMGroupErrorAnchor11").innerHTML=""; 
        addSwitchElem.style.display="block";
        addGroupElem.style.display="none";    
       
    }else{
   
       addSwitchElem.style.display="none";
       addGroupElem.style.display="block";
   }
   
}
function ShowNewGroupConfigField()
{ 
   window.document.getElementById("SPMErrorAnchor").innerHTML=""; 
   var addSwitchElem = document.getElementById("modifySwitch");
   var addGroupElem = document.getElementById("addNewGroupID");
   if(addSwitchElem.style.display =="none") {

        addSwitchElem.style.display="block";
        addGroupElem.style.display="none";    
       
    }else{
   
       addSwitchElem.style.display="none";
       addGroupElem.style.display="block";
   }
   
}

var SPMMainPageIntervalID;
function renderSPMMainView()
{
    //var selectedTab = document.hostForm.selectedSwitchTab.value;
   // window.parent.document.location.href="/MainLayout.do?selectedToolID=SWITCH_PORT_MAPPER&selectedTab=NETWORK_MGMT&selectedParentID=OPTools&selectedSwitchTab="+selectedTab
    //renderViewCurrentView('SwitchPortMapper.cc?selectedSwitchTab'+selectedTab , "SPMMainID");
}
function refreshSPMMAINView()
{   
    window.clearInterval(SPMMainPageIntervalID); 
    SPMMainPageIntervalID = window.setInterval("renderSPMMainView()",150000);       
    
}
function ShowInputFieldNew()
{
    showInputFeildSPM('switchConfig');
     showURLInDialog('/network/SwitchPortMapperAddSwitch.jsp','position=auto,modal=yes,width=580,scrollbars=no,title=Add Switch');
     
} 


function showHelp(inElem,from,pos , isFindPosition , heading , ismessage , message )
{
   
    var helpContent = document.getElementById(inElem).innerHTML;
    msgLeng = helpContent.length
    var helpDiv = document.getElementById("helpDiv");
    helpDiv.style.verticalAlign = "bottom";
    if(ismessage)
    {
        document.getElementById("helpContent").innerHTML = message;
    }else
    {
        document.getElementById("helpContent").innerHTML = helpContent;
    }
    
    var posX = 20//findPosX(from);
    var posY = 295//findPosY(from);
    if(isFindPosition)
    {
        posX = findPosX(from)-100;
        posY = findPosY(from)+150;
        document.getElementById("heading").innerHTML = heading;
    }
     
    var divWidth = 100;
    var divHeight = 70;
    if(msgLeng > 800 )
    {
        divHeight = 300;
        
    }else if(msgLeng > 500 )
    {
        divHeight = 230;
        
    }else if(msgLeng > 150)
    {
        divHeight = 140;
    }
    if(pos)
    {
        helpDiv.style.left = posX+25
        helpDiv.style.top = posY -eval(divHeight+5);
    }
    else
    {        
        helpDiv.style.left = posX - eval(divWidth+5);
        helpDiv.style.top = posY -eval(divHeight+5);
    }
    helpDiv.style.height = divHeight;
    helpDiv.style.width = divWidth;
    helpDiv.className = "";        
}

function closeHelp()
{
    document.getElementById("helpDiv").className = "hide";
}
function startDragH(e)
{
var x;
 var y;
 switch (emod) {
 case "NN4":
 /*A*/
 document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
 document.onmousemove = moveMouseH;
 document.onmouseup = stopDragH;
 break;
 case "IE4+":
 e = window.event;
 /*B*/
 if (e.srcElement.id != "draghold") return true;

 /*C*/
 //elementToDrag = e.srcElement.parentNode;
 elementToDrag = document.getElementById("helpDiv");

 /*D*/
 x = parseInt(elementToDrag.style.left);
 y = parseInt(elementToDrag.style.top);
 deltaX = e.clientX - x;
 deltaY = e.clientY - y;

 document.onmousemove = moveMouseH;
 document.onmouseup = stopDragH;

 /*E*/
 window.event.cancelBubble = true;
 break;
 case "W3C":
 //elementToDrag = e.target.parentNode;

 elementToDrag = document.getElementById("helpDiv");

 x = parseInt(elementToDrag.style.left);
 y = parseInt(elementToDrag.style.top);
 deltaX = e.clientX - x;
 deltaY = e.clientY - y;

 document.addEventListener("mousemove", moveMouseH, true);
 document.addEventListener("mouseup", stopDragH, true);

 e.stopPropagation();
 break; }

 return false;
}

function moveMouseH(e)
{
 if (emod=="IE4+") e = window.event;

 /*F*/
 if ((emod == "W3C")||(emod == "IE4+")) {
 elementToDrag.style.left = (e.clientX - deltaX) + "px";
 elementToDrag.style.top = (e.clientY - deltaY) + "px"; }

 if (emod=="W3C")
 e.stopPropagation();
 else if (emod=="IE4+")
 window.event.cancelBubble = true;

 return false;
}

function stopDragH(e)
{
 switch (emod) {
 case "NN4":
 /*G*/
 document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
 document.onmousemove = null;
 document.onmouseup = null;
 alert("Dragging not supported in NN4.");
 break;
 case "IE4+":
 e = window.event;

 document.onmousemove = null;
 document.onmouseup = null;

 window.event.cancelBubble = true;
 break;
 case "W3C":
 document.removeEventListener("mouseup", stopDragH, true);
 document.removeEventListener("mousemove", moveMouseH, true);

 e.stopPropagation();
 break; }

 return false;
}

function onloadH(e)
{
 /*get the event model*/
 emod = (e) ? (e.eventPhase) ? "W3C" : "NN4" : (window.event) ? "IE4+" : "unknown";

 if (emod == "NN4")
 document.captureEvents(Event.MOUSEDOWN);

 if (emod != "W3C") {
 /*NN4 or IE4+*/
 document.onmousedown = startDragH;
 }else {
 document.getElementById("draghold").addEventListener("mousedown",startDragH,true);
}
// setPackage();
 return true;
}



/*global vars*/
var emod;
var elementToDrag;
var deltaX;
var deltaY;


function addNewGroup()
{
     var url ='/network/SPMGroupConfig.jsp?actionFrom=addNewGroupName&selectedSwitchTab=switchConfigurationTab';
     window.open(url,"htmlExportForm","resizable=yes,screenX=275,screenY=175,scrollbars=yes,toolbar=no,width=600,height=550","centre")    
}
function showDynamicSelectionByIfSpeed(menuItemName,refId,additionalParams,index)
{
    
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);

    var colInd1  = tblModel.getColumnIndex("SNMPInterface.IFSPEED");
    var colInd2  = tblModel.getColumnIndex("SNMPInterface.RESOURCEID");
    var ifSpeedOrIfType = tblModel.getValueAt(index,colInd1)
    var resourceID = tblModel.getValueAt(index,colInd2);
    //var viewName = '/IfSpeedReportView.cc';
    var viewName = '/IfSpeedReportSwitchView.cc';
    var viewName1 = 'IfSpeedReportSwitchView';
    var selectedView = 'ifSpeed';
    var currentReport = 'ifSpeedPortReport';
    if(!ifSpeedOrIfType){
        colInd1  = tblModel.getColumnIndex("SNMPInterface.IFTYPE");
        ifSpeedOrIfType = tblModel.getValueAt(index,colInd1);
        selectedView = 'ifType';
       currentReport = 'ifTypePortReport';
      // viewName = '/IfTypeReportView.cc';
       viewName = '/IfTypeReportSwitchView.cc';
       viewName1 = 'IfTypeReportSwitchView';
   }
   
    //renderViewCurrentView("/InternalReportView.cc?selctedIfSpeed="+ifSpeedOrIfType+"&selectedView="+selectedView+"&currentReportView="+currentReport, "tt")
   //renderViewCurrentView(viewName+"?selctedIfSpeed="+ifSpeedOrIfType+"&selectedView="+selectedView+"&currentReport="+currentReport+"&selView=lstView&showSwitch=showSwitch&viewName="+viewName1, "tt")
   renderViewCurrentView("/InternalReportView.cc?selctedIfSpeed="+ifSpeedOrIfType+"&selectedView="+selectedView+"&currentReport="+currentReport+"&viewName=InternalReportView", "tt")
}
function showDynamicSwitchByIfSpeed(menuItemName,refId,additionalParams,index){
     var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);

    var colInd1  = tblModel.getColumnIndex("SNMPInterface.IFSPEED");
    var colInd2  = tblModel.getColumnIndex("SNMPInterface.RESOURCEID");
    
    var ifSpeedOnly = tblModel.getValueAt(index,colInd1)
    var resourceID = tblModel.getValueAt(index,colInd2);
    
     var selectedView = 'ifSpeed';
     var currentReport = 'ifSpeedPortReport';
     
     if(!ifSpeedOnly){
        colInd1  = tblModel.getColumnIndex("SNMPInterface.IFTYPE");
        ifSpeedOnly = tblModel.getValueAt(index,colInd1);
        selectedView = 'ifType';
       currentReport = 'ifTypePortReport';
      }
     
  //  alert(ifSpeedOnly + "..........." + resourceID)
    renderViewCurrentView("/InternalReportPortCountView.cc?selctedIfSpeed="+ifSpeedOnly+"&selectedView="+selectedView+"&currentReport="+currentReport+"&resourceID="+resourceID+"&switchID="+resourceID+"&viewName=InternalReportPortCountView", "tt")
    
}

//Email alert configuration in spm for port utilization
function setPortUtilization(portUsage){
   showURLInDialog('/network/SPMAlertPolicy.jsp?portUsage='+portUsage,'position=relative,modal=yes,width=380,scrollbars=no,title=Set Alert Policy');
}
function showGivenValue(lowPortUtlSwitch) {
    document.getElementById("lowPortUsageOfSwitch").innerHTML = lowPortUtlSwitch +'%';
}

function ClearSearchField() {
    document.getElementById('SEARCH_VALUE').value = "";
}
function editSchedularUI(menuItemName,refId,additionalParams,index)
{
    var tblModel = getTableModel(refId);

    var colInd5  = tblModel.getColumnIndex("GroupTaskName.TASK_NAME");
    var colInd6  = tblModel.getColumnIndex("GroupTaskName.TASK_ID");
    
    var groupID = tblModel.getValueAt(index,colInd6)
     var groupName = tblModel.getValueAt(index,colInd5)
    
      showURLInDialog('/network/SPMSchedularConfig.jsp?GROUP_NAME='+groupName+'&actionFrom=editSchedular&GROUP_ID='+groupID,'position=relative,modal=yes,width=480,scrollbars=no,title=Edit Switch');
    
}
function snmpV3Validation(f) {
    
    var userName = f.username.value;
            if(userName.length == 0) {
                alert("Please enter username.");
                return false;
            }
            
            var authField = document.getElementById("authID");
            var authPass = document.getElementById("authPassID").value;
                if(authField.value != 'none') {
                    if(authPass.length == 0) {
                        alert("Authentication password cannot be empty.");
                        return false;
                    }
                    var privField = document.getElementById("privID");
                    var privPass = document.getElementById("privPassID").value;
                    if(privField.value != 'none' && privPass.length == 0) {
                        alert("Encryption password cannot be empty.");
                        return false;
                    }
                }
                return true;
}
function showSnmpV3Field(val) {
    var authField = document.getElementById("authID");
    var privField = document.getElementById("privID");
    if(val == 'auth') {
        if(authField.value != 'none') {
            document.getElementById("authPassID").disabled = false;
            privField.disabled = false;
        } else {
            var authid = document.getElementById("authPassID");
            var privid = document.getElementById("privPassID");
            authid.disabled = true;
            privid.disabled = true;
            authid.value = "";
            privid.value = "";
            privField.disabled = true;
            setSelectedValue('privID','none');
        }
    } else {
        if(privField.value != 'none') {
            document.getElementById("privPassID").disabled = false;
        } else {
            document.getElementById("privPassID").disabled = true;
        }
    }
}
function setSnmpVersion(vesrionID) {
    if(vesrionID == "snmpV1rV2Id") {  
        var vesrion1r2 = document.getElementById('snmpV1V2InputID');
        vesrion1r2.style.display = "block";
        var vesrion3 = document.getElementById('snmpV3InputID');
        vesrion3.style.display = "none";
        document.getElementById('setSnmpVersionID').value = "snmpV1rV2";
    } else {
        var vesrion1r2 = document.getElementById('snmpV1V2InputID');
        vesrion1r2.style.display = "none";
        var vesrion3 = document.getElementById('snmpV3InputID');
        vesrion3.style.display = "block";
        document.getElementById('setSnmpVersionID').value = "snmpV3";
    }
}

function setSelectedValue(protoID,selectedProto) {
    var opts = document.getElementById(protoID).options;
    for (i=0; i<opts.length; i++) {
        var option = opts[i].value;
        if(selectedProto == option) {
            opts[i].selected = true;
        } else {
        opts[i].selected = false;
    }
  }
}

var timeToHide;

function onSuccessResponse(resOptions, reqOptions) {
    var error = trim(resOptions.responseText);
    if(error.length > 0) {
        document.getElementById("loadingImgID").style.display='none';
        document.getElementById("InImgID").innerHTML = '';
        var resFlag = error.split(",");
        error = resFlag[0];
        if(resFlag.length > 0) {
            resFlag = resFlag[1];
        }
        var divID = document.getElementById("errorDiv")
        if(resFlag == 'true') {
            document.getElementById("errorDiv").className = "successMsg" 
            document.subnetAddForm.switchIP.value = "";
            document.subnetAddForm.switchIP.focus();
            AjaxAPI.refreshView;
            clearField();
            timeToHide = window.setInterval('refreshSPM()',2000);
        } else if(resFlag == 'false'){
        document.getElementById("errorDiv").className = "failureMsg"
        }
        if(resFlag == 'true' || resFlag == 'false') {
            document.getElementById("errorDiv").style.display='block';
            document.getElementById("errorTD").innerHTML = error;
        } else {
            document.getElementById("errorDiv").style.display='none';
            closeDialog();
        }
    } 
}
function clearField() {
    var privField = document.getElementById("privID");
    var authid = document.getElementById("authPassID");
    var privid = document.getElementById("privPassID");
    authid.disabled = true;
    privid.disabled = true;
    authid.value = "";
    privid.value = "";
    privField.disabled = true;
    setSelectedValue('privID','none');
    setSelectedValue('authID','none');
}
function refreshSPM() {
    window.clearInterval(timeToHide);
    refreshSubView("SPMInputView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}))
}