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, Z){
	//alert("optionType::"+optionType+", MENUPK::"+MENUPK);
	//alert("PID::"+PID+", menuPos::"+menuPos);
	//alert("id1::"+id1+", id2::"+id2+", id3::"+id3);
	//alert("oSelectObj="+ oSelectObj.value+" Z:"+Z);
	optionTypeValues(oSelectObj,Z);
	url=getServerName()+'/pom.do?method=onChange&MENUPK='+MENUPK+'&PID='+PID+'&OTN='+optionType+'&SEL_ROW='+Z;
	Select1=getSelectVariable(id1+MENUPK);
	if(Select1!=''){
		url=url+'&OT1='+id1
		url=url+'&'+id1+'='+oSelectObj.value//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,Z);
	req.onreadystatechange = handlerFunction;
	req.open('GET', url, async);
	req.send(null);
	//alert("End ochod");
}

function getOchodHandler(req,Z)
{
	//alert("getOchodHandler");
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var response = req.responseXML;
        		setOchod(response,Z);
			}else{
				//alert("getInitodHandler error: "+req.status);
			}
		}
	}
}


function setOchod(message,Z1) {

	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];

	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	var selRow = PRODUCTOPTION.getAttribute("selRow"); 
	//alert("id="+id+" pid="+pid+" selRow"+selRow);	
	var optionsTypeString = PRODUCTOPTION.getAttribute("optionsTypes");
	//alert("optionsTypeString="+optionsTypeString);

	var optionsTypeObjects = PRODUCTOPTION.getElementsByTagName("OPTIONTYPE");
for (var Z = 0 ; Z < loopCount ; Z++) {
	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+",'','"+Z+"');\">";
		

	    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>";
			newHtml=newHtml+"<option value=\"0\">Select a "+optionsTypeName+"</option>";
        }else{
            //newHtml=newHtml+"<option value=\"0\">"+followMenuPrefix+", Select a "+optionsTypeName+"</option>";
			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+"<option value=\""+optionID+"\" "+ selected +">"+optionName+"</option>";
        }

	    newHtml=newHtml+"</select>";
	    //alert("newHtml="+newHtml);
        mdiv = document.getElementById("div_options_"+id+"_"+optionsTypeID+"_"+Z);
        //alert(Z1+".."+Z);
		if(Z==Z1)
		{
			//alert("mdiv:"+mdiv.value);
        mdiv.innerHTML = newHtml;
		}
		optionTypeValues(getObjectByID(optionsTypeName+id),Z1);

		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) +'.jpg';

			//setDisplay('SwatchStyleName_'+id, selectedName);
			swapImage('SwatchDetail_'+id,detailImgUrl);
			//alert("selectedID="+selectedID);
			document.images['Swatch_'+id+"_"+selectedID].className="swatchon";
			var preselectswatch=getObjectByID('PreSelectSwatch_'+id);
			//alert("preselectswatch.value="+preselectswatch.value);
			if (preselectswatch.value!="") {
				document.images['Swatch_'+id+"_"+preselectswatch.value].className="swatchoff";
			}
				preselectswatch.value=selectedID;
				//alert("preselectswatch.value="+preselectswatch.value);
		}
	}

}
//end onclick
//****************************

