﻿//jQuery.fn.center = function () {
//    //this.css("position", "absolute");
//    //this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
//    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
//    return this;
//}


function oSetSize() {
    //    var h;
    //    h = GetHeight();
    //    //h=1000;
    //    document.getElementById('my_frame').height = h;


    //$('#dvPopupOffer').css("top", ($(window).height() - $('#dvPopupOffer').height()) / 2 + $(window).scrollTop() + "px");
    $('#odvPopupOffer').css("left", ($(window).width() - $('#odvPopupOffer').width()) / 2 + $(window).scrollLeft() + "px");
}

function oGetHeight() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    //            window.alert('Width = ' + myWidth);
    //            window.alert('Height = ' + myHeight);
    return myHeight - 100
}

$(window).load(function () {
    oSetSize();


    var currentDate = new Date();
    var valueofTomorrowsDate = currentDate.valueOf() + (24 * 60 * 60 * 1000);
    var newDate = new Date(valueofTomorrowsDate);

    var ckOptions = { expiresAt: newDate }
    if (jQuery.cookies.test() == true) {

        if (jQuery.cookies.get('mypop') == null) {
            jQuery.cookies.set('mypop', 'done', ckOptions);
            oToggleOfferPopup();

        }
    }

});
$(window).resize(function () { oSetSize(); });

$(document).ready(function () {


    //inject offer link

    // $('body').prepend('<div style="text-align:center;"><img style="margin:auto; cursor:pointer; border:none;" onclick="ToggleOfferPopup();" alt="VERY SPECIAL OFFER CLICK HERE - $500 INSTANT SAVINGS - VERY SPECIAL OFFER CLICK HERE" src="http://www.dilawriautoweb.com/myusedcarsca/Images/MyUsedCarsCASpecialOffer.png"/></div>');

    //inject offer
    if (typeof PopDealerID == "undefined") {

        var ttl1 = 'SAVE $500 ON ANY DILAWRI VEHICLE!';
        var txt1 = 'Get an extra $500 off the price of any new or used vehicle at any of our stores with this coupon!';

        var oframeHTML = '<iframe id="ofrmPopupOffer" frameborder="0" scrolling="no" style="width: 665px; height: 385px; margin: 5px 0px 0px 0px; padding: 0px;" src="http://www.myusedcarsottawa.com/LandingPageCoupon.aspx?DealerID=' + 0 + '&title=' + encodeURIComponent(ttl1) + '&text=' + encodeURIComponent(txt1) + '"></iframe>';
        var oCloseButtonHTML = '<input type="button" id="obtnCloseOffer" value="X Close Offer" onclick="oToggleOfferPopup();" style="position:absolute; cursor:pointer; right:0px; top:0px; color:gray; border:2px solid gray; background-color:white;" /><br>'
        $('body').append('<div id="odvPopupOffer" style="width: 665px; margin: 0px; padding: 0px; position:absolute; top:25px; display:none; z-index:1000;">' + oCloseButtonHTML + oframeHTML + '</div>');


    }




});

function oToggleOfferPopup() {

    $('#odvPopupOffer').slideToggle();

}
