/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TONGFU JavaScript Class Collections.
TFJCC V1.0
所有程序脚本都是作者一个一个代码敲出来的。请尊重作者的劳动。如果你想使用请保留此信息。
作者：同福
作者主页：www.tongfu.net
作者QQ：76229594
作者电话：(086)13911566640
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

// configuration
var jtongfu_arguments = new Object();
jtongfu_arguments.classPath = (typeof(jtongfu_classPath)!='undefined'&&jtongfu_classPath!=null)?jtongfu_classPath:'js/'; // directive to your scripts directory.

// ##########################################################################################################
// ##########################################################################################################
// ##########################################################################################################

// get mouse pointer position

var jtongfu_browserObject = new Object();
jtongfu_browserObject.BrowserType = (navigator.appVersion.match(/MSIE/)) ? 'IE' : 'NS' ; 

function ddd(){
	var str = new String();
	str = '\n网页可见区域宽：'+document.body.clientWidth+  
'\n网页可见区域高：'+document.body.clientHeight+
'\n网页可见区域宽：'+document.body.offsetWidth+
'\n网页可见区域高：'+document.body.offsetHeight+  
'\n网页正文全文宽：'+document.body.scrollWidth+ 
'\n网页正文全文高：'+document.body.scrollHeight+
'\n网页被卷去的高：'+document.body.scrollTop+
'\n网页被卷去的左：'+document.body.scrollLeft+
'\n网页正文部分上：'+window.screenTop+
'\n网页正文部分左：'+window.screenLeft+
'\n屏幕分辨率的高：'+window.screen.height+
'\n屏幕分辨率的宽：'+window.screen.width+
'\n屏幕可用工作区高度：'+window.screen.availHeight+
'\n屏幕可用工作区宽度：'+window.screen.availWidth;
	return (str);
}

function udv(variable){
	return (typeof(variable) == 'undefined')?'':variable;
}

