
var gShipMode = SHIP_MODE_DOMESTIC;

//---------------------------------------------------------
function setMainIMG(iIdx)
{
  var altText;

  if (gPics.length <= 1) {
      altText = createAltText();
  } else {
      altText = createAltText(iIdx +1);
  }

  setImageWithAspect('art_main_picture',gPics[iIdx],altText,400);
}

//---------------------------------------------------------
function createAltText(num)
{
  var altText=gXmlVars["cache.art.text.alt.prodimage"];
  if (num) { // Image # Product name
    altText=altText.replace(/%s/,gXmlVars["cache.art.text.alt.image"] + " ");
    altText=altText.replace(/%d/,(num) + " ");
  } else { //assume only one image
    altText=altText.replace(/%s/,"");
    altText=altText.replace(/%d/,"");
  }
  return altText;
}

//---------------------------------------------------------
function initPictures()
{
	//-- show big img
	if ( gPics.length > 0 )
	{
		setMainIMG(0);
	}
	
	//-- show small images
	if ( gPics.length > 1 )
	{
		var iPicCnt = gPics.length;
		if(iPicCnt > 12) iPicCnt = 12;		//limit to 12
		
		var iIdx = 0;
		var iRows = Math.ceil(iPicCnt/6);
		var sHtml = '<table class="picture_thumb_tbl" border=0 cellpadding=0 cellspacing=0 style="width: 400px;">';
		
		for(var iR=0; iR<iRows; iR++)
		{
			sHtml += '<tr>';

			for(var iC=0; iC<6; iC++)
			{
				if(iIdx < iPicCnt)
				{
				  sHtml += '<td align=center valign=middle><a href="javascript:setMainIMG('+iIdx+');"><img class="view_item_thumb" border=0 id="smallPic'+iIdx+'" src="'+gLoadingPicSmall+' alt="' + createAltText(iIdx+1) + '"></td>';
				}
				else
				{
					sHtml += '<td align=center valign=middle>&nbsp;</td>';
				}

				iIdx ++;
			}

			sHtml += '</tr>'
		}
		
		//end the table
		sHtml += '</table>';

		$( 'art_picture_list' ).update(sHtml);
		
		//load thumbs with aspect
		for(var i=0; i<gPics.length; i++)
		{
		  setImageWithAspect('smallPic'+i, gPics[i],createAltText(i+1),64);	
		}
	
		$( 'art_picture_list_container' ).style.display = 'block';
	}
}

//---------------------------------------------------------
function resizePopup(sBase, iMaxSz)
{
	var h;
	
	h = $("flox_" + sBase +"_content_inner").offsetHeight;
	if(h < iMaxSz) $("flox_" + sBase +"_content").style.height = h + "px";
}

//---------------------------------------------------------
function onShowFullDesc(e, el)
{
	closeAllPopups();	
	var el = $("show_full_desc_link");
	
	e = e || window.event;
	var op = getElementPosition(el);
	var topY = op.y + 20;
	
	$("flox_description").style.top = topY + "px";
	$("flox_description").show();
	
	resizePopup("description",530);

	el.hide();
	$("hide_full_desc_link").show();
	
	Event.stop(e);
}

//---------------------------------------------------------
function onCloseFullDesc(e)
{
	e = e || window.event;
	$("flox_description").hide();
	$("show_full_desc_link").show();
	$("hide_full_desc_link").hide();
	Event.stop(e);
}

//---------------------------------------------------------
function onShowShipping(e, el, iMode)
{
	closeAllPopups();
	gCurShipElement = el;
	e = e || window.event;
	var op = getElementPosition(el);
	var topX = op.x - 260;
	var topY = op.y + 20;
	
	$("flox_shipping_form").style.left = topX + "px";
	$("flox_shipping_form").style.top = topY + "px";
	
	//clear error case
	$("flox_ship_err_msg").hide();
	$("flox_ship_selcountry").className = "";
	$("flox_ship_selzip").className = "";

	//hide progress
	$("flox_ship_loading").hide();

	gShipMode = iMode;
	switch(iMode)
	{
		case SHIP_MODE_DOMESTIC:
			onShowShippingDomestic(e,el);
			break;
		case SHIP_MODE_INTERNATIONAL:
			onShowShippingInternational(e,el);
			break;
		default:
			onShowShippingBIN();
	}
	
	Event.stop(e);
}

