﻿//---- Date: 2009-9-2----

function $$(id){
  if(typeof(id)=="string"){return document.getElementById(id);}
  else{return id;}
}

function checkcode(e,str){
  if(e.keyCode==13){str.click();}
}

var isFF = (document.all)?false:true;
var _xo = null,_xa = null,_returl = '';

function getOptionValue(e) {
	var ae = g(e),al = ae.length,i = 0;
	for(i=0; i<al; i++)
		if(_g_opt(ae[i])) return (ae[i].value);
	return (-999);
}

function getOptionText(e) {
	var ae = g(e),al = ae.length,i = 0;
	for(i=0; i<al; i++)
		if(_g_opt(ae[i])) return (ae[i].text);
	return ('');
}

function getOptionValueI(e) {
	return (parseInt(getOptionValue(e)));
}

function getOptionValueEx(e) {
	var ae = g(e),al = ae.length,i = 0,k = '';
	for(i=0; i<al; i++)
		if(_g_opt(ae[i])&&parseInt(ae[i].value)>0)
			k += ',' + ae[i].value.toString();
	return (k.substr(1));
}

function setOptionValue(e,k) {
	var ae = g(e),al = ae.length,i = 0;
	for (i=0; i<al; i++)
		if (ae[i].value==k&&!ae[i].disabled) {
			ae.options.selectedIndex = i;
			return true;
		}
}

function getRadioValue(e) {
	var ae = getels(e),al = ae.length,i = 0;
	for(i=0; i<al; i++)
		if(_g_chk(ae[i])) return (ae[i].value);
	return (-999);
}

function getRadioValueI(e) {
	return (parseInt(getRadioValue(e)));
}

function getCheckboxValue(e) {
	var ae = getels(e),al = ae.length,i = 0,k = [];
	for(i=0; i<al; i++)
		if(_g_chk(ae[i])) k.push(ae[i].value);
	return (k.join(','));
}

function getCheckboxValueEx(e) {
	var ae = getels(e),al = ae.length,i = 0,k = 0;
	for(i=0; i<al; i++)
		if(_g_chk(ae[i])) k += parseInt(ae[i].value);
	return (k);
}

function getElementsByName_iefix(tag, name) {
	var el = document.getElementsByTagName(tag);
	var ar = new Array(),il = el.length,att = '';
	for(var i=0,iarr=0; i<il; i++) {
		att = el[i].getAttribute('name');
		if(att==name) {
			ar[iarr] = el[i];
			iarr ++;
		}
	}
	return (ar);
}

function doselall(e,tp) {
	var ae = getels(e),al = ae.length,i = 0;
	for(i=0; i<al; i++)
		_chk_it(ae[i],((tp==1)?true:false));
}

function doSel(e,tp,opt,chkcount) {
	var ae = getels(e),al = ae.length,i = 0;
	var oa = g('selall'),clk = 0,sa = oa.checked;

	if(typeof(opt)!='undefined'){
		if(opt&1) clk = 1;
		if(opt&2) {
			if(typeof(chkcount)!='undefined'){
				sa = true;
				if(chkcount>al)
					chkcount = al;
				if(chkcount<al)
					al = chkcount;
			}
		}
	} else {
		opt = 0;
	}

	for(i=0; i<al; i++) {
		if(clk==1) ae[i].click();
		(tp==1)?_chk_it(ae[i],(sa?true:false)):_unchk_it(ae[i]);
	}

	if(!opt&2){
		oa.checked = (tp==1&&sa)?true:false;
		if(gx('invsel')){
			_xo.checked = (tp==1)?false:true;
		}
	}
}

function doSelTop(e,count){
	doSel(e,1,2,count);
}

function chkselstatus(e,mn) {
	var ae = getels(e),al = ae.length,i = 0,sln = 0,k = '';
	for(i=0;i<al;i++)
		if(!ae[i].disabled && ae[i].checked) sln++;

	if (sln==0) k = '未选中任何数据项，请重新选择';
	if (mn>0&&sln<mn) k = '至少需要选择 ' + mn + ' 项数据';

	if(k!='') alert(k);
	return ((k!='')?false:true);
}

