﻿
$(function() {
    $("#tdTabPage1").addClass("tab_selected");
    $('#imgValidateLocation').hide();


    $("#lnkLanguage").hover(
	            function() {
	                $("#divLanguage").fadeIn(500);
	            },
	            function() {
	                setTimeout("checkHover()", 4000);
	            }
	         );

    $("#lnkSubmitAnotherCase").click(
	    function() {
	        location = 'create-case.aspx?ReqType=SubmitAnother';
	    }

	 )

    $("#lnkViewAnotherCase").click(
	    function() {
	        $("#divShow").hide();
	        $("#divGet").show();
	        $("#txtGet_CaseId").attr("value", "");
	        $("#txtGet_CaseAccessCode").attr("value", "");
	    }

	 )


    $("#lnkSubmitViewCase").click(
	    function() {
	        TabPage2Clicked();
	    }
	 )

    $("#tdTabPage1").click(
	    function() {
	        TabPage1Clicked();
	    }
	 )

    $("#tdTabPage2").click(
	    function() {
	        TabPage2Clicked();
	    }
	 )

    $("#tdTabPage3").click(
	            function() {
	                removeTabClass();
	                $("#tdTabPage3").addClass("tab_selected");
	            }
	 )

    $(".languageLbClass").hover(
	            function() { $(this).addClass("languageLbClass_hover") }
	            ,
	            function() { $(this).removeClass("languageLbClass_hover") }
        );

    $("#imgTelephone").mousedown(function() {

        $.weeboxs.open('#frmCallMeBack',
	                {
	                    title: $("#hidTran_CallMeBack").attr("value"),
	                    okBtnName: $("#btnSubmit").attr("value"),
	                    cancelBtnName: $("#hidTran_Cancel").attr("value"),
	                    width: 400,
	                    height: 180,
	                    contentChange: true,
	                    onok: onCallbackDiaolgOk,
	                    oncancel: onCallbackDialogCancel
	                });

        $("#txtCallbackTel").attr("value", getTelephoneTextarea());
        $("#txtCallbackQuestion").attr("value", getDetailTextarea());




    });

  
    //onGenCaptcha();

})
    function removeTabClass() {
        $("#tdTabPage1").removeClass("tab_selected");
        $("#tdTabPage2").removeClass("tab_selected");
        $("#tdTabPage3").removeClass("tab_selected");
    }

    function hideTabPage() {
        $("#pagediv_CreateCase").hide();
        $("#pagediv_ViewCase").hide();
    }

    function TabPage1Clicked() {

            

    
        //If this tab is already selected, just return
        if ($("#tdTabPage1").attr('class') != 'tab_normal') return;

 
        
     
        

        

        //If user just add a comment to case, we need to reload the page       
        if ($('#hidAddCaseCommentDone').val() == '1') {
            $('#btnReset').click();
            return;

        }
        
        removeTabClass();
        hideTabPage();
        $("#tdTabPage1").addClass("tab_selected");
        $("#pagediv_CreateCase").show();

        //If the page is just showing the result of case submit, we don't need to do any further element hide or show        
        var sDisplayStaus_SubmitResult_Success = document.getElementById('divCaseSubmitResult_Success').style.display.toLowerCase();
        var sDisplayStaus_SubmitResult_Fail = document.getElementById('divCaseSubmitResult_Fail').style.display.toLowerCase();
        if (sDisplayStaus_SubmitResult_Success != 'none' || sDisplayStaus_SubmitResult_Fail != 'none') {

            return;
        }       

        $("#divCaseSubmitResult_Success").hide();
        $("#divCaseSubmitResult_Fail").hide();
        $("#divCreateCase").show();

        hideshowCallerDetails();
        $('#btnSubmit').focus();



        
    }
    
    function TabPage2Clicked(){
         removeTabClass();
         hideTabPage();
         $("#tdTabPage2").addClass("tab_selected");
         $("#pagediv_ViewCase").show();
         $('#btnGet').focus();
    }
    

   function checkHover() {
       $("#divLanguage").fadeOut(500);
   }


   function onCallbackDiaolgOk() {

       var telValue = $("#txtCallbackTel").attr("value").replace(/(^\s*)|(\s*$)/g, "");
       var detailValue = $("#txtCallbackQuestion").attr("value").replace(/(^\s*)|(\s*$)/g, "");
       if(telValue=="" || detailValue==""){
           alert($("#hidTran_FillAllFields").attr("value"));           
        }
       else if(telValue.length>150){
            alert($("#hidTran_MaxlengthOver150").attr("value"));
        }
       else if(detailValue.length>2000){
            alert($("#hidTran_MaxlengthOver2000").attr("value"));   
       }
       else {
            //save the value before close dialog
           $("#hidCallbackTelephone").attr("value", telValue);
           $("#hidCallbackDetails").attr("value", detailValue);

           //Set organization flag to true if organization is specified
           if (ge('frmOrganization').value != '') {
               ge('frmOrganizationFlag').value = 'True';
           } else {
               ge('frmOrganizationFlag').value = 'False';
           }

           //$.weeboxs.close();
           $('#btnCallMeBackSubmit').click();

       }

   }

   function onCallbackDialogCancel() {
   
       $("#txtCallbackTel").attr("value","");
       $("#txtCallbackQuestion").attr("value", "");

//       var telValue = $("#txtCallbackTel").attr("value");
//       var detailValue = $("#txtCallbackQuestion").attr("value");
//       alert(telValue);
//       alert(detailValue);
       $.weeboxs.close();       
       
   }
   

    // get the display text content in call back dialog telephone area.
   function getTelephoneTextarea() {
       var sRet = "";
       var objChkAnonymous = ge(_ANONYMOUS_CHECK);
       if (objChkAnonymous.checked == true ) {
               return "";
      }
           
       var telHome = $("#frmTelephone").attr("value");
       var telWork = $("#frmWork").attr("value");
       var telMobile = $("#frmMobile").attr("value");

       if (telHome != "") { sRet += telHome; sRet += "; " }
       if (telWork != "") { sRet += telWork; sRet += "; " }
       if (telMobile != "") { sRet += telMobile; sRet += "; " }
       return sRet;
       
   }
   
   // get the display text contnet in call back dialog detail area.
   function getDetailTextarea() {
       var sRet = "";
       var elementContent = "";
       var aryLabel = $(".emptyCss");

       var objChkAnonymous = ge(_ANONYMOUS_CHECK);

       
       for (j = 0; j < aryLabel.length; j++) {
           elementContent = "";

           //if anonymous caller is checked, we no longer need caller infomation for call back detail
           if (objChkAnonymous.checked == true && isCtrlBelongToCallerinfo(aryLabel[j].id)) {
               continue;
           }

           if ((getRadioBoxValue("frmLocationType") != "address") && aryLabel[j].id == "lbfrmIncUnit") {
               continue;
           }
           
           if (aryLabel[j].id == "lbfrmIncCity") {
               if (getRadioBoxValue("frmLocationType") == "address" || getRadioBoxValue("frmLocationType") == "intersection") {
                   var ddl = document.getElementById('frmIncCity');
                   elementContent = ddl.options[ddl.selectedIndex].text;
               }
           }
           else {       
               elementContent = $("#" + aryLabel[j].id.substring(2)).attr("value");
           }

           if (aryLabel[j].id == "lbfrmIncCaseType") elementContent=$("#hidSelectedCaseType").val();
           if (elementContent != "" && elementContent != "- select one -")
           {
               sRet += aryLabel[j].innerText;
               sRet += " ";
               sRet += elementContent;
               sRet += "\n"; 
           }
           
         
       }
       return sRet;
   }

   function handleLanguageChange(sLanguage) {
       $("#hidSelectedLanguage").attr("value", sLanguage);
       alert( $("#hidSelectedLanguage").attr("value"));
       $("#hidbtn_ChangeLanguage").click();
   }

   function isIE() { //ie? 
       if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1)
           return true;
       else
           return false;
   }

   if (!isIE()) { //firefox innerText define
       HTMLElement.prototype.__defineGetter__("innerText", function() {var anyString = ""; var childS = this.childNodes; for (var i = 0; i < childS.length; i++) {if (childS[i].nodeType == 1) anyString += childS[i].innerText; else if (childS[i].nodeType == 3)anyString += childS[i].nodeValue;} return anyString; } );
       HTMLElement.prototype.__defineSetter__("innerText", function(sText) { this.textContent = sText; });
   }

   function getRadioBoxValue(radioName) {
       var obj = document.getElementsByName(radioName);             
       for (i = 0; i < obj.length; i++) {
           if (obj[i].checked) {
               return obj[i].value;
           }
       }
       return "undefined";
   }
   
   
   function isCtrlBelongToCallerinfo(sCtrlID) {
       var CallerInfoCtrlID = "lbfrmFirstName|lbfrmLastName|lbfrmEmail|lbfrmOrganization|lbfrmTelephone|lbfrmWork|lbfrmFax|lbfrmMobile|lbfrmStreetNumber|lbfrmStreetName|lbfrmUnitNumber|lbfrmCity|lbfrmState|lbfrmCountry|lbfrmPostal|";
       //alert(CallerInfoCtrlID + "      " + sCtrlID);
       return containsCase(CallerInfoCtrlID, sCtrlID, false)
}


