var selectedColorOption = "0";
var selectedSizeOption = "0";

function getServerName()
{
	//alert("needServerName="+needServerName);
	if(needServerName=='true'){
		//alert("needServerName="+needServerName);
        var ser=window.location.protocol+'//'+window.location.hostname;
        return ser;
   }else{ return '';}

}


function newXMLHttpRequest()
{   var xmlreq = false;
	if (window.XMLHttpRequest) {
		// Create XMLHttpRequest object in non-Microsoft browsers
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// Create XMLHttpRequest via MS ActiveX
		try {
			// Try to create XMLHttpRequest in later versions
			// of Internet Explorer
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				// Try version supported by older versions
				// of Internet Explorer
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2)
			{  doError(e2);
			}
		}
	}
	return xmlreq;

}

function ochod(oSelectObj, optionType, MENUPK,  PID, menuPos, id1, id2, id3){
   //alert("ochod");
	optionTypeValues(oSelectObj);
	url=getServerName()+'/pom.do?method=onChange&MENUPK='+MENUPK+'&PID='+PID+'&OTN='+optionType;
	Select1=getSelectVariable(id1+MENUPK);
	if(Select1!=''){
		url=url+'&OT1='+id1
		url=url+'&'+id1+'='+Select1
	}
	Select2=getSelectVariable(id2+MENUPK);
	if(Select2!=''){
		url=url+'&OT2='+id2
		url=url+'&'+id2+'='+Select2
	}
	Select3=getSelectVariable(id3+MENUPK);
	if(Select3!=''){
		url=url+'&OT3='+id3
		url=url+'&'+id3+'='+Select3
	}

	//alert("url="+url);

	async=true;
	var req = newXMLHttpRequest();
	var handlerFunction = getOchodHandler(req);
	req.onreadystatechange = handlerFunction;
	req.open('GET', url, async);
	req.send(null);
}

function getOchodHandler(req)
{
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var response = req.responseXML;
        		setOchod(response);
			}else{
				//alert("getInitodHandler error: "+req.status);
			}
		}
	}
}


