function in_array(str,arr)
{
	for(var i=0;i<arr.length;i++)	if(str==arr[i])	return true;
	return false;
}

Array.prototype.unique = function()
{
	var a = [];
	for(var i=0;i<this.length;i++)
	{
		if(!in_array(this[i],a))	a.push(this[i]);
	}
	return a;
}

function _G(id)
{
	return document.getElementById(id);
}

function redirect(url)
{
	window.location.replace(url);
}

function get_ext(path)
{
	return path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
}

function is_image(ext)
{
	return $.inArray(ext,['jpg','gif','png','bmp','jpeg'])!=-1;
}

function preview(src,str,w)
{
	document.getElementById('message').style.display = (src || str) ? '' : 'none';
	$('#message').empty();
	if(!w)	var w=400;
	if(src)	$('#message').append(insert_img(decodeURIComponent(src),w));
	if(str)
	{
		$('#message').append('<p Style="width:400px;overflow:hidden;text-align:left;line-height:18px">'+(decodeURIComponent(str).replace(/\+/g,' '))+'</p>');
	}
}
function check_all(id)
{
	(id ? $('#'+id+' > input[type="checkbox"][name!="chkall"]') : $('form input[type="checkbox"][name!="chkall"]')).each(function(){$(this).attr('checked',($(this).attr('checked') ? false : true))});
}
//jquery下显示采用display:block，这导致在火狐下的tbody格式乱套了
function show_hide(id)
{
	return _G(id).style.display = _G(id).style.display=='none' ? '' : 'none';
}
//删除指定节点
function $RN(id)
{
	_G(id).parentNode.removeChild(_G(id));
}
function $CE(tagName)
{
    return document.createElement(tagName);
}
function $RC(father,son)
{
	return _G(father).removeChild(_G(son)); 
}

function is_element(id)
{
	return document.getElementById(id) ? 1 : 0;
}
if(typeof(decode)!='function')
{
	function decode(str)
	{
		return decodeURIComponent(str).replace(/\+/g,' ');
	}
}
function popup_div(html)
{
	$('body').append('<div id="full_window"></div><div id="dialog"><h3><a href="javascript:close_dialog()" title="关闭">关闭</a></h3><div class="content_wrap">'+html+'</div></div>');
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	$('#full_window').css({
					'height':clientHeight+'px',
					'width':clientWidth+20+'px',
					'zIndex':9999,
					'position':(document.all?'absolute':'fixed'),
					'top':'0px',
					'left':'0px',
					'margin':'0px',
					'background':'#000000',
					'opacity':'0.3',
					'filter':'Alpha(opacity=30)'
				});
}
function set_center(id)
{
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var w = parseInt($('#'+id).css('width'));
	var h = parseInt($('#'+id).css('height'));
	var left = (clientWidth - (w?w:400))/2;
	var top = (clientHeight - (h?h:300))/2;
	$('#'+id).css({'left':left,'top':top,'position':'absolute'});
}
function close_dialog()
{
	$RN('full_window');
	$RN('dialog');
}
function show_more(id,w,h)
{
	var html = $('#'+id).html().replace(/【<a[^>]+>显示全部\.\.\.<\/a>】/ig,'');
	w = w ? w+'px' : '400px';
	h = h ? h+'px' : '300px';
	popup_div(html);
	$('#dialog').css({'width':w,'height':h});
	set_center('dialog');
}

function setXY(id,w,e) {
	if(_G(id)) {
		divElement = _G(id);
	} else {
		var divElement = document.createElement("DIV");
		divElement.id = id;
		document.body.appendChild(divElement);
	}
	divElement.className = "ajaxdiv";
	divElement.style.cssText = "width:"+w+"px;";
	divElement.style.position = 'absolute';
		
	var offX = 4;
	var offY = 4;
	var width = 0;
	var height = 0;
	var scrollX = 0;
	var scrollY = 0;  
	var x = 0;
	var y = 0;
		
	if (window.innerWidth) width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		width = document.body.clientWidth;
		
	
	if (window.innerHeight) height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		height = document.body.clientHeight;
	

	if (typeof window.pageXOffset == "number") scrollX = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scrollX = document.body.scrollLeft; 
	else if (window.scrollX) scrollX = window.scrollX;
				
	  
	if (typeof window.pageYOffset == "number") scrollY = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scrollY = document.body.scrollTop; 
	else if (window.scrollY) scrollY = window.scrollY;
		
	x=e.pageX?e.pageX:e.clientX+scrollX;
	y=e.pageY?e.pageY:e.clientY+scrollY;

	if(x+divElement.offsetWidth+offX>width+scrollX){
		x=x-divElement.offsetWidth-offX;
		if(x<0)x=0;
	}else x=x+offX;
	if(y+divElement.offsetHeight+offY>height+scrollY){
		y=y-divElement.offsetHeight-offY;
		if(y<scrollY)y=height+scrollY-divElement.offsetHeight;
	}else y=y+offY;

	divElement.style.left = x+"px";
	divElement.style.top = y+"px";
}

//首页轮换 a:当前id b:轮换总数 c:区别使用该函数
// 轮换列表命名规则 tab'c'_m'a' 轮换层ID命名规则 tab'c'_'a' 
function swap_tab(a,b,c){
	for(var i=1;i<=b;i++){
		if(a==i){
			_G("tab"+c+"_"+i).style.display="block";
			_G("tab"+c+"_m"+i).className="active"
		}else{
			_G("tab"+c+"_"+i).style.display="none";
			_G("tab"+c+"_m"+i).className="normal"
		}
	}
} 