//string:original string
//substr:string to look up
//isIgnoreCase:ignore case
 function containsCase(ostring,substr,isIgnoreCase){
    if(isIgnoreCase)
    {
        ostring = ostring.toLowerCase();
        substr=substr.toLowerCase();
    }
     var startChar=substr.substring(0,1);
     var strLen=substr.length;
     for (var j = 0; j < ostring.length - strLen; j++)
         {
             if (ostring.charAt(j) == startChar)
             {
                 if (ostring.substring(j, j + strLen) == substr)
                   {
                         return true;
                   }   
             }
         }
         return false;
}



//--------show category and case type--------//
$(function() {
    $('#frmIncCategory').change(function() { OnCategorySelected(); });
    $('#frmIncCaseType').change(function() { OnCaseTypeSelected(); });
    $('#btnSubmit').click(function() { OnbtnSubmitClicked(); });
    $('#frmAnonymous').click(function() { OnAnonymoustClicked(); });
    $('#imgCategoryChanged').hide();
    $('#imgCaseTypeChanged').hide();
    HidLocationUdefAttachmentDiv();
})

function OnbtnSubmitClicked() {
    var iCount = $('#hidDetectPageRefresh').val() + 1;
    $('#hidDetectPageRefresh').val(iCount);
}

function IsCaseTypeValid() {
    return CheckCategoryInput() & CheckCaseTypeInput() & SaveCaseUdefValue();
}

