var timeId = 0;
var timeOut = 2000;
var tempX = 0;
var tempY = 0;
//document.onmousemove = getMouseXY;
document.onmousedown = getMouseXY;

function showDialog(){
	setTimeout("show()", 0);
	setTimeout("clear()", timeOut);
}

function clear() {
	document.getElementById('layer').style.visibility = 'hidden';
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

function show(e){
	//alert(e.clientX);
	var layerObj = document.getElementById("layer");
  
	layerObj.style.left=tempX + 30;
	layerObj.style.top=tempY;
	//layerObj.innerHTML = "<br>?à¸¸à¸“?à¸”?à¸«à¸¢à¸´?à¸ªà¸´???à¸²?à¸ª?à¸•à¸°?à¸£?à¸²?à¸¥?à¸§";
	//layerObj.innerHTML += "<br>";

        layerObj.innerHTML = "<img src='/images/FINISH.JPG'>";
	layerObj.style.visibility="";
	return true;
	//"position:absolute; left:0px; top:0px; width:200px; height:40px; z-index:1; background-color: #FFFFCC; layer-background-color: #FFFFCC; border: 1px none #000000; visibility: hidden;"
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
    //tempX = event.clientX + document.documentElement.scrollLeft //pls include DOCTYPE
    //tempY = event.clientY + document.documentElement.scrollTop //pls include DOCTYPE
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}

  var req;
  var which;

  function retrieveURL(url) {
    if (window.XMLHttpRequest) { // Non-IE browsers
      req = new XMLHttpRequest();
      req.onreadystatechange = processStateChange;
      try {
        req.open("GET", url, true);
      } catch (e) {
        alert(e);
      }
      req.send(null);
    } else if (window.ActiveXObject) { // IE
      req = new ActiveXObject("Microsoft.XMLHTTP");
		  if (req) {
			req.onreadystatechange = processStateChange;
			req.open("GET", url, true);
			req.send(false);
		}
    }
  }

  function processStateChange() {
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response
        //window.location.reload();
	//alert("You have " + req.responseText + " product(s) in your shopping cart." );
	var strResponseText = req.responseText;
        var intIndex = strResponseText.indexOf(",");

        var strTotalProduct = strResponseText.substring(0, intIndex);
        var strTotalPrice = strResponseText.substring(intIndex + 1, strResponseText.lastIndexOf(","));
        var strTotalProductReservation = strResponseText.substring(strResponseText.lastIndexOf(",") + 1, strResponseText.length);

        if(document.getElementById('totalProduct') != null){
            document.getElementById('totalProduct').innerHTML = strTotalProduct;
        }

        if(document.getElementById('totalPrice') != null){
            document.getElementById('totalPrice').innerHTML = strTotalPrice;
        }

        if(document.getElementById('totalProductReservation') != null){
            document.getElementById('totalProductReservation').innerHTML = strTotalProductReservation;
        }

	showDialog();

      } else {
        alert("Status: " + req.status + ", Problem: " + req.statusText);
      }
    }
  }

function addToCart(id) {
    var selectName = "specific_" + id;
    var selectObj = document.getElementsByName(selectName)[0];

    if(selectObj != null){
        var selectValue = selectObj[selectObj.selectedIndex].value;

        if(selectValue != '-2') {
            retrieveURL('/AddCart?id='+id+'&specificid=' + selectValue + '&method=callback');
        } else {
            alert("¡ÃØ³ÒàÅ×Í¡»ÃÐàÀ·ÊÔ¹¤éÒ");
        }
    }else{
        retrieveURL('/AddCart?id='+id+'&method=callback');
    }

}

function displayCartType(cartType) {
    if(1 == cartType) {
        //document.write("<img src='/images/bottom_pay.gif' border='0'>");

    } else {
        //document.write("<img src='/images/bottom_reserv.gif' border='0'>");
    }
}