function keyp(e) {
	e = _g_evt(e);
	var k = getkeycode(e);
	if(k==13) {
		if(window.event) {
			e.cancelBubble = true;
			e.returnValue = false;
		}
	}
	else {
		if((k<48||k>57)&&(k<96||k>105)&&k!=46&&k!=190&&k!=8&&k!=9) {
			cancelevt(e);
			return false;
		}
	}
	return true;
}

function setBKColor(o,c){
	if(gx(o)) _xo.style.backgroundColor = c;
}

function GoNext(e,o) {
	e = _g_evt(e);
	var k = getkeycode(e);
	if(k==13||k==32) {
		xfocus(o);
		cancelevt(e);
		return true;
	}
}

function getkeycode(e) {
	return (e.keyCode||e.which);
}

function pasteit(ob) {
	ob.focus();
	var k = ob.value;
	k = k + ',';
	if(k != ',') ob.value = k;

	var c = document.execCommand('Paste');
	return true;
}

function cancelmouse(e) {
	e = _g_evt(e);
	if(window.event)
		e.returnValue = false;
	else
		e.preventDefault();
}

function cancelevt(e) {
	if(window.event) {
		e.cancelBubble = false;
		e.returnValue = false;
	}
	else {
		e.stopPropagation();
		e.preventDefault();
	}
}

function cancel(e) {
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}

function addevent(o,et,fn) {
	if (o.addEventListener) {
		o.addEventListener(et, fn, false);
		return true;
	}
	else if (o.attachEvent) {
		var r = o.attachEvent('on' + et, fn);
		return r;
	}
	else
	return false;
}

function deal_empty(k) {
	return ((k!='')?k:'-');
}

function jumpto(o) {
	if(gx(o)) _xo.scrollIntoView(true);
}

function rsid(t) {
	var psid = g('postsid');
	if(psid) psid.src = 'getsid.asp?t=' + S(t) + '&rid=' + S(Math.random());
}

function getnum(k) {
	k = k.replace(/\D/g,'');
	return ((k=='')?0:parseInt(k));
}

function I(k) {
	return (parseInt(k));
}

function L(k) {
	return (S(k).length);
}

function S(k) {
	return (k.toString());
}

function trim(ss) {
	return (ss.replace(/(^\s*)|(\s*$)/g,''));
}

function len(k) {
	return (trim(k.toString()).length);
}

function StringByteLen(k) {
	var i = 0,n = 0,il = k.toString().length;
	for(i=0; i<il; i++) {
		c = k.charCodeAt(i);
		n += (c>122)?2:1;
	}
	return (n);
}

