﻿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';
                }
            }
        }
    }
}

// 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 roundDollarNormal(unroundedAmount)
{
    var truncValue = unroundedAmount.toFixed(3);
    var returnValue = unroundedAmount;

    returnValue = parseFloat(Math.round(parseFloat(returnValue* 100)) / 100);
    var difference = (truncValue - returnValue).toFixed(3);
    if (difference == .005)
        returnValue += .01;

    return returnValue;
}

function isValueGreaterThanZero(ctlClientID)
{
        var quantityString = $get(ctlClientID).value.toString().trim();
        
        var quantity = 0;
        
        if (quantityString != "")
        {
            quantity = parseInt(quantityString, 10);
        }

        return quantity > 0;
}

function formattedDiscountDisplay(percent)
{
    percent = Math.round(parseFloat(percent * 10000))/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 + "%";
}