function MessageWindow(header, isImage)
{
	this.BackgroundDiv = document.createElement("div");
	this.BackgroundDiv.className = "messageboxBackground";


	var yInnerHeight,yOffSet;
	if (self.pageYOffset)
		yOffSet = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		yOffSet = document.documentElement.scrollTop;
	else if (document.body) // all other Explorers
		yOffSet = document.body.scrollTop;

	if (self.innerHeight) // all except Explorer
		yInnerHeight = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		yInnerHeight = document.documentElement.clientHeight;
	else if (document.body) // other Explorers
		yInnerHeight = document.body.clientHeight;

	y = yInnerHeight + yOffSet;


	this.BackgroundDiv.style.height = "" + y + "px";

	this.BoxDiv = document.createElement("div");
	this.BoxDiv.className = "messageboxBox";

	this.HeaderDiv = document.createElement("div");
	this.HeaderDiv.className = "messageboxHeader";
	if (isImage)
		this.HeaderDiv.style.width = "640px";
	if (!header)
		header = "Achtung!";
	this.HeaderDiv.appendChild(document.createTextNode(header));
	if (!isImage)
		this.BoxDiv.appendChild(this.HeaderDiv);



	this.addContent = function(element){
		if (element.src) {
			var x,y;
			if (self.pageYOffset) // all except Explorer
				y = self.pageYOffset;
			else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
				y = document.documentElement.scrollTop;
			else if (document.body) // all other Explorers
				y = document.body.scrollTop;

			if (self.innerHeight) // all except Explorer
				x = self.innerWidth;
			else if (document.documentElement && document.documentElement.clientHeight)
				x = document.documentElement.clientWidth;
			else if (document.body) // other Explorers
				x = document.body.clientWidth;

			this.BoxDiv.className = "imageBox";
			this.BoxDiv.style.top = "" + (y + 103) + "px";
			imgWidth = element.width;
			if (imgWidth == 0)
				imgWidth = 640;
			this.BoxDiv.style.left = "" + ((x /2) - (imgWidth / 2) ) + "px";
		}
		this.BoxDiv.appendChild(element);
	}
	this.show = function(){document.getElementById("body").appendChild(this.BackgroundDiv);document.getElementById("body").appendChild(this.BoxDiv);}
	this.remove = function(){this.BackgroundDiv.parentNode.removeChild(this.BackgroundDiv);this.BoxDiv.parentNode.removeChild(this.BoxDiv);}
}

function Button(text, action)
{
	this.element = document.createElement("span");
	this.element.className = "messageboxButton";
	this.element.appendChild(document.createTextNode(text));
	this.element.self = this;

	this.element.onclick = function(){this.self.onclick()};
	this.onclick = function(){eval(action)};

	this.getButton = function(){return this.element;}
}

function Image(src, action)
{
	//var myImage = new Image;
	//myImage.src = src;
	this.element = document.createElement("img");
	this.element.src = src;
	this.element.self = this;

	this.element.onclick = function(){this.self.onclick()};
	this.onclick = function(){eval(action)};

	this.getImage = function(){return this.element;}
}

function MessageBox(message, action, header, type)
{
	this.Win = new MessageWindow(header);
	this.MessageDiv = document.createElement("div");
	this.MessageDiv.className = "messageboxMessage";
	this.MessageDiv.appendChild(document.createTextNode(message));

	this.Win.addContent(this.MessageDiv);
	this.Win.addContent(document.createElement("br"));
	this.Win.addContent(document.createElement("br"));

	if (!type || type == 1)
	{
		button = new Button('Ja', action);
		this.Win.addContent(button.getButton());

		button = new Button('Nein', 'this.win.remove()');
		button.win = this.Win;
		this.defaultButton = button.getButton();
		this.Win.addContent(button.getButton());
	}
	if (type == 2)
	{
		if (!action)
			action = 'this.win.remove()';

		button = new Button('Ok', action);
		button.win = this.Win;
		this.defaultButton = button.getButton();
		this.Win.addContent(button.getButton());
	}

	this.Win.defaultButton = this.defaultButton;
	this.Win.onkeydown = function(e){ if (!e) e = window.event; if (e.keyCode == 13) this.defaultButton.onclick();}
	this.Win.show();
	this.defaultButton.focus();

}



function InputBox(message, defaultValue, reference, header, type)
{
	this.Win = new MessageWindow(header);

	this.MessageDiv = document.createElement("div");
	this.MessageDiv.className = "messageboxMessage";
	this.MessageDiv.appendChild(document.createTextNode(message));
	this.Win.addContent(this.MessageDiv);

	this.inputTag = document.createElement("input");
	this.inputTag.className = "messageboxInput";


	this.inputTag.defaultValue = defaultValue;
	if (document.all)
		this.inputTag.value = defaultValue;

	this.Win.addContent(this.inputTag);
	this.Win.addContent(document.createElement("br"));
	this.Win.addContent(document.createElement("br"));
	this.Win.addContent(document.createElement("br"));


	if (!type || type == 1)
	{
		button = new Button('Speichern', 'window.location.href=this.reference+\'/value/\'+this.inputtag.value');
		button.reference = reference;
		button.inputtag = this.inputTag;
		this.defaultButton = button;
		this.Win.addContent(button.getButton());

		button = new Button('Abbrechen', 'this.win.remove()');
		button.win = this.Win;
		this.Win.addContent(button.getButton());
	}

	this.inputTag.defaultButton = this.defaultButton;
	this.inputTag.onkeydown = function(e){ if (!e) e = window.event; if (e.keyCode == 13) this.defaultButton.onclick();}
	this.Win.show();

	this.inputTag.focus();
}


