﻿ function IsShoppingLogInQuery(){
      var html = $.ajax({
      url: "CheckService.aspx?IsLogIn=check",
      async: false
      }).responseText; 
      if (html=="success")return true;
      else{return false;}
  }
  
function load_cartCount(){
    $.ajax({
             url: "SpringService.asmx/load_cartCount",
             type: "POST",
             contentType: "application/json", 
             dataType:"json",
             data: "{}",      
             success: function(result) {  
                  $("#cart_count_div").empty().append("("+result+")");    
             }
            });
}
function addCart(docType,documentId,redirect){    
    var wnd = $(window);
    var doc = $(document);
    
    
    if(wnd.height() > doc.height()){  
      wHeight = wnd.height(); 
    }
    else{
      wHeight = doc.height();  
    }
      
    $("body").append("<div id='shopping_cart_cover'></div>");
    $("#shopping_cart_cover").width(wnd.width()).height(wHeight).css({'position':'absolute','left':'0px','top':'0px','z-index':'1000','background':'lightgrey','filter':'alpha(opacity=40)','opacity':'0.4'});
    
    $.ajax({
             url: "SpringService.asmx/addCart",
             type: "POST",
             contentType: "application/json", 
             dataType:"json",
             data: "{'docType':'" + docType + "','documentId':'" + documentId + "'}",
             success: function(result) {  
                 if(result["message"]!=""){
                    alert(result["message"]);
                 }else{
                   
                   //by Mahongtao Begin
                   
                   writeCookie('ShoppingUrl',location.href,24);
                   if(!redirect)
                   {
                       location.href='ShoppingCart.aspx';
                   }
                   else
                   {
                       $.hidePreviewDialog();
                       alert("This item has been added to your cart.");
                   }
                   
                   //by Mahongtao End
                   
                    $("#cart_count_div").empty().append("("+result["cartCount"]+")");
                    
                    
                 }
                  $("#shopping_cart_cover").remove();
              
             }
            });
   
}
function delete_cart(shoppingCartId){
 
     var wnd = $(window);
    var doc = $(document);
    if(wnd.height() > doc.height()){  
      wHeight = wnd.height(); 
    }
    else{
      wHeight = doc.height();  
    }
      
    $("body").append("<div id='shopping_cart_cover'></div>");
    $("#shopping_cart_cover").width(wnd.width()).height(wHeight).css({'position':'absolute','left':'0px','top':'0px','z-index':'1000','background':'lightgrey','filter':'alpha(opacity=40)','opacity':'0.4'});

    $.ajax({
             url: "SpringService.asmx/delete_cart",
             type: "POST",
             contentType: "application/json", 
             dataType:"json",
             data: "{'shoppingCartId':'" + shoppingCartId + "'}",
             success: function(result) {  
                 if(result["message"]!=""){
                    alert(result["message"]);
                 }else{
                    $("#cart_count_div").empty().append("("+result["cartCount"]+")");
                    $("#ctl00_ContentPlaceHolder1_shopping_cart_"+shoppingCartId).remove();    
                 }
                  $("#shopping_cart_cover").remove();
              
             }
            });
}
function login_shopping(){
    self.location.href="ShoppingCart.aspx";
}



$.showCheckOutDlg=function(CheckOutPage){
  var wnd = $(window);
  var doc = $(document);
  if(wnd.height() > doc.height()){  
      wHeight = wnd.height(); 
  }
  else{
      wHeight = doc.height();  
  }

 
  $("body").append("<div id='check_out_bgDiv'></div><div id='checkout_bgDiv' style='position:absolute; z-index:1001; margin:-200px 0 0 0px;text-align:center;top:40%; left:25%;'></div>");
  $("#check_out_bgDiv").width(wnd.width()).height(wHeight).css({'position':'absolute','left':'0px','top':'0px','z-index':'1000','background':'lightgrey','filter':'alpha(opacity=40)','opacity':'0.4'});
  $("#checkout_bgDiv").load(CheckOutPage);
}
$.hideCheckOutDialog=function()
{
  $("#check_out_bgDiv").remove();
  $("#checkout_div").fadeOut();
}
function OpenCheckOutDlg(){
  if(!IsLogInQuery){
      OpenLoginDlg();
      document.documentElement.scrollTop=0;
      return false;
  }
  document.documentElement.scrollTop=0;
  $.showCheckOutDlg('CheckOut.html');
 
}


$.showCreateProfileHitDlg=function(CreateProfileHitPage){

  var wnd = $(window);
  var doc = $(document);
  if(wnd.height() > doc.height()){  
      wHeight = wnd.height(); 
  }
  else{
      wHeight = doc.height();  
  }
  $("body").append("<div id='CreateProfileHit_bgDiv'></div><div id='CreateProfileHitbgDiv' style='position:absolute; z-index:1001; margin:-200px 0 0 -150px;text-align:center;top:50%; left:50%;'></div>");
  $("#CreateProfileHit_bgDiv").width(wnd.width()).height(wHeight).css({'position':'absolute','left':'0px','top':'0px','z-index':'1000','background':'lightgrey','filter':'alpha(opacity=40)','opacity':'0.4'});
 
 
   $.ajax({
       url:CreateProfileHitPage,
       success:function(data,status){
           //$("#loginbgDiv").load(loginPage);
           $("#CreateProfileHitbgDiv").html(data);
       },
       error:function(xmlhttprequest,error){
           $("#CreateProfileHitbgDiv").html(error);
       }
    });
}
$.hideCreateProfileHitDialog=function()
{
  $("#CreateProfileHit_bgDiv").remove();
  $("#CreateProfileHit_div").fadeOut();
}
function OpenCreateProfileHitDlg(){
  if(!IsLogInQuery){
      $.hideCreateProfileHitDialog();
      OpenLoginDlg();
      document.documentElement.scrollTop=0;
      return false;
  }
 
  document.documentElement.scrollTop=0;
  $.showCreateProfileHitDlg('CreateProfileHit.aspx');
 
}



