﻿
var pids;
var multiShop = false;
function shopalot()
{
	multiShop = true;
	focusedFirst = false;
	for(i = 0; i < pids.length; i++)
	{
		var amnt = document.getElementById('amnt' + pids[i]);
		if (amnt != null)
		{
			document.getElementById('btn' + pids[i]).tabIndex = -1;
			document.getElementById('btn' + pids[i]).setAttribute("disabled", "disabled");
			document.getElementById('btn' + pids[i]).style.color = '#888888';
			document.getElementById('btn' + pids[i]).style.backgroundColor = '#cccccc';
			amnt.value = 0;
			if (!focusedFirst)
			{
				amnt.focus();
				amnt.select();
				focusedFirst = true;
			}
		}
		document.getElementById('mulitshopbtn').style.display = "table-row";
	}
}

function shopalot_add(pName)
{
	for(i = 0; i < pids.length; i++)
	{
		var amnt = document.getElementById('amnt' + pids[i]);
		if (amnt != null)
		{
			if (amnt.value > 0)
				window.top.modCart('add', pids[i], amnt.value, pName);
		}
	}
}

var displayStyle = "table-row";
if (navigator.userAgent.indexOf("MSIE 6") > 0 || navigator.userAgent.indexOf("MSIE 7") > 0)
{
	displayStyle = "inline";
}
var mayToggle = true;
var firstToggle = false;
function toggleVari(id)
{
	if (!mayToggle)
		return;
	mayToggle = false;
	setTimeout("mayToggle = true;", 150);
	
	var ee = document.getElementsByTagName("tr");
	var cc = 0;
	dspValue = 'none';
	
	if (document.getElementById('timg'+id) == null || document.getElementById('timg'+id).src.indexOf('toggle-expand.png') > 2)
	{
		dspValue = displayStyle;
	}
	if (dspValue == displayStyle)
	{
		iStart = 0;
		iStopLt = ee.length;
		iStopGt = -1;
		iFor = 1;
	}
	else
	{
		iStart = ee.length - 1;
		iStopLt = ee.length;
		iStopGt = -1;
		iFor = -1;
	}
	
	for (i = iStart; i < iStopLt && i > iStopGt; i+=iFor)
	{
		if (ee[i].getAttribute("myp") == id)
		{
			cc++;
			if (dspValue == displayStyle)
			{
				//ee[i].style.display = displayStyle;
				setTimeout("trToggle("+i+", '"+id+"')", 30*cc);
				document.getElementById('timg'+id).src = '/img/toggle.png';
			}
			else
			{
				setTimeout("trToggle("+i+", '"+id+"')", 25*cc);
				document.getElementById('timg'+id).src = '/img/toggle-expand.png';
			}
		}
	}
}

function trToggle(i, id)
{
	dspValue = displayStyle;
	if (document.getElementById('timg'+id) == null)
		return;
	
	if (document.getElementById('timg'+id).src.indexOf('toggle-expand.png') > 2)
	{
		dspValue = 'none';
		if (navigator.userAgent.indexOf("MSIE") > 0)
			document.getElementById('_ieximg').height -= 20;
	}
	else
	{
		if (navigator.userAgent.indexOf("MSIE") > 0)
			document.getElementById('_ieximg').height += 20;
	}
	
	var ee = document.getElementsByTagName("tr");
	ee[i].style.display = dspValue;
	
}

function amountInputUp(e, myIndex, tIndex, myId, myName)
{
	if (event == null)
		var event = e;
	
	if ((event.keyCode == 13 && multiShop) || event.keyCode == 40)
	{
		var ips = document.getElementsByTagName('input');
		for(i=myIndex;i<ips.length;i++)
		{
			if (ips[i].tabIndex == tIndex)
			{
				ips[i].focus();
				ips[i].select();
				break;
			}
		}
	}
	else if (event.keyCode == 13 && !multiShop)
	{
		window.top.modCart('add', myId, document.getElementById('amnt' + myId).value, myName, document.getElementById('omgMask'));
	}
}

function amountInputBlur(me, rInstock)
{
	if (multiShop && me.value > rInstock)
	{
		var _tmp = me.value;me.style.backgroundColor = '#ffc9c9';
		me.tag=_tmp + ' N/A';
		me.value = rInstock;
	}
	else
	{
		me.style.backgroundColor = '#ffffff';
		me.tag='';
	}
}

var loadedThumbs = {};
function swapThumb(id, src)
{
	
	if (navigator.userAgent.indexOf("MSIE 6") <= 0)
	{
		if (loadedThumbs[src] == null)
		{
			document.getElementById('pthumb-' + id).src = '/img/ajx_fff_000.gif';
			setTimeout("document.getElementById('pthumb-"+id+"').src = 'http://images.kamisport.se/adidas/thumb.png.php?type=list&img="+src+"';", 10);
			loadedThumbs[src] = 1;
		}
		else
		{
			document.getElementById('pthumb-'+id).src = 'http://images.kamisport.se/adidas/thumb.png.php?type=list&img=' + src;
		}
	}
	else
	{
		if (loadedThumbs[src] == null)
		{
			document.getElementById('pthumb-' + id).src = '/img/ajx_fff_000.gif';
			setTimeout("document.getElementById('pthumb-"+id+"').src = 'http://images.kamisport.se/adidas/thumb.jpg.php?type=list&img="+src+"';", 10);
			loadedThumbs[src] = 1;
		}
		else
		{
			document.getElementById('pthumb-'+id).src = 'http://images.kamisport.se/adidas/thumb.jpg.php?type=list&img=' + src;
		}
	}
}






