function getStringField(str,deli,pos)
{
	arr=str.split(deli);
	if (arr.length>=pos)
  {
    return arr[pos-1];
  }
  else
  {
    return "";
  }
}

function getStringFieldEnd(str,deli,pos)
{
	arr=str.split(deli);
	if (arr.length<pos) return "";
	var sss="";
	var cl=0;
	for (var i=0;i<str.length;i++)
  {
		if (str.substr(i,1) == deli)
    {
			cl++;
			if (cl==pos-1)
      {
				sss=str.substr(i+1);
				break;
			}
		}
	}
	return sss;
}

function getStringFieldEnd2(str,deli,pos) 
{
	arr=str.split(deli);
	if (arr.length<pos) return "";
	var sss="";
	for (var i=pos-1;i<arr.length;i++)
  {
    if (sss=="")
    {
		  sss=arr[i];
    }
    else
    {
      sss+=deli+arr[i];
    }
	}
	return sss;
}

// 获取年月日时分秒
function getCurTime()
{
  var now = new Date();
  var year = now.getYear();
  var month = now.getMonth()+1;
  var day = now.getDate();
  var hour = now.getHours();

  var minute = now.getMinutes();
  var second = now.getSeconds();

  if(minute<10)
  {
    minute = "0" + minute;
  }
  if(second<10)
  {
    second = "0" + second;
  }

  var time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

  return time;
}

// 获取年月日
function getCurTime2()
{
  var now = new Date();
  var year = now.getYear();
  var month = now.getMonth()+1;
  var day = now.getDate();

  if(month<10)
  {
    month = "0" + month;
  }
  if(day<10)
  {
    day = "0" + day;
  }

  var time = year + "-" + month + "-" + day;

  return time;
}

function getTime()
{
  var dd=new Date();
  return Math.floor(dd.getTime()/1000);
}

function getMicroTime()
{
  var dd=new Date();
  return dd.getTime();
}

function getTime2()
{
  var date=new Date();
  var hour="000"+date.getHours();
  var min="000"+date.getMinutes();
  var sec="000"+date.getSeconds();
  hour=hour.substr(hour.length-2);
  min=min.substr(min.length-2);
  sec=sec.substr(sec.length-2);
  return hour+":"+min+":"+sec;
}

if (!Array.prototype.pop)
{
  Array.prototype.pop = function()
  {
    var lastElement = this[this.length-1];
    this.length = Math.max(this.length-1,0);
    return lastElement;
  }
}

if (!Array.prototype.push)
{
  Array.prototype.push = function()
  {
    for(var i=0;i<arguments.length;i++)
    {
      this[this.length]=arguments[i];
    }
    return this.length;
  }
}

if (!Array.prototype.shift)
{
  Array.prototype.shift = function()
  {
    var firstElement = this[0];
    this.reverse();
    this.pop();
    this.reverse();
    return firstElement;
  }
}

if (!Array.prototype.splice) {
 Array.prototype.splice = function() {
  var start = arguments[0];
  var deleteCount = start+arguments[1];
  var deleteItem = this.slice(start,deleteCount);
  var beforeItem = this.slice(0,start);
  var afterItem = this.slice(deleteCount);
  this.length=beforeItem.length;
  var i;
  for (i=2;i<arguments.length;this[this.length]=arguments[i++]);
  for (i=0;i<afterItem.length;this[this.length]=afterItem[i++]);
  return deleteItem;
 }
}

if (!Array.prototype.unshift)
{
  Array.prototype.unshift = function()
  {
    var arr = new Array();
    for (var i=0;i<arguments.length;arr[i]=arguments[i++]);
    arr = arr.concat(this);
    this.length = 0;
    for (i=0;i<arr.length;this[i]=arr[i++]);
  }
}

Array.prototype.del=function(n) {  //n is begin as 0
  if(n<0)
  {
    return this;
  }
  else
  {
    return this.slice(0,n).concat(this.slice(n+1,this.length));
  }
}

Array.prototype.search = function(value)  //数组元素不能包含 ,┢
{
  re = new RegExp(value,[""]);
  return (this.toString().replace(re,"┢").replace(/[^,┢]/g,"")).indexOf("┢");
}

String.prototype.trim=function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

//字符串长度，一个中文字符2位
function _length(str)
{
	var len=0;
	for(var i=0;i< str.length;i++)
  {
	  if (str.charAt(i)>'~')
    {
      len+=2;
    }
    else
    {
      len++;
    }
  }
	return len;
}

