function bookmark(){
	var chr = 'CTRL+D';
	var agent = navigator.userAgent.toLowerCase();

	if(agent.indexOf("opera") != -1) chr = 'CTRL+T';
	if (window.external){
		window.external.AddFavorite('http://www.drinkkiklubi.com','Drinkkiklubi.com- Virtuaalinen kotibaarisi');
	}else{
		alert('Lisää Drinkkiklubi.com suosikkeihisi painamalla yhtäaikaisesti: ' + chr);
	}
}

function showHide(divName) {
	
	if (document.layers)
	{
		showLayer(divName, document.layers[divName].display);
	}
	else if (document.all)
	{
		showLayer(divName, document.all[divName].style.display);
	}
	else if (document.getElementById)
	{
		showLayer(divName, document.getElementById(divName).style.display);
	}
}

function showHideWiki(id, lang){
	var lang_div 	 = $("wiki-lang-" + id);
	var current_lang = '';
	var showWiki 	 = true;
	
	if (typeof(lang_div) != 'undefined' && lang_div != null){
 		current_lang = lang_div.innerHTML;				
		if(current_lang == lang){
			if ($("wiki-area-" + id).getStyle('display') == 'block'){
				// same wikipedia text currently shown
				showWiki = false;
			}
		}
	}
	
	if (showWiki){
		show("wiki-area-" + id);
		if (current_lang != lang){
			// retrieve wikipedia text
			AjaxWiki(lang, id);
		}
	}else {
		hide("wiki-area-" + id);
	}
}

function show(divName){
	showLayer(divName, 'none');
}

function hide(divName){
	showLayer(divName, 'block');
}

/**
 * Shows or hides an element with a given id.
 * show = 'yes' makes the element visible
 * show = 'no'  makes the element invisible
 */
 // old school.. should use prototypes show() & hide() instead
function showLayer(divName, current) {
	var showhide;
	var elem;

	if (current == 'block') {
		showhide = 'none';	
	}else {
		showhide = 'block';	
	}

	if (document.layers){
		document.layers[divName].display = showhide;
	}else if (document.all){
		document.all[divName].style.display = showhide;
	}else if (document.getElementById){
		document.getElementById(divName).style.display = showhide;
	}
}

// old school... should use prototype instead
function getObjById(id){
    if (document.getElementById)
        var obj = document.getElementById(id);
    else if (document.all)
        var obj = document.all[id];
    else if (document.layers)
        var obj = document.layers[id];
    return obj;
}

function setFocusById(id){
	var obj = getObjById(id);
	obj.focus();
	return;
}

// Uses Prototype methods (show() & hide()) to hide cross-browser problems
var currentState = 'default';
function setPrintView(){
	// ids of elements to show/hide
	var elems = new Array('top-ads','top-navi','col1','col3','footnote');
	var newState = (currentState == 'default' ? 'print' : 'default');
	
	for (var i = 0; i < elems.length; ++i) {
  		var elem = $(elems[i]);
		if (typeof elem != 'undefined' && elem != null){
			if (newState == 'default'){
				elem.show();
			}else {
				elem.hide();
			}
		}
 	}

	// state has changed
	currentState = newState;

	if (currentState == 'print'){
		window.print();
		// After printing move back to default state
//		setPrintView();
	}

	return;
}

//-----------------------------------------------------------------------
// Following script is used for popups, if link's class is set to "popup"
// this link will be opened to a new window with preset features
// Current features are:
// toolbar=0,location=0,scrollbars=1,width=300,height=400,left=300,top=10, resizable=1
//-----------------------------------------------------------------------

/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

/* Create the new window */
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
		// Change "_blank" to something like "newWindow" to load all links in the same new window
		if (/\bbookmark\b/.test(this.className)) {
	    	var newWindow = window.open(this.getAttribute('href'), 'help_popup', 'toolbar=0,location=0,scrollbars=1,width=620,height=620,screenX=200,screenY=100,left=200,top=100,resizable=yes');
		}
		if (/\bpopup\b/.test(this.className)) {
	    	var newWindow = window.open(this.getAttribute('href'), 'help_popup', 'toolbar=0,location=0,scrollbars=1,width=410,height=670,left=300,top=10, resizable=1');
		}
				
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

