function stopPropagation(event)
{
	var event = event || window.event;
	
	event.cancelBubble = true;
	
	if (event.stopPropagation)
	{
		event.stopPropagation();
	}
}

var flagMenuFocus = false;
var timerHandle = false;
var doExit = false;

function focusFlagMenu()
{
	flagMenuFocus = true;
}

function hideFlagMenu()
{
	flagMenuFocus = false;
	
	var callback = function()
	{
		if (!flagMenuFocus)
		{
			document.getElementById("pulldown-menu").style.display = "none";
		}
	}
	
	timerHandle = setTimeout(callback, 1000);
	
	doExit = true;
}

function showFlagMenu()
{	
	if (doExit)
	{
		window.clearTimeout(timerHandle);
		doExit = false;
	}
		
	document.getElementById("pulldown-menu").style.display = "block";
	
	return false;
}

function replacePasswordField(obj)
{
	if (obj.type != "password")
	{
		var input = document.createElement("input");
		input.type = "password";
		input.name = obj.name;
		input.id = obj.id;
		input.className = obj.className;
		input.value = "";
		obj.parentNode.replaceChild(input, obj);
		input.focus();
	}
}

function openProductCompare(title)
{
	var params = {
		action: "productsToCompare",
		template: "webshop/products/compare/popup.tpl"
	};
	
	xajax.call("xajax_getHTML", {parameters: [params], context: 
	{
		callback: function(html)
		{
			var div = document.createElement("div");
			div.id = "compareContainer";
			div.className = "compare-container";
			div.innerHTML = html;
	
			divPopup("comparePopup", null, null, title, div);
		}
	}});
}

function switchToTab(selectedTab)
{
	if(selectedTab != currentTab)
	{
		var tab = document.getElementById(currentTab + "_tab");
		var content = document.getElementById(currentTab + "_content")
		
		if (tab && content)
		{
			tab.className = tab.className.replace("active", ""); 
			content.className = content.className.replace("active", "hidden");
		}	
		
		currentTab = selectedTab;
		
		tab = document.getElementById(currentTab + "_tab");
		content = document.getElementById(currentTab + "_content");
		
		if (tab && content)
		{
			tab.className += " active";
			content.className = content.className.replace("hidden", "active");;
		}
	}
}

function stopPropagation(event)
{
	var event = event || window.event;
	
	event.cancelBubble = true;
	
	if (event.stopPropagation)
	{
		event.stopPropagation();
	}
}

function openWindow(url)
{
	var nw = window.open(url, "mp3_speler", "width=350,height=168,scrollbars=0,toolbar=0,location=0,resizable=0,status=0");
	if(!nw)
		return false;
	
	// blank the page
	nw.document.write("");
	
	// load the template
	var template;
	
	// load parameters
	var params = {
		template: "layout/galleries/mp3_player_window.tpl"
	};
	
	xajax.call("xajax_getHTML", {parameters: [params], context: {
		callback: function(html)
		{
			template = html;
			nw.document.write(template);
			nw.document.close();
			
			var el = document.getElementById("pagePlayer");
			el.innerHTML = "";
			el.style.display = "none";
			
			return nw;
		}
	}});
}

function getTranslation(string, locale)
{
	var locale = locale || 0; //false
	
	xajax.call("xajax_getTranslation", {parameters: [string, locale], context: {
		callback: function(value)
		{
			alert(value);
		}		
	}});
}

function getTranslationConfirm(string, func, args)
{
	xajax.call("xajax_getTranslation", {parameters: [string], context: {
		callback: function(value)
		{
			var r = window.confirm(value)
			if (r == true)
			{
				func(args);
			}
			else
			{
				return false;
			}
		}		
	}});
}

function xajax_call(params)
{
	var div = document.getElementById(params.divId);
	if (div)
	{
		div.innerHTML = "";
		div.className = "loader";
		
		xajax.call("xajax_getHTML", {parameters: [params], context: {
			callback: function(html)
			{
				div.innerHTML = html;
				div.className = "";
			}		
		}});
	}
}

function switchVisible(id, titleLeft, titleRight)
{
	var elLeft = document.getElementById("left_" + id);
	var elRight = document.getElementById("right_" + id);
	var imgOver = document.getElementById("img_" + id + "_over");
	var imgOut = document.getElementById("img_" + id + "_out");
	
	imgOver.style.display == "none" ? imgOver.style.display = "block" : imgOver.style.display = "none";
	imgOut.style.display == "none" ? imgOut.style.display = "block" : imgOut.style.display = "none";
	
	elLeft.innerHTML == "&nbsp;" ? elLeft.innerHTML = titleLeft : elLeft.innerHTML = "&nbsp;";
	elRight.innerHTML == "&nbsp;" ? elRight.innerHTML = titleRight : elRight.innerHTML = "&nbsp;";
}

function onInit()
{
	if (window.g_showMessage != undefined && g_showMessage != "")
	{
		window.showMessage(g_showMessage);
	}
	
	var highlight = _GET("highlight");
	if (highlight)
	{
		x = document.getElementById("content") ? document.getElementById("content") : document.body;
		
		highlightText(highlight, "highlighted", x);
	}
}
