

var map = null;

function launchExample() {
	var cusips = [ ];

	$(':checkbox:checked').each(function(indx, obj) {
		if (obj.value)
			cusips[cusips.length] = obj.value;
	});

	if (cusips.length == 0) {
		Ext.Msg.show({
			title: 'No Bonds Selected',
			msg: 'Please select at least one bond from the list before viewing the map',
			buttons: Ext.Msg.OK,
			icon: Ext.MessageBox.INFO,
			maxWidth: 300
		});
		return;
	}

	map = new BondMap({
		title: 'Your Selected Bonds',
		modal: true,
		destroyOnClose: true,
		draggable: true,
		cusips: cusips,
		dataUrl: 'bondmap',
		showSidebar: true,
		hoverFields: ['bonds_security_description', 'bonds_cusip'],
		clickFields: ['bonds_security_description', 'bonds_cusip']
	});

	map.show();
}

/**
 * Implemented by JM to use custom cusips
 */
function launchMap(cusip)
{
    var cusips = [ ];

	/*$('input[name=cusip]').each(function(indx, obj) {
		if (obj.value)
			cusips[cusips.length] = obj.value;
	});*/
    cusips[cusips.length] = cusip;

    if (cusips.length == 1) showSidebarVal = false;
    else showSidebarVal = true;

	if (cusips.length == 0) {
		Ext.Msg.show({
			title: 'No Bonds Selected',
			msg: 'Please select at least one bond from the list before viewing the map',
			buttons: Ext.Msg.OK,
			icon: Ext.MessageBox.INFO,
			maxWidth: 300
		});
		return;
	}

	map = new BondMap({
		title: 'Your Selected Bonds',
		modal: true,
		destroyOnClose: true,
		draggable: true,
		cusips: cusips,
		dataUrl: '/map/bondmap',
		showSidebar: showSidebarVal,
        position: [1,0,-20,20],
		hoverFields: ['bonds_security_description', 'bonds_cusip'],
		clickFields: ['bonds_security_description', 'bonds_cusip']
	});

	map.show();
}



/**
 * Used in Portfolio page (display many results)
 */
function launchMap2(cusip)
{
    var cusips = $('#holdings').val().split(',');

    if (cusips.length == 1) showSidebarVal = false;
    else showSidebarVal = true;

	if (cusips.length == 0) {
		Ext.Msg.show({
			title: 'No Bonds Selected',
			msg: 'Please select at least one bond from the list before viewing the map',
			buttons: Ext.Msg.OK,
			icon: Ext.MessageBox.INFO,
			maxWidth: 300
		});
		return;
	}

	map = new BondMap({
		title: 'Your Selected Bonds',
		modal: true,
		destroyOnClose: true,
		draggable: true,
		cusips: cusips,
		dataUrl: '/map/bondmap',
		showSidebar: showSidebarVal,
        position: [1,0,-20,20],
		hoverFields: ['bonds_security_description', 'bonds_cusip'],
		clickFields: ['bonds_security_description', 'bonds_cusip']
	});

	map.show();
}

