gamPlugin = {
    generateUniqueId : function() {
        var date = new Date();
        var SUP = 1000000;
        random = Math.floor((SUP*Math.random())+1);
        var uniqueId = date.getTime() + "_" +random;
        return uniqueId;
    },
    fillAdv : function( advCode, clickCounterUrl, syncWriter ) {
        if( clickCounterUrl ) {
            advCode = '<div class="psccClkUrl" style="display:none">' + clickCounterUrl  + '</div>' + advCode;
        }
        divName = 'gamPlugin' + gamPlugin.generateUniqueId();
        if( syncWriter ) {
            gamPlugin.syncFillAdv( advCode );    
        }
        else { 
            gamPlugin.writeDiv(divName);
            gamPlugin.addOnLoadWriter( divName, advCode );
        }
    },
    fillAdvIframe : function ( iframeUrl, width, height, clickCounterUrl, syncWriter) {
        advCode = ' <iframe width="' + width + '" height="' + height + '" scrolling="No" frameborder="0" marginheight="0" marginwidth="0" src="' + iframeUrl + '"></iframe>';
        gamPlugin.fillAdv( advCode, clickCounterUrl, syncWriter );
    },
    writeDiv : function(divName) {
        document.write('<div id="' + divName + '"></div>');
    },
    addOnLoadWriter: function( divName, advCode){
        if( typeof(dojo) != "undefined" ) {
            dojo.addOnLoad( function (){
                gamPlugin.asyncFillAdv( divName, advCode);
            });
        }
        else
        {
            if(document.addEventListener) {
                document.addEventListener('DOMContentLoaded', function(){
                    gamPlugin.asyncFillAdv( divName, advCode);
                }, false);
            } else if( document.attachEvent ) {
                document.attachEvent('onreadystatechange', function() {
                   if(document.readyState == 'complete') {
                        gamPlugin.asyncFillAdv( divName, advCode);   
                   }
                });
            }
        }
    },
    syncFillAdv : function( advCode ){
        document.write(advCode);    
    },
    asyncFillAdv : function ( divName, advCode) {
        advContainer = document.getElementById( divName );
        if( advContainer ) {
            advContainer.innerHTML = advCode;
        }   
    }
}
