﻿var agent = navigator.userAgent;
var userAgent = navigator.userAgent;
//JS去前后空格  姚健荣
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.inc = function(k1, k2)
{
	return k2 == null ? this.indexOf(k1) > -1 ? true : false : (k2 + this + k2) .indexOf(k2 + k1 + k2) > -1 ? true : false;
}
String.prototype.realLength   = function()  //获取真实字符串长度 
{   
    return this.replace(/[^\x00-\xff]/g,"**").length;   
    //return   this.replace(/[^\0xa1-\0xff]/g,"**").length
} 
function isChinese(str)//是否是汉字
{
	if(str.length == str.realLength())//表示不是一个汉字	
		return false;
	else
		return true;
}
var is_Kon = userAgent.indexOf('konqueror') != -1;
var is_Saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_Mac = userAgent.indexOf('mac') != -1;
var is_Opr = agent.inc("Opera");
var is_IE = agent.inc("IE") && !is_Opr;
var is_IE4 = agent.inc("IE 4");
var is_IE5 = agent.inc("IE 5") || agent.inc("IE 4");
var is_IE5_5 = agent.inc("IE 5.5");
var is_IE6 = is_IE && !is_IE5;
var is_Moz = agent.inc("Mozilla") && !is_Opr && !is_IE;

if(is_IE4)
{
	oo=function(key){return document.all[key]}
	document.getElementsByName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].name==key)a[a.length]=ol[i];}return a;}
	document.getElementsByTagName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].tagName.toLowerCase()==key)a[a.length]=ol[i];}return a;}
}

if(is_Moz)
{
	Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode;}return node;});
	HTMLElement.prototype.__defineGetter__("children",function(){return this.childNodes});
	HTMLElement.prototype.__defineGetter__("parentElement",function(){return this.parentNode});
}
function RunTime(o)
{
     var TimeDifference = new Date() - new Date(o.innerText.replace(/年/g,"/").replace(/月/g,"/").replace(/日/g,""));
     (function ()
     {
         var d = new Date();
         d.setTime(d.getTime()+TimeDifference);
         o.innerText = "北京时间：" + d.toLocaleString();
         setTimeout(arguments.callee,1000);
     })();
}
function setAtt(obj,Attribute,AttributeValue)
{
	oo(obj).setAttribute(Attribute,AttributeValue);
}

function isIE()
{	
	return is_IE;
}
//is firefox
function isFF()
{
	return is_Moz;
}
function isObject(o) 
{
	return (o && typeof o == 'object') || isFunction(o);
}
function isFunction(o) 
{
	return typeof o == 'function';
}
 function _null(){
    return;
 }
function resetPage()//重新加载页面
{
	window.location = window.location.href;
}
function setCookie(name,value,time){
    //time:以小时为单位
      var exp = new   Date();
      if(time != undefined)
         exp.setTime(exp.getTime() + 60*60*1000*parseInt(time));   
      else
         exp.setTime(exp.getTime() + 60*60*1000);   
      document.cookie   = name + "="+   escape(value)   +";expires="+   exp.toGMTString();   
}   
function getCookie(name){   
      var arr = document.cookie.match(new RegExp("(^|   )"+name+"=([^;]*)(;|$)"));   
      if(arr   !=   null)   return   unescape(arr[2]);   return   null;   
}  
function deleteCookie(name){ 
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    setCookie(name, "", expdate); 
}
function bytes(str){
    if(typeof(str)!='string'){
	    str = str.value.trim();
    }
    var len = 0;
    str = str.trim();
    for(var i = 0; i < str.length; i++){
	    if(str.charCodeAt(i) > 127){
		    len++;
	    }
	    len++;
    }
   return len;
}
function chkstr(str){//判断是否是汉字或者下划线和英文
	if(typeof(str)!='string'){
		str = str.value;
	}
	for(var i = 0; i < str.length; i++){
		if (str.charCodeAt(i) < 127 && !str.substr(i,1).match(/^\w+$/ig)){
			return false;
		}
	}
	return true;
}
//起始IP地址大于结束IP地址时返回false
function completeIPAddress(IP1,IP2)
{
	var ip_1=IP1.split(".")[0]+IP1.split(".")[1]+IP1.split(".")[2]+IP1.split(".")[3];
	var ip_2=IP2.split(".")[0]+IP2.split(".")[1]+IP2.split(".")[2]+IP2.split(".")[3];
	if(parseInt(ip_1)>parseInt(ip_2))
	{
	    alert("起始IP地址不能大于结束IP地址.")
		return false;
	}
	else
	{ 
		return true; 
	}
}

