var alert_id = "";
function clearForm()
{
    document.optionForm.description.value = "";
    document.optionForm.min_value.value = "";
    document.optionForm.max_value.value = "";
    document.optionForm.max_answer.value = "";
    document.optionForm.min_answer.value = "";
    document.optionForm.rows.value = "5";
    document.optionForm.cols.value = "5";
    document.optionForm.problemType.selectedIndex = 0;
    document.optionForm.font_size.selectedIndex = 1;
    document.optionForm.division_answers.selectedIndex = 0;
    document.getElementById('division_answers').disabled = true;
    document.getElementById('include_title').checked = true;
    document.getElementById('no_negative').checked = true;
    document.getElementById('no_negative').disabled = true;
    document.getElementById('num_problem').checked = false;
    document.getElementById('show_horizontally').checked = false;
    document.getElementById('two_decimal').checked = false;
    document.getElementById('large_space').checked = false;
    
}
function onChangeDivisionAnswer(id)
{
    if(id == 1)
    {
        document.getElementById('two_decimal').checked = false;
        document.getElementById('two_decimal').disabled = true;
    }else{
        document.getElementById('two_decimal').disabled = false;
    }
}
function changeDisplayProperty(value)
{
    document.getElementById('no_negative').checked = true;
    document.getElementById('no_negative').disabled = true;
    document.getElementById('division_answers').disabled = true;
    document.getElementById('division_answers').selectedIndex = 0;
    onChangeDivisionAnswer(0);

    if(value == 'divide' || value == 'multiply_divide')
        document.getElementById('division_answers').disabled = false;
    if(value == 'sub' || value == 'add_sub')
        document.getElementById('no_negative').disabled = false;
}

function hideAlert(id)
{
    if(alert_id.indexOf(id) > -1 && document.getElementById('alert_text').style.display != "none")
        toggleNavCal('alert_text');
}
function showAlert(text)
{
    if(document.getElementById('alert_text').style.display == "none")
    {
        document.getElementById('alert_text').innerHTML = text;
        toggleNavCal('alert_text');
    }
}
function toggleNavCal(obj)
{
    if ( document.getElementById(obj).style.display == 'none' )
    {
        new Effect.Appear(obj);
    }
    else
    {
        new Effect.Fade(obj);
    }
}

function evalCreate()
{
    if(document.optionForm.min_value.value == "")
    {
        showAlert('*Please input the minimum value of input number.');
        alert_id = "min_value";
        document.optionForm.min_value.focus();
        return;
    }else if(isNaN(document.optionForm.min_value.value))
    {
        showAlert('*You must input numeric value.');
        alert_id = "min_value";
        document.optionForm.min_value.focus();
        document.optionForm.min_value.select();
        return;
    }
    if(document.optionForm.max_value.value == "")
    {
        showAlert('*Please input the maximum value of input number.');
        alert_id = "max_value";
        document.optionForm.max_value.focus();
        return;
    }else if(isNaN(document.optionForm.max_value.value))
    {
        showAlert('*You must input numeric value.');
        alert_id = "max_value";
        document.optionForm.max_value.focus();
        document.optionForm.max_value.select();
        return;
    }
    if(parseInt(document.optionForm.min_value.value) >  parseInt(document.optionForm.max_value.value))
    {
        showAlert('*Max value must be bigger than min value.');
        alert_id = "max_value:min_value";
        document.optionForm.min_value.focus();
        document.optionForm.min_value.select();
        return;
    }
    if(isNaN(document.optionForm.min_answer.value))
    {
        showAlert('*You must input numeric value.');
        alert_id = "min_answer";
        document.optionForm.min_answer.focus();
        document.optionForm.min_answer.select();
        return;
    }
    if(isNaN(document.optionForm.max_answer.value))
    {
        showAlert('*You must input numeric value.');
        alert_id = "max_answer";
        document.optionForm.max_answer.focus();
        document.optionForm.max_answer.select();
        return;
    }
    if(document.optionForm.min_answer.value != "" && document.optionForm.max_answer.value != "" && parseInt(document.optionForm.min_answer.value) >  parseInt(document.optionForm.max_answer.value))
    {
        showAlert('*Max value must be bigger than min value.');
        alert_id = "max_answer:min_answer";
        document.optionForm.min_answer.focus();
        document.optionForm.min_answer.select();
        return;
    }
    if(document.optionForm.rows.value == "")
    {
        showAlert('*Please input rows.');
        alert_id = "rows";
        document.optionForm.rows.focus();
        return;
    }else if(isNaN(document.optionForm.rows.value))
    {
        showAlert('You must input numeric value.');
        alert_id = "rows";
        document.optionForm.rows.focus();
        document.optionForm.rows.select();
        return;
    }else if(parseInt(document.optionForm.rows.value) > 5)
    {
        showAlert('*The rows must be small than 5.');
        alert_id = "rows";
        document.optionForm.rows.focus();
        document.optionForm.rows.select();
        return;
    }
    if(document.optionForm.cols.value == "")
    {
        showAlert('*Please input cols.');
        alert_id = "cols";
        document.optionForm.cols.focus();
        return;
    }else if(isNaN(document.optionForm.cols.value))
    {
        showAlert('*You must input numeric value.');
        alert_id = "cols";
        document.optionForm.cols.focus();
        document.optionForm.cols.select();
        return;
    }else if(parseInt(document.optionForm.cols.value) > 5)
    {
        showAlert('*The cols must be small than 5.');
        alert_id = "cols";
        document.optionForm.cols.focus();
        document.optionForm.cols.select();
        return;
    }
    document.optionForm.submit();
}