function ImageBox(header, name, reference)
{
	winTitle = header + ' ' + name;
	this.Win = new MessageWindow(winTitle, true);

	action = 'this.win.remove()';

	image = new Image(reference, action);
	image.win = this.Win;
	this.defaultImage = image.getImage();
	this.Win.addContent(image.getImage());

	this.Win.show();
}

function uploadForm(action)
{
	if (document.all)
	{
		newdiv = document.createElement("div");
		newdiv.id = "newdiv";
		innerHTMLStr = '<div class="messageboxBackground"></div><div class="messageboxBox"><div class="messageboxHeader">Datei hochladen</div><form method="post" action="'+action+'" enctype="multipart/form-data">';
		for (i = 0; i < 6; i++) {
			innerHTMLStr = innerHTMLStr + '&nbsp;<input name="file' + i + '" type="file"><br>';
		}
		innerHTMLStr = innerHTMLStr + '<br><br><br><span class="messageboxButton" onclick="submit();">Speichern</span><span class="messageboxButton" onclick="document.getElementById(\'newdiv\').parentNode.removeChild(document.getElementById(\'newdiv\'));">Abbrechen</span></form></div>';
		newdiv.innerHTML = innerHTMLStr;
		document.getElementById("body").appendChild(newdiv);
	}
	else
	{
		this.Formular = document.createElement("form");
		this.Formular.enctype = 'multipart/form-data';
		this.Formular.accept = '*/*';
		this.Formular.action  = action;
		this.Formular.method = 'post';


		this.Formular.Gosubmit = function(){ this.submit();

		}
		for (i = 0; i < 6; i++) {
			this.Formular.appendChild(document.createElement("br"));
			lblSpan = document.createElement("span");
			lblSpan.id = "lblSpan" + i;
			lblSpan.innerHTML = '&nbsp;';
			this.Formular.appendChild(lblSpan);

			this.upload = document.createElement("input");
			this.upload.type = 'file';
			this.upload.name = 'file' + i;
			//this.Formular.upl = this.upload;
			this.Formular.appendChild(this.upload);
		}

		this.Win = new MessageWindow('Datei hochladen');
		this.Win.addContent(this.Formular);
		this.Win.addContent(document.createElement("br"));
		this.Win.addContent(document.createElement("br"));
		this.Win.addContent(document.createElement("br"));
		this.Win.addContent(document.createElement("br"));

		button = new Button('Speichern', 'this.formular.Gosubmit()');
		button.formular = this.Formular;
		this.Win.addContent(button.getButton());

		button1 = new Button('Abbrechen', 'this.win.remove()');
		button1.win = this.Win;
		this.Win.addContent(button1.getButton());

		this.Win.show();
	}
}

