//浏览器类型
var FBrowser={};
var Browser={};	// fix qzone bug
Browser.isIE=((navigator.userAgent.indexOf('MSIE')==-1)?false:true);	// fix qzone bug
Browser.isIE7=((FBrowser.isIE && window.XMLHttpRequest)?true:false);	// fix qzone bug
FBrowser.isIE=((navigator.userAgent.indexOf('MSIE')==-1)?false:true);
FBrowser.isIE7=((FBrowser.isIE && window.XMLHttpRequest)?true:false);
FBrowser.isIE6=((FBrowser.isIE && !window.XMLHttpRequest && window.ActiveXObject)?true:false);
FBrowser.isFirefox=((navigator.userAgent.indexOf('Firefox')==-1)?false:true);
FBrowser.isOpera=((navigator.userAgent.indexOf('Opera')==-1)?false:true);
FBrowser.isSafari=((navigator.userAgent.toLowerCase().indexOf('webkit'))==-1?false:true);

String.prototype.lTrim=function(){return this.replace(/^\s*/, "");}

String.prototype.rTrim=function(){return this.replace(/\s*$/, "");}

String.prototype.trim=function(){return this.rTrim().lTrim();}

String.prototype.hasChinese=function(){return /[^\x00-\xff]/g.test(this);}
String.prototype.onlyChinese=function(){return /^[\u0391-\uFFE5]+$/g.test(this);}
//过滤QQ号hash后的字串
String.prototype.hash_filter=function(){return this.replace(/[^a-f0-9]/gi,'');}
//取得字符串实际长度(汉字算三个字节,英文字母算一个字节)
String.prototype.getLength=function()
{
  return this.replace(/[^\x00-\xff]/gi,'xxx').length;
}
function Fstr_pad(s,n,pad)
{
	if(s.length>=length) return s;
	var p=n-s.length;
	for(var i=0;i<p;i++)
		s=pad+''+s;
	return s;
}

function Farray_exist(d,v)
{
	for(var i=0;i<d.length;i++)
	{
		if(d[i]==v) return true;
	}
	return false;
}

window.clearRunInterval=window.clearInterval;
window.clearRunTimeout=window.clearTimeout;

/**
 * @param fn  函数的引用,函数不能用字符串引起来
 * @param dt  间隔时间
 * 
 * @return bool   正确返回true,否则返回false
 * 例子:setRunTimeout(fun,1000,1,2,4)
 */
window.setRunTimeout=function(fn,dt)
{
	if(typeof(fn)!='function') return false;
	var p=new Array();

	if(arguments.length>2)
	{
		for(var i=2;i<arguments.length;i++)	p[i-2]=arguments[i];
	}
	var f=function(){fn.apply(null,p)}
	return window.setTimeout(f,dt);
}

/**
 * @param fn   函数的引用,函数不能用字符串引起来
 * @param dt  间隔时间
 * 
 * @return bool  正确返回true,否则返回false
 * 例子:setRunInterval(fun,1000,1,2,4)
 */
window.setRunInterval=function(fn,dt)
{
	if(typeof(fn)!='function') return false;
	var p=new Array();
	if(arguments.length>2)
	{
		for(var i=2;i<arguments.length;i++)	p[i-2]=arguments[i];
	}
	var f=function(){fn.apply(null,p)}
	return window.setInterval(f,dt);
}

//document.getElementById的简写
function Fid(id)
{
	return document.getElementById(id);
}

//document.getElementById的简写
function Fname(name)
{
	return document.getElementsByName(name);
}

function FtagName(name)
{
	return document.getElementsByTagName(name);
}

function Fempty(v){
	if(v!=null && (typeof(v)=='object' || typeof(v)=='function')) return false;
	return ((""==v || undefined==v || null==v)?true:false);
}

//字符串过滤的函数
function FxmlEncode(s)
{
	return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;");
}

//对URL参数的分析,需要进行详细的分析
function FgetURLArgs()
{
	var q=location.search.substring(1).replace("&amp;","&").split("&");
	var p=new Object();
	for(var i=0;i<q.length;i++)
	{
		var pos=q[i].indexOf('=');
		if (-1==pos) continue;
		p[q[i].substring(0,pos)]=unescape(q[i].substring(pos+1));
	}
	return p;
}

