﻿// JavaScript Document
var gamelink = "";
var imglink = "";
//read xml file 

function loadXML(filename, gamename) {
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", filename, false);
    xmlhttp.send();
    xmlDoc = xmlhttp.responseXML;

    var root = xmlDoc.getElementsByTagName("pop_up");
    var i;
    for (i = 0; i < root.length; i++) {
        if (root[i].getElementsByTagName("Web_Name")[0].childNodes[0].nodeValue == gamename) {
            gamelink = root[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
            imglink = root[i].getElementsByTagName("images_link")[0].childNodes[0].nodeValue;
        }
    }
}

function GetInfo(gamename) {
    gamelink = "http://tt.playpark.vn/";
    imglink = "http://picture.playpark.vn/tt/images/CS_popup_alphatest.png";
}

function showpopup(gamename) {
    GetInfo(gamename);
    ShowDiv(imglink, gamelink);
    //var t=setTimeout("closepopup()",10000);//close popup sau 10 giây
    //document.getElementById("mylayer").style.display = "none";
}
function closepopup() {
    document.getElementById("popupas").innerHTML = "";
    document.getElementById("popupas").style.display = "none";
    // document.getElementById("mylayer").style.display = "none";
}

function ShowDiv(linkimg, linkgame) {
    document.write('<div id="popupas" align="center" style="width:250px; height:250px; position:absolute; display:block; z-index:3000">');
    document.write('<a href="' + linkgame + '" target="_blank"><img src="' + linkimg + '" width="250" height="250" border="0" usemap="#Mapas"></a>');
    document.write('<map name="Mapas" id="Mapas">');
    document.write('<area shape="rect" coords="219,2,249,26" href="#" onclick="closepopup()">');
    document.write('<area shape="rect" coords="13,27,238,244" href="' + linkgame + '" target="_blank">');
    document.write('</map>');
    document.write('</div>');
    showdeadrightdiv(250, 250, "popupas");
}

function showBox()// làm mờ màn hình
{
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight + document.documentElement.scrollTop;
    //  var layer = document.getElementById('mylayer');
    // layer.style.position = 'fixed';	
    // layer.style.top = '0px';
    //  layer.style.left = '0px';
    //  layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.height = height + 'px';
    layer.style.zIndex = 3000;
    layer.style.backgroundColor = '#000000';
    layer.style.opacity = '.9';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=90)");
    //  document.body.appendChild(layer);
}
function showdeadcenterdiv(Xwidth, Yheight, divid)// show div nằm chính giửa
{
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var o = document.getElementById(divid);
    var r = o.style;
    r.position = 'absolute';
    r.top = topOffset + 100 + 'px';
    r.left = leftOffset + 'px';
    r.zIndex = 3000;
    r.display = "block";
}

function showdeadrightdiv(Xwidth, Yheight, divid)//show div nằm ở dưới góc phải
{
    // First, determine how much the visitor has scrolled
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:

    // Thao 20100612
    //  var leftOffset = scrolledX + (centerX - Xwidth);
    //  topOffset = scrolledY + (centerY - Yheight);

    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;

    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var o = document.getElementById(divid);
    var r = o.style;

    r.top = topOffset + 10 + 'px';
    r.left = leftOffset + 'px';

    r.position = 'absolute';
    r.zIndex = 3000;
    r.display = "block";
} 
