

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 protect()
{
    var vardet = document.forms[0].kampanj.value;
   
    if(vardet != null)
    {
        if(vardet != '')
        {
                        if(vardet == 'abrakadabra')
            {
                                window.location = "http://e.ahlsell.com/b.aspx?vi=12&vid=33&ucrc=3EA598E2";
            }
            else
            {
                                alert('Fel lösenord, försök igen.');
            }
           
        }
    }
   
}
function navOver(id){}
function navOut(id){}
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 < 250)
	{
		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 > 300 && document.getElementById('divStartNoAreaID'))
		{
			if(dxl < 250 && dxr > 250)
			{
				document.getElementById('divStartNoAreaID').style.clip = 'rect(auto ' + (dxl-30) + ' auto auto)';
			}
			else if(dxl < 30 && dxr > 30)
			{
				document.getElementById('divStartNoAreaID').style.clip = 'rect(auto auto auto ' + (dxr-30) + ')';
			}
		}
		else if(y > 300 && document.getElementById('divStartAreaID'))
		{
			if(dxl < 250 && dxr > 250)
			{
				document.getElementById('divStartAreaID').style.clip = 'rect(auto ' + (dxl-30) + ' auto auto)';
			}
			else if(dxl < 30 && dxr > 30)
			{
				document.getElementById('divStartAreaID').style.clip = 'rect(auto auto auto ' + (dxr-30) + ')';
			}
		}
		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 > 265)
			{
				if(dxl < 180 && dxr > 180)
				{
					document.getElementById('divNoRegionID').style.clip = 'rect(auto ' + (dxl-35) + ' auto auto)';
				}
				else if(dxl < 35 && dxr > 35)
				{
					document.getElementById('divNoRegionID').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('divStartAreaID'))
	{
		restoreClip('divStartAreaID');
	}
	else if(document.getElementById('divNoAreaID'))
	{
		restoreClip('divNoAreaID');
		restoreClip('divNoRegionID');
		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 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 myWindow;
	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();
}

function submitLogin()
{
	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();
}

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;
	if(!check || loginInfoEntered)
	{
		doLogin = true;
	}
	if(doLogin && document.forms[0].USER.value.length != 0 && document.forms[0].PWD.value.length != 0)
	{
		document.forms[0].action='JavaScript:submitLogin();';
	}
	return true;
}

function setLogin()
{
	loginInfoEntered = true;
}

function popLoginFromQS()
{
	var qs = document.location.search;
	if (qs.length > 0)
	{
		var a = qs.substring(1,qs.length).replace(/\+/g, ' ').split('&'), exec = false;
		for (var i=0;i<a.length;i++)
		{
			var v = a[i].split('=');
			if (v.length == 2)
			{
				switch(v[0])
				{
					case 'Usr':
					{
						document.forms[0].USER.value = unescape(v[1]);
						break;
					}
					case 'Pwd':
					{
						document.forms[0].PWD.value = unescape(v[1]);
						break;
					}
					case 'eStore':
					{
						if(v[1] == 'External')
						{
							exec = true;
						}
						break;
					}
				}
			}
		}
		if(exec)
		{
			submitLogin();
		}
	}
}
function doAjaxCallBack(res)
{
	document.getElementById('ajaxWin').innerHTML = res;
}
function ajaxSend(url, callback)
{
	function ajaxBindCallback()
	{
		if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200 && ajaxCallback)
		{
			ajaxCallback(ajaxRequest.responseText.toString());
		} 
	}

	var ajaxRequest = null;
	var ajaxCallback = callback;

	try
	{
		if(window.XMLHttpRequest) 
		{
			ajaxRequest = new XMLHttpRequest();
			ajaxRequest.onreadystatechange = ajaxBindCallback;
			ajaxRequest.open("GET", url, true);
			ajaxRequest.send(null);
		} 
		else if (window.ActiveXObject) 
		{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			if(ajaxRequest) 
			{
				ajaxRequest.onreadystatechange = ajaxBindCallback;
				ajaxRequest.open("GET", url, true);
				ajaxRequest.send();
			}
		}
		else
		{
			throw 'No AJAX support';
		}
	}
	catch(ajaxException)
	{
		window.open(url + '&Layout=1','ajaxWindow','width=430,height=180,scrollbars=1,resizable=1');
		document.getElementById('ajaxWin').style.display='none';
	}
	return (ajaxRequest != null);
}
function showAjaxMiddle(url)
{
	try
	{
		var currentMiddle = 0;
		if(document.documentElement && document.documentElement.clientHeight)
		{
			currentMiddle = document.documentElement.scrollTop + document.documentElement.clientHeight/2;
		}
		else
		{
			currentMiddle = document.body.scrollTop + document.body.clientHeight/2;
		}
		
		pW = document.getElementById('ajaxWin');
		pW.style.top = Math.round(currentMiddle - 200) + 'px';
		pW.innerHTML += 'Laddar...';

		pW.style.display = '';
		
		ajaxSend(url,doAjaxCallBack);
	}
	catch(Exception) {}
}
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,{}));