window.onerror = function(msg, url, line)
{
 	return true;
};

//navigate
var gsAgent = navigator.userAgent;
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 == "Netscape");
if (gIsIE) {
	var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
	reIE.test(navigator.userAgent);
	var gIEVer = parseFloat(RegExp["$1"]);
}

function GetDomain() {
	 if(document.cookie.indexOf("foxmail.com") > -1) return "foxmail.com";
	 return "qq.com";
}
  
 
//global msg
var msgNoSubject = "";
var msgSend = "";
var msgSave = "";
var msgSaveOk = "";
var msgAutoSave = "";
var msgAutoSaveOk = "";
var msgSendErrorSaveOK  = "";
var msgSaveErr = "";
var msgNoSender = "";
var msgNoCard = "";
var msgAddrSearchErr = "";
var msgMailSearchErr = "";
var msgSettingOk = "";
var msgWarnningType = "";
var msgLinkErr = "";
var msgRejectAlert = "";
var msgSpamAlert = "";
var msgCheatAlert = "";
var msgSendTimeErr = "";
var msgCreateTimeErr = "";
var msgRemindTimeErr = "";
var msgModifySendTimeMsg = "";
var msgSendMailNoMove = "";
var msgMoveMailSameFldErr = "";


//根据用户输入的邮箱地址
//自动找到对应的POP服务器；
var popsvrlist = [ 
"pop.cclinux.com"
];

