function coupon_counter(id)
{
  var uniq=Math.floor((Math.random() * 410) + 1);
            // Return Request
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange=function() {
                if (this.readyState == 4 && this.status == 200) {
                  
                  
                
                }
                };
               //Make Request 
                xhttp.open("GET", "https://www.taglichrabatt.de/ajax/data_collection.php?coupon_counter="+id+"&uniq="+uniq, true);
                xhttp.send();
}


function copyToClipboard(e,id,track){
    var t=$("<input>");
    $("body").append(t),
    t.val($(e).text()).select(),
    document.execCommand("copy"),
    t.remove(),
    document.getElementsByClassName("copyBtnClass").innerHTML="Copié !",
    window.open(track,"_blank"); 
    window.location.href = "#coupon_popup-"+id; 
    location.reload(); 
}


function getDeal(id,track){
    window.open(track,"_blank"),
    window.location.href ="#coupon_popup-"+id,
    location.reload();
}


function subscribe()
{
	document.getElementById('subscribeResponse').innerHTML="Thanks For Subscribing";
}

function copy() {
    
var clipboard = new Clipboard('.btn');

clipboard.on('success', function(e) {
  document.getElementById('copy_button').innerHTML="Kopiert..!";
});

clipboard.on('error', function(e) {
    console.error('Action:', e.action);
    console.error('Trigger:', e.trigger);
});
}


function popup_coupon()
{	
	
	var id=window.location.hash.substr(1);
	var arr = id.split('-');
	coupon_modal(arr[1]);
	document.getElementById('popup_coupon_'+arr[1]).click();
}

function coupon_modal(id)
{


							// Return Request	
							  var xhttp = new XMLHttpRequest();
							  xhttp.onreadystatechange=function() {
								if (this.readyState == 4 && this.status == 200) {	
							document.getElementById('myModal').innerHTML=this.responseText;
								}
							  };
							 //Make Request						 
							  xhttp.open("GET", "https://www.taglichrabatt.de/ajax/data_collection.php?coupon_modal="+id, true);
							  xhttp.send();
                              return false;


}
function search(val)
{
    
				if(val==null)
				{
					document.getElementById('search_response').style.display='none';
				}
				else
				{
					document.getElementById('search_result').style.display='block';
					
					document.getElementById('search_result').innerHTML='<center><div class="loader"></div></center>';
					// Return Request	
							  var xhttp = new XMLHttpRequest();
							  xhttp.onreadystatechange=function() {
								if (this.readyState == 4 && this.status == 200) {	
									document.getElementById('search_result').innerHTML=this.responseText;
                                   									
									
								}
							  };
							 //Make Request						 
							  xhttp.open("GET", "https://www.taglichrabatt.de/ajax/data_collection.php?search="+encodeURIComponent(val), true);
							  xhttp.send();
					
				}
					
					
				
}

function hidesearch()
{
	
	document.getElementById('search_result').style.display='none';
}




	function pagination(x)
	{

                                     var milliseconds = new Date().getTime();
	                        document.getElementById("blog_list").innerHTML='<center><img src="images/loader.png" class="img-responsive"></center>';
							
							  var xhttp = new XMLHttpRequest();
							  xhttp.onreadystatechange=function(e) {
								  e.preventDefault();
								if (this.readyState == 4 && this.status == 200) {
									
								  document.getElementById("blog_list").innerHTML=this.responseText;
								
								}
							  };
							 //Make Request	
							  xhttp.open("GET", "https://www.taglichrabatt.de/ajax/data_collection.php?pagination="+x+"&ts="+milliseconds);
							  xhttp.send();
		
	}
