
// CSS init (c) Agents.se - v4.0
/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

// Open window
var newWin = null;
function popMeUp(strURL,strType,strWidth,strHeight) {
	if (newWin != null){
		if(!newWin.closed) newWin.close();
	}
	var left=((window.screen.width/2)-(strWidth/2))-12;
	var top=((window.screen.height/2)-(strHeight/2));
	var strOptions="";
	if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

// No spam e-mail address v2
function noSpam(a,b,c,d) {
	if (d==null) {
		d = c+'@'+b+'.'+a;
	}
	document.write('<a href="mai'+'lto:'+c+'@'+b+'.'+a+'" class="sticky">'+d+'</a>');
}

// Go to url
function go(url) {
	document.location.href = url;
}
function goselect(id) {
	go($("#"+id).val());
	return false;
}

// jQuery easeing
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeInOutExpo',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}
});

// jQuery setup on page load
$(document).ready(function() {
	autoblur();
});
function autoblur() {
	$("a").mouseup(function(){
		$(this).blur();
	});
}

// Cloak password field v2
function cloakpass(a,b,c) {
	d = b.split(":").join("_");
	switch(a) {
		case 0:
			e = "<input name=" + b + " id=" + d + " type=\"text\" value=\"L&ouml;senord\" size=\"8\" class=\"fstyle1\" onfocus=\"cloakpass(1, this.name, this.form.name);\" tabindex=\"11\">";
			cloakwrite(e);
		break;
		case 1:
			e = "<input name=" + b + " id=" + d + " type=\"password\" size=\"8\" class=\"fstyle1\" onblur=\"if(this.value==''){cloakpass(0, this.name, this.form.name);}\" tabindex=\"11\">";
			cloakwrite(e);
			document[c][d].focus();
			document[c][d].select();
			document[c][d].focus();
			document[c][d].select();
			document[c][d].focus();
			document[c][d].select();
		break;
	}
}
function cloakwrite(a) {
	document.getElementById("pwfield").innerHTML = a;
}

function showlogin() {
	$("#pwfield").slideDown(950);
	$("#flogin .fbutt3").animate({top:"24"}, 900);
	$("#flogin").animate({height:"52"}, 900, function() {
		$("#flogin").removeClass("fline");
		$("#nopass").show();
  });
	return false;
}
function hidelogin() {
	$("#nopass").hide();
	$("#flogin").addClass("fline");
	$("#pwfield").slideUp(950);
	$("#flogin .fbutt3").animate({top:"0"}, 900);
	$("#flogin").animate({height:"25"}, 900, function() {
		$("#flogin").addClass("fline");
//		$("#nopass").hide();
  });
	return false;
}


// Toggle div
/*function toggle2(a) {
	b = document.getElementById(a).style;
	if (b.display=="none") {
		b.display="block";
	} else {
		b.display="none";
	}
}*/
function toggle2(a) {
	if ($("#"+a).is(":hidden")) {
		$("#"+a).show();
	} else {
		$("#"+a).hide();
	}
	return false;
}
function toggleslide(a) {
	if ($("#"+a).is(":hidden")) {
		$("#"+a).slideDown(600);
	} else {
		$("#"+a).slideUp(600);
	}
	return false;
}
// Levsätt
function levsatt() {
	if ($("#levsatt input:radio:checked").val() == "2") {
		$("#levadress").slideUp(400);
	} else {
		$("#levadress").slideDown(400);
	}
}

// Ajax Capable Browser?
var xmlHttp=null;
function GetXmlHttpObject() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

// Inspiration panel, lagt tillbaka efter ny global.js från agents  /ML 2011-04-01
function goinspirationpanel(a, b, c) {
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            document.getElementById("ajaxpanel").innerHTML = xmlHttp.responseText;
        slimbox();}  //Robban la hit slimbox 2011-02-24
    if (c) { c = "&lrg=" + c; }
    xmlHttp.open("GET", "/Templates/StEriks/Pages/InspirationItemData.aspx?target=panel&cmd=" + a + "&aid=" + b + c + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
    return false;
}

