var newlyloaded = 1;
var bAlreadyClicked = false;

function sizeclick(sel)
{
	UnavailableOff();
	if(document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className=="UnSiz"||document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className=="NoSiz")
	{
		UnavailableClick(document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').innerHTML,document.ProductDetails.hdnSelectedColor.value);
		var finished = new Boolean(false);
		var i = -1;
		while(finished != true)
		{
			i++;
			var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
			if (whichone != null)
			{
				if (whichone.className == 'SelSiz')
				{
					whichone.setAttribute("class", "Siz"); 
					whichone.setAttribute("className", "Siz");
				}
				if (whichone.className == 'NoSiz')
				{
					whichone.setAttribute("class", "UnSiz"); 
					whichone.setAttribute("className", "UnSiz");
				}
			}
			else
			{finished = true;}
		}

		document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').setAttribute("class", "NoSiz");
		document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').setAttribute("className", "NoSiz");

		document.ProductDetails.hdnSelectedSize.value = '';
		//document.getElementById("sizetext").innerHTML = '';
		//return;
	}
	
	var currElem = document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize');
	var itemselected = new Boolean(false);

	if(document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className!="UnSiz"&&document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className!="NoSiz")
	{
	itemselected = true;
	currElem.setAttribute("class", "SelSiz"); 
	currElem.setAttribute("className", "SelSiz");
	}
	var finished = new Boolean(false);
	var i = -1;
	while(finished != true)
	{
		i++;
		var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
		if (whichone != null)
		{
			if (i != (sel - 1) && whichone.className == 'SelSiz')
			{
				whichone.setAttribute("class", "Siz"); 
				whichone.setAttribute("className", "Siz");
			}
		}
		else
		{finished = true;}
	}
	
	if (itemselected == true)
	{
		var finished = new Boolean(false);
		var i = -1;
		while(finished != true)
		{
			i++;
			var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
			if (whichone != null)
			{
				if (whichone.className == 'NoSiz')
				{
					whichone.setAttribute("class", "UnSiz"); 
					whichone.setAttribute("className", "UnSiz");
				}
			}
			else
			{finished = true;}
		}
	}














	var validcolors = new Array(0);

	for (var i = 0; i < lookups.length; ++i)
	{
		var lookup = lookups[i];
		if (lookup.size == currElem.innerHTML)
		{
			if (lookup.color != ''){validcolors[validcolors.length] = lookup.color;}
		}
		
	}

	var finished = new Boolean(false);
	var i = -1;
	while(finished != true)
	{
		i++;
		var whichone = document.getElementById('Colors__ctl' + i + '_lnkColor');
		if (whichone != null)
		{
			var foundcolor = new Boolean(false);
			for (var j = 0; j < validcolors.length; ++j)
			{
			if (whichone.rel == validcolors[j]){foundcolor = true};
			}
			if (foundcolor == true)
			{
			if (whichone.className != 'selCol'){whichone.innerHTML = '<div class="Colspn"></div>';}
			}
			else
			{
			whichone.innerHTML = '<div class="ColspnOff">N/A</div>';
			}
		}
		else
		{finished = true;}
	}
	if(document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className!="UnSiz"&&document.getElementById('Sizes__ctl' + (sel - 1) + '_lnkSize').className!="NoSiz")
		document.ProductDetails.hdnSelectedSize.value = currElem.innerHTML;
	
	var tmpstr = currElem.innerHTML;
	document.getElementById("sizetext").innerHTML = tmpstr.toUpperCase();
	SetSelectedProduct(document.ProductDetails.hdnSelectedSize.value,document.ProductDetails.hdnSelectedColor.value)
	AddToBagEnabling();
}


function colorclick(sel)
{
	UnavailableOff();
	
	var testval = document.getElementById('Colors__ctl' + (sel - 1) + '_lnkColor').innerHTML;
	if (testval.indexOf("ColspnOff") != -1)
	{
		UnavailableClick(document.ProductDetails.hdnSelectedSize.value,document.getElementById('Colors__ctl' + (sel - 1) + '_lnkColor').rel);
		var finished = new Boolean(false);
		var i = -1;
		while(finished != true)
		{
			i++;
			var whichone = document.getElementById('Colors__ctl' + i + '_lnkColor');
			if (whichone != null)
			{
				if (whichone.className == 'SelCol')
				{
					whichone.setAttribute("class", "Col"); 
					whichone.setAttribute("className", "Col");
				}
			}
			else
			{finished = true;}
		}
		document.ProductDetails.hdnSelectedColor.value = '';
		document.getElementById("colortext").innerHTML = '';
		return;
	}
	UpdateSizeSelection();

	var currElem = document.getElementById('Colors__ctl' + (sel - 1) + '_lnkColor');
	var selectedcolor = currElem.rel;
	currElem.setAttribute("class", "SelCol"); 
	currElem.setAttribute("className", "SelCol");

	var finished = new Boolean(false);
	var i = -1;
	while(finished != true)
	{
		i++;
		var whichone = document.getElementById('Colors__ctl' + i + '_lnkColor');
		if (whichone != null)
		{
			if (i != (sel - 1) && whichone.className == 'SelCol')
			{
				whichone.setAttribute("class", "Col"); 
				whichone.setAttribute("className", "Col");
			}
		}
		else
		{finished = true;}
	}

	var validsizes = new Array(0);

	for (var i = 0; i < lookups.length; ++i)
	{
		var lookup = lookups[i];
		if (lookup.color == currElem.rel)
		{
			if (lookup.size != ''){validsizes[validsizes.length] = lookup.size;}
		}
		
	}

	var finished = new Boolean(false);
	var i = -1;
	while(finished != true)
	{
		i++;
		var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
		if (whichone != null)
		{
			var foundsize = new Boolean(false);
			for (var j = 0; j < validsizes.length; ++j)
			{
				if (whichone.innerHTML == validsizes[j]){foundsize = true};
			}
			if (foundsize == true)
			{
				if (whichone.className != 'SelSiz')
				{
					whichone.setAttribute("class", "Siz"); 
					whichone.setAttribute("className", "Siz");
				}
			}
			else
			{
				whichone.setAttribute("class", "UnSiz"); 
				whichone.setAttribute("className", "UnSiz");
			}
		}
		else
		{finished = true;}
	}
	document.ProductDetails.hdnSelectedColor.value = currElem.rel;
	SetSelectedProduct(document.ProductDetails.hdnSelectedSize.value,document.ProductDetails.hdnSelectedColor.value)
	AddToBagEnabling();
	OnColorChange(selectedcolor);
}

function Lookup(size, color, productVariant, isReplenishable, swatchImageFileName, swatchSmallImageFileName, productID)
{
	this.size = size;
	this.color = color;
	this.productVariant = productVariant;
	this.isReplenishable = isReplenishable;
	this.swatchImageFileName = swatchImageFileName;
	this.swatchSmallImageFileName = swatchSmallImageFileName;
	this.productID = productID;
}

function ItemFormat(itemID)
{

	while (itemID.length < 6)
		itemID = '0' + itemID;	
	return itemID;
}

function OnColorChange(selectedcolor)
{
	if (selectedcolor == '') return;
	var itemID = '';
	var colorNumber = '';
    	var currentALT = document.getElementById("currentaltimage").value;
    
	if (currentALT.indexOf('_alt1') > -1)
	{
	currentALT = currentALT.replace('_alt1','');
	}

	for (var i = 0; i < lookups.length; ++i)
	{
		var lookup = lookups[i];
		if (lookup.color == selectedcolor)
		{
			colorNumber = lookup.swatchImageFileName;
			colorNumber = colorNumber.replace('/Swatches/', '');
			colorNumber = colorNumber.replace('_1_l.gif', '');
			colorNumber = colorNumber.replace('_2_l.gif', '');
			colorNumber = colorNumber.replace('_3_l.gif', '');
			colorNumber = colorNumber.replace('_4_l.gif', '');
			colorNumber = colorNumber.replace('_5_l.gif', '');
			colorNumber = colorNumber.replace('_6_l.gif', '');
			document.getElementById('zoom1').innerHTML = '<a href="' + imagestem + 'en-us/catalog/productimages/' + ItemFormat(productSTYLE) + '_f_' + colorNumber + '.jpg' + '" id="ProductImageZoom" rel="opacity:30;zoom-width:340;zoom-height:340;zoom-distance:3;zoom-position:custom;zoom-fade:true;zoom-fade-in-speed:250;zoom-fade-out-speed:125;fps:35;" class="MagicZoom"><img id="ProductImage" name="ProductImage" src="' + imagestem + 'en-us/catalog/productimages/' + ItemFormat(productSTYLE) + '_reg_' + colorNumber + '.jpg'+ '"></a>';
			MagicZoom.refresh();
			break;
		}
	}
	document.getElementById("colortext").innerHTML = selectedcolor.toUpperCase();
}

function rfxChangeMediaJockey(itemID, itemColor, imagestem)
{
	var NewItemID = itemID.substring(itemID.indexOf('_alt') ,itemID.length) 
	document.getElementById("currentaltimage").value = NewItemID;
	if (NewItemID != '_alt1')
	{
	document.getElementById('zoom1').innerHTML = '<img id="ProductImage" name="ProductImage" src="' + imagestem + 'en-us/catalog/productimages/' + ItemFormat(itemID).replace('_alt1','') + '_reg.jpg">';
	}
	else
	{
	document.getElementById('zoom1').innerHTML = '<a href="' + imagestem + 'en-us/catalog/productimages/' + ItemFormat(itemID).replace('_alt1','') + '_f.jpg' + '" id="ProductImageZoom" rel="opacity:30;zoom-width:340;zoom-height:340;zoom-distance:3;zoom-position:custom;zoom-fade:true;zoom-fade-in-speed:250;zoom-fade-out-speed:125;fps:35;" class="MagicZoom"><img id="ProductImage" name="ProductImage" src="' + imagestem + 'en-us/catalog/productimages/' + ItemFormat(itemID).replace('_alt1','') + '_reg.jpg'+ '"></a>';
	MagicZoom.refresh();
	}
}

function ReadReviews()
{
	jtabswap(2);
	window.location.hash="PRtab";
}

function OptionSelected()
{               
    document.ProductDetails.hdnOptionValue.value = document.ProductDetails.ddlQuantity.value;
}

function SwatchOver(imageFileName, title)
{
var aImg = new Image();
aImg.src = imageFileName;

 if (aImg.height <= 80)
    {
//thepopup.setAttribute("class", "popuplocation1"); 
//thepopup.setAttribute("className", "popuplocation1");
popclass = 'poploc1';
    }
 else
    {
//thepopup.setAttribute("class", "popuplocation3"); 
//thepopup.setAttribute("className", "popuplocation3");
 popclass = 'poploc3';
   }



   var thepopup = document.getElementById('popuplocation');
    html = '<div id="popdiv" class="' + popclass  + '">';
    if (imageFileName != '')
		html += '<img src="' + imageFileName + '">';
    if (title != '')
	    html += title;
    html += '</div>';
    
    var swtchElem = document.getElementById('DivSwatch');
	swtchElem.innerHTML = html;
    
	//thepopup.style.top =  newhgt + 'px';
	swtchElem.style.visibility = 'visible';
	//thepopup.style.top = newhgt + 'px';
	
}

function SwatchOff()
{
	document.getElementById('DivSwatch').style.visibility = 'hidden';
}

// function changed to simply note button click
function AddToBagCheck()
{
	document.getElementById('atb').value ="1";
}

function AddToBagEnabling()
{
if (document.ProductDetails.hdnSelectedSize.value != "" && document.ProductDetails.hdnSelectedColor.value != "")	
	{
		document.getElementById('disabledAddButton').style.display = 'none';
		document.getElementById('lnkButtonAddToBag').style.display = 'block';
		document.getElementById('AmazonOneClickButton').style.display = 'block';
		document.getElementById('stckstatus').innerHTML = 'Availability: IN STOCK';
		document.getElementById('stckstatus').style.visibility = 'visible';
		
		if (document.getElementById('atb').value =="1")
		{
			document.getElementById('AltCheckout').style.display = 'block';
		}
	}
	else
	{
		document.getElementById('stckstatus').innerHTML = 'Availability: OUT OF STOCK';
	}
}

function redisplayselection(prodVariant)
{
		for (var i = 0; i < lookups.length; ++i)
		{

			var lookup = lookups[i];
			if (lookup.productVariant == prodVariant)
			{
				var finished = new Boolean(false);
				var i = -1;
				while(finished != true)
				{
					i++;
					var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
					if (whichone != null)
					{
						if (whichone.innerHTML == lookup.size)
						{
							finished = true;
							sizeclick(i+1);
						}
					}
				}				

				var finished = new Boolean(false);
				var i = -1;
				while(finished != true)
				{
					i++;
					var whichone = document.getElementById('Colors__ctl' + i + '_lnkColor');
					if (whichone != null)
					{
						if (whichone.rel == lookup.color)
						{
							finished = true;
							colorclick(i+1);
						}
					}
				}				
				
				document.ProductDetails.hdnSelectedProduct.value = lookup.productVariant;
				break;
			}
		}
}


function SetSelectedProduct(size, color)
{
	for (var i = 0; i < lookups.length; ++i)
		{
			var lookup = lookups[i];
			if (size == lookup.size && color == lookup.color)
			{document.ProductDetails.hdnSelectedProduct.value = lookup.productVariant;}
		}
}


function jtabswap (selectedtab)
{


  if (navigator.appName == "Microsoft Internet Explorer")
  {
	document.getElementById('reviewdata').detachEvent('onmouseover',function5); 
	document.getElementById('reviewdata').detachEvent('onmouseout',function5); 
	
	document.getElementById('reviewdata').detachEvent('onmouseover',function2); 
	document.getElementById('reviewdata').detachEvent('onmouseout',function3); 
	
	document.getElementById('checkthese').detachEvent('onmouseover',function1); 
	document.getElementById('checkthese').detachEvent('onmouseout',function1); 
	document.getElementById('checkthese').detachEvent('onmouseover',function4); 
	document.getElementById('checkthese').detachEvent('onmouseout',function6); 
	} 

	else{ 
	document.getElementById('checkthese').removeEventListener('mouseover',function1,true); 
	document.getElementById('checkthese').removeEventListener('mouseout',function1,true);
	document.getElementById('checkthese').removeEventListener('mouseover',function4,true); 
	document.getElementById('checkthese').removeEventListener('mouseout',function6,true);
	
	document.getElementById('reviewdata').removeEventListener('mouseover',function5,true); 
	document.getElementById('reviewdata').removeEventListener('mouseout',function5,true); 
	document.getElementById('reviewdata').removeEventListener('mouseover',function2,true); 
	document.getElementById('reviewdata').removeEventListener('mouseout',function3,true); 
	} 







	if (selectedtab == 1)
	{
	
			document.getElementById('checkthese').style.background='url('+ imagestem + 'images/detail/tab-PD_on.gif)';
			document.getElementById('reviewdata').style.background='url('+ imagestem + 'images/detail/tab-PD_off.gif)';
			
			if (window.attachEvent) {
      			document.getElementById("checkthese").attachEvent("onmouseover",function1);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("checkthese").addEventListener("mouseover",function1,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("checkthese").attachEvent("onmouseout",function1);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("checkthese").addEventListener("mouseout",function1,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("reviewdata").attachEvent("onmouseover",function2);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("reviewdata").addEventListener("mouseover",function2,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("reviewdata").attachEvent("onmouseout",function3);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("reviewdata").addEventListener("mouseout",function3,true);
   			}			

			document.getElementById('reviews').style.display = 'none';
			document.getElementById('pnlCrosssells').style.display = '';
	
	}
	else
	{
			
			document.getElementById('reviewdata').style.background='url('+ imagestem + 'images/detail/tab-PD_on.gif)';
			document.getElementById('checkthese').style.background='url('+ imagestem + 'images/detail/tab-PD_off.gif)';
			
			
			if (window.attachEvent) {
      			document.getElementById("checkthese").attachEvent("onmouseover",function4);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("checkthese").addEventListener("mouseover",function4,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("checkthese").attachEvent("onmouseout",function6);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("checkthese").addEventListener("mouseout",function6,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("reviewdata").attachEvent("onmouseover",function5);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("reviewdata").addEventListener("mouseover",function5,true);
   			}			
			
			if (window.attachEvent) {
      			document.getElementById("reviewdata").attachEvent("onmouseout",function5);
   			} 
  			 else if (window.addEventListener) {
      			document.getElementById("reviewdata").addEventListener("mouseout",function5,true);
   			}			
			
			
			document.getElementById('pnlCrosssells').style.display = 'none';
			document.getElementById('reviews').style.display = '';
	
	}
}

function function1()
{
			document.getElementById('checkthese').style.background='url('+ imagestem + 'images/detail/tab-PD_on.gif)';
}
function function2()
	{
			document.getElementById('reviewdata').style.background='url('+ imagestem + 'images/detail/tab-PD_hover.gif)';
	}
	
function function3()
{
			document.getElementById('reviewdata').style.background='url('+ imagestem + 'images/detail/tab-PD_off.gif)';
	}
function function4()
	{
			document.getElementById('checkthese').style.background='url('+ imagestem + 'images/detail/tab-PD_hover.gif)';
	}
function function5()
	{
			document.getElementById('reviewdata').style.background='url('+ imagestem + 'images/detail/tab-PD_on.gif)';
	}
function function6()
	{
			document.getElementById('checkthese').style.background='url('+ imagestem + 'images/detail/tab-PD_off.gif)';
	}
function notreadyoff()
{
	document.getElementById('SlctMsg').style.visibility = 'hidden';
}

function notreadytocheckout()
{
   var thepopup = document.getElementById('selectmsgs');
   var msgtext = '';
    if (document.ProductDetails.hdnSelectedColor.value == '' && (document.getElementById('colortext').value == '' || document.getElementById('colortext').value == undefined))
    	msgtext = '<img src="' + imagestem + 'images/detail/TIP_color.gif" alt="please select a color">';
   if (document.ProductDetails.hdnSelectedSize.value == '' && (document.getElementById('sizetext').value == ''||document.getElementById('sizetext').value == undefined))
   	msgtext = '<img src="' + imagestem + 'images/detail/TIP_size.gif" alt="please select a size">';
   if ((document.ProductDetails.hdnSelectedSize.value == '' && document.ProductDetails.hdnSelectedColor.value == '') || (document.ProductDetails.hdnSelectedSize.value == '' && document.getElementById('sizetext').value != '' && document.getElementById('sizetext').value != undefined))
    	msgtext = '<img src="' + imagestem + 'images/detail/TIP_colorsize.gif" alt="please select a size and color">';
    var swtchElem = document.getElementById('SlctMsg');
	swtchElem.innerHTML = msgtext;
	swtchElem.style.visibility = 'visible';
}

function adjustinfoheight()
{
var currElem = document.getElementById('productselectarea');
if (currElem.offsetHeight < 495)
{
currElem.style.height = '495px';
}
}

function UnavailableOff()
{
	document.getElementById('stckstatus').innerHTML = 'Availability: IN STOCK';
}

function UnavailableClick(size, color)
{
	document.getElementById('lnkButtonAddToBag').style.display = 'none';
	document.getElementById('AmazonOneClickButton').style.display = 'none';		
	document.getElementById('disabledAddButton').style.display = 'block';
	document.getElementById('stckstatus').innerHTML = 'Availability: OUT OF STOCK';
}

function AmazonOneClickOnClick()
{        
    var SelectedItemSKU = document.getElementById('hdnSelectedProduct').value;
    var RequestURL = document.domain + "/AmazonOneClick.aspx?SelectedItemSKU=";
    var CatalogName = document.getElementById('htxtCategoryName').value;
    var Qty = document.getElementById('ddlQuantity').value;
   
    if (SelectedItemSKU.length > 0)
    {
        //Append the SKU to the requestURL
        var url = "http://"+ RequestURL + SelectedItemSKU + "&CatalogName=" + CatalogName + "&Quantity=" + Qty;
		
        //Create the xmlHttp object to use in the request
        //stateChangeHandler will fire when the state has changed, i.e. data is received back
        // This is blocking (synchronous)
        xmlHttp = GetXmlHttpObject(AmazonOneClickStateChangeHandler);
        
        //Send the xmlHttp get to the specified url
        xmlHttp_Get(xmlHttp, url);
    }
    else 
    {
        //div blanked out, clear the results
        document.getElementById('hdnAmazonOneClickContainer').innerHTML = '';
    }
}
//stateChangeHandler will fire when the state has changed, i.e. data is received back
// This is blocking (synchronous)
function AmazonOneClickStateChangeHandler()
{
    //readyState of 4 or 'complete' represents that data has been returned
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
    {
        //Gather the results from the callback
        var AmazonOneClickForm = xmlHttp.responseText;

        //Populate the innerHTML of the div with the form
        document.getElementById('hdnAmazonOneClickContainer').innerHTML = AmazonOneClickForm;
        
        //Submit the form
        
    }
}

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=yes, menubar=yes, ' +
  'status=yes, toolbar=yes, scrollbars=yes, resizable=yes');
 win.resizeTo(w, h);
 win.focus();
}

function ReviewWindow(ProductID)
{       
	var objWin = window.open('/PowerReviews/SubmitReview.html?pageID=' + ProductID,'Review','width=850,height=450, resizable=yes, toolbar=no, status=no, menubar=no, scrollbars = yes');
    objWin.window.focus();
}

function UpdateSizeSelection()
{
		var finished = new Boolean(false);
		var i = -1;
		while(finished != true)
		{
			i++;
			var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
			if (whichone != null)
			{
				if (whichone.innerHTML.toUpperCase() == document.getElementById("sizetext").innerHTML.toUpperCase()&&whichone.className == 'NoSiz')
				{
					whichone.setAttribute("class", "SelSiz"); 
					whichone.setAttribute("className", "SelSiz");
					document.ProductDetails.hdnSelectedSize.value = whichone.innerHTML.toUpperCase();
					finished = true;
				}
			}
			else
			{finished = true;}
		}
}

function singleselection()
{
		var finished = new Boolean(false);
		var i = -1;
		var j = -1;
		
		while(finished != true)
		{
			i++;
			var whichone = document.getElementById('Sizes__ctl' + i + '_lnkSize');
			if (whichone == null)
				finished = true;
		}
		if (i == 1)
		{
			var currElem = document.getElementById('Sizes__ctl0_lnkSize')		
			currElem.setAttribute("class", "SelSiz"); 
			currElem.setAttribute("className", "SelSiz");
			document.ProductDetails.hdnSelectedSize.value = currElem.innerHTML;
			var tmpstr = currElem.innerHTML;
			document.getElementById("sizetext").innerHTML = tmpstr.toUpperCase();
		}


		finished = false;
		
		while(finished != true)
		{
			j++;
			var whichone = document.getElementById('Colors__ctl' + j + '_lnkColor');
			if (whichone == null)
				finished = true;
		}
		if (j == 1)
		{
			var currElem = document.getElementById('Colors__ctl0_lnkColor');
			var selectedcolor = currElem.rel;
			currElem.setAttribute("class", "SelCol"); 
			currElem.setAttribute("className", "SelCol");
			document.ProductDetails.hdnSelectedColor.value = currElem.rel;
			OnColorChange(currElem.rel);
		}

		if (j == 1 || i == 1)
		{
			SetSelectedProduct(document.ProductDetails.hdnSelectedSize.value,document.ProductDetails.hdnSelectedColor.value)
			AddToBagEnabling();
		}
}





























