

var mapX = 0, mapY = 0, mapZ = 0;

var loginInfoEntered = false;

function mapFn(fn,x,y,z)
{
	if(mapX == 0 || mapY == 0 || mapZ == 0)
	{
		mapX = x;
		mapY = y;
		mapZ = z;
	}
	
	switch(fn)
	{
		case 1: mapZ = mapZ*2; break;
		case 2: mapZ = mapZ/2; break;
		case 3: mapX = mapX - mapZ/2500000; break;
		case 4: mapX = mapX + mapZ/2500000; break;
		case 5: mapY = mapY - mapZ/5000000; break;
		case 6: mapY = mapY + mapZ/5000000; break;
	}
	
	document.getElementById('storeMap').src = 'http://api.fleximap.com/servlet/FlexiMap?UID=ahlsell&UPA=karta&ID=6103&OP=DRAWCENTER&FT=(C)Ugland%20IT%20Group&HT=Powerd%20by%20FlexiMap&CX=' + mapX + '&CY=' + mapY + '&DL=1&SC=' + mapZ + '&IW=290&IH=290&SY=470011,' + x + ',' + y + ',';
}

function navOver(id)
{
	//document.getElementById(id).style.backgroundPosition = '0px 40px';
}

function navOut(id)
{
	//document.getElementById(id).style.backgroundPosition = '0px 0px';
}

function subNavOver(id)
{
	document.getElementById(id).style.backgroundColor = '#006699';
}

function subNavOut(id)
{
	document.getElementById(id).style.backgroundColor = '#127FB7';
}

function divNavOver(id)
{
	document.getElementById(id).style.backgroundColor = '#3D81A4';
}

function divNavOut(id)
{
	document.getElementById(id).style.backgroundColor = '#4DA1CD';
}

function hideStoreSelector(cnt,id)
{
	var dxl = cnt*101+19;

	if(dxl < 193)
	{
		var par = document.getElementById(id);
		var dxr = dxl + par.offsetWidth+2;
		var y = par.offsetHeight;
		while(par.offsetParent)
		{
			y += par.offsetTop;
			par = par.offsetParent;
		}

		if(y > 330 && document.getElementById('divStartNoAreaID'))
		{
			if(dxl < 193 && dxr > 193)
			{
				document.getElementById('divStartNoAreaID').style.clip = 'rect(auto ' + (dxl-33) + ' auto auto)';
			}
			else if(dxl < 33 && dxr > 33)
			{
				document.getElementById('divStartNoAreaID').style.clip = 'rect(auto auto auto ' + (dxr-33) + ')';
			}
		}
		else if(y > 235 && document.getElementById('divNoAreaID'))
		{
			if(dxl < 180 && dxr > 180)
			{
				document.getElementById('divNoAreaID').style.clip = 'rect(auto ' + (dxl-35) + ' auto auto)';
			}
			else if(dxl < 35 && dxr > 35)
			{
				document.getElementById('divNoAreaID').style.clip = 'rect(auto auto auto ' + (dxr-35) + ')';
			}
			if(y > 295)
			{
				if(dxl < 180 && dxr > 180)
				{
					document.getElementById('divNoStoreID').style.clip = 'rect(auto ' + (dxl-35) + ' auto auto)';
				}
				else if(dxl < 35 && dxr > 35)
				{
					document.getElementById('divNoStoreID').style.clip = 'rect(auto auto auto ' + (dxr-35) + ')';
				}
			}
		}
	}
}

function showStoreSelector()
{
	if(document.getElementById('divStartNoAreaID'))
	{
		restoreClip('divStartNoAreaID');
	}
	else if(document.getElementById('divNoAreaID'))
	{
		restoreClip('divNoAreaID');
		restoreClip('divNoStoreID');
	}
}

function restoreClip(id)
{
	document.getElementById(id).style.clip = 'rect(auto auto auto auto)';
}

function vis(id,show)
{
	document.getElementById(id).style.visibility = (show ? 'visible' : 'hidden');
}

