function getServerName()
{
	if(needServerName=='true'){
        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){
	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
	}

	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{
			}
		}
	}
}


function setOchod(message) {

	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];

	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	var optionsTypeString = PRODUCTOPTION.getAttribute("optionsTypes");

	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")
        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\">"+followMenuPrefix+", 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")
	        newHtml=newHtml+"<option value=\""+optionID+"\" "+ selected +">"+optionName+"</option>";
        }

	    newHtml=newHtml+"</select>";
        mdiv = document.getElementById("div_options_"+id+"_"+optionsTypeID);
        mdiv.innerHTML = newHtml;
		optionTypeValues(getObjectByID(optionsTypeName+id));
		newHtml='';
    }

	var PRICEDISPLAY = PRODUCTOPTION.getElementsByTagName("PRICEDISPLAY")[0];

	if(PRICEDISPLAY!=null){
	    var Price= PRICEDISPLAY.getAttribute("Price");
	    var SalePrice = PRICEDISPLAY.getAttribute("SalePrice");
	    var SaveDollerAmt= PRICEDISPLAY.getAttribute("SaveDollerAmt");
	    var SAndHValue= PRICEDISPLAY.getAttribute("SAndHValue");
	    var InstallmentPrice= PRICEDISPLAY.getAttribute("InstallmentPrice");
        var EasyPayment= PRICEDISPLAY.getAttribute("EasyPayment");
	    var SavePercent= PRICEDISPLAY.getAttribute("SavePercent");

	    setDisplay("wasPrice_"+id, Price);
	    setDisplay("isPrice_"+id, SalePrice);
	    setDisplay("saveDollar_"+id, SaveDollerAmt);
	    setDisplay("SAndHValue_"+id, SAndHValue);
	    setDisplay("savePercent_"+id, SavePercent+'%');

	    var epayArr = easyPaymentMsg.split("0");
	    var epayArr2 = epayArr[1].split("1");
	    var epay=epayArr[0]+EasyPayment+epayArr2[0]+InstallmentPrice+epayArr2[1];

	    setDisplay("easy_"+id, epay);
	}

	var INVENTORY = PRODUCTOPTION.getElementsByTagName("INVENTORY")[0];

	if(INVENTORY!=null){
	    var Threshold= INVENTORY.getAttribute("Threshold");
	    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");
        if(Threshold!='0'){
            var onlyXArr = onlyXleftMsg.split("0");
		    setDisplay("thresHold_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
	    }
	    
	    if(Threshold=='0'){
	                //var onlyXArr = onlyXleftMsg.split("0");
	    		    setDisplay("thresHold_"+id, "");
	    }

	    var inventoryMsg ="";
		
		// Custom TSC Begin - Display all the stock availability-related messaging in one area
        if(InStock=='true') {
		    inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + inStockMsg;
	    } else {     // Out-Of-Stock

			// Out-Of-Stock & Not backorderable...
			if(ShowUnavailableOptions) {
				if(AdvanceOrder=='1'){
					inventoryMsg=advancedOrderMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else if(WaitingList=='1'){
					inventoryMsg=waitListMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else{
					inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + outOfStockMsg;
				}
			}
	    }
		
		//Check if the expected threshold container is present(product detail case) or not (family member case)
		if (document.getElementById("thresHold_"+id))
		{
			// Add the inventory messaging ONLY IF the threshold check didn't yield a result and the threshold_<ID> container is empty
			if(Threshold=='0')
			{
				setDisplay("thresHold_"+id, inventoryMsg);
				
			}
		}
		// Family Member case - always display the inventory messaging
		else
		{
			if (Threshold=='0')
			{
				setDisplay("inventory_"+id,  inventoryMsg);
			}
			else
			{
				setDisplay("inventory_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
			}
			
		}
		//setDisplay("inventory_"+id,  inventoryMsg);
		// Custom TSC End - Display all the stock availability-related messaging in one area
	}

	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");
    		var swOptionsTypeName = SWOPTIONTYPE.getAttribute("name");
			var selectedCode= SWOPTIONTYPE.getAttribute("selectedCode");
			var selectedName= SWOPTIONTYPE.getAttribute("selectedName");
			var selectedID=SWOPTIONTYPE.getAttribute("selectedID");
			var swatchDetailSize=getObjectByID('SwatchDetailSize_'+id);

            var swOptionCodeArr = selectedCode.split("_");
		    if (swOptionCodeArr.length >1 ) {
	 		            selectedCode=swOptionCodeArr[swOptionCodeArr.length-1]
	 		}

			var imgUrl=Scene7ImagesPath+itemCode+"_"+selectedCode;
			//setDisplay('SwatchStyleName_'+id, selectedName);
			swapImage('SwatchDetail_'+id,imgUrl+swatchDetailSize.value);
			document.images['Swatch_'+id+"_"+selectedID].className="swatchon";
			var preselectswatch=getObjectByID('PreSelectSwatch_'+id);
			document.images['Swatch_'+id+"_"+preselectswatch.value].className="swatchoff";
			preselectswatch.value=selectedID;
		}
	}

}
//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;
				// Custom TSC Begin - Incorporation of the new scene 7 product image viewer 
        		var s7ImageParameter = setInitod(response, swatch, swatchType);
				// Load the S7 player
				if (swatch == 'true')
				{
					loadS7Player(s7ImageParameter);
					
					// Need to get the id of the "style" drop-down from the xml object
					// ASSUMPTION: Style drop-down always is the first drop-down in case of "dependent dropdown menus"
					if (response.getElementsByTagName("PRODUCTOPTION")[0].getElementsByTagName("OPTIONTYPE")[0])
					{
						var PO = response.getElementsByTagName("PRODUCTOPTION")[0];
						var PO_id = PO.getAttribute("id");
						var PO_pid = PO.getAttribute("pid");
						var PO_optionsTypeString = PO.getAttribute("optionsTypes");
						var PO_optionsTypeId = PO.getElementsByTagName("OPTIONTYPE")[0].getAttribute("id");
						var PO_optionTypeName = PO.getElementsByTagName("OPTIONTYPE")[0].getAttribute("name");
						var PO_swOptionType = PO.getElementsByTagName("SWOPTIONTYPE")[0];
						if (PO_swOptionType != null)
						{
							var PO_swOptionsTypeId = PO_swOptionType.getAttribute("id");
							var PO_swOptionsTypeName = PO_swOptionType.getAttribute("name");
						}
						var dropdownId = PO_optionTypeName + PO_id;
						sjNotifyStyleChange = function (inIDX) {
							inIDX = parseInt(inIDX);
							if ((inIDX + 1) < document.getElementById(dropdownId).length)
							{
								document.getElementById(dropdownId).selectedIndex = inIDX + 1;
								if (isInitialInit)
								{
									isInitialInit = false;
									if (PO_swOptionType != null)
									{
										var swChgStyleInputText = PO_swOptionsTypeId + ",'" + PO_swOptionsTypeName + "'," + PO_id + "," + PO_pid + "," + document.getElementById(dropdownId).value + "," + PO_optionsTypeString;
										eval('swChgStyle(' + swChgStyleInputText + ')');
									}		
									else
									{
										ochod(document.getElementById(dropdownId), PO_optionTypeName, PO_id, PO_pid, PO_optionsTypeId, PO_optionsTypeString);
									}
								}
								else
								{
									if (PO_swOptionType != null)
									{
										var swChgStyleInputText = PO_swOptionsTypeId + ",'" + PO_swOptionsTypeName + "'," + PO_id + "," + PO_pid + "," + document.getElementById(dropdownId).value + "," + PO_optionsTypeString;
										eval('swChgStyle(' + swChgStyleInputText + ')');
									}
								}								
							}
							else
							{
								document.getElementById(dropdownId).selectedIndex = 0;
							}
						};
						var dropdownsList = [];
						// IE 6 drop-down not displaying issue fix
						for (ii = 0;ii <PO.getElementsByTagName("OPTIONTYPE").length;ii++)
						{
							dropdownsList[ii] = PO.getElementsByTagName("OPTIONTYPE")[ii].getAttribute("name") + PO_id;
						}
						elementsList =['detailQtySelect'];
						elementsList = elementsList.concat(dropdownsList);
					}
					else
					{
						sjNotifyStyleChange = function (inIDX) {};
						// IE 6 drop-down not displaying issue fix
						elementsList =['detailQtySelect'];
					}
					if (typeof window.setImageVideoTabContent == 'function')
					{
						setImageVideoTabContent("imageVideoTab01");
					}	
					// Custom TSC End - Incorporation of the new scene 7 product image viewer 
				}
				else
				{
					var PO = response.getElementsByTagName("PRODUCTOPTION")[0];
					var PO_id = PO.getAttribute("id");
					var PO_optionTypeName = PO.getElementsByTagName("OPTIONTYPE")[0].getAttribute("name");
					sjNotifyStyleChange = function (inIDX) {};
					var dropdownId = PO_optionTypeName + PO_id;
					var dropdownsList = [];
					// IE 6 drop-down not displaying issue fix
					for (ii = 0;ii <PO.getElementsByTagName("OPTIONTYPE").length;ii++)
					{
						dropdownsList[ii] = PO.getElementsByTagName("OPTIONTYPE")[ii].getAttribute("name") + PO_id;
						elementsList = elementsList.concat(dropdownsList);
					}
				}
			}
			else
			{
			}
		}
	}
}