//针对格式为yyyy-MM-dd格式的日期进行比较date1比date2早就返回true或者相等，否则返回false
function dateComplete(date1,date2)
{		    
    var d1 = date1.replace(/-/g , "");
    var d2 = date2.replace(/-/g , "");   
    if(parseFloat(d1) <= parseFloat(d2))    
        return true;
    else
        return false;
}

//验证IP地址、登录帐号、密码、EMAIL、电话号码[包括手机和固定电话] 姚健荣 2006.12.2
function isValidate2(obj,i,showstr)
{  
	var patterns = new Object();
	var thePat;
	var r, re;
    patterns.ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/g;    
    patterns.id = /^[A-Za-z0-9_]{1,20}$/g;  
    patterns.psw = /^[a-zA-Z0-9]{6,20}/g;  
    patterns.email = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/g; 
    patterns.num =  /^\d{1,10}$/g;
    patterns.post =  /^[1-9]\d{5}$/g;     
    patterns.tel =  /^(1(3|5)[0-9]\d{8})|(0[1-9]{3}[-][1-9]\d{6,7}[-]\d{1,5})|(0[1-9]{2}[-][1-9]\d{7}[-]\d{1,5}|([1-9]{1}\d{6,7})|(0[1-9]{3}[-][1-9]\d{6,7})|(0[1-9]{2}[-][1-9]\d{7}))$/g;
    patterns.net =  /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/g;
    patterns.date =  /^[1-9]\d{3}[-]((0[1-9])|(1[0-2]))[-]((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))$/g;//yyyy-MM-dd
    patterns.variable =  /^[A-Za-z_][A-Za-z0-9_]{0,120}$/g;//变量名，以下划线或者字母开头,的由字母、数字和下划线组成的字符串
    
    var control=oo(obj);
	var str=vv(obj);
 
	switch(i)
	{
		case 0:
			thePat = patterns.ip;
			break;
		case 1:
			thePat = patterns.id;
			break;
		case 2:
			thePat = patterns.psw;
			break;
		case 3:
			thePat = patterns.email;
			break;
		case 4:
			thePat = patterns.num;
			break;
		case 5:
			thePat = patterns.post;
			break;	
		case 6:
			thePat = patterns.tel;
			break;	
		case 7:
			thePat = patterns.net;
			break;	
	    case 8:
			thePat = patterns.date;
			break;
	    case 9:
			thePat = patterns.variable;
			break;		
		default:
			break;
	}	   
	var reg = new RegExp(thePat);
	r = reg.exec(str);
	//alert("r:"+ r.length + "    r:"+ r + "   str:" + str + "  r[0]:" + r[0]);
	if (r == null || str != r[0])
	{
		alert(showstr);
		control.focus();
		return false;
	}
	else
	{
		return true;
	}	 
}	
//验证IP地址、登录帐号、密码、EMAIL、电话号码[包括手机和固定电话] 姚健荣 2007.04.25
function isValidate(str,i)
{    
	var patterns = new Object();
	var thePat;
	var r, re;
    patterns.ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/g;    
    patterns.id = /^[A-Za-z0-9_]{1,20}$/g;  
    patterns.psw = /^[a-zA-Z0-9]{6,20}/g;  
    patterns.email = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/g; 
    patterns.num =  /^\d{1,10}$/g;
    patterns.post =  /^[1-9]\d{5}$/g;
    patterns.tel =  /^(1(3|5)[0-9]\d{8})|(0[1-9]{3}[-][1-9]\d{6,7}[-]\d{1,5})|(0[1-9]{2}[-][1-9]\d{7}[-]\d{1,5}|([1-9]{1}\d{6,7})|(0[1-9]{3}[-][1-9]\d{6,7})|(0[1-9]{2}[-][1-9]\d{7}))$/g;
    patterns.net =  /^http:\/\/([\w-]+\.)+[\w-]+(\/[\W\w- .\/?%&=]*)?/g;
    patterns.date =  /^[1-9]\d{3}[-]((0[1-9])|(1[0-2]))[-]((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))$/g;//yyyy-MM-dd
    patterns.variable =  /^[A-Za-z_][A-Za-z0-9_]{0,120}$/g;//变量名，以下划线或者字母开头,的由字母、数字和下划线组成的字符串
    patterns.float_int =  /^[+\-]?\d+(\.\d+)?$/g;   
    patterns.time =  /^(0\d|1\d|2[0-3]):([0-5]\d)$/g
    patterns.Int =  /^[+\-]?\d+$/g;
    patterns.Float =  /^[+\-]?\d+(\.\d+)$/g;
	switch(i)
	{
		case 0:
			thePat = patterns.ip;
			break;
		case 1:
			thePat = patterns.id;
			break;
		case 2:
			thePat = patterns.psw;
			break;
		case 3:
			thePat = patterns.email;
			break;
		case 4:
			thePat = patterns.num;
			break;
		case 5:
			thePat = patterns.post;
			break;	
		case 6:
			thePat = patterns.tel;
			break;	
		case 7:
			thePat = patterns.net;
			break;	
	    case 8:
			thePat = patterns.date;
			break;
	    case 9:
			thePat = patterns.variable;
			break;
        case 10:
			thePat = patterns.float_int;
			break;		
	    case 11:
			thePat = patterns.time;
			break;	
	    case 12:
			thePat = patterns.Int;
			break;	
		case 13:
			thePat = patterns.Float;
			break;		
		default:
			break;
	}	   
	var reg = new RegExp(thePat);
	r = reg.exec(str);
//	alert("r:"+ r.length + "    r:"+ r + "   str:" + str + "  r[0]:" + r[0]);
	if (r == null || str != r[0]) 
		return false; 
	else 
		return true; 
}
//验证身份证号码
function isIdCardNo(num){   
      if (!isNumber(num)) 
           return false;  
      var len = num.length;
      var re;  
      if (len == 15)   
          re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);   
      else if(len == 18)   
          re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);   
      else
          return  false;   
      var a = num.match(re);  
      if (a != null){   
          if (len==15){   
              var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);   
              var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];   
          }else{   
              var D = new   Date(a[3]+"/"+a[4]+"/"+a[5]);   
              var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];   
          }    
          if (!B)return false;   
      }   
      return true;   
}
 
