//跳转
function Location_button(url){
	document.location.href = url;
}
//提交表单
function Query_button(obj,Fname){
	document[Fname].submit();
	obj.disabled = true;
}
//保存
function Save_button(obj,Fname){
	document[Fname].cmd.value = 'save';
	obj.disabled = true;
	document[Fname].submit();
}
//分页
function page(Fname,p){
	document[Fname].page.value = p;
	document[Fname].submit();
}
//分页跳转
function change_page(Fname){
	var el = document.getElementById("page_select");
	if(el != null){
		for(i=0;i<el.options.length;i++){
			if( el.options(i).selected ){
				var pager = el.options(i).value;
				document[Fname].page.value = pager;
				document[Fname].submit();
			}
		}
	}
}
	
//删除
function Delete_check(Fname,field,id) {
	res = confirm("真的要删除这条记录吗?");
	if (res == true) {
		obj = document[Fname];
		obj.cmd.value = "delete";
		obj[field].value = id;
		document[Fname].submit();
	}
}
//table 选项卡
//@card:选项卡标示id
//[card]_tab_[i]:选项卡
//[card]_ctab_[i]:选项卡内容
//[st]_menu_hover,[st]_menu_out:样式
function table_card(card,curr,num,st){
	for(i=1;i<=num;i++){
		document.getElementById(card+"_tab_"+i).className	 = st+"_menu_out"; 
		document.getElementById(card+"_ctab_"+i).style.display= "none"; 
	}
	document.getElementById(card+"_tab_"+curr).className	 = st+"_menu_hover"; 
	document.getElementById(card+"_ctab_"+curr).style.display= "block"; 
}
//自动按比例显示图片，按比例压缩图片显示
function AutoResizeImage(maxWidth,maxHeight,objImg){
	if (typeof(objImg)=='string'){
		objImg = $(objImg);
	}
	var img = new Image();
	img.onload = function(){
		var hRatio;
		var wRatio;
		var Ratio = 1;
		var w = img.width;
		var h = img.height;
		wRatio = maxWidth / w;
		hRatio = maxHeight / h;
		wRatio = wRatio>1?1:wRatio;
		hRatio = hRatio>1?1:hRatio;
		if (maxWidth ==0 && maxHeight==0){
			Ratio = 1;
		}else if (maxWidth==0){	//
			if (hRatio<1) Ratio = hRatio;
		}else if (maxHeight==0){
			if (wRatio<1) Ratio = wRatio;
		}else {
			Ratio = (wRatio<=hRatio?wRatio:hRatio);
		}
		if (Ratio<1){
			w = w * Ratio;
			h = h * Ratio;
		}
		objImg.height = h;
		objImg.width = w;
		this.onload = function(){}
	}
	img.src = objImg.src;
}
function copyToClipBoard(){
	var clipBoardContent="";
	clipBoardContent+=document.title;
	clipBoardContent+="\n";
	clipBoardContent+=this.location.href;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
}
function AddFavorite(sURL,sTitle)
{
	try{
		window.external.addFavorite(sURL, sTitle);
	}
	catch (e){
		try{
			window.sidebar.addPanel(sTitle, sURL, "");
		}
		catch (e){
			alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}
/*
 * 设为主页
 */
function AddHome(sURL)
{
	if (window.sidebar) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
		}
		catch (e){
			alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为true"); 
		} 
		var prefs =  Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch );
		prefs.setCharPref("browser.startup.homepage",sURL);
	}else if(document.all){
		document.body.style.behavior="url(#default#homepage)";
		document.body.setHomePage(sURL);
    }
}
function ChangeLeft_Right(){
	//取得右边高度
	if(document.getElementById('right_h')){
		var RH = document.getElementById('right_h').offsetHeight;
		var LH = document.getElementById('left_h').offsetHeight;
		//改变右边高度
		if( LH > RH ){
			document.getElementById("right_h").style.height = LH+"px";
		}
		//改变左边高度
		if( LH < RH ){
			document.getElementById("left_h").style.height = RH+"px";
		}
	}
}
//onchange="window.open(this.options[this.selectedIndex].value);"
/*
 * AJAX 取得广告
 */
function GetAdver(url,place,return_div){
	$.ajax({
		type: "POST",
		url:  url,
		data: "place="+place,
		success: function(msg){
			$("#"+return_div).html(msg);
		} 
	});
}

/*
 * 幻灯片
 * */
