﻿
function addClickFunction(id)
{
    {
        var b = document.getElementById(id);
        if (b && typeof(b.click) == 'undefined')
            b.click = function()
            {
                {
                    var result = true;
                    if (b.onclick) result = b.onclick();
                    
                    if (typeof(result) == 'undefined' || result)
                    {
                        {
                            eval(b.href);
                        }
                    }
                }
            }
    }
}

// handle keypress submit - browser agnostic
// catch the keypress on a textbox, if the keystroke is the (enter) then call __doPostback to do
// a manual postback using that control

function submitOnEnterPress( ev, buttonId )
{
    var enterkeyCode = 13;    // 13 is for (enter)
    if (window.event)  // ie
    {
        if (ev.keyCode == enterkeyCode)
        {
            __doPostBack(buttonId,'');
            return;
        }
    }
    else if (ev.which)  // all other
    {
        if (ev.keyCode == enterkeyCode)
        {
            __doPostBack(buttonId,'');
        }
    }
}


function unvalidate(myValidationGroup)
{
    // Remove the validator control(s) from display.
    var myValidators = Page_Validators;
    if ((typeof(myValidators) != "undefined") && (myValidators != null))
    {
        for (i=0;i<myValidators.length;i++)
        {
            var myValidator = myValidators[i];
            if (myValidationGroup == null || IsValidationGroupMatch(myValidator, myValidationGroup))
            {
                if (myValidator.style.visibility.length > 0 && myValidator.style.display.length == 0)
                {
                    myValidator.style.visibility = 'hidden';
                }
                else if (myValidator.style.display.length > 0 && myValidator.style.visibility.length == 0)
                {
                    myValidator.style.display = 'none';
                }
            }
        }
    }
}

function isValueGreaterThanZero(ctlClientID)
{
        var quantityString = $get(ctlClientID).value.toString().trim();
        
        var quantity = 0;
        
        if (quantityString != "")
        {
            quantity = parseInt(quantityString, 10);
        }

        return quantity > 0;
}

function roundDollarDown(unroundedAmount)
{
    var returnValue = unroundedAmount;
    
    returnValue = returnValue * 100;
    returnValue = Math.floor(returnValue);
    returnValue = returnValue / 100;
    
    return returnValue;

}

function roundDollarUp(unroundedAmount)
{
    var returnValue = unroundedAmount;
    
    returnValue = returnValue * 100;
    returnValue = Math.ceiling(returnValue);
    returnValue = returnValue / 100;
    
    return returnValue;

}

function roundDollarNormal(unroundedAmount)
{
    var returnValue = unroundedAmount;
    
    returnValue = returnValue * 100;
    returnValue = Math.round(returnValue);
    returnValue = returnValue / 100;
    
    return returnValue;
}
function FormatContribution(discount)
{
//debugger;
        discount = (discount * 100).toFixed(2);
        var discountDisplay;
        
        if (((discount * 100 ) % 1) == 0)
        {
            discountDisplay = (discount * 100).toFixed(0) + "%";
        }
        else
        {
            discountDisplay = (discount * 100).toFixed(2) + "%";
        }
        
        return discountDisplay;

}

function formattedDiscountDisplay(percent)
{
    percent = percent * 100;
    var helper = percent.toString();
    
    if( helper.indexOf(".") != -1 )
    {
        helper = helper.substring(0,helper.indexOf(".")+ 3);
        percent = parseFloat(helper);
    }
    else
    {    
        percent = parseInt(helper,10);
    }
    
    return percent + "%";
}

