//used for the global sites
$(document).ready(function() {

    $(".globalSitesDD").hide();

    $(".globalSites").hover(
        function() {
            $(this).children("ul").show();
        }, function() {
            $(this).children("ul").hide();
        }); //hover

    //add popup query to all rel=popup links
    $("a[rel*='popup']").attr("href", function() {
        var i = this.href;
        if (i.indexOf("?") == -1) {
            return i + "?popup=true";
        }
        else {
            return i + "&popup=true";
        }
    });

    //add in google tracking
    $("a").click(function() {
        var track = $(this).attr("href");
        var ss = track.substr(0, 4)
        if (ss != "http" && ss != "idoc") return;
        var grouping = "/outbound/";
        if (ss == "idoc") grouping = "/doc/";
        try {
            var title = $(this).attr("title");
            track = (title != undefined && title != "") ? title : track;
        }
        catch (err) { }
        try {
            var bbox = $(this).attr("bbox");
            track = (bbox != undefined && bbox != "") ? bbox : track;
        }
        catch (err) { }
        pageTracker._trackPageview(grouping + track);
    });

    //check for popup and alter targets
    if (objURL["popup"]) {
        if (objURL["popup"] == "true") {
            $(".vidPopDetails a").attr("target", function() {
                if (this.target != "") {
                    return this.target;
                }
                else {
                    return "_parent";
                }
            });

            //get all the a and alter the target if not set to _parent
        }
    }

});          // document ready

// Build an empty URL structure in which we will store
// the individual query values by key.
var objURL = new Object();

// Use the String::replace method to iterate over each
// name-value pair in the query string. Location.search
// gives us the query string (if it exists).
window.location.search.replace(
         new RegExp("([^?=&]+)(=([^&]*))?", "g"),

// For each matched query string pair, add that
// pair to the URL struct using the pre-equals
// value as the key.
            function($0, $1, $2, $3) {
                objURL[$1] = $3;
            }
        );

$(document).ready(function() {
    //check for cookie
    if (get_cookie("www2") != null) return;
    $("a[href^='http://www2.visaeurope.com']").click(
        function() {
            if (!confirm("You are now being taken to a dedicated area on the Visa Europe website.")) {
                return false;
            }
            else {
                //save cookie
                var cookie_date = new Date();  // current date & time
                cookie_date.setDate(cookie_date.getDate() + 30); //add 30 days
                document.cookie = "www2=true; expires=" + cookie_date.toGMTString(); //add cookie
            }
        }
        );

});    // document ready


//get cookie function
function get_cookie(cookie_name) {

    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
    if (results)
        return (unescape(results[2]));
    else
        return null;
}