function CheckCategoryInput() {
    var bReturn = true;
    var bShowCategoryList = $('#hidShowCategoryList').val();
    if (bShowCategoryList == '1') {
        document.getElementById('frmIncCategoryError').style.display = 'none';
        var iCategoryIndex = document.getElementById('frmIncCategory').selectedIndex;
        if (iCategoryIndex < 1) {
            document.getElementById('frmIncCategoryError').style.display = 'block';
            bReturn = false;
        }
    }
    return bReturn;
}

function CheckCaseTypeInput() {
    document.getElementById('frmIncCaseTypeError').style.display = 'none';
    var oSelect = document.getElementById('frmIncCaseType');
    if (oSelect.options.length == 0) {
        document.getElementById('frmIncCaseTypeError').style.display = 'block';
        return false;
    }
    if (oSelect.selectedIndex < 1) {
        document.getElementById('frmIncCaseTypeError').style.display = 'block';
        return false;
    }
    return true;
}

function OnCategorySelected() {
    $('#imgValidateLocation').hide();
    $('#lbCategoryDescription').text('');
    $('#lbCaseTypeDescription').text('');
    if (CheckCategoryInput()) {
        document.getElementById('frmIncCaseType').options.length = 0;

        var sSelectedCategory = $('#frmIncCategory').val();
        $('#hidSelectedCategory').val(sSelectedCategory);

        $('#imgCategoryChanged').show();
        try {
            GetCaseTypeList(sSelectedCategory);
        }
        catch (error) {
            $('#imgCategoryChanged').hide();
        }        
    }
}

