﻿// Trim
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
//Check Head Search Key
function CheckTbkey(source)
{
     var tbKey = document.getElementById(source);
     if(tbKey.value.Trim().length == 0)
     {
        alert("请输入要查询的关键字");
        tbKey.focus();
        return false;
     }
     else
     {
        return true;
     }
}

function DrawImage(ImgD,w,h)
{
    var flag = false;
    var MyImage = new Image();
    MyImage.src = ImgD.src;

    if(MyImage.readyState != "complete")
    {
        return false; 
    }
   
    if(MyImage.width > 0 && MyImage.height > 0)
    {  
        flag = true;
        if(MyImage.width / MyImage.height >= w / h)
        {
            if(MyImage.width > w)
            {
                ImgD.width = w;
                ImgD.height = (MyImage.height * w) / MyImage.width;
            }
            else
            {
                ImgD.width = MyImage.width;
                ImgD.height = MyImage.height;
            }
 
        }
        else
        {
            if(MyImage.height > h)
            {
                ImgD.height = h;
                ImgD.width = (MyImage.width * h) / MyImage.height;
            }
            else
            {
                ImgD.width = MyImage.width;
                ImgD.height = MyImage.height;
            }
 
        }
    }
}

function isExc(form)
{
    var values = "";
    var j = 0;
     for (var i=0;i<form.elements.length;i++)    
     {
          var e = form.elements[i];
         
          if (e.checked == true && e.type == "checkbox")
           {  
                if(values.Trim().length == 0)
                {
                    values = e.id;
                }
                else
                {
                    values += "," + e.id
                }
                j++;
           } 
     }

  if(j == 0)
  {
        alert('请选择要对比的商品。');
  }
  else  
  {
    window.open("Compare.aspx?ids=" + values);
  }
}
function Abcd()
{
     var selectedC =  document.getElementById("ctl00_ContentPlaceHolder1_DropBrand").value;
     var value =document.getElementById("c" + selectedC); 
     if(value != null)
     {
        value.innerHTML = value.innerHTML.replace(/<.*?>/g,"");
        value.className = "SelectClass";
     }
}
function sc4()
{
    var removeDiv= document.getElementById("removeDiv");

    if(document.documentElement.scrollTop > 200)
    { 
         if((document.documentElement.scrollHeight-document.documentElement.scrollTop) > 850)
         {
             removeDiv.style.marginTop=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("removeDiv").offsetHeight)/2 - 295)+"px";
         }
         else if(document.getElementById("Wool").offsetHeight > removeDiv.offsetHeight)
         { 
             removeDiv.style.marginTop = (document.getElementById("Wool").offsetHeight - removeDiv.offsetHeight) + "px";
         }
    }
    else
    {
         removeDiv.style.marginTop = "0px";
    }
}
function scall()
{
    sc4();
   Abcd();
}