function ImageMovie(){
	this.width=100;
	this.height=100;
	this.textHeight=20;
	this.flashHeight=0;
	this.pics='';
	this.links='';
	this.texts='';
	this.add=function(pic,link,text){
		if(this.pics!='')this.pics+='|';
		this.pics+=pic;
		if(this.links!='')this.links+='|';
		this.links+=link;
		if(this.texts!='')this.texts+='|';
		this.texts+=text;
	}
	this.play = function(){
		this.flashHeight=this.height + this.textHeight;
		document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ this.width +'" height="'+ this.flashHeight +'">');
		document.writeln('<param name="allowScriptAccess" value="sameDomain">');
		document.writeln('<param name="movie" value="static/flash/focus.swf">');
		document.writeln('<param name="quality" value="high">');
		document.writeln('<param name="bgcolor" value="#FFFFFF">');
		document.writeln('<param name="menu" value="false">');
		document.writeln('<param name=wmode value="transparent">');
		document.writeln('<param name="FlashVars" value="pics='+this.pics+'&links='+this.links+'&texts='+this.texts+'&borderwidth='+this.width+'&borderheight='+this.height+'&textheight='+this.textHeight+'">');
		document.writeln('<embed src="static/flash/focus.swf" wmode="transparent" FlashVars="texts='+this.texts+'&pics='+this.pics+'&links='+this.links+'&borderwidth='+this.width+'&borderheight='+this.height+'&textheight='+this.textHeight+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ this.width +'" height="'+ this.flashHeight +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	    document.writeln('</object>');
	}
}

/*
 * 选项卡
 * */