function setOchod(message) {

	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];

	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	//alert("id="+id);
	var optionsTypeString = PRODUCTOPTION.getAttribute("optionsTypes");
	//alert("optionsTypeString="+optionsTypeString);

	var optionsTypeObjects = PRODUCTOPTION.getElementsByTagName("OPTIONTYPE");
	for (var J = 0 ; J < optionsTypeObjects.length ; J++) {
	    var optionsTypeObject=optionsTypeObjects[J];
        var optionsTypeID = optionsTypeObject.getAttribute("id")
	    //alert("optionsTypeID="+optionsTypeID);
        var optionsTypeName = optionsTypeObject.getAttribute("name")
        //alert("optionsTypeName="+optionsTypeName);
        var optionsTypePos=optionsTypeObject.getAttribute("pos");
        var optionsTypePreFix=optionsTypeObject.getAttribute("preFix");
        var newHtml="<select class=\"detail\" name=\"options_"+id+"_"+optionsTypeID+"\" id=\""+optionsTypeName+id+"\"  onChange=\"ochod(this, '"+optionsTypeName+"', "+id+","+ pid+", "+optionsTypeID+","+optionsTypeString+");\">";

	    if(optionsTypePreFix=='NONE'){
	        newHtml=newHtml+"<option value=\"0\">Select a "+optionsTypeName+"</option>";
        }else if(optionsTypePreFix=='FIRST'){
            newHtml=newHtml+"<option value=\"0\">"+firstMenuPrefix+", Select a "+optionsTypeName+"</option>";
        }else{
            newHtml=newHtml+"<option value=\"0\">Select a "+optionsTypeName+"</option>";
        }
        var optionsObjects = optionsTypeObject.getElementsByTagName("OPTION");
        for (var I = 0 ; I < optionsObjects.length ; I++) {

            var option = optionsObjects[I];

            var optionID = option.getAttribute("id")
            var optionName = option.getAttribute("name")
	        var selected = option.getAttribute("selected")
			var lastPos = option.getAttribute("lastPos")
			var additionalMessage="";
	        //alert("optionID="+optionID);
	        //alert("optionName="+optionName);
	        //alert("selected="+selected);
			//alert("lastPos="+lastPos);
			if(lastPos=='true'){

				var inlineInventoryObjects = option.getElementsByTagName("INVENTORY")[0];
				if(inlineInventoryObjects!=null){
					var InStock= inlineInventoryObjects.getAttribute("InStock");
					var BackOrderable= inlineInventoryObjects.getAttribute("BackOrderable");
					var RestockDate= inlineInventoryObjects.getAttribute("RestockDate");

					//alert("InStock="+InStock);
					//alert("BackOrderable="+BackOrderable);
					//alert("RestockDate="+RestockDate);

					var inventoryMsg ="";

					if(InStock=='true') {
						inventoryMsg=" - "+inStockMsg
					} else {     // Out-Of-Stock
						// Out-Of-Stock & Not backorderable...
						if(BackOrderable=='true') {
        					inventoryMsg=" - "+backorderMsg + " "+ RestockDate
						}else{
							inventoryMsg=" - "+outOfStockMsg;
						}
					}
					additionalMessage+=inventoryMsg;
				}


				var inlinePriceObjects = option.getElementsByTagName("PRICEDISPLAY")[0];
				if(inlinePriceObjects!=null){
					var Price= inlinePriceObjects.getAttribute("Price");
					var SalePrice = inlinePriceObjects.getAttribute("SalePrice");
					var SaveDollerAmt= inlinePriceObjects.getAttribute("SaveDollerAmt");
					var SavePercent= inlinePriceObjects.getAttribute("SavePercent");
					var OnSale= inlinePriceObjects.getAttribute("OnSale");
					if(OnSale=='true'){
						additionalMessage+=" - "+SalePrice;
					}else{
						additionalMessage+=" - "+Price;
					}
				}

			}
			newHtml=newHtml+"<option value=\""+optionID+"\" "+ selected +">"+optionName+additionalMessage+"</option>";

        }

	    newHtml=newHtml+"</select>";
	    //alert("newHtml="+newHtml);
        mdiv = document.getElementById("div_options_"+id+"_"+optionsTypeID);
        mdiv.innerHTML = newHtml;
		optionTypeValues(getObjectByID(optionsTypeName+id));

		newHtml='';
    }

	var PRICEDISPLAY = PRODUCTOPTION.getElementsByTagName("PRICEDISPLAY")[0];

	//alert("PRICEDISPLAY="+PRICEDISPLAY);

	if(PRICEDISPLAY!=null){
	    var Price= PRICEDISPLAY.getAttribute("Price");
	    var SalePrice = PRICEDISPLAY.getAttribute("SalePrice");
	    var SaveDollerAmt= PRICEDISPLAY.getAttribute("SaveDollerAmt");

	    var SavePercent= PRICEDISPLAY.getAttribute("SavePercent");
	    //alert("Price="+Price);
	    //alert("SalePrice="+SalePrice);
	    //alert("SaveDollerAmt="+SaveDollerAmt);



	    setDisplay("wasPrice_"+id, Price);
	    setDisplay("isPrice_"+id, SalePrice);
	    setDisplay("saveDollar_"+id, SaveDollerAmt);

	    setDisplay("savePercent_"+id, SavePercent+'%');


	}

	var INVENTORY = PRODUCTOPTION.getElementsByTagName("INVENTORY")[0];

	if(INVENTORY!=null){
	    var InStock= INVENTORY.getAttribute("InStock");
	    var BackOrderable= INVENTORY.getAttribute("BackOrderable");
	    var RestockDate= INVENTORY.getAttribute("RestockDate");
	    var AdvanceOrder= INVENTORY.getAttribute("AdvanceOrder");
	    var WaitingList= INVENTORY.getAttribute("WaitingList");

	    //alert("InStock="+InStock);
	    //alert("BackOrderable="+BackOrderable);
	    //alert("RestockDate="+RestockDate);
	    //alert("AdvanceOrder="+AdvanceOrder);
	    //alert("WaitingList="+WaitingList);


	    var inventoryMsg ="";

        if(InStock=='true') {
		    inventoryMsg=inStockMsg
	    } else {     // Out-Of-Stock

			// Out-Of-Stock & Not backorderable...
			if(ShowUnavailableOptions) {
				if(AdvanceOrder=='1'){
					inventoryMsg=advancedOrderMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+' <br>'+backorderMsg + " "+ RestockDate
					}
				}else if(WaitingList=='1'){
					inventoryMsg=waitListMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+' <br>'+backorderMsg + " "+ RestockDate
					}
				}else{
					inventoryMsg=outOfStockMsg;
				}
			 }

	    }
	    setDisplay("inventory_"+id,  inventoryMsg);

	}

	//alert("getObjectByID('swPK'+id)="+getObjectByID('swPK'+id));
	if(showAdvancedSwatch && getObjectByID('swPK'+id)!=null){
		var SWOPTIONTYPE = PRODUCTOPTION.getElementsByTagName("SWOPTIONTYPE")[0];
		if(SWOPTIONTYPE!=null){
			var itemCode=getCode(SWOPTIONTYPE.getAttribute("itemCode"));
			var swOptionsTypeID = SWOPTIONTYPE.getAttribute("id");
			//alert("optionsTypeID="+optionsTypeID);
    		var swOptionsTypeName = SWOPTIONTYPE.getAttribute("name");
			var selectedCode= SWOPTIONTYPE.getAttribute("selectedCode");
			var selectedName= SWOPTIONTYPE.getAttribute("selectedName");
			var selectedID=SWOPTIONTYPE.getAttribute("selectedID");
			var swatchDetailPath=getObjectByID('SwatchDetailPath_'+id);

            var swOptionCodeArr = selectedCode.split("_");
		    if (swOptionCodeArr.length >1 ) {
	 		            selectedCode=swOptionCodeArr[swOptionCodeArr.length-1]
	 		}


			//var detailImgUrl=imagePath+swatchDetailPath.value+itemCode+"_"+getSwatchOption(selectedCode) +'_swatch.jpg';
			var detailImgUrl=imagePath+DetailImagePath+itemCode+"."+getSwatchOption(selectedCode) +'.jpg';
			setDisplay('SwatchStyleName_'+id, imageMsg+selectedName);
			swapImage('SwatchDetail_'+id,detailImgUrl);
            selectCode=getSwatchOption(selectedCode);
			previousColorCode =selectCode;
			swapAltImages(id,itemCode,selectCode);
			swapZoomImage(detailImgUrl,itemCode,selectCode);
			//alert("selectedID="+selectedID);
			document.images['Swatch_'+id+"_"+selectedID].className="swatchoff";
			var preselectswatch=getObjectByID('PreSelectSwatch_'+id);
			//alert("preselectswatch.value="+preselectswatch.value);
			//To Fix Defect ARMNI 720
			if(preselectswatch.value != null && preselectswatch.value !="") {
				document.images['Swatch_'+id+"_"+preselectswatch.value].className="swatchoff";
			}
			preselectswatch.value=selectedID;
			//alert("preselectswatch.value="+preselectswatch.value);
		}
	}

}
//end onclick

