function listMightyRecord(id, name, type) {
	this.id = id;
	this.name = name;
	this.type = type;
}

function addlistmightylist() {
	closeAllDialogs();
	var name = getElement("listname");
	var type = getElement("listtype1");
	var password = getElement("listpassword");
	var error = getElement("listmightyerror");
	var message = getElement("listmessage");
	var mode = getElement("newlistmode");
	mode.value = 1;
	name.value = "";
	error.innerHTML = "&nbsp;";
	type.checked = true;
	password.value = "";
	password.className = "inputdisabled";
	password.disabled = true;
	message.value = "";
	message.className = "inputdisabled";
	message.disabled = true;
	var bodyheight = 280;
	if (!is_ie) {
		bodyheight = 257;
	} 
	if (is_firefox) {
		openDialog("listmightylistwindow", 277, 400);
	} else if (is_nav) {
		openDialog("listmightylistwindow", 283, 400);
	} else if (is_ie) {
		openDialog("listmightylistwindow", 275, 400);	
	} else {
		openDialog("listmightylistwindow", 275, 400);		
	}
	name.focus();
}

function updatelistmightylist(listId) {
	var url = "web_mitrya/listmightysubmit.jsp?mode=6&listid="+listId;
	emailsubmitcontainer.innerHTML = "<iframe src='" + url + "'></iframe>";	
}

function showupdatelistmightylist(oldname, oldtype, oldpassword, oldmessage, id) {
	closeAllDialogs();
	
	var name = getElement("listname");
	var typePrivate = getElement("listtype1");
	var typePublic = getElement("listtype2");
	var password = getElement("listpassword");
	var error = getElement("listmightyerror");
	var message = getElement("listmessage");
	var mode = getElement("newlistmode");
	var listid = getElement("newlistid");
	var title = getElement("newlisttitle");
	var note = getElement("newlistnote");
	if (oldpassword == "null") oldpassword = "";
	if (oldmessage == "null") oldmessage = "";
	listid.value = id;
	mode.value = 2;
	name.value = oldname;
	if (oldtype == "1") {
		typePrivate.checked = true;
		password.className = "inputdisabled";
		password.disabled = true;
		message.className = "inputdisabled";
		message.disabled = true;
	} else {
		typePublic.checked = true;
		password.className = "";
		password.disabled = false;
		message.className = "";
		message.disabled = false;
	}
	error.innerHTML = "&nbsp;";
	password.value = oldpassword;
	message.value = oldmessage;
	title.innerHTML = "Modify List Settings";
	note.innerHTML = "To <b>Modify this List</b>, please update the fields below:";

	if (is_firefox) {
		openDialog("listmightylistwindow", 277, 400);
	} else if (is_nav) {
		openDialog("listmightylistwindow", 283, 400);
	} else if (is_ie) {
		openDialog("listmightylistwindow", 275, 400);	
	} else {
		openDialog("listmightylistwindow", 275, 400);		
	}

	name.focus();
	
}

function closeAddListMightyList() {
	var objNewAccount = getElement("listmightylistwindow");
	closeDialog(objNewAccount);
}

function addlistmightylisttype(typevalue) {
	var password = getElement("listpassword");
	var message = getElement("listmessage");
	if (typevalue == 2) {
		password.className = "";
		password.disabled = false;
		message.className = "";
		message.disabled = false;		
	} else {
		password.className = "inputdisabled";
		password.disabled = true;
		message.className = "inputdisabled";
		message.disabled = true;
	}
}

