/**
* requires prototype
* NotifyBox is a class that represents a box for calling an action 
* because some content is not appropriate (the users will have to click it)
* with the method "openNotifyBox" you can create a box(or open it if already avaible)
* the Param is the url that will be called once the send-button is clicked.
* 
* the document needs to have an element with id "contentMain" where it can append itself to
* 
* styles for the following elements are asumed:
* 
* #notifyBoxBackgroundDiv
* #notifyBoxOverlayDiv
*/
var notifyBox = Class.create();
notifyBox.prototype={
	initialize : function(appRoot)
	{
		this.backgroundDiv = document.createElement("div");
		this.backgroundDiv.id = "notifyBoxBackgroundDiv";
		this.backgroundDiv.style.top = "0px";
		this.backgroundDiv.style.left = "0px";
		this.backgroundDiv.style.height = Math.max(document.body.scrollHeight,(document.documentElement.clientHeight || document.body.clientHeight || 0))+"px";
		this.backgroundDiv.style.width = Math.min(document.body.scrollWidth,(document.documentElement.clientWidth || document.body.clientWidth || 0))+"px";
		this.overlayDiv = document.createElement("div");
		this.overlayDiv.id = "notifyBoxOverlayDiv";
		
		this.overlayInnerDiv = document.createElement("div");
		this.overlayInnerDiv.id = "notifyBoxOverlayInnerDiv";

		this.headerText = document.createElement("div");
		this.headerText.innerHTML = "Der Inhalt ist problematisch, weil...";
		
		this.dropDown = document.createElement("select");
		this.dropDown.name = "notifyBoxDropDown";
		this.dropDown.id = "notifyBoxDropDown";
		this.dropDown.size = 1;
		this.dropDown.options[0] = document.createElement("option");
		this.dropDown.options[0].innerHTML = "geschmacklos";
		this.dropDown.options[1] = document.createElement("option");
		this.dropDown.options[1].innerHTML = "Urheberrechtsverletzung";
		this.dropDown.options[2] = document.createElement("option");
		this.dropDown.options[2].innerHTML = unescape("Pers%F6nlichkeitsrechtsverletzung");
		this.dropDown.options[3] = document.createElement("option");
		this.dropDown.options[3].innerHTML = "Pornografischer Inhalt";
		
		this.additionalText = document.createElement("div");
		this.additionalText.innerHTML = unescape("Das m%F6chte ich noch loswerden%3A");
		
		this.additionalTextArea = document.createElement("textarea");
		this.additionalTextArea.id = "notifyBoxTextArea";
		this.additionalTextArea.rows = 5;
		
		this.closeButtonLink = document.createElement("a");
		this.closeButtonLink.href = "javascript:void(0)";
		this.closeButton = document.createElement("img");
		this.closeButton.src=appRoot+"/images/btn_abbrechen.gif";
		this.closeButton.onclick = function(){
			notifyBoxInstance.closeNotifyBox.call(notifyBoxInstance);
		};
		this.closeButtonLink.appendChild(this.closeButton);
		
		this.sendButtonLink = document.createElement("a");
		this.sendButtonLink.href = "javascript:void(0)";
		this.sendButton = document.createElement("img");
		this.sendButton.src=appRoot+"/images/btn_abschicken.gif";
		this.sendButton.onclick = function(){
			notifyBoxInstance.sendRequest.call(notifyBoxInstance);
		};
		this.sendButtonLink.appendChild(this.sendButton);
		
		this.overlayInnerDiv.appendChild(this.headerText);
		this.overlayInnerDiv.appendChild(this.dropDown);
		this.overlayInnerDiv.appendChild(this.additionalText);
		this.overlayInnerDiv.appendChild(this.additionalTextArea);
		this.overlayInnerDiv.appendChild(this.closeButtonLink);
		this.overlayInnerDiv.appendChild(this.sendButtonLink);
		
		this.overlayDiv.appendChild(this.overlayInnerDiv);
		
		document.getElementById("contentMain").appendChild(this.backgroundDiv);
		document.getElementById("contentMain").appendChild(this.overlayDiv);
	},
	sendRequest : function()
	{
		new Ajax.Request(this.actionUrl +"&reason="+this.dropDown.options[this.dropDown.options.selectedIndex].innerHTML
			+"&myText="+this.additionalTextArea.value, 
			{onComplete: this.sendButtonCallback 
			, method: 'post'});
			this.closeNotifyBox();
	},
	sendButtonCallback : function()
	{
		alert(unescape("Deine Beschwerde wurde abgeschickt%2C wir k%FCmmern uns umgehend darum"));
	},
	openNotifyBox : function(actionUrl)
	{
		this.actionUrl = actionUrl;
		this.backgroundDiv.style.visibility = "visible";
		this.overlayDiv.style.visibility = "visible";
	},
	closeNotifyBox : function()
	{
		this.backgroundDiv.style.visibility = "hidden";
		this.overlayDiv.style.visibility = "hidden";
	}
};
var notifyBoxInstance = null;
function openNotifyBox(appRoot,actionUrl){
	if(notifyBoxInstance==null)
		notifyBoxInstance= new notifyBox(appRoot);
	notifyBoxInstance.openNotifyBox(actionUrl);
};