function showEmpty(img) {
	alert(img)
	img.src='spaceImagePath';
}

//****************************

//****************************
//start init
function initod(url, swatch, swatchType)
{
	//------------------------------------------	
// Modify url here and set the pre selected colr and size in it 
//	alert("Original : "+url);
		// Color Option Modification
	var str_temp = url.substring(url.indexOf("Color=")+6,url.indexOf("Color=")+12);
//	alert("Color Option : "+str_temp+" AND color selected on detail page : "+selectedColorOption);
	
	if(selectedColorOption != "" && selectedColorOption !="0")
	{
		if(str_temp != selectedColorOption)
		{
			url = url.replace(str_temp,selectedColorOption);
		}
		//selectedColorOption = "0";
	}
//	alert("After changing color New URL : "+url);

		// Size option Modification
	str_temp = url.substring(url.indexOf("Size=")+5,url.indexOf("Size=")+11);
//	alert("Size Option : "+str_temp+" AND size selected on detail page : "+selectedSizeOption);
	
	if(selectedSizeOption != "" && selectedSizeOption !="0")
	{
		if(str_temp != selectedSizeOption)
		{
			url = url.replace(str_temp,selectedSizeOption);
		}
		//selectedSizeOption = "0";
	}
	else
	{
		url = url.replace(str_temp,"");
	}

//	alert("After changing size New URL : "+url);
//------------------------------------------
	url=getServerName()+'/pom.do?method=initOption&'+url;
	async=true;
	var req = newXMLHttpRequest();
	var handlerFunction = getInitodHandler(req, swatch, swatchType);
	req.onreadystatechange = handlerFunction;
	req.open('GET', url, async);
	req.send(null);
}

function getInitodHandler(req, swatch, swatchType)
{
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var response = req.responseXML;
        		setInitod(response, swatch, swatchType);
			}else{
				//alert("getInitodHandler error: "+req.status);
			}
		}
	}
}

