﻿// JScript 文件

//初始化AJAX引擎
var XMLHTTP;
var XmlHttp2;
var moneyChar="$";
var CurrentSelect;
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;}}}}}
}

function GoldServerChange()
{
    var scode = document.getElementById("dlistServerSelect").value;
    var pro = document.getElementById("dlistGoldSelect");
    var lbprice =  document.getElementById("lblPrice");
    var lblEURPrice=document.getElementById("lblEURPrice");
    var lblGBPPrice=document.getElementById("lblGBPPrice");
    pro.length = 0;
    pro.options.add(new Option("Loading...","0"));
    lbprice.value="Loading...";
    lblEURPrice.value="Loading...";
    lblGBPPrice.value="Loading..."
    XMLHTTP = createXMLHttpRequest();
    if(XMLHTTP == null){
    alert("Sorry, Your browser can't support XMLHTTP, Please update!");
    return;}

    XMLHTTP.onreadystatechange= ServerChangeBack;
    XMLHTTP.open("GET","GoldDataDispose.aspx?CMD=PRODUCTS&SERVERCODE="+scode+"&datetime="+new Date().toLocaleTimeString(),true);
    XMLHTTP.send(null);
}

function ServerChangeBack()
{
    if(XMLHTTP.readyState!=4)
        return;
    var text=XMLHTTP.responseText;
    //alert(text);
    var pro = document.getElementById("dlistGoldSelect");
    pro.length=0;
    var lbprice =  document.getElementById("lblPrice");
    
    var datas = text.split("|");
    for(var i=0;i<datas.length;i++){
        var temp = datas[i].split("^");
        pro.options.add(new Option(temp[0],temp[1]+"|"+temp[2]));
    }
   
    
   var strTable="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table_gold_list\"><tr>";
    strTable+="<th>NAME</th><th>TOTAL</th></tr>";
    for(var i=0;i<datas.length;i++)
    {
        var temp = datas[i].split("^")
        if(temp[0]=="")
        continue;
        if(i%2==1)
        {
            if(moneyChar=="$")
            {
                strTable+="<tr><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[0]+"</td></tr>";
            }
            else if(moneyChar=="€")
            {
                strTable+="<tr><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[1]+"</td></tr>";
            }
            else if(moneyChar=="￡")
            {
                strTable+="<tr><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[2]+"</td></tr>";
            }
            
        }
        else
        {
            if(moneyChar=="$")
            {
                strTable+="<tr onmouseover=\"javascript:this.bgColor='#DEFFA9'\" onmouseout=\"javascript:this.bgColor='#FoF6F9'\"><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[0]+"</td></tr>";
            }
            else if(moneyChar=="€")
            {
                strTable+="<tr onmouseover=\"javascript:this.bgColor='#DEFFA9'\" onmouseout=\"javascript:this.bgColor='#FoF6F9'\"><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[1]+"</td></tr>";
            }
            else if(moneyChar=="￡")
            {
                strTable+="<tr onmouseover=\"javascript:this.bgColor='#DEFFA9'\" onmouseout=\"javascript:this.bgColor='#FoF6F9'\"><td>"+temp[0]+"</td><td>"+moneyChar+temp[1].split(":")[2]+"</td></tr>";
            }
            
        }
        
    } 
   strTable+="</table>"; 
   
    /*
    var strTable = "<table border=\"0\" width=\"10px;\" cellpadding=\"0\" cellspacing=\"0\" class=\"VolumeDiscountbig\"><tr>"; 
    //strTable += "<td>";
    
    for(var i=0;i<datas.length;i++)
    {
        var temp = datas[i].split("^");
        if(temp[0]=="")
            continue;
        strTable += "<td><table  class=\"VolumeDiscount\" style='width:100%;'><th style='height:30px;'>"+temp[0]+"</th><tr style='height:20px;'><td>"+moneyChar+temp[1]+"</td></tr></table></td>";
        if(i!=0&&(i+1)%1==0)
        {
            strTable+="</tr><tr>";
        }
    }
    strTable += "</tr></table>"; 
   */
    document.getElementById("lblpricetable").innerHTML = strTable==""?"0.000":strTable;
    //alert(text); 10000 Gold^21.59^fdsafsasdf-fdsfds-df-dsf|
    
    if(CurrentSelect!="")
    {
        var pp =document.getElementById("dlistGoldSelect");
        for(var i=0;i<pp.length;i++){
            if(i==CurrentSelect){
                pp[i].selected=true;
            }
        }
    }
    
    ProductChange();
}

function ProductChange()
{
    var pro = document.getElementById("dlistGoldSelect").value;
    //alert(pro);
    if(pro!="0"&&pro!=""){
        var infos = pro.split("|");
        document.getElementById("lblPrice").value="$"+infos[0].split(":")[0]+"  ";
        document.getElementById("lblEURPrice").value= "€"+infos[0].split(":")[1]+"  ";
        document.getElementById("lblGBPPrice").value= "￡"+infos[0].split(":")[2]+"  ";
    }else{
        document.getElementById("lblPrice").value="0.000";
    }
}

//function gettype(moneyChar)
//{
//    var j=0;
//    if(moneyChar=="$")
//    j=0;
//    else if(moneyChar=="€")
//    j=1;
//    else if(moneyChar=="￡")
//    j=2;
//}

function changeMoney(moy)
{

    if(moy=="")
    {
        moneyChar="$";
        document.getElementById("lblPrice").style.color="red";
        document.getElementById("lblEURPrice").style.color="black";
        document.getElementById("lblGBPPrice").style.color="black";
    }
    var pp =document.getElementById("dlistGoldSelect");
    for(var i=0;i<pp.length;i++){
        if(pp[i].selected==true)
        {
            CurrentSelect=i;
        }
                                }
    
                //IList<global::Model.ViewSalePriceAndProduct> productusd = WebCommon.DataSource.GetGoldSaleProductList(servercode, "USD");
                //IList<global::Model.ViewSalePriceAndProduct> producteur = WebCommon.DataSource.GetGoldSaleProductList(servercode, "EUR");
                //IList<global::Model.ViewSalePriceAndProduct> productgbp = WebCommon.DataSource.GetGoldSaleProductList(servercode, "GBP");
        
    if(moy=="USD")
    {
        moneyChar="$";
        document.getElementById("lblPrice").style.color="red";
        document.getElementById("lblEURPrice").style.color="black";
        document.getElementById("lblGBPPrice").style.color="black";
    }   
    else if(moy=="EUR")
    {
        moneyChar="€";
        document.getElementById("lblPrice").style.color="black";
        document.getElementById("lblEURPrice").style.color="red";
        document.getElementById("lblGBPPrice").style.color="black";
    }
    else if(moy=="GBP")
    {
        moneyChar="￡";
        document.getElementById("lblPrice").style.color="black";
        document.getElementById("lblEURPrice").style.color="black";
        document.getElementById("lblGBPPrice").style.color="red";
        
    }
       
        
        
        
    $.get("changemoney.aspx",{type:moy,TIME:new Date().toLocaleTimeString()},GoldServerChange);
//    //alert(moneyChar);
//    XmlHttp2 = createXMLHttpRequest();
//    if(XmlHttp2 == null){
//    alert("Sorry, Your browser can't support XMLHTTP, Please update!");
//    return;}
//    
//    XmlHttp2.onreadystatechange=changeBack;
//    XmlHttp2.open("GET","changemoney.aspx?type="+moy,true);
//    XmlHttp2.send(null);
}

function changeBack()
{
    if(XmlHttp2.readyState!=4)
        return;
    var data = XmlHttp2.responseText;
    alert(data);
    GoldServerChange();
}
 



