$(window).resize(function(){
	getIconLoc();
});


$(document).ready(function(){
	equalColumns();
	// Toggle search menu items
	$("#search-text").click(function() {
		if(this.value == "Search") {
			this.value = "";
		}
	});

	$("#search-text").blur(function() {
		if(this.value == "") {
			this.value = "Search";
		}
	});

	$(".searchCategories li a").click(function() {
		if($(this).parent().get(0).id != "") {
			var clickedLi = $(this).parent().get(0).id;
			$(".searchCategories li a").each(function () {	
				if($(this).parent().get(0).id != clickedLi){
					if(this.className == "active") {
						$(this).next('ul').hide("fast");
						$(this).removeClass("active");
					}
				}
			});
		}
		
		if($(this).hasClass("more")) {
			$(this).hide();
			if(navigator.appName == "Microsoft Internet Explorer" && jQuery.browser.version < 8.0) {
				$(this).next('ul').css({'margin-top': '-12px'});
			}
		}
		else if($(this).hasClass("less")) {
			lessLi = $(this).parent().get(0);
			lessLiUl = $(lessLi).parent().get(0);
			moreLi = $(lessLiUl).parent().get(0);
			moreLink = $(moreLi).children();
			$(lessLiUl).hide("fast");
			$(moreLink).show();
		}
		$(this).toggleClass("active");
		$(this).next('ul').toggle("fast");
	});
	
	// Show drop-down navigation on mouseover
	$("#mainNavigation li").mouseover(function() {
		if(this.id != "") {
			$("#" + this.id + " ul").show();					   
			$(this).addClass("over");
		}
	});

	// Hide drop-down navigation on mouseout
	$("#mainNavigation li").mouseout(function() {
		if(this.id != "") {
			$("#" + this.id + " ul").hide();					   
			$(this).removeClass("over");
		}
	});
	
	// Fix for z-index of selects in IE
	if($.browser.msie && $.browser.version == 6) {
	$("#mainNavigation ul ul").bgiframe();
	}
	
	// Toggle news items on homepage
	$(".newsController").click(function() {
		var clicked = this;
		var newsNum = $(clicked).attr('className').split(' ').pop();
		$(".currentHeadlines .newsExpanded").each(function () {
			var newsExpanded = $(this).attr('className').split(' ').pop();
			var newsExpanded = newsExpanded.split('item').pop();
			if(newsNum == newsExpanded) {
				if($(clicked).html() == "[-]") {
					$(clicked).html("[+]");
					$(".item" + newsExpanded).hide();
				}
				else {
					$(clicked).html("[-]");
					$(".item" + newsExpanded).show();
				}
			}
			else {
				$(".currentHeadlines a").each(function () {
					if($(this).hasClass("newsController") && this != clicked) {
						$(this).html("[+]");
						$(".item" + newsExpanded).hide();
					}
				});
			}
		});
	});
	
	/* Hide search parameters
	$(".searchParams li").click(function() {
		$(this).hide();
	});	*/
	
	// Hide pop-ups on click of the body
	$(document).bind('click', function(e) {
		var infoPopUps = $(".infoPopUp");
    	var $clicked=$(e.target); // get the element clicked
		if(!($clicked.is('.icon') || $clicked.is('.rateNum') || $clicked.is('.weatherIcon') || $clicked.is('.bidIncrement') || $clicked.parents().is('.icon') || $clicked.parents().is('.weatherIcon') || $clicked.parents().is('.bidIncrement') || $clicked.is('.closeButton') || $clicked.parents().is('.cartWrapper .closeButton') || $clicked.parents().is('.bidCartWrapper .closeButton') || $clicked.parents().is('#TastingExp .closeButton') || $clicked.parents().is('#moreOptions .closeButton'))) {
			jQuery.each(infoPopUps, function(i, val) {
				if(infoPopUps[i].style.display == "block") {
					infoPopUps[i].style.display = "none";
				}
			});
			$(".icon, .weatherIcon").each(function () {
				if($(this).hasClass("active")) {
					$(this).removeClass("active");
				}
			});
		}
		else if(($clicked.is('.rateNum') || $clicked.is('.closeButton') || $clicked.parents().is('.closeButton') || $clicked.parents().is('#TastingExp .closeButton') || $clicked.parents().is('#moreOptions .closeButton'))) {
			$(".icon, .weatherIcon").each(function () {
				if($(this).hasClass("active")) {
					$(this).removeClass("active");
				}
			});
			$(".cartWrapper").hide();
			$(".bidCartWrapper").hide();
		}
	});
	
	// Display wine bottle info pop-up
	$(".icon, .weatherIcon").click(function() {
		var currentIcon = this;
		var popUpId = $(currentIcon).attr('className').split(' ').pop();
		$(currentIcon).toggleClass('active');
		var iconPosition = $(currentIcon).position();
		if($(currentIcon).hasClass('.weatherIcon')) {
			$("#" + popUpId).css({left:iconPosition.left+35,top:iconPosition.top-17});
		}
		else {
			$("#" + popUpId).css({left:iconPosition.left+20,top:iconPosition.top-17,'z-index':100});
			if(!($(currentIcon).hasClass('.help'))) {
				$(".gridRow").each(function () {
					$(this).css({'z-index': 1});
				});
		        getSimplePopup(popUpId);
			}
		}
		$("#" + popUpId).toggle();
		$(".closeButton").click(function() {
			$("#" + popUpId).hide();
		});
		$(".infoPopUp").each(function () {
			if(this.id != popUpId) {
				$(this).hide();
			}
		});
		$(".icon, .weatherIcon").each(function () {
			if(this != currentIcon && $(this).hasClass("active")) {
				$(this).removeClass("active")
			}
		});
	});

	// Display rating excerpt pop-up
	$(".bidIncrement").click(function() {
 	 	$(".gridRow").each(function () {
          	$(this).css({'z-index': 1});
   	    });
		currentLink = this;
		var popUpId = $(currentLink).attr('className').split(' ').pop();
		var parentDivs = $("#" + popUpId).parents();
		$(parentDivs).each(function () {
			if($(this).hasClass('gridRow')) {
				$(this).css({'z-index':75});
			}
	    });
		var linkPosition = $(currentLink).position();
        $("#" + popUpId).css({left:linkPosition.left-305,top:linkPosition.top-53});        
		if($("#" + popUpId).css('display') == "none") {
			$("#" + popUpId).css({'display': 'block'});
		}
		else {
			$("#" + popUpId).css({'display': 'none'});
		}
		$(".closeButton").click(function() {
			$("#" + popUpId).hide();
		});
		$(".infoPopUp").each(function () {
			if(this.id != popUpId) {
				$(this).hide();
			}
		});
	});

	// Display shopping cart pop-up and update quantity
	$(".addCartButton").click(function() {
		
		// set the value for how long the card dropdown stays open
		var dropdownTimer = 5000;
		
		// the second class in the cart button - comprised of lot and sale nums
		var cartButtonClass = $(this).attr('className').split(' ').pop();
		
		// get the id which contains the quantity
		var quantityId = cartButtonClass + '_qty';
		
		// get the number of items in cart originally
		var numCartItems = $(".numCart").text();
		var numCartItemsVal = parseInt(numCartItems);
		
		// get the number of new items
		var itemstoAdd = parseInt($("#" + quantityId).val());
		
		// split the class into lot and sale nos
		var idArray = cartButtonClass.split('_');
		
		// set some variables to update the cart
		var lotNo = idArray[1];
		var saleNo = idArray[2];
		var cartNo = document.addCart.cartPublicId.value;
			
		// use the cart ajax proxy
		var thisCartProxy = new cartProxy();
		
		// call the editCartContentRemote cffunction
		var resultObj = thisCartProxy.editCartContentRemote(cartNo, lotNo, saleNo, itemstoAdd, 'false');
		// parse the JSON cart dropdown
		//var resultObj = $parseJSON(result);
		var theContents = '';
		
		// if there's an error message, output it
		if (resultObj.errorMessage.message != '') {
			theContents = theContents + '<p class="cartProductInfo">';
			theContents = theContents + '<p class="lowQuantity">' + resultObj.errorMessage.messageLabel + '</p>';
			theContents = theContents + '<p class="lowQuantityInfo">' + resultObj.errorMessage.message + '</p>';
			theContents = theContents + '</p>';
			theContents = theContents + '<p class="viewCart"><a href="/shopping-cart"><img src="/common/images/template/view_cart.gif" alt="View Cart" /></a></p>';
			dropdownTimer = 6000;
		} else {
			
			// create the cart in html
			theContents = '<p class="addedToCart">';
			theContents = theContents + '<a href="javascript:void(0);" class="closeButton"><img src="/common/images/template/close.gif" alt="close" /></a>';
			theContents = theContents + 'Added to your cart:';
			theContents = theContents + '</p>';
			theContents = theContents + '<p class="cartProductInfo">';
			
			// loop through the bottle names
			for (var i=0; i < resultObj.bottleNames.length; i++) {
				theContents = theContents + '<a href="##">' + resultObj.bottleNames[i] + '</a>' + '<br />';
			}
			
			theContents = theContents + 'PRICE: ' + resultObj.price + ' ' + resultObj.pricingGroup + '<br />';
			theContents = theContents + 'QTY: ' + resultObj.quantity + ' ' + resultObj.quantityGroup + '<br />';
			theContents = theContents + '</p>';
			
			if (resultObj.quantityAvailable <= 2) {
				theContents = theContents + '<p class="lowQuantity">Low Quantity Alert</p>';
				theContents = theContents + '<p class="lowQuantityInfo">Please be aware that you are not guaranteed this bottle until your sale is complete. Though our inventory listed is real-time, it is possible for another person to add this to their cart and check out before you finalize your purchase.</p>';
				dropdownTimer = 6000;
			}
			theContents = theContents + 'SUBTOTAL: ' + resultObj.subtotal + '<br />';
			theContents = theContents + '<p class="cartTotal">Cart Total:' + resultObj.total + '</p>';
			theContents = theContents + '<p class="viewCart"><a href="/shopping-cart"><img src="/common/images/template/view_cart.gif" alt="View Cart" /></a></p>';
			
			// grab the spans in which we display this lot's availability
			var qtyNotInCart = '#' + cartButtonClass + '_qtyNotInCart';
			var qtyInCart = '#' + cartButtonClass + '_qtyInCart';
			
			// change the available quantity
			$(qtyNotInCart).html(resultObj.availabilityInfo.sizeDescription + ' ');
			
			// if there's a item in the cart, tell us, otherwise, clear the field.
			if (resultObj.quantityInCart != 0) {
				$(qtyInCart).html('(' + resultObj.quantityInCart + ' in cart)');
			}
			else {
				$(qtyInCart).html('');
			}
		}

		// update the number displayed in the cart
		$(".numCart").text(resultObj.numberInCart);
		$(".numCartDrop").text(resultObj.numberInCart);
		
		// handle the cart dropdown effects
		$(".cartContents").html(theContents);
		$(".cartWrapper").show();
		scrollTop = $(window).scrollTop();
		if(scrollTop > 90) {
			jQuery.each(jQuery.browser, function(i, val) {
				if(!($.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")) {
					$(".cartWrapper").css({'top': '0px', 'position': 'fixed', 'margin-top': '0px'});
				}
				else{
					scroll(0,0);
				}
			});	
		}

		// clear the quantity field
		$("#" + quantityId).val('');
		
		setTimeout('$(".cartWrapper").hide();', dropdownTimer);
		setTimeout('$(".cartWrapper").css({"top": "auto", "position": "absolute", "margin-top": "-69px"});', dropdownTimer);
	});	
	
	// Display Bid cart pop-up and update quantity
	$(".bidCartButton").click(function() {

		// set the value for how long the card dropdown stays open
		var dropdownTimer = 5000;
		
		// the second class in the cart button - comprised of lot and sale nums
		var cartButtonClass = $(this).attr('className').split(' ').pop();
		
		// get the id which contains the quantity
		var quantityId = cartButtonClass + '_qty';
		
		// get the number of items in cart originally
		var numCartItems = $(".numBids").text();
		var numCartItemsVal = parseInt(numCartItems);
		
		// get the number of new items
		var itemstoAdd = parseInt($("#" + quantityId).val());
		
		// split the class into lot and sale nos
		var idArray = cartButtonClass.split('_');
		
		// set some variables to update the cart
		var lotNo = idArray[1];
		var saleNo = idArray[2];
		var cartNo = document.addCart.cartPublicId.value;
			
		// use the cart ajax proxy
		var thisCartProxy = new cartProxy();
		
		// call the editCartContentRemote cffunction
		var result = thisCartProxy.editCartContentRemote(cartNo, lotNo, saleNo, itemstoAdd, 'false');
		
		// parse the JSON cart dropdown
		var resultObj = $.evalJSON(result);
		var theContents = '';

		// if there's an error message, output it
		if (resultObj.errorMessage.message != '') {
			theContents = theContents + '<p class="bidCartProductInfo">';
			theContents = theContents + '<p class="lowQuantity">' + resultObj.errorMessage.messageLabel + '</p>';
			theContents = theContents + '<p class="lowQuantityInfo">' + resultObj.errorMessage.message + '</p>';
			theContents = theContents + '</p>';
			theContents = theContents + '<p class="viewCart"><a href="cart.html"><img src="/common/images/template/view_cart.gif" alt="View Cart" /></a></p>';
			dropdownTimer = 6000;
		} else {
			
			// create the cart in html
			theContents = '<p class="addedToCart">';
			theContents = theContents + '<a href="javascript:void(0);" class="closeButton"><img src="/common/images/template/close.gif" alt="close" /></a>';
			theContents = theContents + 'Added to your cart:';
			theContents = theContents + '</p>';
			theContents = theContents + '<p class="bidCartProductInfo">';
			
			// loop through the bottle names
			for (var i=0; i < resultObj.bottleNames.length; i++) {
				theContents = theContents + '<a href="##">' + resultObj.bottleNames[i] + '</a>' + '<br />';
			}
			
			theContents = theContents + 'PRICE: ' + resultObj.price + ' ' + resultObj.pricingGroup + '<br />';
			theContents = theContents + 'QTY: ' + resultObj.quantity + ' ' + resultObj.quantityGroup + '<br />';
			theContents = theContents + '</p>';
			
			if (resultObj.quantityAvailable <= 2) {
				theContents = theContents + '<p class="lowQuantity">Low Quantity Alert</p>';
				theContents = theContents + '<p class="lowQuantityInfo">Please be aware that you are not guaranteed this bottle until your sale is complete. Though our inventory listed is real-time, it is possible for another person to add this to their cart and check out before you finalize your purchase.</p>';
				dropdownTimer = 6000;
			}
			theContents = theContents + 'SUBTOTAL: ' + resultObj.subtotal + '<br />';
			theContents = theContents + '<p class="cartTotal">Cart Total:' + resultObj.total + '</p>';
			theContents = theContents + '<p class="viewCart"><a href="cart.html"><img src="/common/images/template/view_cart.gif" alt="View Cart" /></a></p>';
			
			// grab the spans in which we display this lot's availability
			var qtyNotInCart = '#' + cartButtonClass + '_qtyNotInCart';
			var qtyInCart = '#' + cartButtonClass + '_qtyInCart';
			
			// change the available quantity
			$(qtyNotInCart).html(resultObj.availabilityInfo.sizeDescription + ' ');
			
			// if there's a item in the cart, tell us, otherwise, clear the field.
			if (resultObj.quantityInCart != 0) {
				$(qtyInCart).html('(' + resultObj.quantityInCart + ' in cart)');
			}
			else {
				$(qtyInCart).html('');
			}
		}
			
		// handle the cart dropdown effects
		$(".cartContents").html(theContents);
		$(".cartWrapper").show();
		scrollTop = $(window).scrollTop();
		if(scrollTop > 90) {
			jQuery.each(jQuery.browser, function(i, val) {
				if(!($.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")) {
					$(".cartWrapper").css({'top': '0px', 'position': 'fixed', 'margin-top': '0px'});
				}
				else{
					scroll(0,0);
				}
			});	
		}
		$(".numBids").text(resultObj.numberInCart);
		$(".numBidsDrop").text(numCartItemsVal);
		
		// clear the quantity field
		$("#" + quantityId).val('');
		setTimeout('$(".bidCartWrapper").hide();', dropdownTimer);
		setTimeout('$(".bidCartWrapper").css({"top": "auto", "position": "absolute", "margin-top": "-69px"});', dropdownTimer);
	});	

	//Display international shipping address form
	$(".internationalAddress").click(function() {
		if($(this).html() == "International Users Click Here") {
			$(this).html("Domestic Users Click Here");
			$("#countryToggle").val("International");
		}
		else {
			$(this).html("International Users Click Here");
			$("#countryToggle").val("US");
		}
		ColdFusion.Event.callBindHandlers('countryToggle',null,'change');
	});	

	// hide or display shipping methods based upon a selected address and a country code
	$(".shippingAddressSelect").change(function() {
		var countryToggle = $("#countryToggle").val();
		if(this.value == "" || countryToggle != "US") {
			$(".chooseShipping").hide();
		}
		else {
			$(".chooseShipping").show();
		}
	});
	
	//Set Tax Price
	$(".shippingInfo input.zip").blur(function() {
		if(this.value != "") {
			$(".taxes").html("$152.73");
		}
		else {
			$(".taxes").html("TBD");
		}
	});
	
	//Edit address
	$(".chosenAddress a").click(function() {
		$(".chosenAddress").hide();
		$(".domesticAddressForm").show();
	});	

	$(".showUForm").click(function() {
		$(".forgotUsername").show();
		$(".forgotPassword").hide();
	});	

	$(".showPForm").click(function() {
		$(".forgotPassword").show();
		$(".forgotUsername").hide();
	});	
	
	$(".readMore").click(function() {
		var isVisible = $('.bidsheetInfo').is(':visible');
		if (isVisible == false) {
			$(".expandhide").hide();
			$(".bidsheetInfo").show();
		} else {
			$(".expandhide").show();
			$(".bidsheetInfo").hide();
		}
	});	
	
	$("#payByCheck").click(function() {
		$(".payByCheck").toggle();
	});
	
	$("#isGift").click(function() {
		$("#giftMessageDiv").toggle('fast');
	});

});

function isDefined(variable){
    return (!(!( variable||false )))
}


// Show advanced search and tasting notes balloons
function showOptionsInfo() {
	var searchOptionsPos = $("a.greybox").position();
	
	var ratingHeaderPos = $(".gridHeader div.rating").position();
	/*sometimes this script is called where there is no .gridHeader
	 * so check to see if it is defined.
	 */
	if(! isDefined(ratingHeaderPos)){
		var ratingHeaderPos = 0;
	}
	
	
	jQuery.each(jQuery.browser, function(i, val) {
		if($.browser.safari) {
			setTimeout("setSafariPos();", 500);
		}
		else {
			$(".moreOptions").css({left:searchOptionsPos.left+155,top:searchOptionsPos.top-16});
			$(".tastings").css({left:ratingHeaderPos.left+78,top:ratingHeaderPos.top-24});
		}
	});
	$(".infoPopUp.moreOptions").show();
	$(".infoPopUp.tastings").show();
	$("#moreOptions .closeButton").click(function() {
		$("#moreOptions").hide();
	});
	$("#TastingExp .closeButton").click(function() {
		$("#TastingExp").hide();
	});
}

//Set Shipping Cost
function chooseShipping(shipCost) {
	$(".shippingCost").html("$" + shipCost);
}


// hide the address toggle
function hideAddressToggle(value) {
	if(value == "hide") {
		$("a.internationalAddress").hide();
	}
	else {
		$("a.internationalAddress").show();
	}
}

//toggle whether allowEdit
function doAllowEdit(value) {
	if(value == "true") {
		$("#allowEdit").val("true");
		resetShippingMethodToggle();
	}
	else {
		$("#allowEdit").val("false");
	}
	ColdFusion.Event.callBindHandlers('allowEdit',null,'change');
}

//toggle whether allowEdit
function userAuctionShippingDoAllowEdit(value) {
	if(value == "true") {
		$("#shippingAllowEdit").val("true");
	}
	else {
		$("#shippingAllowEdit").val("false");
	}
	ColdFusion.Event.callBindHandlers('shippingAllowEdit',null,'change');
}

//reset shippingMethodToggle
function resetShippingMethodToggle() {
	$("#shippingMethodToggle").val("");
	ColdFusion.Event.callBindHandlers('shippingMethodToggle',null,'change');
}

//hide the choose shipping toggle
function hideChooseShippingToggle(value) {
	if(value == "hide") {
		$(".chooseShipping").hide();
		$(".shippingMethod").attr('checked', false);
	}
	else {
		$(".chooseShipping").show();
	}
	ColdFusion.Event.callBindHandlers('shippingMethod',null,'change');
}


function toggleBillingAddress(value) {
	if(value == "sameShipping" || value == "useDefault") {
		$(".domesticAddressForm").hide();
		$("a.internationalAddress").hide();
	}
	else {
		$(".domesticAddressForm").show();
		$("a.internationalAddress").show();
	}
}


//alter position of infopopups when window is resized
function getIconLoc() {
	$(".infoPopUp").each(function () {
		if ($(this).css("display") == "block") {
			var popUpId = this.id;
			$("a").each(function() {
				if($(this).hasClass(popUpId) && !($(this).hasClass("rateNum")) && !($(this).hasClass("greybox"))) {
					var iconPosition = $(this).position();
					if($(this).hasClass('weatherIcon')) {
						$("#" + popUpId).css({left:iconPosition.left+35,top:iconPosition.top-17});
					}
					else {
						$("#" + popUpId).css({left:iconPosition.left+20,top:iconPosition.top-17});
					}
				}
				else if($(this).hasClass(popUpId) && $(this).hasClass("rateNum")) {
					var ratingPosition = $(this).position();
					$("#" + popUpId).css({left:ratingPosition.left-205,top:ratingPosition.top-53});					
				}
				else if($(this).hasClass("greybox")) {
					var searchOptionsPos = $("a.greybox").position();
					$(".moreOptions").css({left:searchOptionsPos.left+155,top:searchOptionsPos.top-16});
				}
			});
			if(this.id == "TastingExp") {
				var ratingHeaderPos = $("div.rating").position();
				$(".tastings").css({left:ratingHeaderPos.left+78,top:ratingHeaderPos.top-24});
			}
		}
	});

}

function setSafariPos() {
	var searchOptionsPos = $("a.greybox").position();
	var ratingHeaderPos = $("div.rating").position();
	$(".moreOptions").css({left:searchOptionsPos.left+155,top:searchOptionsPos.top-16});
	$(".tastings").css({left:ratingHeaderPos.left+78,top:ratingHeaderPos.top-24});
}

function checksearch() {
	var searchText = document.searchForm.keyword.value;
	lowerSearchText = searchText.toLowerCase();
	if(lowerSearchText == "search") {
		alert("Please enter a valid search term");
	}
	else {
		document.searchForm.submit();
	}
}

// Equal columns
	
function equalColumns() {
	if($(".productRight").length != "0" || $(".contentRight").length != "0") {
		if($(".productRight").length != "0") {
			leftColHeight = $(".productLeft").height();
			rightColHeight = $(".productRight").height();
			if(leftColHeight > rightColHeight) {
				$(".productRight").height(leftColHeight);
			}
			else {
				$(".productLeft").height(rightColHeight);
			}
		}
		if($(".contentRight").length != "0") {
			leftColHeight = $(".contentLeft").height();
			rightColHeight = $(".contentRight").height();
			if(leftColHeight > rightColHeight) {
				$(".contentRight").height(leftColHeight);
			}
			else {
				$(".contentLeft").height(rightColHeight);
			}
		}
	}
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/,"");
}



function vintageSearchFieldClean(string,formname){
	var myString = new String(string);
	//myString.split(' ').join('');
	
	//find any keywords entered into the vintage field
	keyword = myString.replace(/[^A-Za-z\ ]/g,"")
	
	keyword = trim(keyword);	
	
	//if there are any, create the keyword field
	if(keyword.length > 0){
		try{
		var input = document.createElement("input");
		input.setAttribute("type", "hidden");
		input.setAttribute("name", "keyword");
		
		input.setAttribute("value", keyword);
		
		document.getElementById(formname).appendChild(input);
		}catch(e){
			//alert(e.toString());
		}		
		//alert(keywords + " set for form " + formname);
	}	
	vintage = myString.replace(/[^0-9\-,]/g,"");
	return vintage;
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', "resizable=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=yes,width="+width+",height="+height+",left="+left+", top="+top+",screenX=3, screenY=4");
}

function showMoreShipDates() {
	$(".moreShipDates").toggle('fast');
	if($("a.showMoreShipDates").css('display') == "block") {
		$("a.showMoreShipDates").css({'display': 'none'});
		$("a.showMoreShipDates.less").css({'display': 'block'});
	}
	else {
		$("a.showMoreShipDates").css({'display': 'block'});
		$("a.showMoreShipDates.less").css({'display': 'none'});
	}
}

function showPayByCheck() {
	if(document.billingInfo.payByCheck.checked) {
		$(".payByCheck").show();
	}
}

function showGiftMessage() {
	if(document.shoppingCartForm.isGift.checked) {
		$("#giftMessageDiv").show();
	}
}

function hideCloseButton() {
	$("#closeLinkBotSS").hide();
}

function showChart(clicked) {
 	$(".gridRow").each(function () {
       	$(this).css({'z-index': 1});
    });
	currentLink = clicked;
	var popUpId = $(currentLink).attr('className').split(' ').pop();
	var parentDivs = $("#" + popUpId).parents();
	$(parentDivs).each(function () {
		if($(this).hasClass('gridRow')) {
			$(this).css({'z-index':75});
		}
    });
	var linkPosition = $(currentLink).position();
    $("#" + popUpId).css({left:linkPosition.left-305,top:linkPosition.top-53});        
	if($("#" + popUpId).css('display') == "none") {
		$("#" + popUpId).css({'display': 'block'});
	}
	else {
		$("#" + popUpId).css({'display': 'none'});
	}
	$(".closeButton").click(function() {
		$("#" + popUpId).hide();
	});
	$(".infoPopUp").each(function () {
		if(this.id != popUpId) {
			$(this).hide();
		}
	});
}

function showHelpBalloon(icon) {
	var currentIcon = icon;
	var popUpId = $(icon).attr('className').split(' ').pop();
	$(icon).toggleClass('active');
	var iconPosition = $(icon).position();
	if($(icon).hasClass('.weatherIcon')) {
		$("#" + popUpId).css({left:iconPosition.left+35,top:iconPosition.top-17});
	}
	else {
		$("#" + popUpId).css({left:iconPosition.left+20,top:iconPosition.top-17,'z-index':100});
		if(!($(currentIcon).hasClass('.help'))) {
			$(".gridRow").each(function () {
				$(this).css({'z-index': 1});
			});
	        getSimplePopup(popUpId);
		}
	}
	$("#" + popUpId).toggle();
	$(".closeButton").click(function() {
		$("#" + popUpId).hide();
	});
	$(".infoPopUp").each(function () {
		if(this.id != popUpId) {
			$(this).hide();
		}
	});
	$(".icon, .weatherIcon").each(function () {
		if(this != currentIcon && $(this).hasClass("active")) {
			$(this).removeClass("active")
		}
	});
}

