// JavaScript Document
function checkallbox(form){
		for (var i=0;i<form.elements.length;i++)
		{
			var e = form.elements[i];
				if (e.checked==false)
					e.checked = true;
				else
					e.checked = false;
		}
}

function checkchildselect(toid,url,data){//二级下拉
if(!url)return false;
/*if(val==0){
	$("#"+toid).empty();$("#"+toid).append("<option value=\"0\">请选择</option>");
	return false;
	}*/
$.ajax({
 type: "GET",
 url: url,
 async: false,
 data:   data,
 success: function(data){$("#"+toid+" option:gt(0)").remove();$("#"+toid).append(data); } 
});
}
//删除TR
function deltr(obj){
	$(obj).parent().parent().remove();
}
//显示弹出框
function displaySubMenu(obj,toid) {
		var test=$(obj).offset();
		$("#"+toid).css({left:test.left-$("#"+toid).outerWidth()+$(obj).outerWidth(),top:test.top+$(obj).outerHeight()-1}).show();
		//if(getie()<70){hideAllSelect();}
		//$("body").not("#"+toid).click(function(){$("#"+toid).hide();});
		
	}
	function hideSubMenu(obj,toid) {
		//if(getie()<70){showAllSelect();}
		$("#"+toid).hide();
		
}
function strip_tags (str, allowed_tags) {

    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
 
    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }
 
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}

function nl2br (str, is_xhtml) {
    var breakTag = '';

    breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }

    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}
function typeset(str)//文字排版正则替换
{
	//修正不规则标点
	str=str.replace(/,/gi,"，");
	str=str.replace(/\.\r/gi,"。\r");
	str=str.replace(/．/gi,"。");
	//str=str.replace(/;/gi,"；");
	str=str.replace(/\"/gi,"＂");
	str=str.replace(/\'/gi,"｀");
	str=str.replace(/!/gi,"！");
	str=str.replace(/\(/gi,"（");
	str=str.replace(/\)/gi,"）");
	str=str.replace(/【/gi,"「");
	str=str.replace(/『/gi,"「");
	str=str.replace(/】/gi,"」");
	str=str.replace(/』/gi,"」");
	//修正不规则换行，其中 。？！…」”）\n\r 为有效换行标志符．（注意：此代码将破坏所有无效标点换行）
	str=str.replace(/([^。？！…」”）\n\r])[\n\r]{2}/gi,"$1");
	//修正不规则段落
	str="\n"+str;
	str=str.replace(/[\n|\r]+[ |　|\t]*/gi,"\n\n　　");
	//str=str.replace("\n\n","");

	return str;
}
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        }
                        catch (e) {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}
function displaySubMenu(id){
	$("#menu1").html($("#menu_"+id).html());
	//$("#menu a#"+id).addClass("select");
}
function greemove(way,id,obj){
	var boxwidth=$('#'+id).parent().width();
	var ulwidth=$('#'+id).width();
	if(ulwidth<boxwidth)return false;
		$.getScript("/ctdoors/inc_greemove.php?way="+way+"&boxwidth="+boxwidth+"&ulwidth="+ulwidth+"&nowleft="+$('#'+id).css('left')+"&ulid="+id);
}
