// Application specific script //
//----------------------------//

// validates the number of checked checkboxes on the form to determine whether
// the form should be submitted or not
function checkNumberChecked(formObj, bNotMultiple)
{
    var numSel;
    numSel = countChecked(formObj);
    if (numSel==0)
    {
	alert("Please select an application before selecting one of the options below.");
	return false;
    }
    else if (bNotMultiple && numSel>1)
    {
	alert("Only one application must be selected for this option.");
	return false;
    }
    else
	return true;
}
//------------------------------------------------------------------------------

// checks whether the number specified is greater than 0. If it is, there is at
// least one checked application which is not the organisation of the logged on
// user, such that an error should occur.
function checkMyOrg(notMyOrg)
{
    if (notMyOrg>0)
    {
	alert("This option can only be selected for applications belonging to your organisation.");
	return false;
    }
    else
	return true;
}
//------------------------------------------------------------------------------

// checks whether there is at least one checked application for which the logged
// on user's council is not the application originator and isn't part of a
// joint submission, such that an error should occur.
function checkMyOrgOrJS(notMyOrg, notMyJS)
{
    if (notMyOrg>0 || (notMyOrg==0 && notMyJS>0))
    {
	alert("This option can only be selected for applications belonging to your organisation or for which you are part of a joint submission.");
	return false;
    }
    else
	return true;
}
//------------------------------------------------------------------------------

function validateTimeline(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.timeStart) || isBlank(formObj.timeEvent))
        return false;

    if (!validDate(formObj.timeStart.value))
    {
        alert("Please enter a valid timeline start date to continue.");
        return false;
    }

    if (formObj.timeEvent.value.length>255)
    {
        alert("Timeline event/activity must be less than 256 characters.\nYou have entered " + formObj.timeEvent.value.length + ". Please amend and try again.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function validateJointSubmission(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.jsRegionAgentSeq, true) || isBlank(formObj.jsCouncilAgentSeq, true))
    {
        alert("Please complete all Joint Submission mandatory fields to continue.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function validateStakeholder(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.shStakeholder, true) || isBlank(formObj.shContribution, true))
    {
        alert("Please complete all Stakeholder mandatory fields to continue.");
        return false;
    }

    if (formObj.shContribution.value.length>255)
    {
        alert("Stakeholder contribution must be less than 256 characters.\nYou have entered " + formObj.shContribution.value.length + ". Please amend and try again.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function validateCommittee(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.comContactName, true) || isBlank(formObj.comOrganisation, true))
    {
        alert("Please complete all Advisory Committee mandatory fields to continue.");
        return false;
    }

    if (formObj.comContactName.value.length>64)
    {
        alert("Committee contact name must be less than 65 characters.\nYou have entered " + formObj.comContactName.value.length + ". Please amend and try again.");
        return false;
    }

    if (formObj.comOrganisation.value.length>255)
    {
        alert("Committee contact organisation must be less than 256 characters.\nYou have entered " + formObj.comOrganisation.value.length + ". Please amend and try again.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function validateCostBudget(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.cbBudgetType) || isBlank(formObj.cbDescription) || isBlank(formObj.cbExpectCost))
        return false;

    if ((isNumeric(formObj.cbExpectCost.value)!=true) ||
        ((new Number(formObj.cbExpectCost.value))<0))
    {
        alert("Please enter a valid expected cost to proceed.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function validateContributor(formObj)
{
    if (formObj==null)
        return false;

    if (isBlank(formObj.cntContributor) || isBlank(formObj.cntExpectFunds))
        return false;

    if ((isNumeric(formObj.cntExpectFunds.value)!=true) ||
        ((new Number(formObj.cntExpectFunds.value))<0))
    {
        alert("Please enter a valid expected funds value to proceed.");
        return false;
    }

    return true;
}
//------------------------------------------------------------------------------

function resetStakeholder(formObj)
{
    formObj.shContribution.value='';
    formObj.shStakeholder.value='';
}
//------------------------------------------------------------------------------

function resetCommittee(formObj)
{
    formObj.comOrganisation.value='';
    formObj.comContactName.value='';
}
//------------------------------------------------------------------------------

function resetJointSubmission(formObj)
{
    formObj.jsCouncilAgentSeq.value='';
    formObj.jsRegionAgentSeq.value='';
    formObj.jsFundManager.checked=false;
}
//------------------------------------------------------------------------------

function resetContributor(formObj)
{
    formObj.cntContributor.value='';
    formObj.cntDescription.value='';
    formObj.cntExpectFunds.value='';
}
//------------------------------------------------------------------------------

function resetCostBudget(formObj)
{
    formObj.cbBudgetType.value='';
    formObj.cbDescription.value='';
    formObj.cbExpectCost.value='';
}
//------------------------------------------------------------------------------

function resetTimeline(formObj)
{
    formObj.timeStart.value='';
    formObj.timeEvent.value='';
    formObj.timeMajorEvent.checked=false;
}
//------------------------------------------------------------------------------