﻿/*
* Buy Now Popup Confirmation
* Copyright (c) 2009 Andrew Greenstreet | andrewgstreet@gmail.com
* Revision: 1.0
*/
//At a baseline, these are our buy now links
var yesURL = "http://my.t-mobile.com";
var noURL = "http://www.t-mobile.com";

function buyNow(_yesURL, _noURL) {
    //alert("Are you a T-mobile Customer\nYes: " + yesURL + "\nNo: " + noURL);
    if (_yesURL != undefined && _yesURL != "undefined" && _yesURL != "") {
        yesURL = _yesURL;
    }
    if (_noURL != undefined && _noURL != "undefined" && _noURL != "") {
        noURL = _noURL;
    }
    showConfirmCustomerYesNo();
    $(window).bind('resize', function() { positionAndSizeConfirm(); });
    $(window).bind('scroll', function() { positionAndSizeConfirm(); });
}

function customerYesCallback() {
    if (trackEventAndGoto({ id: "buynow.yes", href: yesURL })) {
        //if the id exists, the tracking system will automatically change the page
        //if it doens't we'll use the tracking systems page redirect function
        ts_gotoURL();
    }
    return false;
}

function customerNoCallback() {
    if (trackEventAndGoto({ id: "buynow.no", href: noURL })) {
        //if the id exists, the tracking system will automatically change the page
        //if it doens't we'll use the tracking systems page redirect function
        ts_gotoURL();
    }
    return false;
}

function showConfirmCustomerYesNo() {
    positionAndSizeConfirm();
    $('#confirmModalOverlay').show();
    $('#confirmModalContainer').show();
    $('#confirmClose').click(function() {  hideCofirmCustomerYesNo() });
    $('#confirmYes').click(function() { return customerYesCallback(); });
    $('#confirmNo').click(function() { return customerNoCallback(); });
    $('#confirmYes').attr('href', yesURL);
    $('#confirmNo').attr('href', noURL);
}

function hideCofirmCustomerYesNo() {
    $('#confirmModalOverlay').hide();
    $('#confirmModalContainer').hide();
    $(window).unbind('resize', function() { positionAndSizeConfirm(); });
    $(window).unbind('scroll', function() { positionAndSizeConfirm(); });
}

function positionAndSizeConfirm() {
    var width = $(window).width();
    var height = $(window).height();
    var scrollTop = $(document).scrollTop();
    $('#confirmModalOverlay').css({ "width": width + "px", "height": height + "px" });
    $('#confirmModalOverlay').css({ "top": scrollTop + "px"});
    var dialogWidth = $('#confirmModalContainer').width();
    var dialogHeight = $('#confirmModalContainer').height();
    $('#confirmModalContainer').css({ "left": Math.round((width / 2) - (dialogWidth / 2)) + "px", "top": (scrollTop + 200) + "px" });
}

$(document).ready(function() {
    
});