var menuStatus=0;
document.onmouseup = ProfileWinLocation;

/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */
  
var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, gb_width, gb_height)
{
	GB_HEIGHT = gb_height+35 || 400;
	GB_WIDTH = gb_width+10 || 400;
	if(!GB_DONE)
	{
		$(document.body).append("<div id=\u0022GB_overlay\u0022></div><div id=\u0022GB_window\u0022><div id=\u0022GB_caption\u0022></div>"
		+ "<img src=\u0022../images/close.gif\u0022 alt=\u0022Close window\u0022/></div>");
		
		$("#GB_window img").click(GB_hide);
		$("#GB_overlay").click(GB_hide);
		$(window).resize(GB_position);
		
		GB_DONE = true;
	}
	
	$("#GB_frame").remove();
	$("#GB_window").append("<iframe id=\u0022GB_frame\u0022 src=\u0022"+url+"\u0022></iframe>");
	$("#GB_caption").html(caption); 
	$("#GB_overlay").show();
	GB_position();
	
	$("#GB_window").slideDown("slow");
}

function GB_hide()
{
	$("#GB_window,#GB_overlay").hide();
}

function GB_position()
{
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	$("#GB_window").css(
	{
		width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
		left: ((w - GB_WIDTH)/2)+"px"
	});
	$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
}

/* Greybox Reduce End */

function openUserMedia(media, userstat, filetype, sx, sy,  admin)
{
	if (admin)
	{
		ahref = "getmedia.php?media_id="+media+url_separator+"thumb=false"+url_separator+"type="+filetype;
	}
	else
	{
		ahref = "getusermedia.php?media=" + media + url_separator + "userstat=" + userstat+url_separator+"type="+filetype;
	}
	
	if($(".product_image img").attr("src") == null)
	{
		GB_show("",ahref,sx,sy);
	}
	else
	{
		$(".product_image img").attr("src", ahref);
	}
}

function confirm_delete(text_string)
{
	var is_confirmed = confirm(text_string);
	if (is_confirmed){return true;}
	else { return false;}
}

function onlinewin()
{
	var windowprops = "location=0,scrollbars=1,menubar=0,toolbar=0,resizable=1,width=220,height=330,left=10";
	window.open(userIndex + url_separator + "site=online","onlinewindow", windowprops);
}

function openWindow(url_string, popup_name)
{
	var windowprops = "location=0,status=0,scrollbars=1,menubar=0,toolbar=0,resizable=1,width=800,height=700,left=20";
	window.open(url_string, popup_name, windowprops);
}


/*
* Browsererkennung
* @param name Name
*/
function checkBrowserName(name)
{  
	var agent = navigator.userAgent.toLowerCase();  
	if (agent.indexOf(name.toLowerCase())>-1)
	{  
		return true;  
	}  
	return false;  
}  

/**
 *
 * @access public
 * @return void
 **/
function showProfileContext(condata)
{
	var menuwindow=document.getElementById("UserContext");
	menuwindow.innerHTML = '<span id="UserContextHead">&nbsp;' + condata.header + '</span><br /><ul>';
	for(var i=0;i<condata.url.length;i++) {
		menuwindow.innerHTML += '<li><a href="' + userIndex + url_separator + condata.url[i] + url_separator + condata.oUID[i] + '" onClick="closeUserContext()">' + condata.link[i] + '</a><br /></li>';
	}
	menuwindow.innerHTML += '</ul><br />';
	menuwindow.style.visibility='visible';
	menuStatus=1;
    return false;
}

/**
 *
 * @access public
 * @return void
 **/
function ProfileWinLocation(e)
{
	var menuwindow=document.getElementById("UserContext");
	var posx, posy;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop+ document.documentElement.scrollTop;
	}
/*	menuwindow.style.left=(posx-10) + "px";
	menuwindow.style.top=(posy-5) + "px";
*/}

/**
 *
 * @access public
 * @return void
 **/
function hideProfileContext(e)
{
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	if (menuStatus==1) setTimeout("closeUserConetxt();",250);
	return;
}

function profilwin(other_UID)
{
	var windowprops = "location=0,status=0,scrollbars=1,menubar=0,toolbar=0,resizable=1,width=650,height=680,left=20"; 
	window.open(userIndex + url_separator + "site=profil" + url_separator + "other_UID=" + other_UID,"profil",windowprops);
}

/**
 *
 * @access public
 * @return void
 **/
function closeUserConetxt()
{
	document.getElementById('UserContext').style.visibility='hidden';
	menuStatus=0;
}


/**
 * hide/unhide search options used by the TForm-API
 *
 * @access public
 * @return void
 **/
function changeSearchOptions(elementID)
{
    if (document.getElementById("search_operator_"+elementID).value == "0")
    {
	document.getElementById("first_"+elementID).style.display = 'none';
    	document.getElementById("last_"+elementID).style.display = 'none';
    }
    else if (document.getElementById("search_operator_"+elementID).value == "1")
    {
		document.getElementById("first_"+elementID).style.display = 'inline';
	document.getElementById("last_"+elementID).style.display = 'inline';
    }
    else
    {
	document.getElementById("first_"+elementID).style.display = 'inline';
	document.getElementById("last_"+elementID).style.display = 'none';
    }
}