opCard = function()
{
	this.bind = new Array();
	this.index = 0;		//默认显示哪个选项卡，从0开始
	this.style = new Array();		//["","",""]
	this.overStyle = false;		//选项是否有over, out变换样式事件，样式为this.style[2]
	this.overChange = false;		//内容是否用over, out直接激活
	this.menu = false;				//菜单类型
	this.nesting = [false,false,"1","1"];		//是否嵌套，后面2个参数是指定menu,info的子集深度所用id
	this.auto = [false, 1000];		//自动滚动[true,2000]
	this.timerID = null;			//自动播放的
	this.menutimerID = null;		//菜单延时的
	this.creat = function(func)
	{
		var _arrMenu = document.getElementById(this.bind[0]).getElementsByTagName(this.bind[1]);
		var _arrInfo = document.getElementById(this.bind[2]).getElementsByTagName(this.bind[3]);
		var my = this, i;
		var argLen = arguments.length;
		var arrM = new Array();
		if(this.nesting[0] || this.nesting[1])	// 有选项卡嵌套
		{	// 过滤出需要的数据
			var arrMenu = this.nesting[0]?getChilds(_arrMenu,this.bind[0],2):_arrMenu;
			var arrInfo = this.nesting[1]?getChilds(_arrInfo,this.bind[2],3):_arrInfo;
		}
		else
		{
			var arrMenu = _arrMenu;
			var arrInfo = _arrInfo;
		}
		var l = arrMenu.length;
		if(l!=arrInfo.length){alert("菜单和内容必须拥有相同的数量\n如果需要，你可以放一个空的在那占位。")}
		// 修正
		if(this.menu){this.auto=false;this.overChange=true;} //如果是菜单，则没有自动运行，有over, out直接激活
		// 循环添加各个事件等
		for(i=0;i<l;i++)
		{
			arrMenu[i].cName = arrMenu[i].className;
			arrMenu[i].className = (i!=this.index || this.menu)?getClass(arrMenu[i],this.style[0]):getClass(arrMenu[i],this.style[1]);		//加载样式，菜单的话统一样式
			if(arrMenu[i].getAttribute("skip")) // 需要跳过的容器
			{
				if(this.overStyle || this.overChange)	// 有over, out 改变样式 或者 激活
				{
					arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
					arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
				}
				arrMenu[i].onclick = function(){if(argLen==1){func()}}
				arrInfo[i].style.display = "none";
				continue;
			}
			if(i!=this.index || this.menu){arrInfo[i].style.display="none"};	//隐藏初始化，菜单的话全部隐藏
			arrMenu[i].index = i;	//记录自己激活值[序号]
			arrInfo[i].index = i;
			if(this.overChange)	//有鼠标over, out事件
			{
				arrMenu[i].onmouseover = function(){changeOption(this);my.menu?changeMenu(1):autoStop(this, 0);}
				arrMenu[i].onmouseout = function(){changeOption(this);my.menu?changeMenu(0):autoStop(this, 1);}
			}
			else	//onclick触发
			{
				arrMenu[i].onclick = function(){changeOption(this);autoStop(this, 0);if(argLen==1){func()}}
				if(this.overStyle)	// 有over, out 改变样式
				{
					arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
					arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
				}
				else	// 没有over, out 改变样式
				{
					if(this.auto[0])	// 有自动运行
					{
						arrMenu[i].onmouseover = function(){autoStop(this, 0);}
						arrMenu[i].onmouseout = function(){autoStop(this, 1);}
					}
				}
			}
			if(this.auto[0] || this.menu)	//arrinfo 控制自动播放
			{
				arrInfo[i].onmouseover = function(){my.menu?changeMenu(1):autoStop(this, 0);}
				arrInfo[i].onmouseout = function(){my.menu?changeMenu(0):autoStop(this, 1);}
			}
		}	//for结束
		if(this.auto[0])
		{
			this.timerID = setTimeout(autoMove,this.auto[1])
		}
		// 自动播放
		function autoMove()
		{
			var n;
			n = my.index + 1;
			if(n==l){n=0};
			while(arrMenu[n].getAttribute("skip"))		// 需要跳过的容器
			{
				n += 1;
				if(n==l){n=0};
			}
			changeOption(arrMenu[n]);
			my.timerID = setTimeout(autoMove,my.auto[1]);
		}
		// onmouseover时，自动播放停止。num：0为over，1为out。 obj暂时无用。 -_-!!
		function autoStop(obj, num)
		{
			if(!my.auto[0]){return;}
			//if(obj.index==my.index)
			num == 0 ? clearTimeout(my.timerID) : my.timerID = setTimeout(autoMove,my.auto[1]);
		}
		// 改变选项卡
		function changeOption(obj)
		{
			arrMenu[my.index].className = getClass(arrMenu[my.index],my.style[0]);	//修改旧内容
			arrInfo[my.index].style.display = "none";	//隐藏旧内容
			obj.className = getClass(obj,my.style[1]);		//修改为新样式
			arrInfo[obj.index].style.display = "";	//显示新内容
			my.index = obj.index;	//更新当前选择的index
		}
		/*
			只有onclick时，overStyle的onmouseover,onmouseout事件。用来预激活
			obj：目标对象。	num：1为over，0为out
		*/
		function changeTitle(obj, num)
		{
			if(!my.overStyle){return;};
			if(obj.index!=my.index){obj.className = getClass(obj,my.style[num])}
		}
		/*
			菜单类型时用
			obj：目标对象。	num：1为over，0为out
		*/
		function changeMenu(num)
		{
			if(!my.menu){return;}
			num==0?my.menutimerID = setTimeout(menuClose,1000):clearTimeout(my.menutimerID)
		}
		//关闭菜单
		function menuClose()
		{
			arrInfo[my.index].style.display = "none";
			arrMenu[my.index].className = my.style[0];
		}
		// 得到className（防止将原有样式覆盖）
		function getClass(o, s)
		{
			if(o.cName==""){return s}
			else{return o.cName + " " + s}
		}
		//嵌套情况下得到真正的子集
		function getChilds(arrObj, id, num)
		{
			var depth = 0;
			var firstObj = my.nesting[num]==""?arrObj[0]:document.getElementById(my.nesting[num]);		//得到第一个子集
			do	//计算深度
			{
				if(firstObj.parentNode.getAttribute("id")==id){break}else{depth+=1}
				firstObj = firstObj.parentNode;
			}
			while(firstObj.tagName.toLowerCase()!="body")	// body强制退出。
			var t;
			var arr = new Array();
			for(i=0;i<arrObj.length;i++)	//过滤出需要的数据
			{
				t = arrObj[i], d = 0;
				do
				{
					if(t.parentNode.getAttribute("id")==id && d == depth)
					{
						arr.push(arrObj[i]);break;		//得到数据
					}
					else
					{
						if(d==depth){break};d+=1;
					}
					t = t.parentNode;
				}
				while(t.tagName.toLowerCase()!="body")	// body强制退出
			}
			return arr;
		}
	}
}

/*
 * 滚动
 * */