//创建对象
function co(elm)
{
	return document.createElement(elm);
}
//获得控件对象
function oo(obj)
{
	return typeof(obj) != "string" ? obj : (is_IE5 ? document.all(obj) : document.getElementById(obj));
}
function $(id){
    return oo(id);
}
//获取控件的value，去掉了前后空格
function vv(obj)
{
	return oo(obj).value.trim();
}
//获得焦点
function Focus(obj)
{ 
	if(oo(obj).style.display.toLowerCase()!="none")
		oo(obj).focus();
}
//判断是否输入为空
function isNull(obj)
{   
	if(vv(obj).length==0)
	{ 
		return true;		   
	}
	else
	{ 
		return false;
	}
}  
 
//判断是否是图片 
function isPic(obj,msg_span)
{
	var picurl=vv(obj).toUpperCase();	
	if( picurl.lastIndexOf(".GIF") < 0 && 
		picurl.lastIndexOf(".JPG") < 0 && 
		picurl.lastIndexOf(".BMP") < 0 &&
		picurl.lastIndexOf(".JPEG") < 0 &&
		picurl.lastIndexOf(".PNG") < 0)
	{
	    if(msg_span)
		    show_msg(msg_span,"对不起,只能上传*.gif,*.jpg,*.jpeg,*.png,*.bmp图片.");
		else
		    alert("对不起,只能上传*.gif,*.jpg,*.jpeg,*.png,*.bmp图片.");
		return false;
	} 
    return true;
}

