﻿// JScript 文件
    var oriIMg="";
    function gotoShoppingCenter()
    {
        window.location.href='http://'+document.domain+'/shopping/s_content.aspx'
    }

    function showColorSelectSticker(obj)
    {
        if($('div_stickerColor').style.display=="")
        {
            obj.innerHTML='点击选择'+"<img src=\"http://images.carsfun.com/images/palette.gif\" alt=\"\" />";
            $('div_stickerColor').style.display='none';   
            cleanSelectSticker();
            if(oriIMg!="")
            {
                $("img_big").src=oriIMg;
            }
        }
        else
        {
            obj.innerHTML='取消选择';
            $('div_stickerColor').style.display='';   
        }
    }
    
    function cleanSelectSticker()
    {
      var pics =  document.getElementsByName("sticker_img");
      for(var i=0;i<pics.length;i++)
      {
        pics[i].parentNode.className="cq_change_color_list_simg";
      }
      
    }
    function selectSticker(obj)
    {
        cleanSelectSticker();
        obj.parentNode.className='cq_change_color_list_simg selected';
        
        $("div_bigimg_"+obj.id).display="none";
        if(oriIMg=="")
        {
            oriIMg=$("img_big").src;
        }
        $("img_big").src=obj.src;
    }
    function getSelectStickerId()
    {
      var rs=0;
      var pics =  document.getElementsByName("sticker_img");
      for(var i=0;i<pics.length;i++)
      {
        if(pics[i].parentNode.className=="cq_change_color_list_simg selected")
        {
            rs=pics[i].id;
            return rs;
        }
      } 
      return rs; 
    }
    
    function showBigImageSticker(preDiv,preLoading)
    {
        //var oriSrc =$(preLoading).src;
        //$(preLoading).src="http://images.carsfun.com/index/ajax-loader.gif";
        $(preDiv).show();
        //setTimeout("document.getElementById('"+preLoading+"').src='"+oriSrc+"'",2000);
        
    }
    function closeBigImageSticker(preDiv,preLoading)
    {
        $(preDiv).hide();
    }
    function addToCart(ev,id)
    {
        var sellPrice=0.00;
        var isSticker_Size = $("div_stickerSizeMain");
        var isSticker_Stuff = $("div_sitckerStuffMain");
        var isSticker_Color =$("div_stickerColorMain");
        var stickerColoId=0;
        var stickerSizeId=0;
        var stickerStuffId=0;
        if(isSticker_Size!=null)
        {
            if($("div_stickerSizeMain").style.display=="")
            {
                var size_value=$F("ddlStickerSize").split("_");
                sellPrice += parseFloat(size_value[0]);
                stickerSizeId = size_value[1];
            }
        }
        if(isSticker_Stuff!=null)
        {
            if($("div_sitckerStuffMain").style.display=="")
            {
                var stuff_value=$F("ddlStickerStuff").split("_");
                sellPrice += parseFloat(stuff_value[0]);
                stickerStuffId = stuff_value[1];
            }    
        }
        if(isSticker_Color!=null)
        {
            stickerColoId = getSelectStickerId();
        }
        
        ev = ev || window.event;
        var mousePos = mouseCoords(ev);
        var div_loading=$("div_loading");
        div_loading.style.left=mousePos.x+"px";
        div_loading.style.top=mousePos.y+"px";
        div_loading.style.display="";
        var url = 'http://'+document.domain+'/tools/ajax_shopping.aspx';
        var pars = 'action=addtocart&id='+id+"&sellprice="+sellPrice+"&sizeId="+stickerSizeId+"&stuffId="+stickerStuffId+"&colorId="+stickerColoId+"&ra="+Math.random();
        var gs = id.split(",");
        if(gs.length>1)
        {
            for(var i=0;i<gs.length-1;i++)
            {
                pars = 'action=addtocart&id='+gs[i]+"&sellprice="+sellPrice+"&ra="+Math.random();
                var myAjax = new Ajax.Request(url,
                                        {method: 'get',parameters: pars,onComplete: function(res){
                                           
                                        }}
                                      );
            }
            
           pars = 'action=addtocart&id='+gs[gs.length-1]+"&sellprice="+sellPrice+"&ra="+Math.random();
           var myAjax = new Ajax.Request(url,
                                        {method: 'get',parameters: pars,onComplete: function(res){
                                            var div_loading=$("div_loading");
                                            var div_shopinfo =$("div_shopinfo");
                                           
                                            var div_pop = $("div_pop");
                                            var rs =res.responseText;// "{info:'商品已经成功放入购物车!',count:'0',money:'0.00'}"//
                                            
                                            rs = eval('('+rs+')');
                                           div_shopinfo.innerHTML=rs.info;
                                           $("b_goodsCount").innerHTML=rs.count;
                                           $("b_goodsMoney").innerHTML=rs.money+"元";
                                           //div_pop.style.display="";
                                           //div_pop.style.left=div_loading.style.left;
                                           //div_pop.style.top=div_loading.style.top;
                                           div_loading.style.display="none";
                                           gotoCenter("div_pop"); 
                                           return;
                                        }}
                                      );
        }
        
        var myAjax = new Ajax.Request(url,
                                        {method: 'get',parameters: pars,onComplete: function(res){
                                            var div_loading=$("div_loading");
                                            var div_shopinfo =$("div_shopinfo");
                                           
                                            var div_pop = $("div_pop");
                                            var rs =res.responseText;// "{info:'商品已经成功放入购物车!',count:'0',money:'0.00'}"//
                                            
                                            rs = eval('('+rs+')');
                                            if(rs.info=="本品只提供团购定制,不接受单品零售")
                                            {
                                                sAlert("本品为车趣专供团购定制商品，不接受单品零售，点<a href='http://www.carsfun.com/product/"+id+".html'>继续</a>查看商品详细信息");
                                                div_loading.style.display="none";
                                                return;
                                            }
                                           div_shopinfo.innerHTML=rs.info;
                                           $("b_goodsCount").innerHTML=rs.count;
                                           $("b_goodsMoney").innerHTML=rs.money+"元";
                                           //div_pop.style.display="";
                                           //div_pop.style.left=div_loading.style.left;
                                           //div_pop.style.top=div_loading.style.top;
                                           div_loading.style.display="none";
                                           gotoCenter("div_pop"); 
                                        }}
                                      );
        headControler.getCartList(); 
    }
    function addToFavorite(ev,id)
    {
        ev = ev || window.event;
        var mousePos = mouseCoords(ev);
        var div_loading=$("div_loading");
        div_loading.style.left=mousePos.x+"px";
        div_loading.style.top=mousePos.y+"px";
        div_loading.style.display="";
        var url = 'http://'+document.domain+'/tools/ajax_shopping.aspx';
        var pars = 'action=addtofavorite&id='+id+"&ra="+Math.random();
        var myAjax = new Ajax.Request(url,
                                        {method: 'get',parameters: pars,onComplete: function(res){
                                        
                                            var div_loading=$("div_loading");
                                            var div_shopinfo =$("div_info");
                                            
                                            var div_pop = $("div_fav");
                                            var rs =res.responseText;// "{info:'商品已经成功放入购物车!',count:'0',money:'0.00'}"//
                                            
                                            rs = eval('('+rs+')');
                                           div_shopinfo.innerHTML=rs.info;
                                           var des="<div class=\"juz\">暂存架共 <b class=\"ajys\" id=\"b_count\"></b> 种商品</div>"
                                           $("div_count").innerHTML=des;
                                           $("b_count").innerHTML=rs.count;
                                           des = "<input class=\"kang\" onclick=\"window.location.href='http://www.carsfun.com/member/m_favorite.aspx';\" type=\"button\" value=\"查看暂存架\" />"+
                                           "&nbsp;<input class=\"jxgw\" name=\"Input\" type=\"button\" onclick=\"$('div_pop').style.display='none';\" value=\"继续购物\" />";
                                           $("div_count2").innerHTML=des;
                                           div_loading.style.display="none";
                                           gotoCenter("div_fav");
                                        }}
                                      );
    }
    function getIE(e){ 
        var   t=e.offsetTop; 
            var   l=e.offsetLeft; 
            while(e=e.offsetParent){ 
                t+=e.offsetTop; 
                l+=e.offsetLeft; 
                } 
            return   (t+ ", "+l); 
        }
    function mouseCoords(ev){
        if(ev.pageX || ev.pageY){
                return {x:ev.pageX, y:ev.pageY};
              }
              return {
                x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
                y:ev.clientY + document.body.scrollTop - document.body.clientTop
              };
   }
    function IsIE()
    {
	    return document.all ? true : false;
    }
    
    function gotoCenter(id)
    {
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == "number") {
                myWidth = window.innerWidth;
                myHeight = window.innerHeight;
            } else {
                if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                    myWidth = document.documentElement.clientWidth;
                    myHeight = document.documentElement.clientHeight;
                } else {
                    if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                        myWidth = document.body.clientWidth;
                        myHeight = document.body.clientHeight;
                    }
                }
            }
        	
       
	    var obj = document.getElementById(id);
        obj.style.position = "absolute";
        var left =(parseInt(myWidth/2) - parseInt(obj.style.width)/2) +"px";
        var top =(myHeight - obj.style.height)  /2+document.documentElement.scrollTop+"px";

        obj.style.top=top;
        obj.style.left=left;
        obj.style.display="";
            }