function strlength(str) {
	var k = str.length,n = k;
	for (var i=0;i<k;i++) 	{
		if(str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++;
	}
	return (n);
}

function fmtwithchar(src,datalen,c) {
	var dst = '',alen = 0,i = 0,k = 0;

	alen = strlength(src);
	if(alen>=datalen) return (src);

	k = datalen - alen;
	for(i=0; i<k; i++) dst += c;

	return (src + dst);
}

function removelink(k) {
	return (k.replace(/(\<(.*\b).*>)(.*)(<\/\2>)/ig, '$3'));
}

function round(k,d) {
	var z = k.toString(),p = z.indexOf('.');
	return (z.substr(0,p) + '.' + z.substr(p+1,d));
}

function chg_wrap(frmid,objid,ws) {
	document.forms[frmid].elements[objid].wrap = (ws==true)?'soft':'off';
}

function ref_data() {
	var icw = window.opener.closed;

	try {
		if(!icw)
			window.opener.location.reload(1);
		self.close();
	}
	catch(e) {
		self.close();
	}
}

function hideme(o) {
	o.style.visibility = (o.style.visibility=='hidden')?'visible':'hidden';
}

function showme(o) {
	o.style.visibility = 'visible';
}

function toggledisp(o) {
	var obj = g(o).style;
	if(obj) obj.display = (obj.display=='none')?'':'none';
	return (obj.display);
}

function toggledispX(o) {
	var obj = g(o);
	obj.className = (obj.className=='hide')?'show':'hide';
	return (obj.className);
}

function dispme(o) {
	setdisp(o,'');
}

function nodispme(o) {
	setdisp(o,'none');
}

function setdisp(o,k) {
	if(gx(o)) _xo.style.display = k;
}

function getcls(o,c) {
	if(gx(o)) return (_xo.className);
}

function setcls(o,c) {
	if(gx(o)) _xo.className = c;
}

function setclsX(o,c) {
	o.className = c;
}

function _g_evt(e) {
	return (e||window.event);
}

function _g_opt(o) {
	return (o.selected&&!o.disabled);
}

function _g_chk(o) {
	return (o.checked&&!o.disabled);
}

function _chk_it(o,k) {
	if(o) o.checked = k;
}

function _unchk_it(o) {
	if(o) o.checked = !o.checked;
}

function g(o) {
	return (document.getElementById(o));
}

function gx(o) {
	_xo = document.getElementById(o);
	return (_xo?true:false);
}

function getels(o) {
	return (document.getElementsByName(o));
}

function createEl(o) {
	return (document.createElement(o));
}

function createElX(o,k,eOpt) {
	var el = createEl(k);
	if(arguments.length==3)
		setattrEl(el,eOpt);
	o.appendChild(el);
}

function gethtm(o) {
	return (g(o).innerHTML);
}

function sethtm(o,k) {
	g(o).innerHTML = k;
}

function initattrX(o) {
	_xa = g(o);
}

function getattrA(a) {
	return (_xa.getAttribute(a));
}

function setattrA(a,k) {
	_xa.setAttribute(a,k);
}

function getattr(o,a) {
	return (g(o).getAttribute(a));
}

function getattrS(o,a) {
	return (getattr(o,a).toString());
}

function getattrX(o,a) {
	return (o.getAttribute(a));
}

function getattrXS(o,a) {
	return (getattrX(o,a).toString());
}

function setattr(o,a,k) {
	g(o).setAttribute(a,k);
}

function setattrX(o,a,k) {
	o.setAttribute(a,k);
}

function setattrEl(el,argsObj) {
	var arg = null;
	for (arg in argsObj) {
		setattrX(el,arg,argsObj[arg]);
	}
}

function resetattrEl(el,argsObj) {
	var arg = null;
	for (arg in argsObj)
		if(arg!='id') setattrX(el,arg,argsObj[arg]);
}

function getvalue(o) {
	return (g(o).value);
}

function getvalueS(o) {
	return (g(o).value.toString());
}

function getvalueI(o) {
	return (getnum(g(o).value));
}

function getvalueX(o) {
	return (o.value);
}

function setvalue(o,k) {
	g(o).value = k;
}

function setvalueX(o,k) {
	g(o).value += k;
}

function valueis(k,d) {
	return ((k==d)?true:false);
}

function valueisex(k,d) {
	return ((k===d)?true:false);
}

function objvalueis(k,d) {
	return ((getvalue(k)==d)?true:false);
}

function lock(o) {
	if(gx(o)) _xo.disabled = true;
}

function unlock(o) {
	if(gx(o)) _xo.disabled = false;
}

function lockex() {
	_lockit(arguments,true,1);
}

function unlockex() {
	_lockit(arguments,false,1);
}

function lockex2() {
	_lockit(arguments,true,2);
}

function unlockex2() {
	_lockit(arguments,false,2);
}

function lockex3() {
	_lockit(arguments,true,3);
}

function unlockex3() {
	_lockit(arguments,false,3);
}

function _lockit(argv,k,ord) {
	var i = 0,j = argv.length,ff = '';
	if(ord==3) j++;
	for (i=1; i<j; i++) {
		ff = ((ord==1)?(argv[i] + argv[0]):((ord==2)?(argv[0] + argv[i]):argv[i-1]));
		if(gx(ff)) _xo.disabled = k;
	}
}

function xfocus(o) {
	if(gx(o)) _xo.focus();
}

function xselect(o) {
	if(gx(o)) _xo.selected = true;
}

function xcheck(o) {
	if(gx(o)) _xo.checked = true;
}

function xuncheck(o) {
	if(gx(o)) _xo.checked = false;
}

function xcheckex(e,p,t) {
	var ae = getels(e),al = ae.length,i = 0,k = 0;
	for(i=0; i<al; i++) {
		k = parseInt(ae[i].value);
		if((t==1&&k&p)||(t==2&&k==p)) xcheck('c' + e + '_' + k);
	}
}

function getchar(n) {
	return (String.fromCharCode(n));
}

function timeout(o,k) {
	return (window.setTimeout(o,k,'javascript'));
}

function goback() {
	if(arguments.length>0)
		window.close();
	else
		this.location.href = _returl;
}

function gourl(s) {
	if(this.location)
		this.location.href = s;
	else
		window.location.href = s;
}

function rp() {
	this.location.reload(1);
}

function cds(n) {
	return (n<10)? '0'+n.toString() : n.toString();
}

function getCurDay() {
	var d = new Date();
	return (d.getFullYear().toString() + cds(d.getMonth()+1) + cds(d.getDate()));
}

function wo(k) {
	window.open(k);
}

function wopd(pid) {
	if(parseInt(pid)<1) return;
	window.open('prod.asp?productid=' + pid.toString());
}

function round(num,dig) {
	return (Math.round(num*Math.pow(10,dig))/Math.pow(10,dig));
}

function ec(s) {
	return (encodeURIComponent(s));
}

function doSetRowColor(row){
	oID = 'tr_' + row.toString();

	var cks = getattr(oID,'chkstatus');

	if(cks=='0')
		setBKColor(oID,__cCRowBgC);
	else
		setBKColor(oID,getattr(oID,'bkc'));

	cks = (cks=='0')?'1':'0';
	setattr(oID,'chkstatus',cks);
}

function chnum(num){
	if(!/^\d*(\.\d*)?$/.test(num)){alert("请不要输入非法字符!"); return;}

	var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
	var BB = new Array("","拾","佰","仟","萬","億","点","");

	var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";

	for(var i=a[0].length-1; i>=0; i--) {
		switch(k) {
			case 0 : re = BB[7] + re; break;
			case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0]))
				re = BB[4] + re; break;
			case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
		}
		if(k%4 == 2 && a[0].charAt(i+2) != 0 && a[0].charAt(i+1) == 0) re = AA[0] + re;
		if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
	}

	if(a.length>1) //加上小数部分(如果有小数部分)
	{
		re += BB[6];
		for(var i=0; i<a[1].length; i++) re += AA[a[1].charAt(i)];
	}
	sethtm('sp_orderchince',re);
}