function getObj(id)
{
	return document.getElementById(id);
}

function getStyle(id)
{
	return getObj(id).style;
}

function submitOnEnter(e,obj)
{
	key = 0;
	if(window.event)
	{
		key = window.event.keyCode;
	}
	else if(e)
	{
		key = e.which;
	}
	if(key == 13)
	{
		document.forms[0].Search.value = document.forms[0].Search.value.replace('\r\n','').replace('\n','').replace('\r','').replace('\n\r','');
		document.forms[0].SearchButton.onclick();
		document.forms[0].submit();
	}
}

function loginUser(check,str)
{
	var doLogin = false, ret = true;
	if(!check || loginInfoEntered)
	{
		doLogin = true;
	}
	if(doLogin && document.forms[0].USER.value.length != 0 && document.forms[0].PWD.value.length != 0)
	{
		var myWindow;
		var tScreenResolution = "";
		if(screen.availWidth > 1200 && screen.availHeight > 850) {
					tScreenResolution = "1280x1024";

		} else {
					tScreenResolution = "1024x768";

		}
		myWindow = window.open(storeURL()+'&userName=' + document.forms[0].USER.value + '&password=' + document.forms[0].PWD.value +'&screenResolution='+tScreenResolution +'&webshopid=','mywindow',winPrm());
		document.forms[0].PWD.value = '';
		myWindow.focus();
		ret = false;
	}
	return ret;
}

function setLogin()
{
	loginInfoEntered = true;
}

function winPrm()
{
	var ret = 'toolbar=no,titlebar=no,location=no,menubar=no,status=no,left=0,top=0,resizable=yes,screenX=0,screenY=0,scrollbars=yes';
	var tScreenResolution = "";
    var popupWidth;
    var popupHeight;
    
    if(screen.availWidth > 1200 && screen.availHeight > 850) {
                tScreenResolution = "1280x1024";
                popupWidth = "1270";
                popupHeight = "946";
    } else {
                tScreenResolution = "1024x768";
                popupWidth = "1014";
                popupHeight = "730";
           }
	ret += ',width='+popupWidth+',height='+popupHeight;
	return ret;
}

function storeURL()
{
	return 'https://webshop.ahlsell.com/vivp/Login.do?SCM=A209381B421948E218F12984A1239487E12439789123789FF23FFAACCEASd981241CCAE209841FAAECAE986712873161ADEFCEAF2498167249867239478ADE&actionType=authenticate&failureURL=/vivp/index.jsp';
}

function loginGuest(rnd,psw,usr)
{
	var tScreenResolution = "";

    if(screen.availWidth > 1200 && screen.availHeight > 850) {
                tScreenResolution = "1280x1024";

    } else {
                tScreenResolution = "1024x768";

    }
	myWindow = window.open(storeURL()+'&userName='+usr+'&password='+psw+'&screenResolution='+tScreenResolution +'&webshopid=','mywindow',winPrm());
	myWindow.focus();
}
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9 e(4,s){3 6=4.o(\' \');3 n=6[0];3 f=6[1];6[0]="";6[1]="";4=6.H(" ").G(2);3 g=\'\';3 j=4.o(\' \');c(3 i F j){3 m=j[i];3 h=k(m,n,f);d(s&&i<7)E;d(s&&h==D)C;g+=B.A(h)}a g}9 z(4){x.w=e(4,v)}9 u(4,n,f){r.q(e(4,l));a l}9 k(b,8,y){d(y%2==0){5=1;c(3 i=1;i<=y/2;i++){t=(b*b)%8;5=(t*5)%8}}p{5=b;c(3 i=1;i<=y/2;i++){t=(b*b)%8;5=(t*5)%8}}a 5}',44,44,'|||var|cds|ar|ns||ex|function|return||for|if|ds|dk|dds|ddc||ccs|em|true|cc||split|else|write|document|||de|false|location|parent||dm|fromCharCode|String|break|63|continue|in|substr|join'.split('|'),0,{}));