﻿function EncodeValue(value) 
{
    if (typeof(encodeURIComponent) == 'function') 
    {
        return encodeURIComponent(value);
    }
    else 
    {
        return escape(value);
    }
}
function HandleClientException(errorMessage, isServerError)
{
    if (isServerError) return;
    
    var postErrorScript = document.createElement('SCRIPT');
        
    postErrorScript.type = 'text/javascript';
    postErrorScript.id = 'postErrorScript';
     
    var documentHeads = document.getElementsByTagName('HEAD');
    var documentHead = documentHeads == null ? null : documentHeads[0];
    
    if ((documentHead != null) && (typeof(documentHead) != 'undefined'))
    {
        documentHead.appendChild(postErrorScript);
    }
    else
    {
        document.body.appendChild(postErrorScript);
    }
    
    var newLocation = 'HandleError.aspx?__ErrorMessage=' + EncodeValue(errorMessage);
    
    postErrorScript.src = newLocation;
}
function RemovePostErrorScript()
{
    var scriptToRemove = document.getElementById('postErrorScript');
    
    if ((scriptToRemove != null) && (scriptToRemove.parentElement != null)) 
    {
        scriptToRemove.parentElement.removeChild(scriptToRemove);
    }
}
function ErrorMessageLoaded()
{
    setTimeout('RemovePostErrorScript', 10);
}

if (typeof(AddErrorFunction) == 'function') AddErrorFunction(HandleClientException);
