divHTML = {};
curWUID = 0;

//jQuery(document).ready( function() {
//	if ( jQuery(".addToCartButton").length > 0 ) {
//		jQuery('a.pagination').each( function() {
//			var href = jQuery(this).attr("href");
//			jQuery(this).attr("href", "#");
//			jQuery(this).click( function() {
//				viewall(curWUID, href);
//			});
//		});
//	}
//});
	
$(document).ready( function() {
	$('a[@href^=ADDRBOOK]').click( function() { addToAb(); return false; } )
});
	
function showReturnLink() {
	var qs = new Querystring();
	document.getElementById("profileReturnLink").innerHTML = "<a href='userprofile.asp?user_id=" + qs.get("user_id") + "' onclick='document.getElementById(\'profileReturnLink\').innerHTML = \'\''>Return to profile home</a>";
}

function initPage() { 
	//Sortable.create('profile_content', {tag: 'div', onUpdate: function () { serialize('profile_content'); } });
	$('#leftColumn').Sortable (
		{
			accept: 'leftFav',
			opacity: 0.5,
			tolerance: 'pointer',
			onchange: updateOrder,
			axis: 'vertically',
			helperclass: 'dropTargetOutline'
		}
	);
	$('#rightColumn').Sortable (
		{
			accept: 'rightSortable',
			opacity: 0.5,
			tolerance: 'pointer',
			onchange: updateOrder,
			axis: 'vertically',
			helperclass: 'dropTargetOutline'
		}
	);
};

var updateOrder = function (data) {
	var qs = data[0].hash;
	
	$.get("AJAX/userprofile_widgetorder_tj.asp?" + qs, { });

}

function viewall(widget_user_id, pg) {
	showReturnLink();
	curWUID = widget_user_id;
	$.get('/AJAX/userprofile_viewall.asp',
		{ 'widget_user_id': widget_user_id, pg: pg },
		function(data) {
			$('#profile_content').html(data);
		}
	);
}

function viewLeftWidgetChoices() {
	showReturnLink();
	$.get('/AJAX/userprofile_leftwidgetchoice.asp',
		{ },
		function(data) {
			$('#profile_content').html(data);
		}
	);
};

function addToLeftCol(widget_id, user_id) {
	var title = document.getElementById("text_" + widget_id).value;
	
	if (document.getElementById("select_" + widget_id)) {
	
		var book_cat_id = document.getElementById("select_" + widget_id).value;
		
	} else {
		
		var book_cat_id = 0;
		
	}
	
	$.get('/AJAX/userprofile_leftColumnAdd.asp',
		{
			widget_id: widget_id,
			user_id: user_id,
			title: title,
			book_cat_id: book_cat_id	
		},
		function(data) {
			$('#leftColumn').prepend(data);
			$('#leftColumn div:eq(0)').Highlight('normal', '#B6E5EC');
			initPage();
		}
	);
	
};
	
function removeLeftBox(widget_user_id, dom_id) {
	$.get('/AJAX/userprofile_removeLeftBox.asp',
		{ widget_user_id: widget_user_id },
		function(data) {
			$('#' + dom_id).slideUp("normal", function () { $(this).remove(); initPage(); } );
		}
	);
};

function addToAb() {
    var qs = new Querystring();
    $.post('/AJAX/addressbook.asp',
        { id: qs.get("user_id"), action: 'edit', noredir: 'True' },
        function (data) {
            $('a[@href^=ADDRBOOK]').parent().after("<li style='color: blue;'>Member Added</li>").remove()
        });
}
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}