function ppl(id, name, urlName)
{
document.write('	<table width="185" border="0" cellpadding="0" cellspacing="0" style="margin-right:5px;margin-bottom:15px;">');
document.write('		<tr>');
document.write('			<td colspan="2" valign="center" style="height:36px;background-image:url(\'img/img-productHeader.gif\');width:185px;color:#333;padding-left:10px;padding-right:10px;">');
document.write('				<div style="width:160px;overflow:hidden;height:18;"><div style="font-family:sans-serif;font-size:11px;width:500px;"><b>'+name+'</b></div></div>');
document.write('			</td>');
document.write('		</tr>');
document.write('		<tr>');
document.write('			<td colspan="2" style="border-left:1px solid #acacac;border-right:1px solid #acacac;" align="center" height="170">');
document.write('				<a href="/product_'+id+'.'+urlName+'.html"><img id="pthumb-'+id+'"');
document.write('					src="http://images.kamisport.se/adidas/thumb.png.php?type=list&img='+id+'.png" onLoad="this.style.background=\'url(img/blank.gif)\';" border="0" style="background-image:url(\'img/ajax4.gif\');background-position:center center;background-repeat:no-repeat;"');
document.write('				/></a>');
document.write('			</td>');
document.write('		</tr>');
document.write('		<tr style="height:45px;background-image:url(\'img/img-productFooter.gif\');background-position:0 bottom;background-repeat:no-repeat;">');
}

function pmpi(id, src)
{
	document.write('<table style="border:1px solid #fff;float:left;margin-left:0px;cursor:pointer;" onMouseOver="this.style.border=\'1px solid #aaa\';" onClick="swapThumb('+id+', \''+src+'\');" onMouseOut="this.style.border=\'1px solid #fff\';" OnNothing="swapThumb('+id+', \''+id+'.png\');" border="0" cellpadding="1" cellspacing="0" width="30" height="30"><tr><td valign="middle" align="center"><img src="http://images-2.kamisport.se/adidas/thumb.jpg.php?x=30&y=30&img='+src+'"></td></tr></table>');
}

var colorFilter = '';
function doScroll()
{
	var scnWid,scnHei;
	if (self.innerHeight) // all except Explorer
	{
		scnWid = self.innerWidth;
		scnHei = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		scnWid = document.documentElement.clientWidth;
		scnHei = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		scnWid = document.body.clientWidth;
		scnHei = document.body.clientHeight;
	}
	
	var imgList = document.getElementsByTagName('img');
	//alert(document.body.scrollTop + "\n" + document.body.scrollHeight + "\n" + scnHei + "\n");
	
	reach = document.body.scrollTop + scnHei;
	
	
	for (i=0;i<imgList.length;i++)
	{
		if (imgList[i].getAttribute("imgState") == "idle" && ((parseInt(imgList[i].getAttribute("pCount"))*266)+200 < reach || colorFilter != ''))
		{
			imgList[i].setAttribute("imgState", "loading");
			if (navigator.userAgent.indexOf("MSIE 6") <= 0)
			{
				imgList[i].src = imgList[i].getAttribute("pSource");
			}
			else
			{
				imgList[i].src = imgList[i].getAttribute("pSource").replace("thumb.png.php", "thumb.jpg.php");
			}
			fadeInImage(imgList[i].id);
		}
	}
}

function fadeInImage(imgId)
{
	var img = document.getElementById(imgId);
	
	if (img.getAttribute("imgState") != "loading")
		return;
	op = img.getAttribute("myOp");
	op = parseInt(op)+10;
	img.style.opacity = (op / 100);
	img.setAttribute("myOp", op);
	if (op < 100)
		setTimeout("fadeInImage('" + imgId + "');", 80);
}

var useCf = false;
function filterColor(_color, _act)
{
	if (!useCf)
		return;
	
	var tbls = document.getElementsByTagName("table");
	var colbox = document.getElementById('ds_colbox');
	if (colbox != null && _color != '')
	{
		colbox.style.visibility = 'visible';
		colbox.style.backgroundColor = _act;
		document.getElementById('dspAllColors').style.visibility = 'visible';
	} else {
		colbox.style.visibility = 'hidden';
		document.getElementById('dspAllColors').style.visibility = 'hidden';
	}
	
	for (i=0;i<tbls.length;i++)
	{
		_rsptc = tbls[i].getAttribute("_rsptc");
		
		if (_rsptc != null)
		{
			if (_rsptc.indexOf(_color) <= -1 && _color != '')
			{
				tbls[i].style.display = 'none';
			}
			else
			{
				if (navigator.userAgent.indexOf("MSIE") <= 0)
				{
					tbls[i].style.display = 'table';
				}
				else
				{
					tbls[i].style.display = 'inline';
				}
			}
		}
	}
	location=window.location.href.split('#')[0]+"#cf"+_act.replace("#","_");
	colorFilter = _color;
	doScroll();
}