function OnAnonymoustClicked() {


    var bShowCategoryList = $('#hidShowCategoryList').val();
    $('#lbCategoryDescription').text('');
    $('#lbCaseTypeDescription').text('');
    $('#divUdefContainer').hide();
    $('#divLocationContainer').hide();
    document.getElementById('frmIncCaseType').options.length = 0;
    if (bShowCategoryList == '1') {
        LoadDefaultCategoryCaseType();
    } else {
        $('#imgCaseTypeChanged').show();
        try {
            var sDefaultCaseType = $('#hidDefaultCaseType').val();
            GetCaseTypeList('', sDefaultCaseType);

        }
        catch (error) {
            $('#imgCaseTypeChanged').hide();
        }
    }

    var objChkAnonymous = document.getElementById('frmAnonymous');

    if (objChkAnonymous.checked == true) {
        $('#div_frmCity').hide();
        $('#div_frmCountry').hide();
        $('#div_frmState').hide();
    
    }
    else {
        $('#div_frmCity').show();
        $('#div_frmCountry').show();
        $('#div_frmState').show();
    }
     
}

function HidLocationUdefAttachmentDiv() {
    $('#divUdefContainer').hide();
    $('#divLocationContainer').hide();
    $('#pnlUploadAttachment').hide();
}


function GetCaseTypeList(sSelectedCategory, sDefaultCaseType) {

    HidLocationUdefAttachmentDiv();
    try {
        $.get('show-casetype.aspx', { ReqType: 'ShowCaseTypeList', SelectedCategory: sSelectedCategory, LanguageName: $('#hidSelectedLanguage').val() }, function(data) {
            if (data) {
                var objResult = eval('(' + data.split('|')[0] + ')');
                if (objResult.result == '1') {
                    for (var i = 0; i < objResult.CaseTypeNameArray.length; i++) {
                        var bToAdd = true;
                        if (objResult.AllowAnonymous[i] == '0' && $('#hidIsAnoyCase').val() == "1") {
                            bToAdd = false;
                        }
                        if (bToAdd) {
                            document.getElementById('frmIncCaseType').options.add(new Option(unescape(objResult.CaseTypeTranslatedNameArray[i]), unescape(objResult.CaseTypeNameArray[i])));
                        }
                    }
                }
                if (sDefaultCaseType != '') {
                    LoadDefaultCaseType(sDefaultCaseType);
                }

            }

            //show description of category
            if ($("#hidCategoryList").val() != '') {
                var objCategoryList = eval('(' + $("#hidCategoryList").val() + ')');
                for (var i = 0; i < objCategoryList.CategoryNameArray.length; i++) {
                    if (sSelectedCategory == objCategoryList.CategoryNameArray[i]) {
                        $('#lbCategoryDescription').text(unescape(objCategoryList.CategoryDescriptionArray[i]));
                    }
                }

            };

            $('#imgCategoryChanged').hide();
            $('#imgCaseTypeChanged').hide();
        })
    }
    catch (error) {
        $('#imgCategoryChanged').hide();
        $('#imgCaseTypeChanged').hide();
    }
}

