﻿





var vl = new Specials.WSSpecials();
var B_ID ='0';
var numperpage=24;
var id='0';
var sortby;
var NPP=24;
var load='0';
var i;
var f='';
var t=0;
var pr='';
var lsbox=true;
var pty='';
var spec='0';

function T_Load(CID,BID,NP,PAGETYPE,SpecField)
{
$get("divWait").style.display="inline";

 vl.DeletePaging();
    var ct=checkCookie("lp");
  
    if(ct!='' )
   {
       NP=ct;
       
   }
  
    var ct1=checkCookie("lf");
    if(ct1!='' )
   {
       f=ct1;
       
   }
     var pr1=checkCookie("pr");
    if(pr1!='' )
   {
       pr=pr1;
       
   }
      var spc=checkCookie("Spec");
    if(spc!='' )
   {
       spec=spc;
       
   }
   else{
    spec=SpecField;
   }
    var st=checkCookie("St");
    if(st!='' )
   {
      sortby=st;
       
   }else
   {
   sortby='lowestprice desc'
   }

    
    id=unescape(CID); 
    if(BID=='0')
    {
      if($get('selBrand')!=null)
        B_ID =$get('selBrand').value;
      var br=checkCookie("br");
      if(br!='')
      {
        B_ID =br;
           
      }
    }
    else
    {
        B_ID =BID;
    }
    pty=PAGETYPE;
 
    t=$get("ctl00_ContentPlaceHolder1_templatID").value;
   

    vl.T_BrandCategoryListing(CID,B_ID ,sortby,NP,NPP,f,t,pr,pty,spec,D)

}


function RunOnce()
{vl.BPaging(h)}
function pageLoad(sender, e) 
{
   
   vl.DeletePaging();
 }
function d_c()
{
    var CL=checkCookie("CL");
    if(CL!='' )
    {

     Delete_Cookie("CL",-7)
       
    }
    var lp=checkCookie("lp");

    if(lp!='' )
    {
     Delete_Cookie("lp",-7)
       
    }
    var lf=checkCookie("lf");
     if(lf!='' )
    {
     f='';
     Delete_Cookie("lf",-7)
      
    }
    var St=checkCookie("St");
     if(St!='' )
    {
     Delete_Cookie("St",-7)
       
    }
    var Sp=checkCookie("Spec");
     if(Sp!='' )
    {
     Delete_Cookie("Spec",-7)
       
    }
     var pr1=checkCookie("pr");
     if(pr1!='' )
    {
     pr='';
     Delete_Cookie("pr",-7)
       
    }
    var br1=checkCookie("br");
     if(br1!='' )
    {
    if($get("selBrand")!=null)
    {
     B_ID="0";
     }
     Delete_Cookie("br",-7)
     //    alert("d-c"+br1)
    }
  
    
}