// Product panel, ändrad som tidigare, efter ny global.js från agents  /ML 2011-04-01
function gopanel(a,b,c) {
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4)
		document.getElementById("ajaxpanel").innerHTML = xmlHttp.responseText;
        slimbox();}   //Hit lagt av Robban 2011-02-24
	if (c) {c = "&lrg="+c;}
	xmlHttp.open("GET", "/Templates/StEriks/Pages/ProductData.aspx?target=panel&cmd=" + a + "&aid=" + b + c + "&rnd=" + Math.random(), true);
	xmlHttp.send(null);
	return false;
}
// Product info/facts
function gocontent(a,b) {
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4)
		document.getElementById("ajaxcontent").innerHTML=xmlHttp.responseText;}
    xmlHttp.open("GET", "/Templates/StEriks/Pages/ProductData.aspx?target=content&cmd=" + a + "&aid=" + b + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
	return false;
}

// Product info/facts
function gocontent2(a, b, c) {
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            document.getElementById("ajaxcontent").innerHTML = xmlHttp.responseText;
    }
    if (c) { c = "&arg=" + c; }
    xmlHttp.open("GET", "/Templates/StEriks/Pages/ProductData.aspx?target=content&cmd=" + a + "&aid=" + b + c + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
    return false;
}

// lagt tillbaka efter ny global.js från agents  /ML 2011-04-01
function doFilter(pageId) {
    var args = "";
    var f1 = document.getElementById("fType");
    if (f1 && f1.selectedIndex > 0) {
        args += 'type:' + f1.options[f1.selectedIndex].value + ';';
    }

    var f2 = document.getElementById("fFormat");
    if (f2 && f2.selectedIndex > 0) {
        args += 'fmt:' + f2.options[f2.selectedIndex].value + ';';
    }

    var f3 = document.getElementById("fThickness");
    if (f3 && f3.selectedIndex > 0) {
        args += 'th:' + f3.options[f3.selectedIndex].value + ';';
    }

    var f4 = document.getElementById("fTrafficClass");
    if (f4 && f4.selectedIndex > 0) {
        args += 'tc:' + f4.options[f4.selectedIndex].value + ';';
    }

    var f5 = document.getElementById("fColor");
    if (f5 && f5.selectedIndex > 0) {
        args += 'col:' + f5.options[f5.selectedIndex].value + ';';
    }

    gocontent2('facts', pageId, args);
}

// lagt tillbaka efter ny global.js från agents  /ML 2011-04-01
function doAdd(pageId, num) {
    var args = "";
    var f1 = document.getElementById("fType");
    if (f1 && f1.selectedIndex > 0) {
        args += 'type:' + f1.options[f1.selectedIndex].value + ';';
    }

    var f2 = document.getElementById("fFormat");
    if (f2 && f2.selectedIndex > 0) {
        args += 'fmt:' + f2.options[f2.selectedIndex].value + ';';
    }

    var f3 = document.getElementById("fThickness");
    if (f3 && f3.selectedIndex > 0) {
        args += 'th:' + f3.options[f3.selectedIndex].value + ';';
    }

    var f4 = document.getElementById("fTrafficClass");
    if (f4 && f4.selectedIndex > 0) {
        args += 'tc:' + f4.options[f4.selectedIndex].value + ';';
    }

    var f5 = document.getElementById("fColor");
    if (f5 && f5.selectedIndex > 0) {
        args += 'col:' + f5.options[f5.selectedIndex].value + ';';
    }

    args += 'produktnr:' + num + ';';

    var f6 = document.getElementById("a_name" + num);
    if (f6) {
        args += 'antal:' + f6.value + ';';
    }

    var f7 = document.getElementById("ddl" + num);
    if (f7 && f7.selectedIndex >= 0) {
        args += 'sort:' + f7.options[f7.selectedIndex].value + ';';
    }

    window.setTimeout("bdummy()", 1500);
    window.setTimeout(function() { gocontent2('facts2', pageId, args); } , 1500);

}

// Popup pane
function gopopper(a) {
	repositionpopper();
	b=document.getElementById("ajaxpopper").style;
	b.display="block";
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4)
		document.getElementById("ajaxpopper").innerHTML=xmlHttp.responseText;}
    xmlHttp.open("GET", "/Templates/StEriks/Pages/CommonData.aspx?cmd=tell&url=" + a + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
	return false;
}
function repositionpopper() {
	b=document.getElementById("ajaxpopper").style;
	b.top=getScrollHeight()+140+"px";
}
function getScrollHeight() {
   var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
   return h ? h : 0;
}
function closepopper() {
	b=document.getElementById("ajaxpopper").style;
	b.display="none";
	return false;
}

