/**
* $RCSfile: course.js,v $
* $Author: shenyuan $
* $Revision: 1.11 $
* $Date: 2006/02/13 17:56:46 $
* $Log: course.js,v $
* Revision 1.11  2006/02/13 17:56:46  shenyuan
* remove the constraint for Course Group as user requested
*
* Revision 1.10  2005/12/19 17:12:52  shenyuan
* update changes from user, ref no 017
*
* Revision 1.9  2005/12/18 17:47:28  shenyuan
* update changes from user, ref no 014-020
*
* Revision 1.8  2005/12/07 16:43:08  shenyuan
* update for bugs and issues from User
*
* Revision 1.7  2005/10/10 14:25:41  shenyuan
* add for New Course Registration
*
* Revision 1.6  2005/09/30 14:28:16  shenyuan
* remove the Course ID from Course pages
*
* Revision 1.5  2005/09/25 15:09:09  shenyuan
* update for mutiple Course Run occurrance
*
* Revision 1.4  2005/09/22 16:42:53  shenyuan
* add validation on jsp
*
* Revision 1.3  2005/09/20 17:05:48  shenyuan
* add control for choose empty School Id
*
* Revision 1.2  2005/09/19 13:39:52  shenyuan
* Add postpone function
*
* Revision 1.1  2005/09/15 19:24:14  shenyuan
* initial version for Course Module (workable)
*
*
*/
function checkCourseCategory(form, actionVal)
{	
		
    if (form.txtSchoolId.value == '')
    {
    	
        form.txtCategoryId.length = 0;
        form.txtCategoryId.options[0] = new Option('', '');
        return;
    }
    form.target="frmCourseCategory";
    doSubmit(form, actionVal);
}

function validateCreate(form, actionVal)
{
    if (validateFields(form) != 0)
    {
        return;
    }
    document.frmCourseCreate.target="_self";
    doSubmit(form, actionVal);
}

function validateUpdate(form, actionVal)
{
    if (validateFields(form) != 0)
    {
        return;
    }
/*
    if (validateCourseRunFields(form) != 0)
    {
        return;
    }
*/
    document.frmCourseCreate.target="_self";
    doSubmit(form, actionVal);
}

function doPostpone(form, actionVal)
{
    if (validateCourseRunDate(form) != 0)
    {
        return;
    }
    var code = "window.opener.document.forms[0].txtStartDate.value=\'" + form.txtStartDate.value + "\'";
    eval(code);
    code = "window.opener.document.forms[0].txtEndDate.value=\'" + form.txtEndDate.value + "\'";
    eval(code);
    doSubmit(window.opener.document.forms[0], actionVal);
    window.close();
}

