QM_TOOLBAR_CID 			= 'CT2756054';
QM_TOOLBAR_INSTALLED 	= false;

jQuery(function(){
	QM_toolbar_init();
	setTimeout('QM_toolbar_install_check()', 3000);
});
		
function QM_toolbar_init()
{
	// Toolbar awareness
	try	
	{ 
		toolbar = new TPI.Toolbar(QM_TOOLBAR_CID);
	} 
	catch (e) 
	{ 
		return false; 
	};
	
	toolbar_check = toolbar.IsVisible();
	QM_TOOLBAR_INSTALLED = toolbar_check.returnValue;
	setTimeout('QM_toolbar_init()', 500);
	return QM_TOOLBAR_INSTALLED;
};

function QM_toolbar_refresh()
{
	try 
	{ 
		if (QM_TOOLBAR_INSTALLED)
		{ 
			toolbar.Refresh(); 
		}
	}
	catch(e) 
	{ 
		
	}
}

function QM_toolbar_install_check()
{	
	// First check the status to see if it needs to change.
	jQuery.post("/toolbar", {action: "checkToolbarInstalledStatus"}, function(r){
		if(r.status == 'success'){
			if(r.installed != QM_TOOLBAR_INSTALLED){
				// If the status isn't the same, then change it and see if we need to give them credit for it.
				jQuery.post("/toolbar", {action: "updateToolbarInstalledStatus", installed: QM_TOOLBAR_INSTALLED}, jQuery.noop(), "json");
				//If the toolbar is installed and they haven't been credited for it yet, then go ahead.
				if(QM_TOOLBAR_INSTALLED == true && r.credited==false){
					jQuery.post("/toolbar", {action: "apply_toolbar_credit"}, function(atc_r){
						if(atc_r.status == 'success'){
							show_modal_message(atc_r.status_message);
						} else {
							show_modal_error(atc_r.status_message);
						}
					}, "json");
				}
			} else {
				
			}
		}
	}, "json");
}