function addFavorites(){
    window.external.addFavorite(window.location.href,document.title); 
}
function h(obj){
    url = window.location.href;
    obj.style.behavior='url(#default#homepage)';
    obj.setHomePage(url);
} 
function resetImage(sourceImg,width,height)
{  
    var img = new Image(); 
	img.src = sourceImg.src;
	if(parseInt(sourceImg.width) > 0){
	    if(sourceImg.width > width)
		    sourceImg.width = width; 
	}else{
	     if(img.width > width)
		    sourceImg.width = width;
	}
	
	if(parseInt(sourceImg.height) > 0){
	    if(sourceImg.height > height)
		    sourceImg.height = height; 
	}else{
	     if(img.height > height)
		    sourceImg.height = height;
	}	  
}
 
function isNumber(s)//验证字符串中是否是数字  姚健荣 2006.12.29
{      
	s = s +'';
	var i=s.trim().replace(/e/g,'a').replace(/(\.)/g,'a');
	if(isNaN(i)) 
		return false; 
	else 
		return true; 
}
function isFloatNumber(s)//验证字符串中是否是浮点型数字  姚健荣 2006.12.29
{      
	s = s +'';
	var i=s.trim().replace(/e/g,'a');  
	try{
	    if(isNaN(i)) 
		    return false; 
	    else 
		    return true; 
	}catch(ex){return false;}
}
function isImg(src)//判断是否没有上传空图片
{
	var img = null;
	img  =  new  Image();
    img.src  = src;
    //alert(img.fileSize);
    //img.readyState==complete确保图片完全加载 
    if(img.readyState.toUpperCase()!="COMPLETE" || img.fileSize <= 0)//表明图片地址不正确显示的是个空图片
    {
		return false;
    }  
    else
    {
		return true;
    }  	
}
function isSelected(obj)//验证下拉列表是否选择了一项有效的项，第一项均为无效项    姚健荣 2006.11.16 
{
    var control=oo(obj);
    if(control.selectedIndex==0)
    {   
		return false;		   
	}
	else
	    return true;
} 

//repeater控件全选/不选
function selectAll(obj,value)
{ 
	var tb=oo(obj);			       
	var len=tb.rows.length;
	for(var i=1;i<len;i++)
	{ 
	    if (tb.rows[i].cells[0].children.length == 0 || tb.rows[i].cells[0].children[0].tagName.toUpperCase() != "NOBR")
	        continue;
	        
		if(tb.rows[i].cells[0].children[0].children[0].type.toUpperCase()=="CHECKBOX")
		{
			tb.rows[i].cells[0].children[0].children[0].checked = value;	
		}				
	}
}

//repeater控件反选
function un_SelectAll(obj)
{
	var tb=oo(obj);			       
	var len=tb.rows.length;
	for(var i=1;i<len;i++)
	{
		if(tb.rows[i].cells[0].children[0].children[0].type.toUpperCase()=="CHECKBOX")
		{
			tb.rows[i].cells[0].children[0].children[0].checked = !tb.rows[i].cells[0].children[0].children[0].checked;	
		}				
	}
}  
//and return the pos value
function getObjPos(e)
{
	var t=e.offsetTop;
	var l=e.offsetLeft;
	while(e=e.offsetParent)
	{
		t+=e.offsetTop;
		l+=e.offsetLeft;
	}
	var pos = new Array(1);
	pos[0] = t;
	pos[1] = l;
	return pos;
}