//---------------------------------------------------------
function onShowShippingDomestic(e, el)
{
	$("flox_shipform_cntry").hide();
	$("flox_shipform_zip").show();

	$("ship_zip").value = gShipLastDomestic.zip;
	$("ship_country").value = gShipLastDomestic.country;
	onShippingCountryChanged();
	$("flox_shipping_form").show();	
	$("ship_zip").focus();
}

//---------------------------------------------------------
function onShowShippingInternational(e, el)
{	
	$("flox_shipform_cntry").show();
	$("flox_shipform_zip").show();
	
	$("ship_zip").value = gShipLastIntl.zip;
	if(gShipLastIntl.country)
	{
	    $("ship_country").value = gShipLastIntl.country;
    }
    else
    {
		$("ship_country").value = "US";
    }

	onShippingCountryChanged();
	$("flox_shipping_form").show();	
	$("ship_country").focus();
}

//---------------------------------------------------------
function onShowShippingBIN(e, el)
{	
	if(gHasInternationalShipping) $("flox_shipform_cntry").show();
	else $("flox_shipform_cntry").hide();

	$("flox_shipform_zip").show();
	
	$("ship_zip").value = gShipLastBIN.zip;

	if(gShipLastBIN.country)
	{
		$("ship_country").value = gShipLastBIN.country;
	}
	else
	{
		//default to US
		$("ship_country").value = "US";
	}

	onShippingCountryChanged();
	$("flox_shipping_form").show();	
	$("ship_country").focus();
}

//--------------------------------------------------------
// shipping country changed
function onShippingCountryChanged() 
{
	//clear error case
	$("flox_ship_err_msg").hide();
	$("flox_ship_selcountry").className = "";
	$("flox_ship_selzip").className = "";

	var oSel = $("ship_country");
	var sCntry = oSel.value.toUpperCase();
	
	if(sCntry == "CA" || sCntry == "US")
	{
		//show zip field, but hide title
		$("flox_shipform_zip").show();
	}
	else
	{
		$("ship_zip").value = "";
		$("flox_shipform_zip").hide();
	}
}

//---------------------------------------------------------
function onCloseShippingForm(e)
{
	e = e || window.event;
	$("flox_shipping_form").hide();
	
	if(e) Event.stop(e);
}

//---------------------------------------------------------
function onShowTrustologyDetails(e, el)
{	
	closeAllPopups();	
	var el = $("show_trust_details_link");
	
	e = e || window.event;
	var op = getElementPosition(el);
	var topX = op.x - 320;
	var topY = op.y - 200;
	
	$("flox_trustology").style.left = topX + "px";
	$("flox_trustology").style.top = topY + "px";
	$("flox_trustology").show();
	
	resizePopup("trustology",430);

	el.hide();
	$("hide_trust_details_link").show();
	
	Event.stop(e);
}

//---------------------------------------------------------
function onCloseTrustologyDetails(e)
{
	e = e || window.event;
	$("flox_trustology").hide();
	$("show_trust_details_link").show();
	$("hide_trust_details_link").hide();
	Event.stop(e);
}

//---------------------------------------------------------
function onShowGoodPrintDetails(e, el)
{	
	closeAllPopups();	
	var el = $("show_gp_details_link");
	
	e = e || window.event;
	var op = getElementPosition(el);
	var topX = op.x - 320;
	var topY = op.y - 200;
	
	$("flox_goodprint").style.left = topX + "px";
	$("flox_goodprint").style.top = topY + "px";
	$("flox_goodprint").show();
	
	resizePopup("goodprint",430);

	el.hide();
	$("hide_gp_details_link").show();
	
	Event.stop(e);
}

//---------------------------------------------------------
function onCloseGoodPrintDetails(e)
{
	e = e || window.event;
	$("flox_goodprint").hide();
	$("show_gp_details_link").show();
	$("hide_gp_details_link").hide();
	Event.stop(e);
}

