
// Flash and CSS init (c) Agents.se - v3.2

//var flashver = swfobject.getFlashPlayerVersion();
/*
CSS Browser Selector v0.2.7 *Modified by The Agents
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
*/
var css_browser_selector = function() {
	var
		ua=navigator.userAgent.toLowerCase();
		is=function(t){return ua.indexOf(t) != -1;},
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1)
			:is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('nt 5')?' xp':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

// 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(a) {
	document.location.href = a;
}

// 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);\">";
			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);}\">";
			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;
}

// Hide/Show 1 Div
function toggle(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;
}
// Levsätt
function levsatt() {
	if ($("#levsatt input:radio:checked").val() == "3") {
		$("#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
function goinspirationpanel(a, b, c) {
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            document.getElementById("ajaxpanel").innerHTML = xmlHttp.responseText;
    }
    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
function gopanel(a,b,c) {
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4)
		document.getElementById("ajaxpanel").innerHTML=xmlHttp.responseText;}
	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;
}

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);
    }

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 + ';';
    }
     
    gocontent2('facts2', pageId, args);
}


// 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() {
	autoblur();
	tooltip();
});
function autoblur() {
	$(".fwrap input").click(function() {
		this.blur();
	});
	$("select").change(function() {
		$(this).blur();
	});
}

// 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");
	});
}