var enableCache = false;
var jsCache = new Array();
var AjaxObjects = new Array();
var lastUrlArg = '';
var lastProdpage2StyleCode = '';

function LoadProdPage(arg)
{
	lastUrlArg = arg;
	var myHeight = $(window).height();
	if(deviceName == 'ipad' || deviceName == 'ipod' || deviceName == 'iphone' || deviceName == 'android1' || deviceName == 'android2') myHeight = 0;
	tb_show('Click outside to close','/prodpage2_ajax.asp?' + arg + '&height=' + myHeight + '&width=650',false);
}
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 = 'default';
							}
							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 = 'default';
		}
		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 = 'default';
							}
							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 = 'default';
		}
		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);
	else if (lastProdpage2StyleCode != '')
		window.location = '/prodpage2.asp?StyleCode=' + lastProdpage2StyleCode;
}
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;
}
function DisplayReview(val) {
	if (document.getElementById){
		document.getElementById('reviewform').style.display = val;
	}
	else
		return true;
}
function ValReview(frm) {
	if (frm.Review.value == '') {
		alert ("The review field is blank, please enter your review.")
		frm.Review.focus();
		return false;
	}
	if (frm.Review.length > 1000) {
		alert ("Your review is more than 1000 characters long, please shorten your review.")
		frm.Review.focus();
		return false;
	}
	return true;
}
function DisplayEmail(val) {
	if (document.getElementById){
		document.getElementById('emailform').style.display = val;
	}
	else
		return true;
}
function ValEmail(frm) {
	if (frm.YourName.value == "") {
		alert("Please enter your name.");
		frm.YourName.focus();
		return false;
	}
	if (frm.YourEmail.value == "") {
		alert("Please enter your e-mail address.");
		frm.YourEmail.focus();
		return false;
	}
	if (!emailCheck(frm.YourEmail.value))  {
		alert("You entered wrong e-mail format. Please enter correct e-mail address.");
		frm.YourEmail.select();
		frm.YourEmail.focus();
		return false;
	}
	if (frm.FriendName.value == "") {
		alert("Please enter friend's name.");
		frm.FriendName.focus();
		return false;
	}
	if (frm.FriendEmail.value == "") {
		alert("Please enter friend's e-mail address.");
		frm.FriendEmail.focus();
		return false;
	}
	if (!emailCheck(frm.FriendEmail.value))  {
		alert("You entered wrong e-mail format. Please enter correct e-mail address.");
		frm.FriendEmail.select();
		frm.FriendEmail.focus();
		return false;
	}
	return true;
}

