var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
String.prototype.subByte = function(n)
{
  if(this.getByteLength()<=n) return this;
  for(var i=Math.floor((n=n-2)/2), l=this.length; i<l; i++)
  if(this.substr(0,i).getByteLength()>=n)return this.substr(0,i) +"\u2026";
  return this;
};

String.prototype.getByteLength=function(){return this.replace(/[^\x00-\xff]/g, "mm").length;};

String.prototype.trim=function(){return this.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g, "")};

String.prototype.format=function()
{
  if(arguments.length==0) return this;
  for(var s=this, i=0; i<arguments.length; i++)
    s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);
  return s;
};
String.format=function(str)
{
  if("string"!=typeof(str)||arguments.length<=1) return str;
  for(var i=1; i<arguments.length; i++)
    str=str.replace(new RegExp("\\{"+(i-1)+"\\}","g"), arguments[i]);
  return str;
};

document.getParentObjectByClassName=function(element,css){
	var returnElement=element;
	var tag=null;
	while(!e.hasClassName(returnElement,css) && tag!="BODY"){
		returnElement=(returnElement.parentNode || returnElement.parentElement);
		if (returnElement.tagName){tag=returnElement.tagName;}
	}
	return(returnElement==element?null:returnElement);
};
document.Event=function(){
	if(document.all) return(window.event);
	var Fun=document.Event.caller;
	while(Fun!=null){
		var Arg=Fun.arguments[0];
		if(Arg){
			if((Arg.constructor==Event || Arg.constructor ==MouseEvent) || (typeof(Arg)=="object" && Arg.preventDefault && Arg.stopPropagation)) return(Arg);
			}
			Fun=Fun.caller;
	}
	Arg=Fun=null;
	return(Arg);
};
document.This=function(){
	return(document.Event().srcElement || document.Event().target);
	};

//
function isArray(variable){
	if (variable==null) return(false);
	var reValue=true;
	try {
		reValue=(typeof(variable)=="object"&&variable.constructor==Array)?true:false;
		}
		 catch(para) {
			 try{
				 variable.push(1);variable.pop();reValue=true;
				 }
				catch(para){
					reValue=false;
				}
			}
	return(reValue);
};
function chkDate(s){
	var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
		//var reg1=/^(\d{4})([-])(\d{2})([-])(\d{2})/;//yyyy-mm-dd
		//var reg2=/^(\d{4})([\/])(\d{2})([\/])(\d{2})/;//yyyy/mm/dd
		return(reg.test(s));
}
function isFunction(fun) {
	if (fun==null) return(false);
	return (typeof(fun)=='function'&&fun.constructor==Function);
};
function isString(str){
	if (str==null) return(false);
	return (typeof(str)=='string'&&str.constructor==String); 
};
function isNumber(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='number'&&obj.constructor==Number); 
};
function isDate(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='object'&&obj.constructor==Date); 
};
function isObject(obj){
	if (obj==null) return(false);
	return (typeof(obj)=='object'&&obj.constructor==Object); 
};
function isNull(a) {
	if (isArray(a)){return(a.length==0);}
	return(a==null || (!a&&a!=0) || (isString(a)&&(a.replace(/(^\s*)|(\s*$)/g, "")=="" || a.toLowerCase()=="null" || a.toLowerCase()=="empty")) || typeof(a)=='undefined');
};
function isBoolean(a){
	if (a==null) return(false);
  return(typeof(a) == 'boolean'&&a.constructor==Boolean);
};
function $tag(parentElement,tagstring){//getElementsByTagName
		var element=parentElement,tags=tagstring,temp=[],tmp;
		element=$(element);
		if (isNull(element)) element=document;
		if (isNull(tags)) tags="*";
		try{
			tmp=element.getElementsByTagName(tags);
		}
		catch(para){
			tmp=[];
		}
		for (var i=0; i<tmp.length; i++) {
			temp.push(tmp[i])
			}
		tmp=null;
		return(temp);
};

//
function chkTelephone(Tel)
{
	var i,j,strTemp;
	strTemp="0123456789-+#()";
	if (Tel.length < 7 ){
	 return 0;
	 }
	for (i=0;i<Tel.length;i++){
		j=strTemp.indexOf(Tel.charAt(i));	
		if (j==-1){
			return 0;
		}
	}
	return 1;
}
function chkMobile(m){
 var mobile=m;
 var reg0=/^13\d{9}$/;   //130--139。至少7位
 var reg1=/^15\d{9}$/;  //联通150-159。至少7位
 var my=false;
 if (reg0.test(mobile))my=true;
 if (reg1.test(mobile))my=true;
 return my;
}

