﻿// JScript File
function loadtop()
{ $("divmain").innerHTML ="<img alt='tat ca limited' src='images/ajax-loader-bar.gif'  /></br> Đang tải dữ liệu ...";	
            new Ajax.Request("Ajax_LoadProduct.aspx?type=1&page=1",{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
            
            var b= request.responseText;
            if(b=="false")
            {
                $("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
            }
            else
            {
                $("divmain").innerHTML =b;
            }
             }});
}
function m_onControl(sVal)
{
//alert(sVal);
window.location ="index.aspx#tatca"
 $("divmain").innerHTML ="<img alt='tat ca limited' src='images/ajax-loader-bar.gif'  /></br> Đang tải dữ liệu ...";	
            new Ajax.Request("Ajax_LoadProduct.aspx?type=1&page="+ sVal,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
                  		
            var b= request.responseText;
            
            if(b=="false")
            {
                $("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
            }
            else
            {
                $("divmain").innerHTML =b;
            }
            
             }});
}
function addtocart(id)
{
            new Ajax.Request("Ajax_Cart.aspx?type=1&pid=" + id,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
                  		
            var b= request.responseText;
            if(b=="False")
            {
                //$("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
               // alert("Sản phẩm này đã hết hàng!");
               document.location ="MyAccount_login.aspx";
            }
            else if(b=="True")
            {
                //$("divmain").innerHTML =b;
                alert("Đã thêm 1 sản phẩm");
                loadmyCart();
            }
            else //inValidProduct
            {
            alert("Sản phẩm này không tồn tại!");
            }
            
           
             }});
}

function ProductDetail(id,cate)
{
            new Ajax.Request("Ajax_LoadProduct.aspx?type=2&pid=" + id,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
                  		
            var b= request.responseText;
            if(b=="False")
            {
                //$("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
                alert("This Product is Disable");
            }
           
            else 
            {
            $("divmain").innerHTML=b;
            }
            
           
             }});
}
function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function loadmyCart()
{

            new Ajax.Request("Ajax_Cart.aspx?type=5",{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
                      		
                var b= request.responseText;
               
                if(b=="False")
                {
                    $("spanCarts").innerHTML ="";
                }
               
                else 
                {
                
                    $("spanCarts").innerHTML="<font color='blue'>Bạn đã chọn: <a href='Mycart.aspx'>" +  b + " sản phẩm </a></font>";
                }
                
               
                 }});
}






 //=  userrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 function  loadPromotion()
 {
 //   alert("d");
//   if(gup("actq") && gup("page") && gup("menu"))
//   {
//                    var menu = gup("menu");
//                    var page = gup("page");

//                  
//                        new Ajax.Request("Ajax_LoadProduct.aspx?type=8&actq=view&menu=" + menu + "&page=" + page,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
//            
//                            var b= request.responseText;
//                            if(b=="False")
//                            {
//                                $("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
//                            }
//                            else 
//                            {
//                               $("divmain").innerHTML=b;
//                            }
//                       }});

//   }
 }
 
function  pageload() 
{

   if(gup("act") && gup("page") && gup("menu"))
   {
    
        var page = gup("page");
        var menu = gup("menu");
        var act = gup("act");
        if(act=="view")
        {
            new Ajax.Request("Ajax_LoadProduct.aspx?type=7&act=view&menu=" + menu + "&page=" + page,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){

            var b= request.responseText;
            if(b=="False")
            {
                $("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
            }
            else 
            {
                $("divmain").innerHTML=b;
            }
            }});
        }
            
         
   }
   else if(gup("cate")&& gup("page"))
   {

        var cid = gup("cate");
        var page = gup("page");

        new Ajax.Request("Ajax_LoadProduct.aspx?type=3&cid=" + cid + "&page=" + page ,{asynchronous:true,evalScripts:true,encoding:'UTF-8', onComplete:function(request){
        	
            var b= request.responseText;
            if(b=="False")
            {
            $("divmain").innerHTML ="<font color='red'>Không tìm thấy SP này</font>";
            }

            else 
            {
            $("divmain").innerHTML=b;
            }


            }});
                 
                
                 
   }
   else
   {
   loadtop();
        
   }
   loadmyCart();
        
}
