var enableCache = false;
var jsCache = new Array();
var AjaxObjects = new Array();
var lastUrlArg = '';

function LoadProdPage(arg)
{
	lastUrlArg = arg;
    var tbox = document.getElementById('thickbox');
    if (tbox)
    {
		var myWidth = 620, myHeight = 600;
		try
		{
			if( typeof( window.innerWidth ) == 'number' ) {
			  //Non-IE
			  myWidth = window.innerWidth;
			  myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  //IE 6+ in 'standards compliant mode'
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			  //IE 4 compatible
			  myWidth = document.body.clientWidth;
			  myHeight = document.body.clientHeight;
			}
		} catch (e1) {
		}

		tbox.href = '/prodpage2_ajax.asp?' + arg + '&height=' + (myHeight-70) + '&width=620';
		FireEvent(tbox,'click');
	}
}
function AddToWishList(frmname,cartid,imgid,itemindex)
{
	var frm = document.forms[frmname];
	if (frm)
	{
		document.getElementById(imgid).src = '/images/loadinganimation.GIF';

		var tt;
		tt = "addtocart.asp?ck91=11" + "&ItemCode=" + frm.StyleCode[itemindex].value;

		var ajaxIndex = AjaxObjects.length;
		AjaxObjects[ajaxIndex] = new sack();
		AjaxObjects[ajaxIndex].requestFile = tt;
		AjaxObjects[ajaxIndex].onCompletion = function(){ AddedToWishList(ajaxIndex,frm,cartid,imgid,itemindex); };
		AjaxObjects[ajaxIndex].runAJAX();
	}
}
function AddedToWishList(ajaxIndex,frm,cartid,imgid,itemindex)
{
	if (AjaxObjects[ajaxIndex].response.substring(0,4) == "err1")
	{
		AjaxObjects[ajaxIndex] = false;
		window.location = 'https://www.bluebellwholesale.com/login.asp';
	}
	else if (AjaxObjects[ajaxIndex].response.substring(0,4) == "err2")
	{
		AjaxObjects[ajaxIndex] = false;
	}
	else if (isnumeric(AjaxObjects[ajaxIndex].response))
	{
		var listfrm = document.forms['listfrm'];
		if (listfrm)
		{
			if (frm != listfrm)
			{
				var itemCode = frm.StyleCode[itemindex].value;
				if (itemCode != '')
				{
					for (var i=0; i<listfrm.ItemCode.length; i++)
					{
						if (listfrm.ItemCode[i])
						if (itemCode == listfrm.ItemCode[i].value)
						{
							if (document.getElementById('wimg'+i)) 
							{
								document.getElementById('wimg'+i).src = '/images/b_s_towish_added.gif';
								document.getElementById('wimg'+i).style.cursor = 'normal';
							}
							if (document.getElementById('wish'+i)) document.getElementById('wish'+i).onclick = '';
							break;
						}
					}
				}
			}
		}
		if (document.getElementById(imgid))
		{
			document.getElementById(imgid).src = '/images/b_s_towish_added.gif';
			document.getElementById(imgid).style.cursor = 'normal';
		}
		if (document.getElementById(cartid)) document.getElementById(cartid).onclick = '';
		AjaxObjects[ajaxIndex] = false;
	}
	else
	{
		alert(AjaxObjects[ajaxIndex].response);
		AjaxObjects[ajaxIndex] = false;
		if (document.getElementById(imgid))
		{
			document.getElementById(imgid).src = '/images/b_s_towish.gif';
		}
	}
}
function AddToCart(frmname,cartid,imgid,qtynoteid,itemindex)
{
	var frm = document.forms[frmname];
	if (frm)
	{
		document.getElementById(imgid).src = '/images/loadinganimation.GIF';
	
		var tt,t1;
		tt = "addtocart.asp?ck91=12";
		tt += "&ItemID=" + frm.ItemID[itemindex].value;
		tt += "&ItemCode=" + frm.ItemCode[itemindex].value;
		tt += "&ItemColor=" + frm.ItemColor[itemindex].value;
		tt += "&ItemName=" + frm.ItemName[itemindex].value.replace('&','_');
		tt += "&ItemWeight=" + frm.ItemWeight[itemindex].value;
		tt += "&ItemImg=" + frm.ItemImg[itemindex].value;
		tt += "&Qtyt=" + (frm.Qtyt[itemindex].selectedIndex+1);
		tt += "&SellPrice=" + frm.SellPrice[itemindex].value;
		tt += "&StyleCode=" + frm.StyleCode[itemindex].value;
		tt += "&Instock=" + frm.Instock[itemindex].value;

		var ajaxIndex = AjaxObjects.length;
		AjaxObjects[ajaxIndex] = new sack();
		AjaxObjects[ajaxIndex].requestFile = tt;
		AjaxObjects[ajaxIndex].onCompletion = function(){ AddedToCart(ajaxIndex,frm,cartid,imgid,qtynoteid,itemindex); };
		AjaxObjects[ajaxIndex].runAJAX();
	}
}
function AddedToCart(ajaxIndex,frm,cartid,imgid,qtynoteid,itemindex)
{
	if (AjaxObjects[ajaxIndex].response.substring(0,4) == "err1")
	{
		AjaxObjects[ajaxIndex] = false;
		window.location = 'https://www.bluebellwholesale.com/login.asp';
	}
	else if (AjaxObjects[ajaxIndex].response.substring(0,4) == "err2")
	{
		AjaxObjects[ajaxIndex] = false;
	}
	else if (isnumeric(AjaxObjects[ajaxIndex].response.replace(":","")))
	{
		var listfrm = document.forms['listfrm'];
		if (listfrm)
		{
			if (frm != listfrm)
			{
				var itemCode = frm.StyleCode[itemindex].value;
				if (itemCode != '')
				{
					for (var i=0; i<listfrm.ItemCode.length; i++)
					{
						if (listfrm.ItemCode[i])
						if (itemCode == listfrm.ItemCode[i].value)
						{
							if (document.getElementById('cimg'+i))
							{
								document.getElementById('cimg'+i).src = '/images/b_s_tocart_added.gif';
								document.getElementById('cimg'+i).style.cursor = 'normal';
							}
							if (document.getElementById('caddedqty'+i)) document.getElementById('caddedqty'+i).innerHTML = '&nbsp;(' + AjaxObjects[ajaxIndex].response.split(":")[0] + ' Unit)';
							if (document.getElementById('cart'+i))
							{
								document.getElementById('cart'+i).onclick = '';
								if (listfrm.Qtyt[i]) listfrm.Qtyt[i].style.display = 'none';
							}
							break;
						}
					}
				}
			}
		}
		if (document.getElementById(imgid))
		{
			document.getElementById(imgid).src = '/images/b_s_tocart_added.gif';
			document.getElementById(imgid).style.cursor = 'normal';
		}
		if (document.getElementById(qtynoteid)) document.getElementById(qtynoteid).innerHTML = '&nbsp;(' + AjaxObjects[ajaxIndex].response.split(":")[0] + ' Unit)';
		if (document.getElementById('QtyInCart')) document.getElementById('QtyInCart').innerHTML = AjaxObjects[ajaxIndex].response.split(":")[1];
		if (document.getElementById(cartid))
		{
			document.getElementById(cartid).onclick = '';
			if (frm.Qtyt[itemindex]) frm.Qtyt[itemindex].style.display = 'none';
		}
	}
	else
	{
		alert(AjaxObjects[ajaxIndex].response);
		AjaxObjects[ajaxIndex] = false;
		if (document.getElementById(imgid))
		{
			document.getElementById(imgid).src = '/images/b_s_tocart.gif';
		}
	}
}
function SubmitReview(frmname)
{
	var frm = document.forms[frmname];
	if (frm)
	{
		if (document.getElementById('sendingReview'))
		{
			document.getElementById('sendingReview').style.display = 'block';
			document.getElementById('sendingReview').src = '/images/movewait.gif';
		}
		var ajaxIndex = AjaxObjects.length;
		AjaxObjects[ajaxIndex] = new sack();
		AjaxObjects[ajaxIndex].requestFile = "InsertReview.asp";
		AjaxObjects[ajaxIndex].encVar("StyleCode", frm.StyleCode.value);
		for (var i=0; i<frm.Rating.length; i++)
		{
			if (frm.Rating[i].checked)
			{
				AjaxObjects[ajaxIndex].encVar("Rating", frm.Rating[i].value);
				break;
			}
		}
		AjaxObjects[ajaxIndex].encVar("Review", frm.Review.value);
		AjaxObjects[ajaxIndex].onCompletion = function(){ SubmitedReview(ajaxIndex,frm); };
		AjaxObjects[ajaxIndex].runAJAX();
	}
}
function SubmitedReview(ajaxIndex,frm)
{
	if (document.getElementById('sendingReview'))
	{
		document.getElementById('sendingReview').style.display = 'none';
	}
	if (AjaxObjects[ajaxIndex].response != '') alert(AjaxObjects[ajaxIndex].response);
	if (lastUrlArg != '') LoadProdPage(lastUrlArg);
}
function EmailFriend(frmname)
{
	var frm = document.forms[frmname];
	if (frm)
	{
		if (document.getElementById('sendingEmail'))
		{
			document.getElementById('sendingEmail').style.display = 'block';
			document.getElementById('sendingEmail').src = '/images/movewait.gif';
		}
		var ajaxIndex = AjaxObjects.length;
		AjaxObjects[ajaxIndex] = new sack();
		AjaxObjects[ajaxIndex].requestFile = "EmailFriend.asp";
		AjaxObjects[ajaxIndex].encVar("StyleCode", frm.StyleCode.value);
		AjaxObjects[ajaxIndex].encVar("StyleID", frm.StyleID.value);
		AjaxObjects[ajaxIndex].encVar("YourName", frm.YourName.value);
		AjaxObjects[ajaxIndex].encVar("YourEmail", frm.YourEmail.value);
		AjaxObjects[ajaxIndex].encVar("FriendName", frm.FriendName.value);
		AjaxObjects[ajaxIndex].encVar("FriendEmail", frm.FriendEmail.value);
		AjaxObjects[ajaxIndex].encVar("Comment", frm.Comment.value);
		AjaxObjects[ajaxIndex].onCompletion = function(){ EmailFriendSent(ajaxIndex,frm); };
		AjaxObjects[ajaxIndex].runAJAX();
	}
}
function EmailFriendSent(ajaxIndex,frm)
{
	if (document.getElementById('sendingEmail'))
	{
		document.getElementById('sendingEmail').style.display = 'none';
	}
	if (AjaxObjects[ajaxIndex].response != '') alert(AjaxObjects[ajaxIndex].response);
	try {
		DisplayEmail('none');
	} catch (e1) {
	}
}
function ShowRelatedItems(idx) {
	var tab;
	tab = document.getElementById('ColorWay');
	if (tab) tab.style.display = 'none';
	tab = document.getElementById('MatchSet');
	if (tab) tab.style.display = 'none';
	tab = document.getElementById('ConceptSet');
	if (tab) tab.style.display = 'none';
	var bgcolor = '';
	var display = 'inline-block';
	if (jQuery.browser.msie && jQuery.browser.version == 7)
		display = 'inline-block';
	else
		display = 'block';
	if (idx==1) {
		bgcolor = '/images/menu_colorway_bg.jpg';
		document.getElementById('ColorWay').style.display = display;
	} else if (idx==2) {
		bgcolor = '/images/menu_matchingset_bg.jpg';
		document.getElementById('MatchSet').style.display = display;
	} else if (idx=3) {
		bgcolor = '/images/menu_sameconcept_bg.jpg';
		document.getElementById('ConceptSet').style.display = display;
	}
	if (document.getElementById('TabBar'))
		document.getElementById('TabBar').src = bgcolor;
}