function sAlert(str){ 
   var msgw,msgh,bordercolor; 
   msgw=400;//Width
   msgh=100;//Height 
   titleheight=25 //title Height
   bordercolor="#DE0D00"//"#336699";//boder color
   titlecolor="#DE0D00"//"#99CCFF";//title color
   var sWidth,sHeight; 
   sWidth=document.body.offsetWidth; 
   sHeight=document.body.offsetHeight; 
   var bgObj=document.createElement("div"); 
   bgObj.setAttribute('id','bgDiv'); 
   bgObj.style.position="absolute"; 
   bgObj.style.top="0"; 
   bgObj.style.background="#777"; 
   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); 
   var 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, sans-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"; 
   var title=document.createElement("h4"); 
   title.setAttribute("id","msgTitle"); 
   title.setAttribute("align","right"); 
   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(){ 
          document.body.removeChild(bgObj); 
          document.getElementById("msgDiv").removeChild(title); 
          document.body.removeChild(msgObj); 
        } 
   document.body.appendChild(msgObj); 
   document.getElementById("msgDiv").appendChild(title); 
   var txt=document.createElement("p"); 
   txt.style.margin="1em 0" 
   txt.setAttribute("id","msgTxt"); 
   txt.innerHTML=str; 
   document.getElementById("msgDiv").appendChild(txt); 
} 