//$Id: Input.js,v 1.24 2008/03/28 13:05:36 karuppannan Exp $
function validate()
{
	document.InputForm.RouterName.value = trim(document.InputForm.RouterName.value);
        var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

        if(document.InputForm.RouterName.value.length==0)
        {
		alert("Please enter a valid Cisco device name or an IP Address.")
                document.InputForm.RouterName.focus();
		//defaultAction(document.InputForm);
		return false;
        }
	if(document.InputForm.Community.value.length == 0)
       	{
                alert("Please enter the community string.")
       	        document.InputForm.Community.focus();
                return false;
       	}

        key = document.InputForm.RouterName.value
        var parts = key.split(".");
	if(parts[0].length == 0)
	{
		alert("Please enter a valid IP Address.");
		document.InputForm.RouterName.focus();
		return false;
	}

	if(isNumber(parts[0]))
        {
        	if(!isValidIPAddress(document.InputForm.RouterName.value))
			{
				alert("Please enter a valid IP Address.");
				document.InputForm.RouterName.focus();
				return false;
			}
        }
	else
	{
		if(!isSpecialCharacter(document.InputForm.RouterName.value))
		{
			alert("Please enter a Cisco device name without special characters.");
			document.InputForm.RouterName.focus();
			return false;
		}
	}
	return true;
}

function validateInput()
{
	var test = validate();
	
	if (!test)
	{
		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;
}


function validateIPandPass(ipAdd,pass)
{
	var ip = trim(ipAdd);
        var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

        if(ipAdd.length==0)
        {
		alert("Please enter a valid Cisco device name or an IP Address.")
                document.InputForm.RouterName.focus();
		//defaultAction(document.InputForm);
		return false;
        }
	if(pass.length == 0)
       	{
                alert("Please enter the password string.")
       	        document.InputForm.Community.focus();
                return false;
       	}
        key = ipAdd;
        var parts = key.split(".");
	if(parts[0].length == 0)
	{
		alert("Please enter a valid IP Address.");
		document.InputForm.RouterName.focus();
		return false;
	}

	if(isNumber(parts[0]))
        {
        	if(!isValidIPAddress(ipAdd))
			{
				alert("Please enter a valid IP Address.");
				document.InputForm.RouterName.focus();
				return false;
			}
        }
	else
	{
		if(!isSpecialCharacter(ipAdd))
		{
			alert("Please enter a Cisco device name without special characters.");
			document.InputForm.RouterName.focus();
			return false;
		}
	}
	return true;
}

















