﻿

function formatPrice(price)
{
//debugger;
    price=price+"";
    var l=price.indexOf(".");
	if(l>=0)
	{
		  if (price.substring(l + 1, 1) == "0")
            {
                return price.substring(0, l);
            }
            else
            {
                return Math.round(price*10)/10;
            }
	}
	return price;
}

function round(a,b){return(Math.round(a*Math.pow(10,b))*Math.pow(10,-b));}

function addToShoppingCart(id,cat)
{
   if(id)
   {
       if(islogin())
        {
         //   debugger;
          // isDelCat(cat);
           $.post("addToShoppingCart.aspx",{id:id},function(data){ getShoppingInfo();
           
                    if(location.href.indexOf("shoppingCart.aspx")>=0)
		           {
        		        
        		      window.location=window.location.href.replace("id=","");
		           }
           });
           
		  
        }
        else
        {
            alert("请先登录");
            getLoginReg(document.getElementById("logininfo"),'login.html');
        }
    }
}
function buynow(url,cat)
{
    if(islogin())
    { 
          // isDelCat(cat);
           
           var referrer=window.location.href;
           
           if(referrer.indexOf('productview')>=0)
           {
                referrer=document.referrer;
           }
           
            window.location=url+"&urlReferer="+escape(referrer);
       
    }
    else
    {
        alert("请先登录");
        getLoginReg(document.getElementById("logininfo"),'login.html');
    }
}
function islogin()
{
    var loginStatus=$("#logininfo").html();
				if(loginStatus.indexOf('已登录')>0)
				{
				return true;
				}
				return false;
}
function getShoppingInfo()
{
     $.post("getShoppingCount.aspx",{},function(data)
     {
     //alert(data);   
         $("#shoppingCartCount").html(data);
         
     }
     
     );
}

function getDeliverInfo()
{
    $("#deliverInfo").html('<img src="images/ajax-loader.gif" />');    
    showDP(-400,13,0);
	 $("#deliverInfo").load("cache/getDeliverInfo.html?random=" + (new Date().getTime()),function(data){});
	 
}

function showMap(obj,pic)
{
    $("#mapInfo").html('<img src="'+pic+'" />');
    showMP();
	
    showMPic(obj,-300,12,0);
}

function showMP()
{closeAllClass();
    $("#mapPanel").show();
    $("#deliverPanel").show();   
}
function noshowMP()
{
    $("#mapPanel").hide();
     $("#deliverPanel").hide();
}

function showdeliverPanel()
{
    $("#deliverPanel").show();
   closeAllClass();
   DDLHide();
}
function noshowdeliverPanel()
{
    $("#deliverPanel").hide();
    $("#mapPanel").hide();
    DDLShow();
}
function showDP(objleftoffset,objtopoffset,objtopfirefoxoffset)
{
  // debugger;
  var obj=document.getElementById("phoneBooking");
   var p = getposition(obj);    
 
   $("#deliverPanel").show();
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('deliverPanel').style.top=p['y']+"0px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			
		   document.getElementById('deliverPanel').style.top=p['y']-document.getElementById('deliverInfo').offsetHeight-40+"px";
			
        }
        else
        {
			document.getElementById('deliverPanel').style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('deliverPanel').style.left=p['x']+objleftoffset+"px";
     
}
function showMPic(obj,objleftoffset,objtopoffset,objtopfirefoxoffset)
{
  // debugger;
 
   var p = getposition(obj); 
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('mapPanel').style.top=p['y']+"0px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			
		   document.getElementById('mapPanel').style.top=p['y']-document.getElementById('mapInfo').offsetHeight-40+"px";
			
        }
        else
        {
			document.getElementById('mapPanel').style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('mapPanel').style.left=p['x']+objleftoffset+"px";
     
}
function getServicesInfo()
{
    showSP()
	
    showServicesCenter(-123,12,0);
   
}
function getOnlineInfo(obj,show)
{
    $("#onlineInfo").html('<img src="images/ajax-loader.gif" />');
    showOP()
    showOnline(obj,-130,-8,0);
	if(show==1)
	{
    	//$.post('cache/getOnlineServices.html',{},function(data){$("#onlineInfo").html(data);});	
		 $("#onlineInfo").load("cache/getOnlineServices.html?random=" + (new Date().getTime()),function(data){});
	}
	else
	{
		//$.post('cache/getOnlineServices2.html',{},function(data){$("#onlineInfo").html(data);});
		 $("#onlineInfo").load("cache/getOnlineServices2.html?random=" + (new Date().getTime()),function(data){});
	}
	DDLHide();
}
function showSP()
{
    $("#servicesPanel").show();   
	closeAllClass();
	DDLHide();
}
function noshowSP()
{
    $("#servicesPanel").hide();
     $("#onlinePanel").hide();
     DDLShow();
}

