﻿
$(function() {
    var tempalteID = 0;
    var width;
    var height;
    var left;
    var top;
    var midtop;
    var midleft;
    var winheight;
    var winwidth;
    var isOpen = false;
    var isThanksOpen = false;

    $(".link_shareTips").click(function() {
        $('.pop_terms').hide();
        $('.pop_thanks').hide();
        $('.pop_agreeChk').hide();
        width = 624;
        height = 745;
        $(".pop_box").animate({ "opacity": 0 }, 1);
        left = parseInt(Math.ceil($("body").width()) / 2 - (parseInt(width) / 2));
        //top = (document.body.clientHeight-height)/2;
        top=(window.screen.height-height)/2;

        winheight = parseInt($(document).height());
        midleft = parseInt(document.body.clientWidth) / 2;
        midtop = parseInt($.pageHeight() / 2) + $(document).scrollTop();
        winwidth = parseInt($("body").width());
        $(".pop_box").attr("style", "height:" + winheight + "px;width:" + winwidth + "px");
        $(".pop_box").animate({ "opacity": 0.5 }, 50);
        $(".pop_cont").attr("style", "top:" + midtop + "px;width:1px;height:1px;left:" + midleft + "px");
        $(".pop_cont").animate({ "width": width, "height": height, "left": left, "top": top, "opacity": 1 }, 500);
        $('.pop_shareTips').show();
        isOpen = true;
        if ($.browser.msie && $.browser.version < 7){
        $('.weekSelect').css('display','none');
        $('.selectBak').css('display','block');
        }
    });

    $(".link_terms").click(function() {
        $('.pop_shareTips').hide();
        $('.pop_thanks').hide();
        $('.pop_agreeChk').hide();
        width = 610;
        height = 652;
        $(".pop_box").animate({ "opacity": 0 }, 1);
        left = parseInt(Math.ceil($("body").width()) / 2 - (parseInt(width) / 2));
        // top = (document.body.clientHeight-height)/2;
        top=(window.screen.height-height)/2;
        winheight = parseInt($(document).height());
        midleft = parseInt(document.body.clientWidth) / 2;
        midtop = parseInt($.pageHeight() / 2) + $(document).scrollTop();
        winwidth = parseInt($("body").width());
        $(".pop_box").attr("style", "height:" + winheight + "px;width:" + winwidth + "px");
        $(".pop_box").animate({ "opacity": 0.5 }, 50);
        $(".pop_cont").attr("style", "top:" + midtop + "px;width:1px;height:1px;left:" + midleft + "px");
        $(".pop_cont").animate({ "width": width, "height": height, "left": left, "top": top, "opacity": 1 }, 500);
        $('.pop_terms').show();
        isOpen = true;
        if ($.browser.msie && $.browser.version < 7){
        $('.weekSelect').css('display','none');
        $('.selectBak').css('display','block');
        }
    });
    
    $(".link_thanks").click(function() {
        $('.pop_shareTips').hide();
        $('.pop_terms').hide();
        $('.pop_agreeChk').hide();
        width = 610;
        height = 130;
        $(".pop_box").animate({ "opacity": 0 }, 1);
        left = parseInt(Math.ceil($("body").width()) / 2 - (parseInt(width) / 2));
        // top = (document.body.clientHeight-height)/2;
        top = parseInt(($.pageHeight() - height)/2) + $(document).scrollTop();
        winheight = parseInt($(document).height());
        midleft = parseInt(document.body.clientWidth) / 2;
        midtop = parseInt($.pageHeight() / 2) + $(document).scrollTop();
        winwidth = parseInt($("body").width());
        $(".pop_box").attr("style", "height:" + winheight + "px;width:" + winwidth + "px");
        $(".pop_box").animate({ "opacity": 0.5 }, 50);
        $(".pop_cont").attr("style", "top:" + midtop + "px;width:1px;height:1px;left:" + midleft + "px");
        $("#div_thanks").html('<iframe src="Thanks.html" frameborder="0" scrolling="no" width="1" height="1"></iframe>');
        $(".pop_cont").animate({ "width": width, "height": height, "opacity": 1, "left": left, "top": top }, 600, "linear", function(){
            $("#div_thanks iframe").attr("style","width:"+width+"px;height:"+height+"px;");
        });
        $('.pop_thanks').show();
        isOpen = true;
        isThanksOpen = true;
        if ($.browser.msie && $.browser.version < 7){
        $('.weekSelect').css('display','none');
        $('.selectBak').css('display','block');
        }
    });
    
    $(".link_agreeChk").click(function() {
        $('.pop_shareTips').hide();
        $('.pop_terms').hide();
        $('.pop_thanks').hide();
        width = 610;
        height = 95;
        $(".pop_box").animate({ "opacity": 0 }, 1);
        left = parseInt(Math.ceil($("body").width()) / 2 - (parseInt(width) / 2));
        // top = (document.body.clientHeight-height)/2;
        top = parseInt(($.pageHeight() - height)/2) + $(document).scrollTop();
        winheight = parseInt($(document).height());
        midleft = parseInt(document.body.clientWidth / 2);
        midtop = parseInt($.pageHeight() / 2 + $(document).scrollTop());
        winwidth = parseInt($("body").width());
        $(".pop_box").attr("style", "height:" + winheight + "px;width:" + winwidth + "px");
        $(".pop_box").animate({ "opacity": 0.5 }, 50);
        $(".pop_cont").attr("style", "top:" + midtop + "px;width:1px;height:1px;left:" + midleft + "px");
        $("#div_agreeChk").html('<iframe src="Agreement.html" frameborder="0" scrolling="no" width="1" height="1"></iframe>');
        $(".pop_cont").animate({ "width": width, "height": height, "opacity": 1, "left": left, "top": top }, 600, "linear", function(){
            $("#div_agreeChk iframe").attr("style","width:"+width+"px;height:"+height+"px;");
        });
        $('.pop_agreeChk').show();
        isOpen = true;
        if ($.browser.msie && $.browser.version < 7){
        $('.weekSelect').css('display','none');
        $('.selectBak').css('display','block');
        }
    });
        
    $(".closebox img").css("cursor", "pointer");
    $(".closebox img").click(function() {
        // if this is thans page,then fresh page
        if (isThanksOpen == true) {
            window.location.href = 'SubmitYourPhotos.aspx?state=64';
        }
        $(".pop_box").animate({ "opacity": 0 }, 500);
        $(".pop_cont").animate({ "opacity": 0 }, 500, function() {
            $(".pop_cont").hide();
            $(".pop_box").hide();
        });
        isThanksOpen = false;
        isOpen = false;
        if ($.browser.msie && $.browser.version < 7){
            setTimeout(revertSelect,500);
        }
    });
    checkComplete();
});

function revertSelect()
{
    $('.weekSelect').css('display','block');
    $('.selectBak').css('display','none');
}

$.pageWidth = function()
{
    return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

$.pageHeight = function()
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

// check finish and pop window
function checkComplete() {
    var closeLink = document.getElementById("ctl00_ContentPlaceHolder1_close");
    if (closeLink != null) {
        closeLink.click();
    }
}
