//$Id: IPAddressManager.js,v 1.17 2009/02/26 10:59:36 karuppannan Exp $
function validateIPAddressManager()
{
	
	f = document.hostForm;

	if(f.actionFrom.value == 'stopButton')
        {
                return true;
        }
	return true;
}

function groupModifyAlias(menuItemName,refId,additionalParams,index)
{

   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var selValue = (index == null)? tblModel.getSelectedRowIndices(refId):[index];
   if(selValue.length == 0)
   {
      alert("Select atleast one row!!");
      return;
   }
  var resID="";
   for(var i = 0; i < selValue.length; i++)
   {
        if(i < (selValue.length-1))
        {
            resID +=tblModel.getValueAt(selValue[i],colInd1)+" , ";
        }
        else
        {
            resID +=tblModel.getValueAt(selValue[i],colInd1);
        }
   }
   showURLInDialog('/ipam/IPAddressGroupModifyAliasName.jsp?resID='+resID,'position=relative,modal=yes,scrollbars=no,title=Modify Alias Name')
}

function modifyAssertTag(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   
    var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");   
   var colInd2  = tblModel.getColumnIndex("IPResources.ASSERT_TAG");
   var resourceID = tblModel.getValueAt(index,colInd1)
   var assertTag = tblModel.getValueAt(index,colInd2)
   
   
   showURLInDialog('/lan/IPAddressModifyAliasName.jsp?tableName=IPResources&columnName=ASSERT_TAG&name=Asset Tag Name&value='+assertTag+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Modify Asset Tag')
}
function modifyRogueStatus(menuItemName,refId,additionalParams,index)
{
    
  // var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   
    var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");   
   var colInd2  = tblModel.getColumnIndex("RogueResources.ROGUETYPE");
   var resourceID = tblModel.getValueAt(index,colInd1)
   var ROGUETYPE = tblModel.getValueAt(index,colInd2)
   showURLInDialog('/ipam/IPAMModifyRogueType.jsp?tableName=IPResources&columnName=ASSERT_TAG&name=Asset Tag Name&ROGUETYPE='+ROGUETYPE+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,width=400,title=Modify Rogue Type')
}


function modifyAliasName(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("IPResources.ALIAS_NAME");
   var resourceID = tblModel.getValueAt(index,colInd1)
   var aliasName = tblModel.getValueAt(index,colInd2)

   showURLInDialog('/lan/IPAddressModifyAliasName.jsp?tableName=IPResources&columnName=ALIAS_NAME&name=Alias Name&value='+aliasName+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Modify Alias Name')
}
function modifyPhoneNumber(menuItemName,refId,additionalParams,index)
{

   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");   
   var colInd2  = tblModel.getColumnIndex("IPResources.TELEPHONE_NUMBER");
   var resourceID = tblModel.getValueAt(index,colInd1)
   var telephoneNumber = tblModel.getValueAt(index,colInd2)
   showURLInDialog('/lan/IPAddressModifyAliasName.jsp?tableName=IPResources&columnName=TELEPHONE_NUMBER&name=Telephone Number&value='+telephoneNumber+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Modify Phone Number')
}
function modifyLocation(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");   p
   var colInd2  = tblModel.getColumnIndex("SNMPResources.SYSLOCATION");
   var resourceID = tblModel.getValueAt(index,colInd1)
   var telephoneNumber = tblModel.getValueAt(index,colInd2)
   
   showURLInDialog('/lan/IPAddressModifyAliasName.jsp?tableName=SNMPResources&columnName=SYSLOCATION&name=System Location&value='+telephoneNumber+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Modify Locatoin')
}
function editIPAddressDetails(menuItemName,refId,additionalParams,index)
{
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);
    var count = tblModel.getColumnCount();
    var url ="/modifyIPDetails.cc?";
    for(var i = 0 ; i< count ; i++)
    {
        var colName = tblModel.getColumnName(i);
        var valueAt = tblModel.getValueAt(index,i); 
        url = url+""+colName+"="+valueAt+"&";
    }
    
    var colInd  = tblModel.getColumnIndex("IPResources.IPADDRESS");
    var ipAddress = tblModel.getValueAt(index,colInd) 
    showURLInDialog( url ,'position=absolute,modal=yes,top=70,left=400,scrollbars=no,title=Summary for :- '+ipAddress)
    
}

function viewIPHistoryDetails(menuItemName,refId,additionalParams,index)
{
   var tblModel = getTableModel(refId);
   // var tblModel = getTableModel(refId);
    var count = tblModel.getColumnCount();
     var url = "/IPAMHistory.cc?";
    for(var i = 0 ; i< count ; i++)
    {
        var colName = tblModel.getColumnName(i);
        var valueAt = tblModel.getValueAt(index,i); 
        url = url+""+colName+"="+valueAt+"&";
    }
    var colInd  = tblModel.getColumnIndex("IPResources.IPADDRESS");
    var ipAddress = tblModel.getValueAt(index,colInd) 
    if (navigator.appName == 'Netscape')
        {
                newwin=window.open(url,"Schedule","resizable=yes,scrollbars=yes,toolbar=no","centre");
        }
        else
        {
                newwin=window.open(url,"Schedule","resizable=yes,scrollbars=yes,toolbar=no","centre");
        }
        
  // showURLInDialog( url,'position=absolute,modal=no,top=50,left=50,scrollbars=no,title=IP Address History for :- '+ipAddress)
}
function modifySubnetName(netID,subnetName)
{
   if(subnetName == undefined)
   {
        subnetName = "Not Defined";
   }
    var resourceID = netID;
    showURLInDialog('/lan/IPAddressModifyAliasName.jsp?tableName=SubNetwork&columnName=SUBNET_NAME&name=Subnet Name&value='+subnetName+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Apply SubNet Name');

}

function applySubNetName(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("SubNetwork.NETID");
   var colInd2  = tblModel.getColumnIndex("SubNetwork.SUBNET_NAME");
   var netID = tblModel.getValueAt(index,colInd1)
   var subnetName = tblModel.getValueAt(index,colInd2)
   if(netID == undefined)
   {

        colInd1  = tblModel.getColumnIndex("IPAMSummary.NETID");
        netID = tblModel.getValueAt(index,colInd1)
   }
   modifySubnetName(netID,subnetName);


}

function modifiyReservedStatus(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("t1.DESCRIPTION");
   var subNETID = document.getElementById("subNETID").value;
   var resourceID = tblModel.getValueAt(index,colInd1)
   var reservedStatus = tblModel.getValueAt(index,colInd2)
   showURLInDialog('/ipam/ModifiyReservedStatus.jsp?reservedStatus='+reservedStatus+'&resourceID='+resourceID+"&subNETID="+subNETID,'position=relative,modal=yes,scrollbars=no,title=Modify Reserved Status')
}

function modifiyIPStatus(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("IntegerCategorySet.DESCRIPTION");
   var subNETID = document.getElementById("subNETID").value;
   var resourceID = tblModel.getValueAt(index,colInd1)
   var Status = tblModel.getValueAt(index,colInd2)
   showURLInDialog('/ipam/ModifiyIPStatus.jsp?Status='+Status+'&resourceID='+resourceID+"&subNETID="+subNETID,'position=relative,modal=yes,scrollbars=no,title=Modify Status')
}

function modifyOwnername(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("Owner.NAME");

   var resourceID = tblModel.getValueAt(index,colInd1)
   var ownerName = tblModel.getValueAt(index,colInd2)
   showURLInDialog('/ipam/ModifyOwnerName.jsp?ownerName='+ownerName+'&resourceID='+resourceID,'position=relative,modal=yes,scrollbars=no,title=Assign Owner')
}

function modifyNWAliasName(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("IPResources.ALIAS_NAME");
   
   var resourceID = tblModel.getValueAt(index,colInd1)
   var aliasName = tblModel.getValueAt(index,colInd2)

   showURLInDialog('/network/NWModifyAliasName.jsp?aliasName='+aliasName+'&resourceID='+resourceID,'position=relative,modal=yes,width=300,height=100,scrollbars=no,title=Modify Alias Name')

}

function validateModifyAlias(f)
{
    f.actionFrom.value = "modAliasName";
    if(document.subnetInputForm.aliasName.value.length > 100 )
    {
        alert("Alias name cannot exceed 100 characters");
        return false;
    }
	var aliasName = document.subnetInputForm.aliasName.value
		for (i=0; i<aliasName.length; i++)
		{
			var ipChar = aliasName.charCodeAt(i);
			if (ipChar == 92)
			{
				alert("Alias name cannot contain \'\\\'")
					return false;
			}
		}

	return true;
}
function searchAction(action)
{
    if(document.hostForm.enterSearch.value == "no")
    {
        document.hostForm.actionFrom.value=action;
    }
}
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";
                        //setIPMAction(value);
		}
	}
	else if(navigator.appName == "Netscape")
	{
		if(ev.which == 13)
		{
                        document.hostForm.actionFrom.value = value;
			document.hostForm.enterSearch.value = "yes";
                        //setIPMAction(value);
		}
	}
 
}

function showSelectColumn(html)
{
    document.getElementById("subnetData").innerHTML=html;
}




function showInputField(choice)
{

        if(choice == 'homeTab'){
                window.clearInterval(intervalID);
                document.subnetForm.homeDetailTab.value="homeTab"
                ShowTab('homeTab');
                HideTab('inputTab');
                //HideTab('settingTab');
                renderSubnet("IPAddressSummaryTableView.cc")

        }else if(choice == 'inputTab')
        {   
                document.subnetForm.homeDetailTab.value="inputTab"
                window.clearInterval(intervalID);
                ShowTab('inputTab');
                HideTab('homeTab');
                //HideTab('settingTab');
                renderSubnet("IPAddresssubnetView.cc")

        }
}

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 renderSubnet(viewName)
{
 viewName = viewName+'&uid='+new Date().getTime();
   var localVar = "subnetData";
    var myAnonFunction = function(response,reqOptions)
    {
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
    };
    AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});
 }
 function renderIPAMGraph(viewName , id )
{
 viewName = viewName+'&uid='+new Date().getTime();
   var localVar = id;
    var myAnonFunction = function(response,reqOptions)
    {
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
    };
    AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});
 }