//****************************
//start init
function initod(url, swatch, swatchType)
{
	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");
	//alert("loopCount="+loopCount);
	for(var Z = 0 ; Z < loopCount; Z++)
	{
	//alert("optionsTypeObjects.length::"+optionsTypeObjects.length);
	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");
        if (optionsTypeObjects.length==1)
        {
			var newHtml="<select class=\"detail\" name=\"options_"+id+"_"+optionsTypeID+"\" id=\""+optionsTypeName+id+"\"  onChange=\"ochod(this, '"+optionsTypeName+"', "+id+","+ pid+", "+optionsTypeID+","+optionsTypeString+",'','','"+Z+"');\">";
        }else{
			var newHtml="<select class=\"detail\" name=\"options_"+id+"_"+optionsTypeID+"\" id=\""+optionsTypeName+id+"\"  onChange=\"ochod(this, '"+optionsTypeName+"', "+id+","+ pid+", "+optionsTypeID+","+optionsTypeString+",'','"+Z+"');\">";
		}
		//alert(newHtml);
	    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>";
			newHtml=newHtml+"<option value=\"0\">Select a "+optionsTypeName+"</option>";
        }else{
            //newHtml=newHtml+"<option value=\"0\">"+followMenuPrefix+", Select a "+optionsTypeName+"</option>";
			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+"\" "+ ">"+optionName+additionalMessage+"</option>";
			//newHtml=newHtml+"<option value=\""+optionID+"\" "+ selected +">"+optionName+additionalMessage+"</option>";
			//newHtml=newHtml+"<option value=\""+optionID+"\" >"+optionName+"</option>";

        }

	    newHtml=newHtml+"</select>";

		setDisplay("div_options_"+id+"_"+optionsTypeID+"_"+Z, newHtml)
		if(hasElement ("div_options_"+id+"_"+optionsTypeID+"_"+Z)){
			//alert("inside if:: "+Z);
		    optionTypeValues(getObjectByID(optionsTypeName+id),Z);
		}
		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=4;
		//alert("showAdvancedSwatch="+showAdvancedSwatch);
		if(swatchType=='Thumb'){
			swatchDetailPath=ThumbImagePath;
			swatchColumn=6;
		}
	    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 BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">";

                for (var I = 0 ; I < swOptionsObjects.length ; 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+"</tr>";
			        }*/
			        if(I%swatchColumn==0){
				        sw=sw+"<tr valign=top>";
			        }
			        var changeFun="swChgStyle("+swOptionsTypeID+",'"+swOptionsTypeName+"',"+id+","+ pid+","+swOptionID+","+optionsTypeString+")";
			        var detailImgUrl=imagePath+swatchDetailPath+itemCode+"_"+getSwatchOption(swOptionCode) +'.jpg';
					var swatchImgUrl=imagePath+ThumbImagePath+'SW_'+itemCode+"_"+getSwatchOption(swOptionCode) +'.jpg';
			        largeImages=largeImages+','+itemCode+"_"+swOptionCode;
			        var onerror="this.src='"+imagePath+"local/products/prodnotavail.jpg'";
			        if(I%swatchColumn==(swatchColumn-1)){
                        //sw=sw+"<td class=lastswatchspace><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"40\" HEIGHT=\"40\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></td>";
						sw=sw+"<td align=center class=lastswatchspace><div style=\"padding-left:10px;padding-right:10px;margin-bottom:5px;\"><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"35\" HEIGHT=\"35\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" class=swatchoff></A></div><div style=\"font-family : Arial, Verdana, Geneva, Helvetica, sans-serif;font-size: 9px;color: #666666;\">"+swOptionName+"</div></td>";
                    }else{
                        //sw=sw+"<td  class=swatchspace><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"40\" HEIGHT=\"40\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></td>";
						sw=sw+"<td align=center class=swatchspace><div style=\"padding-left:10px;padding-right:10px;margin-bottom:5px;\"><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+detailImgUrl+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+swatchImgUrl+"\" WIDTH=\"35\" HEIGHT=\"35\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" class=swatchoff></A></div><div style=\"font-family : Arial, Verdana, Geneva, Helvetica, sans-serif;font-size: 9px;color: #666666;\">"+swOptionName+"</div></td>";
                    }
			        if(swSelected=='Selected'){
				        preImageName=swOptionName;
				        preImage=detailImgUrl;
				        preImageID=swOptionID;
			        }

			        if(I%swatchColumn==(swatchColumn-1)){
				        sw=sw+"</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, preImageName);

	        if(hasSWoptions){

	            //swapImage('SwatchDetail_'+id,preImage);
	            //document.images['Swatch_'+id+"_"+preImageID].className="swatchon";
	        }

	    }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 swMouseOver(object, imageid, imgUrl, name, id, optionid){
	//setDisplay('SwatchStyleName_', name);
	if (document.images['Swatch_'+id+"_"+optionid].className!="swatchon"){
  document.images['Swatch_'+id+"_"+optionid].className="swatchover";
	}

  swapImage(imageid,imgUrl);
}

function swMouseOut(object, id, optionid){
	//setDisplay('swstylename', 'Click to select a style');
  if (document.images['Swatch_'+id+"_"+optionid].className!="swatchon"){
	document.images['Swatch_'+id+"_"+optionid].className="swatchoff";
  }
swapImage(previousImgID,previousImgSrc);
}

function swChgStyle(optionTypeID, optionTypeName, MENUPK,  PID ,swOptionID,id1, id2, id3){
	//alert("swChgStyle");

	var oSelectObj    = document.getElementById(id1+MENUPK);
	setOptionSelect(oSelectObj, swOptionID);
	//alert("oSelectObj="+oSelectObj);
	ochod(oSelectObj, optionTypeName, MENUPK,  PID, optionTypeID, id1, id2, id3,'0');
}

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("-","");

}


