/**
 * @Project: vqq
 * @File: util.js
 * @Author: Lincoln
 * @Date: 2009-2-23
 * @Email: liangqikang@gmail.com
 * @Description: A js file
 * 
 * 全局公共函数
 */


if (!("console" in window) || !("firebug" in console))
{	
	var names, i;
    names = ["log", "debug", "info", "warn", "error", 
    "assert","assertEquals","assertNotEquals","assertGreater","assertNotGreater","assertLess",
    "assertNotLess","assertContains","assertNotContains","assertTrue","assertFalse",
    "assertNull","assertNotNull","assertUndefined","assertNotUndefined","assertInstanceOf",
    "assertNotInstanceOf","assertTypeOf","assertNotTypeOf",
     "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for ( i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

var g_referrer, host, pathName, projectName, g_basePath, basePath, url, g_url, g_init_year;
	g_referrer = document.referrer;
	host = window.location.protocol + "//" + window.location.host;
	pathName = window.location.pathname;
	projectName = pathName.split("/")[1];
	basePath = host + "/";
	if(host.indexOf("qianquan.com") < 0 && host.indexOf("118.144.88") < 0 && projectName.indexOf(".") < 0){
		basePath += projectName + "/";
	}
	g_basePath = basePath;
	url = window.location.href;
	g_url = url;
	g_init_year = 0;
 window.console.log("basePath-->" + basePath);

function get_parameter_from_url(name) {
	var value, queryStr, ps, i , re, n, v;
	value = null;
	if (url.indexOf('?') > 0) {
		queryStr = window.location.search;
		queryStr = queryStr.substring(1);
		// console.log("queryStr: " + queryStr);
		ps = queryStr.split('&');
		for ( i = 0; i < ps.length; ++i) {
			re = /(.*)=(.*)/;
			// console.log("re: " + re);
			if (re.test(ps[i])) {
				n = RegExp.$1;
				v = RegExp.$2;
				// console.log("n: " + n);
				if (n.trim() == name) {
					value = v;
					if (isNaN(value)) {
						value = decodeURIComponent(value);
					}
				}
				// console.log("v1: " + v);
				// console.log("value: " + value);
			}
		}
	}
	return (value);
}

function get_hash_from_url() {
	return window.location.hash;
}

function get_hash_value() {
	var h = window.location.hash;
	return h.substring(1);
}

String.prototype.appendParam = function(paramName, val) {
	var newStr = this;
	if (this.indexOf(paramName) < 0) {
		// add
		if (this.indexOf("?") >= 0) {
			newStr = this + "&" + paramName + "=" + val;
		} else {
			newStr = this + "?" + paramName + "=" + val;
		}
	} else {
		// replace
		var regx = new RegExp(paramName + "=" + "-*[\\w|\\d]*(&|$)");
		// console.log("regx===>%o", regx);
		// console.log("search===>"+orgURL.search(regx));
		newStr = this.replace(regx, paramName + "=" + val + "$1");
	}
	return newStr;
}

/*
 * //test: var url = "http://test?abc=123&edf=3r5"; console.log("after
 * replace===>" + appendURL(url, "abc", "rr"));
 */

function clone(source) {
	if (typeof (source) != "object") {
		return source;
	}
	var p, ret = new Object();
	for ( p in source) {
		ret[p] = clone(source[p]);
	}
	return ret;
}

function get_value_from_style(str) {
	if (!isNaN(str))
		return str;
	var value = 0, i = str.indexOf("px");
	if (i > 0) {
		value = str.substring(0, i);
	}
	return parseFloat(value);
}

function VqqTime() {
	this.year = 0;
	this.month = 0;
	this.day = 0;
	this.hour = 0;
	this.minute = 0;
	this.second = 0;
	this.week = 0;
}

function convert_vqq_time_to_second(vqqTime) {
	var second = vqqTime.year * vqq_const.QQ_YEAR_INTERVAL
			+ (vqqTime.month - 1) * vqq_const.QQ_MON_INTERVAL
			+ (vqqTime.day - 1) * vqq_const.QQ_DAY_INTERVAL
			+ (vqqTime.hour + vqq_const.QQ_WEEKEND_END)
			* vqq_const.QQ_HOUR_INTERVAL
			// 因为虚拟时间是从1：00算起，ConverSecondToVqqTime 里面减了1个小时，这里补加1个小时
			+ vqqTime.minute * vqq_const.QQ_MINUTE_INTERVAL + vqqTime.second
			* vqq_const.QQ_SECOND_INTERVAL
			+ vqq_const.QQ_INIT_TIME;
	return second;
}

function convert_second_to_vqq_time(s) {
	var vt, timeInterval, year, month, day, hour, minute, second, week; 
	vt = new VqqTime();
	timeInterval = s;

	timeInterval -= (vqq_const.QQ_HOUR_INTERVAL * vqq_const.QQ_WEEKEND_END + vqq_const.QQ_INIT_TIME);// 因为虚拟时间是从1：00算起，为方便起见，减1个小时
	year = Math.floor(timeInterval / vqq_const.QQ_YEAR_INTERVAL);
	month = Math.floor(timeInterval % vqq_const.QQ_YEAR_INTERVAL
			/ vqq_const.QQ_MON_INTERVAL) + 1;
	day = Math.floor(timeInterval % vqq_const.QQ_YEAR_INTERVAL
			% vqq_const.QQ_MON_INTERVAL / vqq_const.QQ_DAY_INTERVAL) + 1;
	hour = Math.floor(timeInterval % vqq_const.QQ_YEAR_INTERVAL
			% vqq_const.QQ_MON_INTERVAL % vqq_const.QQ_DAY_INTERVAL
			/ vqq_const.QQ_HOUR_INTERVAL);
	minute = Math.floor(timeInterval % vqq_const.QQ_YEAR_INTERVAL
			% vqq_const.QQ_MON_INTERVAL % vqq_const.QQ_DAY_INTERVAL
			% vqq_const.QQ_HOUR_INTERVAL / vqq_const.QQ_MINUTE_INTERVAL);
	second = Math.floor(timeInterval % vqq_const.QQ_YEAR_INTERVAL
			% vqq_const.QQ_MON_INTERVAL % vqq_const.QQ_DAY_INTERVAL
			% vqq_const.QQ_HOUR_INTERVAL % vqq_const.QQ_MINUTE_INTERVAL
			/ vqq_const.QQ_SECOND_INTERVAL);
	week = Math.floor(timeInterval % vqq_const.QQ_WEEK_INTERVAL
			/ vqq_const.QQ_DAY_INTERVAL);
	vt.year = year;
	vt.month = month;
	vt.week = week;
	vt.day = day;
	vt.hour = hour;
	vt.minute = minute;
	vt.second = second;
	return vt;
}

function convert_second_to_time(s) {
	var str = "", vt = convert_second_to_vqq_time(s);
	if (vt) {
		str = perfix_to_num('0', 2, vt.hour) + ":"
				+ perfix_to_num('0', 2, vt.minute) + ":"
				+ perfix_to_num('0', 2, vt.second);
	}
	return str;
}

function convert_second_to_hm(s) {
	var str = "", vt = convert_second_to_vqq_time(s);
	if (vt) {
		str = perfix_to_num('0', 2, vt.hour) + ":"
				+ perfix_to_num('0', 2, vt.minute);
	}
	return str;
}

function convert_second_to_vqq_days(s) {
	var str = s / (vqq_const.QQ_DAY_INTERVAL);
	return Math.ceil(str);
}

function convert_second_to_vqq_date(s, connector) {
	if (!s)
		return "";
	var vt, str = "", symbol = "-";
	if (connector) {
		symbol = connector;
	}
	vt = convert_second_to_vqq_time(s);
	if (vt) {
		str = perfix_to_num('0', 3, g_init_year + vt.year) + symbol
				+ perfix_to_num('0', 2, vt.month) + symbol
				+ perfix_to_num('0', 2, vt.day);
	}
	return str;
}

function convert_second_to_vqq_datetime(s) {
	var str = "", vt = convert_second_to_vqq_time(s);
	if (vt) {
		str = "QQ" + perfix_to_num('0', 3, g_init_year + vt.year) + "-"
				+ perfix_to_num('0', 2, vt.month) + "-"
				+ perfix_to_num('0', 2, vt.day) + " "
				+ perfix_to_num('0', 2, vt.hour) + ":"
				+ perfix_to_num('0', 2, vt.minute) + ":"
				+ perfix_to_num('0', 2, vt.second);
	}
	return str;
}

function convert_second_to_vqq_literal_date(s) {
	var str = "", vt = convert_second_to_vqq_time(s);
	if (vt) {
		str = "QQ" + perfix_to_num('0', 3, g_init_year + vt.year) + "年" + vt.month + "月" + vt.day
				+ "日";
	}
	return str;
}

function convert_second_to_normal_date(s) {
	var d, date, dstr;
	d = new Date();
	d.setTime(s * 1000);
	// console.log("date str1===>" + d.getHours());
	date = d.getDate();
	if (d.getHours() != 0) {
		date = d.getDate() + 1;
	}
	dstr = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + date;
	return dstr;
}

function convert_second_to_normal_datetime(s) {
	var d, date, dstr;
	d = new Date();
	d.setTime(s * 1000);
	// console.log("date str1===>" + d.getHours());
	date = d.getDate();
	dstr = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + date + " "
			+ perfix_to_num('0', 2, d.getHours()) + ":"
			+ perfix_to_num('0', 2, d.getMinutes());
	return dstr;
}

function convert_second_to_literal_date(s) {
	var d, date, dstr, now;
	d = new Date();
	d.setTime(s * 1000);
	// console.log("date str1===>" + d.getHours());
	date = d.getDate();
	if (d.getHours() != 0) {
		date = d.getDate() + 1;
	}
	now = new Date();
	// console.log("d.getDate--->" + d.getDate());
	// console.log("now.getDate--->" + now.getDate());
	if (d.getMonth() == now.getMonth() && d.getDate() == now.getDate()) {
		dstr = perfix_to_num('0', 2, d.getHours()) + ":"
				+ perfix_to_num('0', 2, d.getMinutes());
	} else if (d.getMonth() == now.getMonth()
			&& (d.getDate() + 1) == now.getDate()) {
		dstr = "昨天" + perfix_to_num('0', 2, d.getHours()) + ":"
				+ perfix_to_num('0', 2, d.getMinutes());
	} else if (d.getMonth() == now.getMonth()
			&& (d.getDate() + 2) == now.getDate()) {
		dstr = "前天" + perfix_to_num('0', 2, d.getHours()) + ":"
				+ perfix_to_num('0', 2, d.getMinutes());
	} else {
		dstr = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + date;
	}
	return dstr;
}

function convert_second_to_normal_date(s) {
	var d, date, dstr;
	d = new Date();
	d.setTime(s * 1000);
	date = d.getDate();
	dstr = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + date;
	return dstr;
}

function format_float_number(srcStr, nAfterDot) {
	if (srcStr == null || srcStr == 0)
		return '0.00';
	if (nAfterDot == undefined)
		nAfterDot = 2;
	var s = parseFloat(srcStr).toFixed(nAfterDot);
	return s.replace(/\B(?=(?:\d{3})+(?:\.\d*)?$)/g, ',');
}

function literal_number(number, pre, fixUnit) {
	var n, precise = pre;
	if (precise == undefined) {
		precise = 2;
	}
	// console.log("precise--->" + precise);
	if (!fixUnit) {
		if (number > 100000000) {
			n = number / 100000000;
			console.log("number----" + n);
			n = format_float_number(n, precise) + "亿";
			console.log(n + "亿");
		} else if (number > 10000) {
			n = number / 10000;
			n = format_float_number(n, precise) + "万";
		} else {
			n = number;
		}
	} else {
		n = number / 10000;
		n = format_float_number(n, precise);
	}
	if (!n)
		n = 0;
	return n;
}

function VqqToday() {
	this.begin = 0;
	this.end = 0;
}

function get_current_vqq_time() {
	return convert_second_to_vqq_time(g_server_time / 1000);
}

function get_current_vqq_time_second() {
	return g_server_time / 1000;
}

function get_vqq_today(vt) {
	var date, nextDate, begin, end, today;
	if(!vt){
		date = get_current_vqq_time();
	}
	date.hour = 0;
	date.minute = 0;
	date.second = 0;

	nextDate = clone(date);
	nextDate.day = nextDate.day + 1;
	begin = convert_vqq_time_to_second(date);
	end = convert_vqq_time_to_second(nextDate);

	today = new VqqToday();
	today.begin = begin;
	today.end = end;
	return today;
}

function is_in_aggregation_time() {
	var t = g_server_time / 1000, 
		today = get_vqq_today();
	if (t >= (today.end - vqq_const.QQ_AGGREGATE_HANDLE_TIME - vqq_const.QQ_AGGREGATE_AUTION_TIME)
			&& t < today.end) {
		return true;
	}
	return false;
}

function is_in_weekend(t) {
	var d, toCheck, date, h;
	d = new Date();
	d.setTime(g_server_time);
	toCheck = g_server_time;
	if (t) {
		toCheck = t * 1000;
		d.setTime(toCheck);
	}
	date = d.getDate();
	h = d.getHours()
	if (h >= vqq_const.QQ_WEEKEND_BEGIN && h < vqq_const.QQ_WEEKEND_END) {
		return true;
	}
	return false;
}

function trans_index_to_time(index) {
	var vtoday = get_vqq_today(), 
		c = vtoday.begin + vqq_const.QQ_MAX_OPEN_QUOTATION_MINUTE_NUM * 60 + index * vqq_const.LINE_CHART_INTERVAL / 1000;
	return convert_second_to_hm(c);
}

function perfix_to_num(prefix, n, num) {
	var tmp = num + "";
	while (tmp.length < n) {
		tmp = prefix + tmp;
	}
	return tmp;
}

function get_cycle_name(cycleType) {
	var name = "";
	switch (cycleType) {
	case 8:
		name = "1分钟";
		break;
	case 1:
		name = "5分钟";
		break;
	case 2:
		name = "15分钟";
		break;
	case 3:
		name = "30分钟";
		break;
	case 4:
		name = "60分钟";
		break;
	case 5:
		name = "日";
		break;
	case 6:
		name = "周";
		break;
	case 7:
		name = "月";
		break;
	case 12:
		name = "年";
		break;
	default:
		break;
	}
	return name;
}

// ****************************************************************************************************************bid的时间问题
// 将秒换算成绝对的钱泉时间60s-->1m
function convert_second_to_abs_vqq_time(s) {
	// console.log(s);
	var vt, year, oyear, month, omonth, day, oday, hour, ohour, minute, ominute, second;
	vt = new VqqTime();
	year = s / vqq_const.QQ_YEAR_INTERVAL;
	oyear = Math.floor(year);

	month = (s - oyear * vqq_const.QQ_YEAR_INTERVAL)
			/ vqq_const.QQ_MON_INTERVAL;
	omonth = Math.floor(month);
	// console.log(omonth);
	day = (s - oyear * vqq_const.QQ_YEAR_INTERVAL - omonth
			* vqq_const.QQ_MON_INTERVAL)
			/ vqq_const.QQ_DAY_INTERVAL;
	oday = Math.floor(day);

	hour = (s - oyear * vqq_const.QQ_YEAR_INTERVAL - omonth
			* vqq_const.QQ_MON_INTERVAL - oday * vqq_const.QQ_DAY_INTERVAL)
			/ vqq_const.QQ_HOUR_INTERVAL;
	ohour = Math.floor(hour);

	minute = (s - oyear * vqq_const.QQ_YEAR_INTERVAL - omonth
			* vqq_const.QQ_MON_INTERVAL - oday * vqq_const.QQ_DAY_INTERVAL - ohour
			* vqq_const.QQ_HOUR_INTERVAL)
			/ vqq_const.QQ_MINUTE_INTERVAL;
	ominute = Math.floor(minute);

	second = s - oyear * vqq_const.QQ_YEAR_INTERVAL - omonth
			* vqq_const.QQ_MON_INTERVAL - oday * vqq_const.QQ_DAY_INTERVAL
			- ohour * vqq_const.QQ_HOUR_INTERVAL - ominute
			* vqq_const.QQ_MINUTE_INTERVAL;
	vt.year = oyear;
	vt.month = omonth;
	vt.day = oday;
	vt.hour = ohour;
	vt.minute = ominute;
	vt.secode = second;
	// console.log("vt before return-->%o", vt);
	return vt;
}

function convert_second_to_abs_vqq_mon_day(s) {
	// console.log(s);
	var vt, month, omonth, day, oday, hour, ohour, minute, ominute, second;
	vt = new VqqTime();
	month = s / vqq_const.QQ_MON_INTERVAL;
	omonth = Math.floor(month);
	// console.log(omonth);
	day = (s - omonth * vqq_const.QQ_MON_INTERVAL)
			/ vqq_const.QQ_DAY_INTERVAL;
	oday = Math.floor(day);

	hour = (s - omonth * vqq_const.QQ_MON_INTERVAL - oday
			* vqq_const.QQ_DAY_INTERVAL)
			/ vqq_const.QQ_HOUR_INTERVAL;
	ohour = Math.floor(hour);

	minute = (s - omonth * vqq_const.QQ_MON_INTERVAL - oday
			* vqq_const.QQ_DAY_INTERVAL - ohour * vqq_const.QQ_HOUR_INTERVAL)
			/ vqq_const.QQ_MINUTE_INTERVAL;
	ominute = Math.floor(minute);

	second = s - omonth * vqq_const.QQ_MON_INTERVAL - oday
			* vqq_const.QQ_DAY_INTERVAL - ohour * vqq_const.QQ_HOUR_INTERVAL
			- ominute * vqq_const.QQ_MINUTE_INTERVAL;
	if (oday == 0) {
		omonth -= 1;
		oday = 30;
	}
	vt.month = omonth;
	vt.day = oday;
	vt.hour = ohour;
	vt.minute = ominute;
	vt.secode = second;
	// console.log("vt before return-->%o", vt);
	return vt;
}
// 持续时间是整数，因此用这个函数，输出为*天或者*月或者*年
function convert_second_to_vqq_year_month_day(s) {
	var day, month, year;
	day = convert_second_to_vqq_days(s);// 换算为了钱泉天啦
	if (day < 30) {
		// day = "1";
		day = day + "天";
		return day;
	} else {
		month = day / 30;
		if (month < 12) {
			// month = "30";
			month = month + "个月";
			return month;
		} else {
			year = month / 12;
			// year = "365";
			year = year + "年";
			return year;
		}
	}
}
// 剩余时间不一定那个是整数，因此输出的结果为*年*月*天*小时*分*秒
function convert_second_to_vqq_left_year_month_day(s) {
	var str = "", vt = convert_second_to_abs_vqq_time(s);
	str += vt.year < 1 ? "" : (vt.year + "年");
	str += vt.month < 1 ? "" : (vt.month + "个月");
	str += vt.day < 1 ? "" : (vt.day + "天");
	str += vt.hour < 1 ? "" : (vt.hour + "小时");
	str += vt.minute < 1 ? "" : (vt.minute + "分");
	str += vt.second < 1 ? "" : (vt.second + "秒");
	return str == "" ? 0 : str;
}

function remove_options(obj) {
	var i, result = dojo.query("option", obj);
	for ( i = 0; i < result.length; ++i) {
		obj.removeChild(result[i]);
	}
}

function get_vqq_week(seconds) {
	// seconds = seconds - vqq_const.QQ_DAY_INTERVAL * 2;	//函数形参与scope变量声明同名?
	seconds -= vqq_const.QQ_HOUR_INTERVAL;
	var l, w, re = "";
	l = seconds - Math.floor(seconds / vqq_const.QQ_WEEK_INTERVAL)
			* vqq_const.QQ_WEEK_INTERVAL;
	w = Math.floor(l / vqq_const.QQ_DAY_INTERVAL) + 1;
	switch (w) {
	case 1:
		re = "周一";
		break;
	case 2:
		re = "周二";
		break;
	case 3:
		re = "周三";
		break;
	case 4:
		re = "周四";
		break;
	case 5:
		re = "周五";
		break;
	case 6:
		re = "周六";
		break;
	default:
		break;
	}
	return re;
}

function get_vqq_season(seconds) {
	var vt, w;
	if(!seconds){
		vt = get_current_vqq_time();
	}else{
		vt = convert_second_to_vqq_time();
	}
	if(vt.month > 0 && vt.month < 4){
		w = 1;
	}
	if(vt.month > 3 && vt.month < 7){
		w = 2;
	}
	if(vt.month > 6 && vt.month < 10){
		w = 3;
	}
	if(vt.month > 9 && vt.month < 13){
		w = 4;
	}
	return w;
}

function stock_grade(money) {
	if (isNaN(money)) {
		return "";
	}
	var str = "";
	if (money <= 300000) {
		str = "小散户";
	}
	if (money > 300000 && money <= 500000) {
		str = "中散户";
	}
	if (money > 500000 && money <= 1000000) {
		str = "大散户";
	}
	if (money > 1000000 && money <= 2000000) {
		str = "小中户";
	}
	if (money > 2000000 && money <= 5000000) {
		str = "大中户";
	}
	if (money > 5000000 && money <= 20000000) {
		str = "大户";
	}
	if (money > 20000000 && money <= 100000000) {
		str = "特大户";
	}
	if (money > 100000000) {
		str = "超大户";
	}
	return str;
}

function get_radio_value(container) {
	// console.log(container);
	var i, checkRedio, radios;
	radios = dojo.query('INPUT[type=radio]', container);
	// console.log("radios--->%o", radios);
	for ( i = 0; i < radios.length; i++) {
		checkRedio = radios[i];
		if (checkRedio.checked == true) {
			return checkRedio.value;
		}
	}
	return null;
}

function get_checkbox_value(name) {
	// console.log(container);
	var i, checkbox, radios;
	var vals = "";
	radios = dojo.query('INPUT[name='+name+']');
	// console.log("radios--->%o", radios);
	for ( i = 0; i < radios.length; i++) {
		checkbox = radios[i];
		if (checkbox.checked) {
			if(vals != ""){
				vals += ",";
			}
			vals += checkbox.value;
		}
	}
	return vals;
}

function create_form_to_post(url, postData, callback) {
	var getUrl, form, k, input, status;
	form = dojo.doc.createElement("form");
	form.setAttribute("id", new Date().getMilliseconds());
	dojo.body().appendChild(form);
	for (k in postData) {
		if(postData[k] != null && postData[k] != undefined )
		input = vqq_create_hide_input(form, {name: k, value: postData[k]});
	}
	//console.log(form);
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	var ss = url.split(g_basePath)[1];  
	getUrl = g_basePath + "api/" + ss;	
	dojo.xhrPost( {
		url :getUrl,
		form :form,
		handleAs :"json",
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			if(callback){
				callback(data, postData);
			}else{
				if (data && data.result != undefined && !data.result) {
					alert(data.err);
				} else if(data && data.result != undefined && data.result) {
					alert(data.msg);
				}
			} 	
		},
		error : function(error, args) {
			//console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				dojo.addClass(status, "errorStatus");
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
	dojo.destroy(form);
}

function add_url_suffix(url, suffix){
	if(url == undefined || suffix == undefined || url == "" || suffix == ""){
		return url;
	}
	var ss, a, b;
	if(url.indexOf("?") > 0){
		ss = url.split("?");
		a = ss[0];
		b = ss[1];
		a = a + suffix;
		url = a + "?" + b;
	}else{
		url = url + suffix;
	}
	return url;
}

function vqq_http_get(url, callback, thisObj) {
	var getUrl, random, status;
	random = Math.random();
	getUrl = url.appendParam("random", random);
	var ss = getUrl.split(g_basePath)[1];  
	getUrl = g_basePath + "api/" + ss;
	//getUrl = add_url_suffix(getUrl, ".action");	//函数形参与内部变量声明同名url, 且跟全局变量同名?
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	dojo.xhrGet( {
		url : getUrl,
		handleAs :"json",
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
		  /*if(data && !data.result && data.err == "NOLOGIN"){
			  location.href = basePath + "default.html";
		  }*/
		  if(callback){
			 callback(data, thisObj);
		   }
//		  else{
//			// console.log(data);
//			if (data && data.result != undefined && !data.result) {
//				 alert(data.err);
//			} else if(data && data.result != undefined && data.result) {
//				 alert(data.msg);
//			}
//	      }	
		},
		error : function(error, args) {
			console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "连接中...";
			}
		}
	});
}

function vqq_http_get_jsp(url, callback, thisObj) {
	var getUrl, random, status;
	random = Math.random();
	getUrl = url.appendParam("random", random);
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	dojo.xhrGet( {
		url : getUrl,
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
		  if(callback){
			 callback(data, thisObj);
		   }
		},
		error : function(error, args) {
			console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "连接出错，请您刷新页面试试...";
			}
		}
	});
}

