function popWindow()
{
	//alert(a);
	var target = "/tillys/Imglargerview.aspx?prod="+PrdName;
	helpWin=window.open(target,"LargeView","height=580,width=635,screenx=0,screeny=0,dependent=yes,resizable=yes,scrollbars=yes,menubar=no,status=no,titlebar=no");
}

function selectSize()
{
	//alert("select size")
	size = document.Form1.DDSize.options[document.Form1.DDSize.selectedIndex].value;
	if (size == "")
	{
		refreshSize();
	}
	var dvcolor = document.getElementById("dvcolor")
	dvcolor.innerHTML = "Color: <B>"+color+"</B>";
}

function selectColor()
{
	//alert("select color")
	color = document.Form1.DDColor.options[document.Form1.DDColor.selectedIndex].value;
	refreshSize();
}

function refreshSize()
{
	//alert("refresh size")
	var selected = 0;
	var dvcolor = document.getElementById("dvcolor")
	dvcolor.innerHTML = "Color: <B>"+color+"</B>";
	var prodid = document.getElementById("VariantSKU")
	
	document.Form1.DDSize.options.length = 0;
	document.Form1.DDSize.options[0] = new Option("Select a Size","");
	for (x=0; x<Variants.length; x++)
	{
		if (Variants[x][0] == color)
		{
			prodid.innerHTML = Variants[x][3]
			var insize = 0;
			for (y=0; y<document.Form1.DDSize.options.length; y++)
			{
				if (document.Form1.DDSize.options[y].value == Variants[x][1])
				{
					insize = 1;
				}
			}
			if (insize == 0)
			{
				document.Form1.DDSize.options[document.Form1.DDSize.options.length] = new Option(Variants[x][1]+" - "+Variants[x][2],Variants[x][1]);
				//alert(Variants[x][1] +' '+ size)
				if (Variants[x][1] == size)
				{	
					selected = document.Form1.DDSize.options.length-1;
				}
			}
		}
	}
	//alert(selected);
	document.Form1.DDSize.options[selected].selected = true;
	if (document.Form1.DDSize.options.length == 2)
	{
		document.Form1.DDSize.options[1].selected = true;
		size = document.Form1.DDSize.options[1].value;
	}
}

function refreshColor()
{
	document.Form1.DDColor.options.length = 0;
	document.Form1.DDColor.options[0] = new Option("Select a Color","");
	for (x=0; x<Variants.length; x++)
	{
		if (size == "" || Variants[x][1] == size)
		{
			var incolor = 0;
			for (y=0; y<document.Form1.DDColor.options.length; y++)
			{
				if (document.Form1.DDColor.options[y].value == Variants[x][0])
				{
					incolor = 1;
				}
			}
			if (incolor == 0)
			{
				document.Form1.DDColor.options[document.Form1.DDColor.options.length] = new Option(Variants[x][0],Variants[x][0]);
				if (Variants[x][0] == color)
				{
					document.Form1.DDColor.options[document.Form1.DDColor.options.length-1].selected = true;
				}
			}
		}
	}
	if (document.Form1.DDColor.options.length == 2)
	{
		document.Form1.DDColor.options[1].selected = true;
		color = document.Form1.DDColor.options[1].value;
		if (size == "")
		{
			//alert("refresh color")
			refreshSize();
		}
	}
}

function updateSize(val)
{
	size = val;
}

function updateLarge(prod, colorname)
{
	PrdName = prod;
	LargeImg = prod+".jpg";
	color = colorname;
	refreshSize()
	for(x=0; x<document.Form1.DDColor.options.length; x++)
	{
		if(document.Form1.DDColor.options[x].value == color)
		{
			document.Form1.DDColor.options[x].selected = true;
		}
	}
	updateRollover();
}

function updateRollover()
{
	var dvRollover = document.getElementById("dvRollover");
	var tdRollover = document.getElementById("tdLargeRollover");
	try
	{
		dvRollover.innerHTML = "Additional Views:<BR>";
		dvRollover.style.display = "none";
		
		tdRollover.innerHTML = "";
		
		var valid = 0;
		
		for(i=0;i<Rollover.length;i++)
		{
			if(Rollover[i].substring(0,9) == PrdName)
			{
				valid++
				tdRollover.innerHTML += "<img src=\"/tillys/images/catalog/rollover/"+Rollover[i]+"\" onMouseOver=\"flip('popImgLarge', 'http://www.tillys.com/tillys/images/catalog/Large/"+Rollover[i]+"')\" style=\"margin-bottom:10px; margin-right: 5px\" class=\"on\" name=\"small\"><BR>\n";
				
				dvRollover.style.display = "block";
				dvRollover.innerHTML += "<img src=\"/tillys/images/catalog/rollover/"+Rollover[i]+"\" onMouseOver=\"flip('ImgMedium', 'http://www.tillys.com/tillys/images/catalog/300x300/"+Rollover[i]+"');LargeImg='"+Rollover[i]+"'\" style=\"margin:5px\" class=\"on\" name=\"popsmall\">\n";
				
			}
		}
		if(valid < 2)
		{
			tdRollover.innerHTML = "";
			dvRollover.innerHTML = "";
		}
	}
	catch(ex)
	{
	}
}

function popWindowSize()
{
	//alert(a);
	var target = "sizechart.htm";
	helpWin=window.open(target,"BlockedIPs","height=500,width=400,screenx=0,screeny=0,dependent=yes,resizable=no,scrollbars=no,menubar=no,status=no,titlebar=no");
	//return false;
}

function hideLarge()
{
	var dv = document.getElementById("dvImgLarge");
	dv.style.display = "none";
}

function showLarge()
{
	var img = document.getElementById("popImgLarge");
	img.src="http://www.tillys.com/tillys/images/catalog/large/"+LargeImg;
	var dv = document.getElementById("dvImgLarge");
	dv.style.display = "inline";
	dv.style.left = findPageWidth();
}

function findPageWidth()
{
  var width = 0, position = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    width = window.innerWidth;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    width = document.documentElement.clientWidth;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
    width = document.body.clientWidth;
  }
  position = (width/2)-459;
  if(position < 0)
  {
	position = 0
  }
  return position
}

function checkColorSizes()
{ 
	if((document.Form1.DDSize.value == "") && (document.Form1.DDColor.value == ""))
	{
	alert("Please select a size and color");
	return false;
	}
	else if(document.Form1.DDSize.value == "")
	{
	alert("Please select a size");
	return false;
	}
	else if(document.Form1.DDColor.value == "")
	{
	alert("Please select a color");
	return false;
	}
	return true;
}

function getArray(v)
{
	var rtn = new Array()
	var subarray = v.split("|")
	for(i=0;i<subarray.length;i++)
	{
		var values = subarray[i].split("%%")
		rtn[i] = new Array(values[0],values[1],values[2],values[3])
	}
	return rtn
}