//---------------------------------------------------------
function closeAllPopups()
{
	$("flox_description").hide();
	$("show_full_desc_link").show();
	$("hide_full_desc_link").hide();
	
	if($("flox_goodprint") && $("hide_gp_details_link"))
	{
		$("flox_goodprint").hide();
		$("show_gp_details_link").show();
		$("hide_gp_details_link").hide();
	}

	if($("flox_trustology"))
	{
		$("flox_trustology").hide();
		$("show_trust_details_link").show();
		$("hide_trust_details_link").hide();
	}

	$("flox_shipping_form").hide();
}

//---------------------------------------------------------
function calculateShipping()
{
	closeAllPopups();
}

//---------------------------------------------------------
function initializeShoppingAPI()
{   
	//NOTE: now explicitly includes the required JS file
	//in the page

	//com.ebay.widgets.needs(/*com.ebay.widgets.util.Resource*/ {
	//	baseUrl: 'http://w-1.ebay.com/js/2.0/min/',
	//	files: ['GetShippingCosts.js'],
	//	resources: com.ebay.shoppingservice.Shopping.getShippingCosts,
	//	callback: function() { shoppingAPIInitialized(); } }
	//);

	shoppingAPIInitialized();
}   

//---------------------------------------------------------
function shoppingAPIInitialized()
{    
	if(gCalcShippingOnLoad)
	{
		calculateShippingOnLoad();
	}
}   

//--------------------------------------------------------
// start search domestic shipping info
function calculateShippingOnLoad() 
{
	if(gPrefPostalCode && (gPrefCountryCode == "US" || gPrefCountryCode == "CA"))
	{
        //zip code defined, with no country or with US/CA
		$("ship_zip").value = gPrefPostalCode;
		gShipMode = SHIP_MODE_DOMESTIC;
        
        if(gPrefCountryCode == "CA") 
        {
            $("ship_country").value = "CA";
		    gShipMode = SHIP_MODE_INTERNATIONAL;
        }
	}
	else if(gPrefCountryCode)
	{
		$("ship_country").value = gPrefCountryCode;
		gShipMode = SHIP_MODE_INTERNATIONAL;
	}

	goSearchShipping();
}

