//$Id: discoveryConfiguration.js,v 1.1.2.2 2004/06/02 12:44:20 ragoubady Exp $

function toggleSnmpv3()
{
    if(document.DiscForm.snmpv3Discovery.type=="checkbox" && document.DiscForm.snmpv3Discovery.checked)
    {
        document.DiscForm.v3UserName.disabled=false;
        document.DiscForm.v3UserName.className="formStyleSmall";
        document.DiscForm.v3ContextName.disabled=false;
        document.DiscForm.v3ContextName.className="formStyleSmall";
    }
    else
    {
        document.DiscForm.v3UserName.disabled=true;
        document.DiscForm.v3UserName.className="formStyleSmallDisabled";
        document.DiscForm.v3ContextName.disabled=true;
        document.DiscForm.v3ContextName.className="formStyleSmallDisabled";
    }
}
function fillAndSetRediscovery()
{
	if(document.DiscForm.actionToPerform.value="schedular")
	{
		if( document.DiscForm.schedular[0].checked )
			toggleFields('days,hours,dateorday,dateBased,daysOfMonth,daysOfWeek,selectedHour','reDiscInt');
		else
		if( document.DiscForm.schedular[1].checked )
		{
			toggleFields('reDiscInt','days,hours,dateorday,dateBased,daysOfMonth,daysOfWeek,selectedHour');
			if(document.DiscForm.dateorday[0].checked)
			{
				toggleFields('days,daysOfWeek','dateBased,daysOfMonth');
				if(document.DiscForm.dateBased[0].checked)
					toggleFields('daysOfMonth','');
				else
				if(document.DiscForm.dateBased[1].checked)
					toggleFields('','daysOfMonth');
				else
					document.DiscForm.dateBased[0].selected="true";

				if(document.DiscForm.hours[0].checked)
					toggleFields('selectedHour','');
				else
				if(document.DiscForm.hours[1].checked)
					toggleFields('','selectedHour');
				else
					document.DiscForm.hours[0].selected="true";
	

				
					
			}
			else
			if(document.DiscForm.dateorday[1].checked)
			{
				toggleFields('dateBased,daysOfMonth','days,daysOfWeek');
				if(document.DiscForm.days[0].checked)
					toggleFields('daysOfWeek','');
				else
				if(document.DiscForm.days[1].checked)
					toggleFields('','daysOfWeek');
				else
					document.DiscForm.days[0].selected="true";

			}
		}
	}
}


function toggleIcmp()
{
    if(document.DiscForm.icmpDiscovery.checked)
    {
        document.DiscForm.pingRetries.disabled=false;
        document.DiscForm.pingRetries.className="formStyleSmall";
        document.DiscForm.pingTimeout.disabled=false;
        document.DiscForm.pingTimeout.className="formStyleSmall";
    }
    else
    {
        document.DiscForm.pingRetries.disabled=true;
        document.DiscForm.pingRetries.className="formStyleSmallDisabled";
        document.DiscForm.pingTimeout.disabled=true;
        document.DiscForm.pingTimeout.className="formStyleSmallDisabled"
    }
}

function schedular()
{
    document.DiscForm.toPerform.value="schedular";
    document.DiscForm.actionToPerform.value="schedular";
    var url = document.DiscForm.action + "#sch";
    document.DiscForm.action = url;
    document.DiscForm.submit();
}

function toggleFields(todisable,toEnable)
{
    var fields = new String(todisable);
    if (fields != '')
    {
        var f = fields.split(",");
        for(i=0; i<f.length;i++)
        {
		for(var j=0;j<document.DiscForm.elements.length;j++)
		   {
            	if(document.DiscForm.elements[j].name ==  f[i])
		{
			//alert ("enterted ");
			if(document.DiscForm.elements[j].type ==  "text")
		 	   document.DiscForm.elements[j].className="formStyleSmallDisabled";
	            document.DiscForm.elements[j].disabled=true;
		}
	    }

        }
    }
    var to = new String(toEnable);
    if(to != '')
    {
        var x = to.split(",");
        for(j=0;j<x.length;j++)
        {
		for(var k=0;k<document.DiscForm.elements.length;k++)
	   {
            	if(document.DiscForm.elements[k].name ==  x[j])
		{
			//alert ("enterted ");
			if(document.DiscForm.elements[k].type ==  "text")
		 	   document.DiscForm.elements[k].className="formStyleSmall";
	            document.DiscForm.elements[k].disabled=false;
		}
	    }

        }
    }
}