//function: OpenWindow
//Usage:OpenWindow()
//Parameters: 
//           Url:the page location
//           Width: the width of the window
//           Height: the height of the window
//           Left: the window left pos of the screen
//           Top: the window top pos of the screen
//           IsCanResize:is can resize the window width or height(size)
//           IsShowScrollBar: whether the Scroll Bar of the window is show
//=============================================
//This function open a new window by appointed url and some other argus.
function openWindow(Url,Width,Height,Left,Top,IsCanResize,IsShowScrollBar)
{
	if (Width == "" || Width == undefined ) Width = 400;
	if (Height == "" || Height == undefined ) Height = 360;
	if (Left == "" || Left == undefined ) Left = screen.availwidth / 2 - 200 ;
	if (Top == "" || Top == undefined ) Top = screen.availheight / 2 -130 ;
	if (IsCanResize == "" || IsCanResize == undefined ) IsCanResize = "yes";
	if (IsShowScrollBar == "" || IsShowScrollBar == undefined ) IsShowScrollBar = "no";
	var newwin = window.open(Url,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+ IsShowScrollBar +",resizable="+ IsCanResize +",top=" + Top + " ,left=" + Left + ",width="+ Width +",height="+ Height +"");
}

//function: EnDeSelect
//Usage:  EnDeSelect()
//Parametes:
//          theForm: he curForm which the Data in.
//          chkVal: the curCheckBox is checked or unchecked
//          idVal:  the CheckBox's id
//=============================================
//This function checked or unchecked the checkbox in the form
function enDeSelect(theForm,chkVal, idVal)
{ 
	for (i=0; i<theForm.length; i++)
	{
		if (idVal.indexOf ('SelectAll') != -1)
		{
			if(chkVal == true) 
			{
				if(theForm.elements[i].id.indexOf('SelectThis') != -1)
					theForm.elements[i].checked = true;
			}
			else 
			{
				if(theForm.elements[i].id.indexOf('SelectThis') != -1)
					theForm.elements[i].checked = false;
			} 
		}
		else 
		{
			if (idVal.indexOf ('SelectThis') != -1) 
			{
				if(theForm.elements[i].checked == false)
				{
					theForm.elements[1].checked = false; //Uncheck main select all checkbox
				}
			}
		}
	}
	oo(idVal).blur();
}

//function: CompareDate
//Usage:  CompareDate(startDate,endDate)
//Parametes:
//          startDate: the date1 
//			endDate: the date2
//
//=============================================
//This function Compare the two date and return the result
function compareDate(startDate,endDate)
{
	startDate = Date.parse(startDate);
	endDate = Date.parse(endDate);
	if((startDate - endDate)/(1000*60*60) > 0)
		return 2;//小于
	else if((startDate - endDate)/(1000*60*60) == 0)
		return 0;//等于
	else
		return 1;//大于
}
 
 

function arraypop(a) {
	if(typeof a != 'object' || !a.length) {
		return null;
	} else {
		var response = a[a.length - 1];
		a.length--;
		return response;
	}
}

function arraypush(a, value) {
	a[a.length] = value;
	return a.length;
}

