﻿///*******************************************************************************
//*
//*   GeographyDB.js
//*   David Cordner
//*   Fluent Technology 2008
//*
//********************************************************************************/


/*******************************************************************************
*
*   Scripts to handle the geogrpahy data browsers functions
*
********************************************************************************/

        function selectRegion(checked,regionid,code,region) {
        var gl = $('GeographyList'); 
            if (gl) {
                if (checked==1) {
                    var div = new Element('div', {'id':'div'+regionid});
                    var chkButton = new Element('input', {'id':'chk'+regionid, 'type': 'checkbox', 'name': 'chkGeographies', 'value': regionid, 'checked':'checked'});
                    chkButton.setAttribute('checked', 'checked')
                    chkButton.checked=true;
                    chkButton.defaultChecked=true;
                    var label = new Element('span', {'class': 'atRange'});
                    label.update(region + ' (' + code + ')')
                    div.insert(chkButton);
                    div.insert(label);
                    gl.insert(div);
                } else {
                    var div = $('div'+regionid);
                        if (div) {
                            div.remove();
                        }
                }
            }
        }
        
        function ValidateSelection(el)
        {
        var a = el.getElementsByTagName('input');
        var i=0;
            for (i=0;i<a.length;i++)
            {
            if (!a(i).checked)
                {
                document.getElementById(jsPrefix+'selectAllDistricts').checked=false;
                break;
                }
            document.getElementById(jsPrefix+'selectAllDistricts').checked=true;
            }
        }

	    function selectAll(el)
	    {
	    var divs = document.getElementById('d' + el.value);
	    var chks = divs.getElementsByTagName('input');
	    var i=0;
        for (i=0;i<=chks.length-1;i++)
	        {
	        if (chks[i].type='checkbox')
	            {
	            if (el.checked) {chks[i].checked=true} else {chks[i].checked=false} 
	            }
	        }
	    }
	    
	    function hideShowDiv(regionTypeID)
	    {
	       //alert(regionTypeID.replace('d','img'));
	        //alert(document.getElementById(regionTypeID).style.display);
	        if (document.getElementById(regionTypeID).style.display=='inline')
	        {
	            document.getElementById(regionTypeID).style.display='none';
	            document.getElementById(regionTypeID.replace('d','img')).src='images/pnlCollapse.gif';
	        }
	        else
	        {
	            document.getElementById(regionTypeID).style.display='inline';
	            document.getElementById(regionTypeID.replace('d','img')).src='images/pnlExpand.gif';
	        }
	    }
	    function selectionComplete(dragStartEasting,dragStartNorthing,dragEndEasting,dragEndNorthing)
	    {
	        //alert('The selection is complete (' + dragStartEasting + ',' + dragStartNorthing + ' to ' + dragEndEasting + ',' + dragEndNorthing);
	        //alert('Drag from:' + dragStartEasting + ' to ' + dragEndEasting + dragEndNorthing + ')');
	        getGeographiesByCoords('get/getGDBAjax.aspx?q=GeographyListByCoords',dragStartEasting,dragStartNorthing,dragEndEasting,dragEndNorthing);
	    }
	    
	    function CheckBoxListSelect(cbControl)
        {    
           var chkBoxList = document.getElementById(jsPrefix+cbControl);
            var chkBoxCount= chkBoxList.getElementsByTagName("input");
            for(var i=0;i<chkBoxCount.length;i++) 
            {
                chkBoxCount[i].checked = document.getElementById(jsPrefix+'selectAllDistricts').checked;
            }
            return false; 
        }
        
        