function setInitod(message, swatch, swatchType) {
	//alert("message="+message);
	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];
	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	var itemCode = PRODUCTOPTION.getAttribute("itemCode");
	//alert("id="+id);
	var optionsTypeString = PRODUCTOPTION.getAttribute("optionsTypes");
	//alert("optionsTypeString="+optionsTypeString);

	var optionsTypeObjects = PRODUCTOPTION.getElementsByTagName("OPTIONTYPE");
	for (var J = 0 ; J < optionsTypeObjects.length ; J++) {
	    var optionsTypeObject=optionsTypeObjects[J];
        var optionsTypeID = optionsTypeObject.getAttribute("id")
	    var optionsTypeName = optionsTypeObject.getAttribute("name")
        //alert("optionsTypeName="+optionsTypeName);
        var optionsTypePos=optionsTypeObject.getAttribute("pos");
        var optionsTypePreFix=optionsTypeObject.getAttribute("preFix");
        var newHtml="<select class=\"detail\" name=\"options_"+id+"_"+optionsTypeID+"\" id=\""+optionsTypeName+id+"\"  onChange=\"ochod(this, '"+optionsTypeName+"', "+id+","+ pid+", "+optionsTypeID+","+optionsTypeString+");\">";
		
	    if(optionsTypePreFix=='NONE'){
			  newHtml=newHtml+"<option value=\"0\">Select a "+optionsTypeName+"</option>";
        }else if(optionsTypePreFix=='FIRST'){
			
			 newHtml=newHtml+"<option value=\"0\">"+firstMenuPrefix+", Select a "+optionsTypeName+"</option>";


        }else{
			//If option type is Size then by default "Select a Size will be selected"
			var sizeSelected ="";
			if(optionsTypeID==sizeOptionTypeId) {
				// sizeSelected="Selected";
			}
            newHtml=newHtml+"<option value=\"0\""+ sizeSelected+" >Select a "+optionsTypeName+"</option>";
        }
        var optionsObjects = optionsTypeObject.getElementsByTagName("OPTION");
        for (var I = 0 ; I < optionsObjects.length ; I++) {

            var option = optionsObjects[I];

            var optionID = option.getAttribute("id")
            var optionName = option.getAttribute("name")
	        var selected = option.getAttribute("selected")
			//If option type is Size then by default "Select a Size will be selected"
			
			if(optionsTypeID==sizeOptionTypeId && optionsObjects.length == 1 ) {selected="Selected"};
			if(optionsTypeID==sizeOptionTypeId && optionsObjects.length > 1 ) {selected=""};
			var lastPos = option.getAttribute("lastPos")
			var additionalMessage="";
	        //alert("optionID="+optionID);
	        //alert("optionName="+optionName);
	        //alert("selected="+selected);
			//alert("lastPos="+lastPos);
			if(lastPos=='true'){

				var inlineInventoryObjects = option.getElementsByTagName("INVENTORY")[0];
				if(inlineInventoryObjects!=null){
					var InStock= inlineInventoryObjects.getAttribute("InStock");
					var BackOrderable= inlineInventoryObjects.getAttribute("BackOrderable");
					var RestockDate= inlineInventoryObjects.getAttribute("RestockDate");

					//alert("InStock="+InStock);
					//alert("BackOrderable="+BackOrderable);
					//alert("RestockDate="+RestockDate);

					var inventoryMsg ="";

					if(InStock=='true') {
						inventoryMsg=" - "+inStockMsg
					} else {     // Out-Of-Stock
						// Out-Of-Stock & Not backorderable...
						if(BackOrderable=='true') {
        					inventoryMsg=" - "+backorderMsg + " "+ RestockDate
						}else{
							inventoryMsg=" - "+outOfStockMsg;
						}
					}
					additionalMessage+=inventoryMsg;
				}


				var inlinePriceObjects = option.getElementsByTagName("PRICEDISPLAY")[0];
				if(inlinePriceObjects!=null){
					var Price= inlinePriceObjects.getAttribute("Price");
					var SalePrice = inlinePriceObjects.getAttribute("SalePrice");
					var SaveDollerAmt= inlinePriceObjects.getAttribute("SaveDollerAmt");
					var SavePercent= inlinePriceObjects.getAttribute("SavePercent");
					var OnSale= inlinePriceObjects.getAttribute("OnSale");
					if(OnSale=='true'){
						additionalMessage+=" - "+SalePrice;
					}else{
						additionalMessage+=" - "+Price;
					}
				}

			}
			newHtml=newHtml+"<option value=\""+optionID+"\" "+ selected +">"+optionName+additionalMessage+"</option>";


        }

	    newHtml=newHtml+"</select>";
	    //alert("newHtml="+newHtml);

		// Hide the div
		var divObj = getObjectByID("div_options_"+id+"_"+optionsTypeID);
		divObj.style.visibility = "hidden";
		// Set InnerHTML
		setDisplay("div_options_"+id+"_"+optionsTypeID, newHtml)

		// Set the required value in the Size drop down here
		// Do it only if the current option type is Size		

		if(optionsTypeName == "Size" && ((selectedSizeOption != "0" && selectedSizeOption != "") || selectedSizeName.length > 0))
		{
			var selectObj = getObjectByID(optionsTypeName+id);
			var counter = 0;
			for(counter=0; counter<selectObj.length; counter++)
			{
				
				if(selectObj[counter].value == selectedSizeOption || selectObj[counter].innerHTML == selectedSizeName)
				{					
					selectObj.selectedIndex = counter;
				}
			}
		}

		// Make the div Visible
		divObj.style.visibility = "visible";
		if(hasElement ("div_options_"+id+"_"+optionsTypeID)){
		    optionTypeValues(getObjectByID(optionsTypeName+id));
		}
		newHtml='';
    }

	var PRICEDISPLAY = PRODUCTOPTION.getElementsByTagName("PRICEDISPLAY")[0];
	//alert("PRICEDISPLAY="+PRICEDISPLAY);
	if(PRICEDISPLAY!=null){
	    var Price= PRICEDISPLAY.getAttribute("Price");
	    var SalePrice = PRICEDISPLAY.getAttribute("SalePrice");
	    var SaveDollerAmt= PRICEDISPLAY.getAttribute("SaveDollerAmt");
	    var SavePercent= PRICEDISPLAY.getAttribute("SavePercent");
	    //alert("Price="+Price);
	    //alert("SalePrice="+SalePrice);
	    //alert("SaveDollerAmt="+SaveDollerAmt);


	    setDisplay("wasPrice_"+id, Price);
	    setDisplay("isPrice_"+id, SalePrice);
	    setDisplay("saveDollar_"+id, SaveDollerAmt);

	    setDisplay("savePercent_"+id, SavePercent+'%');


	}


	var INVENTORY = PRODUCTOPTION.getElementsByTagName("INVENTORY")[0];

	if(INVENTORY!=null){
	    var InStock= INVENTORY.getAttribute("InStock");
	    var BackOrderable= INVENTORY.getAttribute("BackOrderable");
	    var RestockDate= INVENTORY.getAttribute("RestockDate");
	    var AdvanceOrder= INVENTORY.getAttribute("AdvanceOrder");
	    var WaitingList= INVENTORY.getAttribute("WaitingList");

	    //alert("BackOrderable="+BackOrderable);
	    //alert("RestockDate="+RestockDate);



	    var inventoryMsg ="";
        if(InStock=='true') {
		    inventoryMsg=inStockMsg
	    } else {     // Out-Of-Stock
		    // Out-Of-Stock & Not backorderable...
			if(ShowUnavailableOptions) {
				if(AdvanceOrder=='1'){
					inventoryMsg=advancedOrderMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+' <br>'+backorderMsg + " "+ RestockDate
					}
				}else if(WaitingList=='1'){
					inventoryMsg=waitListMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+' <br>'+backorderMsg + " "+ RestockDate
					}
				}else{
					inventoryMsg=outOfStockMsg;
				}
			 }
	    }
	    setDisplay("inventory_"+id,  inventoryMsg);
	}
    var largeImages='';
	if(showAdvancedSwatch && swatch=='true'){
		var swatchDetailPath=DetailImagePath;
		var swatchPath=SuperMiniThumbImagePath;
		var swatchColumn=5;
		//alert("showAdvancedSwatch="+showAdvancedSwatch);
		if(swatchType=='Thumb'){
			swatchDetailPath=ThumbImagePath;
			swatchColumn=6;
		}
		if(swatchType=='looksproduct'){
			DetailImagePath=LooksImagePath;
			swatchColumn=3;
		}

	    var SWOPTIONTYPE = PRODUCTOPTION.getElementsByTagName("SWOPTIONTYPE")[0];

	    if(SWOPTIONTYPE!=null){
	        //var itemCode=getCode(SWOPTIONTYPE.getAttribute("itemCode"));
	        var swOptionsTypeID = SWOPTIONTYPE.getAttribute("id")
	        //alert("optionsTypeID="+optionsTypeID);
            var swOptionsTypeName = SWOPTIONTYPE.getAttribute("name")
	        var preImage='';
	        var preImageName='';
	        var preImageID='';
            var hasSWoptions=false;
	        if(SWOPTIONTYPE!=null){
		        var swOptionsObjects = SWOPTIONTYPE.getElementsByTagName("SWOPTION");
		        var sw="<div id=\"swPK"+id+"\"><table align= left BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">";
				var swatches =swOptionsObjects.length;
				var maxSwatches =15;
				if(swatches > maxSwatches ) {
					swatches =maxSwatches;
				}

			    for (var I = 0 ; I < swatches ; I++) {
                    hasSWoptions=true;
			        var swOption = swOptionsObjects[I];
                    var swOptionID = swOption.getAttribute("id");
                    var swOptionName = swOption.getAttribute("name");
	                var swSelected = swOption.getAttribute("selected");
			        var swOptionCode = getCode(swOption.getAttribute("code"));
			        var swOptionCodeArr = swOptionCode.split("_");
		            if (swOptionCodeArr.length >1 ) {
	 		            swOptionCode=swOptionCodeArr[swOptionCodeArr.length-1]
	 		        }

			      //  if(I==0){
				    //    sw=sw+"<tr>";
				        //sw=sw+"<td colspan="+swatchColumn+" class=swatchtext><div id=\"SwatchStyleName_"+id+"\">Click to select a style</div></td>";
					//	sw=sw+"<td colspan="+swatchColumn+" class=swatchtext>COLOR OPTIONS Click Swatches to change</td>";
				      //  sw=sw+"</tr>";
			        //}
			        if(I%swatchColumn==0){
				        sw=sw+"<tr valign=top>";
			        }
					
			        var changeFun="swChgStyle("+swOptionsTypeID+",'"+swOptionsTypeName+"',"+id+","+ pid+","+swOptionID+","+optionsTypeString+",'"+swOptionName+"')";
			       
			       // var detailImgUrl=imagePath+swatchDetailPath+itemCode+"_"+getSwatchOption(swOptionCode) +'_swatch.jpg';
					//var swatchImgUrl=imagePath+swatchDetailPath+itemCode+"_"+getSwatchOption(swOptionCode) +'_swatch.jpg';
					var detailImgUrl=imagePath+DetailImagePath+itemCode+"."+getSwatchOption(swOptionCode) +'.jpg';
					var swatchImgUrl=imagePath+SwatchImagePath+itemCode+"."+getSwatchOption(swOptionCode) +'.jpg';
					

			        largeImages=largeImages+','+itemCode+"_"+swOptionCode;
			       // var onerror="this.src='"+imagePath+"local/products/prodnotavail.jpg'";
				   var onerror ="this.src='"+ spaceImagePath +"'";
			        if(I%swatchColumn==(swatchColumn-1)){
                        sw=sw+"<td class=lastswatchspace><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID  +"', '" + itemCode +"', '"+ swOptionCode +"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID +"', '" + itemCode +"', '"+ swOptionCode +"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"32\" HEIGHT=\"35\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\"></A></td>";
                    }else{
                        sw=sw+"<td class=swatchspace><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID  +"', '" + itemCode +"', '"+ swOptionCode +"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID +"', '" + itemCode +"', '"+ swOptionCode +"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"32\" HEIGHT=\"35\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\"></A></td><td><IMG SRC=\"${siteImages.spacer}\" width=\"4\" height=\"1\" border=\"0\"></td>";
                    }
			        if(swSelected=='Selected'){
				        preImageName=swOptionName;
				        preImage=detailImgUrl;
				        preImageID=swOptionID;
						
						previousColorCode =swOptionCode;
						swapAltImages(id,itemCode,swOptionCode);
						swapZoomImage(detailImgUrl,itemCode,swOptionCode);
			        }
					
					/*
			        if(I%swatchColumn==(swatchColumn-1)){
						 if(swOptionsObjects.length !=swatchColumn ) {
							sw=sw+"</tr><tr><td><IMG SRC=\"${siteImages.spacer}\" width=\"1\" height=\"4\" border=\"0\"></td></tr>";
						 }
			        }
					*/
		        }

		        if(I%swatchColumn!=(swatchColumn-1)){
			        for(var j=I%swatchColumn; j<swatchColumn; j++){
				        sw=sw+"<td>&nbsp;</td>"
			        }
			        sw=sw+"</tr>";
		        }
		        sw=sw+"</table><input type='hidden' id='PreSelectSwatch_"+id+"' value='"+preImageID+"'><input type='hidden' id='SwatchDetailPath_"+id+"' value='"+swatchDetailPath+"'>  </div>";
	        }
            if(largeImages.length>0){
	            largeImages=largeImages.substring(1);
	        }
            sw=sw+"<input type='hidden' id='largeImages_"+itemCode+"' value='"+largeImages+"'>";


	        setDisplay("SwatchesDiv_"+id,sw) ;
			
	        setDisplay('SwatchStyleName_'+id, imageMsg+preImageName);

	        if(hasSWoptions){
				//To Fix Defect ARMNI 720
				if(preImageID != null && preImageID !="" ) {
					 swapImage('SwatchDetail_'+id,preImage);
					 document.images['Swatch_'+id+"_"+preImageID].className="swatchoff";
				}
	        }

	    }else{
			largeImages='/'+itemCode;
			sw="<input type='hidden' id='largeImages_"+itemCode+"' value='"+largeImages+"'>";

			setDisplay("SwatchesDiv_"+id,sw) ;
		}
	}
}

