var isIE = false;
var userAgent = navigator.userAgent.toLowerCase();
if ((userAgent.indexOf('msie') != -1) && (userAgent.indexOf('opera') == -1)) {
	isIE = true;
}
Function.prototype.bind = function() { 
	var __m = this, object = arguments[0], args = new Array(); 
	for(var i = 1; i < arguments.length; i++){
		args.push(arguments[i]);
	}
	
	return function() {
		return __m.apply(object, args);
	};
};

Function.prototype.bindAsEventListener = function() { 
	var __m = this, object = arguments[0], args = new Array();
	for(var i = 1; i < arguments.length; i++){
		args.push(arguments[i]);
	}
	
	return function(event) {
		return __m.apply(object, [( event || window.event)].concat(args));
	};
};


function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function G(ele){
	var e = document.getElementById(ele);
	e.tagWith = function(tag){
		var a = [];
		var tags = this.getElementsByTagName(tag);
		for(var i=0; i < tags.length;i ++){
			a.push(tags[i]);
		}
		a.findClass = function(className){
			var result = [];
			a.each(function(e){
				if(e.className.indexOf(className) != -1){
					result.push(e);
				}
			}); 			
			return result;
		}
		return a;
	}
	return e;	
}



Array.prototype.each = function(callback){
	for(var i = 0;i < this.length; i ++){
		callback(this[i]);
	}
}
Array.prototype.indexOf = function(e){
	for(var i = 0; i < this.length; i ++){
		if(this[i] == e){
			return i;
		}	
	}
}
Array.prototype.pushAll = function(a){
	for(var i=0; i < a.length; i ++){
		this.push(a[i]);
	}
}

function getXMLHttpRequest() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

//执行GET操作的调用
function doGet(url,method,obj){
  var req = getXMLHttpRequest();
  req.onreadystatechange = function () {
    if (req.readyState == 4) {
    	if(req.status == 200){
	      var data=req.responseText; 
	      method(data);
	    }
    }else{
    if(obj){
    	//obj.innerHTML ="<div style='text-align:center;font-family:Arial,'宋体';font-size:14px;'><strong>正在加载中，请稍后....</strong></div>";
    }
    }
  };
  req.open("GET",url, true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req.send(null);
}
//执行POST方式的调用
function doPost(url,params,method){
  var req = getXMLHttpRequest();
  req.onreadystatechange = function () {
    if (req.readyState == 4 && req.status == 200) {
      var data=req.responseText; 
      method(data);
    }
  };
  req.open("POST",url, true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req.send(params);
}
function initCookie(){
document.cookie="gam=-1;expires=Fri,1-Jan-3000 00:00:00 GMT;path=/";
}
function getCookie(cookieName){
	var s=document.cookie.indexOf(cookieName);
	if(s==-1){
		return null;
	}
	var e=document.cookie.indexOf(";",s);
	if(e==-1){
		return document.cookie.substring(s+cookieName.length+1);
	}else{
		return document.cookie.substring(s+cookieName.length+1,e);
	}
}


//去掉字符串前后的空白
String.prototype.trim = function () {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

//获得指定的对象标签中的内容
function getElementText(obj){
	var text = "";
	if(isIE){
		text = G(obj).innerText;
	} else{
		text = G(obj).textContent;
	}
	return text;

}

function chimg(){
	G("ckimg").src="/image.jsp?"+new Date();
}

function showimg(obj)
{
	obj.style.margin = '2px';
	obj.style.cursor="hand";
	if (obj.width > 460)
	{
		obj.resized = true;
		obj.height = (obj.height/obj.width)*460;
		obj.width = 460;
		obj.alt = '点击图片在新窗口查看大图';
		obj.title = '点击图片在新窗口查看大图';
	}
}

function showerr(obj){
	obj.src="/image/img_nt_gl.gif";
	obj.width=250;
	obj.height=160;
}


function clearMesg(spid){
	if(G("ckimg").style.visibility =="hidden"){
		G("ckimg").src="/image.jsp";
		G("ckimg").style.visibility ="visible";
		G("chimgA").style.visibility ="visible";
	}
}
function floatGame(){
var slide = document.getElementById("floatGame");
if(slide){
	var slideInterval = 1;
	var slideHeight = 2;
	var slideMinHeight = 30;
	var slideMaxHeight = 60;
	
	var upTimer=null, dowmTimer =null;
	
	slide.onmouseover = function(){
		if(typeof upTimer !="undefined") clearInterval(upTimer);
		downTimer = setInterval(fn, slideInterval);
		function fn(){
			var sHeight = slide.style.height;
			if(parseInt(sHeight) < slideMaxHeight){
				slide.style.height = (parseInt(sHeight) + slideHeight) + "px";
			}else{
				clearInterval(downTimer);
			}
		}
	};
	
	slide.onmouseout = function(){
		if(typeof downTimer !="undefined" ) clearInterval(downTimer);
	
		upTimer = setInterval(fn, slideInterval);
		function fn(){
			var sHeight = slide.style.height;
			if(parseInt(sHeight) > slideMinHeight){
				slide.style.height = (parseInt(sHeight) - slideHeight) + "px";
			}else{
				clearInterval(upTimer);
			}
		}
		
	};
}
}
addLoadEvent(floatGame);