//Hint a friend, tipsa ..
function sendEmail(you, from, to, msg, url) {
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            document.getElementById("ajaxmessage").innerHTML = xmlHttp.responseText;
    }
    xmlHttp.open("GET", "/Templates/StEriks/Pages/MailAfriend.aspx?target=content&name=" + you + "&from=" + from + "&to=" + to + "&msg=" + msg + "&url=" + url + "&rnd=" + Math.random(), true);
    xmlHttp.send(null);
    return false;
}

// jQuery setup on page load
$(document).ready(function() {
	initslide();
	autoblur();
	tooltip();
//	activatebasket();
});
function autoblur() {
	$(".fwrap input").click(function() {
		this.blur();
	});
	$("select").change(function() {
		$(this).blur();
	});
}

function goerror(a,b) {
	if (!a && !b) {
			go("default.aspx?timeout=true");
	} else {
		if(a.status==0){
//				alert("You are offline!\n Please Check Your Network.");
		}else if(a.status==404){
			alert("Requested URL not found.");
		}else if(a.status==408||b=="timeout"){
			go("default.aspx?timeout=true");
		}else if(a.status==500){
			alert("Internal Server Error. ("+b+")");
		}else {
			alert("Unknow Error: "+a.responseText);
		}
	}
}

function slimbox() {
	$("a[rel^='lightbox']").slimbox({  }, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
}

// Tooltip
this.tooltip = function(){
	$("span.tooltip").unbind();
	$("span.tooltip").hover(function(e){
		t = this.title;
		this.title = "";
		$("body").append("<div id='tooltip'>"+ t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY - 10) + "px")
			.css("left",(e.pageX + 20) + "px")
			.show()
    },
		function(){
			this.title = t;
			$("#tooltip").remove();
    });
	$("span.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - 10) + "px")
			.css("left",(e.pageX + 20) + "px");
	});
}


//addummy() ändrad av ML 2011-03-15
//Allt nedan är hit lagt av Robban 2011-02-24

function addummy() { //var Endast för att visa funktion, ta bort
    dialog_on('loadstatus', 0); //startar visa meddelande
}

// lagt till av ML 2011-03-15
//800 is wait 1 second showing 'klart', 700 is wait between panels?
function bdummy() {
    window.setTimeout(function() { dialog_on('loadstatus', 1, 800); }, 700); //var När ajax har laddat färdigt kör: dialog_on('loadstatus',1,x);
    return false;
}

function activatebasket(a) {
	if (!a) a = "";
	switch(a) {
		case "": dialog_on('activatestatus',0); break;
		case "avbryt": dialog_off('activatestatus'); break;
		case "spara":
			// In med spara ajax
			dialog_on('activatestatus',1,2000);
		break;
		case "aktivera":
			// In med aktivera ajax
			dialog_on('activatestatus',2,2000);
		break;
	}
	return false;
}
function tint(a) {
	a ? $("#tint").css({height:$(document).height()}).show() : $("#tint").hide();
}
function dialog_on(a,b,c) { // id, message, delay off
	tint(true);
	if($.browser.safari){bodyelem=$("body")}else{bodyelem=$("html")}
	$(window).height() > 800 ? g=170 : g=($(window).height()/2)-200;
	$("#"+a).css("top", g+bodyelem.scrollTop() + "px")
	$("#"+a).show();
	$("#"+a+" div").hide();
	$("#"+a+" div").eq(b).show();
	if (c)
	window.setTimeout(function(){dialog_off(a);},c);
	return false;
}
function dialog_off(a) {
	$("#"+a+" div").hide();
	$("#"+a).hide();
	tint(false);
	return false;
}

function closenote123(a) {
	$("#infobox"+a+" .fbutt").hide();
	$("#infobox" + a).slideUp(801);
//	var date = new Date();
//	date.setTime(date.getTime() + (days * 365));
//	var expires = "; expires=" + date.toGMTString();
	document.cookie = "ProductInfo123=hide; path=/";

/*	$.ajax({  Sätt flagga på servern för att inte visa note igen
		type:"POST",
		url:"data_note.aspx",
		data:"cmd=close&id="+a+"&rnd="+Math.random(),
		cache:false,
		success:function(b){
		},
		error:function(a,b){goerror(a,b);}
	});*/
	return false;
}