//判断是否对象是否是指定的tagName
function FisTagName(e,tagName)
{
	return ((e.tagName.toUpperCase()==tagName.toUpperCase())?true:false);
}

function FaddOptionToSelect(id,txt,v,selected)
{
	var e=Fid(id);
	if(Fempty(e) || !FisTagName(e,'select')) return false;
	var s=((undefined==selected || true!=selected)?false:true);
	e.options[e.options.length]=new Option(txt,v,s,false);
	return true;
}

//清空一个或多个或全部
function FclearOptionsOfSelect(id)
{
	var e=Fid(id);
	if(Fempty(e) || !FisTagName(e,'select')) return false;
	for(var i=e.length;i>=0;i--)
		e.options[i]=null;
	
}

//注意单选和多选,如果v为空,所有的option都设置成state,否则
function FsetValuesOfSelect(id,v,stat)
{
	var e=Fid(id);
	var v1=new Array();
	if(Fempty(e) || !FisTagName(e,'select')) return false;
	if(typeof(v)!='object'){
		v1[0]=v;
	}else{
		v1=v;
	}

	for(var i=0;i<e.options.length;i++)
	{
		e.options[i].selected=false;
		if(Fempty(v1))
			e.options[i].selected=stat;
		else if(Farray_exist(v1,e.options[i].value))
			e.options[i].selected=stat;
	}
}

//注意单选和多选
function FgetValuesOfSelect(id , type)
{
	var e=Fid(id);
	if(Fempty(e) || !FisTagName(e,'select')) return null;
	var v=new Array();
	for(var i=0,j=0;i<e.options.length;i++)
	{
		if(true==e.options[i].selected)	
			v[j++]=(type && type == 'inner') ? e.options[i].innerHTML : e.options[i].value;
	}
	return ((1==v.length)?v[0]:v)
}

//考虑全选
function FsetValuesOfCheckbox(name,v,stat)
{
	var e=Fname(name);
	if('Array'!=typeof(v) && !Fempty(v)) v=new Array(v);
	for(var i=0;i<e.length;i++)
	{
		if(Fempty(e[i]) || e[i].type!='checkbox') continue;
		e[i].checked=false;
		if(Fempty(v))
			e[i].checked=stat;
		else if(Farray_exist(v,e[i].value))
			e[i].checked=stat;
	}
}

function FgetValuesOfCheckbox(name)
{
	var e=Fname(name);
	var v=new Array();
	for(var i=0;i<e.length;i++)
	{
		if(Fempty(e[i]) || e[i].type!='checkbox') continue;
		if(e[i].checked==true) 
			v[v.length]=e[i].value;
	}
	return v;
}

function FsetValueOfRadio(name,v)
{
	var e=Fname(name);
	for(var i=0;i<e.length;i++)
	{
		if(Fempty(e[i]) || e[i].type!='radio') continue;
		if(e[i].value==v) e[i].checked=true;
	}
}

function FgetValueOfRadio(name)
{
	var e=Fname(name);
	for(var i=0;i<e.length;i++)
	{
		if(e[i].type!='radio') continue;
		if(e[i].checked==true) return e[i].value;
	}
	return null;
}

//对cookie的操作
function FgetCookie(name)
{
	var r=new RegExp("(^|;|\\s+)"+name+"=([^;]*)(;|$)");
	var m=document.cookie.match(r);
	return(!m?"":m[2]);
}
//修改了一下eric的代码
function FaddCookie(name,v,path,expire,domain,noescape){
	var s=name+"="+ ( (noescape) ? v : escape(v));
	if(!Fempty(path)) path="/";
	if(expire>0){
		var d=new Date();
		d.setTime(d.getTime()+expire*1000);
		if(!Fempty(domain))
			s=s+"; path="+path+"; domain="+domain+"; expires="+d.toGMTString();
		else
			s=s+"; path="+path+"; expires="+d.toGMTString();
	}
	document.cookie=s;
}
//修改了一下eric的代码
function FdeleteCookie(name,domain)
{
	if(!Fempty(domain))
		//document.cookie=name+"=; path=/; domain="+domain+"; expires="+(new Date(0)).toGMTString();
		document.cookie=name+"=; path=/; domain="+domain+"; expires=Fri, 02-Jan-1970 00:00:00 GMT";
	else
		//document.cookie=name+"=; path=/; expires="+(new Date(0)).toGMTString();
		document.cookie=name+"=; path=/; expires=Fri, 02-Jan-1970 00:00:00 GMT";
}