function setInitod(message, swatch, swatchType) {
	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];
	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	var itemCode = PRODUCTOPTION.getAttribute("itemCode");
	var optionsTypeString = PRODUCTOPTION.getAttribute("optionsTypes");

	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")
        var optionsTypePos=optionsTypeObject.getAttribute("pos");
        var optionsTypePreFix=optionsTypeObject.getAttribute("preFix");
		
		if (swatch == 'true')
		{
			var newHtml="<select class=\"detail\" name=\"options_"+id+"_"+optionsTypeID+"\" id=\""+optionsTypeName+id+"\"  onChange=\"ochod(this, '"+optionsTypeName+"', "+id+","+ pid+", "+optionsTypeID+","+optionsTypeString+");if (this.selectedIndex == 0){var s7InputVal = 'select a value';}else{var s7InputVal = this.selectedIndex - 1;};sjSetNewStyleIdx(s7InputVal);\">";
		}
		else
		{
			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\">"+followMenuPrefix+", 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")
	        newHtml=newHtml+"<option value=\""+optionID+"\" "+ selected +">"+optionName+"</option>";

        }

	    newHtml=newHtml+"</select>";
		setDisplay("div_options_"+id+"_"+optionsTypeID, newHtml)
		if(hasElement ("div_options_"+id+"_"+optionsTypeID)){
		    optionTypeValues(getObjectByID(optionsTypeName+id));
		}
		newHtml='';
    }

	var PRICEDISPLAY = PRODUCTOPTION.getElementsByTagName("PRICEDISPLAY")[0];
	if(PRICEDISPLAY!=null){
	    var Price= PRICEDISPLAY.getAttribute("Price");
	    var SalePrice = PRICEDISPLAY.getAttribute("SalePrice");
	    var SaveDollerAmt= PRICEDISPLAY.getAttribute("SaveDollerAmt");
	    var SAndHValue= PRICEDISPLAY.getAttribute("SAndHValue");
	    var InstallmentPrice= PRICEDISPLAY.getAttribute("InstallmentPrice");
        var EasyPayment= PRICEDISPLAY.getAttribute("EasyPayment");
	    var SavePercent= PRICEDISPLAY.getAttribute("SavePercent");

	    setDisplay("wasPrice_"+id, Price);
	    setDisplay("isPrice_"+id, SalePrice);
	    setDisplay("saveDollar_"+id, SaveDollerAmt);
	    setDisplay("SAndHValue_"+id, SAndHValue);
	    setDisplay("savePercent_"+id, SavePercent+'%');

	    var epayArr = easyPaymentMsg.split("0");
	    var epayArr2 = epayArr[1].split("1");
	    var epay=epayArr[0]+EasyPayment+epayArr2[0]+InstallmentPrice+epayArr2[1];

	    setDisplay("easy_"+id, epay);
	}


	var INVENTORY = PRODUCTOPTION.getElementsByTagName("INVENTORY")[0];

	if(INVENTORY!=null){
	    var Threshold= INVENTORY.getAttribute("Threshold");
	    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");

        if(Threshold!='0'){
            var onlyXArr = onlyXleftMsg.split("0");
		    setDisplay("thresHold_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
	    }
		
		// Custom TSC Begin - Display all the stock availability-related messaging in one area
	    var inventoryMsg ="";
        if(InStock=='true') {
		    inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + inStockMsg;
	    } else {     // Out-Of-Stock
		    // Out-Of-Stock & Not backorderable...
			if(ShowUnavailableOptions) {
				if(AdvanceOrder=='1'){
					inventoryMsg=advancedOrderMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else if(WaitingList=='1'){
					inventoryMsg=waitListMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else{
					inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + outOfStockMsg;
				}
			 }
	    }
		
		//Check if the expected threshold container is present(product detail case) or not (family member case)
		if (document.getElementById("thresHold_"+id))
		{
			// Add the inventory messaging ONLY IF the threshold check didn't yield a result and the threshold_<ID> container is empty
			if(Threshold=='0')
			{
				setDisplay("thresHold_"+id, inventoryMsg);
				
			}
		}
		// Family Member case - always display the inventory messaging
		else
		{
			if (Threshold=='0')
			{
				setDisplay("inventory_"+id,  inventoryMsg);
			}
			else
			{
				setDisplay("inventory_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
			}
			
		}
		// Custom TSC End - Display all the stock availability-related messaging in one area
	}
    var largeImages='';
	if(showAdvancedSwatch && swatch=='true'){
		var swatchDetailSize=DetailImageSize;
		var swatchSize=SuperMiniThumbImageSize;
		var swatchColumn=5;
		if(swatchType=='Thumb'){
			swatchDetailSize=ThumbImageSize;
			swatchColumn=6;
		}
	    var SWOPTIONTYPE = PRODUCTOPTION.getElementsByTagName("SWOPTIONTYPE")[0];

	    if(SWOPTIONTYPE!=null){
	        //var itemCode=getCode(SWOPTIONTYPE.getAttribute("itemCode"));
	        var swOptionsTypeID = SWOPTIONTYPE.getAttribute("id")
            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 imgUrl=Scene7ImagesPath+itemCode+"_"+swOptionCode;
			        largeImages=largeImages+',TheShoppingChannel/'+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+"','"+imgUrl+swatchDetailSize+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+imgUrl+swatchSize+"\" WIDTH=\"40\" HEIGHT=\"40\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></td>";
                    }else{
                        sw=sw+"<td class=swatchspace><A HREF=\"javascript:;\" onMouseOver=\"swMouseOver(this, 'SwatchDetail_"+id+"','"+imgUrl+swatchDetailSize+"','"+swOptionName+"', '"+id+"','"+swOptionID+"')\" onMouseOut=\"swMouseOut(this, '"+id+"','"+swOptionID+"')\" onClick=\""+changeFun+";\"><IMG SRC=\""+imgUrl+swatchSize+"\" WIDTH=\"40\" HEIGHT=\"40\" ALT=\""+swOptionName+"\" BORDER=0 name=\"Swatch_"+id+"_"+swOptionID+"\" onError=\""+onerror+"\" class=swatchoff></A></td>";
                    }
			        if(swSelected=='Selected'){
				        preImageName=swOptionName;
				        preImage=imgUrl+swatchDetailSize;
				        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='SwatchDetailSize_"+id+"' value='"+swatchDetailSize+"'>  </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='TheShoppingChannel/'+itemCode;
			sw="<input type='hidden' id='largeImages_"+itemCode+"' value='"+largeImages+"'>";

			setDisplay("SwatchesDiv_"+id,sw) ;
		}
	}
	// Custom TSC Begin - Incorporation of the new scene 7 product image viewer 
	return largeImages;
	// Custom TSC End - Incorporation of the new scene 7 product image viewer 
}

//end init
//****************************


//****************************
//start init
function fixedod(url, swatch, swatchType)
{
	url=getServerName()+'/pom.do?method=initFixedOption&'+url;
	async=true;
	var req = newXMLHttpRequest();
	var handlerFunction = getFixedodHandler(req, swatch, swatchType);
	req.onreadystatechange = handlerFunction;
	req.open('GET', url, async);
	req.send(null);
}

function getFixedodHandler(req, swatch, swatchType)
{
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var response = req.responseXML;
        		setFixedod(response, swatch, swatchType);
			}else{
			}
		}
	}
}