function LoadCategoryList()
{
   var PhoneCategoryList = document.getElementById("PhoneCategoryList");
   var buttonMore = document.getElementById("buttonMore");
   if(PhoneCategoryList.offsetHeight >  72)
   {
       PhoneCategoryList.className = "ul_cent_list_01";
   }
   else if(PhoneCategoryList.offsetHeight <=  72)
   {
      buttonMore.style.display = "none";
   }
}
function MroCategory()
{
    var PhoneCategoryList = document.getElementById("PhoneCategoryList");
    var buttonMore = document.getElementById("buttonMore");
    buttonMore.style.display = "none";
    PhoneCategoryList.className = "ul_cent_list";
}
function autoExp()
{
     var query = location.search.substring(1);      
     var pairs = query.split("&");
     var queryString = "";
     var id,parent;
     for(var i = 0; i < pairs.length; i++)
      {
         var pos = pairs[i].indexOf('=');
         if (pos == -1) continue;
         var argname = pairs[i].substring(0,pos);
         if(argname == "id")
         {
            id = pairs[i].substring(pos+1);
         }
         else if(argname == "parent")
         {
            parent =  pairs[i].substring(pos+1); 
         }
     }
     var second = document.getElementById("c" + id),third = document.getElementById("c" + parent);
     var changeNgt = document.getElementById("changeNgt");
        if(second == null && third == null)
        {
                 
        }
        else if(second != null && third == null)
        {
            changeNgt.innerHTML = "<a href=\"PhoneList.aspx\" class=\"a20\">手机广场</a> >> " + second.innerHTML.replace(/<.*?>/g,"");
        }
        else
        {  
           changeNgt.innerHTML = "<a href=\"PhoneList.aspx\" class=\"a20\">手机广场</a> >> " + third.innerHTML.replace(/a17/g,"a20").replace(/a18/g,"a20") + " >> " + second.innerHTML.replace(/<.*?>/g,"");
        }
     if(second != null)
     {
        second.innerHTML = second.innerHTML.replace(/<.*?>/g,"");
        second.className = "SelectClass";
     }
     if(third != null)
     {
        third.innerHTML = third.innerHTML.replace(/<.*?>/g,"");
        third.className = "SelectClass";
     }
     var first;
     if(parent == "0")
     {
        first = second;
     }
     else
     {
        first = third;
     }
     if(first != null && first.offsetTop >=72)
     {
        var PhoneCategoryList = document.getElementById("PhoneCategoryList");
        var buttonMore = document.getElementById("buttonMore");
        buttonMore.style.display = "none";
        PhoneCategoryList.className = "ul_cent_list";
     }
}
function PhoneListOnload()
{
     LoadCategoryList();
     autoExp();
}
//转到List
function ClickToList()
{
    var DropFunction = document.getElementById("ctl00_ContentPlaceHolder1_DropFunction");
    var DropPhoneStyle = document.getElementById("ctl00_ContentPlaceHolder1_DropPhoneStyle");
    var DropSystem = document.getElementById("ctl00_ContentPlaceHolder1_DropSystem");
    var DropNetWord = document.getElementById("ctl00_ContentPlaceHolder1_DropNetWord");
    var DropOrderBy = document.getElementById("ctl00_ContentPlaceHolder1_DropOrderBy");
    var DropPageSize = document.getElementById("ctl00_ContentPlaceHolder1_DropPageSize");
    var lbPageInfo = document.getElementById("ctl00_ContentPlaceHolder1_lbPageInfo");
    var url = "PhoneList.aspx?condition=" + DropFunction.value + "," + DropPhoneStyle.value +"," + DropSystem.value + "," + DropNetWord.value+ "&order=" + DropOrderBy.value + "&size=" + DropPageSize.value + "&page=" + lbPageInfo.innerHTML.split("/")[0];;
    var DropBrand = document.getElementById("ctl00_ContentPlaceHolder1_DropBrand");
    if(DropBrand.value != 0)
    {  
        url += "&id=" + DropBrand.value + "&parent=0";
    }
     location.href = url;
}  
//转到Case
function ClickToCase()
{
    var DropFunction = document.getElementById("ctl00_ContentPlaceHolder1_DropFunction");
    var DropPhoneStyle = document.getElementById("ctl00_ContentPlaceHolder1_DropPhoneStyle");
    var DropSystem = document.getElementById("ctl00_ContentPlaceHolder1_DropSystem");
    var DropNetWord = document.getElementById("ctl00_ContentPlaceHolder1_DropNetWord");
    var DropOrderBy = document.getElementById("ctl00_ContentPlaceHolder1_DropOrderBy");
    var DropPageSize = document.getElementById("ctl00_ContentPlaceHolder1_DropPageSize");
    var lbPageInfo = document.getElementById("ctl00_ContentPlaceHolder1_lbPageInfo");
   
     var category = 0;
     var query = location.search.substring(1);      
     var pairs = query.split("&");
     var queryString = "";
     var id,parent;
     for(var i = 0; i < pairs.length; i++)
      {
         var pos = pairs[i].indexOf('=');
         if (pos == -1) continue;
         var argname = pairs[i].substring(0,pos);
         if(argname == "id")
         {
            id = pairs[i].substring(pos+1);
         }
         else if(argname == "parent")
         {
            parent =  pairs[i].substring(pos+1); 
         }
     }
     if(parent != null && parent != "0")
     {
        category = parent;
     }
     if(parent == "0")
     {
        category = id;
     }
    var url = "Phone.aspx?condition=" +category  +","+ DropFunction.value + "," + DropPhoneStyle.value +"," + DropSystem.value + "," + DropNetWord.value+ "&order=" + DropOrderBy.value + "&size=" + DropPageSize.value + "&page=" + lbPageInfo.innerHTML.split("/")[0];;
    location.href = url;
} 