﻿// JScript 文件
//全选
function _selectallprodcut(){
    var checkbox=document.getElementsByTagName("input");
    for(var i=0;i<checkbox.length;i++){
        if(checkbox[i].id.substring(0,14)=="selectProduct_" && checkbox[i].type=="checkbox")
        { checkbox[i].checked=true;}
    }
}

//全不选
function _unselectallprodcut(){
    var checkbox=document.getElementsByTagName("input");
    for(var i=0;i<checkbox.length;i++){
        if(checkbox[i].id.substring(0,14)=="selectProduct_" && checkbox[i].type=="checkbox")
        { checkbox[i].checked=false; }
    }
}

//contact now
function _productscontactnow(startC,endC,charList){
  if(endC-startC!=charList.length)
  {
    alert("Please select at least one product/offer.");
  }
    var temp=getCheckedIdlist(startC,endC,charList);
     temp=temp.substring(0,temp.length-1);
        if(temp!=""){
            window.location.href="/inquiry-basket.aspx?Item="+temp;
        }
        else
            alert("Please select at least one product/offer.");
}
//更新的contact now 全盘发送
function _productscontactnowall(type,startC,endC,charList,keyword){
  if(endC-startC!=charList.length)
  {
    alert("Please select at least one product/offer.");
  }
    var temp=getCheckedIdlist(startC,endC,charList);
     temp=temp.substring(0,temp.length-1);
        if(temp!=""){
            window.location.href="/inquiry-basket.aspx?Item="+temp+"&keyword="+type+";"+keyword;
        }
        else
            alert("Please select at least one product/offer.");
}

//add to basket
function _productsaddtobasket(temptype,startC,endC,charList)
{
    if(endC-startC!=charList.length)
    {
    alert("Please select at least one product/offer.");
    }
    var temp=getCheckedIdlist(startC,endC,charList);
    temp=temp.substring(0,temp.length-1);
    if(temp!="")
    {
        window.open("/addtobasket.aspx?item=" + temp+"&tp="+temptype );
    }
    else
        alert("Please select at least one product/offer.");
    
}
//vb页面的改进
function _productsaddtobasket_vb(startC,endC,charList)
{
    if(endC-startC!=charList.length)
    {
    alert("Please select at least one product/offer.");
    }
    var temp=getCheckedIdlist(startC,endC,charList);
    temp=temp.substring(0,temp.length-1);
    if(temp!="")
    {
        window.open("/addtobasket.aspx?item=" + temp );
    }
    else
        alert("Please select at least one product/offer.");
    
}


function PageChange()
{
  
  $("rollpage").value = $("choice").value
}

function _sort(sel)
{    
    $("choice").value = $(sel).value;
    $("form1").submit();
}



function _onload(key)
{
    var setkey="";
    switch(key)
    {
    case "i": setkey="Importance";  break;
    case "n": setkey="Name";break;
    case "t": setkey="Time";  break;
    default :setkey="Importance"; break;
    }
     $("select1").value = setkey;     
     $("select2").value = setkey;
}

function _setsorturi(rep,key)
{
    var outUri="";
    var uri = location.href;
    
    var uri = uri.split("/");
    for(i= 0; i < uri.length ; i++)
    {    
        if(i==3)
        {
        outUri += rep + key.substring(0,1).toLowerCase();
        }
        else 
        {
        outUri += uri[i];
        }        
        outUri += "/";
    }    
    
    outUri = outUri.substring(0,outUri.length-1);
    var lastkey=outUri.substring(outUri.length-5,outUri.length)
    //alert(lastkey);
    
    if(lastkey!=".html")
    {
    outUri += ".html"    
    }
    window.location = outUri;
   
}

function _sort(key)
{
    var outUri="";
    var isSetSk=false;
    var uri = location.href;
    
    var uri = uri.split("&");
    for(i= 0; i < uri.length ; i++)
    {
        outUri += "&";
        if(uri[i].substring(0,7).toLowerCase() == "sortkey")
        {
        outUri += "sortkey=" + key.substring(0,1).toLowerCase();
        isSetSk=true;
        }
        else 
        {
        outUri += uri[i];
        }
    }    
    if(!isSetSk)
    {
        outUri += "&sortkey=" + key.substring(0,1).toLowerCase();
    }
    outUri = outUri.substring(1,outUri.length);    
    window.location = outUri;
}

function showValue()
{
    var val = document.getElementById('showValue');
    var img = document.getElementById('showImage');
    var Infomation = document.getElementById('InfoText');
    var hiddenValue = document.getElementById('hiddenValue');
    var hiddenFlag = document.getElementById('hiddenFlag');
    
    if(hiddenValue.value=="")
    {
        val.style.display = "none";
        img.style.display = "block";
        Infomation.style.display = "block";
    }
    else
    {
        if(hiddenFlag.value == "2" || hiddenFlag.value == "3")
        {
            val.style.display = "block";
            img.style.display = "none";
        }
        else
        {
            val.style.display = "none";
            img.style.display = "block";
        }
        Infomation.style.display = "none";
    }
    
}

//将页面添加到收藏夹
function addBookmark(title,url) 
{
    if (window.sidebar) 
    { 
        window.sidebar.addPanel(title, url,""); 
    } 
    else 
    if( document.all ) 
    {
        window.external.AddFavorite( url, title);
    } 
    else 
    if( window.opera && window.print ) 
    {
        return true;
    }
}


//将页面发送到邮箱
function emailThisPage() 
{
    window.location="/sendmail.aspx?url=" + top.window.location.href;
}

//计算Contans输入的内容长度
function checkLen(term)
{
    document.all.termLen.value=1000-term.value.length;
    if (document.all.termLen.value<=0)
    {
        alert("您输入的消息过长！");
        term.value=term.value.substring(0,1000);
    }
}

function Check()
{
    var fm = document.FormMsg; 
    fm.message.value = fTrim(fm.message.value); //Trim the input value. 
    if( fm.message.value == "")
    {
        window.alert("\内容不能为空！");
        fm.message.focus();
        return false;
    }  
    return true;
}

function fTrim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
}


//BuyOffer搜索
function buyOfferSearch()
{
    var _keywords = document.getElementById("ucSearch_searchtext").value.replace(" ","+").replace("-","+").replace("&","+").replace("%","+");
	if(_keywords=="")
	{
	    return false;
	}
	else	
	{
	    window.location.href="/product-s/"+_keywords+".html";
	}
}


//全选和全不选
//sate 
function checkSelectOrClearAll(id,startC,endC,charList) {
  if(endC-startC!=charList.length)
  {alert('(checkSelectOrClearAll) Math Worry！')}//检查调用是否正确;
  var checkbox = document.getElementsByTagName("input");
  var mycheck_val = checkbox[id].checked;
  for(var i=0;i<checkbox.length;i++) 
  {
    if(checkbox[i].id.substring(startC,endC) === charList) 
    {
       checkbox[i].checked = mycheck_val;
    }
  }
}


  function getCheckedIdlist(startC,endC,charList)
  {
  if(endC-startC!=charList.length)
  {
    alert('(getCheckedIdlist) Math Worry?');
  }//检查调用是否正确;
  
  var checkbox = document.getElementsByTagName("input");
  var getIDList = "";
  for(var i=0;i<checkbox.length;i++) {
    if(checkbox[i].checked === true && checkbox[i].id.substring(startC,endC)===charList){
      getIDList += checkbox[i].value+",";
    }
  }
  return getIDList;
}
