﻿


    var res = "";
    if (window.XMLHttpRequest) 
        { // Mozilla, Safari,...
            XmlHttp = new XMLHttpRequest();
        } 
     else if (window.ActiveXObject) 
     { // IE
        try     
        {
          // new version IE
          XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                // old version IE
                XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
    }    

	function ServerProcess()
	{
	    res = "";
		if (XmlHttp.readyState==4 || XmlHttp.readyState=='complete')
		{	
		    //alert("ServerProcess.res="+res);
		    //alert("ServerProcess.XmlHttp.responseText="+XmlHttp.responseText);
		    res = XmlHttp.responseText;   
		}
	}	

	function sendAJAX(id)
	{
		XmlHttp.open("GET","ajx_GetInfo.aspx?id="+id,false);
		
		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function sendAJAXForCheck(domain)
	{
	    XmlHttp.open("GET",domain + "/services/pc/pages/login/checklogin.aspx?r=" +  Math.random(),false);
		
		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function GetPoint(domain)
	{
	    sendAJAXForCheck(domain);
	    alert(res);
	    if(res == "logined=N")
	    {
	        window.location.replace("../common/ico_login_prize.aspx");
	    }
	    else
	    {
	        window.location.href = "ico_LDinfo_prize.aspx?id=" + document.getElementById("txtID").value;
	    }	    
	}
	
    function SendAjaxE(pid)
	{
	    XmlHttp.open("GET","../common/ajx_get_partner.aspx?id="+pid,false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function SendAjaxB(domain, r)
	{
	    XmlHttp.open("GET",domain + "/services/pc/pages/login/checklogin.aspx?r="+r,false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function SendAjaxD()
	{
	    XmlHttp.open("GET","../redeem/ajx_get_point.aspx",false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
   function GetInfo(id, picroot)
   {
        var p1 = document.getElementById("p1");
        var p2 = document.getElementById("p2");
        var txtID = document.getElementById("txtID");
        //alert(txtID.value)
        if(txtID.value != "")
        {
            txtID.value = "";
        }
        txtID.value = id;
        //alert(txtID.value);
        var arr = new Array();
        sendAJAX(id);        
        if(res != "")
        {
            arr = res.split("|"); 
        }        
        
        var img = document.getElementById("imgDetail");
        img.src = picroot + arr[4];
        var name = document.getElementById("lblName");        
        var point = document.getElementById("lblPoint");        
        //var ldp = document.getElementById("lblLDP");        
        var number = document.getElementById("lblNumber");        
        var des = document.getElementById("lblDescription");
        
        //var imgdis = document.getElementById("imgDisplay");
        
        p1.value = arr[16];
        p2.value = arr[17];
        
        var uxbtn;
        if(document.getElementById("uxButton") != null)
        {
            uxbtn = document.getElementById("uxButton");
        }
        res = "";
        SendAjaxE(arr[13]);
        var arry = new Array();
        if(res != "")
        {
            arry = res.split('|');
            uxbtn.style.display = "block";
            uxbtn.value = arry[0];
            uxbtn.onclick = function(){
                window.open(arry[1], "a", "");
            }
        }  
        else
        {
            uxbtn.style.display = "none";
        }
        
//        if(arr[9] == "http://")
//        {
//            imgdis.style.display = "none";
//        }
//        else
//        {
//            imgdis.style.display = "block";

//            imgdis.onclick = function(){
//                window.open(arr[9],'a','');
//            };

//        }
        
        var tmp = arr[2];
        tmp = tmp.replace(/\[/g, "<");
        tmp = tmp.replace(/\]/g, ">");
        
        //对应firefox
        if(!document.all)
        {
            des.innerHTML = tmp;
            name.textContent = arr[1];
            number.textContent = arr[10];
            //ldp.textContent = arr[22];
            point.textContent = arr[14];
        }
        else  //对应IE
        {
            des.innerHTML = tmp;
            name.innerText = arr[1];
            number.innerText = arr[10];
            //ldp.innerText = arr[22];
            point.innerText = arr[14];
        }
   } 
   
   //页面初始化时详细信息按钮的显示与否
   window.onload=function()
   {
        if(document.getElementById("txt") != null)
        {
            //imgdis = document.getElementById("messageImage");
            var txt = document.getElementById("txt");
            
            res = "";
            //alert(txt.value);
            SendAjaxE(txt.value);
            var arry = new Array();
            var uxbtn;
            if(document.getElementById("uxButton") != null)
            {
                uxbtn = document.getElementById("uxButton");
            }
            if(res != "")
            {
                arry = res.split('|');
                uxbtn.style.display = "block";
                uxbtn.value = arry[0];
                uxbtn.onclick = function(){
                    window.open(arry[1], "a", "");
                }
            }  
            else
            {
                uxbtn.style.display = "none";
            }
        }
   };
   
   function Next(domain)
   {
        var r = parseInt(Math.random()*1000000000);
        //alert(r);
        var name = "";
        var point = "";
        var remain = "";
        if(document.all)
        {
            name = document.getElementById("lblName").innerText;
            point = document.getElementById("lblPoint").innerText;
        }
        else
        {
            name = document.getElementById("lblName").textContent;
            point = document.getElementById("lblPoint").textContent;
        }
        var p1 = document.getElementById("p1");
        var p2 = document.getElementById("p2");
        var p3 = document.getElementById("txtID");
        //var p4 = document.getElementById("p4");
        //alert(p4.value);
        res = "";
        SendAjaxB(domain,r); 
        var res1 = res;           
        if(res.match("logined=Y") != null)
        {
            res = "";
            SendAjaxD();
            
            remain = parseInt(res) - parseInt(point);
            
            if(remain < 0)
            {
                alert("很抱歉，您的积分不足，无法兑换该礼品！");
            }
            else
            {
                window.location.href = "ico_LDinfo_prize.aspx?p1=" + p1.value + "&p2=" + p2.value + "&p3=" + p3.value;
            }
        }
        else
        {
            //alert("mm");
            var urlTemp = "";
            urlTemp = encodeURIComponent(window.location.pathname + window.location.search);
             
            //alert(urlTemp);
            window.location.href = "../common/ico_login_prize.aspx?reurl="+urlTemp;
        }     
   }