//end init
//****************************

//****************************
function getSelectVariable(varName) {
	//alert("varName="+varName);
    var oDropDown    = document.getElementById(varName);
	if(oDropDown!=null){
    var intSelected  = oDropDown.selectedIndex;
    var optionID     = oDropDown[intSelected].value;
    return optionID;
	}return '';
}

function getNoOptionsMsg() {
   return noOptionsMsgPom;
}


function setDisplay(id,shtml) {
   if (document.getElementById || document.all) {
      var el = document.getElementById? document.getElementById(id): document.all[id];
      if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;

   }
}

function hasElement(id) {
   if (document.getElementById || document.all) {
      var el = document.getElementById? document.getElementById(id): document.all[id];
      if (el && typeof el.innerHTML != "undefined") return true;

   }
   return false;
}

function getObjectByID(id) {
   if (document.getElementById || document.all) {
      return document.getElementById? document.getElementById(id): document.all[id];

   }
}

function swapImage(id, imgUrl){
	//alert("id="+id);
	//previousImgSrc = document.images[id].src;
	//previousImgID = id;
	//document.images[id].src=imgUrl;

}

function swapText(id, shtml){
     
      var el = document.getElementById? document.getElementById(id): document.all[id];
      if (el && typeof el.innerHTML != "undefined") {
	previousSwatchImgName = el.innerHTML;
      	el.innerHTML = shtml;
      }
}