function Fcookie(document,name,hours,path,domain,secure)
{
    this.$document=document;
    this.$name=name;
    if (hours)
        this.$expiration=new Date((new Date()).getTime()+hours*3600000);
    else this.$expiration=null;
    if (path) this.$path=path; else this.$path=null;
    if (domain) this.$domain=domain; else this.$domain=null;
    if (secure) this.$secure=true; else this.$secure=false;
}

Fcookie.prototype.store=function(){
    var cookieval="";
    for(var prop in this) {
        if ((prop.charAt(0)=='$') || ((typeof this[prop])=='function')) 
            continue;
        if (cookieval!="") cookieval+='&';
        cookieval+=prop+':'+escape(this[prop]);
    }
    var cookie=this.$name+'='+cookieval;
    if (this.$expiration)
        cookie+='; expires='+this.$expiration.toGMTString();
    if (this.$path) cookie+='; path='+this.$path;
    if (this.$domain) cookie+='; domain='+this.$domain;
    if (this.$secure) cookie += '; secure';
    this.$document.cookie=cookie;
}

Fcookie.prototype.load=function() { 
    var allcookies=this.$document.cookie;
    if (allcookies=="") return false;

    var start=allcookies.indexOf(this.$name+'=');
    if (start==-1) return false;   
    start += this.$name.length+1;  
    var end=allcookies.indexOf(';', start);
    if (end==-1) end=allcookies.length;
    var cookieval=allcookies.substring(start, end);

    var a=cookieval.split('&');    
    for(var i=0; i<a.length; i++) 
        a[i]=a[i].split(':');

    for(var i=0; i<a.length; i++) {
        this[a[i][0]]=unescape(a[i][1]);
    }
    return true;
}

Fcookie.prototype.remove=function() {
    var cookie=this.$name+'=';
    if (this.$path) cookie += '; path='+this.$path;
    if (this.$domain) cookie += '; domain='+this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie=cookie;
}

//取得事件发生的元素
function FgetEventTarget(evt)
{
	return evt.target || evt.srcElement;
}

//屏蔽浏览器的差别
function FgetEvent(evt)
{
    evt = evt || window.event;
	    
	//修正Mozilla的event事件
    if (!evt) {
        var c = this.getEvent.caller;
        while (c) {
           evt = c.arguments[0];
           if (evt && Event == evt.constructor) {
               break;
           }
           c = c.caller;
       }
    }
	return evt;
}

//判断是否左键被按下
function FisLeftKeyDown(evt)
{
	return (((evt.which) && (evt.which==1)) || ((evt.button) && (evt.button==1)));
}

//给对象增加一个事件,格式target必须是对象，evt格式"click"
//fn(evt) 的函数定义中需要增加 if (evt.currenttarget == evt.target) return; 

function FaddEvent(e,evt,fn,isID)
{
	if(isID==true) e=Fid(e);
	if(!Fempty(e.attachEvent) && (typeof(e.attachEvent)=="function" || typeof(e.attachEvent)=="object"))
		e.attachEvent("on"+evt,fn);
	else if(!Fempty(e.addEventListener) && (typeof(e.addEventListener)=="function" || typeof(e.addEventListener)=="object"))
		e.addEventListener(evt,fn,false);
}

//给对象删除一个事件,格式target必须是对象，evt格式"click"
//fn(evt) 的函数定义中需要增加 if (evt.currenttarget == evt.target) return; 

function FremoveEvent(e,evt,fun,isID)
{
	if(isID==true) e=Fid(e);
	if(!Fempty(e.detachEvent) && (typeof(e.detachEvent)=="function" || typeof(e.detachEvent)=="object"))
		e.detachEvent("on"+evt,fun);
	else if(!Fempty(e.removeEventListener) && (typeof(e.removeEventListener)=="function" || typeof(e.removeEventListener)=="object"))
		e.removeEventListener(evt,fun,false);
}