//取字符串子串，一个中文字符2位
function _substring(str,len)
{
	var ln=0;
	var subs="";
	var flag2=0;
	for(var i=0;i< str.length;i++)
  {
		if (flag2==1)
    {
			subs+="..";
			break;
		}
		var flag=0;
		var s=str.substr(i,1);
		if (s.charAt(0)>'~') 
    {
			ln+=2;
			flag=1;
		} 
		else ln++;
		subs+=s;
		if (ln==len)
    {
			flag2=1;
			continue;
		}
		if (ln>len)
    {
			if(flag==1)subs=subs.substr(0,subs.length-1);
			subs+="..";
			break;
		}
	}
	return subs;
}

//消息长度:
//  中文为6位，经过escape后，中文格式如：%u4E2D
//  空格在url中为3位：%20 
function _URLLength(str)
{
	var len=0;
	for(var i=0;i< str.length;i++)
  {
		if (str.charAt(i)>'~')
    {
      len+=6; 
    }
		else if (str.charAt(i)==" ")
    {
      len+=3;
    }
		else
    {
      len++;
    }
	}
	return len;
}

//取消息子串：
//  中文为6位，经过escape后，中文格式如：%u4E2D
//  空格在url中为3位：%20 
function _URLSubstring(str,len)
{
	var ln=0;
	var subs="";
	for(var i=0;i< str.length;i++)
  {
		var s=str.substr(i,1);
		if (s>'~')
    {
			ln+=6;
		}
		else if (s==" ")
    {
			ln+=3;
		}
		else
    {
      ln++;
    }
		if (ln<=len)
    {
			subs+=s;
			if (ln==len) break;
		}
		else
    {
      break;
    }
	}
	return subs;
}

function HtmlMode(msg)
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.match(/MSIE \d\.\d/) == "MSIE 5.0"))
  {
		;
	}
  else
  {
		msg=msg.replace(new RegExp('<scr'+'ipt[^>]*?>.*?</scr'+'ipt>','g'), "") ;
		msg=msg.replace(new RegExp('\<\!\-\-.*?\-\-\>','g'), "") ;
	}
	msg=msg.replace('\<\!\-\-', "") ;
	msg+="</a>";
	msg=msg.replace(/(\r\n)/g,"<br>&nbsp;&nbsp;");
	return msg;
}

// url编码
function UrlEncode(text)
{
  return encodeURIComponent(text);
  //return text.replace(/&/g, '%26').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\"/g, '%22').replace(/</g, '%3C').replace(/>/g, '%3E');
}

// url解码
function UrlDecode(text)
{
  try
  {
    return unescape(text);
  }
  catch(e)
  {
    return text;
  }
}

// url解码2
function UrlDecode2(text)
{
  try
  {
    return decodeURIComponent(text);
  }
  catch(e)
  {
    return text;
  }
}

// url解码3
function UrlDecode3(text)
{
  try
  {
    return decodeURIComponent(text);
  }
  catch(e)
  {
    try
    {
      return unescape(text);
    }
    catch(e)
    {
      return text;
    }
  }
}

function HtmlEncode(text)
{
  var msg = text.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/\'/g, '&#039;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  msg = msg.replace(/\r\n/g, "<br>");
  return msg;
}