function swMouseOver(object, imageid, imgUrl, name, id, optionid,itemCode,colorCode){
	//setDisplay('SwatchStyleName_'+id, imageMsg+name);
	//setDisplay('SwatchStyleName_', name);
	if (document.images['Swatch_'+id+"_"+optionid].className!="swatchoff"){
  document.images['Swatch_'+id+"_"+optionid].className="swatchover";
	}

 // swapImage(imageid,imgUrl);
  swapText('SwatchStyleName_'+id, imageMsg+name);
  // alert("previousColorCode" + previousColorCode);
  //if(previousColorCode == undefined){
	//previousColorCode =colorCode;
  //}
   var swOptionCode =colorCode;
 

  swapAltImages(id,itemCode,swOptionCode);
  var zoomImageUrl = imagePath + AltImagePath  + itemCode + "." + swOptionCode + imgSuffix + 1 +imgExt;
  swapZoomImage(zoomImageUrl,itemCode,swOptionCode);
  selectedColorCode=swOptionCode;
  // previousColorCode =colorCode;
 //alert("selectedColorCode "+ selectedColorCode);
  
//alert(aTemp.innerHTML);		
 // alert(document.getElementById('selectedColorCodeDiv'));		
  
}


function swMouseOut(object, id, optionid ,itemCode,optionCode){
	//setDisplay('swstylename', 'Click to select a style');
/*	
  if (document.images['Swatch_'+id+"_"+optionid].className!="swatchoff"){
	document.images['Swatch_'+id+"_"+optionid].className="swatchoff";
  }
 
  //swapImage(previousImgID,previousImgSrc);
  swapText('SwatchStyleName_'+id, previousSwatchImgName);
   var swOptionCode =previousColorCode;

   swapAltImages(id,itemCode,swOptionCode);
 
  var zoomImageUrl = imagePath + AltImagePath  + itemCode + "." + swOptionCode + imgSuffix + 1 +imgExt;
  
  swapZoomImage(zoomImageUrl);
  //selectedColorCode=swOptionCode;
  //previousColorCode =optionCode;
  
  //alert("on mouse out "+previousColorCode );
  */

}

