function initSwitchAccountPopUp()
{
	$('#switchAccountWindow').dialog({ bgiframe: true,modal: true, autoOpen: false, title: 'Select Account', width:570, 
	buttons: {
		"Select": function() {
				document.forms["frmAccountsPopUp"].submit();		
		},	
		"Cancel": function() {
			$(this).dialog('close');
		}
	}
	});
}

function showSwitchAccountPopUp()
{
	$('#switchAccountWindow').dialog('open');
}



function initMyLists(id)
{	
	$.ajax({
		type:"POST",
		url: "AjaxFuncs.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "action=showMyLists&id="+id,
			async: false,
			success: function(msg){document.getElementById("productDetailsSection").innerHTML = msg;}
	})
	$('#productDetailsSection').dialog({ bgiframe: true,modal: true, autoOpen: false, title: 'Add ' + id + ' To My Lists', width:630, 
	buttons: {
		"Add To List": function() {
			if (document.getElementById("txtListNameNew")) {
				if ((!document.getElementById("txtListNameExisting"))&&(document.getElementById("txtListNameNew").value=="")){
					alert("Please specify name of a new list");
				}else{
					var listnew = document.getElementById("txtListNameNew").value;
					var listexisting='';
					if (document.getElementById("txtListNameExisting")){
						listexisting = document.getElementById("txtListNameExisting").value;
					}
					$.ajax({
						type:"POST",
						url: "AjaxFuncs.asp",
						dataType: "application/x-www-form-urlencoded",
						data: "action=addProductToList&id="+id+"&listnew="+encodeURIComponent(listnew)+"&listexisting="+encodeURIComponent(listexisting),
						async: false,
						error: function(){
							alert('Error tring to save list.');
						},
						success: function(msg){document.getElementById("productDetailsSection").innerHTML = msg;
						if (msg.indexOf("Congratulations")>0){
							$(":button:contains('Add To List')").hide();
						}
						}
					})
				}
			}
			else
			{
				$(":button:contains('Add To List')").hide();
				$(":button:contains('Close')").show();
			}
		},
		"Close": function() {
			$(this).dialog('close');
			$(this).dialog("destroy"); 
		
		}
	},
	close: function(){
		$(this).dialog("destroy"); 
	}
	});
}

function showMyLists()
{
	$(":button:contains('Add To List')").show();
	$(":button:contains('Close')").show();
	$('#productDetailsSection').dialog('open');
}




function updateProductQtyAdd(id,um,qty)
{	
	document.getElementById("smallcartdiv").innerHTML="<table border='0'><tr><td width='130px' align='center'><img src='images/preload.gif' /></td></tr></table>";
	$.ajax({
		type:"POST",
		url: "AjaxFuncs3.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "action=updateQtyAdd&id="+id+"&um="+um+"&qty="+qty,
		async: true,
		success: function(msg){
					$.ajax({		
						type:"POST",
						url: "AjaxFuncs3.asp",
						dataType: "application/x-www-form-urlencoded",
						data: "action=displaySmallCartSection",
						async: true,
						success: function(msg){						
							document.getElementById("smallcartdiv").innerHTML=msg;	
						}
					})	
		}
		});
}



function updateProductQtySubtract(id,um,qty)
{	
	document.getElementById("smallcartdiv").innerHTML="<table border='0'><tr><td width='130px' align='center'><img src='images/preload.gif' /></td></tr></table>";	
	$.ajax({
		type:"POST",
		url: "AjaxFuncs3.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "action=updateQtySubtract&id="+id+"&um="+um+"&qty="+qty,
		async: true,
		success: function(msg){
					$.ajax({		
						type:"POST",
						url: "AjaxFuncs3.asp",
						dataType: "application/x-www-form-urlencoded",
						data: "action=displaySmallCartSection",
						async: true,
						success: function(msg){						
							document.getElementById("smallcartdiv").innerHTML=msg;	
						}
					})
		}
		});
}



