var supportMask;

function PluginSupportTickets()
{
    showSupportMask();
    
    // Clean the info of the previously loaded js file to avoid conflicts
    cleanjsfiles();
    
	LazyLoad.js(
		'../plugins/dashboard/supporttickets/ViewSupportTickets.js',
		function(){
			hideSupportMask();
			ViewSupportTickets();
		}
	);

}

function showSupportMask()
{
    if(!supportMask){
        supportMask = new Ext.LoadMask('supportMask', {msg:"Please wait..."});
    }
    
    document.getElementById('supportMask').style.display = '';
    supportMask.show();
}

function hideSupportMask()
{
    supportMask.hide();
    document.getElementById('supportMask').style.display = 'none';
}

function cleanjsfiles()
{
    // Remove the objects loaded from the js file
    if(typeof removeObjects == 'function'){
        removeObjects();
        
        // Remove the removeObjects function, because each js file charge its own function
        removeObjects = null;
    }
    
    // Remove the js file. You need to list all the js files here.
    removejscssfile("ViewSupportTickets.js", "js");
}

function removejscssfile(filename, filetype)
{
    //determine element type to create nodelist from
    var targetelement = (filetype == "js")? "script" : (filetype == "css")? "link" : "none";
    
    //determine corresponding attribute to test for
    var targetattr = (filetype == "js")? "src" : (filetype == "css")? "href" : "none";
    
    var allsuspects = document.getElementsByTagName(targetelement);
    
    //search backwards within nodelist for matching elements to remove
    for(var i = allsuspects.length; i >= 0; i--){
        if(allsuspects[i]
          && allsuspects[i].getAttribute(targetattr) != null
          && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1){
            //remove element by calling parentNode.removeChild()
            allsuspects[i].parentNode.removeChild(allsuspects[i]);
        }
    }
}