﻿if( typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat'){
    if (navigator.appVersion.match(/MSIE [0-6]\./)) {
        document.writeln('<div  style="display: none;z-index:99999999;right:0;bottom:0; height:159px;width:260px;overflow:hidden;position:absolute; margin-top:expression(document.documentElement.clientHeight-this.style.pixelHeight+document.documentElement.scrollTop);" id="PcPoPmarket" >');
    }else{
        document.writeln('<div  style="display: none;z-index:99999999;right:0;bottom:0;overflow:hidden;POSITION:fixed; height:159px;width:260px;" id="PcPoPmarket" >');
    }
}else {
    if (navigator.appVersion.match(/MSIE [0-7]\./)) {
        document.writeln('<div  style="display: none;z-index:99999999;right:0;bottom:0; height:159px;width:260px;overflow:hidden;position:absolute; top:expression(eval(document.body.scrollTop)+eval(document.body.clientHeight)-this.style.pixelHeight);" id="PcPoPmarket" >');
    }
    else {
        document.writeln('<div  style="display: none;z-index:99999999;right:0;bottom:0;overflow:hidden;POSITION:fixed; height:159px;width:260px;" id="PcPoPmarket" >');
    }
}

document.writeln('</div>');


var intervalId = null;
function slideAd(id, nStayTime, sState, nMaxHth, nMinHth) {
    this.stayTime = nStayTime * 1000 || 3000;
    this.maxHeigth = nMaxHth || 567;
    this.minHeigth = nMinHth || 2.5;
    this.state = sState || "down";
    var obj = document.getElementById(id);
    if (intervalId != null) window.clearInterval(intervalId);
    function openBox() {
        obj.style.display = "block";
        var h = obj.offsetHeight;
        obj.style.height = ((this.state == "down") ? (h + 6) : (h - 6)) + "px";
        if (obj.offsetHeight > this.maxHeigth) {
            window.clearInterval(intervalId);
            intervalId = window.setInterval(closeBox, this.stayTime);
        }
        if (obj.offsetHeight < this.minHeigth) {
            window.clearInterval(intervalId);
            obj.style.height = 60;
            document.getElementById("CouponImg").style.display = "none";
            document.getElementById("CouponImgIndex").style.display = "block";
        }
    }
    function closeBox() {
        slideAd(id, this.stayTime, "up", nMaxHth, nMinHth);
    }
    intervalId = window.setInterval(openBox, 1);
} 


var IsShowNote = false;
$(document).ready(function() {
    if ($("#ShowIndexNoteContent").html() != "") {
        $("#PcPoPmarket").html($("#ShowIndexNoteContent").html())
        if ($("#PcPoPmarket") && IsShowNote == false) {
            IsShowNote = true;
            $("#PcPoPmarket").fadeIn("fast");
        }
    }
    if (document.getElementById("MyMoveAd")) {
        var img = new SImage(icall);
        img.get("/Images/coupon_index.png");
    }
    $("a.group").fancybox({
    'hideOnContentClick': false,
        'frameWidth':680,
		'frameHeight':370
    });
});

function SImage(callback) {
    var img = document.getElementById("CouponImg");
    this.img = img;
    var appname = navigator.appName.toLowerCase();
    if (appname.indexOf("netscape") == -1) {
        //ie
        img.onreadystatechange = function() {
            if (img.readyState == "complete") {
                callback(img);
            }
        };
    } else {
        //firefox
        img.onload = function() {
            if (img.complete == true) {
                callback(img);
            }
        }
    }
}

SImage.prototype.get = function(url) {
    this.img.src = url;
}



function icall(obj) {
    slideAd('MyMoveAd', 10);
}


function ShowNoteDiv(){
    document.getElementById("PcPoPmarket").style.height = 159+'px';
    document.getElementById("showvod").style.display = 'none';
    document.getElementById("hidevod").style.display = 'block'
}

function HideNoteDiv(){
    document.getElementById("PcPoPmarket").style.height = 29 + 'px';
    document.getElementById("hidevod").style.display = 'none';
    document.getElementById("showvod").style.display = 'block';
}

function CloseNoteDiv(){
    $("#PcPoPmarket").fadeOut("fast");
}

function SignInSubmit(){
    if($("#txtEmail").val() == ""){
        alert("Email is empty!");
        $("#txtEmail").focus();
        return;
    }
    if(!EmailValider($("#txtEmail").val()))
    {
        alert("Please enter a valid email.");
        $("#txtEmail").focus();
        return;
    }
    if($("#txtpwd").val() == ""){
        alert("Password is empty!");
        $("#txtpwd").focus();
        return;
    }
    ShowBackground();
    $.ajax({
        url: $("#HomeLink").val() + '/Ajax/ProcessIndexLogin.ashx',
        type: 'GET',
        dataType: 'xml',
        data: {Password:$("#txtpwd").val(),Email:$("#txtEmail").val(),time: (new Date()).getTime()},
        error: function(){
            location.href = $("#HomeLink").val() + "/Error/GenericErrorpage.aspx";
        },
        complete: function(){
           RemoveBackground();
        },
        success: function(data){
            if($(data).find("IsLogin").attr("value")){
                if($(data).find("IsLogin").attr("value") == "true"){
                    $("#CustomerLogin").html("Welcome! <span style=\"color:#E3D11E;\">" + $(data).find("Email").attr("value") + "</span>, <a href=\"javascript:void(null);\" onclick=\"javascript:SignOut();\" style=\"text-decoration:none;\">Sign Out!</a>");
                    $("#txtpwd").val("");
                    $("#txtEmail").val("");
                }else if($(data).find("IsLogin").attr("value") == "false"){      
                    alert("Login failed.Please check your email and password and try again.");
                }
            }else{
                location.href = $("#HomeLink").val() + "/Error/GenericErrorpage.aspx";
            }
        }
    });
}