function LoadPage()
{

$get("divWait").style.display="inline";
load='0';
f='';
if($get("selStrap")!=null)
{
var strap=$get("selStrap").value;
if(strap !='0')
{  
  if(f=='')
     f=strap;
  else
    f=f+'|'+strap;
    
}}
if($get("selMaterial")!=null)
{
var Material=$get("selMaterial").value;
if(Material !='0' )
{
  if(f=='')
     f=Material;
  else
    f=f+'|'+Material;
}}
if($get("selCaseShape")!=null)
{
var CaseShape=$get("selCaseShape").value;
if(CaseShape !='0' )
{
   if(f=='')
     f=CaseShape;
  else
    f=f+'|'+CaseShape;
}}
var PriceRang=$get("selPriceRang").value;

    pr=PriceRang;
if($get("selBrand")!=null)
{
var Brandid=$get("selBrand").value;

    B_ID =Brandid;
}
if($get("selStone")!=null)
{
var Stone=$get("selStone").value;
if(Stone !='0')
{
  if(f=='')
     f=Stone;
  else
    f=f+'|'+Stone;
    
}}
if($get("selMetal")!=null)
{
var Metal=$get("selMetal").value;
if(Metal !='0' )
{
  if(f=='')
     f=Metal;
  else
    f=f+'|'+Metal;
}}
var sortby=$get("spnSortBy").value;
//CL=strap+'|'+Metal+'|'+CaseShape+'|'+Complication +'|'+sortby;
CL=Stone+'|'+Metal+'|'+strap+'|'+Material+'|'+CaseShape+'|'+pr+'|'+sortby+'|'+B_ID;
setCookie("CL",CL)
setCookie("lf",f)
setCookie("St",sortby)
setCookie("pr",PriceRang)
setCookie("br",Brandid)
setCookie("Spec",spec)
Delete_Cookie("lp",-7)

vl.T_BrandCategoryListing(id,B_ID ,sortby,1,numperpage,f,t,pr,pty,spec,D)
}
function setSel(c)
{

   var s=c.split("|");
  
   if(lsbox && s.length>4)
   {
   //alert(lsbox);
    if($get("selStone")!=null)
    {
        $get("selStone").value=s[0];
        }
    if($get("selMetal")!=null)
    {
       $get("selMetal").value=s[1];
       }
       if($get("selStrap")!=null)
    {
       $get("selStrap").value=s[2];
       }
       if($get("selMaterial")!=null)
    {
       $get("selMaterial").value=s[3];
       }
       if($get("selCaseShape")!=null)
    {
       $get("selCaseShape").value=s[4];
       }
       if($get("selPriceRang")!=null)
    {
       $get("selPriceRang").value=s[5];
       }
       if($get("spnSortBy")!=null)
    {
       $get("spnSortBy").value=s[6];
       }
    
       if($get("selBrand")!=null)
       {
         $get("selBrand").value=s[7];
        }
   }
}


document.onclick=check; 
function check(e)
{


  var target = (e && e.target) || (event && event.srcElement); 
  
  //alert(target.firstChild.id)
  
  if (target.id.indexOf("A_BrandStyle")>-1)
 {
       
      d_c();
        }
       
}

function h(result)
{  
    if(result!='')
        d_c();
    
 } 