function setFixedod(message, swatch, swatchType) {
	var PRODUCTOPTION = message.getElementsByTagName("PRODUCTOPTION")[0];
	var id = PRODUCTOPTION.getAttribute("id");
	var pid = PRODUCTOPTION.getAttribute("pid");
	var itemCode = PRODUCTOPTION.getAttribute("itemCode");

	var PRICEDISPLAY = PRODUCTOPTION.getElementsByTagName("PRICEDISPLAY")[0];
	if(PRICEDISPLAY!=null){
	    var Price= PRICEDISPLAY.getAttribute("Price");
	    var SalePrice = PRICEDISPLAY.getAttribute("SalePrice");
	    var SaveDollerAmt= PRICEDISPLAY.getAttribute("SaveDollerAmt");
	    var SAndHValue= PRICEDISPLAY.getAttribute("SAndHValue");
	    var InstallmentPrice= PRICEDISPLAY.getAttribute("InstallmentPrice");
        var EasyPayment= PRICEDISPLAY.getAttribute("EasyPayment");
	    var SavePercent= PRICEDISPLAY.getAttribute("SavePercent");

	    setDisplay("wasPrice_"+id, Price);
	    setDisplay("isPrice_"+id, SalePrice);
	    setDisplay("saveDollar_"+id, SaveDollerAmt);
	    setDisplay("SAndHValue_"+id, SAndHValue);
	    setDisplay("savePercent_"+id, SavePercent+'%');

	    var epayArr = easyPaymentMsg.split("0");
	    var epayArr2 = epayArr[1].split("1");
	    var epay=epayArr[0]+EasyPayment+epayArr2[0]+InstallmentPrice+epayArr2[1];

	    setDisplay("easy_"+id, epay);
	}


	var INVENTORY = PRODUCTOPTION.getElementsByTagName("INVENTORY")[0];

	if(INVENTORY!=null){
	    var Threshold= INVENTORY.getAttribute("Threshold");
	    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");

        if(Threshold!='0'){
            var onlyXArr = onlyXleftMsg.split("0");
		    setDisplay("thresHold_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
	    }

		// Custom TSC Begin - Display all the stock availability-related messaging in one area
	    var inventoryMsg ="";
        if(InStock=='true') {
		    inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + inStockMsg;
	    } else {     // Out-Of-Stock
		    // Out-Of-Stock & Not backorderable...
			if(ShowUnavailableOptions) {
				if(AdvanceOrder=='1'){
					inventoryMsg=advancedOrderMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else if(WaitingList=='1'){
					inventoryMsg=waitListMsg;
					if(BackOrderable=='true') {
        				inventoryMsg=inventoryMsg+', '+backorderMsg + " "+ RestockDate
					}
				}else{
					inventoryMsg = "<span class='availabilityTitle'>Availability:</span> " + outOfStockMsg;
				}
			 }
	    }		
		
		//Check if the expected threshold container is present(product detail case) or not (family member case)
		if (document.getElementById("thresHold_"+id))
		{
			// Add the inventory messaging ONLY IF the threshold check didn't yield a result and the threshold_<ID> container is empty
			if(Threshold=='0')
			{
				setDisplay("thresHold_"+id, inventoryMsg);
				
			}
		}
		// Family Member case - always display the inventory messaging
		else
		{
			if (Threshold=='0')
			{
				setDisplay("inventory_"+id,  inventoryMsg);
			}
			else
			{
				setDisplay("inventory_"+id, onlyXArr[0]+Threshold+onlyXArr[1]);
			}
			
		}
		// Custom TSC End - Display all the stock availability-related messaging in one area
	}
}

//end fixed
//****************************
function getSelectVariable(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){
	document.images[id].src=imgUrl;

}

function swMouseOver(object, imageid, imgUrl, name, id, optionid){
	if (document.images['Swatch_'+id+"_"+optionid].className!="swatchon"){
  document.images['Swatch_'+id+"_"+optionid].className="swatchover";
	}
  swapImage(imageid,imgUrl);
}

function swMouseOut(object, id, optionid){
  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){
	var oSelectObj    = document.getElementById(id1+MENUPK);
	setOptionSelect(oSelectObj, swOptionID);
	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 getDetailImageLink(){
    return code.replace("-","");

}

function getZoom(width, height,code, id){

     var largeImages=getObjectByID('largeImages_'+code);
	 var largeImageUrl1=largeImageUrl;
	 
	 if(largeImages!= "undefined" && largeImages.value.length==0){
		 SwatchDetail=document.images['SwatchDetail_'+id].src;

		 if(SwatchDetail.indexOf('_')>0){
			SwatchDetail=SwatchDetail.substring(SwatchDetail.indexOf('_'), SwatchDetail.indexOf('?'));
			largeImageUrl1=largeImageUrl1+'TheShoppingChannel/'+code+SwatchDetail;
		 }else{
			largeImageUrl1=largeImageUrl1+'TheShoppingChannel/'+code;
		 }
	 }else{
		
		largeImageUrl1=largeImageUrl1+largeImages.value;
		
     }
	 
     flyopen2(width, height,largeImageUrl1, 'LargeImageStyle');
}

function getMoreView(width, height,code, id){
    var largeImages=getObjectByID('largeImages_'+code);
	if(largeImages!= "undefined" && largeImages.value.length==0){
		 SwatchDetail=document.images['SwatchDetail_'+id].src;

		 if(SwatchDetail.indexOf('_')>0){
			SwatchDetail=SwatchDetail.substring(SwatchDetail.indexOf('_'), SwatchDetail.indexOf('?'));
			largeImageUrl=largeImageUrl+'TheShoppingChannel/'+code+SwatchDetail;
		 }else{
			largeImageUrl=largeImageUrl+'TheShoppingChannel/'+code;
		 }
	 }else{
		largeImageUrl=largeImageUrl+largeImages.value;
     }
    largeImageUrl=largeImageUrl+initialTabMultipleviews;

    flyopen2(width, height,largeImageUrl, 'MoreViews');

}

function getVideo(width, height,code, id){
    var largeImages=getObjectByID('largeImages_'+code);
	if(largeImages!= "undefined" && largeImages.value.length==0){
		 SwatchDetail=document.images['SwatchDetail_'+id].src;

		 if(SwatchDetail.indexOf('_')>0){
			SwatchDetail=SwatchDetail.substring(SwatchDetail.indexOf('_'), SwatchDetail.indexOf('?'));
			largeImageUrl=largeImageUrl+'TheShoppingChannel/'+code+SwatchDetail;
		 }else{
			largeImageUrl=largeImageUrl+'TheShoppingChannel/'+code;
		 }
	 }else{
		largeImageUrl=largeImageUrl+largeImages.value;
     }

    largeImageUrl=largeImageUrl+initialTabVideo;
    flyopen2(width, height,largeImageUrl, 'Video');

}


function flyopen2(width, height){
    width = (width && !isNaN(width))? width:null;
    height = (height && !isNaN(height))? height:null;
    var winURL = (arguments[2])? arguments[2]:null;
    var winName = (arguments[3])? arguments[3]:"generic";

	//only launch the window if we've got a width, height and url
	if (width && height && winURL){
        var ieIncrement = ((navigator.appName+"").indexOf("Netscape") == -1)? 0:0;
        eval(winName+"=window.open('"+ winURL +"','"+ winName +"','resizable=no,scrollbars=auto,width="+ (width + ieIncrement) +",height="+ (height + ieIncrement) +",top=5,left=75')");
        eval("window."+ winName +".focus()");
	}
}
