//
// right hand header tabs
var iAutoRollerAt = -1;
var header_order = Array('subscribe', 'advertise', 'classifieds', 'buy_photos', 'contact_us');

//
//flag, turns true when user rolls over top, right hand tabs

//userRoll = false;

//
//
// Header Righthand Roll over tab currently on/set
var RROCurrentlyOn = null;

//
/////

var header_tabs = Array();
header_tabs['subscribe']  = Array();
header_tabs['subscribe']['on']  = new Image(97,21);
header_tabs['subscribe']['on'].src ='http://ricath.new.adqic.com/images/branding/header/on/subscribe.png';
header_tabs['subscribe']['off'] = new Image(97,21);
header_tabs['subscribe']['off'].src='http://ricath.new.adqic.com/images/branding/header/off/subscribe.png';
header_tabs['subscribe']['num']=0;


header_tabs['advertise']  = Array();
header_tabs['advertise']['on']  = new Image(97,22);
header_tabs['advertise']['on'].src ='http://ricath.new.adqic.com/images/branding/header/on/advertise.png';
header_tabs['advertise']['off'] = new Image(97,22);
header_tabs['advertise']['off'].src='http://ricath.new.adqic.com/images/branding/header/off/advertise.png';
header_tabs['advertise']['num']=1;

header_tabs['about_us']= Array();
header_tabs['about_us']['on']  = new Image(97,18);
header_tabs['about_us']['on'].src ='http://ricath.new.adqic.com/images/branding/header/on/about_us.png';
header_tabs['about_us']['off'] = new Image(97,18);
header_tabs['about_us']['off'].src='http://ricath.new.adqic.com/images/branding/header/off/about_us.png';
header_tabs['about_us']['num']=2;

header_tabs['buy_photos'] = Array();
header_tabs['buy_photos']['on']  = new Image(97,22);
header_tabs['buy_photos']['on'].src ='http://ricath.new.adqic.com/images/branding/header/on/buy_photos.png';
header_tabs['buy_photos']['off'] = new Image(97,22);
header_tabs['buy_photos']['off'].src='http://ricath.new.adqic.com/images/branding/header/off/buy_photos.png';
header_tabs['buy_photos']['num']=3;

header_tabs['contact_us'] = Array();
header_tabs['contact_us']['on']  = new Image(97,22);
header_tabs['contact_us']['on'].src ='http://ricath.new.adqic.com/images/branding/header/on/contact_us.png';
header_tabs['contact_us']['off'] = new Image(97,22);
header_tabs['contact_us']['off'].src='http://ricath.new.adqic.com/images/branding/header/off/contact_us.png';
header_tabs['contact_us']['num']=4;


function onLoadFunc()
{
    // only want 'subscribe' to show
    //oMessageAreaDiv = document.getElementById('message_area');
    //oMessageAreaDiv.innerHTML = header_tabs['subscribe'].text;

    // ticker interval canned
   // var ticker_interval;
   // ticker_interval = window.setInterval("nextRollerTab()", 2000);
}

/*
function nextRollerTab()
{
    //  userRoll becomes true when the user rolls over
    //  the upper right tabs

    if (! userRoll)
    {
        // turn all of the tabs off
        header_right_clearAllTabs();

        iAutoRollerAt++;
        if (iAutoRollerAt>=header_order.length) { iAutoRollerAt=0;}
       // alert('roller at: '+header_order);
        sName = header_order[iAutoRollerAt];
        //alert('name: '+sName);
        oDiv= document.getElementById(sName);
        header_right_action(oDiv, 1);

        //alert(sText);
        // show next tab
    }
    else
    {
        userRoll=false;
    }
}
*/



function header_right_action(oDiv, iAction)
{
    if (oDiv)
    {
        switch (iAction)
        {
            //mouse over
            case 1:
                header_right_clearAllTabs();

                //first change the button on
                //iAutoRollerAt = header_tabs[oDiv.id]['num'];

                oDiv.src= header_tabs[oDiv.id]['on'].src;
                //oMessageAreaDiv = document.getElementById('message_area');
                //oMessageAreaDiv.innerHTML = header_tabs[oDiv.id].text;

                selfclick=true;
                return true;
                break;

            //mouse out
            case 0:

                //first change the button off
                oDiv.src= header_tabs[oDiv.id]['off'].src;

                // the change the text panel
                //oMessageAreaDiv = document.getElementById('message_area');
                //oMessageAreaDiv.style.innerHTML = ''; //
                
                //oMessageAreaDiv.src = '/images/spacer.png';
                return true;
                break;
        }
    }
}

/* clears all mouseovers for upper right nav tabs */
function header_right_clearAllTabs()
{
    // turn all of the tabs off
    sText='';
    for(a=0;a<header_order.length;a++)
    {
        sName = header_order[a];

        if (sName!=RROCurrentlyOn)
        {
            oDiv= document.getElementById(sName);
            if (oDiv)
            {
                header_right_action(oDiv, 0);
            }
        }
    }
}


/* main horizontal nav tabs */
function mousetab(oDivStart, iAction)
{
    switch (iAction)
    {
        case 1:
            sName = oDivStart.id+'_hide';
            oDiv = document.getElementById(sName);
            oDiv.style.visibility='visible';
            break;

        case 0:
            sName = oDivStart.id+'_hide';
            oDiv = document.getElementById(sName);
            oDiv.style.visibility='hidden';
            break;
    }
}



function tpl_search_go()
{
    if( document.getElementById('tpl_search_filter').value )
    {
        document.tpl_overall_search.submit();
    }
}


function print_page(subid)
{
    popUp('/print_detail.html?sub_id='+subid);
}




/*************** core functions *********************/

function popUp(sURL)
{
window.open(sURL);
}

function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
    while(1){
        curleft += obj.offsetLeft;
        if(!obj.offsetParent) break;
        obj = obj.offsetParent;
    }
    else if(obj.x)
    curleft += obj.x;
    return curleft;
}

function findPosY(obj){

    var curtop = 0;
    if(obj.offsetParent)
    while(1){
        curtop += obj.offsetTop;
        if(!obj.offsetParent) break;
        obj = obj.offsetParent;
    }
    else if(obj.y)
    curtop += obj.y;
    return curtop;

}

function confirm_delete(in_url){

    if( confirm("Permenantly delete this item?") ){

        window.location.href = in_url;

    }

}


/* ------------------------------------------------------------ */

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}




// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}