var detailimg_x=200;
var detailimg_y=250;
var detailimg_id = '';
function ExpandDetailImg()
{
	if(detailimg_x > 450) { 
		clearTimeout(t);
		return;
	}
	var dimg = document.getElementById(detailimg_id);
	if (dimg){
		var dimgwin = document.getElementById('dimagewindow');
		dimgwin.style.marginLeft = '-' + (detailimg_x/2) + 'px';
		dimgwin.style.marginTop = '-' + (detailimg_y/2) + 'px';
		dimg.style.width=detailimg_x+'px';
		dimg.style.height=detailimg_y+'px';
	}
	detailimg_x+=24;
	detailimg_y+=30;
	t=setTimeout('ExpandDetailImg()',0.1); 
}
function LoadDetailImg (which, dir) {
	if (document.getElementById('dimagewindow')) document.body.removeChild(document.getElementById('dimagewindow'));
	var dimgwin = document.createElement('div');
	dimgwin.setAttribute('id', 'dimagewindow');
	if(deviceName == 'ipad' || deviceName == 'ipod' || deviceName == 'iphone' || deviceName == 'android1' || deviceName == 'android2'){
		dimgwin.setAttribute('style', 'Z-INDEX: 200; POSITION: fixed; TOP: ' + ($(window).scrollTop()+(($(window).height() / 2)-275)) + 'px; LEFT: 50%; CURSOR: pointer; MARGIN-LEFT:-221px; BACKGROUND: white; BORDER: 1px solid black');
	}else{
		dimgwin.setAttribute('style', 'Z-INDEX: 200; POSITION: fixed; TOP: 50%; LEFT: 50%; CURSOR: pointer; MARGIN-LEFT:-221px; MARGIN-TOP:-275px; BACKGROUND: white; BORDER: 1px solid black');
	}
	dimgwin.setAttribute('onclick', 'javascript:HideDetailImg(\'detailimg\');');
	var dimgcon = document.createElement('div');
	dimgcon.setAttribute('id', 'dimagecontainer');
	dimgcon.setAttribute('style', 'BORDER-LEFT: 2px solid white; BORDER-TOP: 2px solid white; BORDER-RIGHT: 1px solid grey; BORDER-BOTTOM: 1px solid grey;');
	dimgwin.appendChild(dimgcon);
	var dimg = document.createElement('img');
	dimg.setAttribute('id', 'dimage');
	dimg.setAttribute('style', 'DISPLAY: none;');
	dimg.setAttribute('title', 'click to return');
	dimgcon.appendChild(dimg);
	if (dimg){
		if (deviceName == 'ipad' || deviceName == 'ipod' || deviceName == 'iphone' || deviceName == 'android1' || deviceName == 'android2'){
			dimg.src = 'http://www.bluebellwholesale.com/products/de/' + which + '.jpg';
			dimg.style.width = '440px';
			dimg.style.height = '550px';
			dimg.style.display = 'block';

			var ldiv = document.createElement('div');
			ldiv.setAttribute('style', 'Z-INDEX:201; POSITION: fixed; TOP:' + ($(window).scrollTop() + ($(window).height() / 2)) + 'px; LEFT:50%; MARGIN-LEFT:-104px;');
			var limg = document.createElement('img');
			limg.src = '/includes/thickbox/loadingAnimation.gif';
			limg.style.display = 'block';
			ldiv.appendChild(limg);
			document.body.appendChild(ldiv);

			setTimeout(function(){document.body.removeChild(ldiv);document.body.appendChild(dimgwin);}, 300);
			dimg.style.display = 'block';
		}else{
			dimg.src = 'http://www.bluebellwholesale.com/products/' + dir + '/' + which + '.jpg';
			dimg.style.width='200px';
			dimg.style.height='250px';
			dimg.style.display = 'block';
			document.body.appendChild(dimgwin);
			if (browserName.indexOf("msie") !== -1){
				dimgwin.style.marginLeft = '-221px';
				dimgwin.style.marginTop = '-275px';
				dimg.style.width = '440px';
				dimg.style.height = '550px';
			}else{
				dimgwin.style.marginLeft = '-100px';
				dimgwin.style.marginTop = '-125px';
				detailimg_x=200;
				detailimg_y=250;
				detailimg_id = dimg.id;
				setTimeout('ExpandDetailImg()',0.1); 
			}
			dimg.src = 'http://www.bluebellwholesale.com/products/de/' + which + '.jpg';
		}
	}
}
function HideDetailImg (){
	document.body.removeChild(document.getElementById('dimagewindow'));
}
function PreloadDetailImg (which) {
	if(!(deviceName == 'ipad' || deviceName == 'ipod' || deviceName == 'iphone' || deviceName == 'android1' || deviceName == 'android2')) {
		var tmpdimg = document.getElementById('tmpdetailimage');
		if (tmpdimg) tmpdimg.src = 'http://www.bluebellwholesale.com/products/de/' + which + '.jpg';
	}
}
function LargeImg (StyleCode, Pic, MultiPic, dir) {
	if (browserName == 'msie5' || browserName == 'msie6' || browserName == 'msie7' || (window.location.href.indexOf("prodpage2.asp") !== -1 && browserName.indexOf("msie") !== -1)){
		var url = '/ViewImg2.asp?StyleCode=' + StyleCode + '&moreview=' + MultiPic + '&pic=' + Pic;
		showPopup (url, 'ViewPhoto', 550, 520);
	}else{
		if (Pic==0) {
			LoadDetailImg(StyleCode,dir);
		}else{
			LoadDetailImg(StyleCode+'-'+Pic,dir);
		}
	}
}
function GetRecommendedItem(StyleCode, StyleID, VendorID, ItemDesigns, ItemCollects, ItemBasColors, ItemPointColors) {
	if (document.getElementById('prodpage2_recommendeditem')) {
		var ajaxIndex = AjaxObjects.length;
		AjaxObjects[ajaxIndex] = new sack();
		AjaxObjects[ajaxIndex].requestFile = '/includes/prodpage2_common_recommended.asp?StyleCode=' + StyleCode + '&StyleID=' + StyleID + '&VendorID=' + VendorID + '&ItemDesigns=' + ItemDesigns + '&ItemCollects=' + ItemCollects + '&ItemBasColors=' + ItemBasColors + '&ItemPointColors=' + ItemPointColors;
		AjaxObjects[ajaxIndex].onCompletion = function(){ ShowRecommendedItem(ajaxIndex); };
		AjaxObjects[ajaxIndex].runAJAX();
	}
}
function ShowRecommendedItem(ajaxIndex) {
	var recmnd = document.getElementById('prodpage2_recommendeditem')
	if (AjaxObjects[ajaxIndex].response != '' && recmnd) {
		recmnd.innerHTML = AjaxObjects[ajaxIndex].response;
		recmnd.style.display = 'block';
	}
	AjaxObjects[ajaxIndex] = false;
}

