﻿function $(getid){return document.getElementById(getid); }

//搜索类型切换
//  var act=0;
//	function show(id,notopen) {if (id != 8) {
//	        for (i = 0; i < 8; i++) {
//	            if (i == id) { $("menu" + i).className = "block"; }
//	            else { $("menu" + i).className = ""; } 
//	        } 
//	    }
//		act = id;
//		if (!notopen) {
//		    search();
//		}
//	}
//去左空格
function ltrim(s){return s.replace( /^\s*/, "");}
//去右空格
function rtrim(s){return s.replace( /\s*$/, "");}
//去左右空格
function trim(s){return rtrim(ltrim(s));}
//批量替换指定字符
String.prototype.replaceAll = function(s1,s2){return this.replace(new RegExp(s1,"gm"),s2);}
//替换非法字符
function changestr(strs){
    strs=strs.replace(/\(/g,"");
    strs=strs.replace(/\)/g,"");
    strs=strs.replace(/\[/g,"");
    strs=strs.replace(/]/g,"");
    strs=strs.replace(/\"/g,"");
    strs=strs.replace(/\\/g,"");
    strs=strs.replaceAll("'","");
    strs=strs.replaceAll("/","");
    strs=strs.replaceAll(" ","");
    strs=strs.replaceAll("　","");
    return trim(strs);
}
/*-----------输入框自动提示_Begin------------------*/
var typeid;//获取搜索的分类信息
var isloadAutoPrompt=false;
function handle(){
  $("shownr").innerHTML="";
  if(isloadAutoPrompt){//验证是否允许加载提示功能
    var inputString = document.getElementById("txtkey").value;
    if(inputString.length == 0){$('shownr').style.display="none";}
    else{
        var str="/ajax/bakdatatoSearch.aspx?queryString="+encodeURI(inputString)+"&typeid="+typeid;
        SendChange(str);
    }
  }
}
//--------------------------------//
var xmlHttp;
function SendChange(url){
   createXMLHTTP();
   xmlHttp.onreadystatechange=function(){
   if(xmlHttp.readyState==4){
     if(xmlHttp.status==200){
       if(xmlHttp.responseText.length>0){
         $("shownr").style.display="block";
         $("shownr").innerHTML=xmlHttp.responseText+"<li class=\"close\"><a href=\"javascript:void(0)\" onclick=\"closetishi()\">关闭提示</a></li>";}}
     else{$("shownr").style.display="block"; $("shownr").innerHTML=xmlHttp.responseText;}}}
   xmlHttp.open("POST",url,false); 
   xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
   xmlHttp.send(null);     
} 
/*--------------------------------
function createXMLHTTP(){
  if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest();}
  else if(window.ActiveXObject){
    try{ xmlHttp=new ActiveXObject("Msxml12.XMLHTTP");}catch(e){}
    try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
    if(!xmlHttp){ return false;}}}*/
//创建文本框的触发事件
function chkbrowser()
{
    if(/msie/i.test(navigator.userAgent)){//IE
       document.getElementById('txtkey').attachEvent('onpropertychange',handle);}
    else{//非IE，如Firefox等
        document.getElementById('txtkey').addEventListener("input",handle,false);
        document.getElementById('txtkey').watch('a', fn);}
}
//选择自动提示的记录并运行查询
function selectkey(tishikey,react){
    $("txtkey").value=tishikey;
    $('shownr').style.display="none";
    search(tishikey);
    //window.location.href = "/?act=" + encodeURI(react) + "&key=" + encodeURI(changestr(tishikey));
}
//关闭提示内容
function closetishi(){document.getElementById("shownr").style.display="none";}
/*-----------输入框自动提示_End------------------*/
//搜索
function search(act){
    var key=$("txtkey").value.replace(/\s/ig, "");
    if(key.length>0){
      if(key.length>25)key=key.substring(0,25);//搜索关键字长度最多50个字符
      if((act+"").toLowerCase()!="express"){
        window.location.href = "/?act=" + encodeURI(act) + "&key=" + encodeURI(changestr(key));}
      else{//报价搜索
	    if(parent.window.location.href.toLowerCase().indexOf("key")>0)
	      window.location.href = "/express/expresslist.aspx?key=" + encodeURI(changestr(key));
	    else
	      window.open("/express/expresslist.aspx?key=" + encodeURI(changestr(key)));
	  }
    }
    else{
        //$("txtkey").focus();
        window.location.href = "/?act=" + encodeURI(act);
    }
}
//====================提问验证===============================
var maxnumlen = 240;//最大字数限制
var defaultshow = "您还可以输入<b id=\"shownumlen\">"+maxnumlen+"</b>字";
var errorshow = "<font color=\"#db0000\">详细描述已经达到长度限制.</font>";
var contentfont = "请详细描述您所遇到的问题或想要的结果，有助于神州网友给出准确的答案。";//描述框内默认值
//计算文本框内的字数
function jsnumlen(){
    var str = $("txtcontent").value;
    if(str != null && str != ""){
        var numlen = parseInt(maxnumlen - parseInt(str.length));
        if(numlen>=0) 
        {
            if($("shownumlen")) $("shownumlen").innerHTML=numlen;//未超出最大字数
            else $("chknumlen").innerHTML=defaultshow.replace(maxnumlen,numlen);
        }
        else if(numlen<0) $("chknumlen").innerHTML=errorshow;//已超出
    }
    else
    { $("chknumlen").innerHTML=defaultshow;}
}
//获取焦点和失去焦点时
function shownumlen(flag){
    var content = $("txtcontent").value;
    if(content==contentfont){ $("txtcontent").value = ""; content = ""; $("txtcontent").style.color = "#333";}
    
    
    if(content == null || content == ""){
        var str="";
        if(flag==1) str = "<span id=\"chknumlen\">"+defaultshow+"</span>";
        $("chkcontent").innerHTML = str;
    }
}
//清空提问控件值
function resetasktj(){
  //$("txtusername").value = "神州乐器网友";  $("chkusername").innerHTML = "";
  $("txttitle").value = "";                 $("chktitle").innerHTML = "";
  $("txtcontent").value = "";               $("chkcontent").innerHTML = "";  
}
//加入收藏
function SaveSite(title, url){ 
if (document.all) 
    window.external.AddFavorite(url, title); 
else if (window.sidebar) 
    window.sidebar.addPanel(title, url, "") 
}
//收缩/扩展编辑框
var oldheight = 64;
function changeControl(obj,act){
    if($(obj)){
        if(act==1)
        { oldheight += 32;}
        else
        { oldheight = oldheight>64 ? (oldheight-32):oldheight;}
        $(obj).style.height = oldheight + "px";
    }
}
//========//验证所有提问控件值、提交提问信息===========
function chkasktj(){
    //if($("txtusername").value.replace(/\s/ig,"") == ""){$("chkusername").innerHTML="<font color=\"#db0000\">请输入您的姓名或昵称.</font>";$("txtusername").focus();return false;}
    //else{$("chkusername").innerHTML="";}
    
    if($("txttitle").value.replace(/\s/ig,"") == ""){$("chktitle").innerHTML="<font color=\"#db0000\">请输入您要提问的问题.</font>";$("txttitle").focus();return false;}
    else{$("chktitle").innerHTML="";}
    
    //if($("txtcontent").value.replace(/\s/ig,"") == ""){
    //    $("chkcontent").innerHTML="<span id=\"chknumlen\"><font color=\"#db0000\">请详细描述您要提问的问题或建议.</font></span>";return false;}
    if($("txtcontent").value.length>maxnumlen){ 
        $("chkcontent").innerHTML="<span id=\"chknumlen\"><font color=\"#db0000\">详细描述已经达到长度限制.</font></span>";return false;}
    if($("txtcontent").value == contentfont){ document.getElementById("txtcontent").value="如题";}
    
    var str="/AddAsk.aspx?username="+escape("神州乐器网友")+"&title="+escape($("txttitle").value)+"&content="+escape($("txtcontent").value);
    SendAdd(str);
}
//---------------------------------//
var xmlHttp;
function SendAdd(url){
  createXMLHTTP();
  xmlHttp.onreadystatechange=function(){
  if(xmlHttp.readyState==4){
       if(xmlHttp.status==200){
           var spl=xmlHttp.responseText.toString().split("##");
           spl[0]=(spl[0]!=null&&spl[0]!="")?parseInt(spl[0]):0;
           spl[1]=(spl[1]!=null&&spl[1]!="")?(spl[1]+"_神州问吧"):"神州乐器网问吧";
           spl[2]=(spl[2]!=null&&spl[2]!="")?spl[2].toString():"http://ask.chinayq.com/Knowledge/";
           
           if(spl[0]>0){
                resetasktj();
                //var str = '<span class="true-bg"></span>';
                //str += '<span class="true-bt1">您的问题已经提交成功!</span>';
                //str += '<span class="true-bt2">请点击弹出对话框的“添加”按钮收藏问题页，以方便查看对此问题的回答；</span>';
                //str += '<span class="true-bt3">若没有弹出框或其它原因无法收藏，请<a href="javascript:void(0)" onclick="SaveSite(\''+spl[1]+'\',\''+spl[2]+'\')">点此收藏</a>。&nbsp;&nbsp;&nbsp;&nbsp;<a href="'+spl[2]+'" target="_blank">查看此问题</a></span>';
                
                //$("askModule").innerHTML=str;
                //SaveSite(spl[1],spl[2]);
                parent.window.location.href = spl[2];
           }
           else{alert("提问失败，请重试或联系技术人员.");}//+xmlHttp.responseText
       }
       else{alert("提问失败，请重试或联系技术人员!");}//+xmlHttp.responseText
  }}
  xmlHttp.open("POST",url,false); 
  xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  xmlHttp.send(null);     
} 
//-------------------------//
function createXMLHTTP(){
  if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest();}
  else if(window.ActiveXObject){
    try{ xmlHttp=new ActiveXObject("Msxml12.XMLHTTP");}catch(e){}
    try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
    if(!xmlHttp){ return false;}}}
//-----------------------//
//显示分类下的品牌
function ShowBrand(Id,styleT){
    if($("tc" + Id).style.display == "none"){//显示
        $("tm" + Id).className = "biaoti2" + styleT; $("tc" + Id).style.display = "block";}
    else{//隐藏
        $("tm" + Id).className = "biaoti" + styleT; $("tc" + Id).style.display = "none";}}
//显示/隐藏对应产品的报价信息
function showsupply(sid){
    if($("product"+sid) && $("price"+sid)){
        if($("price"+sid).style.display == "none"){//显示
            $("product"+sid).className = "yes";
            $("price"+sid).style.display="block";
        }
        else{//隐藏
            $("product"+sid).className = "no";
            $("price"+sid).style.display="none";
        }
    }
}
//报价产品鼠标经过效果
function showprobg(act,id){
    if($("price"+id).style.display=="none"){
        if(act==1)$("product"+id).style.background="#BDD8FB";
        else if(act==0)$("product"+id).style.background="";
    }
}
