// dummy function
function playnext()
{
}

function newImage( arg )
{   if( document.images )
    {   rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages()
{   if( document.images && ( preloadFlag == true ) )
    {   for( var i = 0; i < changeImages.arguments.length; i += 2 )
        {   document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

var preloadFlag = false;
function preloadImages()
{   if( document.images )
    {   nav_home_over = newImage( "/resources/gui/nav/nav_home_over.gif" );
        nav_news_over = newImage( "/resources/gui/nav/nav_news_over.gif" );
        nav_life_over = newImage( "/resources/gui/nav/nav_life_over.gif" );
        nav_music_over = newImage( "/resources/gui/nav/nav_music_over.gif" );
        nav_sports_over = newImage( "/resources/gui/nav/nav_sports_over.gif" );
        nav_school_over = newImage( "/resources/gui/nav/nav_school_over.gif" );
        nav_games_over = newImage( "/resources/gui/nav/nav_games_over.gif" );
        nav_exchange_over = newImage( "/resources/gui/nav/nav_exchange_over.gif" );
        nav_video_over = newImage( "/resources/gui/nav/nav_video_over.gif" );
        nav_anchors_over = newImage( "/resources/gui/nav/nav_anchors_over.gif" );
        preloadFlag = true;
    }
}

function popUp( url )
{   window.open( url, "pop", "width=400,height=500,toolbars=0,scrollbars=1" );
}

function popComments( place, name, width, height, options )
{   if( !width )
    {   width = 657;
    }
    if( !height )
    {   height = 450;
    }
    if( options == 1 )
    {   var properties = 'width=' + width + ',height=' + height + ',directories=no,history=no,statusbar=no,scrollbars=yes,resizable=no,menubar=no,personalbar=no,toolbar=no,locationbar=no';
    }
    else if( options == 2 )
    {   var properties = 'width=' + width + ',height=' + height + ',directories=no,history=no,statusbar=no,scrollbars=yes,resizable=no,menubar=yes,personalbar=no,toolbar=no,locationbar=no';
    }
    else
    {   var properties = 'width=' + width + ',height=' + height + ',directories=no,history=no,statusbar=no,scrollbars=no,resizable=no,menubar=no,personalbar=no,toolbar=no,locationbar=no';
    }
    msgWindow = window.open( place, name, properties );
    msgWindow.focus();
}

var expDays = 1; // number of days the cookie should last

function getRandom()
{   var total_pops = 3;
    var now = new Date();
    var sec = now.getSeconds();
    var random = sec % total_pops;
    random += 1;
    return random;
}

var rand = getRandom();
var page = "/resources/feedback/popup.html?random=" + rand;
var windowprops = "width=200,height=400,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

if( rand == 1 )
{   var windowprops = "width=200,height=400,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
}
else if( rand == 2 )
{   var windowprops = "width=200,height=361,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
}
else if( rand == 3 )
{   var windowprops = "width=300,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";
}

function GetCookie( name )
{   var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while( i < clen )
    {   var j = i + alen;
        if( document.cookie.substring( i, j ) == arg )
        {   return getCookieVal( j );
        }
        i = document.cookie.indexOf( " ", i ) + 1;
        if( i == 0 )
        {   break;
        }
    }
    return null;
}

function SetCookie( name, value )
{   var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie( name )
{   var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie( name );
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt()
{   var count = GetCookie('count');
    if( count == null )
    {   SetCookie( 'count', '1' );
        return 1;
    }
    else
    {   var newcount = parseInt( count ) + 1;
        DeleteCookie( 'count' );
        SetCookie( 'count', newcount, exp );
        return count;
    }
}

function getCookieVal( offset )
{   var endstr = document.cookie.indexOf( ";", offset );
    if( endstr == -1 )
    {   endstr = document.cookie.length;
    }
    return unescape( document.cookie.substring( offset, endstr ) );
}

function checkCount( which )
{   var count = GetCookie( 'count' );
    var acount = GetCookie( 'acount' );
    if( which == 1 )
    {   if( acount == null )
        {   acount = 1;
            SetCookie( 'acount', acount, exp );
            window.open( "/resources/feedback/feedback_anchors.html", "", "width=251,height=185,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no" );
        }
    }
    else if( which == 2 )
    {   if( acount == null )
        {   acount = 1;
            SetCookie( 'acount', acount, exp );
            Effect.BlindDown( 'feedback_survey', {duration:1.2, scaleX:false, scaleFrom:0} );
        }
    }
    else
    {   if( count == null )
        {   count = 1;
            SetCookie( 'count', count, exp );
            window.open( page, "", windowprops );
        }
    }
}

function checkFlash()
{   var flash = GetCookie( 'flashset' );
    if( flash == null )
    {   location = "/flash/no_flash.html?href=" + escape( window.location.href );
        window.location( location );
    }
}

function checkAge( month, day, year )
{   var now = new Date();
    var birthday = new Date( year, month, day, 0, 0, 0 );
    var y = now.getFullYear() - 13;
    var m = now.getMonth() + 1;
    var d = now.getDate();
    var h = now.getHours();
    var t = now.getMinutes();
    var s = now.getSeconds();
    var subtractor = new Date( y, m, d, h, t, s );
    if( birthday.getTime() <= subtractor.getTime() )
    {   return true;
    }
    else
    {   var ageblock = 1;
        SetCookie( 'ageblock', ageblock, exp );
        return false;
    }
}

function choose_search( form )
{   //Search Articles
    if( form.radio_btn[0].checked )
    {   form.action = 'http://search.channelone.com/search';
        return true;
    }
    //Search Videos
    else if( form.radio_btn[1].checked )
    {   var url = 'http://livewire.channelone.com/livewireplayer/livewire.html?category=Search&search=' + form.q.value;
        popComments( url, 'livewire', 860, 660 );
        return false;
    }
}

//  End
