﻿// 说明：Javascript 获取链接(url)参数的方法 
// 整理：http://www.CodeBit.cn 
function getQueryString(name) 
{ 
  // 如果链接没有参数，或者链接中不存在我们要获取的参数，直接返回空 
  if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1) 
  { 
   		return ''; 
  } 
  // 获取链接中参数部分 
  var queryString = location.href.substring(location.href.indexOf("?")+1); 
  
  // 分离参数对 ?key=value&key2=value2 
  var parameters = queryString.split("&"); 
  var pos, paraName, paraValue; 
  for(var i=0; i<parameters.length; i++) 
  { 
	  // 获取等号位置 
	  pos = parameters[i].indexOf('='); 
	  if(pos == -1) { continue; }
	  // 获取name 和 value 
	  paraName = parameters[i].substring(0, pos); 
	  paraValue = parameters[i].substring(pos + 1); 
	  // 如果查询的name等于当前name，就返回当前值，同时，将链接中的+号还原成空格 
	  if(paraName == name) 
	  { 
	   		return unescape(paraValue.replace(/\+/g, " ")); 
	  } 
  } 
  return ''; 
}; 

//http://localhost/test.html?aa=bb&test=cc+dd&ee=ff 
//alert(getQueryString('test')); 

//打开网页库链接 
function s(l,id)
	{
		if(l==null || l=="")
         {
             var win = window.open("/portal/content.jsf?id="+id);					   
			//win.focus(); 
         }
		else if(l.indexOf("ttp")==-1)
	   	{
			var win =	window.open("content.jsf?t=14&id="+id);								   
			//win.focus(); 
		}
		else
		{
			var win = window.open(l);								   
			//win.focus();	
			
		}
	}

var stabid=0;
function inittype(){
	if(getQueryString("t"))
	{
		for(i=1;i<=6;i++){document.getElementById("stab"+i).className = "";}
		document.getElementById("stab"+getQueryString("t")).className = "cur";
		stabid=getQueryString("t");
	}
}

setTimeout("inittype()",500);

function settype(c){	
	for(i=1;i<=6;i++){document.getElementById("stab"+i).className = "";}
	c.className = "cur";
	stabid=c.id.substr(c.id.length-1,1);
}


function setsrch(c){	
settype(c);
btsearch();
}


//top查询按钮
    function btsearch()
    {
    	var keywords = document.getElementById('inputkeywords').value;
    	//var keytype = document.getElementById('keytype').value;
    	 
		var keytype=stabid;
		
		
		if(keywords.replace(/(^\s*)|(\s*$)/g, "")!="" && keywords!="输入关键词")    		
    	{
    		keywords = toUTF8(keywords);
    		if(keytype=="6")
    		{
    			//self.location = "http://www.baidu.com/s?si=www.tbtmap.cn&rn=10&&cl=3&ie=utf-8&ct=2097152&wd="+keywords 
    			window.top.location ="http://www.google.com/search?ie=utf-8&sitesearch=www.tbtmap.cn&hl=zh_CN&q="+keywords;
    			//self.location = "http://search.cn.yahoo.com/search?ei=utf-8&vs=www.tbtmap.cn&p="+keywords;
    		}
    		else
    		{
    			keywords = encodeURI(keywords);    		
        		window.top.location.href = "/portal/common/search2.jsf?k="+keywords+"&t="+keytype;
        	}
        }	
    }
	
    function toUTF8(szInput){ 
 var wch,x,uch="",szRet="";
 for (x=0; x<szInput.length; x++){
  wch=szInput.charCodeAt(x);
  if (!(wch & 0xFF80)){
   szRet += szInput.charAt(x);
  }
  else if (!(wch & 0xF000)){
   uch = "%" + (wch>>6 | 0xC0).toString(16) + 
      "%" + (wch & 0x3F | 0x80).toString(16);
   szRet += uch; 
  }
  else{
   uch = "%" + (wch >> 12 | 0xE0).toString(16) + 
      "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) +
      "%" + (wch & 0x3F | 0x80).toString(16);
   szRet += uch; 
  }
 }
 return(szRet);
}
 
    //top查询类型选择
	function showsearchbg(i)
	{
		var secToDo = 'search_bg_img' + i;
		var secToDoSrc = '/portal/image/search_bg_img'+ i +'_on.jpg';
		eval("document.all[secToDo].src=secToDoSrc;");
		for(var j=1;j<=6;j++)
		{
			if(j!=i)
			{
				var secNotDo = 'search_bg_img' + j;
				var secNotDoSrc = '/portal/image/search_bg_img'+ j +'.jpg';
				eval("document.all[secNotDo].src=secNotDoSrc;");
			}
		}
		document.getElementById('keytype').value = i;
		
	}

function showoutsearchbg(){
for(var j=1;j<=6;j++){
var secNotDo = 'search_bg_img' + j;
var secNotDoSrc = '/portal/image/search_bg_img'+ j +'.jpg';
eval("document.all[secNotDo].src=secNotDoSrc;");
}
}

//根据URL确定导航的active项
function showHeadActive(URL)
{
	
	if(URL.indexOf("专题样式模板")>0)
	{
			
		//document.getElementById("zhuanti-td").setAttribute("class","active"); 
		document.getElementById("zhuanti-td").className = "active";
		//alert(document.all['zhuanti-td'].getAttribute("class"));	

	}
}

//enter
function showSel()
{
  if(event.keyCode==13) 
  {
  		btsearch();
  }
 }
//iframe_set <iframe id="mainFramee2" src="" width="100%" height="20" name="mainFramee2" marginwidth="0" frameborder="0" height="50px" width="200px" onLoad="TuneHeight('mainFramee2')" scrolling="no" 

function TuneHeight(S) 
{ 
  try
  {
	var frm = document.getElementById(S); 
	var subWeb = document.frames ? document.frames[S].document : frm.contentDocument; 
	if(frm != null && subWeb != null) 
		{ 
			frm.height = subWeb.body.scrollHeight;
		} 
  }
  catch(e){}
} 

function isValidMail(sText){
 if(sText==null || sText=="")
 	return true;
 var reMail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
 return reMail.test(sText);
}

function isVailidInteger(sText){
 if(sText==null || sText=="")
 	return true;
 var reInteger = /^\d+$/;
 return reInteger.test(sText);
}

function Show_TabADSMenu(tabadid_num,tabadnum,tabCount){
	for(var i=0;i<tabCount;i++)
	{
		try{
			document.getElementById("tabadcontent_"+tabadid_num+i).style.display="none";
		}
		catch(e){}
	}
	for(var i=0;i<tabCount;i++){
		try{
			document.getElementById("tabadmenu_"+tabadid_num+i).className="";
		}
		catch(e){}
	}
	document.getElementById("tabadmenu_"+tabadid_num+tabadnum).className="TasADSOn";
	
	try{
		document.getElementById("tabadcontent_"+tabadid_num+tabadnum).style.display="block";
	}
	catch(e){}
}


