$(document).ready(function() {
  //Removes border around the checkboxes
  $(":checkbox").css({border:"0"});
});

function ConfirmMessage(src,message)
{
    var retVal=false;
    event.returnValue = false;    //fail-safe, need to return true explicly with confirm
    if (confirm(message))
    {
        event.returnValue = true;
        retVal = true;
    }
    
    
    return;
}

// multiply values of src and multiplier, and put product in result
function GetGrowth(ctrl1, ctrl2, result)
{
    var val1 = parseFloat(ctrl1.value);
    var val2 = parseFloat(ctrl2.value);
    if(val1 && val2)
    {
        result.value = ((val2 - val1)/val1*100).toFixed(2);
    }
}


// multiply values of src and multiplier, and put product in result
function Multiply(src, multiplier, result)
{
    var m2 = document.getElementById(multiplier);
    var p = document.getElementById(result);
    if (m2 && p)
    {
        var val1 = parseFloat(src.value);
        var val2 = parseFloat(m2.value);
        if (val1 && val2)
        {
            p.value = (val1*val2).toFixed(2);
        }
    }
    else
    {
        alert("Multiply: missing multiplier, result");
    }
}

function Divide(divisor, dividend, result)
{
    var dsor = document.getElementById(divisor);
    var dend = document.getElementById(dividend);
    var r = document.getElementById(result);
    if (dsor && dend && r)
    {
        var vsor = parseFloat(dsor.value);
        var vend = parseFloat(dend.value);
        if (vsor && vend)
        {
            r.value = (vsor/vend).toFixed(2);
        }
    }
    else
    {
        alert("Divide: missing divisor, dividend or result");
    }
}

function display(src, textControlID)
{
    var textControl = document.getElementById(textControlID);
    if(textControl.style.visibility=='visible')
    {
        textControl.style.visibility = 'hidden';
        textControl.style.display = 'none';
    }
    else
    {
        textControl.style.visibility = 'visible';
        textControl.style.display = 'block';
    }
}

function checkIntermediate(src, groupName)
{
    if(src.checked)
    {
        var gn = getIdName(groupName);

        var buyer = document.getElementById(gn + '_0');
        buyer.checked = true;
        var seller = document.getElementById(gn + '_1');
        seller.checked = true;
    
    }
}

function AgreeToTerms(sender, args)
{
    var valid = false;
    var chkID = sender.getAttribute('CheckboxID');
    var chk = document.getElementById(getIdName(chkID));
    if(chk)
    {
        if(chk.checked)
        {
            valid = true;
        }
        else
        {
            var message = "Click 'OK' to continue without agreeing to the Terms of " +
                        "Use. Otherwise, click 'Cancel' and check the Agree to Terms of Use " +
                        "to make your profile available on this website.";
            valid = confirm(message);
        }
    
    }
    args.IsValid = valid;
   
}

function getIdName(name)
{
    return name.replace(/\$/g,'_');
}

function DisplaySearchServicesChildren(source, servicesName, bpoName)
{
    var ITServices = 204;
    var ITSolutions = 304;
    var Outsourcing = 404;
    var BT_BPO = document.getElementById(getIdName(bpoName));
    var BT_ITServices = document.getElementById(getIdName(servicesName));
    if(BT_BPO && BT_ITServices)
    {
        var ITServicesStyle = "display:none;visibility:hidden;";
        var BPOStyle = "display:none;visibility:hidden;";

        BT_BPO.style.display = "none";
        BT_BPO.style.visibility = "hidden";
        BT_ITServices.style.display = "none";
        BT_ITServices.style.visibility = "hidden";

        if (source.value == ITServices ||
            source.value == ITSolutions)
        {
            BT_ITServices.style.display = "block";
            BT_ITServices.style.visibility = "visible";
        }
        else if (source.value == Outsourcing)
        {
            BT_BPO.style.display = "block";
            BT_BPO.style.visibility = "visible";
        }
    }

}
