var brw_v = navigator.appVersion.charAt(0);
var brw_n = navigator.appName.charAt(0);
var iIE4 = false;
var iNN4 = false;
if((brw_v >= 4)&&(brw_n == "M"))iIE4 = true;
if((brw_v >= 4)&&(brw_n == "N"))iNN4 = true;

var Laymax = 7;  // the max value for number of displaying layers;

function SelectFactor(theForm) {

    var factor = theForm.ClinicalFactor;
    var n = theForm.CancerType.selectedIndex;

    set_default(factor);

    if (n == 0){
        cancer_factor0(factor);
    } else if (n == 1) {
        cancer_factor1(factor);
    } else if (n == 2) {
        cancer_factor2(factor);
    } else if (n == 3) {
        cancer_factor3(factor);
    } else if (n == 4) {
        cancer_factor4(factor);
    } else if (n == 5) {
        cancer_factor5(factor);
    } else if (n == 6) {
        cancer_factor6(factor);
    } else if (n == 7) {
        cancer_factor7(factor);
    }

}

function set_default(list) {
    list.selectedIndex = 0;
}

function cancer_factor0(list) {
    list.options.length = 1;
    list.options[0].text = '-------------------------';
    list.options[0].value = 0;
}

function cancer_factor1(list) {
    list.options.length = 9;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'ER';
    list.options[2].text = 'menopause';
    list.options[3].text = 'Tumor_size';
    list.options[4].text = 'tumor/normal';
    list.options[5].text = 'erbB2';
    list.options[6].text = 'His. Grade';
    list.options[7].text = 'LN_meta';
    list.options[8].text = 'p53';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
    list.options[3].value = 3;
    list.options[4].value = 4;
    list.options[5].value = 5;
    list.options[6].value = 6;
    list.options[7].value = 7;
    list.options[8].value = 8;
}

function cancer_factor2(list) {
    list.options.length = 5;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'distant metastasis';
    list.options[2].text = 'histology';
    list.options[3].text = 'lymphnode metastasis';
    list.options[4].text = 'tumor/normal';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
    list.options[3].value = 3;
    list.options[4].value = 4;
}

function cancer_factor3(list) {
    list.options.length = 3;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'cancer/non-tumor/normal';
    list.options[2].text = 'virus type';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
}

function cancer_factor4(list) {
    list.options.length = 7;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'sex';
    list.options[2].text = 'depth';
    list.options[3].text = 'histology';
    list.options[4].text = 'lymph node meta';
    list.options[5].text = 'major recurrence';
    list.options[6].text = 'stage';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
    list.options[3].value = 3;
    list.options[4].value = 4;
    list.options[5].value = 5;
    list.options[6].value = 6;
}

function cancer_factor5(list) {
    list.options.length = 11;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'gender';
    list.options[2].text = 'histology';
    list.options[3].text = 'lymph node';
    list.options[4].text = 'peritoneal dissem.';
    list.options[5].text = 'tumor/normal';
    list.options[6].text = 'age';
    list.options[7].text = 'invasion';
    list.options[8].text = 'location in stomach';
    list.options[9].text = 'stage';
    list.options[10].text = 'tumor size';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
    list.options[3].value = 3;
    list.options[4].value = 4;
    list.options[5].value = 5;
    list.options[6].value = 6;
    list.options[7].value = 7;
    list.options[8].value = 8;
    list.options[9].value = 9;
    list.options[10].value = 10;
}

function cancer_factor6(list) {
    list.options.length = 3;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'tumor/normal';
    list.options[2].text = 'tissure type';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
}

function cancer_factor7(list) {
    list.options.length = 4;
    list.options[0].text = '-------------------------';
    list.options[1].text = 'gross response';
    list.options[2].text = 'rec or neo';
    list.options[3].text = 'response';
    list.options[0].value = 0;
    list.options[1].value = 1;
    list.options[2].value = 2;
    list.options[3].value = 3;
}

function changeRadio(theForm, no) {
    theForm.P1[no].checked = true;
    ButtonOn(theForm, no);
}

function clearButton(theForm, no) {
    var factor = theForm.ClinicalFactor;
    if (no == 0) {
        theForm.CancerType.selectedIndex = 0;
        cancer_factor0(factor);
    }
    if (no == 1) {
        theForm.pvalue_input.value = "";
        theForm.qvalue_input.value = "";
        theForm.P1[0].checked = true;
        theForm.ClinicalFactor.disabled = false;
    }
}

function ButtonOn(theForm, no) {
    if (no == 0) {
        theForm.ClinicalFactor.disabled = false;
        SelectFactorForPvalueCheck(theForm);
    } else if (no == 1) {
        theForm.ClinicalFactor.selectedIndex = 0;
        theForm.ClinicalFactor.disabled = true;
    }
}

function CheckInput(theForm) {
    var pvalue = theForm.pvalue_input.value;
    var qvalue = theForm.qvalue_input.value;
    if (pvalue.match(/[^0-9|.]/) || qvalue.match(/[^0-9|.]/)) {
        alert("This form can be input decimal number.");
        return false;
    } else {
        return true;
    }
}

function SelectFactorForPvalueCheck(theForm) {

    var factor = theForm.ClinicalFactor;
    var n = theForm.CancerType.selectedIndex;

    if (n == 0){
        cancer_factor0(factor);
    } else if (n == 1) {
        cancer_factor1(factor);
    } else if (n == 2) {
        cancer_factor2(factor);
    } else if (n == 3) {
        cancer_factor3(factor);
    } else if (n == 4) {
        cancer_factor4(factor);
    } else if (n == 5) {
        cancer_factor5(factor);
    } else if (n == 6) {
        cancer_factor6(factor);
    } else if (n == 7) {
        cancer_factor7(factor);
    }

}


