var showRadio = false;
var addEnabled = true;

function openBrWindow(url, winName, features) {
	if(typeof(jsession) == 'undefined') {
		jsession = null;
	}
	if(jsession && url.indexOf(";jsessionid=")<0) {
		if(url.indexOf("?")>0) {
			url = url.replace("?", ';jsessionid='+jsession+"?");
		} else {
			url += ';jsessionid='+jsession; 
		}
	}
	//alert(url);
	pop = window.open(url, winName, features);
	pop.focus();
}

function setPriceTest(testGroup) {
	if (getCookie('psplid') != 'ntg') {
		var expires = new Date();
		expires.setTime(expires.getTime() + 61536000000);
		setCookie('psplid', testGroup, expires, '/', false, false);
	}
}

function addItem(formName) {
	if (addEnabled) {
		document[formName].submit();
		addEnabled = false;
	}
}

textCounter = function(field, countfield, maxlimit) {
	if 
		(field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit);
	else
		countfield.value = maxlimit - field.value.length;
}

$(document).ready(function() {

	//Set the title for the breadcrumb links
	$('.breadcrumbLink').each(function() {
		$(this).attr('title', 'Choose this to return to ' + $(this).attr('title'));
	});

	//Set the title for the cross sell breadcrumb links
	$('.crossSellBreadcrumbs').each(function() {
		var crossSellDisplayName = $.trim($(this).html());
		$(this).attr('title', 'Choose this to return to ' + crossSellDisplayName);
	});
	
	// Fancybox link
	$("a.popupBasic").fancybox({
			'hideOnContentClick': false,
			'titleShow': false,
			'overlayColor': '#000000'
	});	
	
	$('#emptyCartPopupCover, .truckicon, a.freeShippingPolicyCartPopUp').hover(function() {
		$('a.freeShippingPolicyCartPopUp').css('text-decoration','underline');
	},
		function() {
		$('a.freeShippingPolicyCartPopUp').css('text-decoration','none');
	});
	
	var funcFreeShippingPolicy = function(){
		View.createWindow({
			title: "Free Basic Shipping Offer",
			id: "freeBasicShip",
			width: 475,
			height: 525,
			url: '/Store/support/faq/shipping/popup.jsp'
		});
			//alert($.browser.version);
	}
	// set Free Shipping Policy popup in the cart
	$(".freeShippingPolicyCartPopUp").click(function(){
		funcFreeShippingPolicy();
		var thewindowheight = $(document).height();
		$("div.dhx_modal_cover_dv").css("height",thewindowheight + "px");	
		//$("div.dhx_modal_cover_dv").css("width","130%");								 
	});
	// set Free Shipping Policy popup in the footer
	$("#freeShippingPolicyFooterPopUp").click(function(){
		funcFreeShippingPolicy();   
		var thewindowheight = $(document).height();
		$("div.dhx_modal_cover_dv").css("height",thewindowheight + "px");
		//$("div.dhx_modal_cover_dv").css("width","130%");
	});
	// set Free Shipping Policy popup on the product page
	$(".freeShippingPolicyProductPopUp").click(function(){
		funcFreeShippingPolicy();
		var thewindowheight = $(document).height();
		$("div.dhx_modal_cover_dv").css("height",thewindowheight + "px");			 
	});
	
	var funcLowPriceGuarantee = function(){
		View.createWindow({
			title: "Low Price Guarantee",
			id: "lowPriceGuarantee",
			width: 475,
			height: 525,
			url: '/Store/support/faq/lpg/popup.jsp'
		});
		var thewindowheight = $(document).height();
		$("div.dhx_modal_cover_dv").css("height",thewindowheight + "px");
		//$("div.dhx_modal_cover_dv").css("width","130%");
	}
	
	$("#lowPriceGuaranteeFooterPopUp").click(funcLowPriceGuarantee);
});
