// $Header: /home/sb/cvsroot/templates-lang/__SYS__/SB.js,v 1.6 2005/09/14 14:53:55 martin Exp $
// This file should be included in the bottom frameset page with a line similar to the below
// 	<script language="JavaScript" src="/__SYS__/SB.js" type="text/javascript"></script>


// Funktion för vykort
var vykortWin = null;

function vykort( product_id, category_id )
{

	if( vykortWin != null && !vykortWin.closed) {
		vykortWin.focus();
	}
	url = "vykort/vykort.htm?product_id=" + product_id + "&category_id=" + category_id;
	vykortWin = window.open(url, "vykort", "left=0,top=0,width=585,height=530,dependent,resizable=yes");

}

// funktion för att visa originalbilder i eget fönster
function fullsize_pic( name, url, width, height )
{
	var left = 0;
	var top  = 0;
	var win = window.open('', 'BigPic', 'width='+width+',height='+height+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=yes');
	var ePen ='<html><head><title>'+name+'</title></head>'; 
	ePen += '<body text="black" bgcolor="white" leftmargin=0 topmargin=0 onBlur="self.close()">';
	ePen += '<img src="'+escape(url)+'">';
	ePen += '</body></html>';
	var wd = win.document;
	wd.open();
	wd.write(ePen);
	wd.close();
}



// Från Macromedia Dreamweaver, används av debug funktionen
function MM_findObj(n, d) { //v4.01
	var p,i,x;  
	if(!d) 
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById)
		x=d.getElementById(n);
	return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+2];
			if (obj.style) { 
				obj=obj.style;
				v=(v=='show')?'visible':(v='hide')?'hidden':v;
			}
			obj.visibility=v;
		}
}

function ShowHide( myDoc, Id, action )
{
  myDoc.getElementById(Id).style.visibility = action;
}

/* eMenu
 * menuExpandable2.js - implements an expandable menu based on a HTML list
 * Original Author: Dave Lindquist (dave@gazingus.org)
 * Made up to snuff by Svenskabutiker AB (martin@svenskabutiker.se)
 */

var eMenuDocument = null;
var eMenuSelected = null;
var eMenuState = new Object();
//if (!document.getElementById)
//    document.getElementById = function() { return null; }


function eMenuInit(myDoc, menuId) {
	eMenuDocument = myDoc;
	var menu = eMenuDocument.getElementById(menuId);
	var obj, submenu;
	if (menu == null) return;
 //   if (window.opera) return; // I'm too tired

	var elem =  menu.getElementsByTagName("a");
	for( var i=0; i < elem.length; i++ ) {
		obj = elem[i];
		if( obj.className == "actuator" ) {
			submenu = obj.parentNode.getElementsByTagName("ul")[0];
			if( eMenuState[submenu.parentNode.id] ) { // Display
				obj.parentNode.style.backgroundImage = "url(/__SYS__/minus.gif)";
				submenu.style.display = "block";
			} else { // Hide - this is default in the stylesheet, no work needs to be done
//	      obj.parentNode.style.backgroundImage = "url(/__SYS__/plus.gif)";
//        submenu.style.display = "none";
			}
			obj.onclick = eMenuClick;
		}
	}
	if(eMenuSelected)
		eMenuShowSelect(eMenuSelected);
}

function eMenuClick() {
	var submenu = this.parentNode.getElementsByTagName("ul")[0];
	var display = submenu.style.display;

	if( display == "block" ) { // is open
		this.parentNode.style.backgroundImage = "url(/__SYS__/plus.gif)";
		submenu.style.display = "none";
		delete eMenuState[this.parentNode.id];
	} else {
		this.parentNode.style.backgroundImage = "url(/__SYS__/minus.gif)";
		submenu.style.display = "block";
//		alert("ADD: " + this.parentNode.id);
		eMenuState[this.parentNode.id] = 1;
	}

	return false;
}

function eMenuShowSelect( id ) {
	var obj;

	if(!eMenuDocument) return null;

	if( eMenuSelected ) 
		eMenuDocument.getElementById( eMenuSelected ).className = null;

	obj = eMenuDocument.getElementById( id );
	if(!obj) return null;
	obj.className = "selected";
	eMenuSelected = id;

	while( obj.className != "menu" ) {
		if( obj.className == "submenu" ) 
			obj.style.display = "block";
		if( obj.className == "menubar" ) {
			obj.style.backgroundImage = "url(/__SYS__/minus.gif)";
//		alert("ADD: menubar " + obj.id);
			eMenuState[obj.id] = 1;
		}
		obj = obj.parentNode;
	}
}	

/**************** General cooke handling functions ****************/

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

// Function glow & noglow works on images and buttons with src named as follows
// image1.ext  - Button up normal state
// image2.ext  - Buttoun down glow state
// Example button:
// <input name="PROJECT2" type="image" src="/bilder/forts1.jpg" width="100" height="30" id="knapp1" onmouseover="glow('knapp1')" onmouseout="noglow('knapp1')" />
function glow(Id, doc)
{
 if( !doc ) doc = document;
 
 obj = doc.getElementById(Id);
 var s = obj.src;
 obj.src = s.replace(/1\./, "2.");
}
function noglow(Id, doc)
{
 if( !doc ) doc = document;
 
 obj = doc.getElementById(Id);
 var s = obj.src;
 obj.src = s.replace(/2\./, "1.");
}

// Functions to keep track of windows that needs to be updated when status changes

var update;
var update_url;
function registerUpdateStatus(win, url) {
	if( url ) {
		update_url = url
    } else {
		tmp = new String(win.location)
		update_url = tmp.match( /([^?]+)/i )[0]
	}
	update = win;
}

function updateStatus(no_update) {
    if( !no_update && update_url) 
	  update.location = update_url;
}
