//navigate

var gsAgent = navigator.userAgent.toLowerCase();
var gfAppVer = parseFloat(navigator.appVersion);
var gIsOpera = gsAgent.indexOf("opera") > -1;
var gIsKHTML = gsAgent.indexOf("khtml") > -1 || gsAgent.indexOf("konqueror") > -1 || gsAgent.indexOf("applewebkit") > -1;
var gIsSafari = gsAgent.indexOf("applewebkit") > -1;
var gIsIE = ( gsAgent.indexOf("compatible") > -1 && !gIsOpera ) || gsAgent.indexOf("msie") > -1;
var gIsTT = gIsIE ? (navigator.appVersion.indexOf("tencenttraveler") != -1 ? 1 : 0) : 0;
var gIsFF = gsAgent.indexOf("gecko") > -1 && !gIsKHTML;
//var gIsNS = !gIsIE && !gIsOpera && !gIsKHTML && (gsAgent.indexOf("mozilla") == 0) && (navigator.appName.toLowerCase() == "netscape");
//var gIsAgentErr = !( gIsOpera || gIsKHTML || gIsSafari || gIsIE || gIsTT || gIsFF || gIsNS );

if (gIsIE) {
	var reIE = new RegExp("MSIE (\\d+\\.\\d+);", "i");
	reIE.test(navigator.userAgent);
	var gIEVer = parseFloat(RegExp["$1"]);
}

