var done_url = '';
function popunder(url, target, options) {
	if(!($.browser.msie || $.browser.mozilla || $.browser.safari)) {
		return;
	}
	if (navigator.userAgent.match(/chrome/i) == "Chrome") {
		return;
	}
    if (url == null || url == "") {
        return;
    }

    if (done_url != url)
    {
	    pu = window.open(url, target, options);
	}
    if (pu != null) {
        pu.blur();
    }
	window.focus();
    setTP_PUCookie();
}

function makeTP_PUOptions() {
    var nW = 1024;
    var nH = 425;
    var edgeY = $(window).height();
    var edgeX = $(window).width();
    return "toolbar=0,scrollbars=1,location=1,status=0,menubar=1,resizable=1,width=1,height=1,left=" + edgeX + ",top=" + edgeY + ",screenX=" + edgeX + ",screenY=" + edgeY;
}

function setTP_PUCookie() {
    $.cookie("tp_pu", "1", {expires: 7, path: "/"});
}

function isTP_PUCookieSet() {
    return $.cookie("tp_pu") == "1";
}

function setUpdateCookie() {
	var date = new Date();
	date.setTime(date.getTime() + (1 * 60 * 60 * 1000)); // 1 hour
    $.cookie("pu_update", "yes", {expires: date, path: "/"});
}

function isUpdateCookieSet() {
    return $.cookie("pu_update") == "yes";
}

function isTPMember() {
	return $.cookie("tp_member") == "yes";
}

function openExpediaExitWindow(locationid, accommodation, tp_params) {
    var url = "/continue?geo_id=" + locationid;
    if (accommodation != null) {
        url = url + "&accom_id=" + accommodation;
    }
    url = url + tp_params;
    if (!isTPMember() && !isTP_PUCookieSet())
	    popunder(url, "popunder", makeTP_PUOptions());
}