function validatelistItem(sessionid) {
	var name = getElement("listname");
	var error = getElement("listmightyerror");
	var publicitem = getElement("listtype2");
	var password = getElement("listpassword");
	var message = getElement("listmessage");
	var mode = getElement("newlistmode");
	var fail = 0;
	var type = 1;
	
	if (name.value.length == 0) {
		error.innerHTML = "Please enter a Name for this List";
		fail = 1;
		name.className = "inputerror";
		name.focus();
	} else {
		error.innerHTML = "&nbsp;"
		name.className = "";
	}
	if (publicitem.checked) {
		if (fail == 0) {
			if (password.value.length == 0) {
				error.innerHTML = "Please enter a Password for this List";
				fail = 1;
				password.className = "inputerror";
				password.focus();
			} else {
				type = 2;
				error.innerHTML = "&nbsp;";
				password.className = "";
			}
		}
	}
	if (fail == 0) {
		var url = "web_mitrya/listmightysubmit.jsp?sid="+sessionid;
		if (mode.value == 1) {
			url = url + "&mode=1";
		} else {
			var listid = getElement("newlistid");
			url = url + "&mode=7&listid="+listid.value;
		}
		url += "&name="+encodeURIComponent(name.value)+"&type="+type;
		if (type == 2) {
			url += "&password="+encodeURIComponent(password.value)+"&message="+encodeURIComponent(message.value);
		}
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
	}
}

function showPublicListPasswordError() {
	var error = getElement("listmightyerror");
	var password = getElement("listpassword");
	error.innerHTML = "Password already used. Please select another password";
	password.className = "inputerror";
	password.focus();
}

var currentlistdetails = "";
function closeListMightyDetails() {
	//if (currentlistdetails.length > 0) {
	//	var hideobj = getElement("lmsh"+currentlistdetails);
	//	hideobj.className = "listmightytabshowdetails";
	//	hideobj.innerHTML = "Show";
	//}
	currentlistdetails = "";
	
	var objNewAccount = getElement("listmightydetailwindow");
	var objContent = getElement("listmightydetailscontent");
	objContent.style.height = 1;
	closeDialog(objNewAccount);
}

function showListMightyMessage() {
	var prodcatid = arguments[0].substring(2, arguments[0].length);
	var stop = 0;
	if (currentlistdetails == prodcatid) stop = 1;
	if (currentlistdetails.length > 0) closeListMightyDetails();
	if (stop == 1) return;
	currentlistdetails = prodcatid;
	var parentObj = getElement(arguments[0]);
	var parentTop = getElementTopObj(parentObj);
	var parentLeft = getElementLeftObj(parentObj);
	var parentWidth = 145
	
	var elemTop = parentTop+23;
	var elemLeft = (parentLeft + (parentWidth / 2)) - 250;
	
	var slide = getElement("listmightydetailsSilde");
	slide.style.left = parentLeft + 100;

	var windowheight = 1;
	var objNewAccount = getElement("listmightydetailwindow");
	objNewAccount.style.height = windowheight;

	objNewAccount.style.top = elemTop;
	objNewAccount.style.left = elemLeft;
	objNewAccount.style.display = "block";	
	resizeWindowFixed("listmightydetailscontent", 1, 80);
	var htmlbody;
	if (arguments[1] == 1) {
		htmlbody = "Create a \"<u>no personal information</u>\" anonymous account to use <b>ListMighty</b> on ShopMighty.com to save yourself time and money.<br>Gift registries and shopping lists across millions of products and hundreds of stores.<div class=\"more\"><a href=\"/ListmightyHome\">Click here for more details or select \"New Shopper\" at the top of this page.</a></div>";
	}
	if (arguments[1] == 2) {
		htmlbody = "You too can harness the power of <b>ListMighty</b> on ShopMighty.com like your firends and family have, by creating a \"<u>no personal information</u>\" anonymous account for yourself.<div class=\"more\"><a href=\"/ListmightyHome\">Click here for more details or \"Sign Out\" and select \"New Shopper\" at the top of this page.</a></div>";
	}
	if (arguments[1] == 3) {
		htmlbody = "Now that you have seen the power of <b>ListMighty</b> and the ease of use your friends and family have experienced, create a \"<u>no personal information</u>\" anonymous account for yourself.<div class=\"more\"><a href=\"/ListmightyHome\">Click here for more details or \"Sign Out\" and select \"New Shopper\" at the top of this page.</a></div>";
	}	var body = getElement("listmightydetailscontent");
	body.innerHTML = htmlbody;	

}