function chkEmail(a){ 
	if(!a.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
		return false;
		}
	return true;
		
} 
function chkNumeric(NUM){
	var i,j,strTemp;
	var PointNum;
	PointNum=0
	strTemp="0123456789.";
	if(NUM=="")return 0;
	for (i=0;i<NUM.length;i++){
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1){
			return 0;
		}
		if(j==10){
			PointNum=PointNum+1;
		}
		
	}
	if(PointNum>1){
		return 0;
	}
	return 1;
}

function chkInteger(NUM){
	return(/^[0-9]+$/.test(NUM));	
}

function DrawImage(ImgD,x,y){
	var flag=false;
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= x/y){
     if(image.width>x){  
     ImgD.width=x;
     ImgD.height=(image.height*x)/image.width;
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"x"+image.height;
     }
    else{
     if(image.height>y){  
     ImgD.height=y;
     ImgD.width=(image.width*y)/image.height;     
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"x"+image.height;
     }
    }
}

function chkImageSize(ImgD,x,y){
   var image=new Image();
   image.src=ImgD;
   if(image.width>x || image.height>y){
		alert("图片的宽不能大于"+x+"像素;高不能大于"+y+"像素.");
		return false;
	}
	return true;
}

// 是否有效的扩展名
function IsExt(url, opt){
	var sTemp;
	var b=false;
	if(url==""){
		return b;
		}
	var s=opt.toUpperCase().split("|");
	for (var i=0;i<s.length ;i++ ){
		sTemp=url.substr(url.length-s[i].length-1);
		sTemp=sTemp.toUpperCase();
		s[i]="."+s[i];
		if (s[i]==sTemp){
			b=true;
			break;
		}
	}
	return b;
}

function chkLength(strTemp){
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++){
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}

function jtrim(str)
{     
	while ((str.charAt(0)==" ")||(str.charAt(0)=="　")){
		str=str.substr(1);
		}      
	while (str.charAt(str.length-1)==" "){
		str=str.substr(0,str.length-1);
		}
     return(str);
}


//设置选中
function checkAll(obj,value){
  var arr=$A(document.getElementsByName(obj));
  arr.each(function(e,i){$(e).checked=value;})
}
//选择或取消选反列表中全部记录
function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements[checkall].checked;
		}
	}
}



//至少有一个元素被选择
function checkSub(theform,theid){
  var k=0;
  for(var i=0;i<theform.elements.length;i++){  
     var e = theform.elements[i];
     if (e.name == theid){
     if(e.checked==true){
		  k++;
		}
     }
  }
 return k;
}
function setcopy(text, alertmsg){
 if(is_ie){
	clipboardData.setData('Text', text);
	 alert(alertmsg);
 }else if(prompt('Press Ctrl+C Copy to Clipboard', text)){
	alert(alertmsg);
}
}
function goUrl(url){
	window.location.replace(url);
}
function openUrl(url){
	window.open(url,'');
}

function isIE(){
		if(document.all){return true}else{return false}
}

function setCookie (name, value) {
  //document.cookie = name + "=" + value + ";expires=Thursday,01-Jan-2099 00:00:00 GMT";
  document.cookie = name + "=" + value + "; path=/;expires=Thursday,01-Jan-2099 00:00:00 GMT";
}

function getCookie(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(name) {
  setCookie(name, "");
}
function nohtml (s){ 
        var reTag = /<(?:.|\s)*?>/g; 
        return s.replace(reTag, ""); 
}
function getQueryString(queryname) {
    var qKeys = {};
    var re = /[?&]([^=]+)(?:=([^&]*))?/g;
    var matchInfo;
    while(matchInfo = re.exec(location.search)){
	    qKeys[matchInfo[1]] = matchInfo[2];
    }
    return typeof(qKeys[queryname])=='undefined'?'':qKeys[queryname];
}
function getpageurl(url,value){
	return url.replace(/\$page/ig,value);	
}


function ShowFormatBytesStr(bytes) {
	if(bytes > 1073741824) {
		document.write((Math.round((bytes/1073741824)*100)/100).toString()+' G');
	} else if(bytes > 1048576) {
		document.write((Math.round((bytes/1048576)*100)/100).toString()+' M');
	} else if(bytes > 1024) {
		document.write((Math.round((bytes/1024)*100)/100).toString()+' K');
	} else {
		document.write(bytes.toString()+' Bytes');
	}
}


function convertdate(strdate) {
	strdate = strdate.replace(/-/ig,'/');
	var d = new Date(strdate);
	var now = new Date();
	var result;

	if (d.getYear() == now.getYear() && d.getMonth() == now.getMonth()) {
		var xday = now.getDate() - d.getDate();

		switch (xday) {
			case 0:
				result = "今天 " + d.format("hh") + ":" + d.format("mm");
				break;
			case 1:
				result = "昨天 " + d.format("hh") + ":" + d.format("mm");
				break;
			case 2:
				result = "前天 " + d.format("hh") + ":" + d.format("mm");
				break;
			default:
				result = d.format("yyyy-MM-dd hh:mm");
				break;		
		}
	} else {
		result = d.format("yyyy-MM-dd hh:mm");
	}
	
	return result;
}

function convertdate2(strdate)
{
	strdate = strdate.replace(/-/ig,'/');
	var d = new Date(strdate);
	var now = new Date();
	var result = now - d;
	if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() - d.getDate() > 0){
		result = convertdate(strdate);
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() - d.getHours() > 0){
		result = convertdate(strdate);
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() == d.getHours() && now.getMinutes() - d.getMinutes() > 0){
		result = (now.getMinutes() - d.getMinutes()) + " 分钟前"
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() == d.getHours() && now.getMinutes() == d.getMinutes() && now.getSeconds() - d.getSeconds()> 0){
		result = (now.getSeconds() - d.getSeconds()) + " 秒前"
	} else {
		result = d.format("yyyy-MM-dd hh:mm");
	}
	return result;

}