function vqq_http_get_text(url, callback, thisObj) {
	var getUrl, random, status;
	random = Math.random();
	getUrl = url.appendParam("random", random);
	//url = add_url_suffix(url, ".action");	//函数形参与内部变量声明同名url, 且跟全局变量同名?
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	dojo.xhrGet( {   
		url : getUrl,
		handleAs :"text",
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
		  if(callback){
			 callback(data, thisObj);
		   }
		},
		error : function(error, args) {
			console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "连接故障，请您刷新页面试试...";
			}
		}
	});
}

function vqq_http_post(url, callback, formId, thisObj) {
	var status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	//url = add_url_suffix(url, ".action");
	var ss = url.split(g_basePath)[1]; 
	url = g_basePath + "api/" + ss;
	dojo.xhrPost( {
		url :url,
		form :formId,
		handleAs :"json",
		load : function(data) {
			// console.log(data);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			/*if(data && !data.result && data.err == "NOLOGIN"){
				  location.href = basePath + "default.html";
			  }*/
			if(callback){
				callback(data, thisObj);
			}else{
				if (!data.result) {
					alert(data.err);
					return;
				} else {
					alert(data.msg);
				}
			}
		},
		error : function(error, args) {
			//alert(error);
			console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
}

function vqq_http_post_text(url, callback, formId, thisObj) {
	var status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	//url = add_url_suffix(url, ".action");
	var ss = url.split(g_basePath)[1]; 
	url = g_basePath + "api/" + ss;
	dojo.xhrPost( {
		url :url,
		form :formId,
		load : function(data) {
			// console.log(data);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			/*if(data && !data.result && data.err == "NOLOGIN"){
				  location.href = basePath + "default.html";
			  }*/
			if(callback){
				callback(data, thisObj);
			}else{
				if (!data.result) {
					alert(data.err);
					return;
				} else {
					alert(data.msg);
				}
			}
		},
		error : function(error, args) {
			 console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
}

function vqq_http_post_jsp(url, callback, formId, thisObj) {
	var status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	dojo.xhrPost( {
		url :url,
		form :formId,
		load : function(data) {
			// console.log(data);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			/*if(data && !data.result && data.err == "NOLOGIN"){
				  location.href = basePath + "default.html";
			  }*/
			if(callback){
				callback(data, thisObj);
			}else{
				if (!data.result) {
					alert(data.err);
					return;
				} else {
					alert(data.msg);
				}
			}
		},
		error : function(error, args) {
			 console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
}

function get_gender(n) {
	var ret = "-";
	if (n == 0) {
		ret = "男";
	}
	if (n == 1) {
		ret = "女";
	}
	return ret;
}

function removeAndCreate(container) {
	var parent, e, list;
	parent = dojo.byId(container);
/*
	var parent;
	if (typeof(container) == "string") {
		parent = dojo.byId(container);
	}
	else if (typeof(container) == "object") {
		parent = container;
	}
*/
	// console.log("container6:%o",parent);
	e = dojo.byId(container + "_pageDatas");
	if (e) {
		parent.removeChild(e);
	}
	e = dojo.byId(container + "_pageIndex");
	if (e) {
		parent.removeChild(e);
	}// 清空
	list = dojo.doc.createElement("div");
	list.setAttribute("id", container + "_pageDatas");
	parent.appendChild(list);
	return list;
}

function array_2_map(array, keyName) {
	var i, obj, map = {};
	for ( i = 0; i < array.length; i++) {
		obj = array[i];
		map[obj[keyName]] = obj;
	}
	return map;
}

function vqq_create_element(name, parent, attrs) {
	if (parent == null)
		return null;
	var e, str, k; 
	if(dojo.isIE && name=="img"){
/*	已经不再使用的变量
		var date = new Date();
		var ss = date.getTime() + date.getMilliseconds() + "";
*/
		str = "<img onerror=\"this.src='" + basePath + "images/default/defaultLogo.jpg'\" ";
		// var str = "<img id='" + ss + "' onerror=\"this.src='" + basePath +
		// "images/default/defaultLogo.jpg'\" ";
		if (attrs) {
			for (k in attrs){
				str += (k + "='" + attrs[k] + "' ");
			}
		}
		parent.innerHTML += str + " />";
		//parent.innerHTML += str + "></img>";
		return parent.lastChild;
	}
	if(dojo.isIE && name=="input"){
		var str = "<input ";
		if (attrs) {
			for (k in attrs){
				str += (k + "='" + attrs[k] + "' ");
			}
		}
		parent.innerHTML += str + "/>";
		return parent.lastChild;
	}
	e = dojo.doc.createElement(name);
	parent.appendChild(e);
	if (attrs) {
		for (k in attrs) {
			if(dojo.isIE > 5){
				if(k == "style"){
					e.style.cssText = attrs[k];
				}
				else if(k == "onclick"){
					e.onclick = attrs[k];
				}
				else if(k == "class"){
					e.className = attrs[k];
				}
				else if(k == "type"){
					//
				}
				else{
					// e.setAttribute(k, attrs[k]);
					e[k] = attrs[k];
				}
			}else{
				e.setAttribute(k, attrs[k]);
			}
		}
	}
	if(name == "img"){
		e.setAttribute("onerror", "this.src = '" + basePath + "images/default/defaultLogo.jpg'");
	}
	return e;
}

function vqq_create_button(parent, attrs){
	var k, str = "<input type='button' ";
	if (attrs) {
		for (k in attrs){
			str += (k + "='" + attrs[k] + "' ");
		}
	}
	parent.innerHTML += str + "/>";
}

function vqq_create_hide_input(parent, attrs){
	var k, str = "<input type='hidden' ";
	if (attrs) {
		for (k in attrs){
			str += (k + "='" + attrs[k] + "' ");
		}
	}
	parent.innerHTML += str + "/>";
}

function vqq_create_text_input(parent, attrs){
	var k, str = "<input type='text' ";
	if (attrs) {
		for (k in attrs){
			str += (k + "='" + attrs[k] + "' ");
		}
	}
	parent.innerHTML += str + "/>";
}

function get_literal_privacy(n) {
	var str = "对所有人公开";
	switch (n) {
	case 0:
		break;
	case 1:
		str = "仅对好友公开";
		break;
	case 2:
		str = "回答问题";
		break;
	case 3:
		str = "仅自己可见";
	}
	return str;
}

function get_rolebits() {
	var roleBits = [];
	roleBits.push( {
		"系统管理员" :vqq_const.ROLE_SYS_ADMIN
	});
	roleBits.push( {
		"招投标管理员" :vqq_const.ROLE_BID_ADMIN
	});
	roleBits.push( {
		"用户管理员" :vqq_const.ROLE_USER_ADMIN
	});
	roleBits.push( {
		"股票管理员" :vqq_const.ROLE_STOCK_ADMIN
	});
	roleBits.push( {
		"理财产品管理员" :vqq_const.ROLE_PRODUCT_ADMIN
	});
	roleBits.push( {
		"消费购置管理员" :vqq_const.ROLE_CONSUME_ADMIN
	});
	roleBits.push( {
		"消息系统管理员" :vqq_const.ROLE_INFO_ADMIN
	});
	return roleBits;
}

function remove_children(eid) {
	var n = dojo.byId(eid);
	while (n && n.hasChildNodes()) {
		n.removeChild(n.firstChild);
	}
	return n;
}

function onerror_default_img(img){
	var obj, isIE;
	if(typeof(img) == "string"){
		obj = dojo.byId(img);
	}else{
		obj = img;
	}
	isIE = dojo.isIE;
	if (isIE) {
		// obj.onerror = "this.src='" + basePath +
		// "images/default/defaultLogo.jpg'";
		// 在此加onerror无效， 在vqq_create_element 里边已经做处理
	}
	else {
		obj.setAttribute("onerror", "this.src = '" + basePath + "images/default/defaultLogo.jpg'");
	}
}

function sub_words_count(content, n) {
	var r, m, i;
	r =/[^\x00-\xff]/g;

	if (!(typeof(content) == "string")) {
		return;
	}

	if (content.replace(r, "mm").length <= n){
		return content;
	}

	m = Math.floor(n/2);    
	for ( i = m;  i< content.length; i++) {    
		if (content.substr(0, i).replace(r, "mm").length >= n) {    
			return content.substr(0, i) +"..."; 
		}    
	} 
	return content;   
}

function scale_img(i, x, y) {
	var w, h, k, p, a, b;
	w = (x!= null) ? x: 85;
	h = (y!=null) ? y: 65;

	p = new Image();
	p.src = i.src;

	a = p.width;
	b = p.height;

	if(a > w) {
		k = w;
	}
	else {
		k = a;
	}

	if ( (b * k/a) > h) {
		i.height = h;
		i.width = h/b * a;
	}
	else {
		i.width = k;
		i.height = k/a * b;
	}  
}  


function mouseMove(evt){
	var evt = evt||window.event,
	mousePos = mouseCoords(evt);
	return mousePos;
}

function mouseCoords(evt){
	if(evt.pageX || evt.pageY){
		return {
			x:evt.pageX,
			y:evt.pageY
		};
	}
	return {
		x:evt.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:evt.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

/*
function IsIE() {
	return !-[1,];
	// 或者 var isIE = !+'\v1';
}
*/

function is_DescendantOf(element, ancestor) {
	var element = element, ancestor = ancestor;
	while (element = element.parentNode)
	    if (element == ancestor) return true;
	return false;	
}

function calc_mortgage(loan/* 贷款总额 */, rate/* 利率 */, y/* 年份数 */){
	var a, i, n, pow, m;
	a = loan;
	i = rate / 12 / 100;
	n = y * 12;
	pow = Math.pow((1 + i) , n);
	m = a * (i * pow) / (pow - 1);
	return m;
}

// 返回元素具体位置函数
function getElementPos(elementId) {
	var ua, isOpera, isIE, el, parent, box, pos = [];
	ua = navigator.userAgent.toLowerCase();
	isOpera = (ua.indexOf('opera') != -1);
	isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
	el = document.getElementById(elementId);
	if(el.parentNode === null || el.style.display == 'none') {
		return false;
	}     
	parent = null;
	if(el.getBoundingClientRect)    // IE
	{         
		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)    // gecko
	{
		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    // safari & opera
	{
		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') { // account
																			// for
																			// any
																			// scrolled
																			// ancestors
		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 build_div_clear(node, css) {// 创建清除浮动Div元素
	if (!css || typeof(css) == "undefined") {
		vqq_create_element("div", node, {"class": "clearfix"});
	}
	else {
		vqq_create_element("div", node, {"class": css});
	}
}

function handle_product_name(product){
	product.name = product.name.replace("YY", "钱泉" + perfix_to_num('0', 3, get_current_vqq_time().year) + "年").replace("XX", product.id); 
	return product;
}
//*
// 1.为img路径加上basePath
function handle_words(body){
	var rxp = /(.*?<img\s+src=")(\S+.*?)(\d+.gif)(".*?)/ig;
	body = body.replace(rxp, "$1"+basePath+ "img/" + "$3$4");	
	return body;
}

function load_js(src, callback){ 
	vqq_http_get_text(basePath + src, function(data){
		var oHead = document.getElementsByTagName("HEAD").item(0);
		var oScript = vqq_create_element("script", oHead);
		oScript.language = "javascript";
		oScript.type = "text/javascript";
		oScript.id = "sg";
		oScript.defer = "true";
		oScript.text = data;
		
		if(callback){
			setTimeout(function(){callback()}, 500);
		}
	});
}

function load_css(src, callback) {
/*
	vqq_http_get_text(g_basePath + src, function(data) {
			var oHead = document.getElementsByTagName("HEAD").item(0);
			//var oCss = vqq_create_element("link", oHead);
*/
			var oHead = document.getElementsByTagName("HEAD").item(0);
			var oCss = document.createElement("link");
			oCss.rel = "stylesheet";
			oCss.type = "text/css";
			oCss.defer = "true";
			oCss.href = src;
			oCss.id = "dynamicCss";
			oCss.media = "screen";
			oCss.rev = "stylesheet";
			//oCss.text = data;
			oHead.appendChild(oCss);
			if (callback) {
				setTimeout(function(){callback()}, 500);
			}
//		});
}

/* 过滤html标签 */
function filter_html(str) {
	if (!str || typeof(str) != "string") {
		return "";
	}
	var match = /<[^>]*>/g;
	return str.replace(match, "");
}

/*/
function handle_words(body){
	var rxp = /(.*?<img\s+src=")(\S+)(".*?)/ig;
	body = body.replace(rxp, "$1"+basePath+"$2$3");	
	return body;
}


/** ********************以下定义全局变量***************************** */
var g_me,	// 用户信息
	g_him,	// 他人信息
	g_user_title = "他", 
	g_userProperty,	// 用户的资产
	g_callbacks = [],	// 回调函数，别的地方要用到g_userProperty，可以把函数放到此数组，等待调用。
	g_init_top_left_auto = true,	// 页面主动初始化左侧栏。如不需要主动初始化，将此置为false。
	g_fund,	// 基金
	g_currTarget,	// 当前目标
	g_server_time = 0,	// 页面初始化的时候，服务器时间
	g_is_timing = false,
	g_pass,
	g_chatMainWnd,
	g_winkInterval = null,
	g_onlineUids = new Array(),
	g_userCometChannel = null;
/** ********************以上定义全局变量***************************** */

// 获取服务器时间，开始计时
dojo.addOnLoad(function(){
	if(g_is_timing){
		return;
	}
	g_is_timing = true;
	vqq_http_get(basePath + "serverTime?r=" + Math.random(), function(data){
		g_server_time = data;
		setInterval(function(){
			// console.log("g_server_time--->" + g_server_time);
			g_server_time += 1000;
		}, 1000);
		setTimeout(function() {
			if ('showVqqTime' in window) {
				showVqqTime();
			}
		}, 1000);
	});
});


function cancel_onClick_event(evt) {
	var evt = evt || event;
	if (evt.preventDefault) {
		evt.preventDefault();
		evt.stopPropagation();
	}
	else {
		evt.cancelBubble = true;
		evt.returnValue = false;
	}	
}

function get_node_from_event(evt) {
	var evt = evt || event;
	var node;
	if (evt.preventDefault) {
		evt.preventDefault();
		evt.stopPropagation();
		node = evt.target;
	}
	else {
		evt.cancelBubble = true;
		evt.returnValue = false;
		node = evt.srcElement;
	}
	return node;
}

