﻿// JScript 文件

//判断浏览器是否是IE
function isIE(){ 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1)     
    return true;     
   else     
    return false;     
}    

function createXMLHttpRequest(){
	            if(window.XMLHttpRequest) return new XMLHttpRequest();
	            try{return new ActiveXObject('MSXML2.XMLHTTP.4.0');}
	            catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP.3.0');}
	            catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP.2.6');}
	            catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP');}
	            catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP');}
	            catch(e){return null;}}}}}
} 

var XHLHTTP1;
var XHLHTTP2;
function GetAllGoldPrice(code,currtype)
{
testMessageBox(); 
               var d=new Date();
                XHLHTTP1 = createXMLHttpRequest();
                if(XHLHTTP1 == null){
                alert("Sorry, Your browser can't support XMLHTTP, Please update!");
                return;}
	            XHLHTTP1.onreadystatechange= DisplayGoldTable;
	            XHLHTTP1.open("GET","GetGoldInfo.aspx?code="+code+"&ct="+currtype+"&datetime="+d,true);
	            XHLHTTP1.send(null);
}

//获取一种金币的三种价格
function GetOneGolePrice(code,currtype,goldAmount)
{
testMessageBox();
               var d=new Date();
                XHLHTTP2 = createXMLHttpRequest();
                if(XHLHTTP2 == null){
                alert("Sorry, Your browser can't support XMLHTTP, Please update!");
                return;}
	            XHLHTTP2.onreadystatechange= DisplayGoldPrice;
	            XHLHTTP2.open("GET","getPriceList.aspx?code="+code+"&ct="+currtype+"&ga="+goldAmount+"&datetime="+d,true);
	            XHLHTTP2.send(null);
}

//显示三种货币的价格
function DisplayGoldPrice(){
                var  strTable;
                if(XHLHTTP2.readyState!=4){     
                     return;
                }
                var text=XHLHTTP2.responseText;
                var odiv= document.getElementById("priceList");
               if(odiv){odiv.innerHTML=text;}else{odiv.innerHTML="";}
               closeWindow();
}

//显示服务器下的所有金币列表
function DisplayGoldTable()
{
                if(XHLHTTP1.readyState!=4){                
                     return;
                }
                var text=XHLHTTP1.responseText;
               document.getElementById("divsaleprice").innerHTML = text;
               closeWindow();
}


//验证打折券
var xmlHTTP;
function GoToCheckCoupon(coupon){
     var d=new Date();
                xmlHTTP = createXMLHttpRequest();
                if(xmlHTTP == null){
                alert("Sorry, Your browser can't support XMLHTTP, Please update!");
                return;}
	            xmlHTTP.onreadystatechange= ShowCheckResult;
	            xmlHTTP.open("GET","CheckCoupon.aspx?code="+coupon+"&datetime="+d,true);
	            xmlHTTP.send(null);
}
function ShowCheckResult(){
     if(xmlHTTP.readyState!=4){
                     return;
                }
                var text=xmlHTTP.responseText;
               if(text=="0"){
                    alert("Coupon Code is valid");
                    return false;
               }else{
                    alert("Coupon Code is invalid,please try again!");
                    return false;
               }
}

/* 弹出层JS */
var isIe;

//弹出方法
function showMessageBox()
{
isIe=isIE();
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);

var back=document.createElement("div");
back.id="back";
back.innerHTML="<center><div class=\"test\"><img src=\"images/load.gif\" />Loading......</div></center>";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;padding-top:300px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
back.style.cssText=styleStr;
document.body.appendChild(back);
showBackground(back,50);
}
//让背景渐渐变暗
function showBackground(obj,endInt)
{
if(isIe)
{
obj.filters.alpha.opacity+=10;
if(obj.filters.alpha.opacity<endInt)
{
setTimeout(function(){showBackground(obj,endInt)},5);
}
}else{
var al=parseFloat(obj.style.opacity);al+=0.10;
obj.style.opacity=al;
if(al<(endInt/100))
{setTimeout(function(){showBackground(obj,endInt)},5);}
}
}
//关闭窗口
function closeWindow()
{
if(document.getElementById('back')!=null)
{
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null)
{
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
isIe=isIE();
}
//测试弹出
function testMessageBox()
{
showMessageBox();
}