function RegFilter( str ) {
	return str.replace( /([\^\.\[\$\(\)\|\*\+\?\{\\])/ig, "\\$1" ) ;
}
function Template( t, f ) {
	var _t = typeof( t ) == "string" ? t : ( t.join ? t.join( "" ) : "" );
	var _tD, _lD, _f = f ? f : "$", _rf = RegFilter( _f );
	var rP =  function(p) {
		if ( !_tD ) 
			_lD = ( _tD = _t.split( _f ) ).concat();
		for ( var i = 1, _len = _tD.length; i < _len; i += 2 ) 
			_lD[ i ] = p[ _tD[ i ] ];
		return _lD.join( "" );
	};
	var rRE = function( p ) {
		return _t.replace( new RegExp( [ _rf, "(.*?)", _rf ].join( "" ), "ig" ), function( m, v ){return p[ v ];} );
	};
	this.toString = function() {
		return _t;
	};
	this.replace = function( p, defaultFunc ) {
		return ( defaultFunc == "parse" || !( document.all && !( /opera/i.test(navigator.userAgent ) ) ) ? rP : rRE )( p );
	};
};

function T( t, f ) {
	return new Template( t, f );
}

//global base function
var gd = document;
function Gel(id, ob) {
	return ( ob || gd ).getElementById(id);
}
function GelTags(tag, ob) {
	return ( ob || gd ).getElementsByTagName(tag);
}
function S(i, win) {
	try {
		return ( win || window ).document.getElementById(i);
	}
	catch( e ) {
		return null;
	}
}
function SO(i, o) {
	return Gel(i, o);
}
function SN(i, win) {
	try {
		return ( win || window ).document.getElementsByName(i);
	}
	catch( e ) {
		return null;
	}
}
function SNO(i, o) {
	return (o ? o : gd).getElementsByName(i);
}
function F(sID, win) {
	if ( !sID )
		return null;
	var frame = S( sID, win );
	if ( !frame )
		return null;
	return frame.contentWindow || ( win || window ).frames[sID];
}
function E(list, Func, start, end) {
	if (!list)
		return;
	if ( list.constructor == Array ) {
		var len = list.length;
		for (var i = (start || 0), end = end < 0 ? (len + end) : (end < len ? end : len); i < end; i++)
			try{Func(list[i], i, len);}catch(e){}
	}
	else {
		for (var i in list)
			try{Func(list[i], i);}catch(e){}
	}
}
function GetSid() {
	try {var s = top.g_sid;}catch(e){}
	s = s ? s : (S("sid") ? S("sid").value : "");
	if (!s) {
		s = (top.location.href.split("?")[1]).split("&");
		s = s[0].split("=")[1];
	}
	return s;
}

function Show(obj, bShow) {
	obj = (typeof(obj) == "string" ? S(obj) : obj);
	if (obj) obj.style.display= (bShow ? "" : "none");
}

//Event Mng Fun
function fAddEvent(oTarget, sType, fHandler, bRemove) {
	if (!oTarget)
		return;

	if (oTarget.addEventListener) {
		bRemove ? oTarget.removeEventListener(sType, fHandler, false) : oTarget.addEventListener(sType, fHandler, false);
	}
	else if (oTarget.attachEvent) {
		bRemove ? oTarget.detachEvent("on" + sType, fHandler) : oTarget.attachEvent("on" + sType, fHandler);
	}
	else {
		oTarget["on" +sType] = bRemove ? null : fHandler;
	}
}
function fPreventDefault(oEvent) {
	if (oEvent) {
		if (oEvent.preventDefault) {
			oEvent.preventDefault();
		}
		else {
			oEvent.returnValue = false;
		}
	}	
}

function fIsInObj( nObj, oObj ) {
	if ( !nObj || !oObj )
		return false;

	if ( typeof(oObj) == "string" ? nObj.id == oObj : nObj == oObj )
		return true;

	return fIsInObj( nObj.parentNode, oObj );
}
//str api
function Trim(sStr) {
	return sStr.replace(/(^\s*)|(\s*$)/ig,"");
}
function StrReplace(s, o, d, mode) {
	return s.replace(new RegExp( RegFilter(o), mode ), d);
}
function HighLight(filter, head, end) {
	return function(str) {
		return str.replace(new RegExp(["(", RegFilter(filter), ")"].join(""), "ig"), [head, "$1", end].join(""));
	};
}
//textarea api
function PutTextareaValue(o, val) {
	if (o.tagName != "TEXTAREA" && o.tagName != "textarea") return false;
	o.innerText != null ? o.innerText = val : o.value = val;
	return true;
}
function GetTextareaValue(o) {
	if (o.tagName != "TEXTAREA" && o.tagName != "textarea") return null;
	return o.value;
}

//======================================================================
function HtmlDecode(s) {
	return (s == null)?s:s.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,"\"");
}
function HtmlEncode(s) {
	return (s == null)?s:s.replace(/&/g,"&amp;").replace(/\"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
	//注释不以加在上一行，因为上面有正则，并且用了一个引号
}
//editor api
function TextToHtml(content) {
	//the attr of innerHTML in firefox is diff in ie
	var res = "<DIV>" + content.replace((content.indexOf("<BR>") >= 0)? /<BR>/ig: /\n/g, "</DIV><DIV>") + "</DIV>";
	res = res.replace(new RegExp("\x0D","g"), "");
	res = res.replace(new RegExp("\x20","g"), "&nbsp;");
	res = res.replace(new RegExp("(<DIV><\/DIV>)*$","g"), "");
	return res.replace(/<DIV><\/DIV>/g, "<DIV>&nbsp;</DIV>");
}
function HtmlToText(content) {
	//function for firefox
	//manal change div,p,br
	var res = content.replace(/<\/div>/ig, "\n");
	res = res.replace(/<\/p>/ig, "\n");
	return res.replace(/<br>/ig, "\n");
}




function request(tag,win)//本文件用的 取返回值
{	
	var t='&'+tag+"=";
	var	url=request_all("",win)//如?a=1&b=2
	if(url.substring(0,1)=="?")
	{
		url="&"+url.substring(1)
	}
	var n="";
	
	if(url.indexOf(t)>-1)
	{
		var arr=url.split(t);
		n=(arr[1].indexOf('&')>-1)?(arr[1].split('&')[0]):(arr[1]);
	}
	return (n.indexOf('#')>-1)?(n.split('#')[0]):(n)
}



function request_all(not_str,win)//取得所有传过来的参数，not_str表示不返回的字符
{	
	if(!win)win=window
	var url=win.document.location.href;
	var arr=url.split("?")
	var s="";
	for(var i=1;i<arr.length;i++)//因为可能 有多个问号
	{
		s+="?"+arr[i]
	}
	
	if(not_str)//要排除一些值
	{
		var arr_not=not_str.split(",");//如：,parent_fileName,parent_id
		for(var j=0;j<arr_not.length;j++)
		{
			var v=request(arr_not[j]);
			var not_str_sub=arr_not[j]+"="+v;//如：fileName=f000s
			s=s.replace("?"+not_str_sub,'');
			s=s.replace("&"+not_str_sub,'');//有可能是?exe=save或&exe=save
		}
		var s2=s;
	}
	else
	{
		var s2=s;
	}
	s2="?"+s2
	s2=s2.replace("?&","?");
	s2=s2.replace("??","?");
	if(s2.indexOf('#')>-1)s2=s2.split('#')[0];
	return s2
}
