var urlToShow = "http://7.rotator.wigetmedia.com/servlet/ajrotator/117434/0/vh?z=wiget&amp;dim=79059&amp;kw=&amp;click=";
var popCookieName = "wigetmedia_tankafetast";
var expireHours = "12";

var alreadyExecuted = false;
var browserUserAgent = navigator.userAgent;
var time = new Date().getTime();

var config = "width=1000,toolbar=1,menubar=1,resizable=1,scrollbars=1";

function displayTheWindow() {
    var didPop = false;
    if(alreadyExecuted == false && Get_Cookie(popCookieName) === null){
        alreadyExecuted = true;
        if(browserUserAgent.search("Firefox/3") > -1 || browserUserAgent.search("Safari") > -1){
            config = "width=" + screen.width + ", height=" + screen.height + ",toolbar=1,menubar=1,resizable=1,scrollbars=1";
            var w = window.open(urlToShow,popCookieName,config).blur();
            window.focus();
            if(w)
                didPop = true;
        }
        else if(browserUserAgent.search("Firefox") > -1){
            config = "width=" + screen.width + ", height=" + screen.height + ",toolbar=1,menubar=1,resizable=1,scrollbars=1";
            var w = window.open(urlToShow,popCookieName,config);
            var temp = w.window.open("about:blank");
            temp.close();
            if(w)
                didPop = true;
        }
        else if(browserUserAgent.search("Opera") > -1){
           
            var w = window.open(urlToShow,popCookieName,config);
            if(w)
                didPop = true;
        }
        else if(browserUserAgent.search("Chrome") > -1){
            config = "width=" + screen.width + ", height=" + screen.height + ",toolbar=1,menubar=1,resizable=1,scrollbars=1";
            var w = window.open(urlToShow,popCookieName,config).blur();
            window.focus();
            if(w)
                didPop = true;
        }
        else if(browserUserAgent.search("MSIE") > -1){
            config = "width=" + screen.width + ", height=" + screen.height + ",toolbar=1,menubar=1,resizable=1,scrollbars=1";
            var w = window.open(urlToShow,popCookieName,config);
            window.setTimeout(window.focus, 750);
            window.setTimeout(window.focus, 850);
            if(w){
                w.blur();
                didPop = true;
            }
        } 
        else{
            var w = window.open(urlToShow,popCookieName,config);
            if(w)
                didPop = true;
        }
       
        Set_Cookie( popCookieName, "1", expireHours);
    }
    alreadyExecuted = true;
}

document.onclick = displayTheWindow;

function Set_Cookie( popCookieName, value, expire_hours)
{
    var today = new Date();
    today.setTime( today.getTime() );
    var expires_date = new Date( today.getTime() + (1000 * 60 * 60 * expire_hours) );
    document.cookie = popCookieName + "=" +escape( value ) + ";expires=" + expires_date.toGMTString() + ";path=/";
}

function Get_Cookie( check_name ) {
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        a_temp_cookie = a_all_cookies[i].split( '=' );
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}