function Marquee()
{
	this.ID = document.getElementById(arguments[0]);
	if(!this.ID)
	{
		alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
		this.ID = -1;
		return;
	}
	this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
	this.Step = 1;
	this.Timer = 30;
	this.DirectionArray = {"top":0 , "up":0 , "bottom":1 , "down":1 , "left":2 , "right":3};
	if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.Direction = arguments[1];
	if(typeof arguments[2] == "number")this.Step = arguments[2];
	if(typeof arguments[3] == "number")this.Width = arguments[3];
	if(typeof arguments[4] == "number")this.Height = arguments[4];
	if(typeof arguments[5] == "number")this.Timer = arguments[5];
	if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
	if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
	if(typeof arguments[8] == "number")this.ScrollStep = arguments[8];
	this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
	this.ID.noWrap = true;
	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	if(arguments.length >= 7)this.Start();
}
Marquee.prototype.Start = function()
{
	if(this.ID == -1)return;
	if(this.WaitTime < 800)this.WaitTime = 800;
	if(this.Timer < 20)this.Timer = 20;
	if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
	if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
	if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
	this.HalfWidth = Math.round(this.Width / 2);
	this.HalfHeight = Math.round(this.Height / 2);
	this.BakStep = this.Step;
	this.ID.style.width = this.Width + "px";
	this.ID.style.height = this.Height + "px";
	if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
	var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td></tr></table>";
	var templateTop = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;'><tr><td>MSCLASS_TEMP_HTML</td></tr><tr><td>MSCLASS_TEMP_HTML</td></tr></table>";
	var msobj = this;
	msobj.tempHTML = msobj.ID.innerHTML;
	if(msobj.Direction <= 1)
	{
		msobj.ID.innerHTML = templateTop.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
	}
	else
	{
		if(msobj.ScrollStep == 0 && msobj.DelayTime == 0)
		{
			msobj.ID.innerHTML += msobj.ID.innerHTML;
		}
		else
		{
			msobj.ID.innerHTML = templateLeft.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
		}
	}
	var timer = this.Timer;
	var delaytime = this.DelayTime;
	var waittime = this.WaitTime;
	msobj.StartID = function(){msobj.Scroll()}
	msobj.Continue = function()
				{
					if(msobj.MouseOver == 1)
					{
						setTimeout(msobj.Continue,delaytime);
					}
					else
					{	clearInterval(msobj.TimerID);
						msobj.CTL = msobj.Stop = 0;
						msobj.TimerID = setInterval(msobj.StartID,timer);
					}
				}
	msobj.Pause = function()
			{
				msobj.Stop = 1;
				clearInterval(msobj.TimerID);
				setTimeout(msobj.Continue,delaytime);
			}
	msobj.Begin = function()
		{
			msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth / 2 : msobj.ID.scrollHeight / 2;
			if((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step))			{
				msobj.ID.innerHTML = msobj.tempHTML;
				delete(msobj.tempHTML);
				return;
			}
			delete(msobj.tempHTML);
			msobj.TimerID = setInterval(msobj.StartID,timer);
			if(msobj.ScrollStep < 0)return;
			msobj.ID.onmousemove = function(event)
						{
							if(msobj.ScrollStep == 0 && msobj.Direction > 1)
							{
								var event = event || window.event;
								if(window.event)
								{
									if(msobj.IsNotOpera)
									{
										msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
									}
									else
									{
										msobj.ScrollStep = null;
										return;
									}
								}
								else
								{
									msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
								}
								msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
								msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
								msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
							}
						}
			msobj.ID.onmouseover = function()
						{
							if(msobj.ScrollStep == 0)return;
							msobj.MouseOver = 1;
							clearInterval(msobj.TimerID);
						}
			msobj.ID.onmouseout = function()
						{
							if(msobj.ScrollStep == 0)
							{
								if(msobj.Step == 0)msobj.Step = 1;
								return;
							}
							msobj.MouseOver = 0;
							if(msobj.Stop == 0)
							{
								clearInterval(msobj.TimerID);
								msobj.TimerID = setInterval(msobj.StartID,timer);
							}
						}
		}
	setTimeout(msobj.Begin,waittime);
}
Marquee.prototype.Scroll = function()
{
	switch(this.Direction)
	{
		case 0:
			this.CTL += this.Step;
			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
			{
				this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
				this.Pause();
				return;
			}
			else
			{
				if(this.ID.scrollTop >= this.ClientScroll)
				{
					this.ID.scrollTop -= this.ClientScroll;
				}
				this.ID.scrollTop += this.Step;
			}
		break;
		case 1:
			this.CTL += this.Step;
			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
			{
				this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
				this.Pause();
				return;
			}
			else
			{
				if(this.ID.scrollTop <= 0)
				{
					this.ID.scrollTop += this.ClientScroll;
				}
				this.ID.scrollTop -= this.Step;
			}
		break;
		case 2:
			this.CTL += this.Step;
			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
			{
				this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
				this.Pause();
				return;
			}
			else
			{
				if(this.ID.scrollLeft >= this.ClientScroll)
				{
					this.ID.scrollLeft -= this.ClientScroll;
				}
				this.ID.scrollLeft += this.Step;
			}
		break;
		case 3:
			this.CTL += this.Step;
			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
			{
				this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
				this.Pause();
				return;
			}
			else
			{
				if(this.ID.scrollLeft <= 0)
				{
					this.ID.scrollLeft += this.ClientScroll;
				}
				this.ID.scrollLeft -= this.Step;
			}
		break;
	}
}