function closenote456(a) {
    $("#infobox" + a + " .fbutt").hide();
    $("#infobox" + a).slideUp(801);
//    var date = new Date();
//    date.setTime(date.getTime() + (days * 365));
//    var expires = "; expires=" + date.toGMTString();
    document.cookie = "ProductInfo456=hide; path=/";

    /*	$.ajax({  Sätt flagga på servern för att inte visa note igen
    type:"POST",
    url:"data_note.aspx",
    data:"cmd=close&id="+a+"&rnd="+Math.random(),
    cache:false,
    success:function(b){
    },
    error:function(a,b){goerror(a,b);}
    });*/
    return false;
}

// Slideshow v3
var slideID = null;
var timerID = null;
var timerPos = -980;
var sliding = false;
function slideshow(a) {
	if (a<9) {
		stopslide();
		playpause(0,slng[2]);
	} else {
		clearInterval(timerID);
		timerPos = -980;
		timerID = setInterval("timerslide()", 8330/49);
	}
	if (!sliding && !$("#slideshow ul li").eq(a-1).hasClass("current")) {
		sliding = true;
		var current = $("#slideshow ul li.current");
		var snavcur = $("#snav a.current");
		// use this to pull the divs in the order they appear in the markup
		if (a==9) {
			next = current.next().length ? current.next() : $("#slideshow ul li:first");
			snxt = snavcur.next().length ? snavcur.next() : $("#snav a:first");
			fadespeed = 400;
		} else {
			next = $("#slideshow ul li").eq(a-1);
			snxt = $("#snav a").eq(a-1);
			fadespeed = 50;
		}
		current.addClass("prev-current");
		snxt.addClass("current");
		snavcur.removeClass("current");

		if (!$.browser.msie || ($.browser.msie && $.browser.version >= 9.0)) { // No fancy fading for IE7/8
			$("div", current).css({opacity: 1.0}).animate({opacity: 0.0}, fadespeed*2.5);
			$("div", next).css({opacity: 0.0}).delay(fadespeed*1.1).animate({opacity: 1.0}, fadespeed*3.5, function() {
				if ($.browser.msie){this.style.removeAttribute('filter');} // Fixes antialiasing in IE7/IE8
			});
		}
		next.css({opacity: 0.0}).addClass("current").animate({opacity: 1.0}, fadespeed*3.5, "jswing", function() { // Fade in next slide
			current.removeClass("current prev-current");
			sliding = false;
		});
	}
	return false;
}
function initslide() {
	if ($("#slideshow").length) {
		slidelength = $("#slideshow ul li").length;
		if (slidelength>1) {
			$("#slideshow ul li div").css("bottom","50px");
			a = ' class="current"';
			b = "";
			for (i=1;i<=slidelength;i++) {
				b += '<a href=""'+a+' onclick="return slideshow('+i+');" title="'+slng[0]+' '+i+'"></a>'
				a = "";
			}
			$("#snav div").html(b);
			$("#snav div").mouseup(function() {
				$("a", this).blur();
			});
			toggleslide();
		} else {
			$("#snav").html("");
		}
	}
}
function timerslide() {
	timerPos+=20;
	$(".gecko #snav .timer").css({backgroundPosition:"2px "+timerPos+"px"});
	$("#snav .timer").css({backgroundPositionY:timerPos+"px"});
}
function toggleslide() {
	if (!slideID) {
		slideID = setInterval("slideshow(9)", 8330);
		timerID = setInterval("timerslide()", 8330/49);
		playpause(1,slng[1]);
	} else {
		stopslide();
		clearInterval(timerID);
		playpause(0,slng[2]);
	}
	return false;
}
function playpause(a,title) {
	if (a) {a="play";b="pause"} else {b="play";a="pause"};
	$("#splaypause").removeClass(a).addClass(b).attr("title",title);
}
function stopslide() {
	clearInterval(slideID);
	clearInterval(timerID);
	slideID = null;
	timerID = null;
	timerPos = -980;
	return false;
}

