var bigImg = $("#bigImg");
var docEle = function()
{
    return document.getElementById(arguments[0]) || false;
}

function openNewDiv(_id, cid, type, a)
{
    if(document.getElementById("indexSelect") != null && document.getElementById("indexSelect2") != null){
      document.getElementById("indexSelect").style.display = "none";
      document.getElementById("indexSelect2").style.display = "none";
    }
    var temp_h1 = document.body.clientHeight;
    var temp_h2 = document.documentElement.clientHeight;
    var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false; 
    var htmlbody = isXhtml?document.documentElement:document.body;
    htmlbody.style.overflow = "hidden";
    var m = "mask";
    if (docEle(_id)) document.body.removeChild(docEle(_id));
    if (docEle(m)) document.body.removeChild(docEle(m));
    
    //mask遮罩层
    
    var newMask = document.createElement("div");
    newMask.id = m;
    newMask.style.position = "absolute";
    newMask.style.zIndex = "1";
    _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
    _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
    newMask.style.width = _scrollWidth + "px";
    newMask.style.height = _scrollHeight + "px";
    newMask.style.top = "0px";
    newMask.style.left = "0px";
    newMask.style.background = "#33393C";
    newMask.style.filter = "alpha(opacity=40)";
    newMask.style.opacity = "0.40";
    document.body.appendChild(newMask);
    
    //新弹出层

    var newDiv = document.createElement("div");
    newDiv.id = _id;
    newDiv.style.position = "absolute";
    newDiv.style.zIndex = "9999";
    
    newDivWidth = 600;
    newDivHeight = 300;
    newDiv.style.width = newDivWidth + "px";
    newDiv.style.height = newDivHeight + "px";
    newDiv.style.top = (document.documentElement.scrollTop + 60) + "px";
    newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
    newDiv.style.background = "#ffffff  no-repeat center center";
    newDiv.style.border = "1px solid #860001";
    newDiv.style.padding = "5px";
    newDiv.style.cursor = "pointer";
    
    var bigImgHtml = $("#commodityPicstab").data("bigImgUrl");
    if (bigImgHtml == null || bigImgHtml == "") {
      bigImgHtml = "<img style='width:"+newDivWidth+"px;height:"+newDivHeight+"px;' src='/photos/show/" + cid + "." + type + "' />";
    } else {
      bigImgHtml = "<img src='" + bigImgHtml + "' />";
    }
    newDiv.innerHTML = bigImgHtml;
    newDiv.onclick = function()
    {
      htmlbody.style.overflow = "auto";
      if(document.getElementById("indexSelect") != null && document.getElementById("indexSelect2") != null){
        document.getElementById("indexSelect").style.display = "";
        document.getElementById("indexSelect2").style.display = "";
      }
        document.body.removeChild(docEle(_id));
        document.body.removeChild(docEle(m));
        return false;
    };
    document.body.appendChild(newDiv);
    //关闭新图层和mask遮罩层

    var newA = document.createElement("a");
    newA.href = "javascript:void(0)";
    newA.innerHTML = "<img src='/images/cross.gif' style='width:15px;height:15px;'/>";
    newA.style.border = "0px";
    newA.style.padding = "0px";
    newA.style.right = "1px";
    newA.style.top = "1px";
    newA.style.position = "absolute";
    newA.onclick = function()
    {
      htmlbody.style.overflow = "auto";
        if(document.getElementById("indexSelect") != null && document.getElementById("indexSelect2") != null){
          document.getElementById("indexSelect").style.display = "";
          document.getElementById("indexSelect2").style.display = "";
        }
        document.body.removeChild(docEle(_id));
        document.body.removeChild(docEle(m));
        return false;
    };
    newDiv.appendChild(newA);
}

