/* @charset "utf-8" */
/**
  *共用js
  *
  *@author : 祝文博  <email : zhuwenbo@myhexin.com> 
  *@create on 2011-09-21 15:00
  */
/**
 * JS方式获取GET参数方法
 */
function getArgs()
{  
	var args = {}; 
	var query = location.search.substring(1);
	// Get query string 
	var pairs = query.split("&");  
	// Break at ampersand 
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('='); 
		// Look for "name=value" 
		if (pos == -1) continue; 
		// If not found, skip 
		var argname = pairs[i].substring(0,pos);// Extract the name 
		var value = pairs[i].substring(pos+1);// Extract the value 
		value = decodeURIComponent(value);// Decode it, if needed 
		args[argname] = value; 
		// Store as a property 
	}
	return args;// Return the object  
}

/**
 * 判断变量是否有值
 */
function hasValue(ckValue)
{
	if (ckValue == "" || ckValue == null || ckValue == undefined || ckValue.length == 0 || typeof(ckValue) == 'undefined') {
		return false;
	}
	return true;
}

/**
 * 加单位
 * @param float num 
 * @param integer	decimal
 * @returns string
 */
function judgeNum(num, decimal)
{
	var fNum = parseFloat(num);
	if (isNaN(fNum)) {
		return "--";
	}
	var interNum = fNum.toFixed(0);
	var positiveNum = Math.abs(interNum); 
	var fNumLength = positiveNum.toString().length;
	if (fNumLength <5) {//不加单位
		retNum = fNum.toFixed(decimal);
	} else if ( fNumLength >= 5 && fNumLength < 9 ) {//万
		retNum = (interNum / Math.pow(10, 4)).toFixed(decimal) + '万';
	} else if ( fNumLength >= 9 && fNumLength < 13 ) {//亿
		retNum = (interNum / Math.pow(10, 8)).toFixed(decimal) + '亿';
	} else {//万亿
		retNum = (interNum / Math.pow(10, 12)).toFixed(decimal) + '万亿';
	}
	return retNum;
}

/**
 * 小数位数处理，不加单位
 * @param float num 
 * @param integer	decimal
 * @returns string
 */
function judgeNumNoUnit(num, decimal)
{
	var fNum = parseFloat(num);
	if (isNaN(fNum)) {
		return "--";
	}
	return fNum.toFixed(decimal);
}


//分钟时间的格式
//|<- 32 - 29 ->|<- 28 - 21 ->|<- 20 - 17 ->|<- 16 - 12 ->|<- 11 - 7 ->|<- 6 - 1 ->|
//  保留            年             月           日            时           分
//						3				2			2			2			  2
//年份减去1900
//201202201120
/**
 * 转换时间201102201120->117613268
 */
function minuteToData(time) {
	var timeStr, minute, hour, day, month, year, retTime;
	timeStr = String(time);
	minute = timeStr.substring(10);
	hour = timeStr.substring(8,10);
	day = timeStr.substring(6,8);
	month = timeStr.substring(4,6);
	year = String(timeStr.substring(0,4) - 1900);
	
	retTime = year * Math.pow(2, 20) + month * Math.pow(2, 16) + day * Math.pow(2, 11)  + hour * Math.pow(2, 6) + minute * Math.pow(2, 0);
	/* document.write(minute+"<br/>");
	document.write(hour+"<br/>");
	document.write(day+"<br/>");
	document.write(month+"<br/>");
	document.write(year+"<br/>"); */
	return retTime;
}

function getAreaData(params, callback) {
	var thsQuote, param;
	thsQuote = external.createObject('Quote');
	param = {
		code		: params['code'],
		datatype	: params['datatype'],
		sorttype	: params['sorttype'],
		period		: params['period'],
		ascend		: params['ascend'],
		sortbegin	: params['sortbegin'],
		sortcount	: params['sortcount'],
		begintime	: params['begintime'],
		endtime		: params['endtime'],
		onready		: function(retStr) {
//			document.write(retStr);
			retObj = eval('(' + retStr + ')');
			var i	= 0;
			for (var k in retObj) {
				i++;
			}
			if (i > params['sortcount']) {
				retObj	= undefined
			}
			
			if (typeof callback == 'function') {
				callback(retObj);
			}
		}
	};
	thsQuote.AreaStatRequest(param);
}