
/**********************************************/

function is_d2pass_bar(){
    return (getCookie('NetiA') && (((getCookie('NetiA')).split(":"))[0]).match(/@/)) ? 1 : 0;
}

var baseBX = 360;
//var baseBY = is_d2pass_bar() ? 721 : 698;
var baseBY = is_d2pass_bar() ? 806 : 798;

var baseCX = 338;
//var baseCY = is_d2pass_bar() ? 522 : 500;
var baseCY = is_d2pass_bar() ? 600 : 589;

var diffBX = 80;
var diffBY = 80;

var diffCY = 60;
var diffCX = 65;

var currCX;
var currBX;

numbers = new Array(10);
/**********************************************/

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function $(v)      { return(document.getElementById(v)); }
function agent(v)  { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v)   { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }
function parsePx(s){ return parseInt(s.substring(0, s.length - 2)); }
function screen(v) { return (v?(agent('msie')?document.body.offsetWidth:window.innerWidth):(agent('msie')?document.body.offsetHeight:window.innerHeight)); }
function sX(base)  { return (screen(1) <= 1000) ? parseInt(base) : parseInt((screen(1) - 1000) * 0.49 + parseInt(base) - parseInt((agent('msie'))?0:8)); } // y = 0.49x + base

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function dragObj(n, d, e){

	for(i=1; i<=10; i++){ if(numbers[i-1] == n){ numbers[i-1] = null; break; } }

        var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop,t,l,bY,bX; 

        document.onmousemove = function(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } }
        document.onmouseup   = function(e) {

            stop = 1; document.onmousemove = ''; document.onmouseup   = ''; t = parsePx(d.style.top); l = parsePx(d.style.left);            

            for(i=1; i<=10; i++){

                bY = parsePx($("b"+i).style.top)+10; bX = parsePx($("b"+i).style.left)+10;

                if(bY+50 > t && t > bY-50 && bX+50 > l && l > bX-50 && numbers[i-1] == null){                 
                    d.style.top = bY  + "px";
                    d.style.left = bX + "px";
                    numbers[i-1] = n;
                    return;
                }  
            }       

        }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function game2007_init(){

  currCX = sX(baseCX); currBX = sX(baseBX);

  for(i=1; i<=10; i++){
        t = parseInt(baseBY)+(parseInt((i-1)/5) * diffBY);
        l = sX(baseBX) + (((i-1)%5) * diffBX);
        document.write("<div id=\"b" + i + "\" style=\"position: absolute; top: "+t+"px; left: "+l+"px;\"><img src=\" ./images/boxes" + i + ".gif\"></div>");
  }

  for(i=1; i<=21; i++){
     t = parseInt(parseInt(baseCY)+(parseInt((i-1)/7) * diffCY));
     l = sX(baseCX) + (((i-1)%7) * diffCX);  

     document.write("<div id=\"c" + i + "\" style=\"cursor:pointer; position: absolute; top: "+t+"px; left: "+l+"px; background-image: URL(./images/"+i+".gif);height:50px;width:50px\" onmousedown = \"javascript:dragObj("+i+",this, event) \"></div>");
  }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onResize(){
    
    for(i=1; i<=10; i++){ $("b"+i).style.left = parseInt(parsePx($("b"+i).style.left) + (sX(baseBX) - currBX)) + "px"; }
    for(i=1; i<=21; i++){ $("c"+i).style.left = parseInt(parsePx($("c"+i).style.left) + (sX(baseCX) - currCX)) + "px"; }

    currCX = sX(baseCX); currBX = sX(baseBX);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var strPath;
var strQueryString;

function game2007_httpPost(callback) {
    //httpReady = 0;

    var strURI = strPath + strQueryString, xmlHttpReq = false, self = this;

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', strURI, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            //alert(self.xmlHttpReq.responseText);
            //httpReady = 1;
            return callback(self.xmlHttpReq.responseText);

        }
    }
    self.xmlHttpReq.send(strURI);


}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function game2007_response(response){
   r = response.split("#");   
   if(parseInt(r[0]) == 1){
        location.href  = r[1];
        //alert("ATARI");
   }else{
        alert("¥Ï¥º¥ì");
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function game2007_check(){
    strPath = "./game2007_check.php";
    strQueryString = "?";
    for(i=0; i<10; i++)
       strQueryString += "n" + i + "=" + ((numbers[i]) ? numbers[i] : "") + "&";

    //alert(strQueryString);
    game2007_httpPost(game2007_response);
}




