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.toLowerCase()+"</option>";
        }else if(optionsTypePreFix=='FIRST'){
            newHtml=newHtml+"<option value=\"0\">"+firstMenuPrefix+", select a "+optionsTypeName.toLowerCase()+"</option>";
        }else{
            newHtml=newHtml+"<option value=\"0\">"+followMenuPrefix+", select a "+optionsTypeName.toLowerCase()+"</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.indexOf('true') != -1 ) {
						InStock=InStock.substring(4,InStock.length+1);
						var str1 =InStock.substring(0,InStock.indexOf("-"));
						var str2=InStock.substring(InStock.indexOf("-")+1,InStock.length);
  				        str2 = trimAll(str2);
  				      
						if (str2=="" || str2=="null") {
							//inventoryMsg=str1+" - "+inStockMsg+str2;
							inventoryMsg = str1+" - "+backorderMsg+str2;
						} else {

							inventoryMsg=str1+" - "+inStockMsg;
							
						}
						
//						alert("inStockMsg" + inStockMsg);
	//					alert("backorderMsg" + backorderMsg);
					    //	inventoryMsg=str1+" - "+inStockMsg+str2;
						//inventoryMsg=""+InStock+inStockMsg					

					}else {     // Out-Of-Stock
						// Out-Of-Stock & Not backorderable...
						if(BackOrderable=='true') {
        						inventoryMsg=" - "+backorderMsg + " "+ RestockDate
						}else if("null"==InStock || ""==InStock)
						{ 
							inventoryMsg="";
						}
						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'){
						if(SalePrice != "null")
							additionalMessage+=" - "+SalePrice;
					}else{
						if(Price != "null")
							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.indexOf('true') != -1 ) {
					InStock=InStock.substring(4,InStock.length+1);
					var str1 =InStock.substring(0,InStock.indexOf("-"));
					var str2=InStock.substring(InStock.indexOf("-")+1,InStock.length);
					 str2 = trimAll(str2);
						if (str2=="" || str2=="null") {
							//inventoryMsg=str1+" - "+inStockMsg+str2;
							inventoryMsg = str1+" - "+backorderMsg+str2;
						} else {

							inventoryMsg=str1+" - "+inStockMsg;
							
						}
				    //inventoryMsg=str1+" - "+inStockMsg+str2;
				  //  alert(inventoryMsg);
//					inventoryMsg=""+InStock+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 if("null"==InStock || ""==InStock){ 
					inventoryMsg="";
				}
				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);
			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");
	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="<div style=\"padding-bottom:5px;\"><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.toLowerCase()+"</option>";
        }else if(optionsTypePreFix=='FIRST'){
            newHtml=newHtml+"<option value=\"0\">"+firstMenuPrefix+", select a "+optionsTypeName.toLowerCase()+"</option>";
        }else{
            newHtml=newHtml+"<option value=\"0\">"+followMenuPrefix+", select a "+optionsTypeName.toLowerCase()+"</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.indexOf('true') != -1 ) {
					InStock=InStock.substring(4,InStock.length+1);
					var str1 =InStock.substring(0,InStock.indexOf("-"));
					var str2=InStock.substring(InStock.indexOf("-")+1,InStock.length);
				     str2 = trimAll(str2);


						if (str2=="" || str2=="null") {
							//inventoryMsg=str1+" - "+inStockMsg+str2;
							inventoryMsg = str1+" - "+backorderMsg+str2;
						} else {

							inventoryMsg=str1+" - "+inStockMsg;
							
						}
				    //inventoryMsg=str1+" - "+inStockMsg+str2;
//				    alert(inventoryMsg);
//					inventoryMsg=""+InStock+inStockMsg
					//alert(inventoryMsg);

					} else {     // Out-Of-Stock
						// Out-Of-Stock & Not backorderable...
						if(BackOrderable=='true') {
        						inventoryMsg=" - "+backorderMsg + " "+ RestockDate
						}else if("null"==InStock || ""==InStock){ 
							inventoryMsg="";
						}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'){
						if(SalePrice != "null")	
							additionalMessage+=" - "+SalePrice;
					}else{
						if(Price != "null")
							additionalMessage+=" - "+Price;
					}
				}

			}
			newHtml=newHtml+"<option value=\""+optionID+"\" >"+optionName+additionalMessage+"</option>";// deleted  "+ selected +"


        }

	    newHtml=newHtml+"</select></div>";
	    //alert("newHtml="+newHtml);
		setDisplay("div_options_"+id+"_"+optionsTypeID, newHtml)
		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.indexOf('true') != -1 ) {
				   InStock=InStock.substring(4,InStock.length+1);
					var str1 =InStock.substring(0,InStock.indexOf("-"));
					var str2=InStock.substring(InStock.indexOf("-")+1,InStock.length);
					 str2 = trimAll(str2);
						if (str2=="" || str2=="null") {
							//inventoryMsg=str1+" - "+inStockMsg+str2;
							inventoryMsg = str1+" - "+backorderMsg+str2;
						} else {

							inventoryMsg=str1+" - "+inStockMsg;
							
						}
				    //inventoryMsg=str1+" - "+inStockMsg+str2;
//		    inventoryMsg=inStockMsg + InStock

	    } 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 if("null"==InStock || ""==InStock){ 
					inventoryMsg="";
				}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;
		}
	    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+"\"><b>Click to view another color:</b></div></td>";
						sw=sw+"<td colspan="+swatchColumn+" class=swatchtext><img src="+imagePath+"local/page_specific/detail/color.gif border=\"0\" alt=\'Click to view another color\'></td>";
				        sw=sw+"</tr>";
			        }
			        if(I%swatchColumn==0){
				        sw=sw+"<tr valign=top><td class=swatchcell>";
			        }
			        var changeFun="swChgStyle("+swOptionsTypeID+",'"+swOptionsTypeName+"',"+id+","+ pid+","+swOptionID+","+optionsTypeString+")";
			        var detailImgUrl=imagePath+swatchDetailPath+itemCode+"_"+getSwatchOption(swOptionCode) +'.jpg';
					var swatchImgUrl=imagePath+swatchDetailPath+itemCode+"_"+getSwatchOption(swOptionCode) +'.jpg';
			        largeImages=largeImages+','+itemCode+"_"+swOptionCode;
			       // var onerror="this.src='"+imagePath+"local/products/prodnotavail.jpg'";
				    var onerror="";
			        if(I%swatchColumn==(swatchColumn-1)){
                        sw=sw+"<div 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=\"50\" HEIGHT=\"50\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></div>";
                    }else{
                        sw=sw+"<div 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=\"50\" HEIGHT=\"50\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></div>";
                    }
			        if(swSelected=='Selected'){
				        preImageName=swOptionName;
				        preImage=detailImgUrl;
				        preImageID=swOptionID;
			        }

			        if(I%swatchColumn==(swatchColumn-1)){
				        sw=sw+"</td></tr>";
			        }
		        }

		        if(I%swatchColumn!=(swatchColumn-1)){
			        for(var j=I%swatchColumn; j<swatchColumn; j++){
				        sw=sw+"</td><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) ;
	        //commented to display 'Click to view another color:'
	        //setDisplay('SwatchStyleName_'+id, preImageName);

			// commentecd for displaying default image at detail page when page gets loaded.
	       // 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);
	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";
  }

}

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);
}

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("-","");
    return code;

}

function getSwatchOption(option){
    option=option.replace(" ","");
	return option.toLowerCase()

}

function getDetailImageLink(){
    //return code.replace("-","");
    return code;	
}
//function to trim white spaces in string
function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

