//
// common.js
//
// 1.0.0	ssj		2005.8.15
//
//

//--------- 公共函数

// 获取文件的扩展名
function GetExtension(path)
{
	var p = path.indexOf(".");
	if (p == -1)
	{
		return "";
	}
	else
	{
		return path.substring(p);
	}
}

function GoToUrl(url)
{
	
	window.location.href = url;

}

// 获得页面上控件的输入
function GetInput(id)
{
	return document.getElementById(id).value;
}


// 使用DataInfo中的数据作为QueryString打开url
function OpenWindow(url, data)
{
	url += url.indexOf("?") == -1 ? "?" : "&";
	url += data.GetQuery();
	
	window.open(encodeURI(url));
}


//--------- 公共类



// 存储输入数据的类
function DataInfo()
{
	this.MemberExcept = "/MemberExcept/Error/";	// 用于ToString之类的方法不输出此成员

	this.Error = "";
	
	
	this.HasError = function()
	{
		return this.Error.length != 0; 
	};
	
	this.Require = function(name, msg)
	{
		if (this[name] == null || this[name].length == 0)
		{
			this.Error += msg + "\n";
		}
	};
	
	this.Check = function(condition, msg)
	{
		if (!condition)
		{
			this.Error += msg + "\n";
		}
	}
	
	
	this.ToString = ToString;
	this.GetQuery = GetQuery;
}

function ToString()
{
	var str = "";
	for (member in this)
	{
		if (member.length != 0
			&& !(this[member] instanceof Function)
			&& this.MemberExcept.indexOf( "/" + member + "/") == -1)
		{
			str += member + "=" + this[member] + "\n";
		}
	}
	
	return str;
}

function GetQuery()
{
	var q = this.ToString();
	if (q.length != 0)
	{
		q = q.replace(/\n/g, "&");
		q = q.substring(0, q.length - 1); // 去除最后的&
	}

	return q;
}


// 解析查询字符串

function QueryString(query)
{
	this.MemberExcept = "/MemberExcept/";
	
	
	// init
	query = decodeURI(query);
	if (query.substring(0, 1) == "?")
	{
		query = query.substring(1);
	}

	var arrQuery = query.split("&");
	for (i = 0; i < arrQuery.length; i++)
	{
		var q = arrQuery[i].split("=");
		this[q[0]] = q[1];
	}
	// init - end
	
	
	this.ToString = ToString;
	this.GetQuery = GetQuery;
}
//---------浮动广告-------------------------------
function floatDiv(id,x,y,content)
{
	document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
	play(id,x,y);
}

function play(id,x,y)
{

	var delta=0.15

	var followObj = document.all.item(id);
	var followObj_x = x;
    var followObj_y = y;

	if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) 
    {
	    var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
	    dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
	    followObj.style.left=followObj.offsetLeft+dx;
	}

	if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) 
    {
	    var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
	    dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
	    followObj.style.top=followObj.offsetTop+dy;
	}
	followObj.style.display = '';

	setTimeout("play('"+id+"',"+x+","+y+");", 10);

}	
//-------------------------------------------------------------------------------



//小数位计算
//-------------------------------------------------------------------------------

function formatnumber(value,num) 
{
	var a,b,c,i;
	a = value.toString();
	b = a.indexOf('.');
	c = a.length;
	if (num==0)
	{
		if (b!=-1)
		a = a.substring(0,b);
	}
	else
	{
		if (b==-1)
		{
			a = a +".";
			for (i=1;i<=num;i++)
				a = a +"0";
		}
		else
		{
			a = a.substring(0,b+num+1);
			for (i=c;i<=b+num;i++)
				a = a +"0";
		}
	}
	return a
}


function  cheng(num,n)  
{
	var  dd=1;  
	var  tempnum;  
	for(i=0;i<n;i++)  
	{  
		dd*=10;  
	}  
	tempnum=num*dd;  
	tempnum=Math.round(tempnum);  
	return (tempnum/dd);  
}  