function swChgStyle(optionTypeID, optionTypeName, MENUPK,  PID ,swOptionID,id1, id2, id3){
	previousSwatchImgName = imageMsg+id3;
      	var oSelectObj    = document.getElementById(id1+MENUPK);
	setOptionSelect(oSelectObj, swOptionID);
	//alert("oSelectObj="+oSelectObj);
	ochod(oSelectObj, optionTypeName, MENUPK,  PID, optionTypeID, id1, id2, id3);
}

function setOptionSelect(oSelectObj, value){
	for (optionCounter = 0; optionCounter < oSelectObj.length; optionCounter++){
    	if(oSelectObj.options[optionCounter].value==value){
   			oSelectObj.selectedIndex=optionCounter;
		}
	}
}

function getCode(code){
    return code.replace("-","");

}

function getSwatchOption(option){
    option=option.replace(" ","");
	return option.toLowerCase()

}

function getDetailImageLink(){
    return code.replace("-","");

}
// Zoom and AlternateImage Related 

function setViewer(theFlashViewer) {
  this.theFlashViewer =theFlashViewer;
}


function changeOnOver(img,event)
{

	//alert("changeOnOver");
	if(event == "out")
	{
		//document.getElementById('SwatchDetail_${DetailModel.product.Pk.asString}').src=document.getElementById('SwatchDetail_${DetailModel.productPk.asString}').value;
		//swapZoomImage(img);
		//alert("out");
	}
	else
	{
			//document.getElementById('SwatchDetail_${QuicklookdetailModel.currentProduct.Pk.asString}').src=img;
			swapZoomImage(img);
			
	}
	
	
	
}