//---------------------------------------------------------
function ShippingService(config)
{
	this.config = config;
	this.sCountryCode = "";
	this.sCountryName = "";
	this.sZip = "";
	
	//called when the GetShippingCosts ajax request returns successfully for
	//a domestic shipping rate.  The function process the shipping service data
	this.onRateCallbackDomestic = function(data) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		// hide error and loading block
		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").hide();
		$("flox_ship_go").disabled = false;
		
		if(!data.shippingDetails)
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
			return;
		}

		if(this.hasServiceRate(data.shippingDetails.shippingServiceOption))
		{
			gShipLastDomestic.country = this.sCountryCode;
			gShipLastDomestic.zip = this.sZip;
			
			this.setRatesToNotAvilable(SHIP_MODE_DOMESTIC, this.sZip);

			for(i=0; i<data.shippingDetails.shippingServiceOption.length; i++)
			{
				var oShp = data.shippingDetails.shippingServiceOption[i];
				this.processServiceOption(oShp, this.sZip);
			}
			
			this.updateBINShipping(data.shippingDetails.shippingServiceOption,null);
			onCloseShippingForm();
		}
		else
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
		}

	}
		
	//called when the GetShippingCosts ajax request returns failure. basically
	//shows an error message in the shipping popup
	this.onCallbackFailedDomestic = function(error) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").show();
		
		if(error[0].errorCode == "10.8")
		{
			$("ship_err_msg").update(gXmlVars["shared.art.text.entervalidzip"]);
		}
		else
		{
			$("ship_err_msg").update(error[0].longMessage);
		}

		$("flox_ship_go").disabled = false;
	}
	    
	//called when the GetShippingCosts ajax request returns successfully for
	//a int'l shipping rate.  The function process the shipping service data
	this.onRateCallbackInternational = function(data) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		// hide loading and error block
		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").hide();
		$("flox_ship_go").disabled = false;
		
		if(!data.shippingDetails)
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
			return;
		}

		// update prices all international shipping
		if (this.hasServiceRate(data.shippingDetails.internationalShippingServiceOption))
		{
			gShipLastIntl.country = this.sCountryCode;
			gShipLastIntl.zip = this.sZip;
			
			//to set an initial condition, all service rows in the shipping table
			//are set to display "Not Available". Then as we process the options in
			//response, the correct values will be placed in the table
			this.setRatesToNotAvilable(SHIP_MODE_INTERNATIONAL, this.sCountryName);
			
			//go through each returned rate
			for(i=0; i<data.shippingDetails.internationalShippingServiceOption.length; i++)
			{
				var oShp = data.shippingDetails.internationalShippingServiceOption[i];
				this.processServiceOption(oShp, this.sCountryName);
			}
			
			//update the buy it now shipping information
			this.updateBINShipping(null, data.shippingDetails.internationalShippingServiceOption);
			onCloseShippingForm();
		}
		else
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
		}
		
	}
	
	//called when the GetShippingCosts ajax request returns failure. basically
	//shows an error message in the shipping popup
	this.onCallbackFailedInternational = function(error) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").show();
		
		if(error[0].errorCode == "10.8")
		{
			$("ship_err_msg").update(gXmlVars["shared.art.text.entervalidzip"]);
		}
		else
		{
			$("ship_err_msg").update(error[0].longMessage);
		}

		$("flox_ship_go").disabled = false;
	} 

	//called when the GetShippingCosts ajax request returns successfully for
	//a shipping rate.  This can be a domestic or international rate request because
	//it originated from the BIN shipping area.
	this.onRateCallbackBIN = function(data) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		// hide error and loading block
		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").hide();
		$("flox_ship_go").disabled = false;
				
		if(!data.shippingDetails)
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
			return;
		}

		if(this.hasServiceRate(data.shippingDetails.shippingServiceOption) ||
		   this.hasServiceRate(data.shippingDetails.internationalShippingServiceOption))
		{

			if(this.sCountryCode == "US")
			{
				gShipLastDomestic.zip = this.sZip;

				// update prices all domestic shipping
				if(gCalculatedDomestic)
				{
					this.setRatesToNotAvilable(SHIP_MODE_DOMESTIC, this.sZip);
					
					if ( data.shippingDetails.shippingServiceOption )
					{
						for(i=0; i<data.shippingDetails.shippingServiceOption.length; i++)
						{
							var oShp = data.shippingDetails.shippingServiceOption[i];
							this.processServiceOption(oShp, this.sZip);
						}
					}
				}
			}
			else
			{
				// update prices all international shipping
				if(gCalculatedInternational)
				{
					this.setRatesToNotAvilable(SHIP_MODE_INTERNATIONAL, this.sCountryName);
					
					if ( data.shippingDetails.internationalShippingServiceOption )
					{
						for(i=0; i<data.shippingDetails.internationalShippingServiceOption.length; i++)
						{
							var oShp = data.shippingDetails.internationalShippingServiceOption[i];
							this.processServiceOption(oShp, this.sCountryName);
						}
						
					}
				}
			}

			this.updateBINShipping(data.shippingDetails.shippingServiceOption,
								   data.shippingDetails.internationalShippingServiceOption);

			onCloseShippingForm();
		}
		else
		{
			$("flox_ship_err_msg").show();
			$("ship_err_msg").update(gXmlVars["shared.art.text.general_ship_err"]);
		}

	}
		
	//called when the GetShippingCosts ajax request returns failure. basically
	//shows an error message in the shipping popup
	this.onCallbackFailedBIN = function(error) 
	{
		window.clearTimeout(gShippingTimer);
		gShippingTimer = null;

		$("flox_ship_loading").hide();
		$("flox_ship_err_msg").show();
		
		if(error[0].errorCode == "10.8")
		{
			$("ship_err_msg").update(gXmlVars["shared.art.text.entervalidzip"]);
		}
		else
		{
			$("ship_err_msg").update(error[0].longMessage);
		}

		$("flox_ship_go").disabled = false;
	}
	 
	//check to see if at lease one service in the array returned a valid
	//shipping rate for the request.
	this.hasServiceRate = function(aServices)
	{
		if(aServices)
		{
			for(var i=0; i<aServices.length; i++)
			{
				//first service that has a rate
				if(aServices[i].shippingServiceCost)
				{
					return true;
				}
			}
		}

		return false;
	}
	
	//set all the appropriate shipping table rows to "Not Available"
	this.setRatesToNotAvilable = function(iMode, sShipTo)
	{
		for(var i=0; i<gShippingOpt.length; i++)
		{
			if(gShippingOpt[i].mode == iMode)
			{	
				var srvnm = gShippingOpt[i].service.toLowerCase();
				srvnm = srvnm.replace(/\s+/g,'_');

				var idCostDiv = 'shipCalc_' + srvnm;
				var idReDiv = 'shipReCalc_' + srvnm;
				var idLink = 'shipCalcLink_' + srvnm;
				
				try
				{
					$(idCostDiv).update(gXmlVars["shared.art.text.notavailable"]);
					$(idReDiv).show();
					$(idLink).update(sShipTo);
				}
				catch (e) { }
			}
		}
	}
	
	//process the passed shipping option, update its information on the 
	//view item page, reveal the link to recalculate the shipping
	this.processServiceOption = function(oShp, sShipTo)
	{
		if(oShp.shippingServiceCost)
		{
			var srvnm = oShp.shippingServiceName.toLowerCase();
			srvnm = srvnm.replace(/\s+/g,'_');

			var costWithCurrency = '';
			var idCostDiv = 'shipCalc_' + srvnm;
			var idReDiv = 'shipReCalc_' + srvnm;
			var idLink = 'shipCalcLink_' + srvnm;

			if ( oShp.shippingServiceCost == 0 )
				costWithCurrency = gXmlVars["cache.art.text.freecaps"];
			else
				costWithCurrency = formatCurrency(oShp.shippingServiceCost,gBidCurrency);
			
			try
			{
				$(idCostDiv).update('<span class="shipping_cost">' + costWithCurrency + '</span>');
				$(idReDiv).show();
				$(idLink).update(sShipTo);
			}
			catch (e) { }
		}
	}
	
	this.updateBINShipping = function(aDomestic, aIntl)
	{
		var oShp = null;
		var oMinDom = this.findMinimumRateService(aDomestic, this.sCountryCode);
		var oMinIntl = this.findMinimumRateService(aIntl, this.sCountryCode);
		
		gShipLastBIN.country = this.sCountryCode;
		gShipLastBIN.zip = this.sZip;
		
		if(oMinDom)
			saveShippingInfo(oMinDom.shippingServiceCost, this.sZip, this.sCountryCode);
		else if(oMinIntl)
			saveShippingInfo(oMinIntl.shippingServiceCost, this.sZip, this.sCountryCode);

		if( oMinDom )
		{
			//use domestic shipping
			this.updateBINShippingHTML(this.sZip,oMinDom.shippingServiceCost);		
		}
		else if( oMinIntl)
		{
			//use international shipping
			if(this.sCountryCode == "CA")
			{
				//show zip code for Canada
				this.updateBINShippingHTML(this.sZip,oMinIntl.shippingServiceCost);
			}
			else
			{
				this.updateBINShippingHTML(this.sCountryName,oMinIntl.shippingServiceCost);
			}
		}
	}
	
	//update the BIN shipping areas with the given shipping information
	this.updateBINShippingHTML = function(sShipTo, sCost)
	{
		var sVal = '';

		if(sCost == 0) sVal = gXmlVars["cache.art.text.freecaps"];
		else sVal = '<span class="shipping_cost">' + formatCurrency(sCost,gBidCurrency) + '</span>';

		var sLbl = gXmlVars["shared.art.text.shippingto"] + "&nbsp;<a href='#' onclick='onShowShipping(event,this,SHIP_MODE_COMBINED)'>" + sShipTo + "</a>:";
		$("shipping_label_1").update(sLbl);
		$("shipping_label_2").update(sLbl);
		$("shipping_value_1").update(sVal);
		$("shipping_value_2").update(sVal);
	}
	
	//find the minimum service rate that supports the given country code
	this.findMinimumRateService = function(aShp, sCountryCode)
	{
		var minVal = 99999999;
		var minSvc = null;

		if(aShp)
		{
			for(var i=0; i<aShp.length; i++)
			{
				//first service that has a rate
				if(aShp[i].shippingServiceCost && this.doesServiceShipTo(aShp[i],sCountryCode))
				{
					if(aShp[i].shippingServiceCost.value < minVal)
					{
						minVal = aShp[i].shippingServiceCost.value;
						minSvc = aShp[i];
					}
				}
			}
		}
		
		return minSvc;
	}
	
	//looks through the service ships to array and determines if the desired ship to
	//location is in the list
	this.doesServiceShipTo = function(oService, sCountryCode)
	{
		if(!sCountryCode) return true;
		
		//no shipts to location? assume its US (domestic)
		if(!oService.shipsTo)
		{
			if(sCountryCode == "US") return true;
			else return false;
		}

		for(var i=0; i<oService.shipsTo.length; i++)
		{
			if(this.isCountryInShippingRegion(oService.shipsTo[i],sCountryCode)) return true;
		}

		return false;
	}

	//looks through the countries that make up the shipping region and
	//determines if the given country code is part of the region
	this.isCountryInShippingRegion = function(sRegion, sCountryCode)
	{
		if(gShippingRegionMap[sRegion])
		{
			var aReg = gShippingRegionMap[sRegion];
			for(var i=0; i<aReg.length; i++)
			{
				if(aReg[i] == sCountryCode) return true;
			}
		}

		return false;
	}

	this.getShippingInfoDomestic = function(sItemID, sZipCode)
	{
		this.sCountryCode = "US";
		this.sCountryName = "United States";
		this.sZip = sZipCode;

		// new Shopping service	
		var service = new com.ebay.shoppingservice.Shopping(this.config);
		var fRequest = new com.ebay.shoppingservice.GetShippingCostsRequestType({
											IncludeDetails: true,
											ItemID: sItemID, 
											DestinationCountryCode: "US",
											DestinationPostalCode: sZipCode});
		var url = service.getShippingCosts(fRequest,{object: this, success: this.onRateCallbackDomestic, failure: this.onCallbackFailedDomestic  });
	}

	this.getShippingInfoInternational = function(sItemID, sCountryCode, sCountryName, sZipCode)
	{
		this.sCountryCode = sCountryCode;
		this.sCountryName = sCountryName;
		this.sZip = sZipCode;
		
		// new Shopping service	
		var service = new com.ebay.shoppingservice.Shopping(this.config);
		var params = { IncludeDetails: true, ItemID: sItemID, DestinationCountryCode: sCountryCode };			
		if(sZipCode) params.DestinationPostalCode = sZipCode;
		
		var fRequest = new com.ebay.shoppingservice.GetShippingCostsRequestType(params);
		var url = service.getShippingCosts(fRequest,{object: this, success: this.onRateCallbackInternational, failure: this.onCallbackFailedInternational  });
	}
	
	this.getShippingInfoBIN = function(sItemID, sCountryCode, sCountryName, sZipCode)
	{
		this.sCountryCode = sCountryCode;
		this.sCountryName = sCountryName;
		this.sZip = sZipCode;
		
		// new Shopping service	
		var service = new com.ebay.shoppingservice.Shopping(this.config);
		var params = { IncludeDetails: true, ItemID: sItemID, DestinationCountryCode: sCountryCode };			
		if(sZipCode) params.DestinationPostalCode = sZipCode;
		
		var fRequest = new com.ebay.shoppingservice.GetShippingCostsRequestType(params);
		var url = service.getShippingCosts(fRequest,{object: this, success: this.onRateCallbackBIN, failure: this.onCallbackFailedBIN });
	}
	
}

