//$Id: DesktopInput.js,v 1.19 2008/03/28 13:07:30 karuppannan Exp $

function setDiscSpaceView(actionFrom , rowcount)
{
   
    ShowTab("loadingImgID");
    document.hostForm.selTool.value ="diskSpaceMonitor"; 
    document.hostForm.actionFrom.value = actionFrom;
    var ipOrHost = document.hostForm.ipOrHost.value ;
    var community = document.hostForm.community.value ;
    renderViewCurrentView("diskSpaceMonitor.cc?actionFrom="+actionFrom+"&ipOrHost="+ipOrHost+"&community="+community+"&rowcount="+rowcount , 'sysExplorer');
    
}
 var refreshIntervalID;

function validateSysExplorer()
{
	document.hostForm.doAction.value = "startAction";
         var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

	document.hostForm.ipOrHost.value = trim(document.hostForm.ipOrHost.value);

        if(document.hostForm.ipOrHost.value.length==0)
        {
                alert("Please enter an IP address or a host Name.")
                document.hostForm.ipOrHost.focus();
		return false;
        }

        if(document.hostForm.community.value.length==0)
        {
                alert("Please enter the community.")
                document.hostForm.community.focus();
		return false;
        }

        key = document.hostForm.ipOrHost.value

        var parts = key.split(".");
	

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

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


function successAction121()
{
    setCurrentView(document.hostForm.selTool.value , document.hostForm.actionFrom.value);    
}
function setCurrentView(viewName,actionFrom)
{
    if(validateSysExplorer())
        {
            
        
    ShowTab("loadingImgID");
    window.clearInterval(refreshIntervalID);
    document.hostForm.selTool.value = viewName; 
    document.hostForm.actionFrom.value = actionFrom;
    var ipOrHost = document.hostForm.ipOrHost.value ;
    var community = document.hostForm.community.value ;
    
    renderViewCurrentView123(viewName+".cc?actionFrom="+actionFrom+"&ipOrHost="+ipOrHost+"&community="+community+"&doAction=" , 'sysExplorer');
  }
}
function renderViewCurrentView123(viewName , localVar)
{
    //alert(viewName);
    var myAnonFunction = function(response,reqOptions)
    {        
       document.getElementById(localVar).innerHTML = response.getOnlyHtml();
        HideTab("loadingImgID");
    };
    AjaxAPI.sendRequest({URL:viewName,ONSUCCESSFUNC:myAnonFunction});

}

function refreshCPUMonitorView()
{
    var ipOrHost = document.hostForm.ipOrHost.value ;
    var community = document.hostForm.community.value ;
    var refreshInterval =document.hostForm.refreshInterval.value;
    var url ="cpuMonitor.cc?actionFrom=cpuMonitor&ipOrHost="+ipOrHost+"&community="+community+"&refreshInterval="+refreshInterval; 
    renderViewCurrentView123( url , 'sysExplorer');    
}

function setDiscSpaceView(actionFrom , rowcount)
{   
    ShowTab("loadingImgID");
    document.hostForm.selTool.value ="diskSpaceMonitor"; 
    document.hostForm.actionFrom.value = actionFrom;
    var ipOrHost = document.hostForm.ipOrHost.value ;
    var community = document.hostForm.community.value ;
    renderViewCurrentView123("diskSpaceMonitor.cc?actionFrom="+actionFrom+"&ipOrHost="+ipOrHost+"&community="+community+"&rowcount="+rowcount , 'sysExplorer');
    
}
function validate()
{
	startAction(document.hostForm);

	document.hostForm.doAction.value = "startAction";

        var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

	document.hostForm.ipOrHost.value = trim(document.hostForm.ipOrHost.value);

        if(document.hostForm.ipOrHost.value.length==0)
        {
                alert("Please enter an IP address or a host Name.")
                document.hostForm.ipOrHost.focus();
		defaultAction(document.hostForm);
                return false;
        }

        if(document.hostForm.community.value.length==0)
        {
                alert("Please enter the community.")
                document.hostForm.community.focus();
		defaultAction(document.hostForm);
                return false;
        }

        key = document.hostForm.ipOrHost.value

        var parts = key.split(".");
	

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

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

function validateMacResolver(){
	document.hostForm.ipOrHost.value = trim(document.hostForm.ipOrHost.value);
        if(document.hostForm.ipOrHost.value.length==0)
        {
                alert("Please enter an IP address, a host name or a MAC address.")
                document.hostForm.ipOrHost.focus()
                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 trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, ""); }
   return temp;
}

