﻿var Yifu={};
var isapple = (navigator.userAgent.indexOf('AppleWebKit') != -1);  // Safari, Chrome
var isopera = (navigator.userAgent.indexOf('Opera') != -1)&&(typeof window.opera == 'object'); //Opera
var isie = typeof window.attachEvent != 'undefined' && !isopera;
var isie70 = isie && typeof window.XMLHttpRequest != 'undefined';  // IE7, IE8
var isie60 = isie && typeof window.XMLHttpRequest == 'undefined';  // IE6, IE5.5, IE5.0
var isie55 = isie && typeof document.compatMode == 'undefined';    // IE5.5, IE5.0
var isie50 = isie55 && typeof Array.prototype.push == 'undefined'; // IE5.0

function $(id){return document.getElementById(id);}function insertEventListener(element,eventName,handle){if(typeof element.addEventListener!='undefined'){element.addEventListener(eventName,handle,false);}else if(typeof element.attachEvent!='undefined'){element.attachEvent('on'+eventName, handle);}else{if(typeof element['on'+eventName]=='function'){var oldFunction=element['on'+eventName];element['on'+eventName]=function(){oldFunction();return handle();};}else{element['on'+eventName]=handle;}}}function deleteEventListener(element,eventName,handle){if(typeof element.removeEventListener!='undefined'){element.removeEventListener(eventName,handle,false);}else if(typeof element.detachEvent!='undefined'){element.detachEvent('on'+eventName,handle);}else{element['on'+eventName]=null;}}function $L(func){insertEventListener(window,'load',func);}function $RS(element,style_key){if(typeof element.currentStyle!='undefined'){return element.currentStyle[style_key];}else{return document.defaultView.getComputedStyle(element, null)[style_key];}}function a(obj){if(typeof obj!='object')return false;try{obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);}catch(e){alert('对不起，您的浏览器不支持该操作。');}return false;}function b(){if(window.sidebar){window.sidebar.addPanel(title,url,desc);return;}try{window.external.AddFavorite(url,title);}catch(e){alert('对不起，您的浏览器不支持该操作。');}return false;}
if(typeof Array.prototype.push=='undefined'){Array.prototype.push=function(){for(var i=0;i<arguments.length;i++){this[this.length]=arguments[i];}return arguments[i-1];};}
// -- 仿移动窗口 ---------------------------------
Yifu.Window = function(obj) {
	if(typeof obj != 'object' || obj == null || typeof obj.pro =='object'){alert(obj.pro);return false;}
	this.oPosition = $RS(obj, 'position'); // 原始 position
	if(this.oPosition == 'static' || isie60 && (this.oPosition == 'fixed')) {obj.style.position = 'relative';}
	if(!parseInt($RS(obj, 'left'))) obj.style.left = '0px'; // 未设置 left
	if(!parseInt($RS(obj, 'top'))) obj.style.top = '0px'; // 未设置 top
	this.oCursor = $RS(obj, 'cursor'); // 原始鼠标形态
	obj.style.cursor = 'move';
	this.obj = obj;
	this._left = 0;
	this._top = 0;
	this._x = 0;
	this._y = 0;
	this.obj.pro = this;
	insertEventListener(this.obj, 'mousedown', this.mousedownHandel);
};
Yifu.Window.prototype = {
	mousedownHandel : function(e) {
		if(typeof e == 'undefined') e = window.event;
		var obj = isie ? e.srcElement : e.target;
		if(!obj.pro) return false;
		Yifu.Window.current = obj.pro;
		obj.pro._left = parseInt($RS(obj, 'left'));
		obj.pro._top = parseInt($RS(obj, 'top'));
		obj.pro._x = e.clientX;
		obj.pro._y = e.clientY;
		insertEventListener(document, 'mousemove', Yifu.Window.current.mousemoveHandle);
		insertEventListener(document, 'mouseup', Yifu.Window.current.mouseupHandel);
		if(typeof e.preventDefault != 'undefined'){e.preventDefault();} // Mozilla Firefox
		return e.returnValue = false; // IE
	},
	mousemoveHandle : function(e) {
		if(typeof e == 'undefined') e = window.event;
		Yifu.Window.current.obj.style.left = e.clientX - Yifu.Window.current._x + Yifu.Window.current._left + 'px';
		Yifu.Window.current.obj.style.top = e.clientY - Yifu.Window.current._y + Yifu.Window.current._top + 'px';
		return e.returnValue = false; // 禁止选取
	},
	mouseupHandel : function(e) {
		if(!Yifu.Window.current) return false;
		deleteEventListener(document, 'mousemove', Yifu.Window.current.mousemoveHandle);
		deleteEventListener(document, 'mouseup', Yifu.Window.current.mouseupHandel);
		if(!Yifu.Window.current) Yifu.Window.current = null;
		return e.returnValue = false;
	}
};
Yifu.Window.regist = function(obj) {
	return new Yifu.Window(obj);
};
Yifu.Window.unRegist = function(obj) {
	if(typeof obj.pro == 'object' && obj.pro != null) {
		deleteEventListener(obj, 'mousedown', obj.pro.mousedownHandel);
		obj.style.cursor = obj.pro.oCursor;
		//obj.style.position = obj.pro.oPosition;
		obj.pro = 'undefined';
	}
};
// 动画处理模块 -------------------------------------
Yifu.An = function(func, pt) {
	if(typeof func != 'function') return false;
	this.mark = null;
	this.moving = false;
	this.loop = func;
	this.pt = ((typeof pt == 'number' && pt > 0) ? pt : 50);
};
Yifu.An.prototype = {
	go : function() {
		var _this = this;
		if(!this.moving) {
			this.mark = setInterval(function(){_this.loop();}, this.pt);
			this.moving = true;
		}
	},
	end : function() {
		clearInterval(this.mark);
		this.moving = false;
	}
};
Yifu.Ajax={request:false,loadingElement:null,showLoading:function(){if(!this.loadingElement)return;this.loadingElement.style.display='block';},hideLoading:function(){if(!this.loadingElement)return;this.loadingElement.style.display='none';},getReqeust:function(){if(window.XMLHttpRequest){this.request=new XMLHttpRequest();}else{try {this.request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){try{this.request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){his.request=false;}}}return this.request;},ajax:function(req){var _this=this;this.stop();this.getReqeust();this.request.onreadystatechange=function(){_this.callback(req);};this.request.open(req.method,req.url,true);if(req.method.toLowerCase!='get'){this.request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.request.send(req.parameters);}else{this.request.send(null);}},callback:function(req){if(!this.request)return false;if(this.request.readyState==4){if(req.showLoading!=false)this.hideLoading();if(this.request.status==200||this.request.status==304){if(typeof req.finish=='function')req.finish(this.request);}else{if(typeof req.failed=='function')req.failed(this.request);else this.failed(this.request.status);}}else if(this.request.readyState==1){if(req.showLoading!=false)this.showLoading();if(typeof req.loading=='function')req.loading();}},stop:function(){if(!this.request)return false;this.request.abort();},failed:function(status){this.stop();switch(status){case 0:/*alert('请求出现错误:重复请求, 上次的请求被取消 ！');*/ break;case 400:alert('错误 : 错误的请求 ！'); break;case 401:alert('错误 : 没有权限 ！'); break;case 404:alert('错误 : 未找到请求的资源 ！'); break;case 500:alert('错误 : 服务器端出现异常 ！');break;default:alert('错误 ！\n状态码:'+status);}},onError:function(status){this.stop();var msg='错误:'+(e.message?e.message:e)+'！\n\n';if(e.number)msg+='\n错误号:'+(e.number&0xFFFF);if(e.lineNumber)msg+='\n行:'+e.lineNumber;alert(msg);},init:function(){if(this.loadingElement)return true;if(document&&document.getElementsByTagName&&document.getElementById&&document.body){this.loadingElement=document.createElement("div");var cssText='z-index:999;position:fixed;right:10px;top:10px;padding:2px 5px;width:100px;border:1px solid #333333;color:#FFFFFF;background-color:#FF0000;font-size:12px;font-weight:bold;display:none;';var top='';if(isie){if(typeof document.compatMode=='undefined'||document.compatMode=='BackCompat'){top='position:absolute;top:expression(eval(document.body.scrollTop+10));';}else if(!isie70){top='position:absolute;top:expression(eval(document.documentElement.scrollTop+10));';}}cssText+=top;this.loadingElement.style.cssText=cssText;this.loadingElement.innerHTML='正在加载...';document.body.appendChild(this.loadingElement);}else{$L(function(){Yifu.Ajax.init();});}}};Yifu.Ajax.init();
