﻿//var msgObjMoveTimeSpan
//function msgObjMove() {
//    var   bgObj=document.getElementById("bgDiv")
//    var   msgObj=document.getElementById("msgDiv")
//    if(msgObj!=null && bgObj!=null)
//    {
//        bgObj.style.top = document.documentElement.scrollTop+'px';       
//        msgObjMoveTimeSpan=setTimeout("msgObjMove();",10);
//    }
//}

var bgObj=null;
var msgObj=null
var title=null;
var txt=null;
var titleClose=null;
function RemoveObj()
{
    if(bgObj!=null)
    {
        document.getElementById( "msgTitle").removeChild(titleClose);          
        document.getElementById( "msgDiv").removeChild(title);
        document.getElementById( "msgDiv").removeChild(txt);
        document.body.removeChild(msgObj);
        document.body.removeChild(bgObj);
        
        titleClose=null;
        title=null;
        txt=null;
        msgObj=null;
        bgObj=null;
    }
}

function   sAlert(str,t,w,h){
    RemoveObj();
    var   msgw,msgh,bordercolor;
    msgw=w;//提示窗口的宽度
    msgh=h;//提示窗口的高度
    //titleheight=25   //提示窗口标题高度
    bordercolor= "#c51100 ";//提示窗口的边框颜色
    //titlecolor= "#c51100 ";//提示窗口的标题颜色

    var   sWidth,sHeight;
    sWidth=screen.width;
    sHeight=document.documentElement.scrollHeight;//screen.height;
    //bgObj
    bgObj=document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top='0px';//document.documentElement.scrollTop+'px';
    bgObj.style.background="#cccccc";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width=sWidth+"px";
    bgObj.style.height=sHeight+"px";
    bgObj.style.zIndex="10000";
    document.body.appendChild(bgObj);
    //msgObj
    msgObj=document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.style.background="white ";
    msgObj.style.border="1px solid "+ bordercolor;
    msgObj.style.position="absolute";
    msgObj.style.left   =   "50%";
    msgObj.style.top   =   "50%";
    msgObj.style.font= "12px/1.6em Verdana,Geneva,Arial,Helvetica,ans-serif ";
    msgObj.style.marginLeft   =   "-225px"   ;
    msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+ "px";
    msgObj.style.width   =   msgw   +   "px";
    msgObj.style.height   =msgh   +   "px";
    msgObj.style.textAlign   =   "center";
    msgObj.style.lineHeight   = "25px";
    msgObj.style.zIndex   =   "10001";


    //title   
    title=document.createElement( "h4");
    title.setAttribute( "id", "msgTitle");
    title.setAttribute( "align", "left");
    title.style.margin= "0";
    title.style.padding= "3px";
    title.style.background=bordercolor;
    title.style.filter= "progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100); ";
    title.style.opacity= "0.75";
    title.style.border= "1px solid "   +   bordercolor;
    title.style.height= "18px";
    title.style.font= "12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif ";
    title.style.color= "white";
    title.style.cursor= "pointer";
    title.innerHTML= t;
    title.onclick=function(){
//        if (confirm("确认要关闭吗？"))
//        {	   
            RemoveObj();
//        }
    }
    document.body.appendChild(msgObj);
    document.getElementById( "msgDiv").appendChild(title);
    
    //titleClose
    titleClose=document.createElement( "div");
    titleClose.innerHTML= "关闭";
    titleClose.style.position="absolute";
    titleClose.style.left   =   "90%";
    titleClose.style.top   =   "5%";
    title.appendChild(titleClose);      

    //txt
    txt=document.createElement( "p");
    txt.style.margin= "1em   0"
    txt.setAttribute( "id", "msgTxt");
    txt.innerHTML=str;
    document.getElementById( "msgDiv").appendChild(txt);     

    //msgObjMove();
}