function showListMightyDetails() {
	var prodcatid = arguments[0].substring(2, arguments[0].length);
	var categoryid = arguments[1];
	var sessionid = arguments[2];
	var nameId = arguments[3];
	var highlight = arguments[4];
	var stop = 0;
	if (currentlistdetails == prodcatid) stop = 1;
	closeListMightyDetails();
	if (stop == 1) return;
	
	currentlistdetails = prodcatid;
	var parentObj = getElement(arguments[0]);
	var parentTop = getElementTopObj(parentObj);
	var parentLeft = getElementLeftObj(parentObj);
	var parentWidth = 145
	
	var elemTop = parentTop+23;
	var elemLeft = (parentLeft + (parentWidth / 2)) - 250;
	
	var slide = getElement("listmightydetailsSilde");
	slide.style.left = parentLeft + 100;
	var windowheight = 1;
	var objNewAccount = getElement("listmightydetailwindow");
	objNewAccount.style.height = windowheight;

	objNewAccount.style.top = elemTop;
	objNewAccount.style.left = elemLeft;
	objNewAccount.style.display = "block";	
	
	resizeWindowFixed("listmightydetailscontent", 1, 80);
	var htmlbody = "<table border=0 cellpadding=0 cellspacing=0 class=\"listmightylisttable\"><tbody>";
	htmlbody += "<tr><td class=\"listmightylistheadder\" style=\"text-align: center; font-size:11px;border-right: thin solid #CCCCCC;\">List</td><td class=\"listmightylistheadder\" width=70 style=\"text-align: center; font-size:11px;border-right: thin solid #CCCCCC;\">Type</td><td class=\"listmightylistheadder\" width=70 style=\"text-align: center; font-size:11px;border-right: thin solid #CCCCCC;\">Status</td><td class=\"listmightylistheadder\" width=70 style=\"text-align: center; font-size:11px;border-right: thin solid #CCCCCC;\">Action</td><td class=\"listmightylistheadder\" width=70 style=\"text-align: center; font-size:11px;border-right: thin solid #CCCCCC;\">Purchased</td></tr>";
	if (listMightyLists.length > 0) {	
		var foundMatch;
		var purchased;
		for (var i=0; i<listMightyLists.length; i++) {
			foundMatch = 0;
			purchased = 0;
			if (arguments.length > 5) {
				for (var j=5;j<arguments.length; j=j+2) {
					if (arguments[j] == listMightyLists[i].id) {
						foundMatch = 1;
						if (arguments[j+1] == "yes") purchased = 1;
						break;
					}
				}
			}
			htmlbody += "<tr>";
			htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\">"+listMightyLists[i].name+"</td>";
			if (listMightyLists[i].type == 1) {
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\"><span id=\"listmightydetailsTypePublic\">Private</span></td>";
			} else {
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\"><span id=\"listmightydetailsTypePrivate\">Public</span></td>";						
			}
			if (foundMatch == 1) {
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\"><span id=\"listmightydetailsAdded\">Added</span></td>";
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\"><a href=\"javascript:RemoveFromList('"+listMightyLists[i].id+"', '"+prodcatid+"', '"+sessionid+"');\" class=\"listmightydetailsRemove\">Remove</a></td>";
				if (purchased == 1) {
					htmlbody += "<td class=\"listmightylistcelllast\" style=\"background-color: white\"><span id=\"listmightydetailsPurchased\">Yes</span></td>";
				} else {
					htmlbody += "<td class=\"listmightylistcelllast\" style=\"background-color: white\">&nbsp;</td>";				
				}
			} else {
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\">&nbsp;</td>";				
				htmlbody += "<td class=\"listmightylistcellfirst\" style=\"background-color: white\"><a href=\"javascript:AddToList('"+listMightyLists[i].id+"', '"+prodcatid+"', "+categoryid+", '"+sessionid+"', '"+nameId+"', "+highlight+");\" class=\"listmightydetailsInclude\">Include</a></td>";
				htmlbody += "<td class=\"listmightylistcelllast\" style=\"background-color: white\">&nbsp;</td>";
			}
			htmlbody += "</tr>";
		}
	} else {
		htmlbody += "<td class=\"listmightylistcelllast\" colspan=5 style=\"background-color: white\">No Lists Created</td>";	
	}
	htmlbody += "</tbody></table>";
	var body = getElement("listmightydetailscontent");
	body.innerHTML = htmlbody;	
}

