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();
}

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 */
    form.expand_toggle.value = '';
}

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';");
    }
}

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.display = 'none';
    }
}

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