function   ShowFavorite(w,h){
    RemoveObj();
    if(document.getElementById('SortCodeSearch'))
        document.getElementById('SortCodeSearch').style.display='none';
    var   msgw,msgh,bordercolor;
    msgw=w;//提示窗口的宽度
    msgh=h;//提示窗口的高度
    //titleheight=25   //提示窗口标题高度
    bordercolor= "#c51100 ";//提示窗口的边框颜色
    //titlecolor= "#c51100 ";//提示窗口的标题颜色

    var   sWidth,sHeight;
    sWidth=screen.width;
    sHeight=document.documentElement.scrollHeight;//screen.height;

    //bgObj
    bgObj=document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top='0px';//document.documentElement.scrollTop+'px';
    bgObj.style.background="#cccccc";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width=sWidth+"px";
    bgObj.style.height=sHeight+"px";
    bgObj.style.zIndex="10000";
    document.body.appendChild(bgObj);

    //msgObj
    msgObj=document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.style.background="white ";
    msgObj.style.border="1px solid "+ bordercolor;
    msgObj.style.position="absolute";
    msgObj.style.left   =   "50%";
    msgObj.style.top   =   "20%";
    msgObj.style.font= "12px/1.6em Verdana,Geneva,Arial,Helvetica,ans-serif ";
    msgObj.style.marginLeft   =   "-225px"   ;
    msgObj.style.marginTop   =   -75+document.documentElement.scrollTop+ "px";
    msgObj.style.width   =   msgw   +   "px";
    msgObj.style.height   =msgh   +   "px";
    msgObj.style.textAlign   =   "center";
    msgObj.style.lineHeight   = "25px";
    msgObj.style.zIndex   =   "10001";


    //title   
    title=document.createElement( "h4");
    title.setAttribute( "id", "msgTitle");
    title.setAttribute( "align", "left");
    title.style.margin= "0";
    title.style.padding= "3px";
    title.style.background=bordercolor;
    title.style.filter= "progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100); ";
    title.style.opacity= "0.75";
    title.style.border= "1px solid "   +   bordercolor;
    title.style.height= "18px";
    title.style.font= "12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif ";
    title.style.color= "white";
    title.style.cursor= "pointer";
    title.innerHTML= "购物车结算";
    title.onclick=function(){
//        if (confirm("确认要关闭吗？"))
//        {	   
            RemoveObj();
            if(document.getElementById('SortCodeSearch'))
                document.getElementById('SortCodeSearch').style.display='';
//        }
    }
    document.body.appendChild(msgObj);
    document.getElementById( "msgDiv").appendChild(title);
    
    //titleClose
    titleClose=document.createElement( "div");
    titleClose.innerHTML= "关闭";
    titleClose.style.position="absolute";
    titleClose.style.left   =   "93%";
    titleClose.style.top   =   "5px";
    title.appendChild(titleClose);      

    //txt
    txt=document.createElement( "p");
    txt.style.margin= "1em   0"
    txt.setAttribute( "id", "msgTxt");
    
    var s='<table id="tb" border="1" bordercolor="#cccccc" cellpadding="0" cellspacing="0"><tr><td width="200">产品</td><td width="80">数量</td><td width="80">单价(元)</td><td width="100">总价(元)</td><td width="100">操作</td></tr>';
    list.GetProducts();
    var totalPrice2=0.0;
    var totalPrice1=0.0;
    for(var i = 0; i < list.count; i++) {      
        totalPrice2=parseFloat(list.items[i]["price"])*parseInt(list.items[i]["count"]);
        totalPrice2=(Math.round(totalPrice2*100))/100.0;  
        totalPrice1 += totalPrice2;
        s+='<tr><td>'+list.items[i]['title']+'</td><td>'+list.items[i]['count']+'</td><td>'+list.items[i]['price']+'</td><td>'+totalPrice2+'</td><td><a href="javascript:ModifyCount('+list.items[i]['id']+');" class="nrfont4l">修改数量</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:RemoveProduct('+list.items[i]['id']+');" class="nrfont4l">删除</a></td></tr>';
    }
    totalPrice1=(Math.round(totalPrice1*100))/100.0;  
    var dateTime=(new Date()).getTime();
    s+='<tr><td>&nbsp;</td><td>&nbsp;</td><td>合计</td><td>'+totalPrice1+'</td><td>&nbsp;</td></tr>';
    s+='</table><input type="button" onclick="javascript:location.href=\'ClientCall/Down.aspx?t='+dateTime+'\';" value="保存"/>';
    txt.innerHTML=s;
    document.getElementById( "msgDiv").appendChild(txt);    


    //msgObjMove();
}

function RemoveProduct(id)
{
    list.Remove(id);
    ShowFavorite(600,400)
}
function ModifyCount(id)
{
    var item=list.Get(id);
    if(item!=null)
    {
        var count=item["count"];  
        do
        {
            count=prompt("请输入产品数量:",count);   
        }
        while(isNaN(count))
        if(isNumber(count))
        {
            list.Set(item["id"],item["price"],count,item["title"]);
            ShowFavorite(600,400)
        }
    }
}
