﻿String.prototype.trim = function()
{
 return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.len=function()
{
 return this.replace(/[^\x00-\xff]/g,'aa').length;
} 

function StringBuilder(value)
{
	this.strings = new Array("");
	this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
	if (value)
	{
		this.strings.push(value);
	}
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
	this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
	return this.strings.join("");
}

function subString(str, len, ignoreDot)
{
	var newLength = 0;
	var newStr = "";
	var chineseRegex = /[^\x00-\xff]/g;
	var singleChar = "";
	var strLength = str.replace(chineseRegex,"**").length;
	for(var i = 0;i < strLength;i++)
	{
 singleChar = str.charAt(i).toString();
		if(singleChar.match(chineseRegex) != null)
		{
			newLength += 2;
		}	
		else
		{
			newLength++;
		}
		if(newLength > len)
		{
			break;
		}
		newStr += singleChar;
	}
	
	if(ignoreDot && strLength > len)
	{
	 newStr += "...";
	}
	return newStr;
}

function $(objName)
{
 
 if(document.getElementById)
 {
 return document.getElementById(objName );
 }
 else if(document.layers)
 {
 return eval("document.layers['" + objName +"']");
 }
 else
 {
 return eval('document.all.' + objName);
 }
}

function go_Search()
{
	window.open("http://sosu.cmfu.com/genius/Result.aspx?k="+ escape(document.all("k").value) +"&t="+document.all("t").value);
	return false;
}

//function TabSearch()
//{
// if(event.keyCode == 13)
// { 
// go ();
// } 
//}
//function opwin(keywords,type){ window.open("http://sosu.qidian.com/search.aspx?k="+keywords+"&t="+type); }
//function go(){
// var key = $("txtwords").value;
// key = key.replace("请输入",""); 
// var index = $("searchtype").selectedIndex;
// var type= $("searchtype").options[index].value; 
// if(key == null || key.length==0)
// {
// alert("请输入搜索关键字");
// return false;
// }
//	 else if(type.indexOf('ft') != -1 && key.length < 2) 
//	 {
//	 alert("请输入2个或以上字符");
//	 return;
//	 } 
//	 key = key.replace(/</g, "");
//	 key = key.replace(/>/g, ""); 
// opwin(key,type);
//}

function checkLoginByCookie()
{
 var cookieId="AUTHTEST";
 if(window.location.href.toLowerCase().indexOf("qidian.com") > -1)
 {
 cookieId="cmfuToken";
 }

 if((GetCookie(cookieId)!=null && GetCookie(cookieId).length > 0 ))
 {
 return true;
 }
 return false;
}

function GetCookie(cookieName) 
{
 var cookieString = document.cookie;
 
 var start = cookieString.indexOf(cookieName + '=');
	
	

 // 加上等号的原因是避免在某些 Cookie 的值里有
 // 与 cookieName 一样的字符串。
	
 if (start == -1) // 找不到
 return null;

 start += cookieName.length + 1;
 var end = cookieString.indexOf(';', start);
 if (end == -1) return unescape(cookieString.substring(start));
 return unescape(cookieString.substring(start, end));
}
function getUrlParam(name)
{ 
 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)","i"); 
 var r = window.location.search.substr(1).match(reg); 
 if (r!=null) 
 {
 return unescape(r[2]);
 }
 else
 { 
 return null; 
 }
}

//切换Tab
//function switchTab(divName, divTag, divID)
//{
// if(divID==1){
// document.getElementById(divName+"1").style.display="";
// document.getElementById(divName+"2").style.display="none";
// MM_showHideLayers(divTag + "B",'','show');
// MM_showHideLayers(divTag + "A",'','hide');
// }
// else{
// document.getElementById(divName+"2").style.display="";
// document.getElementById(divName+"1").style.display="none";
// MM_showHideLayers(divTag + "A",'','show');
// MM_showHideLayers(divTag + "B",'','hide'); 
// } 
//}

function MM_showHideLayers() { //v9.0
 var i,p,v,obj,args=MM_showHideLayers.arguments;
 for (i=0; i<(args.length-2); i+=3) 
 with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
 if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
 obj.visibility=v; }
}