//global base function
var gd = document;
function Gel(id, ob) {
	return (ob ? ob : gd).getElementById(id);
}
function GelTags(tag, ob) {
	return (ob ? ob : gd).getElementsByTagName(tag);
}
function S(i, win) {
	return (win?win:window).document.getElementById(i);
}
function SO(i, o) {
	return Gel(i, o);
}
function SN(i, win) {
	return (win?win:window).document.getElementsByName(i);
}
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?frame.contentWindow:(win?win:window).frames[sID];
}
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;
}
 
 
//js cookie operation global function
function SetCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	if (sName == null && sValue == null) return false;
	var sCookie = sName + "=" + encodeURIComponent(sValue);
	if (oExpires) 	sCookie += "; expires=" + oExpires.toGMTString();
	if (sPath) sCookie += "; path=" + sPath;
	if (sDomain) 	sCookie += "; domain=" + sDomain;
	if (bSecure) sCookie += "; secure";
	gd.cookie = sCookie;
	return true;
}
function GetCookie(sName) {
	var oRE = new RegExp("(?:; )?" + sName + "=([^;]*);?");
	return oRE.test(gd.cookie) ? decodeURIComponent(RegExp["$1"]) : null;
}
function DeleteCookie(sName, sPath, sDomain) {
	SetCookie(sName, "", new Date(0), sPath, sDomain);
}
function GetCookieFlags(_name) {
   var a=GetCookie(_name);
   if(null==a)a="";
   for(var i=a.length;i<6;i++) a+='0';
   return a.split("");
}
function SetCookieFlag(_name,i,flag,_cookie) {
	 if(null==_cookie) _cookie=GetCookieFlags(_name);
	 _cookie[i]=flag;
	 var expdate = new Date();
	 expdate.setTime(expdate.getTime() + ( 30 * 24 * 3600 * 1000 ));
	 SetCookie(_name, _cookie.join(""), expdate, '/', GetDomain());
	 return _cookie;
}
//Event Mng Fun
function fAddEvent(oTarget, sType, fHandler, bRemove) {
	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 fRemoveEvent(oTarget, sType, fHandler) {
	if (oTarget.removeEventListener) {
		oTarget.removeEventListener(sType, fHandler, false);
	} 
	else if (oTarget.detachEvent) {
		oTarget.detachEvent("on" + sType, fHandler);
	}
	else {
		oTarget["on" + sEventType] = null;
	}
}
function fPreventDefault(oEvent)
{
	if (oEvent.preventDefault)
	{
		oEvent.preventDefault();
	}
	else
	{
		oEvent.returnValue = false;
	}
}
function fLoadJsFile(file, checked, doc) {
	doc = doc ? doc : document;
	if (checked) {
		var s = GelTags("script", doc);
		for (var i = s.length - 1; i >= 0; i--) {
			if (s[i].src.indexOf(file) != -1) return;
		}
	}
	var o = doc.createElement("script");
	o.language = "javascript";
	o.src = file;
	var h = GelTags("head", doc)[0];
	if (h) h.appendChild(o);
}
function fLoadCssFile(file, checked, doc) {
	doc = doc ? doc : document;
	if (checked) {
		var s = GelTags("link", doc);
		for (var i = s.length - 1; i >= 0; i--) {
			if (s[i].href.indexOf(file) != -1) return;
		}
	}
	var o = doc.createElement("link");
	o.type = "text/css";
	o.rel = "stylesheet";
	o.href = file;
	var h = GelTags("head", doc)[0];
	if (h) h.appendChild(o);
}
function fReplaceCssFile(pattern, file, doc)
{
	if (!pattern) return;
	doc = doc ? doc : document;

	var s = GelTags("link", doc);
	for (var i = s.length - 1; i >= 0; i--)
	{
		if (s[i].href.indexOf(pattern) != -1)
		{
			s[i].parentNode.removeChild(s[i]);
		}
	}

	if (file) fLoadCssFile(file, false, doc);
}
function fIsInObj(nObj, oObj) {
	if (typeof(oObj) == "string" ? nObj.id == oObj : nObj == oObj) return true;
	var p = nObj.parentNode;
	if(p) return fIsInObj(p, oObj);
	return false;
}
//object rewrite --> for ie active problom
function fParamsInTag(o) {
	var c = "";
	var p = GelTags("PARAM", o);
	for (var i = p.length - 1; i >= 0; i--) {
		c += p[i].outerHTML;
	}
	return c;
}
function fTagRewrite(tag, doc) {
	var o = GelTags(tag, doc);
	for (var i = o.length - 1; i >= 0; i--) {
		o[i].outerHTML = o[i].outerHTML.split(">")[0] + ">" + fParamsInTag(o[i]) /*+ o[i].innerHTML*/ + "</" + o[i].tagName + ">";
	}
}
function fObjectActive(doc) {
	if (gIsIE) {
		fTagRewrite("embed", doc);
		fTagRewrite("object", doc);
	}
}
//quick replace
function StrReplace(s, o, d) {
	return s.replace(new RegExp(o), d);
}
//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;
}
//other api
function ScrollIntoMidView(obj, container, bforce, win) {
	if (!container) container = (win ? win : window).document.body;
	var ot = 0;
	for (var o = obj; o && o != container;o = o.offsetParent) ot += o.offsetTop;
	var h = ot - container.scrollTop;
	if (bforce || h < 0 || h + obj.offsetHeight  > container.clientHeight) {
		container.scrollTop = ot - (container.clientHeight - obj.offsetHeight) / 2
	}
}
//
if(!Function.prototype.apply) {
	Function.prototype.apply = function (obj, argu) {
		if (obj) obj._caller = this;
		var argus = new Array();
		for (var i=0;i<argu.length;i++) {
			argus[i] = "argu[" + i + "]";
		}
		var r;
		eval("r = " + (obj ? ("obj._caller(" + argus.join(",") + ");") : ("this(" + argus.join(",") + ");"))); 
		return r;
	};
}
if(!Array.prototype.push) {
	Array.prototype.push=function() {
		for(var i=0;i<arguments.length;i++) {
			this[this.length]=arguments[i];
		}
	}
}  
 
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 SelectAll(flag) {
	var mail_list_table = S('list');
	var mail_list_checkbox = GelTags("input", mail_list_table);
	for(var i = mail_list_checkbox.length - 1;i >= 0; i--) {
		mail_list_checkbox[i].checked = flag;
	}
} 

function Trim(sStr)
{
	return sStr.replace(/(^\s+)|(\s+$)/ig,"");
} 
 
function ParseStr(val, len) {
	var str = val.toString();
	for (var i = str.length; i < len; i++) {
		str = "0" + str;
	} 
	return str;
}
 
function PGV() {}
function InitAutoComplete(iptName) {  
	var inputNames = [iptName,"cc", "bcc"];
	var defaltTxt = ["", "", ""];
	var defaultCss = ["", "", ""];
	var clickObjNames = ["to_btn", "cc_btn", "bcc_btn"];
	var rightWidth = [null, null, null];
	var targetObj = [null, null, null];
	for(var i=0,len=inputNames.length;i<len;i++) { 
		var input = S(inputNames[i]);
		
		if (input) (new CCRelease.AutoCompleteAllAddr()).Init(input, AutoCompleteFrm, S("AutoCompleteFrmId"), true, defaltTxt[i], defaultCss[i], S(clickObjNames[i]), rightWidth[i], targetObj[i]);
	}
} 