function getScrollTop(){
	return ((document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop);
}
function getScrollLeft(){
	return ((document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft);
}

function jtongfu_loadFilesInIframe(fileUrls){
	this.fileUrls=fileUrls;
	this.taskCount=0;
	this.loadFile=function(file){
		if(file == null || file == ''){
			this.doneLoad();
			return;
		}
		var _doc = document.getElementsByTagName('head')[0];
	    var js = document.createElement('iframe');
	    js.setAttribute('width', '0');
	    js.setAttribute('height', '0');
	    js.setAttribute('frameborder', 'no');
	    js.setAttribute('src', file);
	    js.caller=this;
	    _doc.appendChild(js);
	    if(!/*@cc_on!@*/0){ //if not IE
	        //Firefox2??Firefox3??Safari3.1+??Opera9.6+ support js.onload
	        js.onload=function(){
	            this.caller.doneLoad();
	        };
	    }
	    else{
	        //IE6??IE7 support js.onreadystatechange
	        js.onreadystatechange=function(){
	            if(js.readyState == 'loaded'
	            	|| js.readyState == 'complete'){
	                this.caller.doneLoad();
	            }
	        };
	    }
	}
	this.doneLoad=function(){
		this.taskCount--;
		if(this.taskCount == 0
			&& this.afterLoad != null){
			this.afterLoad();
		}
	}
	this.load=function(){
		this.taskCount = this.fileUrls.length;
		for(ii=0;ii<this.fileUrls.length;ii++){
			this.loadFile(this.fileUrls[ii]);
		}
	}
    this.afterLoad = null;
}

function jtongfu_loadJSFiles(fileUrls){
	this.fileUrls=fileUrls;
	this.taskCount=0;
	this.loadJSFile=function(file){
		if(file == null || file == ''){
			this.doneLoad();
			return;
		}
		var _doc = document.getElementsByTagName('head')[0];
	    var js = document.createElement('script');
	    js.setAttribute('type', 'text/javascript');
	    js.setAttribute('src', file);
	    js.caller=this;
	    _doc.appendChild(js);
	    if(!/*@cc_on!@*/0){ //if not IE
	        //Firefox2??Firefox3??Safari3.1+??Opera9.6+ support js.onload
	        js.onload=function(){
	            this.caller.doneLoad();
	        };
	    }
	    else{
	        //IE6??IE7 support js.onreadystatechange
	        js.onreadystatechange=function(){
	            if(js.readyState == 'loaded'
	            	|| js.readyState == 'complete'){
	                this.caller.doneLoad();
	            }
	        };
	    }
	}
	this.doneLoad=function(){
		this.taskCount--;
		if(this.taskCount == 0
			&& this.afterLoad != null){
			this.afterLoad();
		}
	}
	this.load=function(){
		this.taskCount = this.fileUrls.length;
		for(ii=0;ii<this.fileUrls.length;ii++){
			this.loadJSFile(this.fileUrls[ii]);
		}
	}
    this.afterLoad = null;
}

function jtongfu_getObjectXY(obj){
	var tmpPos = new Object();
	tmpPos.x = 0;
	tmpPos.y = 0;
	var tmpObj = obj;
	do{
		if(tmpObj != null){
			//alert(tmpObj.tagName);
			//alert(tmpObj.offsetLeft+'|'+tmpObj.offsetTop);
			if(tmpObj.style.position == 'absolute'){
				tmpPos.x += isNaN(parseInt(tmpObj.style.left))?0:parseInt(tmpObj.style.left);
				tmpPos.y += isNaN(parseInt(tmpObj.style.top))?0:parseInt(tmpObj.style.top);
				break;
			}
			else{
				tmpPos.x += tmpObj.offsetLeft;
				tmpPos.y += tmpObj.offsetTop;
			}
			tmpObj = (tmpObj.offsetParent != null && tmpObj.tagName != 'BODY') ? tmpObj.offsetParent : null ;
		}
	}
	while(tmpObj != null);
	//tmpPos.x += parseInt(document.documentElement.scrollLeft);
	//tmpPos.y += parseInt(document.documentElement.scrollTop);
	return tmpPos;
}

function jtongfu_obj1(obj,noCheckPos){
	this.obj=obj;
	this.noCheckPos=noCheckPos;
	this.l;
	this.t;
	this.w;
	this.h;
	this.r;
	this.b;
	this.getCellWH=function(){
		if(this.obj.tagName=='TH'||this.obj.tagName=='TD'){
			cellPadding = (jtongfu_browserObject.BrowserType=='IE')?this.obj.parentElement.parentElement.parentElement.cellPadding:this.obj.parentNode.parentNode.parentNode.cellPadding;
			this.w = (isNaN(parseInt(this.obj.style.width))!=null)?(parseInt(this.obj.clientWidth)-parseInt(cellPadding)*2):parseInt(this.obj.style.width);
			this.h = (isNaN(parseInt(this.obj.style.height))!=null)?(parseInt(this.obj.clientHeight)-parseInt(cellPadding)*2):parseInt(this.obj.style.height);
		}
	}
	this.init=function(){
		if(this.noCheckPos)
			this.l = this.t = 0;
		else{
			var tmpPos = jtongfu_getObjectXY(this.obj);
			this.l = tmpPos.x;
			this.t = tmpPos.y;
		}
		this.w = (isNaN(parseInt(this.obj.style.width))!=null)?parseInt(this.obj.clientWidth):parseInt(this.obj.style.width);
		this.h = (isNaN(parseInt(this.obj.style.height))!=null)?parseInt(this.obj.clientHeight):parseInt(this.obj.style.height);
		this.getCellWH();
		this.r = this.l+this.w;
		this.b = this.t+this.h;
		//alert('l:'+this.l+'\nt:'+this.t+'\nw:'+this.w+'\nh:'+this.h+'\nr:'+this.r+'\nb:'+this.b);
	}
	this.inme=function(x,y){
		if((x>=this.l&&y>=this.t&&y&&x<=this.r&&y<=this.b)){
			return true;
		}
		return false;
	}
	this.init();
}

function CallJTongfuScript(src){
	document.write('<script language="javascript" type="text/javascript" src="'+jtongfu_arguments.classPath+'jtongfu/jtongfu.'+src+'.js"></script>');
}

function appendEvent(obj, sEvtName, Func, NotGroup){
	if(!NotGroup && typeof(obj.length) != 'undefined'){
		for(ii=0;ii<obj.length;ii++){
			appendEventElement(obj[ii], sEvtName, Func);
		}
	}
	else{
		appendEventElement(obj, sEvtName, Func);
	}
}

function appendEventElement(obj, sEvtName, Func){
	if(typeof(document.addEventListener)!='undefined'){
		sEvtName = sEvtName.replace(/^on/i, "");
		obj.addEventListener(sEvtName, Func, false);
	}
	else if(typeof(document.attachEvent)!='undefined'){
		if(obj[sEvtName]==null){
			obj[sEvtName] = Func;
		}
		else{
			obj.attachEvent(sEvtName, Func);
		}
	}
}

function jtongfuObject(obj){
	if(typeof(obj)!='undefined'&&obj!=null){
		obj.jtfSL=obj.jtfST=obj.jtfSW=obj.jtfSH=null;
		obj.setAbs=function(val,zIndex){
			this.style.position=(val)?'absolute':'relative';
			if(parseInt(zIndex)>0)
				this.style.zIndex=zIndex;
		}
		obj.setSLT=function(l,t){
			if(!isNaN(parseInt(l))) this.style.left=obj.jtfSL=parseInt(l)+'px';
			if(!isNaN(parseInt(t))) this.style.top=obj.jtfST=parseInt(t)+'px';
		};
		obj.setSWH=function(w,h){
			if(!isNaN(parseInt(w))) this.style.width=obj.jtfSW=parseInt(w)+'px';
			if(!isNaN(parseInt(h))) this.style.height=obj.jtfSH=parseInt(h)+'px';
		};
/*		var attrs=obj.attributes;
		var attrl=attrs.length;
		var ai=0;
		for(ai=0;ai<attrl;ai++)
			eval('obj.'+attrs[ai].name+'="'+attrs[ai].value+'"');*/
//		var newObj=new jtongfu_obj1(obj);
//		obj.setSLT(newObj.l,newObj.t);
//		obj.setSWH(newObj.w,newObj.h);
		obj.getAttr=function(attrName){
			var attrl=this.attributes.length;
			var ai=0;
			for(ai=0;ai<attrl;ai++){
				if(this.attributes[ai].name==attrName)
					return this.attributes[ai].value;
			}
			return null;
		};
		obj.test=function(checkPos){
			var tmpObj=new jtongfu_obj1(this,(typeof(checkPos)=='undefined'||checkPos==null)?true:checkPos);
			this.setSLT(tmpObj.l,tmpObj.t);
			this.setSWH(tmpObj.w,tmpObj.h);
		};
		obj.where=function(){
			alert('id:'+this.id+'\n'+
				'l:'+this.jtfSL+'\n'+
				't:'+this.jtfST+'\n'+
				'w:'+this.jtfSW+'\n'+
				'h:'+this.jtfSH+'\n'+
				'pst:'+this.style.position);
		};
	}
	return obj;
}
function jtf$(id){
	var newObj=null;
	if(typeof(id)=='string')
		newObj=document.getElementById(id);
	else
		newObj=id;
	if(newObj!=null)
		return jtongfuObject(newObj,false);
	return null;
}

function $$(id){
	var newObjs=document.getElementsByName(id);
	var newObjl=newObjs.length;
	var newObji=0;
	for(newObji=0;newObji<newObjl;newObji++)
		jtf$(newObjs[newObji]);
	return newObjs;
}

function envSL(){
	return (document.body.scrollLeft>0)?document.body.scrollLeft:document.documentElement.scrollLeft;
}

function envST(){
	return (document.body.scrollTop>0)?document.body.scrollTop:document.documentElement.scrollTop;
}

function apendMMEvent(){
	
}

var mousePositionJTongfu = new Object();
function getMousePos(eve){
	if(window.event){
		mousePositionJTongfu.x = window.event.x+envSL();
		mousePositionJTongfu.y = window.event.y+envST();
	}
	else{
		mousePositionJTongfu.x = eve.clientX+envSL();
		mousePositionJTongfu.y = eve.clientY+envST();
	}
}

function SetCookie(name,value,expired,path,domain)
{
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires = new Date();
	if(expired == null){
		expired = 24*60*60*1000*365;
	}
	if(path != null){
		path = ";path="+path;
	}
	else{
		path = "";
	}
	if(domain != null){
		domain = ";domain="+domain;
	}
	else{
		domain = "";
	}
	expires.setTime(expires.getTime()+(expired));
	cookieStr = name+"="+escape(value)+((expires==null)?"":(";expires="+expires.toGMTString()))+(path)+(domain);
	//alert(cookieStr);
	document.cookie = cookieStr;
}

function GetCookie(name)
{
	var abc=document.cookie.split("; ");
	var cstr="";
	var rstr="";
	var nlen=name.length;
	for(i=0;i<abc.length;i++)
	{
		cstr=abc[i].indexOf(name+"=");
		if(cstr!=-1)
		{
			cstr=cstr+nlen+1;
			rstr=unescape(abc[i].substring(cstr,abc[i].length));
			break;
		}
	}
	if(rstr){
		return rstr;
	}
	else{
		return null;
	}
}

var ajax_get_tiems_statistic=0;
var ajax_post_tiems_statistic=0;
var ajax_get_urls=new String();
var ajax_post_urls=new String();
function ajax()
{
	this.com;
	this.ret;
	this.lastmodified;
	this.etag;
	this.regheader=new Array("User-Agent",
		"Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4",
		"Accept",
		"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,\*/\*;q=0.5",
		"Accept-Language",
		"zh-cn",
		"Accept-Encoding",
		"gzip,deflate",
		"Accept-Charset",
		"gb2312,utf-8;q=0.7,*;q=0.7",
		"Keep-Alive",
		"300",
		"Connection",
		"keep-alive");
	this.init=function()
	{
 		var msxmlhttp=new Array(
					'Msxml2.XMLHTTP.5.0',
					'Msxml2.XMLHTTP.4.0',
					'Msxml2.XMLHTTP.3.0',
					'Msxml2.XMLHTTP',
					'Microsoft.XMLHTTP');
		for(i=0;i<msxmlhttp.length;i++)
		{
			try
			{
				this.com=new ActiveXObject(msxmlhttp[i]);
			}
			catch(e)
			{
				this.com=null;
			}
		}
		if(!this.com
			&& typeof XMLHttpRequest != "undefined"){
			this.com=new XMLHttpRequest();
		}
		if(!this.com)
		{
			alert("Your Browser doesn't support Ajax technology.");
		}
		this.ret=false;
	}
	this.actStatus=function(text)
	{
		status=text;
	}
	this.actGET=function(url)
	{
		var tobj=this;
		ajax_get_tiems_statistic++;
		ajax_get_urls+=url+'\r\n';
		tobj.ret=false;
		(url.indexOf('?')!=-1) ? url=url+"&randomstring="+Math.random() : url+"?randomstring="+Math.random() ;
		tobj.com.open("GET", url, true);
		tobj.com.setRequestHeader("Host", document.domain);
		reglen=tobj.regheader.length;
		for(regi=0;regi<reglen;regi=regi+2){
			tobj.com.setRequestHeader(tobj.regheader[regi], tobj.regheader[regi+1]);
		}
		if(tobj.lastmodified!=null
			&&tobj.etag!=null
			&&tobj.lastmodified!=""
			&&tobj.etag!="")
		{
			tobj.com.setRequestHeader("If-Modified-Since", tobj.lastmodified);
			tobj.com.setRequestHeader("If-None-Match", tobj.etag);
		}
		tobj.com.onreadystatechange=function()
		{
			tobj.ret=true;
			if(tobj.com.readyState==4)
			{
				tobj.lastmodified=tobj.com.getResponseHeader("Last-Modified");
				tobj.etag=tobj.com.getResponseHeader("ETag");
				/*if(tobj.com.status!=200)
				{
					tobj.ret=false;
				}*/
				tobj.doGetAfter(tobj);
			}
			else{
				tobj.doGetOn(tobj);
			}
		};
		tobj.actStatus('loading...');
		tobj.com.send(null);
	}
	this.doGetAfter=function(obj)
	{
		if(obj.afterGET!=null){
			obj.afterGET();
		}
		obj.actStatus('done');
	}
	this.doGetOn=function(obj)
	{
		if(obj.onGET!=null){
			obj.onGET();
		}
		obj.actStatus('done');
	}
	this.doPostAfter=function(obj)
	{
		if(obj.afterPOST!=null){
			obj.afterPOST();
		}
		obj.actStatus('done');
	}
	this.doPostOn=function(obj)
	{
		if(obj.onGET!=null){
			obj.onGET();
		}
		obj.actStatus('done');
	}
	this.actPOST=function(url,data,contenttype)
	{
		var tobj=this;
		ajax_post_tiems_statistic++;
		ajax_post_urls+=url+'\r\n';
		(url.indexOf('?')!=-1) ? url=url+"&randomstring="+Math.random() : url+"?randomstring="+Math.random() ;
		tobj.com.open("POST", url, true);
		tobj.com.setRequestHeader("Host", document.domain);
		reglen=tobj.regheader.length;
		for(regi=0;regi<reglen;regi=regi+2){
			tobj.com.setRequestHeader(tobj.regheader[regi], tobj.regheader[regi+1]);
		}
		if(contenttype==null){
			tobj.com.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
		}
		else{
			tobj.com.setRequestHeader("Content-Type", contenttype);
		}
		tobj.com.setRequestHeader("Content-Length", data.length);
		tobj.com.onreadystatechange=function()
		{
			tobj.ret=true;
			if(tobj.com.readyState==4)
			{
				/*if(tobj.com.status!=200)
				{
					tobj.ret=false;
				}*/
				tobj.doPostAfter(tobj);
			}
			else{
				tobj.doPostOn(tobj);
			}
		};
		tobj.actStatus('loading...');
		tobj.com.send(data);
	}
	this.afterGET;
	this.afterPOST;
	this.onGET;
	this.onPOST;
	this.init();
}