//阻止事件向上传递
function FstopEventTransfer(evt)
{
	if(evt.preventDefault){
		evt.stopPropagation();
		evt.preventDefault();
	}else{
		evt.returnValue=false;
		evt.cancelBubble=true;
	}
}

//禁止指定对象指定事件的传播,格式target必须是对象，evts格式"click,mousedown,mousedown"
function FstopObjectEventTransfer(e,evts)
{
	if(Fempty(e) || Fempty(evts)) return;
	var l=evts.split(",");
	for(var i=0;i<l.length;i++)
	{
		var evt=l[i].trim();
		if(Fempty(evt)) continue;
		var fn=function(event){event=FgetEvent(event);FstopEventTransfer(event);}
		FaddEvent(e,evt,fn);
	}
}

//设置事件捕获
function FsetEventCapture(target)
{
	if(target.setCapture)
		target.setCapture();
	else{
	 if(!FBrowser.isFirefox && document.captureEvents)
		document.captureEvents(Event.MouseMove|Event.MouseUp);
	}
}

//释放事件捕获
function FreleaseEventCapture(target)
{
	if(target.releaseCapture)
		target.releaseCapture();
	else{
		if(!FBrowser.isFirefox && document.releaseEvents)
			document.releaseEvents(Event.MouseMove|Event.MouseUp);
	}
}

//获得页面窗口的大小
function FgetWindowSize()
{
	if(FBrowser.isOpera)
		return {width:document.body.clientWidth,height:document.body.clientHeight};
	else if(FBrowser.isIE6)
		return {width:document.body.clientWidth,height:document.body.clientHeight};
	else
		return {width:document.documentElement.clientWidth,height:document.documentElement.clientHeight};
}

//获得页面窗口的大小
function FgetPageSize()
{
	if(FBrowser.isIE6)
		return {width:document.body.scrollWidth,height:document.body.scrollHeight};
	return {width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight};
}

function FgetUrlParam()
{
	var locurl = location.href;
	var start = locurl.indexOf("?");
	var end = locurl.length;
	var request = {};
	if(start != -1)
	{
		var tempstr = locurl.substring(start + 1,end)
		tempstr = tempstr.split("&");
		var temp;
		for(var i = 0 ; i < tempstr.length ; i++){
			temp = tempstr[i].split("=");
			if(temp.length == 2)
			{
				request[temp[0]] = temp[1];
			}
		}
	}
	return request;
}

//获得滚动的大小,此函数在IE FF中在刚刷新页面的时候不能取到真正的值，因为那时候IE FF正在初试化 opera下是正确的
function FgetScrollPostion()
{
	if(FBrowser.isIE6)
		return {left:document.body.scrollLeft,top:document.body.scrollTop};
	return {left:document.documentElement.scrollLeft,top:document.documentElement.scrollTop};
}

//需要区分页面位置和屏幕位置 还需要区分xhtml html
//获得当前指针在页面上的位置 有问题 在点击的时候要锁定滚动条
//网页是不是body?
function FgetPointerPostion(evt)
{
    if(evt.pageX || evt.pageY)  return {x:evt.pageX,y:evt.pageY};
    return {x:evt.clientX+document.documentElement.scrollLeft-document.documentElement.clientLeft,y:evt.clientY+document.documentElement.scrollTop-document.documentElement.clientTop};
}

//计算出对象在页面上的位置以及宽和高
function FgetPostion(e,isID)
{
	if(isID==true) e=Fid(e);
	var left=0,top=0,w=e.offsetWidth,h=e.offsetHeight;
	do{ 
		top+=e.offsetTop || 0; 
		left+=e.offsetLeft || 0; 
		e=e.offsetParent; 
	}while(e); 

	return {x:left,y:top,width:w,height:h};
}

