/* $Id: nx_commonTopContent.js,v 1.21 2012/02/21 06:45:15 nimisha Exp $ */

if ((location.hostname.match(/nettikone/i) || location.hostname.match(/nettikaravaani/i) || location.hostname.match(/nettimoto/i) || location.hostname.match(/nettivene/i) || location.hostname.match(/nettiauto/i)) &&
(document.location.href.match(/yritys/i) != 'yritys') && (document.location.href.match(/mainOnly/i) != 'mainOnly') &&
(document.location.href.match(/hakukone/i) != 'hakukone'))
{
    if(document.referrer.match(SITEWISE_MOBILE_URL))
    {
        var date = new Date();
        var expdate = date.getTime();

        expdate = expdate + (24 * 1000 * 60 * 60 * 24); //for 30 hour
        date.setTime(expdate);

        document.cookie = 'mob_ver=1; expires='+ date.toGMTString() + '; path=/;';
    }
    else if(document.cookie.indexOf('mob_ver_allow') == -1)
    {

        var date = new Date();
        var expdate = date.getTime();

        if(MOBILE_COOKIE == 0 && MOBILE_DEVICE > 0 )
        {
            window.location.href=window.location.href.replace('http://'+window.location.hostname,SITEWISE_MOBILE_URL);
        }
        else
        {
            expdate = expdate + (60 * 60 * 1000);   //for 1 hour
            date.setTime(expdate);
            document.cookie = 'mob_ver_allow=1; expires='+ date.toGMTString() + '; path=/;';
        }
    }
}
document.cookie = 'yritys=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;';

if(window.attachEvent){
    window.attachEvent("onload",function(){onLoadBanner();});
}else{
    window.addEventListener("load",function(){onLoadBanner();},false);
}
function onLoadBanner()
{
    if (_isNLSite == 1)
    {
        show_mostNL()
        var scriptName = location.href.substring((location.protocol.length + location.hostname.length + 3)).split('?')[0];
        var cookNm = GetCookie('cookNameComp');
        if(!scriptName.match(/yritys/i) && !scriptName.match(/hakukone/i) && !location.href.match(/camp_ducati/i) && cookNm == null)
            chkLenLoad();
    }
    else if(document.location.href.match(/ellit/i) != 'ellit' && document.location.href.match(/kaksplus/i) != 'kaksplus' )
        show_most();
}
function show_most(){
    /* Dont apply jquery here. bz few pages don't contain jquery.js for ex. printable version of service index*/
    if (document.getElementById('mostbanner'))
    {
        if( document.getElementById('mostbanner').clientHeight < 100) {
            document.getElementById('most_viewed').style.display='inline';
        }
    }
}

function show_mostNL(){
    if(jQuery('#mostbanner').height() < 100)
        jQuery('#most_viewed').css('display','inline');
    if(jQuery('#body_banner').width() > 300)
    {
        jQuery('#article_sh').css('display','none');
        jQuery('#v_more_article').css('display','none');
        jQuery('#body_banner').css('width','100%');
        jQuery('#body_banner').css('float','none');
        jQuery('#body_banner').css('padding','20px 0');
        jQuery('#body_banner').css('margin','0 auto;');
    }
    else
        jQuery('#body_banner').css('width','300px;');
}
function redirectSite(sc,I,U,O,e,lang)
{
    var pars = 'auth=Y&O='+O+'&I='+I+'&U='+U+'&e='+e+'&sitelang='+lang;
    window.location.href = sc+'/login.php?'+pars;
}
