﻿function callback(res)    
        {
            var html = [];
            
            for(var i=0; i<res.value.Tables[0].Rows.length; i++)
               html[html.length] = "<li>" + res.value.Tables[0].Rows[i].Title + "</li>";
           if(html.length>0)
            document.getElementById("bookMarkedJobs").innerHTML = "<ul><li><span onClick='__doPostBack(\"updatePanel3\",\"ListbookMarkJobs\")'><b>Total "+ html.length +" bookmarked jobs.</b></span></li>"+ html.join("") + "</ul>";
           else
            document.getElementById("bookMarkedJobs").innerHTML="";
            
        }
        
       // window.onload = fnGetBookMarkedJobs;

      
          
        function fnGetBookMarkedJobs()
        {
            assign();
           // WebClickHandler.GetBookMarkedJobs(bjids,callback);
           // WebClickHandler.GetRegionByTask(document.getElementById('dplRegion').value,populateRegion);
        }
        
        function fnGetRegion(taskID)
        {
           // showLoading();
            WebClickHandler.GetRegionByTask(taskID,populateRegion);
        }
        
        function populateRegion(res)
        {             
            var objRegion = document.getElementById('dplRegion');
            var html = [];
            var selected="" ;
            var selectedValue = objRegion.value;

            html[html.length] = "<option value='0'>Välj län</option>";
            for(var i=0; i<res.value.Tables[0].Rows.length; i++)
            {
                if(res.value.Tables[0].Rows[i].id ==selectedValue)
                    selected= " selected"
                 else
                     selected =  " "; 
              
                    
               html[html.length] = "<option value='"+res.value.Tables[0].Rows[i].id+"' "+ selected +">" + res.value.Tables[0].Rows[i].name + "</option>";
            }
            if(html.length>0)
                document.getElementById("selRegion").innerHTML = "<select id='dplRegion' name='dplRegion' > "+ html.join("") + "</select>";             
                               
            // hideLoading();  
            
        }
        