function  swapZoomImage(imgUrl,itemCode,optionCode) {
	
	//alert("swapZoomImage " +imgUrl );
	var  imgWidth =1100;
	var  imgHeight =1413;
	var width;
    var height;
	
	if(itemCode != undefined){
		imgUrl = imagePath + AltImagePath  + itemCode + "." + optionCode + imgSuffix + 1 +imgExt;
	}
	 for (var index = 0 ; index < zoomImages.length  ; index++) {
  
		if (zoomImages[index].url  == imgUrl ) {
			width=zoomImages[index].width;
			height =zoomImages[index].height;
			//alert(imgUrl);
			break;
		 }
    }
	 //For testing only  
	if(width >0) {
		imgWidth =width
	}
	if(width >0) {
		imgHeight =height
	}
	
	var zoom = Math.min( this.theFlashViewer.viewerWidth / imgWidth,
		this.theFlashViewer.viewerHeight / imgHeight );
 
	this.theFlashViewer.zoomTo( imgUrl, imgWidth,
		imgHeight, zoom, 0,
		imgHeight, 0, imgWidth );    

}
function swapAltImages(id,itemCode,selectedCode)
{
	var onerror ="this.src='"+ spaceImagePath +"'";
	 
	for (var J = 1 ; J < 5 ; J++) {

		var aTemp=document.getElementById('alt_'+J);
		if(aTemp!=null){
			var altImagePath =imagePath + AltImagePath  + itemCode + "." + selectedCode +imgSuffix +J+imgExt ;// + "?fit=57w73h";
			var link = "<c:url value='/product/zoom.do?productID=" + id +"' />"
			//alert(altImagePath);
			//alert(link);
			
			//aTemp.innerHTML="<A HREF=\"javascript:;\" onclick=\"javascript:flyopen(425,585,link,'ViewLarger');\"><img style='cursor:hand' class=checkoutouterborder src='"+altImagePath+"'  onmouseover=\"javascript:changeOnOver('"+altImagePath+"','over');\" onmouseout=\"javascript:changeOnOver('','out');\" onError=\""+onerror+"\"><\a>";
			//aTemp.innerHTML="<img style='cursor:hand' class=checkoutouterborder src='"+altImagePath+"' onclick=\"javascript:flyopen(425,585,link,'ViewLarger');\" onmouseover=\"javascript:changeOnOver('"+altImagePath+"','over');\" onmouseout=\"javascript:changeOnOver('','out');\" onError=\""+onerror+"\">";
			aTemp.innerHTML="<A HREF=\"javascript:;\" onclick=\"javascript:flyopen(425,585,link,'ViewLarger');\" onmouseover=\"javascript:changeOnOver('"+altImagePath+"','over');\" onmouseout=\"javascript:changeOnOver('','out');\"><img  class='imgborderdetail' src='"+altImagePath+"?fit=90w90h' WIDTH=\"69\" HEIGHT=\"76\"  onError=\""+onerror+"\"></A>";
		}
		
	}
		
}


function setPreSelectedOptions(selectedColor, selectedSize)
{
	
	if(selectedColor != null && selectedColor!="")
	{
		selectedColorOption = selectedColor;
	}

	if(selectedSize != null && selectedSize!="")
	{
		selectedSizeOption = selectedSize;
	}

}