function showOP()
{
    $("#onlinePanel").show();
    $("#servicesPanel").show();  
	closeAllClass();
	DDLHide();
}
function noshowOP()
{
    $("#onlinePanel").hide();
    $("#servicesPanel").hide();
    DDLShow();
}

function showServicesCenter(objleftoffset,objtopoffset,objtopfirefoxoffset)
{
  // debugger;
    var obj=document.getElementById("servicesCenter");
   var p = getposition(obj); 
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('servicesPanel').style.top=p['y']+"0px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			
		   document.getElementById('servicesPanel').style.top=p['y']-document.getElementById('servicesInfo').offsetHeight-40+"px";
			
        }
        else
        {
			document.getElementById('servicesPanel').style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('servicesPanel').style.left=p['x']+objleftoffset+"px";
     
}
function showOnline(obj,objleftoffset,objtopoffset,objtopfirefoxoffset)
{
  // debugger;
    //var obj=document.getElementById("Online");
   var p = getposition(obj); 
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('onlinePanel').style.top=p['y']+"0px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			
		   document.getElementById('onlinePanel').style.top=p['y']-document.getElementById('onlineInfo').offsetHeight-40+"px";
			
        }
        else
        {
			document.getElementById('onlinePanel').style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('onlinePanel').style.left=p['x']+objleftoffset+"px";
     
}
function addFav(id)
{
	$.post('addFav.aspx',{id:id},function(data)
										  {
											  switch(data)
											  {
												  	case "1":alert("你还没有登录!只有登录会员才享有此功能!");
													break;
													case "2":alert("添加收藏失败,请与管理员联系!");
													break;
													case "3":alert("添加成功!该商品已经在您的收藏里!");
													break;
													case "4":alert("该商品已经在您的收藏里!");
													break;
													default: alert("内部错误!请联系管理员!");
													break;
											  }
											  }
										  );
}

function getBuyList(obj,show)
{

    $("#buyListInfo").html('<img src="images/ajax-loader.gif" />');
	buyListShow();
	if(show==1)
	{
		showBuyList(obj,-410,23,0);
		$.post("getShoppingCart.aspx",{},function(data)
												  {
													 $("#buyListInfo").html(data);  
												  });		
		
	}
	else
	{
		showBuyList(obj,-505,23,0);
		$.post("getBuyRecord.aspx",{},function(data)
												  {
													 $("#buyListInfo").html(data);  
												  });		
	}
}
function buyListShow()
{
	$("#buyList").show();
	closeAllClass();
	DDLHide();
}
function buyListNoShow()
{
	$("#buyList").hide();
	DDLShow();
}
function showBuyList()
{
	
}
function showBuyList(obj,objleftoffset,objtopoffset,objtopfirefoxoffset)
{
  // debugger;
    //var obj=document.getElementById("Online");
   var p = getposition(obj); 
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
   {
        document.getElementById('buyList').style.top=p['y']+"0px";
   }
   else
   {
        if(objtopoffset == 0)
        { 
			
		   document.getElementById('buyList').style.top=p['y']-document.getElementById('buyListInfo').offsetHeight-40+"px";
			
        }
        else
        {
			document.getElementById('buyList').style.top=p['y']+objtopoffset+"px";
        }
   }
   document.getElementById('buyList').style.left=p['x']+objleftoffset+"px";
     
}