function D(result) 
{  

        $get('spnPaging').innerHTML ='';
        $get('spnBottomPaging').innerHTML ='';
        if (result == null) 
        {
        alert("no product found");
        }
        else 
        {
             var pd = $get('divProductList');
             pd.innerHTML = '';
             pd.innerHTML=result.W_Page+"<div class='spacer'></div>";
             pd.innerHTML=pd.innerHTML+"<div class='spacer'></div>";
            if( result.TotalCount<=NPP)
            {
                
                $get("spnViewAll").style.display="none";
                $get("spnBottomViewAll").style.display="none";
                $get('spnPaging').style.display="none";
                $get('spnBottomPaging').style.display="none";
                $get("spnViewAll_24").style.display="none";
                $get("spnBottomViewAll_24").style.display="none";
            }
            else
            {
                var sb = new Sys.StringBuilder();
                var functionName;
                functionName="Paging";
                var TotalNum = 0;
                var PageNumber=result.CurrentPage;
                TotalNum = result.TotalCount;
                var total_pages = Math.floor(TotalNum / NPP);
                if (TotalNum % NPP > 0) total_pages++;
                sb.append('<table cellpadding=\"1\"cellspacing=\"1\"><tr><td style=\"vertical-align: top;\"><div><span class=\"TextFont TextColor\" style=\"font-size:11px;\">Page&nbsp;</span></td><td style=\"vertical-align: top;\">');
                sb.append(String.format("<span style=\"position:relative;\"><select class='TextFont TextColor' style=\"font-size:11px;vertical-align: middle;\" name='selectPage' onchange='{0}(this.value,"+NPP+");'>",functionName));
                for (var i = 1; i <= total_pages; i++)
                {
                    if (i == PageNumber)
                    {
                        sb.append(String.format("<option value='{0}' selected>{1}</option>",i,i));
                       
                    }
                    else
                        sb.append(String.format("<option value='{0}'>{1}</option>",i,i));
                }
                sb.append(String.format("</select></span></td><td  style='vertical-align: top;'><span class='TextFont TextColor' style='font-size:11px;'> of {0}</span></td><td> ", total_pages));
                if (PageNumber > 1)
                {
                    sb.append(String.format("<span  class='PictureSpecs' style='border:0px;vertical-align: top;margin-top:30px;'><a href='#' onclick='{1}({0},{2});' style='margin-top:3px;'><img src=\"http://image.vialuxe.com/GlobalImages2/b_previous2_off.gif\" border=\"0\" id=\"imgpre\" onmouseover=\"MM_swapImage1(this.id,'','http://image.vialuxe.com/GlobalImages2/b_previous2_on.gif',1)\" onmouseout=\"MM_swapImgRestore2(this.id,'http://image.vialuxe.com/GlobalImages2/b_previous2_off.gif')\" ></a>&nbsp;</span> ",result.CurrentPage-1,functionName,NPP));
                }
                if (PageNumber < total_pages)
                {
                    sb.append(String.format("<span  class='PictureSpecs' style='border:0px;vertical-align: top;margin-top:30px;'><a href='#' onclick='{1}({0},{2});' style='margin-top:3px;'><img src=\"http://image.vialuxe.com/GlobalImages2/b_next2_off.gif\" border=\"0\" id=\"imgnext\" onmouseover=\"MM_swapImage1(this.id,'','http://image.vialuxe.com/GlobalImages2/b_next2_on.gif',1)\" onmouseout=\"MM_swapImgRestore2(this.id,'http://image.vialuxe.com/GlobalImages2/b_next2_off.gif')\" ></a></span>  ",result.CurrentPage+1,functionName,NPP));
                    sb.append("&nbsp;");
                }
               
                $get('spnBottomPaging').innerHTML = sb.toString().replace("imgpre","bottomimgpre").replace("imgnext","bottomimgnext")+"</td></tr></table>";
                $get('spnPaging').innerHTML = sb.toString().replace("imgpre","topmimgpre").replace("imgnext","topimgnext")+"</td></tr></table>";
                if(numperpage==NPP)
                {
                    $get("spnViewAll").style.display="inline";
                    $get("spnBottomViewAll").style.display="inline";
                    $get('spnPaging').style.display="inline";
                    $get('spnBottomPaging').style.display="inline";

                }
                else if(numperpage==100000)
                {
                    $get("spnViewAll_24").style.display="inline";
                    $get("spnBottomViewAll_24").style.display="inline";
                }
               
           }
      }
   
     $get("divWait").style.display="none"; 
    
     if(result.LoadSelectBox !=null && result.LoadSelectBox)
     {
       
        var CL=checkCookie("CL");
        if(CL!='' ){setSel(CL);}
      
      }
      else
      {
       // alert("PP-delete")
        d_c();
      }
}

function Paging(C_P,num)
{//alert(C_P)
load='0';
var sortby=$get("spnSortBy").value;
///$get("p").value=C_P;
setCookie("lp",C_P)
//alert(getCookie("lpage"))
vl.T_BrandCategoryListing(id,B_ID,sortby,C_P,num,f,t,pr,pty,spec,D)


//LoadPage();
}
function ViewNumPage(c)
{

if( c==100000)
{
numperpage=100000;
$get("spnPaging").style.display="none";
$get("spnBottomPaging").style.display="none";
$get("spnViewAll").style.display="none";
$get("spnBottomViewAll").style.display="none";
$get("spnViewAll_24").style.display="inline";
$get("spnBottomViewAll_24").style.display="inline";
}
else
{
numperpage=NPP;
$get("spnPaging").style.display="inline";
$get("spnBottomPaging").style.display="inline";
$get("spnViewAll").style.display="inline";
$get("spnBottomViewAll").style.display="inline";
$get("spnViewAll_24").style.display="none";
$get("spnBottomViewAll_24").style.display="none";
}
LoadPage()
}


function getCookie(c_name)
{
    if (document.cookie.length>0)
    { 
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        } 
    }
    return ""
}

function setCookie(c_name,value)
{

//var exdate=new Date();
    //exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value);
   // ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie(CookiesName)
{
username=getCookie(CookiesName)

return username;
}
function Delete_Cookie( name, value) 
{

document.cookie=name+ "=" +escape(value)+ "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
}