var closeErrorMessageDivTimerID;
function IPAddSubnetModifiedAction()
{
    closeDialog();
    refreshView();
  
}
function closeResponseText()
{
    window.clearInterval(closeErrorMessageDivTimerID);
     var emailchaneIDElem = document.getElementById('mc_messagediv');
    if(emailchaneIDElem.className != "hide") {
        emailchaneIDElem.className = "hide";
    }
}


//this code for refresh view after scanning in progress
var intervalID = "";
function refreshPage(scanningStatus)
{
    window.clearInterval(intervalID);
    if(scanningStatus == 'true')
    {
        intervalID = window.setInterval('refreshView()',30000);
    }else
    {
        window.clearInterval(intervalID);
    }
}
function IPAddAliasNameModifiedAction()
{
   closeDialog();
   refreshIPMangerView("IPAddressAvailabilityView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false})); 
   refreshIPMangerView("IPAMTreeSummaryView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshIPMangerView("IPAddresssubnetView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshIPMangerView("IPLevelSearchView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshIPMangerView("IPLevelSearchView1",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshSubView("CustomFieldListView");//Its use for customField do not   delete it.   
}
function IPAddAliasNameModifiedAction123()
{
  // closeDialog();
   refreshIPMangerView("IPAddressAvailabilityView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false})); 
   refreshIPMangerView("IPAMSummaryView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false})); 
   refreshIPMangerView("IPAddresssubnetView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshIPMangerView("IPLevelSearchView",true,new AjaxOptions({USEXMLHTTPFORREFRESH:true,NAVIGABLE:false}));
   refreshSubView("CustomFieldListView");//Its use for customField do not   delete it.   
}

function refreshIPMangerView(id,useOldState)
{
ViewAPI.refreshView({VIEWTOREFRESH_RN:id,USEOLDSTATE_RN:(useOldState == false),NAVIGABLE_RN:true});
}
function cancelAliasNameModifiedAction()
{
   var formDiv = document.getElementById("modifyAliasName_div");
   document.getElementById("modifyAliasName_container").appendChild(formDiv);
}

function refreshView()
{
   window.clearInterval(intervalID);
   refreshSubView("IPAddresssubnetView");
   refreshSubView("IPAddressAvailabilityView");
 
}

function showAddField(val) {

   var addSubnetElem = document.getElementById(val);
   var addSubnetLinkElem = document.getElementById("addSubnetLink");

   if(addSubnetElem.style.display =="none") {
        window.clearInterval(intervalID);
       addSubnetElem.style.display="block";
        addSubnetLinkElem.style.display="none";
   } else {
       addSubnetElem.style.display="none";
       addSubnetLinkElem.style.display="block";
       //renderSubnet("IPAddresssubnetView.cc")
   }

   
}
function closeAddField(val)
{
    showAddField(val) 
    //refreshView();
    //renderSubnet("IPAddresssubnetView.cc")
} 
function setIPMAction(f,action)
{
        //alert(action);
	f.actionFrom.value=action;
}

function validateInputValues()
{
    var daysVal = document.settingsForm.days.value
    if(daysVal.length == 0)
        {
               alert("Please enter the Number of Days value.");
                document.settingsForm.days.focus();
                return false;
        }
        if(parseInt(daysVal)  != daysVal)
        {
                alert("Number fo days value should be an integer.");
                document.settingsForm.days.focus();
                return false;
        }
        if(daysVal < 1 || daysVal > 299)
        {
                alert("Number of days value should be between 1 a nd 299.");
                document.settingsForm.days.focus();
                return false;
        }
        
        var url = '/IPAddressManager.do?&actionFrom=saveDays&days='+daysVal+'&uid='+new Date().getTime();
        persist(url);
}
function validateIPAddressSettings()
{
    if(document.subnetForm.actionFrom.value == "cancel")
    {
        showSwitchSettings() 
        return false;
    }else if(document.subnetForm.actionFrom.value == "save")
    {
        validateInputValues(); 
        return false;
    }
    

    return true;
}

function showSwitchSettings() {
    var emailchaneIDElem = document.getElementById('emailchaneID');
    if(emailchaneIDElem.style.visibility =="visible") {
        emailchaneIDElem.style.visibility="hidden";
    }

    document.settingsForm.actionFrom.value="getNumberOfDays";
   var switchSettingElem = document.getElementById('policyTableID');
   if(switchSettingElem.style.visibility =="hidden") {
       switchSettingElem.style.visibility="visible";
       var url = '/IPAddressManager.do?&actionFrom=getNumberOfDays&uid='+new Date().getTime();;
       persist(url);
   } else {
       switchSettingElem.style.visibility="hidden";
   }
   
}
function persist(url)
{
        var ua = navigator.userAgent.toLowerCase();
        //alert(ua);
        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(null);
                }
        }else
        {
            
            req  = new ActiveXObject("Msxml2.XMLHTTP");
            isIE = true;
            if (req)
            {
                    req.onreadystatechange = processReqChangeDay;
                    req.open("GET", url, true);
                    req.send();
            }
        }

}

function processReqChangeDay()
{
        
        if (req.readyState == 4) 
	{
	
		if (req.status == 200) 
                {
                    var action = trim(document.settingsForm.actionFrom.value);
                    if(action == "getNumberOfDays")
                    {
                         
                        var x = req.responseXML.getElementsByTagName('Settings');
                        var daysValue= trim(x[0].getAttribute("noOfDays"));
                        if(parseInt(daysValue)  == daysValue)
                        {
                            window.document.getElementById("days").value=daysValue;
                        }
                        else
                        {
                            window.document.getElementById("days").value="";
                        }
                    }
                    else if(action == "save")
                    {
                        
                        var result = trim(req.responseText);
                       
                        if(result=="Success")
                        {
                            
                            showSwitchSettings();

                        }
                        else if(result=="Failure")
                        {
                            alert("Available policy days update Failed");
                        }

                    }if(action == "getMailID")
                    {
                       // alert(req.responseText);
                        var x = req.responseXML.getElementsByTagName('MailSettings');;
                        var resolveDNSValue = trim(x[0].getAttribute("toAddress"));
                        document.getElementById("toAdd").value=resolveDNSValue;
                       
                        if(x[0].getAttribute("SoundOption") == "1")
                        {
                            document.settingsForm.selectSound.checked = true;
                        }else
                        {
                            document.settingsForm.selectSound.checked = false;
                        }
                        
                        if(x[0].getAttribute("EmailOption") == "1")
                        {
                            document.settingsForm.emailID.checked = true;
                            document.settingsForm.toAdd.disabled=false;
                           
                        }else
                        {
                            document.settingsForm.emailID.checked = false;
                            document.settingsForm.toAdd.disabled=true;
                        }
                         var count = trim(x[0].getAttribute("COUNT"));
                        document.getElementById("COUNT").value=count;
                        
                        if(x[0].getAttribute("HISTORY_STATUS") == "1")
                        {
                            document.settingsForm.alertHisOption.checked = true;
                            
                           
                        }else
                        {
                            document.settingsForm.alertHisOption.checked = false;
                            
                        }
                        
                        
                    }else if(action == "sendAlerts")
                    {
                       showMailOption("mailCancel");
 
                    }else if(action == "stopAlerts")
                    {
                        showMailOption("mailCancel");
                    }
                    
                    
                 }       
		else
                {  
			alert("There was a problem retrieving the XML data:\n" +req.statusText);
		}
	}
}

function validateIPPolicySettings()
{
    var actionVal = document.settingsForm.actionFrom.value;
    document.settingsForm.actionFrom.value
    if(actionVal == "cancel")
    {
        showSwitchSettings() 
        return false;
    }else if(actionVal == "save")
    {
         
        validateInputValues(); 
        return false;

    }else if(actionVal == "sendAlerts")
    {
       return false;

    }else if(actionVal == "stopAlerts")
    {
        return false;
    }else if(actionVal == "mailCancel")
    {
        return false;
    }
    
}

function showMailOption(val)
{
    var switchSettingElem = document.getElementById('policyTableID');
    if(switchSettingElem.style.visibility =="visible")
    {
       switchSettingElem.style.visibility="hidden";
    }

    document.settingsForm.actionFrom.value=val;
    var emailchaneIDElem = document.getElementById('emailchaneID');
    if(emailchaneIDElem.style.visibility =="hidden") {
        
      emailchaneIDElem.style.visibility="visible";
      document.settingsForm.actionFrom.value="getMailID";
      var url = '/IPAddressManager.do?actionFrom=getMailID&uid='+new Date().getTime();
      persist(url);

   } else {
       emailchaneIDElem.style.visibility="hidden";
   }
   
}

function setButtonType(value)
{
            
             document.settingsForm.actionFrom.value = value;
             var toAddress = document.settingsForm.toAdd.value;
             var soundOption =document.settingsForm.selectSound.checked;
             var soundFile =document.settingsForm.soundFile.value; 
             var mailOption = document.settingsForm.emailID.checked; 
             
             var COUNT =document.settingsForm.COUNT.value; 
             var historyOption = document.settingsForm.alertHisOption.checked; 
             var HISTORY_STATUS = "0";
             if(historyOption == true)
                 {
                     HISTORY_STATUS = "1";
                 }
             if(value == "sendAlerts")
             {
                if(mailOption == true)
                {
                    toAdd1 = toAddress.split(",");
                    for(var i = 0 ; i< toAdd1.length ; i++)
                    {
                        if(!validateEmail(toAdd1[i]))
                        {
                            return false;
                        }
                    }
                }
                var url = '/IPAddressManager.do?&methodToCall=execute&actionFrom='+value+'&toAddress='+toAddress+'&soundOption='+soundOption+'&soundFile='+soundFile+'&mailOption='+mailOption+'&COUNT='+COUNT+'&HISTORY_STATUS='+HISTORY_STATUS+'&uid='+new Date().getTime();
                persist(url);
                
             }else if(value == "stopAlerts")
             {
                    var url = '/IPAddressManager.do?&methodToCall=execute&actionFrom='+value+'&toAddress='+toAddress+'&soundOption='+soundOption+'&soundFile='+soundFile+'&mailOption='+mailOption+'&uid='+new Date().getTime();;
                    persist(url);
             }
}
function validateRogue()
{
    return false;
}
function scheduleWindow(linkParams)
{
        if (navigator.appName == 'Netscape')
        {
                newwin=window.open("/framework/WOLScheduler.jsp?"+linkParams,"Schedule","screenX=300,screenY=250,scrollbars=no,toolbar=no,width=500,height=325","centre");
        }
        else
        {
                newwin=window.open("/framework/WOLScheduler.jsp?"+ linkParams,"Schedule","scrollbars=yes,toolbar=no,width=500,height=325","centre");
        }
}
//Newly added codes

function changeTabs(viewName,tabName)
{
    updateState('ipAddressManagerInputPage',"homeDetailTab",tabName,true);
    document.getElementById("homeDetailTab").value = tabName;
    document.getElementById("selectView").value = viewName;
    var localVar = "tt";
    changeStyle(viewName,tabName);

    var selID = tree.getSelectedItemId()
    var netID = getNodeChildSubnetIDs(selID);
    viewName = viewName+"?childNode=true"+netID+"&treeIDValue="+tree.getSelectedItemId();
    renderCurrentView(viewName , localVar);
    refreshSubView("IPAMMsgBoard");
}
function changeIPAMHomeTabs(viewName,tabName)
{
   
     var localVar = "ipamHomeID";
     changeIPAMHomeStyle(viewName,tabName);
     renderIPAMGraph(viewName+"?" , localVar);
     //loadTree();
}
function renderCurrentView(viewName , localVar)
{
  
    var myAnonFunction = function(response,reqOptions)
   {
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
   };
   AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});
   window.SPM_VIEW=viewName+"?";
}
function renderTreeCurrentView(viewName , localVar)
{
    var selID = tree.getSelectedItemId();
    var childTrees = tree.getAllSubItems(selID)
    var netIDs = getChildIDs(childTrees);
    viewName = viewName+"&childNode=true"+netIDs;
    renderCurrentView(viewName , localVar);
}

function changeIPAMHomeStyle(viewName,tabName)
{

    var nwinfo="nwinfo";
    var ipamreports="ipamreports";
    var ipamAudit="ipamAudit";
    

    if(tabName == undefined)
    {

     nwinfo="nwinfo";
     ipamreports="ipamreports";
     ipamAudit="ipamAudit";

    }
    if(viewName == "ipAddressManager.cc")
    {
        changeBackgroundBlock(nwinfo);
        changeBackgroundNone(ipamreports);
        changeBackgroundNone(ipamAudit);
        

    }
    else if(viewName == "IPAMReport.cc")
    {
        changeBackgroundNone(nwinfo);
        changeBackgroundBlock(ipamreports);
        changeBackgroundNone(ipamAudit);
        

    }
    else if(viewName == "AuditView.cc")
    {
        changeBackgroundNone(nwinfo);
        changeBackgroundNone(ipamreports);
        changeBackgroundBlock(ipamAudit);
        

    } 
}
function changeStyle(viewName,tabName)
{
     
    var summary="summary";
    var input="input";
    var alerts="alert";
    var ipHistory ="ipHistory";
  
    if(tabName == undefined)
    {
       
        summary="intabsummary";
        input="intabinput";
        alerts="intabalert";
        ipHistory ="intabipHistory";
        
    }
    if(viewName == "IPAddressSummaryTableView.cc")
    {
        changeBackgroundBlock(summary);
        changeBackgroundNone(input);
        changeBackgroundNone(alerts);
        changeBackgroundNone(ipHistory);
      
    }
    else if(viewName == "IPAddresssubnetView.cc")
    {
        changeBackgroundNone(summary);
        changeBackgroundBlock(input);
        changeBackgroundNone(alerts);
        changeBackgroundNone(ipHistory);
        
    }
    else if(viewName == "IPAddressAlerts.cc")
    {
        changeBackgroundNone(summary);
        changeBackgroundNone(input);
        changeBackgroundBlock(alerts);
        changeBackgroundNone(ipHistory);
        
    } else if(viewName == "IPHistoryView.cc")
    {
        changeBackgroundNone(summary);
        changeBackgroundNone(input);
        changeBackgroundNone(alerts);        
        changeBackgroundBlock(ipHistory);
    }
}

function  changeBackgroundNone(tdName)
{
    document.getElementById(tdName+"1").style.backgroundImage='url(/images/switch_tab_deselect_bg.gif)';
    document.getElementById(tdName+"2").src='/images/switch_tab_deselect_left.gif';
    document.getElementById(tdName+"3").style.backgroundImage='url(/images/switch_tab_deselect_bg.gif)';
    document.getElementById(tdName+"4").className="tabdeselectedtxt";
    document.getElementById(tdName+"5").src='/images/switch_tab_deselect_right.gif';
}

function  changeBackgroundBlock(tdName)
{
    document.getElementById(tdName+"1").style.backgroundImage='url(/images/switch_tab_select_bg.gif)';
    document.getElementById(tdName+"2").src='/images/switch_tab_select_left.gif';
    document.getElementById(tdName+"3").style.backgroundImage='url(/images/switch_tab_select_bg.gif)';
    document.getElementById(tdName+"4").className="tabselectedtxt";
    document.getElementById(tdName+"5").src='/images/switch_tab_select_right.gif';
}

function settingTab(viewName,tabName)
{
    if(viewName == "IPAMGenrelSettings.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("c"+tabName);
        changeBackgroundNone("owner");
        changeBackgroundNone("wmi");
        changeBackgroundNone("cf");
        changeBackgroundNone("publish");
    }
    else if(viewName == "IPAMConfigureAlert.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("settings");
        changeBackgroundNone("owner");
        changeBackgroundNone("wmi");
        changeBackgroundNone("cf");
        changeBackgroundNone("publish");
    }
    else if(viewName == "OwnerMgmt.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("settings");
        changeBackgroundNone("csettings");
         changeBackgroundNone("wmi");
        changeBackgroundNone("cf");
        changeBackgroundNone("publish");
    }    
     else if(viewName == "wmiSettings.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("settings");
        changeBackgroundNone("csettings");
        changeBackgroundNone("owner");
        changeBackgroundNone("cf");
        viewName = viewName+"?chosenTab=WMI";
        changeBackgroundNone("publish");
    }   
    else if(viewName == "CustomFieldListView.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("owner");
        changeBackgroundNone("settings");
        changeBackgroundNone("csettings");
        changeBackgroundNone("wmi");
        changeBackgroundNone("publish");
    } 
    else if(viewName == "AutoPublish.cc")
    {
        changeBackgroundBlock(tabName);
        changeBackgroundNone("owner");
        changeBackgroundNone("settings");
        changeBackgroundNone("csettings");  
        changeBackgroundNone("wmi");
        changeBackgroundNone("cf");
    } 
    
    var localVar = "tt";
    renderCurrentView(viewName , localVar);
}

function addSubnet(viewName,tabName)
{
    var treeID = tree.getSelectedItemId();
    document.getElementById("treeID").value = treeID;

    var temp = treeID.split("_");
    var parentID = temp[0];
    if(parentID == "SUBNET")
        {
            treeID = tree.getParentId(tree.getSelectedItemId());
            temp = treeID.split("_");
            parentID = temp[0];
        }
    if(temp.length > 1)
    {
        parentID = temp[1];
    }
    
    var parentName = tree.getItemText(treeID);
    var parentPath = getParentPathWithIfon(treeID);

    showURLInDialog('/framework/AddSubnetList.jsp?isAddFromTree=true&parentID='+parentID+"&parentName="+parentName+"&parentPath="+parentPath,'position=absolute,modal=yes,top=30,left=250,width=650,scrollbars=no,title=Add Subnet');
    changeTabs(viewName,tabName);    
}

function addMenuSubnet(menuItemName,refId,additionalParams,index)
{
     var treeID = tree.getSelectedItemId();
    document.getElementById("treeID").value = treeID;

    var temp = treeID.split("_");
    var parentID = temp[0];
    if(parentID == "SUBNET")
        {
            treeID = tree.getParentId(tree.getSelectedItemId());
            temp = treeID.split("_");
            parentID = temp[0];
}
    if(temp.length > 1)
    {
        parentID = temp[1];
    }

    var parentName = tree.getItemText(treeID);
    var parentPath = getParentPathWithIfon(treeID);
    showURLInDialog('/framework/AddSubnetList.jsp?isAddFromTree=true&parentID='+parentID+"&parentName="+parentName+"&parentPath="+parentPath,'position=absolute,modal=yes,top=30,width=650,left=250,scrollbars=no,title=Add Subnet');
}

function routerMsg()
{
    showURLInDialog('/ipam/RouterTextMsg.jsp','position=absolute,modal=yes,top=150,left=250,width=300,scrollbars=no,title=Discover Subnets from Routers');
}

function checkSubnet(f)
{   
    computeForm(f);
    var maskVal=trim(f.mask.value);
    msgDisplay(maskVal);
}
function changeSubnet(f)
{ 
    calibrateSubnet(f)
    var maskVal=trim(f.mask.value);
    msgDisplay(maskVal);
}   

function msgDisplay(maskVal)
{
    if(!checkClassA(maskVal))
    {
        if(maskVal == "255.255.0.0")
        {
            document.getElementById("subnetMsg").innerHTML="You have specified a Class B Subnet. This might have an impact in the performance.";
        }
        else
        {
            document.getElementById("subnetMsg").innerHTML="You have specified a Class A Subnet. This might have an impact in the performance.";
        }
    }
    else if(!checkClassB(maskVal))
    {
        if(!(maskVal=="255.255.255.0"))
        {
            document.getElementById("subnetMsg").innerHTML="You have specified a Class B Subnet. This might have an impact in the performance.";
        }
        else
        {
            document.getElementById("subnetMsg").innerHTML="";
        }

    }
    else
    {
        document.getElementById("subnetMsg").innerHTML="";
    }
}
 
function checkClassA(maskVal)
{
    var temp = maskVal.split(".");
    if(temp[2]=="0" && temp[3]=="0")
    {
        return false;
    }
    return true;
}

function checkClassB(maskVal)
{
    var temp = maskVal.split(".");
   
    if (temp[3]=="0")
    {
        return false;
    }
    return true;
}

function checkSubnetDetail(mask)
{
    var msg = "";
    if(!checkClassA(mask))
    {
        msg="Do you want to add this Class A Subnet?"; 
        if(mask=="255.255.0.0")
        {
            msg="Do you want to add this Class B Subnet?";
        }
    }
    else if(!checkClassB(mask))
    {
         if(!(mask=="255.255.255.0"))
        {
            msg="Do you want to add this Class B Subnet?";
        }
    }

    if((msg.length) > 0)
    {
        if (confirm(msg)) 
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    return true;
}
function  checkRowSelect(menuItemName,refId,additionalParams,index)
{
  var tblModel = getTableModel(refId);
  var selectRow=tblModel.getSelectedRowIndices(refId);
  if(selectRow.length<=0)
  {
       alert("Select IPAddress");
       return false;
  }
  else
  {
       var menuItemObj = getMenuItemObj(menuItemName);
       confirmtext = confirm(menuItemObj.CONFIRMSTRING);
       if (confirmtext==true)
       {
           var actUrl = menuItemObj.getActionURL(refId,additionalParams,index);
           menuItemObj.invokeActionURL(actUrl,refId);
       }
       else
       {
           return false;
       }
  }
}

function IPLevelSubnetModify(sNetID,subnet,sMask,sName,sDesc,sValn,sLoc,sScanDetail)
{
     var netID = sNetID;
    var subnetAddress = subnet;
    var subnetMask = sMask;
    var subnetname  = sName;
    var desc = sDesc;
    var vlan = sValn;
    var loc =sLoc;
    var scanDetails = sScanDetail;
     var treeID = tree.getSelectedItemId();
    document.getElementById("treeID").value = treeID;

    var temp = treeID.split("_");
    var parentID = temp[0];
    if(parentID == "SUBNET")
        {
            treeID = tree.getParentId(tree.getSelectedItemId());
            temp = treeID.split("_");
            parentID = temp[0];
        }
    if(temp.length > 1)
    {
        parentID = temp[1];
    }

    var parentName = tree.getItemText(treeID);
    var parentPath = getParentPathWithIfon(treeID);



   showURLInDialog('/lan/IPAddressMod.jsp?ipAddress='+subnetAddress+'&netID='+netID+'&subnetMask='+subnetMask+'&subnetname='+subnetname+'&desc='+desc+'&vlan='+vlan+'&loc='+loc+'&scanDetails='+scanDetails+'&parentID='+parentID+'&parentName='+parentName+'&parentPath='+parentPath ,'position=relative,modal=yes,scrollbars=no,title=Modify Subnet');
}
function updateFiled(txt)
{
    document.getElementById("callFor").value = txt;
}
var time;
function IPLevelScanNow(sNetID)
{
    document.getElementById("scanMsg").style.display = "block";
    var url='/IPAddressScanSubnetAction.do?netID='+sNetID+'&actionFrom=IPLevelScan&uid='+new Date().getTime();
    persistValues(url); 
    window.clearInterval(time);
    refreshSubView("IPAddressAvailabilityView");
    
    //scan_disabled.gif
}


    
    function persistValues(url)
    {
        var req = null;
        if(window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            req  = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.onreadystatechange = function()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    var text = trim(req.responseText);
                    if(text == "1")
                    {
                        time=window.setInterval('getStatusID()',10000);
                    }
                    else
                    {       
                        window.clearInterval(time);
                        document.getElementById("scanMsg").style.display = "none";
                        refreshSubView("IPAddressAvailabilityView");
                        window.clearInterval(time);
                    }
              }
            }
        };
        req.open("POST",url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(null);
    }
function getStatusID()
{
    window.clearInterval(time);
    var sNetID = document.getElementById("netID").value;
    var url='/IPAddressScanSubnetAction.do?netID='+sNetID+'&actionFrom=getStatusId&uid='+new Date().getTime();
    persistValues(url);
}



function showDropDown(e , id , id1)
{
    var x = getActualLeftSide(document.getElementById(id));
    var y = getActualTopSide(document.getElementById(id));
    var scrollLeft = document.body.scrollLeft;
    var scrollTop = document.body.scrollTop;
    x = x-scrollLeft;
    y = y-scrollTop;
    showURLInDialog('/ipam/SearchDropDown.jsp?uid='+new Date().getTime(),'position=absolute,modal=no,scrollbars=no,left='+x+',top='+y+',width=205,title=Search Drop Down,closeOnBodyClick=yes')
}
function getActualLeftSide(oElement) {

    var iLeft = 0;
    var oNode = oElement;
    while (oNode != document.body) {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;
    }
    return iLeft-1;
}

function getActualTopSide(oElement) {

    var iTop = 0;
    var oNode = oElement;
    while (oNode != document.body) {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    return iTop+16;
}


function selectforSearch(id)
{   
    document.getElementById(id).src="/images/tick_icon.gif";
    document.getElementById("selectValue").value = id;
    if(document.getElementById("SEARCH_VALUE") != undefined)
    {
        document.getElementById("SEARCH_VALUE").value = id;
    }
    var selectedToolID = document.getElementById("selectedToolID").value
    var url = "/commonaction.do?actionFrom=storeSearchType&selectValue="+id+"&selectedToolID="+selectedToolID;
    AjaxAPI.sendRequest({URL:url,ONSUCCESSFUNC:closeLayer});
}

function closeLayer()
{
    var searchValue = document.getElementById("SEARCH_VALUE");
    if(!searchValue) {
        searchValue = document.getElementById('textfield222');
        searchValue.focus();
    }
closeDialog();
}


function addOwner(menuItemName,refId,additionalParams,index)
{
   showURLInDialog('/ipam/OwnerAddForm.jsp','position=absolute,modal=yes,top=100,left=300,scrollbars=no,title=Add Owner');
}

function modifyOwner(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("Owner.OWNERID");
   var colInd2  = tblModel.getColumnIndex("Owner.NAME");
   var colInd3  = tblModel.getColumnIndex("Owner.LOCATION");
   var colInd4  = tblModel.getColumnIndex("Owner.DESIGNATION");
   var colInd5  = tblModel.getColumnIndex("Owner.EMAIL");
   var colInd6  = tblModel.getColumnIndex("Owner.PHON_NUMBER");
   
   var ownerId = tblModel.getValueAt(index,colInd1);
   var ownerName = tblModel.getValueAt(index,colInd2);
   var loc = tblModel.getValueAt(index,colInd3);
   var designation  = tblModel.getValueAt(index,colInd4);
   var emailid = tblModel.getValueAt(index,colInd5);
   var pnumber= tblModel.getValueAt(index,colInd6);
   showURLInDialog('/ipam/OwnerAddForm.jsp?ownerId='+ownerId+'&ownerName='+ownerName+'&loc='+loc+'&designation='+designation+'&emailid='+emailid+'&pnumber='+pnumber,'position=relative,modal=yes,scrollbars=no,title=Modify User');
}

function deleteOwner(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("Owner.OWNERID");
   var colInd2  = tblModel.getColumnIndex("Owner.NAME");
   var ownerID = tblModel.getValueAt(index,colInd1)
   var ownerName = tblModel.getValueAt(index,colInd2)
   
   var txt="Are you sure you want to delete the owner "+ownerName+"?";
   var confirmtxt=confirm(txt);
   if (confirmtxt == false)
   {
       return false;
   }
   else
   {
       var actUrl = menuItemObj.getActionURL(refId,additionalParams,index);
       actUrl=actUrl+"&ownerID="+ownerID+"&ownerName="+ownerName;
       menuItemObj.invokeActionURL(actUrl,refId);         
   }
}



function setActionValueWMI(actionValue)
    {
   
     f= document.schedulerForm;
    document.getElementById("response_layer").innerHTML="";
    document.schedulerForm.actionFrom.value = actionValue;
    if(validateWMIParams())
    {
        var WMILoginName = f.WMILoginName.value;
        var WMIPassword = f.WMIPassword.value;
        var WMIDomainName = f.WMIDomainName.value;
        var WMIDomainControllerName = f.WMIDomainControllerName.value;
        var url = "/IPAddressManager.do?actionFrom="+actionValue+"&WMILoginName="+WMILoginName+"&WMIPassword="+WMIPassword+"&WMIDomainName="+WMIDomainName+"&WMIDomainControllerName="+WMIDomainControllerName+"&uid="+new Date().getTime();
        persistWMI(url);
    }
    
}
 function persistWMI(url)
    {
        var req = null;
        if(window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            req  = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.onreadystatechange = function()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                   if(document.schedulerForm.actionFrom.value == "restoreWMIDefaults")
                    {
                        document.schedulerForm.WMILoginName.value="";
                        document.schedulerForm.WMIPassword.value="";
                        document.schedulerForm.WMIDomainName.value="";
                        document.schedulerForm.WMIDomainControllerName.value="";
                    }
                     document.getElementById("response_layer").innerHTML= " Your changes have been saved";
              }
            }
        };
        req.open("POST",url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(null);
    }
function onSucessFun(resOptions, reqOptions)
{
  var msg = trim(resOptions.responseText);
  if(msg.length > 0 )
  {
        document.getElementById("response_layer").innerHTML = msg;
        //document.getElementById("response_layer").innerHTML="Your changes have been saved";
       // window.setInterval("hideMsgDiv()",3000);
}
}
function PopUpMenuForwardIP(menuItemName,refId,additionalParams,index)
{
     var tblModel = getTableModel(refId);
   
   var colInd4  = tblModel.getColumnIndex("IPResources.FORWORD_ADDRINLONG");   
   var ipAddress = tblModel.getValueAt(index,colInd4)
   
    showURLInDialog('/framework/TroubleShootSystem.jsp?addressinlong='+ipAddress+'&community=public&convertIP=true','position=relative,top=-20,left=70,modal=no,scrollbars=no,title=System TroubleShoot,closeOnBodyClick=yes')

   
}
/* Tool List  tools code start */
function PopUpMenu(menuItemName,refId,additionalParams,index)
{
   var yPos =  findPosY(index);
   
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   
   var colInd1  = tblModel.getColumnIndex("IPResources2.RESOURCEID");
   var colInd2  = tblModel.getColumnIndex("IPResources2.ADDRINLONG");
   var colInd3  = tblModel.getColumnIndex("IPResources2.IPADDRESS");
   var colInd4  = tblModel.getColumnIndex("IPResources2.FORWORD_ADDRINLONG");
   var community = tblModel.getValueAt(index,colInd1)
   
   var aliasName = tblModel.getValueAt(index,colInd2)
   var ipAddress = tblModel.getValueAt(index,colInd3)
   var flag = 'false';
   
   if(!aliasName)
   {
       
      colInd2  = tblModel.getColumnIndex("IPResources.ADDRINLONG");
      colInd4  = tblModel.getColumnIndex("CiscoResources.CHASSIS_ID");
      colInd3  = tblModel.getColumnIndex("IPResources.IPADDRESS");
      aliasName = tblModel.getValueAt(index,colInd2);
      ipAddress = tblModel.getValueAt(index,colInd3)
      var chass_id = tblModel.getValueAt(index,colInd4);
   
      if(chass_id)
      {
         flag = 'true';
      }
     
      if(!aliasName)
      {
           colInd1  = tblModel.getColumnIndex("NetMonState.IPADDRESS");
           ipAddress = tblModel.getValueAt(index,colInd1);
           if(!ipAddress)
           {
               colInd1  = tblModel.getColumnIndex("BandWidthHost.IPADDRESS");
               ipAddress = tblModel.getValueAt(index,colInd1);
               if(!ipAddress)
               {
                   colInd1  = tblModel.getColumnIndex("ConfigFileInputConfig.IPADDRESS");
                   colInd2  = tblModel.getColumnIndex("ConfigFileInputConfig.COMMUNITY");
                   ipAddress = tblModel.getValueAt(index,colInd1);
                   community = tblModel.getValueAt(index,colInd2);
                   flag = 'true';
               }
              
           }
           
           
      }
      
   }
   
  if(!ipAddress)
  {
     colInd1  = tblModel.getColumnIndex("IPHistory.IPADDRESS");
     ipAddress = tblModel.getValueAt(index,colInd1);
  }
    
   var visibleHeight =	(window.opera) ? document.body.clientHeight || document.documentElement.clientHeight || window.innerHeight
		: window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight;
              
   showURLInDialog('/framework/TroubleShootSystem.jsp?ipAddress='+ipAddress+'&community='+community+'&flag='+flag,'position=relative,top=-20,left=70,modal=no,scrollbars=no,title=System TroubleShoot,closeOnBodyClick=yes')

}
 function setSubnet(uniqueId , subnet)
  {
     
      updateState(uniqueId,"NETWORKADDRESS",subnet,true);
      updateState(uniqueId,"SEARCH_VALUE",null,true);
      refreshSubView(uniqueId);
      return false;
  }
  function setSubnetView(uniqueId , subnet)
  {  
      
      updateState(uniqueId,"NETWORKADDRESS",subnet,true);
      updateState(uniqueId,"SELTAB",document.getElementById("SELTAB").value,true);
      updateState(uniqueId,"PARENTTREEID",document.getElementById("PARENTTREEID").value,true);
      updateState("IPAddressAvailabilityView","NETWORKADDRESS",subnet,true);
      updateState("IPAddressAvailabilityView","dnsFailure","All",true);
      updateState("IPAddressAvailabilityView","PARENTTREEID",document.getElementById("PARENTTREEID").value,true);
      var newTreeID = getNewSelectedID(subnet);
      tree.selectItem(newTreeID,true);
      var parentPath = getParentPath(newTreeID);
      updateState("IPAddressAvailabilityView","parentPath",parentPath,true);
      updateState(uniqueId,"parentPath",parentPath,true);
      refreshSubView(uniqueId);
      return false;
  }
  function changeSummaryTabs(viewName,tabName)
{
    
     var localVar = "subnetSummary";
    
     changeSummaryStyle(viewName,tabName);
     
     //refreshSubView(uniqueId);
     var NETWORKADDRESS = document.getElementById("NETWORKADDRESS").value;
     viewName = viewName+"&NETWORKADDRESS="+NETWORKADDRESS;
    
     renderCurrentView(viewName , localVar);
     
}
function changeSummaryTabs123(viewName,tabName,dnsFailure)
{
     var localVar = "subnetSummary";
    
     changeSummaryStyle(viewName,tabName);
     
     // refreshSubView(uniqueId);
     var NETWORKADDRESS = document.getElementById("NETWORKADDRESS").value;
     viewName = viewName+"&NETWORKADDRESS="+NETWORKADDRESS+"&dnsFailure="+dnsFailure+"&filterValue=dns_"+dnsFailure;
     renderCurrentView(viewName , localVar);
     
}
function changeSummaryStyle( viewName,tabName)
{
    
    document.getElementById("SELTAB").value = tabName
    var subnetSummary="subnetSummary";
    var history="history";
    var alerts = "alerts";
    if(viewName == "IPAddressAvailabilityView.cc?")
    {
        changeBackgroundBlock(subnetSummary);
        changeBackgroundNone(history);
        changeBackgroundNone(alerts);
        
    }else if(viewName == "IPHistoryView.cc?isSupnetOpt=false")
    {
        changeBackgroundNone(subnetSummary);
        changeBackgroundBlock(history);
        changeBackgroundNone(alerts);
    }else if(viewName == "IPAddressAlerts.cc?isSupnetOpt=false")
    {
        changeBackgroundNone(subnetSummary);
        changeBackgroundNone(history);
        changeBackgroundBlock(alerts);
    }
    return true;
}

function exportipHistory(viewName , val )
{
    if(window.OWN_EXPORT == undefined)
    {
             var ar; 
             if(window.NO_MCK_PDF )
             {
                    ar = trim(window.SPM_VIEW);
                    
             }
             else if(window.TAB_VIEW_NAME)
             { 
                 ar = trim(window.TAB_VIEW_NAME);
                 var noExportView = false;
                 if(window.TRIAL_VIEW)
                 {
                    noExportView = true;
                 }
                 ar = updateStateCookieAndAppendSid(ar);
                
              }else if(window.ROOT_VIEW_ID)
             {  
                ar = getViewURL(ROOT_VIEW_ID);
                ar = updateStateCookieAndAppendSid(ar);
                var csvAndXlsView = true;
                if(window.NO_CSV_VIEW)
                {
                    csvAndXlsView = false;
                }
                
                var noExportView = false;
                if(window.TRIAL_VIEW)
                {
                    noExportView = true;
                }
                
              }else if(window.NO_MCK_VIEW)
              {
                ar = trim(window.NO_MCK_VIEW_NAME);                
              }
              
                if(val == "pdf")
                 {
                    ar = ar.replace(/.cc\?/,".pdf?");
                 }else if(val == "csv")
                 {
                    ar = ar.replace(/.cc\?/,".csv?");
                    
                 }else 
                 { 
                      ar = ar.replace(/.cc\?/,".xls?");
                 }
         
          ar = ar+"&Export=true"
          newwin= window.open(ar);
          newwin.focus();
        
    }else{         
       
          newwin = window.open(viewName  ,'Export',230,220,0);
          newwin.focus();
    }
}

function importIPDetails()
{
      var networkAdd =document.getElementById('NETWORKADDRESS').value;       
      var displayName ="Alias Name";
      if (navigator.appName == 'Netscape')
      {
                newwin=window.open('/importIPDatas.cc?NETWORKADDRESS='+networkAdd+'&displayName='+displayName,"CustomTool","resizable=yes,screenX=300,screenY=250,scrollbars=yes,toolbar=no,width=600,height=400","centre")
      }
      else
      {
                newwin=window.open('/importIPDatas.cc?NETWORKADDRESS='+networkAdd+'&displayName='+displayName,"CustomTool","resizable=yes,screenX=300,screenY=250,scrollbars=yes,toolbar=no,width=600,height=400","centre")
      }
}
function closeDialogBox()
{
    document.importForm.actionFrom.value = "close";
    closeDialog()
}
 
 
function setActionValues(value)
{
     document.routerAddForm.actionFrom.value=value;
} 
/* Tools list code end */
function getAction()
{
    var fromList = eval('document.forms[0].selectedSwitches');
    var selColumnTxt = "";
    var selColumn = "";
    for(i=0; i < fromList.options.length ; i++)
    {
        var current = fromList.options[i].value ;
        //if(current != "IPADDRESS")
        {
            selColumn = selColumn+current;
        }
        selColumnTxt = selColumnTxt+fromList.options[i].text ;
        if(i+1 < fromList.options.length)
        {
            //if(current != "IPADDRESS")
            {
                selColumn = selColumn+",";
            }
            selColumnTxt  = selColumnTxt+","; 
        }
    }
    document.getElementById("groupErrorMssg").innerHTML = selColumnTxt;
    document.schedulerForm.columnName.value=selColumn;
}
function copyToList(optionValue , from,to)
{   
    
    var fromList = eval('document.forms[0].'+from);
    var toList = eval('document.forms[0].'+to);
    
    if(toList.options.length > 0 && toList.options[0].value == 'temp')
    {
        toList.options.length =0;
    }
    var sel =false;    
    for(i=0; i < fromList.options.length ; i++)
    {
        var current = fromList.options[i];
        if(current.selected)
        {
            sel =true;
            if(current.value == 'temp')
            {
                alert ('You cannot move this text!');
                return;
            }
            txt = current.text;
            val = current.value;
            if(optionValue == "true")
            {
                var alreadyExist = false;
                for(j = 0 ; j < toList.options.length ; j++)
                {
                    var toValue = toList.options[j].text;
                    if(toValue == txt)
                    {
                        alreadyExist = true;
                    }
                }
                if(!alreadyExist)
                {   
                    
                    // var toList1 = eval('document.forms[0].selectedSwitches');
                    toList.options[toList.length]=new Option(txt  ,val);   
                    fromList.options[i]=null;
                    i--;                            
                }
                else
                {
                    alert("Already added  the device : "+txt);
                }
                
            }else
            {
                
                if(current.value == 'IPADDRESS')
                {
                    alert ('You cannot remove \"IP Address\" column');
                    
                }else
                {
                    fromList.options[i]=null;
                    toList.options[toList.length]=new Option(txt  ,val);
                    i--;
                }
            }            
            
        }
    }
    if(!sel)
    {
        if(optionValue == "true")
        {
            alert ('Please select a column to move');
            
        }else
        {
            alert ('Please select a column to remove');
        }    
    }
    getAction()
}
var importIntervalID = "";
function windowClose()
{
    window.clearInterval(importIntervalID);
    
    importIntervalID = window.setInterval('window.close()',60000);
}

function validateIPAMImport123(f)
{
    var button = document.schedulerForm.actionFrom.value
    //alert(button)
    //alert(document.schedulerForm.isAction.value)
    if(button == "close")
    {
        if( trim(document.schedulerForm.isAction.value) == "true")
        {
            /// closeWindow()
            window.opener.document.hostTestForm.actionFrom.value="ipAvailability_tab";
            window.opener.document.hostTestForm.NETWORKADDRESS.value=document.schedulerForm.NETWORKADDRESS.value;
            window.opener.document.hostTestForm.submit();
            window.close()
        }else{
            window.close();
        }
        return false;
    }else if(button == "importIPDetails")
    {
        getAction()
        var fromList = eval('document.forms[0].selectedSwitches');
        
        if(fromList.options.length == 0){
            alert("Select atleast one column to import ")
            return false;
        }
        
        var path = document.schedulerForm.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')
            { 
                window.clearInterval(intervalID);        
                intervalID = window.setInterval('windowClose()',1000);
                
                return true;
            }else
            {
                alert("Please Select a \".CSV\" file ");
                return false;
            }
            
            window.clearInterval(intervalID);        
            intervalID = window.setInterval('windowClose()',1000);
            return true;
        }
        
    }
    
    
    return false;
}
function closeWindow(url)
{
    window.opener.document.hostTestForm.actionFrom.value="ipAvailability_tab";
    window.opener.document.hostTestForm.NETWORKADDRESS.value=url;
    window.opener.document.hostTestForm.submit();
    window.close()
}
function setActionValue(f,action,isAction)
{
    
    f.actionFrom.value=action;
    f.isAction.value =isAction
    
}
function setAction123(f,action)
{
    f.actionFrom.value=action;
    
}
function openErrorFile(file)
{
    var url ='/IPAddressManager.do?actionFrom=downLoadCSV';
    window.open(url,"htmlExportForm","menubar=1,scrollbars=1,status=1,toolbar=1,resizable","center");    
}



function addColumn()
{
    showURLInDialog('/ipam/AddCustomField.jsp?actionFor=addCustomField&uid='+new Date().getTime(),'position=absolute,modal=yes,top=50,left=250,scrollbars=no,title=Add Custom Column')
}
function modifyCFColumn(menuItemName,refId,additionalParams,index)
{
    var menuItemObj = getMenuItemObj(menuItemName);
    var tblModel = getTableModel(refId);
    var count = tblModel.getColumnCount();
    var url ="/ipam/AddCustomField.jsp?";
    for(var i = 0 ; i< count ; i++)
    {
        var colName = tblModel.getColumnName(i);
        var valueAt = tblModel.getValueAt(index,i); 
        url = url+""+colName+"="+valueAt+"&";
    }
    url = url +"actionFor=modifyCustomField&uid="+new Date().getTime();
    showURLInDialog(url,'position=relative,modal=yes,scrollbars=no,title=Modify Custom Column')
}

function deleteCFColumn(menuItemName,refId,additionalParams,index)
{
    
   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("CFColumnList.COLUMN_ID");
   var colInd2  = tblModel.getColumnIndex("CFColumnList.COLUMN_NAME");
   var colInd3  = tblModel.getColumnIndex("CFTableList.TABLE_NAME");
   var columnID = tblModel.getValueAt(index,colInd1);
   var columnName = tblModel.getValueAt(index,colInd2);
   var tableName = tblModel.getValueAt(index,colInd3);
 
   var txt="Are you sure you want to delete this column?";
   var confirmtxt=confirm(txt);
   if (confirmtxt == false)
   {
       return false;
   }
   else
   {
       var actUrl = menuItemObj.getActionURL(refId,additionalParams,index);
       actUrl=actUrl+"&columnID="+columnID+"&columnName="+columnName+"&tableName="+tableName;
       menuItemObj.invokeActionURL(actUrl,refId);         
   }
}

function modifyCFValue(menuItemName,refId,additionalParams,index)
{
    var temp = index.split("_");
    var rowIndex = temp[0];
    var cfIndex = temp[1];
    var cfName = temp[2];
    var defaultText = temp[3];

    var tdef =cfName.split(".");
    var tableName = tdef[0];
    var columnName = tdef[1];
    var tblModel = getTableModel(refId);
    var colInd1  = tblModel.getColumnIndex("IPResources.RESOURCEID"); 
    var id = tblModel.getValueAt(rowIndex,colInd1)
    var cfValue = tblModel.getValueAt(rowIndex,cfIndex)
    var idName = "RESOURCEID";
    var tableID = 1;
    if(cfValue == null)
    {
        cfValue = defaultText;
    }
    if(id == undefined )
    {
        colInd1  = tblModel.getColumnIndex("SubNetwork.NETID");
        id = tblModel.getValueAt(rowIndex,colInd1);
        idName = "NETID";
        tableID = 2;
    }
    var url = "/IPAddressManager.do?actionFrom=getSizeandDataType&columnName="+columnName+"&tableID="+tableID+"&uid="+new Date().getTime();
        var req = null;
        if(window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            req  = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.onreadystatechange = function()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    var resTest = req.responseText;
                    var values = resTest.split(",")
                    var dtypeID = values[0];
                    var size = values[1];
                    showURLInDialog('/ipam/ModifyCFValue.jsp?tableName='+tableName+'&columnName='+columnName+'&name='+columnName+'&value='+cfValue+'&id='+id+'&idName='+idName+'&dtypeID='+dtypeID+'&dtypeSize='+size,'position=relative,modal=yes,scrollbars=no,title=Modify '+columnName)
                }
            }
        };
        req.open("POST",url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(null);

    
    //showURLInDialog('/ipam/ModifyCFValue.jsp?tableName='+tableName+'&columnName='+columnName+'&name='+columnName+'&value='+cfValue+'&id='+id+'&idName='+idName,'position=relative,modal=yes,scrollbars=no,title=Modify '+columnName)
}
function  addNewColumn(columnFor)
{
    showURLInDialog('/ipam/AddCustomField.jsp?columnFor='+columnFor+'&actionFor=addCustomField&uid='+new Date().getTime(),'position=relative,modal=yes,scrollbars=no,title=Add Custom Column')
}