/////////////////////////////////////////////////////////////////////////////////////        
        var curTime;

        function SearchDelay(objList) {

            
            
            
            //debugger;
            if (curTime != null)
            { clearTimeout(curTime); }

            fnUnSelectAllBox(objList);
            curTime = setTimeout("showLoading();__doPostBack('" + objList + "','')",0);

        }

        function showhide(divid, btnexpid, rowIndex, gridId, job_id) {
            
            
            var rowCount = document.getElementById(gridId).rows.length;
            for (ij = 1; ij <= rowCount; ij++) {
                if (document.getElementById(btnexpid) == null)
                    return;
                objDivHead = document.getElementById(btnexpid).parentNode.getElementsByTagName("DIV");
                var pre; var btn;

                if (ij >= 10) {
                    pre = gridId+'_ctl' + ij + '_desc';
                    // dont add 0 after 10...
                    btn = gridId+'_ctl' + ij + '_lblMakeButton';
                }
                else {
                    pre = gridId+'_ctl0' + ij + '_desc';
                    btn = gridId+'_ctl0' + ij + '_lblMakeButton';
                }
                if (pre == divid) {

                    if (document.getElementById(divid).style.display == 'block') {
                        document.getElementById(divid).style.display = 'none';
                        document.getElementById(btnexpid).className = 'plus';
                        //document.getElementById(divid).parentNode.style.background = "url(../stylesheet/images/boxtitle_bg.gif) repeat-x";
                        objDivHead[0].getElementsByTagName('a')[0].className = "plusLink";
                        
                        objDivHead[0].setAttribute('style', 'overflow:hidden;height:16px;width:545px;');
                        if(objDivHead[1]!=null)
                            objDivHead[1].setAttribute('style', 'overflow:hidden;height:16px;width:545px;');
                    }
                    else {
                         if (curTime != null)
                            { clearTimeout(curTime); }
                        curTime= setTimeout("ClickHandler.InsertUpdateJobViewCount("+job_id+")",500);
                        document.getElementById(divid).style.display = 'block';
                        document.getElementById(btnexpid).className = 'minus';
                        objDivHead[0].getElementsByTagName('a')[0].className = "minusLink";

                        objDivHead[0].setAttribute('style', 'overflow:visible;padding-right:10px;width:545px;');
                        if (objDivHead[1] != null) {
                            objDivHead[1].setAttribute('style', 'overflow:visible;padding-right:10px;width:545px;');
                        }

                    }
                    if (isMaxZoomSet == false) {
                        map.setCenter(temppoint, zoomLvl);
                    }
                }
                else {
					
                    if (document.getElementById(pre) != null) {
							
                        if (document.getElementById(pre).style.display != 'none') {
                            //one line title
                            objDivHead = document.getElementById(btn).parentNode.getElementsByTagName("DIV");
                            if (objDivHead[0] != null)
                                objDivHead[0].setAttribute('style', 'overflow:hidden;height:16px;width:545px;');
                            if (objDivHead[1] != null)
                                objDivHead[1].setAttribute('style', 'overflow:hidden;height:16px;width:545px;');
                        }
                        document.getElementById(pre).style.display = 'none';
                        //document.getElementById(pre).parentNode.style.background = "url(../stylesheet/images/boxtitle_bg.gif) repeat-x";
                        document.getElementById(btn).className = 'plus';
                        objDivHead = document.getElementById(pre).parentNode.getElementsByTagName("DIV");
                        if (objDivHead) {
                            var objDivHead2 = objDivHead[0].getElementsByTagName('DIV');
                            if (objDivHead2)
                                objDivHead2[0].getElementsByTagName('a')[0].className = "plusLink";
                        }
						
                    }
                   
                }

            }
            isMaxZoomSet = false;
        }     

        function close_popup(id) {
            document.getElementById(id).style.display = "none";
        }
        
        
 ////////////////////////////////////////////////////////////////////////////
 
        var checkedBoxesArray = new Array();

        function checkBoxChanged(controlInfo) {
            var ary = controlInfo.split(":");
            var maxSelection = ary[2];
            var countChecked = 0;
            var recentCheckbox;


            var chkBoxList = document.getElementById('<%# gdvjob.ClientID %>');

            if (chkBoxList != null) {
                var a = ary[0].split("_");

                var chkboxListId = chkBoxList.getAttribute('id');
                recentCheckbox = document.getElementById(chkboxListId + "_" + a[a.length - 1]);
                var chkboxlength = ary[1];

                for (var i = 0; i < chkboxlength; i++) {
                    var chkBxid = chkboxListId + "_" + i;

                    var chkBx = document.getElementById(chkBxid);
                    alert(document.getElementById(chkBxid));

                    if (!chkBx.checked)
                        alert(document.getElementById(chkBxid));
                }
            }

        }
        
        function fnUnCheckAll(obj,eventTarget)
        {            
           if(obj.checked)
           {
               obj = document.getElementById(eventTarget);
               if (obj == null) return;
                objAllCheckBoxes = obj.getElementsByTagName("INPUT");  
                for(var i=0;i<objAllCheckBoxes.length;i++)
                {
                    objAllCheckBoxes[i].checked=false;
                }
            }
           SearchDelay(eventTarget);
        }
        
        function fnUnSelectAllBox(objList)
        {            
         
           obj = document.getElementById(objList);
           if (obj == null) return;
            objAllCheckBoxes = obj.getElementsByTagName("INPUT");  
            for(var i=0;i<objAllCheckBoxes.length;i++)
            {
                if(objAllCheckBoxes[i].checked)
                    {
                        if(objList=='cblTargetGroup')
                            document.getElementById('chkAll').checked = false;
                        else if(objList=='cblCriteria')
                            document.getElementById('chkAllCriteria').checked = false; 
                        else if(objList=='cblMunicipality')
                            document.getElementById('chkAllMunicipality').checked = false;    
                        break;    
                    }
            }
            
        }
