var sfHover = function()
{
    var nav = document.getElementById("nav");
    var sfEls = nav.getElementsByTagName("LI");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function()
        {
            this.className += " sfhover";
        };
        sfEls[i].onmouseout = function()
        {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        };
    }
};
if (window.attachEvent) {
    window.attachEvent("onload", sfHover);
}

//pop-up window
function popup(url)
{
    window.open(url, 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=640,height=500");
}
function popupQuote(url)
{
    window.open(url, 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupRent()
{
    window.open(url + '/student_insurance/pages/win_your_rent/index.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=750,height=800");
}
function popupSPLogin()
{
    window.open(url + '/login', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupSPQuote()
{
    window.open(url + '/student_insurance/pages/possessions/quickquote.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupSPQuoteAA()
{
    window.open(url + '/student_insurance/pages/possessions/quickquote.jsp?REFERRER_ID=TheAA', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupSPRenewal()
{
    window.open(url + '/student_insurance/pages/possessions/renewal.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupSPRenewal2()
{
    window.open(url + '/student_insurance/pages/possessions/renewal2.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupRetrieveSPQuote()
{
    window.open(url + '/student_insurance/pages/possessions/retrievequote.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupBlockhallsQuote(name)
{
    window.open(url + '/student_insurance/pages/blockhalls/quote.jsp?NAME=' + name, 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=800,height=800");
}
function popupSaxonRegister(code)
{
    window.open(url + '/student_insurance/pages/saxon/register/index.jsp?CODE=' + code, 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=700,height=800");
}
function popupMobilePhoneQuote()
{
    window.open(url + '/mobilephone/quote/quote.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function popupTenantsPossessionsQuote()
{
    window.open(url + '/possessions/quote/quickquote.jsp', 'popup', "toolbar=no,location=no,scrollbars=yes,directories=no,status=no,resizable=yes,width=900,height=800");
}
function setCurrent(name)
{
    var ele = document.getElementById(name);
    ele.className = "current";
}

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function()
        {
            if (oldonload) {
                oldonload();
            }
            func();
        };
    }
}

function confirmPayment()
{
    var answer = confirm("We will now apply for payment\nClick on OK to continue.");
    if (answer) {
        var el1 = document.getElementById('formDiv');
        el1.style.display = 'none';
        var el2 = document.getElementById('processingDiv');
        el2.style.display = 'block';
        return true;
    }
    else {
        return false;
    }
}

function confirmPopup(message)
{
    return confirm(message);
}


function confirmPolicyChanges()
{
    return confirm("We will now apply the changes to your policy\nClick on OK to continue.");
}

function confirmSaveQuote()
{
    return confirm("We will now save your quote\nClick on OK to continue.");
}

function popupSeal()
{
    window.open("https://www.digi-sign.com/digi-seal/siteseal.pl?id=D30DBB0", "newWin", "scrollbars=no,status=yes,width=400,height=460");
}

function animate()
{
    // Check to see if the counter has been initialized
    if (typeof animate.counter == 'undefined') {
        // It has not... perform the initilization
        animate.counter = 1;
    }
    var el1 = document.getElementById('i' + animate.counter);
    el1.src = '../../common/images/orange.gif';
    if (++animate.counter == 8) {
        animate.counter = 1;
    }
    var el2 = document.getElementById('i' + (animate.counter));
    el2.src = '../../common/images/white.gif';
    setTimeout(animate, 500);
}
function initMenu()
{
    $('#menu ul').hide();
    $('#menu ul:first').hide();
    $('#menu li a').click(
            function()
            {
                var element = $(this).next();
                if ((element.is('ul')) && (element.is(':visible'))) {
                    $('#menu ul:visible').slideUp('normal');
                    return false;
                }
                if ((element.is('ul')) && (!element.is(':visible'))) {
                    $('#menu ul:visible').slideUp('normal');
                    element.slideDown('normal');
                    return false;
                }
            }
            );
}
$(document).ready(function()
{
    initMenu();
});

function getCookie(check_name)
{
    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 (var 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 = decodeURI(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            return cookie_value;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    return null;
}

function setCookie(name, value, expires, path, domain, secure)
{
    var today = new Date();
    today.setTime(today.getTime());
    if (expires)
        expires = expires * 1000 * 60 * 60 * 24;

    var expires_date = new Date(today.getTime() + (expires));
    document.cookie = name + "=" + encodeURI(value) +
                      ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
                      ( ( path ) ? ";path=" + path : "" ) +
                      ( ( domain ) ? ";domain=" + domain : "" ) +
                      ( ( secure ) ? ";secure" : "" );
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name)) document.cookie = name + "=" +
                                           ( ( path ) ? ";path=" + path : "") +
                                           ( ( domain ) ? ";domain=" + domain : "" ) +
                                           ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