//---------------------------------------------------------
function killShippingRequest()
{
	gShippingTimer = null;
	$("flox_ship_loading").hide();
	$("flox_ship_err_msg").show();
	$("ship_err_msg").update(gXmlVars["cache.art.error.shopping_api_timeout"]);
	$("flox_ship_go").disabled = false;
}

//---------------------------------------------------------
function saveShippingInfo(sCost, sZip, sCountry)
{
    try
    {
        document.BinForm1.shipcost.value = formatCurrency(sCost,gBidCurrency);
        document.BinForm1.shipzip.value = sZip ? sZip : "";
        document.BinForm1.shipcountry.value = sCountry ? sCountry : "";

        document.BinForm2.shipcost.value = formatCurrency(sCost,gBidCurrency);
        document.BinForm2.shipzip.value = sZip ? sZip : "";
        document.BinForm2.shipcountry.value = sCountry ? sCountry : "";
    }
    catch (e)
    {
    }
}

//--------------------------------------------------------
// start search domestic shipping info
function goSearchShipping() 
{	
	$("flox_ship_go").disabled = true;
	$("flox_ship_err_msg").hide();
	$("flox_ship_loading").show();
	$("flox_ship_selcountry").className = "";
	$("flox_ship_selzip").className = "";

	var props = {};
	props["appId"] = gShoppingAppId;
	props["siteId"] = gRequestSiteId;
    
	if(gShipMode == SHIP_MODE_DOMESTIC) goSearchDomestic(props);
	else if(gShipMode == SHIP_MODE_INTERNATIONAL) goSearchInternational(props);
	else goSearchBIN(props);
}