function AddToList(listid, prodcatid, categoryid, sessionid, nameId, highlight) {
	var nameObj = getElement(nameId);
	var name = "";
	if (highlight) {
		name = nameObj.value;		
	} else {
		name = nameObj.innerHTML;
	}
	var url = "web_mitrya/listmightysubmit.jsp?sid="+sessionid+"&mode=2";
	url += "&listid="+listid+"&prodcatid="+prodcatid+"&categoryid="+categoryid+"&name="+encodeURIComponent(name);
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";	
} 

function RemoveFromList(listid, prodcatid, sessionid) {
	var url = "web_mitrya/listmightysubmit.jsp?sid="+sessionid+"&mode=3";
	url += "&listid="+listid+"&prodcatid="+prodcatid;
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";	
} 

function RemoveListProductId(listproductid, sessionid) {

	var url = "web_mitrya/listmightysubmit.jsp?sid="+sessionid+"&mode=3";
	url += "&listproductid="+listproductid;
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + url +"\"></iframe>";
}

function listmightybuy(listProductId, listid, productCatalogId, name, url) {
	var text = "Did you purchase the product:<br>'"+name+"'?<br><br><input type=\"radio\" name=\"baughtproduct\" value=\"yes\" onclick=\"javascript:processListMightyBuy('"+listProductId+"', '"+listid+"', this.value);\">&nbsp;Yes&nbsp;&nbsp;<input type=\"radio\" name=\"baughtproduct\" value=\"no\" onclick=\"javascript:processListMightyBuy('"+listProductId+"', '"+listid+"', this.value);\">&nbsp;No&nbsp;&nbsp;<input type=\"radio\" name=\"baughtproduct\" value=\"na\" onclick=\"javascript:processListMightyBuy('"+listProductId+"', '"+listid+"', this.value);\">Not Me";
	showMessage(3, text, 1);
	ref = window.open(url, '_blank');
	var submiturl = "web_mitrya/listmightysubmit.jsp?mode=4&listproductid="+listProductId+"&value=pnd";
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + submiturl + "\"></iframe>";
}

function processListMightyBuy(listProductId, listid, value) {
	if (value == "na") {
		var url = "web_mitrya/listmightysubmit.jsp?mode=5&listproductid="+listProductId+"&listid="+listid+"&reload=1";
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
	} else {
		var url = "web_mitrya/listmightysubmit.jsp?mode=4&listproductid="+listProductId+"&value="+value+"&reload=1";
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";	
	}
}

function removelistitem(listid, name, sessionid) {
	var text = "Are you sure you want to remove the list:<br>'"+name+"'?<br><br><input type=\"radio\" name=\"removelistmightylist\" value=\"yes\" onclick=\"javascript:processremovemightylist('"+listid+"', this.value, '"+sessionid+"');\">&nbsp;Yes&nbsp;&nbsp;<input type=\"radio\" name=\"removelistmightylist\" value=\"no\" onclick=\"javascript:closeMessage();\">&nbsp;No";
	showMessage(4, text, 1);

}

function processremovemightylist(listid, value, sessionid) {
	if (value == "yes") {
		var url = "web_mitrya/listmightysubmit.jsp?sid="+sessionid+"&mode=8&listid="+listid;
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
	} else {
		closeMessage();
	}
}

function processpostremovelist(listid, sessionid) {
	if (window.location.href.indexOf("/listmighty/") > -1 && window.location.href.indexOf(listid) > -1) {
		var session = "";
		if (!cookiesEnabled()) {
			window.location.replace("/"+";jsessionid="+sessionid, true);
		} else {
			window.location.replace("/", true);
		}			
	} else {
		location.reload();
	}
}