﻿   // variables for reports calendar scripts -->
    var recowner = "MONT";
    var d1;
    var d2;
    var emsg;
    var rptarr = ["101", "201", "202", "301", "302", "710", "711", "720", "721", "805", "807", "905", "907"];      
         
         
        Array.prototype.contains = function (element) {
        for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
        return true;
        }
        }
        return false;
        }
       
        function doreport(aspx)
         {
            emsg='';
            recowner='';
            //setrecowners();
            recowner = 'MONT'
            if (emsg=='') 
                {
                   setdates(aspx);
                   if (emsg=='')
                      {Wait(); window.location = aspx + ';' + recowner + ';' + d1 + ';' + d2;}
                }
            if (emsg!='') {alert(emsg);}                        
         }
        
        function setdates(aspx) 
        {
            d1 = document.getElementById('txtFromDate').value;
            d2 = document.getElementById('txtToDate').value;
            if (d1=='' || d2=='') 
                {emsg='You must enter both start and end dates for the report.'} 
            else
                //verify dates in one year for 2-yr comparison reports... 
                verifydates(aspx, d1, d2)      
        }
        
       function setrecowners()
        {
            if (document.getElementById('cb_county_0').checked) {recowner = 'cuy,'}
            if (document.getElementById('cb_county_1').checked) {recowner = recowner + 'gea,'}
            if (document.getElementById('cb_county_2').checked) {recowner = recowner + 'med'}
            // set boolean to continue or stop here...
            if (recowner == '') {emsg='You must select a County for the report';}        
        
        }
        
       function verifydates(aspx, d1, d2)
            {
              var irpt;
              var aPosition = aspx.indexOf("?");
              var yr1
              var yr2
             
             irpt = aspx.substring(aPosition + 1);
              if (rptarr.contains(irpt) == true)
                 {
                    var arrD1;
                    var arrD2;
                    arrD1 = d1.split("/");
                    arrD2 = d2.split("/");
                    yr1 = arrD1[2];
                    yr2 = arrD2[2];
                    
                    if (yr1 != yr2) {emsg="You selected a 2-year comparison report that requires a date range within the same calendar year. The report will show the pior year's data for comparison.\n\nEnter '1/1/2010' or later as the 'From Date' for a report that compares 2010 to 2009.\n"}
                }              
            }
        
       function Wait()
        {
         document.getElementById('pleasewaitScreen').style.display = 'block';
         document.getElementById('txtFromDate').focus();
         window.setTimeout('document.images["waitgif"].src="images/wait.gif"', 100);
        }