//--------------------------------------------------------
// start search domestic shipping info
function goSearchDomestic(props) 
{	
	var sZip = $F("ship_zip");

	//check zip
	if(validateZipCode(sZip, "US") == false) return;
	
	try
	{
		//start timeout
		gShippingTimer = window.setTimeout(killShippingRequest,60000);
		var config = new com.ebay.shoppingservice.ShoppingConfig(props);
		new ShippingService(config).getShippingInfoDomestic(gItemId, sZip);					
	}
	catch (err)
	{
		window.clearTimeout(gShippingTimer);
		killShippingRequest();
	}
}

//--------------------------------------------------------
// start search international shipping info
function goSearchInternational(props) 
{
	var sCntry = $F("ship_country").toUpperCase();
	var sCntryNm = $("ship_country").options[$("ship_country").selectedIndex].text;
	var sZip = $F("ship_zip");
	
	if(sCntry == "US" || sCntry == "CA")
	{
		//check zip
		if(validateZipCode(sZip,sCntry) == false) return;
	}
	else
	{
		if(validateCountry(sCntry) == false) return;
		sZip = "";
	}
	
	try
	{
		//start timeout
		gShippingTimer = window.setTimeout(killShippingRequest,60000);
		var config = new com.ebay.shoppingservice.ShoppingConfig(props);
		new ShippingService(config).getShippingInfoInternational(gItemId, sCntry, sCntryNm, sZip);
	}
	catch (err)
	{
		window.clearTimeout(gShippingTimer);
		killShippingRequest();
	}
}