function validateFields(form)
{
    if (isBlank(form.txtCourseTitle.value) == 0)
    {
        alert("Please enter a Course Title");
        form.txtCourseTitle.focus();
        return 1;
    }

	// added by Andreas 18/06/2007
	if (isBlank(form.txtOnlineCourseTitle.value) == 0)
    {
        alert("Please enter an Online Course Title");
        form.txtOnlineCourseTitle.focus();
        return 1;
    }
	
    if (isBlank(form.txtCourseCode.value) == 0)
    {
        alert("Please enter a Course ID");
        form.txtCourseCode.focus();
        return 1;
    }

    if (isBlank(form.txtSchoolId.value) == 0)
    {
        alert("Please select a School");
        form.txtSchoolId.focus();
        return 1;
    }

    if (isBlank(form.txtCategoryId.value) == 0)
    {
        alert("Please select a Course Category");
        form.txtCategoryId.focus();
        return 1;
    }

    if (isBlank(form.txtType.value) == 0)
    {
        alert("Please select a Course Type");
        form.txtType.focus();
        return 1;
    }

    if (isBlank(form.txtSubType.value) == 0)
    {
        alert("Please select a Course Subtype");
        form.txtSubType.focus();
        return 1;
    }

/*  Commented by Shen Yuan as user requested
    if (isBlank(form.txtCourseGroup.value) == 0 || form.txtCourseGroup.value == 'N')
    {
        alert("Please select a Course Group");
        form.txtCourseGroup.focus();
        return 1;
    }
*/

    if (isBlank(form.txtDuration.value) == 0)
    {
        alert("Please enter a Duration");
        form.txtDuration.focus();
        return 1;
    }

    if (isBlank(form.txtSgdFee.value) != 0 && (isNumeric(form.txtSgdFee.value)!=0 || isDouble(form.txtSgdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtSgdFee.focus();
        return 2;
    }

    if (isBlank(form.txtUsdFee.value) != 0 && (isNumeric(form.txtUsdFee.value)!=0 || isDouble(form.txtUsdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtUsdFee.focus();
        return 2;
    }

    if (isBlank(form.txtImputedFee.value) != 0 && (isNumeric(form.txtImputedFee.value)!=0 || isDouble(form.txtImputedFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtImputedFee.focus();
        return 2;
    }

    if (isBlank(form.txtSecondSgdFee.value) != 0 && (isNumeric(form.txtSecondSgdFee.value)!=0 || isDouble(form.txtSecondSgdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtSecondSgdFee.focus();
        return 2;
    }

    if (isBlank(form.txtSecondUsdFee.value) != 0 && (isNumeric(form.txtSecondUsdFee.value)!=0 || isDouble(form.txtSecondUsdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtSecondUsdFee.focus();
        return 2;
    }

    if (isBlank(form.txtThirdSgdFee.value) != 0 && (isNumeric(form.txtThirdSgdFee.value)!=0 || isDouble(form.txtThirdSgdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtThirdSgdFee.focus();
        return 2;
    }

    if (isBlank(form.txtThirdUsdFee.value) != 0 && (isNumeric(form.txtThirdUsdFee.value)!=0 || isDouble(form.txtThirdUsdFee.value, 999999999.99)!=0))
    {
        alert("Please enter a valid Fee value, no decimal point is allowed");
        form.txtThirdUsdFee.focus();
        return 2;
    }

    if (form.txtFormType.value == '3' && isBlank(form.txtFormURL.value) == 0)
    {
        alert("Please enter a Form URL");
        form.txtFormURL.focus();
        return 3;
    }

    return 0;
}

function validateCourseRunFields(form)
{
/*  Commented by Shen Yuan at 18/12/2005, requested by Yang Lin at 16/12/2005
    if (isBlank(form.txtRunNo.value) == 0)
    {
        alert("Please enter a Running Number");
        form.txtRunNo.focus();
        return 1;
    }
*/

    if (isBlank(form.txtProposedAll.value) != 0 && isNumeric(form.txtProposedAll.value)!=0)
    {
        alert("Please enter a numeric value");
        form.txtProposedAll.focus();
        return 2;
    }

    if (isBlank(form.txtProposedLocal.value) != 0 && isNumeric(form.txtProposedLocal.value)!=0)
    {
        alert("Please enter a numeric value");
        form.txtProposedLocal.focus();
        return 2;
    }

    if (isBlank(form.txtProposedCaas.value) != 0 && isNumeric(form.txtProposedCaas.value)!=0)
    {
        alert("Please enter a numeric value");
        form.txtProposedCaas.focus();
        return 2;
    }

    return 0;
}

function validateCourseRunDate(form)
{
    if (isBlank(form.txtStartDate.value)==0)
    {
        alert("Please enter a Start Date");
        form.txtStartDate.focus();
        return 1;
    }
    else if (isValidDate(form.txtStartDate.value)!=0)
    {
        alert("Please enter a valid Start Date");
        form.txtStartDate.focus();
        return 1;
    }

    if (isBlank(form.txtEndDate.value)==0)
    {
        alert("Please enter an End Date");
        form.txtEndDate.focus();
        return 2;
    }
    else if (isValidDate(form.txtEndDate.value)!=0)
    {
        alert("Please enter a valid End Date");
        form.txtEndDate.focus();
        return 2;
    }

    if (after(form.txtEndDate.value, form.txtStartDate.value)==0)
    {
        alert("The End Date cannot be earlier than Start Date");
        form.txtEndDate.focus();
        return 3;
    }

    return 0;
}

function validateCourseRunCreate(form, actionVal)
{
    if (validateCourseRunFields(form) != 0)
    {
        return;
    }
    if (validateCourseRunDate(form) != 0)
    {
        return;
    }
    doSubmit(form, actionVal);
}

function validateCourseRunUpdate(form, actionVal)
{
    if (validateCourseRunFields(form) != 0)
    {
        return;
    }
    if (validateCourseRunDate(form) != 0)
    {
        return;
    }
    doSubmit(form, actionVal);
}

// added by Andreas 18/06/2007
function copyDown(destination, val)
{
	destination.value = val.toUpperCase();
}