function clearSearchValue() 
{
    document.getElementById('SEARCH_VALUE').value = "";
}
function checkIPAMToadd(f)
{
    	if(f.emailID.checked )
	{
		f.toAdd.disabled=false;	
                f.IPAM_IP_STATE_CHANGED.disabled=false;	
                f.IPAM_REVERSE_DNS_FAIL.disabled=false;	
                f.IPAM_FORWARD_DNS_FAIL.disabled=false;	
                f.IPAM_FORWARD_DNS_IP_MISSMATCH.disabled=false;	
                
                f.IPAM_IP_STATE_CHANGED.checked=true;	
                f.IPAM_REVERSE_DNS_FAIL.checked=true;	
                f.IPAM_FORWARD_DNS_FAIL.checked=true;	
                f.IPAM_FORWARD_DNS_IP_MISSMATCH.checked=true;
            
	}
	else
	{
            f.toAdd.disabled=true;
            f.IPAM_IP_STATE_CHANGED.disabled=true;	
            f.IPAM_REVERSE_DNS_FAIL.disabled=true;	
            f.IPAM_FORWARD_DNS_FAIL.disabled=true;	
            f.IPAM_FORWARD_DNS_IP_MISSMATCH.disabled=true;	
           
            f.IPAM_IP_STATE_CHANGED.checked=false;	
            f.IPAM_REVERSE_DNS_FAIL.checked=false;	
            f.IPAM_FORWARD_DNS_FAIL.checked=false;	
            f.IPAM_FORWARD_DNS_IP_MISSMATCH.checked=false;
                
	}

}
function getDetails()
{
      document.settingsForm.actionFrom.value="getMailID";
      var url = '/IPAddressManager.do?actionFrom=getMailID&uid='+new Date().getTime();
      persist(url);        
}
function validateEmailInput()
{
            
            var value = "sendAlerts";
             document.settingsForm.actionFrom.value = value;
             var toAddress = document.settingsForm.toAdd.value;
             document.settingsForm.toAddress.value=toAddress;
             var soundOption =document.settingsForm.selectSound.checked;
             var soundFile =document.settingsForm.soundFile.value; 
             var mailOption = document.settingsForm.emailID.checked; 
             document.settingsForm.mailOption.value=document.settingsForm.emailID.checked;
             document.settingsForm.soundOption.value=document.settingsForm.selectSound.checked;
             
             var COUNT =document.settingsForm.COUNT.value; 
             var historyOption = document.settingsForm.alertHisOption.checked; 
             var HISTORY_STATUS = "0";
             
            var daysVal = document.settingsForm.days.value;
            if(daysVal.length == 0)
            {
                alert("Please enter the Number of Days value.");
                document.settingsForm.days.focus();
                return false;
            }
            if(parseInt(daysVal)  != daysVal)
            {
                alert("Number fo days value should be an integer.");
                document.settingsForm.days.focus();
                return false;
            }
            if(daysVal < 1 || daysVal > 299)
            {
                alert("Number of days value should be between 1 a nd 299.");
                document.settingsForm.days.focus();
                return false;
            }
             if(historyOption == true)
                 {
                     HISTORY_STATUS = "1";
                 }
                 document.settingsForm.HISTORY_STATUS.value=HISTORY_STATUS;
             if(value == "sendAlerts")
             {
                if(mailOption == true)
                {
                    if( !document.settingsForm.IPAM_IP_STATE_CHANGED.checked  &&  !document.settingsForm.IPAM_REVERSE_DNS_FAIL.checked  && !document.settingsForm.IPAM_FORWARD_DNS_FAIL.checked && !document.settingsForm.IPAM_FORWARD_DNS_IP_MISSMATCH.checked)
                    {
                            alert("Please select atleast one option to send email ")
                            return false;
                    }else{
                        toAdd1 = toAddress.split(",");
                        for(var i = 0 ; i< toAdd1.length ; i++)
                        {
                            if(!validateEmail(toAdd1[i]))
                            {
                                return false; 
                            }
                    }
                  }
                }
             }
             return  true;
 }
 function showSummaryDiv()
{
    
    var newstates=(document.getElementById("state123").value);  
    var treeNodeID = document.getElementById("treeNodeID").value
  
    var netID = "";
    if(treeNodeID)
        {
            netID = getNodeChildSubnetIDs(treeNodeID);
        }
        if(netID.length == 0)
            {
                netID = "&TD=0"
            }
      
   var viewName = "";    
   var URL = "";
    if(newstates == "1")
    {
        viewName = "IPAMDNSFailureView.cc";
        URL = "dnsFailureString=true";
    }else if(newstates == "2")
    {
        viewName = "AllIPAvailabilityReservedReport.cc";
        URL = "reservedStatus=3";
    }else if(newstates == "3")
    {
        viewName = "RogueSummary.cc";
        URL = "rogueTypeString=true";
    }else if(newstates == "4")
    {
        viewName = "NICTypeSummaryView.cc";
        URL = "nicTypeString=true";
        
    }else if(newstates == "6")
    {
            viewName = "IPAMADSummary.cc"
             URL = "PARTOFAD=true";
    }else {
        
        viewName = "IPAMInventoryView.cc";
        URL = "baseTypeString=true";
    }
    document.getElementById("selectGraph").value = newstates;
       
    viewName = "/IPAMUpdateURLToGraph.cc?viewName="+viewName+"&childNode=true&treeIDValue="+treeNodeID+netID+"&"+URL+"&SelectTreeID="+tree.getSelectedItemId();
    renderIPAMGraph(viewName , "ipamSubnetSumID" )

        
        
}
function ShowSelectDiv(divId)
{
	var id = document.getElementById(divId);
	id.style.display = "block";
}
function HideSelectDiv(divId){
	var id = document.getElementById(divId);
	id.style.display = "none";
}
function checkGuestSelect(menuItemName,refId,additionalParams,index)
{
  var tblModel = getTableModel(refId);
  var selectRow=tblModel.getSelectedRowIndices(refId);
  if(selectRow.length <= 0)
  {
       alert("Select device(s) to move as Guest");
       return false;
  }
  else
  {
           var colInd1  = tblModel.getColumnIndex("RogueResources.RESOURCEID");
           var selValue = (index == null)? tblModel.getSelectedRowIndices(refId):[index];
           
           var resID="";
           for(var i = 0; i < selValue.length; i++)
           {
               var residValue = ""+tblModel.getValueAt(selValue[i],colInd1);
              
               if(residValue != "null")
                {
                    
                        resID +="&RESOURCEID="+residValue
                    
                }
           }
            if(resID.length == 0)
             {
                  alert("Please select a valid device(s) to move as Guest");
                  return false;  
             }                         
            showURLInDialog('/ipam/guestConfig.jsp?&actionFrom=trustConfigTempDevice&'+resID,'position=relative,modal=yes,scrollbars=no,title=Configure Guest Validity Period')
        
        }  
}
function showAllDetails(viewName , view , title)
{
    var NETID = document.getElementById("subNETID").value;
    var NETWORKADDRESS = document.getElementById("NETWORKADDRESS").value;
    showURLInDialog('expandGraph.cc?viewName='+viewName+"&view="+view+"&NETID="+NETID+"&NETWORKADDRESS="+NETWORKADDRESS+"&title="+title,'position=auto,top=10,modal=yes,scrollbars=no,width=1000,height=500,title='+title+" : "+NETWORKADDRESS)
}
function showAllIPAMDetails(viewName , view , title)
{
    showURLInDialog('expandGraph.cc?viewName='+viewName+"&view="+view+"&title="+title,'position=auto,top=10,modal=yes,scrollbars=no,width=1000,height=500,title='+title)
}
function setAutoPublish(action) {
    document.getElementById("response_text").innerHTML="";
    var enablePublish = document.getElementById("publishID").checked;
    if(enablePublish) {
        enablePublish = "enable";
    } else {
        enablePublish = "disable";
    }
    var path = document.getElementById("dirID");
    
    var pathEnable = "false";
    if(!path.disabled) {
        pathEnable = "true";
    }
    
    path = path.value;
    if(path.length == 0) {
        alert("Publish directory cannot be empty!");
    }
    var url = "/IPAddressManager.do?actionFrom="+action+"&publishpath="+path+"&enablePublish="+enablePublish+"&pathEnable="+pathEnable;
    sendPublishAction(url);
}
function sendPublishAction(url) {
    var req = null;
    if(window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject){
        req  = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = function(){
        if(req.readyState == 4){
            if(req.status == 200){
               document.getElementById("response_text").innerHTML= " Your changes have been saved";
          }
        }
    };
    req.open("POST",url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send(null);
}

function hideMsgDiv()
{
    document.getElementById("response_layer").innerHTML="";
}

function testCredential()
{
    f= document.schedulerForm;
    var WMILoginName = f.WMILoginName.value;
    var WMIPassword = f.WMIPassword.value;
    var WMIDomainName = f.WMIDomainName.value;
    var WMIDomainControllerName = f.WMIDomainControllerName.value;

}


function validateWMIParams()
{


    f= document.schedulerForm;
    var WMILoginName = trim(f.WMILoginName.value);
    var WMIPassword = trim(f.WMIPassword.value);
    var WMIDomainName = trim(f.WMIDomainName.value);
    var WMIDomainControllerName = trim(f.WMIDomainControllerName.value);
    var adminStatus = trim(f.adminStatus.value);
    if(WMILoginName == '')
    {
        alert("Administrator login name cannot be empty string");
        return false;
    }
    if(WMIPassword  == '')
    {
        alert("Administrator Password  cannot be empty string");
        return false;
    }
    if(WMIDomainName  == '')
    {
        alert("Domain name/Workgroup cannot be empty string");
        return false;
    }
    if(!checkRecurrenceValues(this.form))
    {
       return false;
    }
    return true;
}


function persistADScanNow(url)
{
    var req = null;
    if(window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        req  = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = function()
    {
        if(req.readyState == 4)
        {
            if(req.status == 200)
            {
                var result = trim(req.responseText);
                if(result == "1")
                {
                    document.getElementById("adScan").src='/images/loading_img.gif';
                    document.getElementById("adScanMsg").style.display = "block";
                    var url = "/IPAddressManager.do?actionFrom=getADStatus&uid="+new Date().getTime();
                    persistADScanNow(url);                    
                }
                else
                {
                    document.getElementById("adScan").src='/images/scan_ad.gif';
                    document.getElementById("adScanMsg").style.display = "none";
                }
            }
        }
    };
    req.open("POST",url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send(null);
}


function displayADDetails(menuItemName,refId,additionalParams,index)
{

   var menuItemObj = getMenuItemObj(menuItemName);
   var tblModel = getTableModel(refId);
   var colInd1  = tblModel.getColumnIndex("IPResourcesExt.AD_ID");
   var adID = tblModel.getValueAt(index,colInd1);
   showURLInDialog('/ipam/ADDetailsView.jsp?adID='+adID,'position=relative,modal=yes,scrollbars=no,title=AD Computer Details')
}

function adScanNow()
{
    var url = "/IPAddressManager.do?actionFrom=adScanNow&uid="+new Date().getTime();
    persistADScanNow(url);
}
function ipamSetSubnet(uniqueId , subnet , childNode)
  {
      //var childNode = document.getElementById("childNode").value;
      updateState(uniqueId,"NETWORKADDRESS",subnet,true);
      updateState(uniqueId,"childNode",childNode,true);
      if(document.getElementById("actionFrom").value == "ipam_saerch_tab")
          {
            refreshSubView(uniqueId);
          }else{
       var childTrees = tree.getSubItems(tree.getSelectedItemId())
        var netID = getChildIDs(childTrees);
      var url = uniqueId+".cc?NETWORKADDRESS="+subnet+"&childNode="+childNode+netID;
      //
      renderIPAMGraph(url,"tt");
  }
      return false;
  }
var partofAD = null;
function moveIPAction()
{
	var action=document.getElementById('moveaction').value;
	if(action=="Reserved")
	{
		invokeMenuAction('markAsReserve', 'IPAddressAvailabilityView',null);
	}
	else if(action=="NotReserved")
	{
                invokeMenuAction('markAsUnReserve', 'IPAddressAvailabilityView',null)
	}
	else if(action=="ReservedStaicIP")
	{
                invokeMenuAction('markAsReserveStatic', 'IPAddressAvailabilityView',null)
	}
	else if(action=="used")
	{
                invokeMenuAction('markAsUsed', 'IPAddressAvailabilityView',null)
	}
	else if(action=="transient")
	{
                invokeMenuAction('markAsTransient', 'IPAddressAvailabilityView',null)
	}
	else if(action=="available")
	{
                invokeMenuAction('markAsAvailable', 'IPAddressAvailabilityView',null)

	}else if(action=="2")
	{
                invokeMenuAction('markAsTrusted', 'IPAddressAvailabilityView',null)

	}else if(action=="3")
	{
                invokeMenuAction('markAsRogue', 'IPAddressAvailabilityView',null)

	}else if(action=="4")
	{
            invokeMenuAction('guestConfig', 'IPAddressAvailabilityView',null)
	}
	document.getElementById('moveaction').options[0].selected = "selected";
}
function changeFilter(uniqueId)
{
    var filterValue=trim(document.getElementById('filteraction').value);
    var temp=filterValue.split("_");
    var state=temp[1];
    var reserved=temp[0];

    var stateValue,reservedStatus;
    if(state == "Used")
    {
        stateValue=1;
    }
    else if(state == "Transient")
    {
        stateValue=2;
    }
    else if(state == "Available")
    {
        stateValue=3;
    }
    else if(state == "NotScan")
    {
        stateValue=5;
    }
    if(reserved == "res")
    {
        reservedStatus=2;
    }
    else if(reserved == "resStatic")
    {
        reservedStatus=3;
    }
    else if(reserved == "notRes")
    {
        reservedStatus=1;
    }
    var rogueType = "All";
    if(reserved == 'rogueType')
    {
        dnsState = "All";
        setFilterState(uniqueId, stateValue , reservedStatus , filterValue ,  dnsState , state);

    }else if(reserved == 'dns')
    {

        setFilterState(uniqueId, stateValue , reservedStatus , filterValue , state ,rogueType);

    }
    else if(reserved == "In AD")
    {
        partofAD = true;
        availState = "all";
        updateState(uniqueId,"ADTYPE","In AD",true);
        setFilterState(uniqueId, stateValue , reservedStatus , filterValue , state,rogueType); 
    }
   else if(reserved == "Not in AD")
   {
        partofAD = true;
        availState = "all";
        updateState(uniqueId,"ADTYPE","Not in AD",true);
        setFilterState(uniqueId, stateValue , reservedStatus , filterValue , state,rogueType);        
   }    
   else
   {
        state = "All"
        setFilterState(uniqueId, stateValue , reservedStatus , filterValue , state,rogueType);
    }
}
function setFilterState(uniqueId , availState , reservedStatus , filterValue ,dnsFailure,rogueType)
{

   updateState(uniqueId,"STATUS",availState,true);
   updateState(uniqueId,"reservedStatus",reservedStatus,true);
   updateState(uniqueId,"filterValue",filterValue,true);
   updateState(uniqueId,"dnsFailure",dnsFailure,true);
   updateState(uniqueId,"rogueType",rogueType,true);
   updateState(uniqueId,"PARTOFAD",partofAD,true);     
   refreshSubView(uniqueId);
}
function showCalDiv(uniqueId)
{
    var newstates=(document.getElementById("state1").value);
    
    updateState(uniqueId,"selectGraph",newstates,true);
    var netid  = document.getElementById("subNETID").value;
    var viewName = "";
    if(newstates == "1")
    {

        viewName = "IPAMSubnetDNSFailureView.cc?";


    }else if(newstates == "2")
    {

        viewName = "IPSubnetReservedReport.cc?";
    }else if(newstates == "3")
    {

        viewName = "RogueSubnetSummaryView.cc?";
    }else if(newstates == "4")
    {

        viewName = "NICTypeSubnetSummaryView.cc?";
    } else if(newstates == "6")
        {
            viewName = "SubnetPartofADReport.cc?";
        }else
        {

            viewName = "InventorySubnetView.cc?";
        }
        //alert(newstates);
         document.getElementById("selectGraph").value = newstates;
    renderIPAMGraph(viewName+"NETID="+netid , "ipamSubnetSumID" )

}
function ShowSelectDiv(divId)
{
	var id = document.getElementById(divId);
	id.style.display = "block";
}
function HideSelectDiv(divId){
	var id = document.getElementById(divId);
	id.style.display = "none";
}
 function setAvaialabilityState(uniqueId , availState,filterValue)
  {
    var temp=filterValue.split("_");
    var state=temp[1];
    var reserved=temp[0];
    var reservedStatus = "";
    var dnsStat = "All";
    var rogueType = "All"
    var inventryType = "All"
    var partofaD = null;
    
    if(reserved == "resStatic")
    {
        reservedStatus=3;
        updateState("IPSubnetReservedReport","filterValue",filterValue,true);
    }else if(reserved == "dns")
    {
        dnsStat=availState;
        availState = "all";
        updateState("IPAMSubnetDNSFailureView","filterValue",filterValue,true);
    }else if(reserved == "rogueType")
    {
        rogueType = availState;
        availState = "all";
        updateState("RogueSubnetSummaryView","filterValue",filterValue,true);
    }
    else if(reserved == "In AD")
    {
        availState = "all";
        partofaD = "true";        
        updateState(uniqueId,"ADTYPE","In AD",true);
        updateState("SubnetPartofADReport","filterValue",filterValue,true);        
    }
   else if(reserved == "Not in AD")
   {
        availState = "all";
        partofaD = "true";
        updateState(uniqueId,"ADTYPE","Not in AD",true);
        updateState("SubnetPartofADReport","filterValue",filterValue,true);
   }    
      updateState(uniqueId,"STATUS",availState,true);
      updateState(uniqueId,"reservedStatus",reservedStatus,true);
      updateState(uniqueId,"filterValue",filterValue,true);
      updateState(uniqueId,"dnsFailure",dnsStat,true);
      updateState(uniqueId,"rogueType",rogueType,true);
      updateState(uniqueId,"inventryType",inventryType,true);
      updateState(uniqueId,"PARTOFAD",partofaD,true);        
      refreshSubView(uniqueId);
  }
   function setReservedState(uniqueId , reservedStatus)
  {
      var availState = "All";
      updateState(uniqueId,"STATUS",availState,true);
      updateState(uniqueId,"reservedStatus",reservedStatus,true);
      refreshSubView(uniqueId);
  }

  function setSearchState(uniqueId , searchStr)
  {
      updateState(uniqueId,"SEARCH_VALUE",searchStr,true);
      refreshSubView(uniqueId);
      return false;
  }
  function divEle()
  {
     var x =scale1.offsetLeft;
     document.getElementById("pointer").style.left = x + 40 ;
     document.getElementById("pointer").style.display = "block";
  }

function showNextRange(val)
{
    var childTrees = tree.getAllSubItems(tree.getSelectedItemId())
    var netID = getChildIDs(childTrees);
    var t=val.split("?");
    var viewName = "IPAMSummarBarChart.cc?childNode=true&"+t[1]+"&"+netID+document.getElementById("other").value;
    renderIPAMGraph (viewName , "ipamBarChartID");
}
function updateStateVaule(u)
{
    var u=t[1].split("&");
    for(var q=0;q<u.length;q++){

        var keyVal = u[q].split("=");

        updateState("IPAMSummaryChart",keyVal[0],keyVal[1],true);

    }
}
function submitGraphViewForm(f)
{
    var Range  = f.RANGE.value;
    var selID = tree.getSelectedItemId();
    var childTrees = tree.getAllSubItems(selID)
    var netID = getChildIDs(childTrees);
    var t = "PAGE_NUMBER=1&FROM_INDEX=1&TO_INDEX="+Range+"&RANGE="+Range+"&recordsPerPage="+Range;
    var viewName = "IPAMSummarBarChart.cc?childNode=true&"+t+"&"+netID+document.getElementById("other").value;
    renderIPAMGraph (viewName , "ipamBarChartID");

	return false;

}

function getDeleteAllStatusMsg(resOptions, reqOptions)
{
    var treeID = tree.getSelectedItemId();
    var childTrees = tree.getAllSubItems(treeID)
    if(childTrees)
    {
        var temp = childTrees.split(",");
        for(var i =0; i< temp.length ; i++)
        {
            var childid = temp[i]
            var childids = childid.split("_");
            if(childids[0] == "SUBNET")
            {
                tree.deleteItem(childid);
            }
        }
    }
}
function getDeleteStatusMsg(resOptions, reqOptions)
{
    var msg = resOptions.responseText;    
    if(msg != null)
    {
        var txtID =  msg.split("_");
        var gid = txtID[1].split(",");
        for(var i=0; i < gid.length-1; i++)
        {
            var gidName = trim(gid[i]);
            gidName = "SUBNET_"+gidName;
            tree.deleteItem(gidName);            
        }
    }
    return false;
}


