﻿// JScript File

function clearForm(formId) 
{ 
    var form, elements, i, elm, field; 
    form = document.getElementById ? document.getElementById(formId) : document.forms[formId]; 

    //look through by tag name 
    if (document.getElementsByTagName)
    {
       
        //clear text boxes, check boxes, and radio buttons
        elements = form.getElementsByTagName('input');
        for(i = 0, elm; elm = elements.item(i++);)
        {
            if (elm.disabled == false)
            {
                //clear text boxes
                if (elm.getAttribute('type') == "text" || elm.getAttribute('type') == "password")
                {
                    elm.value = '';
                }

                //clear check boxes and radio buttons
                //else if (elm.getAttribute('type') == "checkbox" || elm.getAttribute('type') == "radio")
                else if (elm.getAttribute('type') == "checkbox" )
                {
                    elm.checked = false;
                }
            }
        }

        //reset list boxes and drop down lists to the first item
        elements = form.getElementsByTagName('select');
        for(i = 0, elm; elm = elements.item(i++);)
        {
            if (elm.disabled == false && elm.id != 'dnn_dnnLANGUAGE_selectCulture')
            {
                elm.options.selectedIndex=0;
            }
        }
        //reset list boxes and drop down lists to the first item
        elements = form.getElementsByTagName('textarea');
        for(i = 0, elm; elm = elements.item(i++);)
        {   
            elm.value = '';
        }
    }
    //look through by element type here but the result is the same as above for input type
    else
    {
        elements = form.elements;
        for(i = 0, elm; elm = elements[i++];)
        {
            if (elm.disabled == false)
            {
                //clear text boxes
                if (elm.type == "text" || elm.type == "password") 
                {
                    elm.value ='';
                }
                //clear check boxes and radio buttons
                else if (elm.type == "checkbox" || elm.type == "radio")
                {
                    elm.checked = false;
                }
            }
        }
    }

} //clearForm(formId)