﻿//
// init
//
$(document).ready(function() {

    // tabs #1
    $("#ulTab1.tabHorz a").click(function() {
        $("#ulTab1.tabHorz a").removeClass("tabFocus");
        $(this).addClass("tabFocus");
        return bcChangeTab1($(this).attr("rel"));
    });

    // tabs #2
    $("#ulTab2.tabHorz2 a").click(function() {
        $("#ulTab2.tabHorz2 a").removeClass("tabFocus");
        $(this).addClass("tabFocus");
        return bcChangeTab2($(this).attr("rel"));
    });    

    // set current tabs + store click state in hidden field
    $("#ulTab1.tabHorz a[rel='" + iTabIdx1 + "']").addClass("tabFocus");
    $("#ulTab2.tabHorz2 a[rel='" + iTabIdx2 + "']").addClass("tabFocus");
    $("#hfTabIdx1").attr("value", iTabIdx1);
    $("#hfTabIdx2").attr("value", iTabIdx2);

    // area loc: attach event 
    $(bcLocationID).change(function() {
        $(bcLocationID + " option:selected").each(function() {
            bcUpdateFlagTelCode($(this).val(), spnTelCodeID, imgFlagID);
        });
    });

    // area loc: set default 
    bcUpdateFlagTelCode($(bcLocationID + " option:selected").val(), spnTelCodeID, imgFlagID);

    // units: attach event
    $(ddlUnits2).change(function() {
        $(ddlUnits2 + " option:selected").each(function() {
            bcSetHeightList($(this).val());
        });
    });

    // units: set default 
    bcSetHeightList($(ddlUnits2).val());

    // citizen spotlight
    $("#aCSMore").click(function() {
        $("#divCSText").hide();
        $("#divCSText").css({ "height": "100%", "overflow": "" });
        $("#divCSText").fadeIn(250, function() { bcUnfilterIE(this) });
        $(this).hide();
        return false;
    });

});


//
// change tab #1
//
function bcChangeTab1(iIdx) {
    switch (iIdx) {
        case "2":
        {
            $(pnlPage0).hide();
            $(pnlPage1).hide();
            $(pnlPage2).show();
            $(divBRow).hide();
            break;
        }    
        case "1": 
        {
            $(pnlPage0).show();
            $(pnlPage1).show();
            $(pnlPage2).hide();
            $(divBRow).show();                                
            break;
        }
        default:
        {
            iIdx = "0";
            $(pnlPage0).show();
            $(pnlPage1).hide();
            $(pnlPage2).hide();
            $(divBRow).show();
        }
    }
    $("#hfTabIdx1").attr("value", iIdx);
    return false;
}


//
// change tab #2
//
function bcChangeTab2(iIdx) {
    switch (iIdx) {
        case "4":
            {
                $(divSubPage0).hide();
                $(divSubPage1).hide();
                $(divSubPage2).hide();
                $(divSubPage3).hide();
                $(divSubPage4).show();
                break;             
            }
        case "3":
            {
                $(divSubPage0).hide();
                $(divSubPage1).hide();
                $(divSubPage2).hide();
                $(divSubPage3).show();
                $(divSubPage4).hide();
                break;             
            }
        case "2":
            {
                $(divSubPage0).hide();
                $(divSubPage1).hide();
                $(divSubPage2).show();
                $(divSubPage3).hide();
                $(divSubPage4).hide();                
                break;
            }
        case "1":
            {
                $(divSubPage0).hide();
                $(divSubPage1).show();
                $(divSubPage2).hide();
                $(divSubPage3).hide();
                $(divSubPage4).hide();   
                break;
            }
        default:
            {
                iIdx = "0";
                $(divSubPage0).show();
                $(divSubPage1).hide();
                $(divSubPage2).hide();
                $(divSubPage3).hide();
                $(divSubPage4).hide();   
            }
    }
    $("#hfTabIdx2").attr("value", iIdx);
    return false;
}


//
// save tab
//
function bcSaveTab2() {
    $.getJSON("../_api/citizens_json.ashx?method=110&ts="+(new Date()).getTime()); 
    return true;                                    
}


//
// get ft-in
//
function bcGetFtIn(sIn) {
    var sResult = "";
    var iIn = parseInt(sIn);                        
    if (!isNaN(iIn) && (iIn > 0)) {
        sResult = Math.floor(iIn/12) + "' ";
        if ((iIn % 12) != 0) sResult += (iIn % 12) + "\"";
    }
    return sResult;
}


//
// get cm
//
function bcGetCm(sIn) {
    var sResult = "";
    var iIn = parseInt(sIn);                        
    if (!isNaN(iIn) && (iIn > 0)) {
        sResult = Math.round(iIn / 0.393709);
    }
    return sResult;
}


//
// set height list
//
function bcSetHeightList(sUnits) {
    if (sUnits == "0") {
        $(ddlHeight1 + " option").each(function() {
            $(this).text(bcGetFtIn( $(this).val()));
        });
        $(ddlHeight2 + " option").each(function() {
            $(this).text(bcGetFtIn( $(this).val()));
        });                                    
    } else {
        $(ddlHeight1 + " option").each(function() {
            $(this).text(bcGetCm( $(this).val()));
        });
        $(ddlHeight2 + " option").each(function() {
            $(this).text(bcGetCm($(this).val()));
        });                                                                    
    }
}


//
// del search
//
function bcDelSearch(oA, iSID) {
    if ((iSID > 0) && (oA != null)) {
        $(oA).parent().parent().css({ 'text-decoration': 'line-through' });
        $(oA).hide();
        $.getJSON("../_api/citizens_json.ashx?method=100&sid=" + iSID + "&ts=" + (new Date()).getTime(), function(json, textStatus) {
            var iStatus = parseInt(json[0].status);
            if (iStatus > 0) $(oA).parent().parent().fadeOut(300); //hide row        
        });
    }
    return false;
}