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)
{
	if(!_G(id))	return;
	_G(id).parentNode.removeChild(_G(id));
}
function $CE(tagName)
{
    return document.createElement(tagName);
}
function $RC(father,son)
{
	return _G(father).removeChild(_G(son)); 
}

//首页轮换 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"
		}
	}
} 
function loading(id,msg)
{
	$('#'+id).html('<img src="'+site_root+'skin/img/default/loading.gif" align="absmiddle" border="0"/> &nbsp;&nbsp;'+(msg ? msg+'...' : ''));
}
//==================  以下是表单种按ctrl+enter提交的代码===================\\
function isKeyTrigger(e,keyCode){
    var argv = isKeyTrigger.arguments;
    var argc = isKeyTrigger.arguments.length;
    var bCtrl = false;
    if(argc > 2){
        bCtrl = argv[2];
    }
    var bAlt = false;
    if(argc > 3){
        bAlt = argv[3];
    }

    var nav4 = window.Event ? true : false;

    if(typeof e == 'undefined') {
        e = event;
    }

    if( bCtrl && 
        !((typeof e.ctrlKey != 'undefined') ? 
            e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)){
        return false;
    }
    if( bAlt && 
        !((typeof e.altKey != 'undefined') ? 
            e.altKey : e.modifiers & Event.ALT_MASK > 0)){
        return false;
    }
    var whichCode = 0;
    if (nav4) whichCode = e.which;
    else if (e.type == "keypress" || e.type == "keydown")
        whichCode = e.keyCode;
    else whichCode = e.button;

    return (whichCode == keyCode);
}

function ctrlEnter(obj,e){
    var ie =navigator.appName=="Microsoft Internet Explorer"?true:false; 
    if(ie){
        if(event.ctrlKey && window.event.keyCode==13){dosubmit(obj);}
    }else{
        if(isKeyTrigger(e,13,true)){dosubmit(obj);}
    }
}
function dosubmit(obj)
{
	obj.action += '&dosubmit=1';
	obj.submit();
}
//=============================调用的时候只需要在TEXTAREA中增加 onkeyup="javascript:return ctrlEnter(obj,event);" 其中obj是表单对象，比如在表单内可以用this.form
function get_pos(e)
{
	var ev = e || window.event;
	if(ev.pageX || ev.pageY)
	{
		return {x:ev.pageX, y:ev.pageY};
	}
	return	{x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop  - document.body.clientTop};
}

if(typeof(decode)!='function')
{
	function decode(str)
	{
		return decodeURIComponent(str).replace(/\+/g,' ');
	}
}
function make_select(arr,name,sid,ext,first_opt)
{
	if(!ext)	ext = '';
	if(!first_opt)	first_opt = '';
	if(!sid)	sid  = 0;
	if(!name)	name = '';
	var slt = '<select name="'+name+'" '+ext+'>'+first_opt;
	$.each(arr,function(i,n){slt += '<option value="'+n+'"'+(n==sid?' selected':'')+'>'+i+'</option>';});
	return slt + '</select>';
}
function is_check(id)
{
	var check = 0;
	id = id ? '#'+id : 'form';
	$(id+' input[type="checkbox"]').each(function(){if($(this).attr('checked')){check=1;return false;}});
	return check;
}