function DateFormat(fmtCode, date) {
    var result, d, arr_d;

    var patrn_now_1 = /^y{4}-M{2}-d{2}\sh{2}:m{2}:s{2}$/;
    var patrn_now_11 = /^y{4}-M{1,2}-d{1,2}\sh{1,2}:m{1,2}:s{1,2}$/;

    var patrn_now_2 = /^y{4}\/M{2}\/d{2}\sh{2}:m{2}:s{2}$/;
    var patrn_now_22 = /^y{4}\/M{1,2}\/d{1,2}\sh{1,2}:m{1,2}:s{1,2}$/;

    var patrn_now_3 = /^y{4}M{2}d{2}\sh{2}时m{2}s{2}$/;
    var patrn_now_33 = /^y{4}M{1,2}d{1,2}\sh{1,2}时m{1,2}s{1,2}$/;

    var patrn_date_1 = /^y{4}-M{2}-d{2}$/;
    var patrn_date_11 = /^y{4}-M{1,2}-d{1,2}$/;

    var patrn_date_2 = /^y{4}\/M{2}\/d{2}$/;
    var patrn_date_22 = /^y{4}\/M{1,2}\/d{1,2}$/;

    var patrn_date_3 = /^y{4}M{2}d{2}$/;
    var patrn_date_33 = /^y{4}M{1,2}d{1,2}$/;

    var patrn_time_1 = /^h{2}:m{2}:s{2}$/;
    var patrn_time_11 = /^h{1,2}:m{1,2}:s{1,2}$/;
    var patrn_time_2 = /^h{2}时m{2}s{2}$/;
    var patrn_time_22 = /^h{1,2}时m{1,2}s{1,2}$/;

    if (!fmtCode) { fmtCode = "yyyy-MM-dd hh:mm:ss" }
    if (date) {
        d = new Date(date);
        if (isNaN(d)) {
            alert("时欠");
            return "";
        }
    }
    else { d = new Date() }

    if (patrn_now_1.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.yyyy + "-" + arr_d.MM + "-" + arr_d.dd + " " + arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_now_11.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "-" + arr_d.MM + "-" + arr_d.dd + " " + arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_now_2.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.yyyy + "/" + arr_d.MM + "/" + arr_d.dd + " " + arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_now_22.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "/" + arr_d.MM + "/" + arr_d.dd + " " + arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_now_3.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.yyyy + "" + arr_d.MM + "" + arr_d.dd + "" + " " + arr_d.hh + "时" + arr_d.mm + "" + arr_d.ss + "";
    }
    else if (patrn_now_33.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "" + arr_d.MM + "" + arr_d.dd + "" + " " + arr_d.hh + "时" + arr_d.mm + "" + arr_d.ss + "";
    }
    else if (patrn_date_1.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.yyyy + "-" + arr_d.MM + "-" + arr_d.dd;
    }
    else if (patrn_date_11.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "-" + arr_d.MM + "-" + arr_d.dd;
    }
    else if (patrn_date_2.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.yyyy + "/" + arr_d.MM + "/" + arr_d.dd;
    }
    else if (patrn_date_22.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "/" + arr_d.MM + "/" + arr_d.dd;
    }
    else if (patrn_date_3.test(fmtCode)) {
        arr_d = splitDate(d,true);
        result = arr_d.yyyy + "" + arr_d.MM + "" + arr_d.dd + "";
    }
    else if (patrn_date_33.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.yyyy + "" + arr_d.MM + "" + arr_d.dd + "";
    }
    else if (patrn_time_1.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_time_11.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.hh + ":" + arr_d.mm + ":" + arr_d.ss;
    }
    else if (patrn_time_2.test(fmtCode)) {
        arr_d = splitDate(d, true);
        result = arr_d.hh + "时" + arr_d.mm + "" + arr_d.ss + "";
    }
    else if (patrn_time_22.test(fmtCode)) {
        arr_d = splitDate(d);
        result = arr_d.hh + "时" + arr_d.mm + "" + arr_d.ss + "";
    }
    else {
        result = "";
    }
    return result;
}