function OnCaseTypeSelected() {
    $('#imgValidateLocation').hide();
    $('#lbCaseTypeDescription').text('');
    try {
        if (CheckCaseTypeInput()) {
            var sSelectedCaseType = $('#frmIncCaseType').val();
            $('#hidSelectedCaseType').val(sSelectedCaseType);
            $('#imgCaseTypeChanged').show();
            $.get('show-casetype.aspx', { ReqType: 'ShowCaseTypeDetails', SelectedCaseType: sSelectedCaseType, LanguageName: $('#hidSelectedLanguage').val() }, function(data) {
                if (data) {
                    $('#divUdefContainer').show();
                    //$('#divLocationContainer').show();
                    var objResult = eval('(' + data.split('|')[0] + ')');
                    if (objResult.result == '1') {
                        $('#lbCaseTypeDescription').text(objResult.CaseTypeDetails.Description);

                        //set location control displaying
                        HideAllLocationControls();
                        var objLocationType = objResult.CaseTypeDetails.AllowedLocationTypeList
                        if (objLocationType.Unknown == '1') {
                            $('#frmUnknownType').show();
                            $('#frmUnknownType').attr('checked', 'checked');
                            $('#lbLocationUnknown').show();
                        }
                        if (objLocationType.Other == '1') {
                            $('#frmOtherType').show();
                            $('#frmOtherType').attr('checked', 'checked');
                            $('#lbLocationOther').show();
                        }
                        if (objLocationType.Intersection == '1') {
                            $('#frmIntersectionType').show();
                            $('#frmIntersectionType').attr('checked', 'checked');
                            $('#lbLocationIntersection').show();
                        }
                        if (objLocationType.Address == '1') {
                            $('#frmAddressType').show();
                            $('#frmAddressType').attr('checked', 'checked');
                            $('#lbLocationAddress').show();
                        }
                        hideshowLocationFields();

                        if (objLocationType.Address == '1') {
                            $('#pnlAddress').show();
                        } else if (objLocationType.Intersection == '1') {
                            $('#pnlIntersection').show();
                        } else if (objLocationType.Other == '1') {
                            $('#pnlOther').show();
                        }

                        //set attachment controls displaying
                        if (objResult.CaseTypeDetails.IsAttachmentAllowed == '1') {
                            //$('#pnlUploadAttachment').show();
                        } else {
                            $('#pnlUploadAttachment').hide();
                        }

                        //show udef
                        var s = data.substring(data.split('|')[0].length + 1);
                        s = s.replace('__VIEWSTATE', 'hidethecontrol_1').replace('__VIEWSTATE', 'hidethecontrol_2');
                        $('#divUdefContainer').html(s);
                    }
                    $("#hidCaseTypeDetails").val(data);
                }
                $('#imgCaseTypeChanged').hide();
            })
        }
    }
    catch (error) {
        $('#imgCaseTypeChanged').hide();
    }
}

