var testbucket = .2;
var dialogtitle = "<h3>Feedback zu Psych-Info</h3>";
var feedbackdialog = "<div id='dialog'><h4>W&uuml;rden Sie uns im Anschluss an Ihren Besuch &uuml;ber Ihre Erfahrungen mit Psych-Info berichten?</h4></div>";

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function returnDocument() {
       var file_name = document.location.href;
       var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
       // return file_name.substring(file_name.lastIndexOf("/")+1, end);
return document.location.href;
   }
var currentpage = returnDocument();


function popitup(url) {
	newwindow=window.open(url,'name','height=700,width=620,resizable=1,scrollbars=1');
	if (window.focus) {
//		newwindow.focus()
		self.focus();
		}
	return false;
}

	$(function(){

			$("body").append(feedbackdialog);
			
		
		// Dialog			
		$('#dialog').dialog({
			autoOpen: false,
			width: 400,
			modal: true,
			title: dialogtitle,
			buttons: {
				"Ja, gerne": function() { 
					$(this).dialog("close"); 
					popitup('feedback.php?entry='+currentpage);
				}, 
				"Nein, danke": function() { 
					$(this).dialog("close"); 
					setCookie("askfeedback","no",90);
				} 
			}
		});


	});


$(document).ready(function() {
	
	if(Math.random() <= testbucket){
	
		var askfeedback=getCookie("askfeedback");
		if (askfeedback != "no")
		{
			$('#dialog').dialog('open');
		}
	}
});
