﻿function CheckOccupation(mEvent, hfCounter, txtOccupation, hfOccupationsSelectedValues) {
    var o;
    var Total;
    if ($get(hfCounter).value=="")
        Total = 0;
    else
        Total = $get(hfCounter).value * 1;
    
    // Internet Explorer    
    if (mEvent.srcElement) {
        o = mEvent.srcElement;
    }
    // Netscape and Firefox
    else if (mEvent.target) {
        o = mEvent.target;
    }
   
    if (o.tagName == "INPUT" && o.type == "checkbox") {
       
        var lenId = 15; //len("TreeOccupdations")
        var treeViewId = o.id.substring(0, o.id.lastIndexOf("TreeOccupations") + lenId);
        var spanId = o.nextSibling.firstChild.id;
        var value = spanId.replace("span_"+treeViewId + "_", "");

        if (o.checked) {
            Total = Total + 1;
            $get(hfOccupationsSelectedValues).value += value + ",";
            
        }
        else {
            Total = Total - 1;
            $get(hfOccupationsSelectedValues).value = $get(hfOccupationsSelectedValues).value.replace("," + value + ",", ",");
            
        }
        
        $get(hfCounter).value = Total;

        if (Total == 0) {
            $get(txtOccupation).innerHTML = "Select up to 30 occupations";
            $get(hfCounter).value = "0";
        }
        else {
            $get(txtOccupation).innerHTML = Total + " occupations selected";
        }
    }
}

//call this function in occupationTree.ascx
function checkTreeView(treeViewId, hfOccupationsSelectedValuesId) {
    alert("checkTreeView");
    selectedValues = $get(hfOccupationsSelectedValuesId).value;
    alert(selectedValues);
    debugger;
    if (selectedValues != ",") {
        selectedValues = selectedValues.split(',');
        for (var i = 1; i < selectedValues.length; i++) {
        var span = $get("span_"+treeViewId+"_"+selectedValues[i]);
        if(span!=null)
            var checkBox = span.parentElement.previousSibling.checked = true;
        }
        
    }

}
function occuptionBlurHandle(event) {
    if (isActive == 1) {
    }
}

