var fade_timer = null;
var fade_times = 3;
var fade_ctime = 0;
  

function removemask(_id)
{
	var div = document.getElementById(_id);
	if (div)
		document.body.removeChild(div);
}
function fade_out()  
{
	var isIE = document.all ? true : false;
	if(isIE)
		setSelectState('');
	removemask("mask1");
	removemask("mask2");
	removemask("mask3");
	removemask("mask4");
}
  
function fade_in(_id)
{
	var isIE = document.all ? true : false;
	var bWidth=parseInt(document.documentElement.scrollWidth);
	var bHeight=parseInt(document.documentElement.scrollHeight)<592?592:parseInt(document.documentElement.scrollHeight);
	if(isIE)
	{
		setSelectState('hidden');
	}
	
//	document.body.style.overflow = 'hidden';
// 	document.body.style.height = document.documentElement.clientHeight +2+ 'px';
document.body.scroll="no";
	var ber = 0;
	var box = getElementBox(_id);
	_createmaskdiv('mask1',0,0,box.x-ber,box.y+box.h,'down1');
	_createmaskdiv('mask2',box.x-ber,0,bWidth-box.x+ber,box.y-ber,'left1');
	_createmaskdiv('mask3',box.x+box.w,box.y-ber,bWidth-box.x-box.w,bHeight-box.y+ber,'up1');
	_createmaskdiv('mask4',0,box.y+box.h,box.x+box.w,bHeight-box.y-box.h,'right1');

	window.clearTimeout(fade_timer);
	fade_timer = null;
	fade_ctime = 0;
	fade_timer = window.setTimeout(bigfade,50);

 	SetTop("restore");
}


function changediv(_id,_deltatime)
{
	var div = document.getElementById(_id);     
	var delta = 0; 
	
	if (div.direction =='left')
	{
		delta = div.storewidth / _deltatime;
		div.style.left = parseInt(div.style.left)-delta+'px';
		div.style.width = parseInt(div.style.width)+delta+'px';
	}
	else if (div.direction =='right')
	{
		delta = div.storewidth / _deltatime;
		div.style.width = parseInt(div.style.width)+delta+'px';
	}
	else if (div.direction =='down')
	{
		delta = div.storeheight / _deltatime;
		div.style.height = parseInt(div.style.height)+delta+'px';
	}
	else if (div.direction =='up')
	{
		delta = div.storeheight / _deltatime;
		div.style.top = parseInt(div.style.top)-delta+'px';
		div.style.height = parseInt(div.style.height)+delta+'px';
	}
	
}

function bigfade()
{
	window.clearTimeout(fade_timer);
	fade_timer = null;
	changediv('mask1',fade_times);
	changediv('mask2',fade_times);
	changediv('mask3',fade_times);
	changediv('mask4',fade_times);
	fade_ctime++;
	if (fade_ctime<fade_times)
		fade_timer = window.setTimeout(bigfade,50);
}


function SetTop(_id)
{
		var box = getElementBox(_id);
		var div = document.getElementById(_id);
		div.oldp = div.parent;
		div.style.zIndex = 99999;
		div.style.position="absolute";
//		document.body.appendChild(div);

}

function _createmaskdiv(_id,_left,_top,_width,_height,_direction)
{
	var div = window.document.createElement("div");
	div.setAttribute("id",_id);
	div.setAttribute('className','maskstyle');
	div.setAttribute('class','maskstyle');
	if (_direction=='left')
		div.style.left = _left+_width+'px';	 
	else
		div.style.left = _left+'px';	 
	
	if (_direction=='up')
		div.style.top = _top+_height+'px';	 
	else
		div.style.top = _top+'px';	 
		
	if ((_direction=='left') || (_direction=='right'))
		div.style.width = '0px';	 
	else
		div.style.width = _width+'px';	 

	if ((_direction=='up') || (_direction=='down'))
		div.style.height = '0px';	 
	else
		div.style.height = _height+'px';	 

	div.storewidth = _width;
	div.storeheight= _height;
	div.storeleft = _left;
	div.storetop= _top;
	div.direction = _direction;
	
	div.style.display = 'block';
	document.body.appendChild(div);
}

function getElementBox(elementId)
{
	var ua = navigator.userAgent.toLowerCase();     
	var isOpera = (ua.indexOf('opera') != -1);     
	var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof      
	var el = document.getElementById(elementId);      
	var lefttop = getElementPos(elementId);
	if (isIE)
		return {x:lefttop.x-2,y:lefttop.y-2,w:el.offsetWidth,h:el.offsetHeight};
	else
		return {x:lefttop.x,y:lefttop.y,w:el.clientWidth,h:el.clientHeight};
}

function getElementPos(elementId) 
{      
	var ua = navigator.userAgent.toLowerCase();     
	var isOpera = (ua.indexOf('opera') != -1);     
	var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof      
	var el = document.getElementById(elementId);      
	if(el.parentNode === null || el.style.display == 'none')      
	{         
		return false;     
	}      
	
	var parent = null;     
	var pos = [];     
	var box;      
	if(el.getBoundingClientRect)    //IE     
	{         
		box = el.getBoundingClientRect();         
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);         
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);          
		return {x:box.left + scrollLeft, y:box.top + scrollTop};     
	}     
	else if(document.getBoxObjectFor)    // gecko     
	{         
		box = document.getBoxObjectFor(el);                     
		var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;         
		var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;          
		pos = [box.x - borderLeft, box.y - borderTop];     
	}     
	else    // safari & opera     
	{         
		pos = [el.offsetLeft, el.offsetTop];         
		parent = el.offsetParent;         
		if (parent != el) 
		{             
			while (parent) 
			{                 
				pos[0] += parent.offsetLeft;                 
				pos[1] += parent.offsetTop;                 
				parent = parent.offsetParent;             
			}         
		}         
		if (ua.indexOf('opera') != -1              
		|| ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' ))          
		{                 
			pos[0] -= document.body.offsetLeft;                 
			pos[1] -= document.body.offsetTop;         
		}      
	}              
	if (el.parentNode) 
	{ 
		parent = el.parentNode; 
	}     
	else 
	{ 
		parent = null; 
	}        
	
	while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')      
	{ // account for any scrolled ancestors         
		pos[0] -= parent.scrollLeft;         
		pos[1] -= parent.scrollTop;            
		if (parent.parentNode) 
		{ 
			parent = parent.parentNode; 
		}          
		else 
		{ 
			parent = null; 
		}     
	}     
	return {x:pos[0], y:pos[1]}; 
}


//获取滚动条的高度
function getPageScroll()
{
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
//获取页面实际大小
function getPageSize()
{
	var xScroll,yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		sScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;
	var pageHeight,pWidth; 
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	
	if(xScroll < windowWidth) {
		pWidth = windowWidth;
	} else {
		pWidth = xScroll;
	}
	arrayPageSize = new Array(pWidth,pageHeight,windowWidth,windowHeight)
//	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function setSelectState(state)
{
		var objl=document.getElementsByTagName('select');
		for(var i=0;i<objl.length;i++)
		{
			objl[i].style.visibility=state;
		}
}
