var RfData = [
["Number", "SoilType", "MaxRainfall", "Minrainfall", "KValue", "TValue"],
[1, "Pierre - Samsil", 40, 55, 0.37, 2.5],
[2, "Bridgeport - Keith", 40, 55, 0.32, 5],
[3, "Canyon - Rosebud", 50, 80, 0.3, 3],
[4, "Keith - Rosebud", 40, 85, 0.3, 4],
[5, "Anselmo - Keith", 50, 90, 0.3, 5],
[6, "Mitchell - Tripp", 50, 75, 0.38, 5],
[7, "Dunday - Valentine", 50, 130, 0.16, 5],
[8, "Las - McCook", 60, 150, 0.35, 5],
[9, "Coly - Keith", 75, 100, 0.38, 5],
[10, "Holt - Valentine", 70, 90, 0.18, 4],
[11, "Boyd - Reliance", 85, 125, 0.35, 3.5],
[12, "Jansen - Thurman", 80, 115, 0.23, 4.5],
[13, "Loup - Valentine", 90, 125, 0.18, 4],
[14, "Thurman - Valentine", 115, 140, 0.16, 5],
[15, "Crofton - Moody", 125, 160, 0.38, 5],
[16, "Crofton - Nora", 125, 150, 0.38, 5],
[17, "Coly - Ulysses", 80, 115, 0.38, 5],
[18, "Hall - Wood River", 80, 135, 0.38, 3.5],
[19, "Leshara - Platte", 125, 150, 0.3, 5],
[20, "Marshall -Sharpsburg", 140, 200, 0.3, 5],
[21, "Marshall - Monona", 150, 180, 0.28, 5],
[22, "Hayne - Luton", 140, 200, 0.3, 5],
[23, "Coly - Holdrege", 85, 150, 0.38, 5],
[24, "Hastings - Holdrege", 110, 130, 0.32, 5],
[25, "Holdrege - Kenesaw", 115, 135, 0.32, 5],
[26, "Crete - Hastings", 125, 160, 0.35, 5],
[27, "Sharpsburg - Shelby", 145, 155, 0.3, 5],
[28, "Crete - Filmore", 130, 165, 0.37, 4],
[29, "Crete - Wymore", 150, 175, 0.37, 4],
[30, "Pawnee - Wymore", 160, 200, 0.35, 3],
[31, "Hedville - Lancaster", 160, 170, 0.24, 2]
];
var CData=[
["CropNumber,CropSystem",0,10,20,30,40,50,60,70,80,90],
[1,"Continious Corn or Sorghum",0.3,0.28,0.24,0.2,0.16,0.14,0.11,0.08,0.06,0.04],
[2,"-Soybean Rotation",0.35,0.32,0.28,0.25,0.21,0.18,0.14,0.11,0.07,0.04],
[3,"Continious Wheat",0.2,0.23,0.2,0.17,0.14,0.12,0.08,0.06,0.04,0.03],
[4,"Wheat after Fallow",0.2,0.21,0.19,0.17,0.14,0.12,0.08,0.06,0.04,0.03],
[5,"Corn/Sorghum after Wheat",0.3,0.28,0.26,0.2,0.16,0.14,0.11,0.08,0.06,0.04],
[6,"Continious Soybean",0.4,0.37,0.35,0.3,0.25,0.22,0.2,0.15,0.1,0.08],
[7,"Vegetables/Beets",0.3,0.28,0.24,0.2,0.16,0.14,0.11,0.08,0.06,0.04],
[8,"Grass and Legume mix",0.3,0.25,0.21,0.17,0.13,0.1,0.07,0.04,0.03,0.02],
[9,"AlfAlfa",0.3,0.29,0.25,0.21,0.17,0.13,0.09,0.05,0.03,0.02],
[10,"Bare Soil",1,1,1,1,1,1,1,1,1,1]
];
//default P factor to 1
$("#Results_PFactor").html(1);
//******************************************************* SELECCT AND SET SOIL FACTOR ***********************************************************
$("#soilSelect").change(function() {
var v = $(this).val();
$(".R-min").html(RfData[v][2]);
$(".R-max").html(RfData[v][3]);
$(".KFactor_SoilType,.soilType").html(RfData[v][1]);
$(".KFactor_KFactor,#Results_KFactor").html(RfData[v][4]);
$(".KFactor_TValue,#Results_TolerableSoilLoss").html(RfData[v][5]);
$("#soilTypeResult").html(RfData[v][1]);
});
//******************************************************* USER SETS R-FACT (see RfData above) ****************************************************************
$("#R-Factor-input").blur(function() {
$(".KFactor_RFactor").html($(this).val());
$("#Results_RFactor").html($(this).val());
});
//******************************************************* USER SETS LS FACTOR *********************************************************************************
$(".ls-SlopeLength,.ls-SlopeSteepness").keyup(function() {
if($(".ls-SlopeLength").val() != "" && $(".ls-SlopeSteepness").val() != "") {
var l2 = $(".ls-SlopeSteepness").val();
x = 0;
if(l2 < 1) {
x = 0.2;
} else if(l2 >= 1 && l2 < 3) {
x = 0.3;
} else if(l2 >= 3 && l2 < 5) {
x = 0.4;
} else if(l2 >= 5) {
x = 0.5;
}
var LS = Math.pow($(".ls-SlopeLength").val() / 72.6, x) * (0.0065 * Math.pow(l2, 2) + (0.0456 * l2) + 0.065);
$("#ls-factor,#Results_LSFactor").html(LS.toFixed(4));
$("#Results_SlopeLength").html($(".ls-SlopeLength").val());
$("#Results_SlopeSteepness").html($(".ls-SlopeSteepness").val());
}
});
//******************************************************* CFACTOR SELECTION ***********************************************************
$("#cFactor_CroppingSequenceSelect").change(function () {
$("#Results_Crop").html($(this).find("option:selected").text());
$("#cFactor_CropSystem").html($(this).find("option:selected").text());
cxjsC();
});
$("#cFactor_TillageSelect").change(function () {
$("#cFactor_TillageEffect").html($(this).find("option:selected").text());
$("#cFactor_TillageEffectResult").html($(this).find("option:selected").attr("a-v"));
//Populate residue values
var cselect;
if($(this).val()=="1"){
cselect=' ';
}else if($(this).val()=="2"){
cselect=' ';
}else{
cselect=' ';
}
$("#cFactor_CoverSelect").html(cselect);
cxjsC();
});
$("#cFactor_CoverSelect").change(function () {
$("#cFactor_percentCover").html($(this).find("option:selected").text());
$("#cFactor_result1").html(CData[$("#cFactor_CroppingSequenceSelect").val()][$(this).val()]);
$("#Results_Cover").html($(this).find("option:selected").text());
cxjsC();
});
$("#cFactor_YieldSelect").change(function () {
$("#cFactor_ExpectedYield").html($(this).find("option:selected").text()) ;
$("#cFactor_ExpectedYieldResult").html($(this).val());
cxjsC();
});
$("#cFactor_PrevCropSelect").change(function () {
$("#cFactor_PreviousCrop").html($(this).find("option:selected").text()) ;
$("#cFactor_PreviousCropResult").html($(this).val());
var c_fa=parseFloat($("#cFactor_result1").html())*parseFloat($("#cFactor_TillageEffectResult").html())*parseFloat($("#cFactor_ExpectedYieldResult").html())*parseFloat($("#cFactor_PreviousCropResult").html());
console.log(parseFloat($("#cFactor_result1").html())+" :"+parseFloat($("#cFactor_TillageEffectResult").html())+" :"+parseFloat($("#cFactor_ExpectedYieldResult").html())+" :"+parseFloat($("#cFactor_PreviousCropResult").html())+" :");
$("#cFactor_AdjustedCFactor,#Results_CFactor").html(c_fa.toFixed(5)); //relust 选项显示C选项卡的结果
});
function cxjsC () {
$("#cFactor_PreviousCrop").html($("#cFactor_PrevCropSelect").find("option:selected").text()) ;
$("#cFactor_PreviousCropResult").html($("cFactor_PrevCropSelect").val());
var c_fa=parseFloat($("#cFactor_result1").html())*parseFloat($("#cFactor_TillageEffectResult").html())*parseFloat($("#cFactor_ExpectedYieldResult").html())*parseFloat($("#cFactor_PreviousCropResult").html());
console.log(parseFloat($("#cFactor_result1").html())+" :"+parseFloat($("#cFactor_TillageEffectResult").html())+" :"+parseFloat($("#cFactor_ExpectedYieldResult").html())+" :"+parseFloat($("#cFactor_PreviousCropResult").html())+" :");
$("#cFactor_AdjustedCFactor,#Results_CFactor").html(c_fa.toFixed(5));
if(isNaN(c_fa)){
$("#cFactor_AdjustedCFactor,#Results_CFactor").html("---");
}
}
//******************************************************************** P FACTOR ADJUSTMENTS *************************************************************************
$("#PFactor_PracticeSelection").change(function () {
$("#Results_Practice,#pFactor_Practice").html($(this).find("option:selected").attr("v"));
var slope=parseFloat($(".ls-SlopeSteepness").val());
var pz="";
if($(this).val()=="0.8"){
if(slope<2.5){
pz=0.6;
}else if(slope >= 2.5&& slope < 8.5){
pz=0.5;
}else if(slope >= 8.5&& slope < 12.5){
pz=0.6;
}else if(slope >= 12.5&& slope < 16.5){
pz=0.7;
}else if(slope >= 16.5&& slope < 20.5){
pz=0.8;
}else if(slope >= 20.5&& slope <=25){
pz=0.9;
}
}else if($(this).val()=="0.4"){
if(slope<2.5){
pz=0.3;
}else if(slope >= 2.5&& slope < 8.5){
pz=0.25;
}else if(slope >= 8.5&& slope < 12.5){
pz=0.3;
}else if(slope >= 12.5&& slope < 16.5){
pz=0.35;
}else if(slope >= 16.5&& slope < 20.5){
pz=0.4;
}else if(slope >= 20.5&& slope <=25){
pz=0.45;
}
}
else if ($(this).val() == "1"){
pz = 1;
}
else {pz = 1;}
$("#pFactor_PracticeFactor,#cFactor_PreviousCropResult").html(pz);
$("#pFactor_Terraces,#pFactor_TerracesFactor").html("");
$("#pFactor_AdjustedPFactor").html(1 * pz);
});
$("#PFactor_TerraceSelection").change(function () {
if($(this).val()=="1"){
$("#PFactor_TerraceInterval").html(' ');
}else if($(this).val()=="2"){
$("#PFactor_TerraceInterval").html(' ');
}else{
$("#PFactor_TerraceInterval").html('');
}
});
$("#PFactor_TerraceInterval").change(function () {
$("#pFactor_Terraces").html($(this).find("option:selected").text());
$("#pFactor_TerracesFactor").html($(this).val());
var b=($(this).val()*parseFloat($("#pFactor_PracticeFactor").html()));
$("#pFactor_AdjustedPFactor").html(b.toFixed(2));
$("#Results_PFactor").html(b.toFixed(2));
});
//******************************************************* CALCULATE RESULTS *******************************************************************
$("#resultk").click(function () {
//P-factor defaults to 1
var pz=1;
if(isNaN(parseFloat($("#pFactor_AdjustedPFactor").html()))){
var pz=1;
}else{
pz=parseFloat($("#pFactor_AdjustedPFactor").html());
}
var a=parseFloat($("#R-Factor-input").val())*parseFloat($(".KFactor_KFactor").html())*parseFloat($("#ls-factor").html())*parseFloat($("#cFactor_AdjustedCFactor").html())*pz;
if(isNaN(a)){
$("#Results_PredictedSoilLoss").html("Please select variables to calculate value");
}else{
$("#Results_PredictedSoilLoss").html(a.toFixed(3) + " tons/acre");
}
console.log(parseFloat($("#R-Factor-input").val())+" : "+parseFloat($("#KFactor_TValue").html())+" : "+parseFloat($("#ls-factor").html())+" : "+parseFloat($("#cFactor_AdjustedCFactor").html())+" : "+parseFloat($("#pFactor_AdjustedPFactor").html()));
})