//--------------------------------------------------------
// start search international + domestic shipping info
function goSearchBIN(props) 
{
	var sCntry = $F("ship_country").toUpperCase();
	var sCntryNm = $("ship_country").options[$("ship_country").selectedIndex].text;
	var sZip = $F("ship_zip");
	
	if(sCntry == "US" || sCntry == "CA")
	{
		//check zip
		if(validateZipCode(sZip,sCntry) == false) return;
	}
	else
	{
		if(validateCountry(sCntry) == false) return;
		sZip = "";
	}
	
	try
	{
		//start timeout
		gShippingTimer = window.setTimeout(killShippingRequest,60000);
		var config = new com.ebay.shoppingservice.ShoppingConfig(props);
		new ShippingService(config).getShippingInfoBIN(gItemId, sCntry, sCntryNm, sZip);
	}
	catch (err)
	{
		window.clearTimeout(gShippingTimer);
		killShippingRequest();
	}
}

//--------------------------------------------------------
// start search international shipping info
function validateCountry(sCntry) 
{
	//check country
	if(sCntry == "")
	{
		$("flox_ship_go").disabled = false;
		$("flox_ship_err_msg").show();
		$("flox_ship_selcountry").className = "flox_ship_red_bold";
		$("flox_ship_loading").hide();
		$("ship_err_msg").update(gXmlVars["shared.art.text.entershiplocation"]);
		return false;
	}

	return true;
}

//--------------------------------------------------------
// start search international shipping info
function validateZipCode(sZip, sCntry) 
{
	sCntry = sCntry.toUpperCase();

	//check zip
	if( (sZip.length == 0) ||
		(sCntry == "US" && sZip.search(rexUSZip) < 0) ||
		(sCntry == "CA" && sZip.search(rexCAZip) < 0) )
	{
		$("flox_ship_go").disabled = false;
		$("flox_ship_err_msg").show();
		$("flox_ship_selzip").className = "flox_ship_red_bold";
		$("flox_ship_loading").hide();
		$("ship_err_msg").update(gXmlVars["shared.art.text.entervalidzip"]);
		return false;
	}

	return true;
}