function copycode(obj) {
	if(is_ie && obj.style.display != 'none') {
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}

function setcopy(text, alertmsg){
	if(is_ie) {
		clipboardData.setData('Text', text);
		alert(alertmsg);
	} else {
		prompt('Please press "Ctrl+C" to copy this text', text);
	}
} 
//选中radiobutton的某个值
function chooseRadioValue(radioName,Value)
{
    var radio = new Array();
    radio = document.getElementsByName(radioName);
    for(var i=0;i<radio.length;i++)
    {
        if(radio[i].value == Value)
            radio[i].checked = true;
    }
}

//选中下拉菜单的指定值
function chooseSelectValue(obj,Value)
{
    for(var i=0;i<oo(obj).length;i++)
    {
        if(oo(obj)[i].value == Value.trim())
            oo(obj).selectedIndex = i;
    }
}



//获取单选按钮值function getRadioValue(radioName)
{
   var radio = document.getElementsByName(radioName);
      for (i=0;i<radio.length;i++)
        if(radio[i].checked) 
          return radio[i].value; 
  return null;        
}
//获取下拉列表值function getSelectValue(selectId)
{
   try
   {
    var sel = oo(selectId); 
    return sel.options[sel.selectedIndex].value;
    }
    catch(e)
    {
        return "";
    }
}

//获取下拉列表文字
function getSelectText(selectId)
{  
   try
   {
    var sel = oo(selectId);
      return sel.options[sel.selectedIndex].text;
   }catch(e){ return "";}
   
}


//获取列表框值function getListValue(listId)
{
   var sel = oo(listId);
   str = "";
   for (i=0;i<sel.length;i++)
     if(sel.options[i].selected) 
          str += sel.options[i].value + ","; 
   if(str != "") str.substr(0,str.length-1);       
   return str;
}


//获取复选框值function getCheckBoxValue(chkName)
{
   var chk = document.getElementsByName(chkName);
   str = "";
   for (i=0;i<chk.length;i++)
     if(chk[i].checked) 
          str += chk[i].value + ","; 
   if(str != "") str.substr(0,str.length-1);       
   return str;
}

//生成随机数:
//under:下限
//over:上限 不提供 随机数范围为 1 - under
function Random(under, over)
{ 
    switch(arguments.length)
    { 
        case 1: return parseInt(Math.random()*under+1); 
        case 2: return parseInt(Math.random()*(over-under+1) + under);  
        default: return 0; 
    } 
}


function HideLoading(div)
{
	if(div != undefined)
		div.style.display = 'none';
}
//全角半角转换
//str:特转换的字符串
//flag: false:全角转半角
function Dc2Sc(str,flag)
{ 
    var i; 
    var result=''; 
    for(i=0;i<str.length;i++) 
    {
         str1=str.charCodeAt(i); 
        if(str1<125&&!flag) 
            result+=String.fromCharCode(str.charCodeAt(i)); 
        else 
            result+=String.fromCharCode(str.charCodeAt(i)-65248); 
    } 
    return result; 
}
//检测是否在半角状态下输入英文或数字 
function IsSingleChar(str) {
    for(var i = 0;i < str.length;i++) 
    { 
        strCode = str.charCodeAt(i); 
        if(strCode > 65248||strCode == 12288) 
        { 
            return false;
        } 
    } 
    return true;

   }
   
//使用onload=resizeImage(this,长,宽);
function resizeImage(img,w,h)
{
    var image=new Image();
    image.src = img.src;
    if(image.width > 0 && image.height > 0)
    {
        if(image.width / image.height >= w/h)
        {
            if(image.width > w)
            {
                img.width = w;
                img.height = (image.height * w) / image.width;
            }
            else
            {
                img.width = image.width;
                img.height = image.height;
            }
            //img.alt=image.width+"×"+image.height;
        }
        else
        {
            if(image.height > h)
            {
                img.height = h;
                img.width = (image.width * h) / image.height;
            }
            else
            {
                img.width = image.width;
                img.height = image.height;
            }
        }
    }
}


    //得到url参数值
    //param是参数名
    function getparam(param)
    {
	    var _param1 = "";
	    var _param2 = "";
        var search = window.location.search;    
	    var paramvalue = null;   
	    var args_arr = new Array();
	    var args = search;
	    
	    _param1 = "?" + param + "=";
	    _param2 = "&" + param + "=";
	    var p = -1;
	    var p1 = args.indexOf(_param1);
	    var p2 = args.indexOf(_param2);
	    if(p1 >= p2)
		    p = p1;
	    else
	        p = p2;
	    var j = param.length + 2;//加上"？"或者"&"的长度以及"="的长度
	    var k = args.length;//整个长度
	    var h = args.indexOf("&",p+1);//当前参数后是否还有参数
	    var i;
	    if(p> -1)//说明包含了需要的参数
	    {  		 
	        if(h > -1)//表示后面还有参数
	            i = h - (j+p);
	        else
	            i = k - (j+p); 
		    paramvalue = args.substr(p+j,i);
	    } 
	    return paramvalue;
    }   

//截取字符串
function subString(info,len)
{
    if(info.length > len)
        return info.substr(0,len);
    else
        return info;
}
     
function FormatString2(str, length)
{
    length *= 2;
	var i = 0;
	for (var k = 0; k < str.length; k++)
	{
		if (str.charCodeAt(k) > 127)
		{
			i += 2;
		}
		else
		{
			i++;
		}
		if (i > length)
		{
			str = str.substr(0, k);
			break;
		}
	}
	return str;

}
function getStr(str,byte_len){
    str = FormatString2(str,byte_len);
    return str;
} 
function setCookie_1(name,value,time){
    //time:以小时为单位
      var exp = new   Date();
      if(time != undefined)
         exp.setTime(exp.getTime() + 60*60*1000*parseInt(time));   
      else
         exp.setTime(exp.getTime() + 60*60*1000);   
      document.cookie   = name + "="+   escape(value)   +";expires="+   exp.toGMTString();
}
function setCookie_2(name,value,time){
    //time:以小时为单位
      var exp = new   Date();
      if(time != undefined)
         exp.setTime(exp.getTime() + 60*60*1000*parseInt(time));   
      else
         exp.setTime(exp.getTime() + 60*60*1000);   
      document.cookie   = name + "="+   escape(value)   +";expires="+   exp.toGMTString()  +";path=/";
}
function getCookie_1(name){ 
   var search;
   search = name + "="
   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));
  }
  else
     return "";
}
function deleteCookie_1(name){ 
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    setCookie_1(name, "", expdate); 
}
function deleteCookie_2(name,flag){
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    if(flag==0)//同一级别
        setCookie_1(name, "", expdate);
    else
        setCookie_2(name, "", expdate); 
}
	
