	var MAIN_WINDOW = null;

	var IDCARD = null;
	var IDCARD_URL = "idcard.php?";
	var IDCARD_WIDTH = 420;
	var IDCARD_HEIGHT = 245;
	var IDCARD_POSX = 200;
	var IDCARD_POSY = 200;

	var MSGBOX = null;
	var MSGBOX_URL = "shortmsg.php?";
	var MSGBOX_WIDTH = 340;
	var MSGBOX_HEIGHT = 400;
	var MSGBOX_POSX = 200;
	var MSGBOX_POSY = 200;
	var MSGBOX_SENDER_WIDTH = 300;
	var MSGBOX_SENDER_HEIGHT = 200;
	var MSGBOX_SENDER_POSX = 220;
	var MSGBOX_SENDER_POSY = 240;

	var CBOX_URL = "contacts.php?";
	var CBOX_WIDTH = 320;
	var CBOX_HEIGHT = 400;
	var CBOX_POSX = 150;
	var CBOX_POSY = 150;

	function updateWindowRefs()
	{
		if (MAIN_WINDOW == null || MAIN_WINDOW.closed == true) {
			MAIN_WINDOW = null;
			try {
				if (self.opener != null && self.opener.closed == false && self.opener.updateWindowRefs) {
					self.opener.updateWindowRefs();
					if (self.opener.MAIN_WINDOW != null && self.opener.MAIN_WINDOW.closed == false) {
						MAIN_WINDOW = self.opener.MAIN_WINDOW;
					}
					if (IDCARD == null || IDCARD.closed == true) {
						IDCARD = opener.IDCARD;
					}
					if (MSGBOX == null || MSGBOX.closed == true) {
						MSGBOX = opener.MSGBOX;
					}
				}
			} catch(e) {}
		}
		if (MAIN_WINDOW != null) {
			IDCARD = MAIN_WINDOW.IDCARD;
			MSGBOX = MAIN_WINDOW.MSGBOX;
		}
		if (IDCARD != null && IDCARD.closed == true) {
			IDCARD = null;
		}
		if (MSGBOX != null && MSGBOX.closed == true) {
			MSGBOX = null;
		}
	}

	function open_main(url)
	{
		updateWindowRefs();
		if (MAIN_WINDOW != null) {
			MAIN_WINDOW.location.href = url;
			MAIN_WINDOW.focus();
		} else {
			MAIN_WINDOW = window.open(url, 'Xksd83hsaKJLsdfciaobella');
		}
		return MAIN_WINDOW;
	}

	function open_main_close(url)
	{
		var win = open_main(url);
		win.focus();
		self.close();
	}

	function IDCard(user_id, user_name)
	{
		updateWindowRefs();
		var url = IDCARD_URL;
		if (user_id != undefined) {
			url += "&user_id=" + encodeURIComponent(user_id);
		} else if (user_name != undefined) {
			url += "&user_name=" + encodeURIComponent(user_name);
		}
		var opener = (MAIN_WINDOW != null ? MAIN_WINDOW : window);
		var idcard = window.open(url, "idcard", "width="+IDCARD_WIDTH+",height="+IDCARD_HEIGHT+",screenX="+IDCARD_POSX+",screenY="+IDCARD_POSY
				+",resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=no");
		if (MAIN_WINDOW != null) {
			MAIN_WINDOW.IDCARD = idcard;
		} else {
			IDCARD = idcard;
		}
		return idcard;
	}

	function ImageBox(url, width, height, title, stretch)
	{
		updateWindowRefs();
		var imgbox = window.open(url, "_blank",
				"width="+(width+20)+",height="+(height+(stretch==true ? 35 : 20))+",screenX=100,screenY=100"
				+",resizable=yes,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=no");
		if (MAIN_WINDOW != null) {
			imgbox.MAIN_WINDOW = MAIN_WINDOW;
		} else {
			imgbox.MAIN_WINDOW = window;
		}
		try {
			var doc = imgbox.document;
			doc.open();
			doc.write("<html><head></head>"
					+ "<body style=\"background-image: url('img/page-layout/background.jpg'); margin:10px;\" onclick=\"window.setTimeout('self.close()', 10);\">"
					+ "<img id='image' src='"+url+"' width='"+width+"' height='"+height+"' />"
					+ (stretch==true ?
					 "<br/><div style='float:right;padding-right:10px;padding-top:6px;color:black;font-family:Arial,sans serif;font-size: 8pt'>"
					 + "<img src='/img/page-layout/arrow_orange.gif' style='vertical-align:middle' alt='' /> "
					 + "<a href=\"javascript:"
					  + "void(window.open("
					   + "'/mm/applets/stretch.php?src="+encodeURIComponent(url)
					   + "&width="+encodeURIComponent(width)+"&height="+encodeURIComponent(height)+"',"
					   + " '_blank',"
					   + "'width="+(width+25)+",height="+(height+50)+",screenX=100,screenY=100"
					   + ",status=yes,resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=no'));\""
					 + " style='color:black;'>Foto &quot;verschönern&quot;</a></div>"
					: "")
					+ "</body></html>");
			doc.close();
			if (title != undefined) {
				doc.title = title;
				doc.image.alt = title;
				doc.image.title = title;
			}
		} catch(e) {}
		return imgbox;
	}

	function MsgBox(user_id, user_name)
	{
		updateWindowRefs();
		var url = MSGBOX_URL;
		var windowName;
		var width = MSGBOX_SENDER_WIDTH;
		var height = MSGBOX_SENDER_HEIGHT;
		var opener;
		var dependent;
		var pos;
		if (user_id != undefined) {
			url += "&user_id=" + encodeURIComponent(user_id);
			windowName = "msgbox_sender_"+user_id;
			dependent = "yes";
			pos = "screenX="+MSGBOX_SENDER_POSX+",screenY="+MSGBOX_SENDER_POSY+",";
			opener = MsgBox();
		} else if (user_name != undefined) {
			url += "&user_name=" + encodeURIComponent(user_name);
			windowName = "msgbox_sender_"+user_name;
			dependent = "yes";
			pos = ",="+MSGBOX_SENDER_POSX+",screenY="+MSGBOX_SENDER_POSY+",";
			opener = MsgBox();
		} else {
			if (MSGBOX != null && MSGBOX.closed == false) {
				MSGBOX.focus();
				return MSGBOX;
			} else if (MAIN_WINDOW != null && MAIN_WINDOW.MSGBOX != null && MAIN_WINDOW.MSGBOX.closed == false) {
				MAIN_WINDOW.MSGBOX.focus();
				return MAIN_WINDOW.MSGBOX;
			}
			windowName = "msgbox";
			width = MSGBOX_WIDTH;
			height = MSGBOX_HEIGHT;
			dependent = "no";
			pos = "screenX="+MSGBOX_POSX+",screenY="+MSGBOX_POSY;
			opener = window; //(MAIN_WINDOW != null ? MAIN_WINDOW : window);
		}
		var msgbox = opener.open(url, windowName, "width="+width+",height="+height+","+pos
				+"resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent="+dependent);
		if (windowName == "msgbox") {
			if (MAIN_WINDOW != null) {
				MAIN_WINDOW.MSGBOX = msgbox;
			} else {
				MSGBOX = msgbox;
			}
		}
		return msgbox;
	}

	function ContactsBox(query_string)
	{
		updateWindowRefs();
		var url = CBOX_URL + query_string;
		var opener = (MAIN_WINDOW != null ? MAIN_WINDOW : window);
		var cbox = window.open(url, "contacts", "width="+CBOX_WIDTH+",height="+CBOX_HEIGHT+",screenX="+CBOX_POSX+",screenY="+CBOX_POSY
				+",resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=no");
		cbox.focus();
		return cbox;
	}

	function ContactsBox_addContact(user_id, contact_type)
  	{
  		updateWindowRefs();
		var cbox;
		cbox = window.open("", "contacts", "width="+CBOX_WIDTH+",height="+CBOX_HEIGHT+",screenX="+CBOX_POSX+",screenY="+CBOX_POSY
				+",resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=no");
		var form = document.createElement("form");
		document.documentElement.appendChild(form);
		with(form) {
			target = "contacts";
			method = "post";
			action = CBOX_URL+"&action=add&contacts-form[user_ids][]="+user_id+"&contacts-form[contact_type]="
					+ (contact_type == "friend" ? "1" : (contact_type == "ignore" ? "-1" : "0"));
			
			submit();
		}
		document.documentElement.removeChild(form);
		try {
			cbox.focus();
		} catch(e) {}
		return cbox;
  	}

  	function Tell_a_Friend_Window()
  	{
		window.open("tellafriend.php", "tell_a_friend_window",
				"width=350,height=460,screenX=250,screenY=250"
				+",resizable=no,toolbar=no,menubar=no,locationbar=no,titlebar=no,scrollbars=no,dependent=yes");
  	}