function MailForm(eMailLabel,subjectLabel,messageLabel, hyperLink, senderName, reference, header, autocomplete, type)
{
	// the subject
	inputTag2DefaultValue = "Link auf Ihre Dateien bei eye-files.com";
	// the message
	inputTag3DefaultValue = senderName + " sendet Ihnen diesen Link zum Zugriff auf Ihre Dateien bei eye-files.com.\n\n" + hyperLink;

	this.Win = new MessageWindow(header);

	this.MessageDiv = document.createElement("div");
	this.MessageDiv.className = "mailFormMessage";

	this.Form = document.createElement("form");
	this.Form.method = 'post';
	this.Form.action = reference;
	this.Form.id = 'mailFormId';

	this.Form.appendChild(document.createElement("br"));
	lblSpan = document.createElement("span");
	lblSpan.id = "lblSpan1";
	lblSpan.innerHTML = '&nbsp;' + eMailLabel;
	this.Form.appendChild(lblSpan);
	this.Form.appendChild(document.createElement("br"));

	this.inputTag1 = document.createElement("input");
	this.inputTag1.className = "messageboxInput";
	this.inputTag1.name = "email_ac";
	this.inputTag1.id = "email_ac";
//	this.inputTag1.setAttribute("name","email_ac");
	this.inputTag1.style.width = "330px";

	this.autodiv = document.createElement("div");
	this.autodiv.id = "email_auto_complete";
	this.autodiv.name = "email_auto_complete";
//	this.autodiv.setAttribute("name","email_auto_complete");
	this.autodiv.className = "auto_complete";


	this.Form.appendChild(this.inputTag1);
	this.Form.appendChild(this.autodiv);
	this.Form.appendChild(document.createElement("br"));

	lblSpan = document.createElement("span");
	lblSpan.id = "lblSpan2";
	lblSpan.innerHTML = '&nbsp;' + subjectLabel;
	this.Form.appendChild(lblSpan);

	this.Form.appendChild(document.createElement("br"));
	this.inputTag2 = document.createElement("input");
	this.inputTag2.className = "messageboxInput";
	this.inputTag2.name = "subject";
	this.inputTag2.style.width = "330px";
	inputTag2DefaultValue = "Link auf Ihre Dateien bei eye-files.com";
	this.inputTag2.defaultValue = inputTag2DefaultValue;
	if (document.all)
		this.inputTag2.value = inputTag2DefaultValue;

	this.Form.appendChild(this.inputTag2);
	this.Form.appendChild(document.createElement("br"));

	lblSpan = document.createElement("span");
	lblSpan.id = "lblSpan3";
	lblSpan.innerHTML = '&nbsp;' + messageLabel;
	this.Form.appendChild(lblSpan);

	this.Form.appendChild(document.createElement("br"));
	this.inputTag3 = document.createElement("textarea");
	this.inputTag3.className = "messageboxInput";
	this.inputTag3.name = "message";
	this.inputTag3.style.width = "330px";
	this.inputTag3.style.height = "100px";
	this.inputTag3.defaultValue = inputTag3DefaultValue;
	if (document.all)
		this.inputTag3.value = inputTag3DefaultValue;

	this.Form.appendChild(this.inputTag3);
	this.MessageDiv.appendChild(this.Form);
	this.MessageDiv.appendChild(document.createElement("br"));

	this.Win.addContent(this.MessageDiv);


	this.Win.addContent(document.createElement("br"));
	this.Win.addContent(document.createElement("br"));


	if (!type || type == 1)
	{
		button = new Button('Senden', 'document.getElementById(\'mailFormId\').submit();');
		button.reference = reference;
		button.inputtag = this.inputTag1;
		this.defaultButton = button;
		this.Win.addContent(button.getButton());

		button = new Button('Abbrechen', 'this.win.remove()');
		button.win = this.Win;
		this.Win.addContent(button.getButton());
	}

	this.inputTag1.defaultButton = this.defaultButton;
	//this.inputTag1.onkeydown = function(e){ if (!e) e = window.event; if (e.keyCode == 13) this.defaultButton.onclick();}
	this.Win.show();

	this.inputTag1.focus();
	new Ajax.Autocompleter('email_ac', 'email_auto_complete', autocomplete, {tokens:','});
}
/*
function mailAccount(reference, header, type)
{
	this.Win = new MessageWindow(header);

	this.MessageDiv = document.createElement("div");
	this.MessageDiv.className = "mailFormMessage";

	this.Form = document.createElement("form");
	this.Form.method = 'post';
	this.Form.action = reference;
	this.Form.id = 'mailFormId';

	this.Form.appendChild(document.createTextNode("Username:"));
	this.Form.appendChild(document.createElement("br"));

	this.inputTag1 = document.createElement("input");
	this.inputTag1.className = "messageboxInput";
	this.inputTag1.name = "username";

	this.Form.appendChild(this.inputTag1);
	this.Form.appendChild(document.createElement("br"));

	this.Form.appendChild(document.createTextNode("Passwort:"));
	this.Form.appendChild(document.createElement("br"));
	this.inputTag2 = document.createElement("input");
	this.inputTag2.className = "messageboxInput";
	this.inputTag2.name = "password";

	this.Form.appendChild(this.inputTag2);
	this.Form.appendChild(document.createElement("br"));

	this.Form.appendChild(document.createTextNode("Server:"));
	this.Form.appendChild(document.createElement("br"));
	this.inputTag3 = document.createElement("input");
	this.inputTag3.className = "messageboxInput";
	this.inputTag3.name = "host";

	this.Form.appendChild(this.inputTag3);
	this.MessageDiv.appendChild(this.Form);
	this.MessageDiv.appendChild(document.createElement("br"));

	this.Win.addContent(this.MessageDiv);


	this.Win.addContent(document.createElement("br"));
	this.Win.addContent(document.createElement("br"));


	if (!type || type == 1)
	{
		button = new Button('Speichern', 'document.getElementById(\'mailFormId\').submit();');
		button.reference = reference;
		button.inputtag = this.inputTag1;
		this.defaultButton = button;
		this.Win.addContent(button.getButton());

		button = new Button('Abbrechen', 'this.win.remove()');
		button.win = this.Win;
		this.Win.addContent(button.getButton());
	}

	this.inputTag1.defaultButton = this.defaultButton;
	this.inputTag1.onkeydown = function(e){ if (!e) e = window.event; if (e.keyCode == 13) this.defaultButton.onclick();}
	this.Win.show();

	this.inputTag1.focus();
}
*/