//验证IP地址、登录帐号、密码、EMAIL、电话号码[包括手机和固定电话] 姚健荣 2007.04.25
function verifyStr(str,i)
{     
	var patterns = new Object();
	var thePat;
	var r, re;
    patterns.ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/g;    
    patterns.id = /^[A-Za-z0-9_]{1,20}$/g;  
    patterns.psw = /^[a-zA-Z0-9]{6,20}/g;  
    patterns.email = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/g; 
    patterns.num =  /^\d{1,10}$/g;
    patterns.post =  /^[1-9]\d{5}$/g;     
    patterns.tel =  /^(13[0-9]\d{8})|([1-9]{1}\d{6,7})|(0[1-9]{3}[-][1-9]\d{6})|(0[1-9]{2}[-][1-9]\d{7})$/g;
    patterns.net =  /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/g;
    patterns.date =  /^[1-9]\d{3}[-]((0[1-9])|(1[0-2]))[-]((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))$/g;//yyyy-MM-dd
    patterns.variable =  /^[A-Za-z_][A-Za-z0-9_]{0,120}$/g;//变量名，以下划线或者字母开头,的由字母、数字和下划线组成的字符串
	switch(i)
	{
		case 0:
			thePat = patterns.ip;
			break;
		case 1:
			thePat = patterns.id;
			break;
		case 2:
			thePat = patterns.psw;
			break;
		case 3:
			thePat = patterns.email;
			break;
		case 4:
			thePat = patterns.num;
			break;
		case 5:
			thePat = patterns.post;
			break;	
		case 6:
			thePat = patterns.tel;
			break;	
		case 7:
			thePat = patterns.net;
			break;	
	    case 8:
			thePat = patterns.date;
			break;
	    case 9:
			thePat = patterns.variable;
			break;		
		default:
			break;
	}	   
	var reg = new RegExp(thePat);
	r = reg.exec(str);
	//alert("r:"+ r.length + "    r:"+ r + "   str:" + str + "  r[0]:" + r[0]);
	if (r == null || str != r[0]) 
		return false; 
	else 
		return true; 
}	