function wishlstEmailShow() {
	// document.getElementById('list_invXfer').style.display = 'inline';
	$('#dialog').dialog('open');
}
function addWishlstShow(rugIdent,rugImg,rugImg2,modalWinObj) {
	// alert("message: JavaScript code successfully initialized");
	var theImgPath1 = "http://intranet.mattcamron.com/images/invthumb/"+rugImg;
	var theImgPath2 = "http://intranet.mattcamron.com/images/invthumb/"+rugImg2;
	document.editForm.RugId.value = rugIdent;
	document.editForm.RugImgSrc.value = rugImg;
	document.editForm.RugImgSrc2.value = rugImg2;
	document.getElementById('wishlstImg').src = theImgPath1;
	document.getElementById('wishlstImg2').src = theImgPath2;
	// alert("showme: "+theImgPath);
	if (!modalWinObj || modalWinObj == "") {
		$('#dialog').dialog('open');
	} else if (modalWinObj == 2) {
		$('#dialog2').dialog('open');
	}
}
function listNewSave(invObjId,invObjImg,invObjImg2,formObj,lev1id) {
	var lev1id = 2714;
	var theNewName = formObj.value; theNewName = escape(theNewName); theNewName = encodeURI(theNewName);
	var theUrl = "/index.cfm/lev1/"+lev1id+"/Wishlist?act=wishlst.listAddNew&name="+theNewName+"&rugid="+invObjId.value+"&rugimgsrc="+invObjImg.value+"&rugimgsrc2="+invObjImg2.value;
	/* var theUrl = "/index.cfm?act=wishlst.listAddNew&name="+theNewName+"&rugid="+invObjId.value+"&rugimgsrc="+invObjImg.value+"&rugimgsrc2="+invObjImg2.value; */
	document.location.href = theUrl; // +"&redir="+redirInfo;
}

/* Wishlist cookie script */

function wishlistOptReveal(formObj,targetFormObjId) {
	// alert ("showme: " + formObj.options[formObj.selectedIndex].value);
	if (formObj.options[formObj.selectedIndex].value.length > 0 && formObj.options[formObj.selectedIndex].value == 1) {
		document.getElementById('lbllistNewName').style.display = "inline";
		document.getElementById('listNewName').style.display = "inline";
		document.getElementById('listNewBtnSave').style.display = "inline";
		document.getElementById("btnSave").disabled = true;
		document.getElementById("btnSave").style.color = "909090";
		document.getElementById("btnSave").style.fontWeight = "normal";
		document.getElementById("btnSave").value = "(Must click SAVE above before you can add to list)";
	} else {
		document.getElementById('lbllistNewName').style.display = "none";
		document.getElementById('listNewName').style.display = "none";
		document.getElementById('listNewBtnSave').style.display = "none";
		document.getElementById("btnSave").disabled = false;
		document.getElementById("btnSave").style.color = "";
		document.getElementById("btnSave").style.fontWeight = "bold";
		document.getElementById("btnSave").value = "ADD";
	}
}

function getWishlist() {
	var i,name,value,elements=document.cookie.split(";");
	for (i=0;i<elements.length;i++) {
		name  = elements[i].substr(0,elements[i].indexOf("="));
		value = elements[i].substr(elements[i].indexOf("=")+1);
		name  = name.replace(/^\s+|\s+$/g,"");
		if (name == "WISHLIST") {
			return unescape(value);
		}
	}
	return "";
}

function addToWishlist(cust,value,listnm,doAlert) {
	// if (!doAlert) doAlert = true;
	var existingWishlist = getWishlist();
	var newvalue = cust+"^"+listnm+"^"+value;
	if (existingWishlist != "") existingWishlist = existingWishlist + "|";
	constructCookie(existingWishlist + escape(newvalue));
	// TODO: Replace this with a jQuery dialog
	/* var $wishlist = $('<div></div>')
		.html('The rug was added to your wishlist.')
		.dialog({
			autoOpen: false
		});
	$('#opener').click(function() {
	$wishlist.dialog('open');
	});
	}); */
	$('#dialog').dialog('close');
	if (doAlert) { alert("The item was added to your wishlist!"); }
}
function removeFromWishlist(value,redirUrl,delim) {
	var existingWishlist = getWishlist();
	if (existingWishlist != "") {
		var values = existingWishlist.split("|");
		var index  = values.indexOf(value);
		if (index >= 0) { /* alert("show: "+value+" = "+values+" = "+index); */ values.splice(index, 1); }
		constructCookie(values.join("|"));
		var validRedirUrl = redirUrl + delim + "rwl=1&inv=" + value; // using var 'rwl' to mean 'remove [from] wish list'
		document.location.href = validRedirUrl;
	}
}
function constructCookie(value) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + 365); // Wishlist is good for 1 year
	cookieData = "WISHLIST=" + value + "; expires=" + exdate.toUTCString() + "; path=/";
	document.cookie = cookieData;
}
function clearWishlist(redirUrl,delim) {
	document.cookie = "WISHLIST=; path=/";
	var validRedirUrl = redirUrl + delim + "cwl=1"; // using var 'cwl' to mean 'clear wish list'
	document.location.href = validRedirUrl;
}