//需要经过充分的测试，设置元素的页面位置 w=-1 h=-1不会设置这两个属性
function FsetPostion(e,x,y,w,h,isID){
	if(isID==true) e=Fid(e);
	if(e.style.position=="absolute")
	{
		e.style.left=x+"px";
		e.style.top=y+"px";
	}else if(e.style.position=="relative")
	{
		var p=FgetPostion(e.offsetParent);
		e.style.left=(x-p.x)+"px";
		e.style.top=(y-p.y)+"px";
	}
	if(w>=0) e.style.width=w+"px";
	if(h>=0) e.style.height=h+"px";
}

//获得元素1相对与元素2的位置，在显示的时候没有改变
function FgetOffsetPostion(e1,e2)
{
	var p1=FgetPostion(e1);
	var p2=FgetPostion(e2);
	return {x:(p1.x-p2.x),y:(p1.y-p2.y)};
}

//把指定的元素移动到相对元素的位置
function FsetOffsetPostion(e1,e2,x,y,isID)
{
	if(isID==true){
		e1=Fid(e1);
		e2=Fid(e2);
	}
	var p=FgetPostion(e2);
	FsetPostion(e1,x+p.x,y+p.y);
}

//设置元素到另一个元素的指定位置，按比例
function FsetOffsetPostionByRate(e1,e2,nx,ny,isID)
{
	if(isID==true){
		e1=Fid(e1);
		e2=Fid(e2);
	}
	var s1=FgetPostion(e1);
	var s2=FgetPostion(e2);
	FsetPostion(e1,(s2.x+(s2.width-s1.width)/nx),(s2.y+(s2.height-s1.height)/ny),-1,-1);
}

//设置元素相对窗口的位置
function FsetOffsetWindowPostion(e,x,y,isID)
{
	if(isID==true) e=Fid(e);
	var p=FgetScrollPostion();
	FsetPostion(e,x+p.left,y+p.top,-1,-1);
}

//移动元素到窗口的指定位置，只按比例
function FsetOffsetWindowPostionByRate(e,nx,ny,isID)
{
	if(isID==true) e=Fid(e);
	var s=FgetWindowSize();
	FsetOffsetWindowPostion(e,(s.width-e.offsetWidth)/nx,(s.height-e.offsetHeight)/ny);
}

//判断两个元素是否有相同的父节点
function FhasSameParent(e1,e2,isID)
{
	if(isID==true)
	{
		e1=Fid(e1);
		e2=Fid(e2);
	}
	if(Fempty(e1) || Fempty(e2)) return false;
	return (e1.parentNode==e2.parentNode);
}

//设置元素css float的属性
function FsetStyleFloat(e,v,isID)
{
	if(isID==true) e=Fid(e);
	if(e.style.styleFloat!=undefined)
		e.style.styleFloat=v;
	else
		e.style.cssFloat=v;
}
//获得元素的属性值
function FgetAttr(e,isID,name)
{
	if(isID==true) e=Fid(e);
	return e.getAttribute(name);
}

function FisSameUrl(u1,u2)
{
	if(u1==u2) return true;
	//还需要正则表达式判断
	var d1=document.location.host;
	var d2=d1;
	var re=/^(http:\/\/([^\/]+))?([\S]*)$/i;
	var p1=u1.match(re);
	if(!Fempty(p1[2])) d1=p1[2];
	var p2=u2.match(re);
	if(!Fempty(p2[2])) d2=p2[2];
	return ((d1==d2 && p1[3]==p2[3])?true:false);
}

//动态加载js,异步执行的，也就是说，在加载这些脚本的同时，主页面的脚本继续运行,为了节约内存可以考虑在使用后
//删除js对象
function FloadJS(url,sucfn,failfn,head_tag,char_set)
{
	head_tag = (head_tag) ? head_tag : 'SCRIPT';
	var l=FtagName(head_tag);
	for(var i=0;i<l.length;i++)
	{
		if(l[i].src && FisSameUrl(l[i].src,url))
		{
			sucfn();
			return;
		}
	}
	var js=document.createElement("script");
	js.type="text/javascript";
	if ( char_set )
	{
		js.charset = char_set;
	}
	js.src=url;
	var h=FtagName('HEAD').item(0);
	h.appendChild(js);
	if(FBrowser.isIE)
	{
		js.onreadystatechange=function()
		{
			//什么情况下是complete loaded,this.$funExeced:说明函数已经被执行了，由于ie下可能出现两次调用的问题
			if(this.readyState.toLowerCase()!="complete" && this.readyState.toLowerCase()!="loaded")
				return;
			if(this.$funExeced!=true && !Fempty(sucfn) && 'function'==typeof(sucfn)){
				this.$funExeced=true;
				sucfn();
			}
		}
	}else if(FBrowser.isOpera)
	{
		if(!Fempty(sucfn) && 'function'==typeof(sucfn))
		sucfn();
	}else{
		js.onload=function()
		{
			if(!Fempty(sucfn) && 'function'==typeof(sucfn))
			sucfn();
		}
	}
	js.onerror=function(){
		h.removeChild(js);
		if(!Fempty(failfn) && 'function'==typeof(failfn)) 
			failfn();
	}
}

