﻿




    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()
	{
		if (XmlHttp.readyState==4 || XmlHttp.readyState=='complete')
		{	
		//alert(XmlHttp.responseText);
		    res = XmlHttp.responseText;   
		}
	}	

	function sendAJAX(id)
	{
		XmlHttp.open("GET","ajx_100get.aspx?p3="+id,false);
		
		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
    function sendAJAXA(id)
	{
		XmlHttp.open("GET","ajx_getProduct.aspx?p3="+id,false);
		
		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
    function SendAjaxPost(domain, strSend)
	{
	    XmlHttp.open("POST", domain + "/services/pc/pages/fhservc/SFHServC.aspx",false);
		XmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		XmlHttp.send(strSend);	
	    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 SendAjaxC(p1, p2, p3)
	{
	    XmlHttp.open("GET","ajx_get_plimit.aspx?p1="+p1+"&p2="+p2+"&p3="+p3,false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function SendAjaxD()
	{
	    XmlHttp.open("GET","ajx_get_point.aspx",false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function SendAjaxE(pid)
	{
	    XmlHttp.open("GET","../common/ajx_get_partner.aspx?id="+pid,false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
	
	function SendAjaxInventory(p1, p2, p3)
	{
	    XmlHttp.open("GET","../../../../channels/pc/v2/redeem/ajx_get_Inventory.aspx?p1="+p1+"&p2="+p2+"&p3="+p3,false);

		XmlHttp.send(null);	
		if(XmlHttp.status == 200)
		{
		    ServerProcess();
		}
	}
   function GetInfo(type, id, picRoot)
   {
        
        if(type == "wa")
        {
            sendAJAX(id);
        }
        else if(type == "all")
        {
            sendAJAXA(id);
        }
        var arr = new Array();
        if(res != "")
        {
            arr = res.split('|');
        }
        var cImage;
        if(document.getElementById("clientImage") != null)
        {
            cImage = document.getElementById("clientImage");
        }
        cImage.src = picRoot + arr[4];
        var spName = document.getElementById("spName");
        var spPoint = document.getElementById("spPoint");
        var spDesc;
        if(document.getElementById("spDesc")!=null)
        {
            spDesc = document.getElementById("spDesc");
        }
//        var imgdis;
//        if(document.getElementById("messageImage") != null)
//        {
//            imgdis = document.getElementById("messageImage");
//        }
        var p1 = document.getElementById("p1");
        var p2 = document.getElementById("p2");
        var p3 = document.getElementById("p3");
        var p4 = document.getElementById("p4");
        
        p1.value = arr[16];
        p2.value = arr[17];
        p3.value = arr[0];
        p4.value = arr[3];
        
        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, ">");
        //alert(tmp);
        if(document.all)
        {
            spName.innerText = arr[1];
            spPoint.innerText = arr[14];
            spDesc.innerHTML = tmp;
        }
        else
        {
            spName.textContent = arr[1];
            spPoint.textContent = arr[14];
            spDesc.innerHTML = tmp;
        }
        var r = parseInt(Math.random()*1000000000000000);
        var t = "http://tracking.icoke.cn/web_service/list/Add_File.aspx?cli=icokem111&schno=1&li=5&1=0&2=website&3=&4=Product_View_100&5=" + id + "&6=W_S_DATE&rs=" + r;
        document.getElementById("uxT3").src = t;
   } 
   
   window.onload=function()
   {
        //var imgdis;
        if(document.getElementById("t5") != null)
        {
            var t5 = document.getElementById("t5").value;
            if(t5 == "t")
            {
                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";
                    }
                }
            }
            else
            {
                if(document.getElementById("uxButton") != null)
                {
                    document.getElementById("uxButton").style.display = "none";
                }
                if(document.getElementById("uxAc") != null)
                {
                    document.getElementById("uxAc").style.display = "none";
                }
            }
        }

        
   };
   
   function RedirectUrl()
   {
        var pn = "";
        var pa = "";
        if(document.getElementById("ddlPartner") != null)
        {
            pn = document.getElementById("ddlPartner").value;
        }   
        if(document.getElementById("ddlPassion") != null)
        {
            pa = document.getElementById("ddlPassion").value;
        }
        window.location.href = "ico_all_prize.aspx?pn="+pn+"&pa="+pa;
   }
   
    function Back()
    {
        var url = document.referrer;
        window.location.href = url;        
    }
    
    function BackA()
    {
        //history.go(-1);    
        history.back();
        return false; 
    }
   
   function GetVi(domain)
   {
        var r = parseInt(Math.random()*1000000000);
        //alert(r);
        var name = "";
        var point = "";
        var remain = "";
        if(document.all)
        {
            name = document.getElementById("spName").innerText;
            point = document.getElementById("spPoint").innerText;
        }
        else
        {
            name = document.getElementById("spName").textContent;
            point = document.getElementById("spPoint").textContent;
        }
        var p1 = document.getElementById("p1");
        var p2 = document.getElementById("p2");
        var p3 = document.getElementById("p3");
        var p4 = document.getElementById("p4");
        //alert(p4.value);
        res = "";
        SendAjaxB(domain,r); 
        var res1 = res;           
        if(res.match("logined=Y") != null)
        {
            res = "";
            SendAjaxInventory(p1.value, p2.value, p3.value);
            if(res == "n")
            {
                alert("很抱歉，目前无法兑换该礼品，请选择其他礼品兑换。");
            }
            else
            {                
                res = "";
                SendAjaxC(p1.value, p2.value, p3.value);
                //alert(res);
                if(res == "y")  //
                {
                    window.open("../../ico_prize_100redeem_v2.aspx?ud=&p1="+ p1.value +"&p2=" + p2.value + "&p3=" +p3.value+ "&r=" + r, "", "");
                }
                else if (res == "MC")
                {
                  window.open("../../../../services/pc/pages/v2/redeem/ico_100r_vmc_prize.aspx?p1="+ p1.value +"&p2=" + p2.value + "&p3=" +p3.value+ "&p4=V2VMC&r=" + r, "", "");
                }
                else
                {
                    res = "";
                    SendAjaxD();
                    
                    remain = parseInt(res) - parseInt(point);
                    
                    if(remain < 0)
                    {
                        alert("很抱歉，您的积分不足，无法兑换该礼品！");
                    }
                    else
                    {            
                        if(p4.value != "1" && p4.value != "2" && p4.value != "14")
                        {
                            if(confirm("兑换 " + name + " \n将扣除您" + point + "iCoke积分。兑换该礼品后，您的帐户中还剩余" + remain + "积分。"))
                            {
                                var pams = "r1=&r2=&r3=&r4=&r5=&r6=&r7=&r8=&r9=&fn=redeem&p1="+p1.value + "&p2=" + p2.value + "&p3=" + p3.value + "&p4=1";
                                res = "";
                                SendAjaxPost(domain, pams);
                                //alert(res.match("<Result Description=\"OK for "));
                                if(res.match("<Result Description=\"OK for ") != null)
                                {
                                    //var j = res.indexOf("TypeID=");
                                    //var t = res.slice(j+8, j+9);
                                    var rr = "";
                                    var m = res.indexOf("Code=");
                                    res = res.replace("></Result>", "");
                                    rr = res.slice(m+6, res.length-2);
                                    //alert(res);
                                    //document.getElementById("p5").value = r;
                                    //document.getElementById("p6").value = t;
                                    //document.getElementById("a1").value = p3.value;
                                    var fm = document.getElementById("form2");
                                    document.form2.elements["a1"].value = p3.value;
                                    document.form2.elements["p5"].value = rr;
                                    document.form2.elements["p6"].value = p4.value;
                                    fm.method = "post";
                                    fm.action = "ico_100done_prize.aspx";
                                    //alert(form2);
                                    fm.submit();
                                    //window.location.href = "ico_100done_prize.aspx?c=" + r + "&p3=" + p3.value + "&i=" + t;
                                }
                                else
                                {
                                    alert("系统繁忙！");
                                }
                            }   
                        }
                        else
                        {
                            window.location.href = "ico_100info_prize.aspx?p3=" + p3.value + "&p1=" + p1.value + "&p2=" + p2.value;
                        }
                    }
                }        
                
            }
        }
        else
        {
            //alert("mm");
            var urlTemp = "";
            if(document.getElementById("t1") != null && document.getElementById("t2")!=null && document.getElementById("t3")!=null && document.getElementById("t4")!=null)
            {   
                urlTemp = window.location.pathname + "?pn=" + document.getElementById("t1").value + "&pa=" + document.getElementById("t2").value + "&pt=" + document.getElementById("t3").value + "&pg=" + document.getElementById("t4").value;
            }
            else
            {
                urlTemp = window.location.pathname + window.location.search;
            }
            urlTemp = encodeURIComponent(urlTemp);
             
            //alert(urlTemp);
            window.location.href = "../common/ico_login_prize.aspx?reurl="+urlTemp;
        }     
   }