function SaveCaseUdefValue() {
    var bValid = true;
    var lstUdef = null;
    if ($("#hidCaseTypeDetails").val() != "") {
        lstUdef = eval('(' + $("#hidCaseTypeDetails").val().split('|')[0] + ')').CaseTypeDetails.CaseUdefList;
    }
    var sValue = '';

    if (!lstUdef) {
        return true; //no udef
    }

    for (var i = 0; i < lstUdef.length; i++) {
        if (bValid) {
            try {
                var oUdef = lstUdef[i];
                sValue += oUdef.Id + '|';
                if (oUdef.Type == 'CheckBox') {
                    if (document.getElementById(oUdef.ControlId).checked == true) {
                        sValue += 'Yes;';
                    } else {
                        sValue += 'No;';
                    }
                } else if (oUdef.Type == 'CheckBoxList' || oUdef.Type == 'RadioButton') {
                    var bSet = false;
                    for (var j = 0; j < oUdef.SubControlList.length; j++) {
                        if (document.getElementById(oUdef.SubControlList[j]).checked == true) {
                            sValue += j + ',';
                            bSet = true;
                        }
                    }
                    sValue += ';';
                    try {
                        if (!bSet && oUdef.IsRequired == 'True') {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'inline';
                            bValid = false;
                        } else {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'none';
                        }
                    } catch (error) { }
                } else if (oUdef.Type == 'List') {
                    var olist = document.getElementById(oUdef.ControlId);
                    for (var j = 1; j < olist.options.length; j++) {
                        if (olist.options[j].selected) {
                            sValue += (j - 1) + ',';
                        }
                    }
                    sValue += ';';
                    var s = $('#' + oUdef.ControlId).val();
                    try {
                        if ((!s || s == '') && oUdef.IsRequired == 'True') {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'inline';
                            bValid = false;
                        } else {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'none';
                        }
                    } catch (error) { }
                } else {
                    var s = $('#' + oUdef.ControlId).val();
                    sValue += escape(s) + ';';
                    try {
                        if ((!s || s == '') && oUdef.IsRequired == 'True') {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'inline';
                            bValid = false;
                        } else {
                            document.getElementById('lblErr' + oUdef.ControlId).style.display = 'none';
                        }
                    } catch (error) { }
                }
            } catch (error) { }
        }
    }
    $("#hidCaseUdefValues").val(sValue);
    return bValid;
}

function HideAllLocationControls() {
    $('#frmAddressType').hide();
    $('#lbLocationAddress').hide();
    $('#frmIntersectionType').hide();
    $('#lbLocationIntersection').hide();
    $('#frmOtherType').hide();
    $('#lbLocationOther').hide();
    $('#frmUnknownType').hide();
    $('#lbLocationUnknown').hide();

    $('#pnlAddress').hide();
    $('#pnlIntersection').hide();
    $('#pnlOther').hide();
}


function CreateReq_GenCaptcha() {
    return { ReqType: 'GenCaptcha' };
}

function CreateReq_VlidateCaptcha() {
    var input = $("#txtCaptchaInput").attr('value');
    return { ReqType: input };
}

function onGenCaptcha() {
    $.get('GenCaptcha.aspx', CreateReq_GenCaptcha(), function(data) {
    if (data) {
            var s = data.substring(data.split('|')[0].length + 1);
            s = s.replace('__VIEWSTATE', 'hidethecontrol_3').replace('__VIEWSTATE', 'hidethecontrol_4');

            $('#divCaptchaPlaceHolder').html(s);
            $("#lbCaptchaError").hide();
            $("#imgCaptchaOK").hide();
            $("#lbCaptchaTipCaseSensitive").show();
            $("#txtCaptchaInput").attr('value','');
        }
    })
}

function onVlidateCaptcha() {
    var input = $("#txtCaptchaInput").attr('value');

    //alert(input);
    $.get('GenCaptcha.aspx', CreateReq_VlidateCaptcha(), function(data) {
        if (data) {
            var objResult = eval('(' + data.split('|')[0] + ')');
            if (objResult.result == '1') {
                $("#lbCaptchaError").hide();
                $("#imgCaptchaOK").show();
                $("#lbCaptchaTipCaseSensitive").hide();
              
            }
            else {
                $("#lbCaptchaError").show();
                $("#imgCaptchaOK").hide();
                $("#lbCaptchaTipCaseSensitive").hide();
            }
        }
    })

}

function onInputCaptchakeyup() {
    var input = $("#txtCaptchaInput").attr('value');
    if (input.length == 6) onVlidateCaptcha();
    else {
        $("#lbCaptchaError").hide();
        $("#imgCaptchaOK").hide();
        $("#lbCaptchaTipCaseSensitive").show();
        
    }
}