/**
 * 返回数组下标
 * @author Willzhou
 * @param dx 数组下标
 *	 注：如果没有找到，则返回 -1
 */
function array_search(arr , sw)
{
	for(var i = 0 ; i < arr.length ; i++)
	{
		if(arr[i] == sw)
		{
			return i;
		}
	}
	return -1;
}

/**
 * 删除数组中一个元素
 * @author Willzhou
 * @param dx 数组下标
 */
function array_remove(arr , dx)
{
	if(isNaN(dx)||dx>arr.length){return arr;}
	arr.splice(dx,1);
	return arr;
}

/**
 * 删除DOM上的一个元素
 * @author Willzhou
 * @param eid dom元素ID
 */
function FremoveElement(eid)
{
	var e = Fid(eid);
	if(e)
	{
		e.parentNode.removeChild(e);
	}
}

/**
 * 克隆一份数据，因为对象的直接等于是传引用
 * @author Willzhou
 */
function obj_clone(old_obj){
	var newObj = new Object();
	for(elements in old_obj){
		newObj[elements] = old_obj[elements];
	}
	return newObj;
}

/*等比压缩图片, ImgD为要压缩的img对象, img_width为限制宽带,img_height为限制高度,img_height为0时限制宽度,img_width为0时限制高度*/
function  DrawImage(ImgD, img_width, img_height)
{  
	var image = new Image();
	image.src = ImgD.src;
	
	if(img_width <= 0 && img_height <= 0)
	{
		return;
	}
	
	var draw_type = 0;
	if(img_width > 0 && img_height > 0)
	{
		draw_type = (ImgD.width/img_width >= ImgD.height/img_height) ? 1 : 2;
	}
	else if(img_width > 0 && img_height <= 0)
	{
		draw_type = 1;
	}
	else
	{
		draw_type = 2;
	}
   
	if(draw_type == 1)
	{    
		if(image.width > img_width)
		{      
			ImgD.width=img_width;  
			ImgD.height=(image.height*img_width)/image.width;  
		}
		else
		{  
			ImgD.width=image.width;      
			ImgD.height=image.height;  
		}
		//ImgD.alt=image.width+"x"+image.height;  
	}
	else if (draw_type == 2)
	{  
		if(image.height>img_height)
		{      
			ImgD.height=img_height;  
			ImgD.width=(image.width*img_height)/image.height;            
		}
		else
		{  
			ImgD.width=image.width;
			ImgD.height=image.height;
		}  
		//ImgD.alt=image.width+"x"+image.height;  
	}
}

function Fshow(id)
{
	if(Fid(id)) Fid(id).style.display = '';
}

function Fhide(id)
{
	if(Fid(id)) Fid(id).style.display = 'none';
}

function FvaildateUin(uin)
{
	var R=/^[1-9]\d{4,11}$/;
	return R.test(uin);
}

function FgetUin()
{
	var uin=parseInt(FgetCookie("zzpaneluin"));
	if(FvaildateUin(uin)) return uin;
	var R=/^o(0)*/;
	uin=FgetCookie("uin");
	uin=parseInt(uin.replace(R,''));
	return ((FvaildateUin(uin))?uin:false)
}

function FisLogon()
{
	var uin=FgetUin();
	return (uin==false)?false:true;
}/*  |xGv00|5c55be87272c8bf0f89ad7fb0c08d589 */