Date.prototype.format = function(format) {
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(),    //day
	"h+" : this.getHours(),   //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	"S" : this.getMilliseconds() //millisecond
	};
	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1,
			(this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for(var k in o) {
		if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,
				RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	}
	return format;
}


var __format = function(n, m) {
	if (!n) return 0;
	var _m;
	var s;
	var _n;
	_m = m === undefined ? 0 : m;
	_n = n * Math.pow(10, _m);
	_n = Math.round(_n);
	_n = _n / Math.pow(10, _m);
	return _n.toString();
};
var __formatSize = function(n) {
	var s;
	var m;
	var a = [];
	var i;
	for (i = 0; n > 0; i++) {
		m = Math.floor(n / 1024);
		a[i] = n - m * 1024;
		n = m;
	}
	switch (a.length) {
		case 0:
			return '0KB';
		case 1:
			return __format(a[0]) + 'B';
		case 2:
			return __format(a[1] + a[0] / 1024) + 'KB';
		case 3:
			return __format(a[2] + a[1] / 1024) + 'MB';
		case 4:
			return __format(a[3] + a[2] / 1024) + 'GB';
		case 5:
			return __format(a[4] + a[3] / 1024) + 'TB';
		default:
			;
	}
};
var __formatTime = function(n, isEn) {
	var s;
	isEn = isEn ? true : false;
	if (n < 1000) s = __format(n) + (isEn ? 'ms' : '毫秒');
	else if (n < 60 * 1000) s = __format(n / 1000) + (isEn ? 's' : '秒');
	else if (n < 60 * 60 * 1000) s = __format(n / (60 * 1000)) + (isEn ? 'm' : '分钟');
	else if (n < 24 * 60 * 60 * 1000) s = __format(n / (60 * 60 * 1000)) + (isEn ? 'h' : '小时');
	else s = __format(n / (24 * 60 * 60 * 1000)) + (isEn ? 'd' : '天');
	return s;
};
var __formatClock = function(ms) {
	var n = parseInt(ms / 1000);
	var s;
	var hour = parseInt(n / 3600);
	var minute = parseInt((n - hour * 3600) / 60);
	var second = parseInt(n % 60);
	return (hour < 10 ? '0' + hour : hour) + ':' + (minute < 10 ? '0' + minute : minute) + ':' + (second < 10 ? '0' + second : second);
};
var __sprintf = function($s, $a) {
	for (var $i in $a) {
		$s = $s.replace('%' + $i, $a[$i]);
	}
	return $s;
};
function GetScrollXY(){
    var x=0,y=0
    if(document.documentElement.scrollTop){
        x=document.documentElement.scrollLeft;
        y=document.documentElement.scrollTop;
    }
    else{
        x=document.body.scrollLeft;
        y=document.body.scrollTop;
    }
    return {x:x,y:y}
}

function getEventXY(e){
    var posx=0,posy=0;
    if(e==null) e=window.event;
    if(e.pageX || e.pageY)
    {
        posx=e.pageX; posy=e.pageY;
    }
    else if(e.clientX || e.clientY)
    {
       posx=e.clientX+GetScrollXY().x;
       posy=e.clientY+GetScrollXY().y;
    }
    return {"x":posx, "y":posy};
}

function realOffset(o)
{
  if(!o) return null; var e=o, x=y=l=t=0;
  do{l+=e.offsetLeft||0; t+=e.offsetTop||0; e=e.offsetParent;}while(e);
  do{x+=o.scrollLeft||0; y+=o.scrollTop||0; o=o.parentNode;}while(o);
  var xy=GetScrollXY();
  return {"x":l-x+xy.x, "y":t-y+xy.y};
};
 
function BaseAlert(str){
		alert(str);
}