function SetRadioChecked( form, name, index, dodirty )
{
    if (!form.elements[name][index])
    {
	form.elements[name].checked = true;
	if( dodirty )
	    SetDirtyFlag( form );
    }
    else if (!form.elements[name][index].checked)
    {
	form.elements[name][index].checked=true;
	if( dodirty )
	    SetDirtyFlag( form );
    }
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(the_input, destination, len, e)
{
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

    if(the_input.value.length >= len && !containsElement(filter,keyCode) && e.keyCode != 9 && e.keyCode != 16)
    {
        if(destination)
            destination.select();
        else
        {
            the_input.value = the_input.value.slice(0, len);
            the_input.form[(getIndex(the_input)+1) % the_input.form.length].select();
        }
    }

    function containsElement(arr, ele)
    {
        var found = false, index = 0;
        while(!found && index < arr.length)
        if(arr[index] == ele)
        found = true;
        else
        index++;
        return found;
    }

    function getIndex(the_input)
    {
        var index = -1, i = 0, found = false;
        while (i < the_input.form.length && index == -1)
        if (the_input.form[i] == the_input)index = i;
        else i++;
        return index;
    }

    return true;
}

function OpenStandardPopup(theUrl,theName) {
	var topCornerX = screen.width * 0.1;
	var topCornerY = screen.height * 0.05;
	var winWidth = screen.width * 0.8;
	var winHeight = screen.height * 0.7;
	var windowOptions = 'screenX='+topCornerX+',screeny='+topCornerY+',left='+topCornerX+',top='+topCornerY+',toolbar=yes,status=yes,scrollbars=yes,resizable=yes,WIDTH='+winWidth+',HEIGHT='+winHeight;
	popup = window.open(theUrl,theName,windowOptions);
	popup.focus();
}

function OpenCustomPopup(theUrl, theName, topCornerX, topCornerY, winWidth, winHeight, otherOptions, useFullScreen)
{
    var windowOptions

    if(useFullScreen == 1)
    {
        if(window.screen)
        {
            windowOptions = "left=0,screenX=0,top=0,screenY=0";

            winWidth = screen.availWidth - 10;
            winHeight = screen.availHeight - 30;

            windowOptions += ', WIDTH='+winWidth+',HEIGHT='+winHeight+', innerWidth='+winWidth+',innerHeight='+winHeight;
        }
        else
            windowOptions = '';
    }
    else
    {
        windowOptions = 'screenX='+topCornerX+',screenY='+topCornerY+
    ',left='+topCornerX+',top='+topCornerY+
    ',WIDTH='+winWidth+',HEIGHT='+winHeight;
    }

  if (otherOptions)
    windowOptions += ','+otherOptions;

  popup = window.open(theUrl,theName,windowOptions);
  popup.focus();
}

// added for FE 96 to allow for Div tag hide/display features (code stolen from 4.03.01 IR)
function toggleDisplay(element,form,str) 
{
    var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = (style.display == 'none') ? 'inline' : 'none';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }
    /* For the Expand collapse all fields */
    if(form.expand_toggle)
    {
    form.expand_toggle.value = '';
    }
    
    form.save_div_toggles.value = 1;
}
// added for FE 96 to allow for Div tag hide/display features (code stolen from 4.03.01 IR)
function toggleOn(element,form,str)
{
	var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = 'block';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }
}
// added for FE 96 to allow for Div tag hide/display features (code stolen from 4.03.01 IR)
function toggleOff(element,form,str)
{
	var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = 'none';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }
}


function hideSelect()
{
    var sel = document.getElementsByTagName('select');
    for (var i = 0; i < sel.length; i++)
    {
        sel[i].style.visibility = 'hidden';
    }
}

function showSelect()
{
    var sel = document.getElementsByTagName('select');
    for (var i = 0; i < sel.length; i++)
    {
        sel[i].style.visibility = 'visible';
    }
}

function toggleDisplay_Assessment(element,form,str) 
{
    var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = (style.display == 'none') ? 'inline' : 'none';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }
}

function CollapseHousehold(element, form, str)
{
	var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = (style.display == 'none') ? 'inline' : 'none';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }	
}

function toggleDisplay2(element,form,str) 
{
    var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    
    if (element && (style = element.style))
        style.display = (style.display == 'none') ? 'inline' : 'none';
        
    if(element && style.display == 'none')
    {
    	eval("form." + str + ".value = 'none';");
    }
    else
    {
    	eval("form." + str + ".value = 'block';");
    }
    //eval('alert(form.toggle_households2.value);');

    /* For the Expand collapse all fields */
}

// For household functionality
function GoToRelevantLink(url)
{
	GoToNewUrl(url);
	return false;
}

// For household functionality - ensures there is proper saving of dirty data
function MenuCheck(url, code)
{
	return MenuSubmitData(url, code)
}
// This will no be on the mouseover and mouseout event on the div tag
function OnMenuSelect(type)
{
    var sel = document.getElementsByTagName('select');
    for (var i = 0; i < sel.length; i++)
    {
        sel[i].style.visibility = type;
    }
}