//---------------------------------------------------------
function _jiveGetSellerInfo(bResult, sImg, sText)  
{  
	window.clearTimeout(gJiveTimer);
	gJiveTimer=null;

	var date = new Date();
	var randstr = "?rstr=" + date.getTime();


	if(bResult)
	{
		if(sImg) $('imgSellerImg').src = sImg + randstr;
	}

	if(!sText)
	{
		sText = gXmlVars["shared.art.text.defaultquote"];
	}

	//trim text
	if(sText.length > 150)
	{
	   sText = sText.substr(0,147) + "...";
    }

	$('divSellerDescArea').show();
	$('divSellerDesc').update(sText);
}

//---------------------------------------------------------
function injectScript(sSource)  
{ 
	var oReq = new oJSONScriptReq(sSource);
	oReq.inject();
} 

//---------------------------------------------------------
function getSellerInfo(sId, sCallback)  
{
	var date = new Date();
    var randstr = "&rstr=" + date.getTime();

	var sEncId = encodeURIComponent(sId);
	injectScript(gSellerAPIUrl + "?avatarSize=96&output_method=ajax&eiasToken=" + sEncId + "&callback=" + sCallback + randstr);

	gJiveTimer = window.setTimeout(getSellerInfoFailed,5000);
} 

//---------------------------------------------------------
function getSellerInfoFailed()  
{
	if($('divSellerDesc'))
	{
		var sText = gXmlVars["shared.art.text.defaultquote"];
		$('divSellerDesc').update(sText);
	}

	gJiveTimer = null;
} 

//---------------------------------------------------------
function resetStyle()
{
	if (document.body.style.background != "#F4F4E8")
	{
		document.body.style.background = "#F4F4E8";
	}

    if(document.body.style.fontFamily != "Verdana,helvetica,arial")
	{
        document.body.style.fontFamily = "Verdana,helvetica,arial";
	}

	if(document.body.style.fontWeight != "normal")
	{
        document.body.style.fontWeight = "normal";
	}

	if(document.body.style.fontSize != "12px")
	{
        document.body.style.fontSize = "12px";
	}
	 
	if(document.body.style.width != "960px")
	{
       document.body.style.width = "960px"; 
	}
	if(document.body.style.height != "100%")
	{
       document.body.style.height = "100%"; 
	}

     document.body.style.textAlign="left";
		
    if(document.getElementsByTagName("td").style.color != '#666666')
	{
      document.getElementsByTagName("td").style.color = '#666666';
	}

	 //if($('breadcrumbs').style.fontSize != "10px")
	 //{
      //$('breadcrumbs').style.fontSize = "10px";
     //}
}

//---------------------------------------------------------

// method: hideAllSelects
//---------------------------------------------------------
function hideAllSelects() {
    if(document.all) { // Only do this for IE
        var aEl = document.all.tags("SELECT");
        if(aEl) {
            for(var idx=0; idx < aEl.length; idx++) {
                aEl[idx].style.visibility = "hidden";
            }
        } 
    }
}

//---------------------------------------------------------
// method: showAllSelects
//---------------------------------------------------------
function showAllSelects()
{
 if(document.all) // Only do this for IE
 {
  var aEl = document.all.tags("SELECT");

  if(aEl)
  {
   for(var idx=0; idx < aEl.length; idx++)
   { 
    aEl[idx].style.visibility = "visible";
   }
  }
 }
}

//---------------------------------------------------------
function watchItem(sItemId)
{
    $j('#watchThisLink').css('display', 'none');
    $j('#watchLoad').css('display', '');
    var l_url = '/my/watchitem.html?item=' + sItemId;
    $j.ajax( {
            url: l_url,
            success: onItemWatched
          } );
}

//---------------------------------------------------------
function onItemWatched(sResp)
{
    try
    {
        sResp = sResp.replace(/\s/g,'');

        if(sResp == 'ERROR')
        {
            $j('#watchArea').css('display', 'none');
            alert('Unable to add this item.');
        }
        else
        {
            $j('#watchLoad').css('display', 'none');
            $j('#watchingThis').css('display', '');
        }
    }
    catch(e) { }
}


