//$Id: NetworkMonitorEPingCommonValidator.js,v 1.9 2006/08/30 13:47:17 karuppannan Exp $

function setActionValue(action)
{
		document.hostForm.actionFrom.value = action;
}

function removeRowFromTable(ip)
{
	document.hostForm.actionFrom.value="deleteHost";
	document.hostForm.deleteRow.value=ip;
	var actionFrom = document.hostForm.actionFrom.value;
}

function validateIPOrHost()
{
	var action = document.hostForm.actionFrom.value;
        var host = document.hostForm.ipOrHost.value;
        if( action == "saveButton" || action == "deleteHost" ||  action == "pageNavigation")
        {
           
            return true;
        }
        if((document.hostForm.actionFrom.value) =='delete' )
	{
                
		if(!checkSelection("delete", "Please Select a host to \"Delete\""))
                {       
			return false;
                }       
		if(eval(document.hostForm.selectAll))
		{
			document.hostForm.selectAll.checked = false;
		}
	}else if( (document.hostForm.actionFrom.value) =='stopScheduler')
        {
                if(!checkSelection("stopScheduler", "Please Select a host to \"Stop Monitor\""))
                {       
			return false;
                }       
		if(eval(document.hostForm.selectAll))
		{
			document.hostForm.selectAll.checked = false;
		}
        }
        else if( (document.hostForm.actionFrom.value) =='startScheduler')
        {
                if(!checkSelection("startScheduler", "Please Select a host to \"Start Monitor\""))
                {       
			return false;
                }       
		if(eval(document.hostForm.selectAll))
		{
			document.hostForm.selectAll.checked = false;
		}
        }

	else if( action == 'stopButton' || action == 'actionButton' || action == 'globalAlertConfig')
        {
                return true;
        }
	document.hostForm.ipOrHost.value = trim(document.hostForm.ipOrHost.value);
        if( action == 'addHost' ){
	if(document.hostForm.ipOrHost.value.length==0)
	{
		alert("Please enter an IP address or a host name.")
		document.hostForm.ipOrHost.focus()
		return false;
	}
        
	ip = document.hostForm.ipOrHost.value;
	var parts = ip.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(ip))
		{
			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;
}

