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:'+w+'px;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)
{
	if(is_element(id))	_G(id).parentNode.removeChild(_G(id));
}
function $CE(tagName)
{
    return document.createElement(tagName);
}
function $RC(father,son)
{
	return _G(father).removeChild(_G(son)); 
}

if(typeof(decode)!='function')
{
	function decode(str)
	{
		return decodeURIComponent(str).replace(/\+/g,' ');
	}
}
function is_element(id)
{
	return document.getElementById(id) ? 1 : 0;
}
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";
}
function stag(id,num,total)
{
	for(var i=0;i<total;i++)
	{
		$('#'+id+'_content'+i).hide();
	}
	$('#'+id+'_content'+num).show();	
}