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() {
    if (!document.Form1.DDSize.options) {
        try {
            document.Form1.DDSize[0].parentNode.removeChild(document.Form1.DDSize[0]);
            var dvcolor = document.getElementsByName("dvcolor")
        }
        catch (x) {
        }
    }
	var selected = 0;
	var dvcolor = document.getElementById("dvcolor");
	var lblExclusive = document.getElementById("lblExclusive");
	dvcolor.innerHTML = "Color: <B>"+color+"</B>";
	var prodid = document.getElementById("VariantSKU")
	var saleimg = document.getElementById("imgSale")
	
	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];
		    if (lblExclusive) {
		        lblExclusive.innerHTML = Variants[x][4];
		    }
		    PrdName = Variants[x][3];
			if(saleimg)
			{
				if(Variants[x][2].substring(Variants[x][2].length-2) == "97")
				{
					saleimg.style.display = "inline";
				}
				else
				{
					saleimg.style.display = "none";
				}
			}
			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;
				}
			}
		}
	}
	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 updateSize(val)
{
	size = val;
}

function refreshColor() {

    if (!document.Form1.DDColor.options) {
        try {
            document.Form1.DDColor[0].parentNode.removeChild(document.Form1.DDColor[0]);
            document.Form1.qty[0].parentNode.removeChild(document.Form1.qty[0]);
        }
        catch (x) {
        }
    }
	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 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 = "";
		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 getNotification() {
    dv = document.getElementById("dvSizeNotification");
    dv.style.top = Number(document.body.scrollTop) + 150 + "px"
    var left = findPosition() - 225
    dv.style.left = left + "px"
    dv.style.display = "block";
}

function CloseNotification() {
    dv = document.getElementById("dvSizeNotification");
    dv.style.display = "none";
}

function UpdateNotificationImage() {
    for (i = 0; i < Colors.length; i++) {
        if (Colors[i][1] == document.Form1.ddNotification.options[document.Form1.ddNotification.selectedIndex].value) {
            document.getElementById("imgNotification").src = "http://www.tillys.com/tillys/images/catalog/thumb/" + Colors[i][0] + ".jpg";
            break;
        }
    }
}


function AddNotification() {
    var newsletter = document.getElementById("cbEmail").checked ? "1" : "0";
    var action = "?prod=" + document.getElementById("ddNotification").value + "&ctlg=" + ctlg + "&email=" + document.getElementById("txtNotificationEmail").value + "&n=" + newsletter;
    sndReqN(action)
}

function sndReqN(action) {
    http.open('get', '/tillys/notify.aspx' + action);
    http.onreadystatechange = handleResponseN;
    http.send(null);
}

function handleResponseN() {
    if (http.readyState == 4 && http.status == 200) {
        var response = http.responseText.replace(/^\s+|\s+$/g, '');
        if (response == "1") {
            document.getElementById("dvError").style.color = "blue";
            document.getElementById("dvError").innerHTML = "THANK YOU!<br /> We'll send you an email at " + document.getElementById("txtNotificationEmail").value + " if your size becomes available.";
            setTimeout("CloseNotification()", 3500);
        }
        else if (response == "0") {
            document.getElementById("validate").innerHTML = "Invalid email address";
        }
        else {
            document.getElementById("dvError").style.color = "red";
            document.getElementById("dvError").innerHTML = "There was an error processing your request. Please try again later.";
        }
    }
}

function ValidateNotification() {
    if (typeof (Page_Validators) == "undefined") {
        alert("no validation");
        return false;
    }
    alert("validation status: " + Page_IsValid)
    return false;
}

function popWindowSize()
{
	//alert(a);
	var target = "sizechart.htm";
	helpWin = window.open(target, "BlockedIPs", "height=425,width=855,screenx=0,screeny=0,dependent=yes,resizable=yes,scrollbars=yes,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],values[4])
	}
	return rtn
}