function splitDate(d, isZero) {
	var yyyy, MM, dd, hh, mm, ss;
	if (isZero) {
		yyyy = d.getFullYear();
		MM = (d.getMonth() + 1) < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
		dd = d.getDate() < 10 ? "0" + d.getDate() : d.getDate();
		hh = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
		mm = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
		ss = d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds();
	}
	else {
		yyyy = d.getFullYear();
		MM = d.getMonth() + 1;
		dd = d.getDate();
		hh = d.getHours();
		mm = d.getMinutes();
		ss = d.getSeconds();
	}
	return {"yyyy":yyyy, "MM":MM, "dd":dd, "hh":hh, "mm":mm, "ss":ss};
}

function GetCookieVal(offset){
  var endstr=document.cookie.indexOf(";",offset);
  if(endstr==-1) {endstr=document.cookie.length;}
  return unescape(document.cookie.substring(offset,endstr));
}

function SetCookie(name,value){
	var expdate=new Date();
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc>2) ? argv[2] : null;
	var path=(argc>3) ? argv[3] : null;
	var domain=(argc>4) ? argv[4] : null;
	var secure=(argc>5) ? argv[5] : false;
	if(expires!=null) {expdate.setTime(expdate.getTime()+(expires*1000));}
	document.cookie=name+"="+escape(value)+((expires==null) ? "" : ("; expires="+expdate.toGMTString()))
	+((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))
	+((secure==true) ? "; secure" : "");
}

function GetCookie(name){
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while(i<clen){
	var j=i+alen;
	if(document.cookie.substring(i,j)==arg) {return GetCookieVal(j);}
	i=document.cookie.indexOf(" ",i)+1;
	if(i==0) break;
	}
	return null;
}

function Deletecookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function fOver(obj){
	obj.className = "on";
}
function fOut(obj){
	obj.className = "";
}

// standart string replace functionality
function str_replace(str, needle, replacement) {
	var temp = str.split(needle);
	return temp.join(replacement);
}

