
window.onload = function(){
let filterBtn = document.getElementById('filter-btn')


	let showingCard = document.getElementById('showing-card');
    let overlay = document.getElementById('backgroundOverlay'); 
    // var openButton = document.getElementById('openOverlay'); => filterBtn
    document.onclick = function(e){
        if(e.target.id == 'backgroundOverlay'){
            showingCard.style.display = 'none';
            overlay.style.display = 'none';
        }
        if(e.target === filterBtn){
            showingCard.style.display = 'block';
            overlay.style.display = 'block';
        }
    };


    $(".range-plus").on('click', function() {
        let rangeid = $(this).data('rangeid');
        let range = $('#' + rangeid);
        let val = range.val();
        if(val < 10)
            val++;
        range.val(val);
        showVal(val);
    });
    $(".range-minus").on('click', function() {
        let rangeid = $(this).data('rangeid');
        let range = $('#' + rangeid);
        let val = range.val();
        if(val > 1)
            val--;
        range.val(val);
        showVal(val);
    });

};

let country_arr = new Array("Afghanistan", "Albania", "Algeria", "American Samoa", "Angola", "Anguilla", "Antartica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Ashmore and Cartier Island", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Clipperton Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czeck Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Europa Island", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern and Antarctic Lands", "Gabon", "Gambia, The", "Gaza Strip", "Georgia", "Germany", "Ghana", "Gibraltar", "Glorioso Islands", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (Vatican City)", "Honduras", "Hong Kong", "Howland Island", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Ireland, Northern", "Israel", "Italy", "Jamaica", "Jan Mayen", "Japan", "Jarvis Island", "Jersey", "Johnston Atoll", "Jordan", "Juan de Nova Island", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Man, Isle of", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Midway Islands", "Moldova", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcaim Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romainia", "Russia", "Rwanda", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Scotland", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and South Sandwich Islands", "Spain", "Spratly Islands", "Sri Lanka", "Sudan", "Suriname", "Svalbard", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Tobago", "Toga", "Tokelau", "Tonga", "Trinidad", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "Wales", "Wallis and Futuna", "West Bank", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe");

let s_a = new Array();


function print_country(country_id){

	let option_str = document.getElementById(country_id);
	option_str.length=0;
	option_str.options[0] = new Option('Select Country','');
	option_str.selectedIndex = 0;
	for (let i=0; i<country_arr.length; i++) {
		option_str.options[option_str.length] = new Option(country_arr[i],country_arr[i]);
	}
}

function print_state(state_id, state_index){
	let option_str = document.getElementById(state_id);
	option_str.length=0;	
	option_str.options[0] = new Option('Select State','');
	option_str.selectedIndex = 0;
	let state_arr = s_a[state_index].split("|");
	for (let i=0; i<state_arr.length; i++) {
		option_str.options[option_str.length] = new Option(state_arr[i],state_arr[i]);
	}
}

// Take a screenShot 
// function captureEntireDiv() {
//     const captureElement = document.getElementById('capture'); // Replace 'capture' with the ID of your div
//     const elementHeight = captureElement.scrollHeight;
//     const windowHeight = window.innerHeight;
//     const numScreenshots = Math.ceil(elementHeight / windowHeight);
    
//     const promises = [];

//     for (let i = 0; i < numScreenshots; i++) {
//         const scrollToY = i * windowHeight;
//         promises.push(
//             new Promise((resolve) => {
//                 window.scrollTo({ top: scrollToY, behavior: 'smooth' });
//                 setTimeout(() => {
//                     html2canvas(captureElement).then((canvas) => {
//                         resolve(canvas);
//                     });
//                 }, 1000); // Adjust the delay as needed
//             })
//         );
//     }

//     Promise.all(promises)
//         .then((screenshots) => {
//             // Combine all screenshots into a single canvas
//             const combinedCanvas = document.createElement('canvas');
//             const context = combinedCanvas.getContext('2d');

//             combinedCanvas.width = screenshots[0].width;
//             combinedCanvas.height = elementHeight;

//             screenshots.forEach((canvas, index) => {
//                 context.drawImage(canvas, 0, index * windowHeight);
//             });

//             // Convert the combined canvas to a data URL and initiate the download
//             const image = combinedCanvas.toDataURL('image/png').replace('image/png', 'image/octet-stream');
//             const a = document.createElement('a');
//             a.setAttribute('download', 'entire-div.png');
//             a.setAttribute('href', image);
//             a.click();
//         })
//         .catch((error) => {
//             console.error('Error capturing screenshots:', error);
//         });
// }

// // Add event listener to the button
// document.addEventListener('DOMContentLoaded', function () {
//     const btn = document.querySelector('#cap');
//     if (btn) {
//         btn.addEventListener('click', captureEntireDiv);
//     }
// });



// Uncheck a checkbox if another checked 
function cbChange(obj) {
    var cbs = document.getElementsByClassName("chk");
    for (var i = 0; i < cbs.length; i++) {
        cbs[i].checked = false;
    }
    obj.checked = true;
}

function setZoom(zoom,el) {
      
      transformOrigin = [0,0];
      el = el || instance.getContainer();
      var p = ["webkit", "moz", "ms", "o"],
            s = "scale(" + zoom + ")",
            oString = (transformOrigin[0] * 100) + "% " + (transformOrigin[1] * 100) + "%";

      for (var i = 0; i < p.length; i++) {
          el.style[p[i] + "Transform"] = s;
          el.style[p[i] + "TransformOrigin"] = oString;
      }

      el.style["transform"] = s;
      el.style["transformOrigin"] = oString;
      if(zoom >= 3) {
        hiddenP_events(false);
        $('.hiddenP').addClass('zoom-out').css('display', 'flex');
      } else {
        hiddenP_events(true);
        $('.hiddenP').removeClass('zoom-out').css('display', 'none');
      }
      
}

function showVal(a){
   var zoomScale = Number(a);
   setZoom(zoomScale,document.getElementsByClassName('tables')[0])
}

$(document).on({
    ajaxStart: function(){
        $("body").addClass("loading"); 
    },
    ajaxStop: function(){ 
        $("body").removeClass("loading"); 
    }    
});