function HtmlDecode(text)
{
    return text.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&#039;/g, '\'').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

function msgFilter(msg)
{
  return msg;
  msg=msg.replace(/((?:kehu\.cn|qollar\.com|5107\.cn|tq\.cn|zoosnet\.net|live800\.com))/gi,"{内容屏蔽，53KF对此类行为表示谴责}");
  msg=msg.replace(/((?:洽谈通|忠仕|live800|qollar|恒聚|网站伴侣))/gi,"{内容屏蔽}");
  return msg;
}

function textCounter(obj,maxlength)
{
	if (obj.value.length>maxlength)
  {
		obj.value=obj.value.substr(0,maxlength);
	}
}

function getpara(strname)
{
  var hrefstr, pos, parastr, para, tempstr;
  hrefstr = window.location.href;
  pos=hrefstr.indexOf("#");
  pos=(pos==-1?hrefstr.length:pos);
  hrefstr=hrefstr.substring(0,pos);

  pos = hrefstr.indexOf("?");
  parastr = hrefstr.substring(pos + 1);
  para = parastr.split("&");
  tempstr = "";
  for (i = 0; i < para.length; i++)
  {
    tempstr = para[i];
    pos = tempstr.indexOf("=");
    if (tempstr.substring(0, pos) == strname)
    {
      return tempstr.substring(pos + 1);
    }
  }
  return "";
}

function addQQ(qq)
{
	window.open('lib/common/qq.php?qq='+qq,'_blank',"top=400,width=5,height=5");
}

// 设置cookie
function setCookie(name, value)
{
  var today = new Date();
  var expires = new Date();
  expires.setTime(today.getTime()+1000*60*60*24*365);
  document.cookie = name+"="+escape(value)+"; expires="+expires.toGMTString();
}

// 获取cookie
function getCookie(name)
{
  var search = name+"=";
    if(document.cookie.length>0)
    {
      offset = document.cookie.indexOf(search);
      if(offset!=-1)
      {
        offset += search.length
        end = document.cookie.indexOf(";", offset)
        if(end==-1)
        {
          end = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, end));
      }	
    }
    return "";
}
function deleteCookie(name, path, domain) 
{
  if (getCookie(name)) 
	{
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function Cookie()
{
	this._Cookie=[];
	
	this.Load=function()
	{
		if(document.cookie.indexOf(";")!=-1)
		{
			var _sp,_name,_tp,_tars,_tarslength;
			var _item=document.cookie.split("; ");
			var _itemlength=_item.length;
			while(_itemlength>0)
			{
				_sp=_item[--_itemlength].split("=");
				_name=_sp[0];
				if (_sp.length <2 )
				{
					continue;
				}
				_tp=_sp[1].split(",");
				_tars=_tp.slice(1,_tp.length);
				this._Cookie[_name]=[];
				this._Cookie[_name]=_tars;
				this._Cookie[_name]["timeout"]=_tp[0];
			}
			return true;
		}
	return false;
	}
        
	this.Save=function()
	{
		var _str,_ars,_mars,_marslength,timeout,i,key;
		for(key in this._Cookie)
		{
			if(!this._Cookie[key])return;
			_str=[];
			_mars=this._Cookie[key];
			_marslength=_mars.length;
			for(i=0;i<_marslength;i++)_str[_str.length]=escape(_mars[i]);
			document.cookie=key+"="+_mars["timeout"]+(_str.length>0?",":"")+_str+(_mars["timeout"]==0?"":";expires="+new Date(parseInt(_mars["timeout"])).toGMTString());
		}        
	}
        
	this.Create=function(name,days)
	{
		days=days?days:0;
		if(!this._Cookie[name])this._Cookie[name]=[];
		this._Cookie[name]["timeout"]=days!=0?new Date().getTime()+parseInt(days)*86400000:0;
	}    
        
	this.Modify=function(name,days)
	{
		this.Create(name,days);
	}
			
	this.Delete=function(name)
	{
		this.Create(name,0);
	}     
			
	this.AddItem=function(name,value)
	{
		this._Cookie[name][this._Cookie[name].length]=value;
	}
			
	this.DelItem=function(name,index)
	{
		var _ttime=this._Cookie[name]["timeout"];
		this._Cookie[name]=this._Cookie[name].slice(0,index).concat(this._Cookie[name].slice(parseInt(index)+1,this._Cookie[name].length));
		this._Cookie[name]["timeout"]=_ttime;
	}

	this.GetItem=function(name,index)
	{
		return this._Cookie[name][index];
	}

	this.GetTime=function(name)
	{
		return new Date(parseInt(this._Cookie[name]["timeout"]));
	}

	this.GetCount=function(name)
	{
		return this._Cookie[name].length;
	}

	this.GetCookieCount=function()
	{
		var _length=0,key;
		for(key in this._Cookie)_length++;
		return _length;
	}
        
	this.SetCookie=function(name,value)
	{
		var today = new Date()
		var expires = new Date()
		expires.setTime(today.getTime() + 1000*60*60*24*365)
		document.cookie = name + "=" + escape(value)	+ "; expires=" + expires.toGMTString()
	}
	
	this.GetCookie=function(Name)
	{
		var search = Name + "="
		if(document.cookie.length > 0) 
		{
			offset = document.cookie.indexOf(search)
			if(offset != -1) 
			{
				offset += search.length
				end = document.cookie.indexOf(";", offset)
				if(end == -1) end = document.cookie.length
				return unescape(document.cookie.substring(offset, end))
			}	
		}
		return ""
	}
}	

function detectBrowser()
{ 
  var ret = "ie6"; // default 
  var user_agent = navigator.userAgent; 
  if(user_agent.indexOf("compatible")>-1)
  {
    if(user_agent.indexOf("MSIE 6.0") > -1)
    {
      ret = "ie6";
    }
    else if(user_agent.indexOf("MSIE 7.0") > -1)
    {
      ret = "ie7";
    }
    else if(user_agent.indexOf("MSIE 8.0") > -1)
    {
      ret = "ie8";
    }
  }
  else if(user_agent.indexOf("Gecko") > -1)
  {
    ret = "firefox";
  }

  return ret;
}

// 获取搜索引擎
function get_search(url)
{
  var realSearch = new Array("Google", "Google", "Baidu_adv", "Baidu", "Baidu", "3721", "3721", "Yisou", "Sogou", "Sina", "Sina", "Yahoo", "Tom", "Tom", "Youdao", "SOSO", "Bing");
  var search = new Array("google.com", "google.cn", "cpro.baidu.com", "baidu.com", "baidu.com", "3721.com", "3721.com", "yisou.com", "sogou.com", "iask.com", "sina.com", "yahoo.com", "search.tom.com", "search.tom.com", "youdao.com", "soso.com", "cn.bing.com");

  var len = search.length;
  for(var i=0; i<len; i++)
  {
    if(url.indexOf(search[i])!=-1)
    {
      return realSearch[i];
    }
  }
  return "";
}

// 获取域名
function get_domain(url)
{
  var pos = url.indexOf("http://");
  if(pos==0)
  {
    var pos1 = url.indexOf("/", 7);
    if(pos1==-1)
    {
      return url.substr(7);
    }
    else
    {
      var len = pos1-pos-7;
      return url.substr(7, len);
    } 
  }
  else
  {
    pos = url.indexOf("www.");
    if(pos==0)
    {
      var pos1 = url.indexOf("/");
      if(pos1==-1)
      {
        return url.substr(0);
      }
      else
      {
        return url.substr(0, pos1);
      }
    }
  }

  pos = url.indexOf("/");
  if(pos==-1)
  {
    return url;
  }
  else
  {
    return url.substr(0, pos);
  }
}

// 预载图片
function preLoadImages()
{
	var len = arguments.length;
  var imgs = new Array();
	for(var i=0; i<len; i++)
  {
		imgs[i] = new Image();
		imgs[i].src = arguments[i];
	}
}

// 动态生成天数
function createDays(month_id, day_id)
{
  var month = document.getElementById(month_id).value;
  switch(month)
  {
    case '1':
    case '3':
    case '5':
    case '7':
    case '8':
    case '10':
    case '12':
      createDaysHtml(day_id, 31);
      break;
    case '2':
      createDaysHtml(day_id, 29);
      break;
    case '4':
    case '6':
    case '9':
    case '11':
      createDaysHtml(day_id, 30);
      break;
    default:
      break;
  }
}

// 动态生成天数HTML
function createDaysHtml(day_id, days)
{
  var obj = document.getElementById(day_id);

  if(browser=="firefox")
  {
    var optionArr = new Array();
    for(var i=1; i<=days; i++)
    {
      var html = "<option>"+i+"</option>";
      optionArr.push(html);
    }
    obj.innerHTML = optionArr.join("");
    return;
  }

  obj.innerHTML = "";
  for(var i=1; i<=days; i++)
  {
    var optionNode = document.createElement("option");
    optionNode.innerText = i;
    optionNode.value = i;
    obj.appendChild(optionNode);
  }
}

// 获取输入框的值
function GetValue(id)
{
  try
  {
    return document.getElementById(id).value.trim();
  }
  catch(e){}
}

String.prototype.IsNumber = function()
{
	var myReg = /^[0-9]+$/;
	if(!myReg.test(this)) return false;
	ActRd=parseInt(this)	
	return true;
}
String.prototype.IsDomain = function()
{
	var myReg = /^[0-9a-zA-Z\-]+$/;
	if(myReg.test(this)) return true;
	return false;
}


String.prototype.IsEmail = function()
{
	var myReg = /[\u4e00-\u9fa5]/;
	if(!myReg.test(this))
	{
		myReg = /^[_a-zA-Z0-9][-._a-zA-Z0-9]*@[-_a-zA-Z0-9]+\.[-._a-zA-Z0-9]+(\.[-._a-zA-Z])*$/;
		if (myReg.test(this)) return true;
	}
	else
	{
		myReg = /^[_a-zA-Z0-9\u4e00-\u9fa5][-_.a-zA-Z0-9\u4e00-\u9fa5]*@[-._a-zA-Z0-9\u4e00-\u9fa5]+(\.[-._0-9a-zA-Z\u4e00-\u9fa5]+)*$/;
		if (myReg.test(this)) return true;
	}
	return false;
}