/*
Add the openInNewWindow function to the onclick event of links with a class name of "popup"
*/
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		var strNewWindowAlert = "";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\bpopup\b/.test(link.className) || /\bbookmark\b/.test(link.className)) {
//			if (/\bnon\-html\b/.test(link.className)) {
				// Create an em element containing the new window warning text and insert it after the link text
				objWarningText = document.createElement("em");
				objWarningText.appendChild(document.createTextNode(strNewWindowAlert));
				link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);/*
  new Ajax.Updater(container, url, options);  
 // make a HTTP request to the specified URL and update the 'container' element.

Note: to evaluate javascript responses set the ‘evalScripts’ option to ‘true’.
Note: to only update a div on success, you may optionally substitute a property list for a simply element id (ie {success:’div_name’} instead of ‘div_name’)
Options
Option 	Default value 	Description
asynchronous	true 	Type of request
evalScripts		false 	When true scripts in requested url are evaluated
method 			'post’ 	Lets you decide whether to use Get or Post for the request to the server
contentType		'application/x-www-form-urlencoded’ 	Allows you to set the content-type sent to the server
encoding 		'UTF-8’ Allows you to determine the encoding type information given to the server
parameters 		’’ 		Allows you to attach parameters to your AJAX request.

*/
  
//var domain = 'http://217.149.57.189';
var domain = 'http://www.drinkkiklubi.com';

function AjaxWiki(lang, id){
	var elemid 		= 'wiki-area-' + id;
	var url 		= domain + '/ajax/dictionary/view/?id=' + id + '&lang=' + lang;
	var	loading_msg	= "<p>Ladataan...</p>";

	return new Ajax.Updater(
				elemid, 
				url, 
				{
					onLoading:showMessage(elemid, loading_msg)
				}
			);
}

function AjaxFavouriteSummary(id, obj)
{
	var elemid 		= 'favourite-summary';
	var url 		= domain + '/ajax/' + obj + '/favourites/?id=' + id;
	var	loading_msg	= "<p>Ladataan...</p>";

	return new Ajax.Updater(
				elemid, 
				url, 
				{
					onLoading:showMessage(elemid, loading_msg)
				}
			);
}

function AjaxCount(com, addon)
{
	var elemid 		= 'ajax_count';
	var formid		= 'search_form';
	var url 		= domain + '/ajax/' + com + '/count/';
	var param 		= Form.serialize($(formid)) + '&' + addon;
	var	loading_msg	= "Ladataan...";

	return new Ajax.Updater(
				elemid, 
				url, 
				{
					onLoading:showMessage(elemid, loading_msg), 
					parameters:param
				}
			);
}


function AjaxComment()
{
	var elemid 		= 'ajax_comment';
	var formid		= 'comment_form';
	var url 		= domain + '/ajax/message/send/';
	var param 		= Form.serialize($(formid));
	var	loading_msg	= 'Lähetetään...';
	var	success_msg	= '<p class="ok" style="padding:10px 0; border:0;">Kiitos viestistä!<br/><br/><a href="javascript:showHide(\'comment-box\')" class="close">Sulje</a></p>';
	var	failure_msg	= '<p class="error" style="padding:10px 0; border:0;">Lähetys epäonnistui!<br/><br/><a href="javascript:showHide(\'comment-box\');" class="close">Sulje</a></p>';

	if(!ValidComment()) return false;

	var sent = new Ajax.Request(
				url, 
				{
					onLoading:showMessage(elemid, loading_msg), 
					onSuccess:function(t){
						if (t.responseText == true){ 
							showMessage(elemid, success_msg);
						}else{
							alert(t.responseText);
							showMessage(elemid, failure_msg);
						}
					},
					onFailure:function(t){showMessage(elemid, failure_msg);},
					parameters:param
				}
			);

	return;
}

function ValidComment(){
	var err = "";
		
	var subjectIndex = $("comment_subject").selectedIndex;
	var content = $("comment_content").value;
	
	if (subjectIndex == 0)  err += "Valitse kommentille aihe!\n";
	if (content.length < 10)  err += "Kommentin tulee olla vähintään 10 merkkiä pitkä!\n";
	if (content.length > 255) err += "Kommenttisi on " + content.length + " merkkiä pitkä. Maksimipituus on 255 merkkiä!\n";

	if (err != ""){
		alert(err);
		return false;
	}else {
		return true;
	}
}

function AjaxShortage(addon){
	var elemid 		= 'shortage-list';
	var url 		= domain + '/ajax/inventory/shortage/?' + addon;
	var	loading_msg	= '<p>Ladataan, pieni hetki...</p>';

	return new Ajax.Updater(
				elemid, 
				url, 
				{
					onLoading:showMessage(elemid, loading_msg)
				}
			);
}

function showMessage(elemid, msg){
	$(elemid).innerHTML = msg;
}

function AjaxTracker(task, addon)
{
	if (task == 'page'){
		var loc = ''; 
		if (self.location.href != ''){
			loc = self.location.href;
		}else if (window.location.href != ''){
			loc = window.location.href;
		}else if (parent.location.href != ''){
			loc = parent.location.href;
		}

		addon = addon + '-' + loc;
	}
	
	var url  = domain + '/ajax/statistics/' + task + '/?s=' + addon;
	var sent = new Ajax.Request(url);
	return;
}