function getElementPos(elementId){
	var ua = navigator.userAgent.toLowerCase();
	var isOpera = (ua.indexOf('opera') != -1);
	var isIE = (ua.indexOf('msie') != -1 && !isOpera);
	if(typeof elementId=='string') {
		var el = document.getElementById(elementId);
	} else {
		var el = elementId;	
	}
	var parent = null;
	var pos = [];
	var box;

	if(el.parentNode === null || el.style.display == 'none'){
		return false;
	}

	if(el.getBoundingClientRect){
		box = el.getBoundingClientRect();
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		return {x:box.left + scrollLeft, y:box.top + scrollTop};
	}else if(document.getBoxObjectFor){
		box = document.getBoxObjectFor(el);
		var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
		var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
		pos = [box.x - borderLeft, box.y - borderTop];
	} else{
		pos = [el.offsetLeft, el.offsetTop];
		parent = el.offsetParent;
		if (parent != el){
			while (parent) {
				pos[0] += parent.offsetLeft;
				pos[1] += parent.offsetTop;
				parent = parent.offsetParent;
			}
		}
		if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )){
			pos[0] -= document.body.offsetLeft;
			pos[1] -= document.body.offsetTop;
		}
	}
	if (el.parentNode){
		parent = el.parentNode;
	}else{
		parent = null;
	}

	while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML'){
		pos[0] -= parent.scrollLeft;
		pos[1] -= parent.scrollTop;
		if (parent.parentNode) {
			parent = parent.parentNode;
		}else{
			parent = null;
		}
	}
	return {x:pos[0], y:pos[1]};
}

function stripSpecial(s){
	s = s.replace('^','!?');
	s = s.replace('#','!?');
	return s;
}

function CreatXml(){
  var str;
  if(window.XMLHttpRequest){
    str=new XMLHttpRequest();
    if(str.overrideMimeType){str.overrideMimeType('text/xml');}
  }
  else if(window.ActiveXObject){
    str=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return str;
}

function PostXml(str,url,pe){
	var xmlhttp=CreatXml();
	url = url+(url.indexOf("?")!=-1 ? "&" : "?")+"rtime="+Math.random(); //new Date().getTime();
	xmlhttp.open("Post",url,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			
			xr=unescape(xmlhttp.responseText);
			pe.disabled=false;
			if(xr.indexOf('登录成功') != -1){
				window.location.reload();
				return false;
			}
			alert(xr);
			if(xr.indexOf('删除成功')!=-1){
				window.location.reload();
			}else if(xr.indexOf('注册成功')!=-1){
				window.location='./';
			}else if(xr.indexOf('成功')!=-1){
				if(window!=top){
					try{parent.TB_remove();}
					catch(e){}
				}else{
					window.location = 'index.aspx';
					//alert(xr);
					}
			}else if(xr.indexOf('验证码')!=-1){
				reloadnumcode();
			}else if(xr.indexOf('密码错误')!=-1){
				//loginerror+=1;
				//if(loginerror>2){$$("ncli").style.display='';}
			}
		}
		if(xmlhttp.readyState==3){}
	}
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
function reloadnumcode(){
  var a=document.getElementById("nc");
  a.src+="1";
}
function checkLogin(tf,url,pe){
	if(tf.UserName.value==""){
		alert("用户名不能为空.");
		xfocus('se_o_username');
		return false;
	}else if(tf.UserPass.value==""){
		alert("密码不能为空.");
		xfocus('se_o_userpass');
		return false;
	}else if(tf.txtCheckCode.value==""){
		alert("验证码不能为空.");
		tf.txtCheckCode.focus();
		xfocus('se_o_numcode');
		return false;
	}else{
		pe.disabled=true;
		var str="ac=login";	
		str+="&UserName="+escape(tf.UserName.value);
		str+="&UserPass="+escape(tf.UserPass.value);
		str+="&txtCheckCode="+tf.txtCheckCode.value;
		PostXml(str,url,pe)
	}
}

function setHomePageInFF(url, obj) {
    if (window.ActiveXObject) {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(url);
    } else if (window.XMLHttpRequest) {
        alert("暂时不支持firefox!");
        return false;
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    }
}

function addFavor(title, url) {
    if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
        window.sidebar.addPanel(title, url, "");
    } else {
        window.external.addFavorite(url, title);
    }
}
