/*
 * This file contains generic JS helper functions.
 */

/*
 * Return the protocol and hostname as a string.
 * Only covers http and https
 */
function httpHostname()
{
    var fullUrl = window.location.href;
    var httpHost = window.location.hostname;
    if( typeof fullUrl != 'undefined' && typeof httpHost != 'undefined' )
    {
        return ( fullUrl.substr(0, 8) == "https://" )? "https://"+httpHost : "http://"+httpHost ;
    }
    return '';
}

function resetAllFields( formId, resetHidden )
{
    var form = $(formId);
    if( typeof resetHidden === 'undefined' )
    {
        resetHidden = false;
    }
    if( ! form )
    {
        return;
    }
    for( var i = 0; i < form.length; ++ i )
    {
        var type = form[i].type;
        if(  type !== 'button' && type !== 'submit' && type !== 'reset' && ( resetHidden || ( ! resetHidden && type !== 'hidden') ) )
        {
            form[i].value = '';
        }
    }
}
function labelFor( id )
{
    var list = document.getElementsByTagName('label');
    for (var i = 0; i < list.length; i++)
    {
        if (list[i].htmlFor === id)
        {
            return list[i].collectTextNodes();
        }
    }
}

