﻿function pointitem(obj)
{
 if( document.getElementById("customerid").innerHTML!="")
 {
var epoint=document.getElementById(obj).lang;
var rpoint=document.getElementById("point").innerHTML;
var des=document.getElementById("des"+obj).innerHTML;
if(epoint<=rpoint)
{

var info="<table width=\"260px\" cellpadding=\"0\" cellspacing=\"0\" class=\"floatTable\"><tr><td><img src=\"images/PointsStore/psLi.gif\" /><span class=\"psName\">Introduction:</span></td</tr><tr><td width=\"250px\" class=\"tdText1\">"+des+"</td></tr><tr><td><img src=\"images/PointsStore/psLi.gif\" /><span class=\"psName\">Delivery Method:</span></td></tr><tr><td class=\"tdTextMail\">Online by MSN (Recomended)</td></tr><tr><td><input id=\"msn\" class=\"input1\" type=\"text\" /></td></tr><tr><td class=\"tdTextMail2\">by Email</td></tr><tr><td><input id=\"email\" class=\"input2\" type=\"text\" /></td></tr><tr><td class=\"buttonimages\"><img onclick=\"PointItem("+obj+")\" src=\"images/PointsStore/confirm1.gif\" /><span style=\"padding-right:10px;\"></span><img onclick=\"remove()\" src=\"images/PointsStore/cancel1.gif\" /></td></tr><tr><td id=\"pointinfo\"></td></tr></table>";

openNewDiv("floatDiv",info)
}
else
{
alert("Sorry, your points are insufficient.");
}
}
else
{
alert("please login!");
}

}

function PointItem(obj)
{

    
    //获取选择的金币数量
    var itemname=document.getElementById("name"+obj).innerHTML;
    var itemtype=document.getElementById("type"+obj).lang;
    var point =document.getElementById(obj).lang;
    var customerid=document.getElementById("customerid").title;
    var email=document.getElementById("email").value;
    var msn=document.getElementById("msn").value;
    var p = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
					
         if(email==""&&msn=="")
         {
         document.getElementById("pointinfo").innerHTML="please intput your email or msn!";
         }
         else if(email!=""&&!p.test(email))
         {
         document.getElementById("pointinfo").innerHTML="The email format is wrong!";
         }
         else if(msn!=""&&!p.test(msn))
         {
         document.getElementById("pointinfo").innerHTML="The msn format is wrong!";
         }
         
         else
         {
             
            var xmlStr ="<nextlist>"
                 xmlStr+="<itemname>"+escape(itemname)+"</itemname>";
                 xmlStr+="<itemtype>"+escape(itemtype)+"</itemtype>";
                 xmlStr+="<point>"+escape(point)+"</point>";
                 xmlStr+="<customerid>"+escape(customerid)+"</customerid>";
                 xmlStr+="<email>"+escape(email)+"</email>";
                 xmlStr+="<msn>"+escape(msn)+"</msn>";
                 xmlStr+="</nextlist>";
                  
        var PointAjax=new Ajax.Request('ashx/pointitem.ashx',{method:'POST',
        postBody:xmlStr,
       onComplete: PointSuc,
       onError:function(PointAjax){alert("error,HttpStatus:"+PointAjax.status);}
       })
       }
         
}

function PointSuc(PointAjax)
{
    var result=PointAjax.responseText;
    var arr=result.split("|");
    if(arr[0]=="-1")
    {
       document.getElementById("pointinfo").innerHTML="sorry,please refresh this page and try again!";
    }
    else
    {
        var bpoint=document.getElementById("point").innerHTML;
        var epoint=bpoint-arr[1];
        document.getElementById("point").innerHTML=epoint;
        setCookie("point",epoint,1);
        alert("ok!");
        remove();
    }
}








var docEle = function() {
  return document.getElementById(arguments[0])||false;
 }
 function openNewDiv(_id,text) {
   
  var m = "mask";
 if (docEle(_id)) document.removeChild(docEle(_id));
 if (docEle(m)) document.removeChild(docEle(m));
 // 新激活图层
  var newDiv = document.createElement("div");
  newDiv.id = _id;
  newDiv.style.position = "absolute";
  newDiv.style.zIndex = "25";
  newDiv.style.width = "260px";
  //newDiv.style.height = "195px";
  newDiv.style.top = "340px";
  newDiv.style.fontSize="12px";
  newDiv.style.color="#2eadee";
  //newDiv.style.textAlign="left";
  //newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2+70 + "px"; // 屏幕居中
  newDiv.style.left = (parseInt(screen.width) - 300) / 2+70 + "px"; // 屏幕居中
  newDiv.style.background = "#f7fdff";
  newDiv.style.border = "2px solid #a0018b";
  newDiv.style.padding = "5px";
  newDiv.innerHTML =text;
  newDiv.style.cursor="pointer";
  
  document.body.appendChild(newDiv);
  // mask图层
  var newMask = document.createElement("div");
  newMask.id = m;
  newMask.style.position = "absolute";
  newMask.style.zIndex = "24";
  newMask.style.width = window.screen.width+ "px";
 // newMask.style.width = "510"+ "px";
  newMask.style.height = "3000"+ "px";
  //newMask.style.height ="310"+ "px";
  newMask.style.background="#000000";
  newMask.style.top = "0px";
  newMask.style.left = "0px";
   //newMask.style.left = (parseInt(document.body.scrollWidth) - 300) / 2-100+"px";
  // newMask.style.left = (parseInt(screen.width-530)) / 2+"px";
  //(parseInt(document.body.scrollWidth) - 300) / 2
  //newMask.style.background = "#000";
  newMask.style.filter = "alpha(opacity=35)";
  newMask.style.opacity = "0.35";
//  newDiv.onclick = function() {
//   document.body.removeChild(docEle(_id));
//   document.body.removeChild(docEle(m));
//   return false;
//  }
  document.body.appendChild(newMask);

// 关闭mask和新图层
//  var newA = document.createElement("a");
//  newA.href = "#";
//  newA.innerHTML = "confirm";
//  newA.style.color="#ff0000";
  
  //newDiv.appendChild(newA);
  }
  function remove() {
   document.body.removeChild(docEle("floatDiv"));
   document.body.removeChild(docEle("mask"));
  // document.getElementById('floatDiv').childNodes[0].removeNode(true); 
   //document.getElementById('mask').childNodes[0].removeNode(true); 

   
   
  }