function IsCallerLoacationValid() {

    var objChkAnonymous = document.getElementById('frmAnonymous');

    if (objChkAnonymous.checked == true) {return true;}

    var bValid = true;   
    
    
    document.getElementById('frmCityError').style.display = 'none';

    $('#frmStateError').hide();
    $('#frmCountryError').hide();
    $('#frmCityTextError').hide();
    

    var oSelect = document.getElementById('frmCity');

    
//    if (oSelect.options.length == 0) {
//        document.getElementById('frmCityError').style.display = 'block';
//        bValid = false;
//    }
//    if (oSelect.selectedIndex < 1) {
//        document.getElementById('frmCityError').style.display = 'block';
//        bValid = false;
//    }



    var sSelectedCity = $.trim($('#frmCity').val());

    if (sSelectedCity == '') {
        document.getElementById('frmCityError').style.display = 'block';
        bValid = false;
    }

    if (sSelectedCity == 'Other...') {
        //if city is other, we need to validate country and states
        var sInputedCity = $.trim($('#frmCityTextValue').val());
        var sSelectedCountry = $.trim($('#frmCountry').val());
        var sSelectedState = $.trim($('#frmState').val());

        if (sSelectedCountry == "") {
            $('#frmCountryError').show();
            bValid = false;
        }

        if (sInputedCity == "") {
            $('#frmCityTextError').show();
            bValid = false;
        }

        if (sSelectedState == "" && (sSelectedCountry == 'UNITED STATES' || sSelectedCountry == 'CANADA')) {
            $('#frmStateError').show();
            bValid = false;
        }
        
        
    }

    return bValid;
}

function LoadDefaultCategoryCaseType(bHideDDL) {

    
    var sDefaultCategory = $('#hidDefaultCategory').val();
    var sDefaultCaseType = $('#hidDefaultCaseType').val();

    if (sDefaultCategory != '') {
        $('#frmIncCategory').val(sDefaultCategory);
        $('#imgValidateLocation').hide();
        $('#lbCategoryDescription').text('');
        $('#lbCaseTypeDescription').text('');
        if (CheckCategoryInput(false)) {
            document.getElementById('frmIncCaseType').options.length = 0;

            $('#hidSelectedCategory').val(sDefaultCategory);

            $('#imgCategoryChanged').show();
            try {
                GetCaseTypeList(sDefaultCategory, sDefaultCaseType);                
            }
            catch (error) {
                $('#imgCategoryChanged').hide();
            }
        }
        else {
            document.getElementById('frmIncCategory').selectedIndex = 0;
        }

    }
    else {
        document.getElementById('frmIncCategory').selectedIndex = 0;
    }


    if (bHideDDL == 'True') {
        $('#pnlCategory').hide();
        $('#pnlCaseType').hide();
    }
    
}

function LoadDefaultCaseType(bHideDDL) {


    var sDefaultCaseType = $('#hidDefaultCaseType').val();
    if (sDefaultCaseType != '') {
        $('#frmIncCaseType').val(sDefaultCaseType);
        OnCaseTypeSelected(false);
    }

    if (bHideDDL == 'True') {
        $('#pnlCategory').hide();
        $('#pnlCaseType').hide();
    }

}


function FireDefaultButton(event, defaultButton) {
    if (event.keyCode == 13) {
        var __nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);
        var src = null;

        if (__nonMSDOMBrowser) {
            src = event.target;
        }
        else {
            src = event.srcElement;
        }

        var tagName = src.tagName.toLowerCase();

        if (tagName == "a") {
            return true;
        }
        else if (tagName == "textarea") {
            return true;
        }
        else if ((tagName == "input") && ((src.type == "submit") || (src.type == "reset") || (src.type == "image") || (src.type == "file"))) {
            return true;
        }
        else {
            if (defaultButton.click != "undefined") {
                defaultButton.click();

                if (__nonMSDOMBrowser) {
                    event.cancelBubble = true;
                }

                return false;
            }
        }
    }

    return true;
}