/*
Rem =========================================================
Rem  $Revision: 1.5 $
Rem  $Author: JY_Online $
Rem  $Date: 2008/02/29 08:09:13 $
Rem  $Header: /CVS/Meizhou114.com/Js_File/KY_Function.js,v 1.5 2008/02/29 08:09:13 JY_Online Exp $
Rem  $Log: KY_Function.js,v $
Rem  Revision 1.5  2008/02/29 08:09:13  JY_Online
Rem  增加了一个TIPS函数，修正断行时未加分号的错误
Rem
Rem  Revision 1.4  2008/02/20 03:11:38  JY_Online
Rem  *** empty log message ***
Rem
Rem  Revision 1.3  2008/02/03 05:30:10  JY_Online
Rem  增加了一个新的分页函数
Rem
Rem  Revision 1.2  2007/08/06 09:04:03  JY_Online
Rem  更新了分页函数
Rem
Rem  Revision 1.2  2007/03/10 13:50:40  JY_Online
Rem  增加常用函数
Rem
Rem =========================================================
Rem  Function:KuaYue.com.cn　专用 JavaScript 函数集合
Rem  caution against:
Rem =========================================================
Rem  Copyright (C) 1999-2006 KuaYue.Com.cn All rights reserved.
Rem  Web: http://www.KuaYue.com.cn | www.KYit.cn
Rem		  www.iUser.cn | www.Datas.cn | idc.KuaYue.com.cn
Rem  Email: server@KuaYue.com.cn
Rem	 		mzkuayue@Gmail.com
Rem         server@KYit.cn
Rem  MSN:   mzxjx@hotmail.com
Rem =========================================================
*/
/* 重定义JavaScript的常用方法 */
function $(s){return document.getElementById(s);}
function dw(s){document.write(s);}
function $$(s){return document.frames?document.frames[s]:$(s).contentWindow;}
function $c(s){return document.createElement(s);}
function exist(s){return $(s)!=null;}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
function hide(s){$(s).style.display=$(s).style.display=="none"?"":"none";}
function swap(s,a,b,c){$(s)[a]=$(s)[a]==b?c:b;}
function isIE(){return BROWSER.indexOf('ie') > -1;}
function setCopy(_sTxt){try{clipboardData.setData('Text',_sTxt)}catch(e){}}
function OpenEditWindow(){setTimeout("window.parent.BHA_frame.cols='140,0,*'",500);}
function CloseEditWindow(){window.parent.BHA_frame.cols="140,*,0";}
function GotoNewsWindows(s){parent.Edit.location=s;OpenEditWindow();}
function Button(Str_Button_Text,Str_Window,Str_FileName,Str_Script){
	var Str_Temp="<input type=button value='"+Str_Button_Text+"' class=hand style='Width:80;' onclick=\"";
	switch(Str_Window){
		case "":
			Str_Temp+="window.location='"+Str_FileName+"';\">";
			break;
		case "New":
			Str_Temp+="parent.Edit.location='"+Str_FileName+"';OpenEditWindow();\">";
			break;
		case "Back":
			Str_Temp+="CloseEditWindow();\">";
			break;
		case "UpdateBack":
			Str_Temp+="parent.middle.location='"+Str_FileName+"';CloseEditWindow();\">";
			break;
		case "Script":
			Str_Temp+=""+Str_Script+";\">";
			break;
	}
	return Str_Temp;
}
var BROWSER = browserDetect();
function browserDetect(){
	var sUA = navigator.userAgent.toLowerCase();
	var sIE = sUA.indexOf("msie");
	var sOpera = sUA.indexOf("opera");
	var sMoz = sUA.indexOf("gecko");
	if (sOpera != -1) return "opera";
	if (sIE != -1){
		nIeVer = parseFloat(sUA.substr(sIE + 5));
		if (nIeVer >= 6) return "ie6";
		else if (nIeVer >= 5.5) return "ie55";
		else if (nIeVer >= 5 ) return "ie5";
	}
	if (sMoz != -1)	return "moz";
	return "other";
}
function resizeImg(_oObj, _iWidth){
	var tMark = true;var iWidth = 0;var sOuterHtml;var aNode = _oObj.attributes;
	for(var i = 0; i < aNode.length; i++){if(aNode[i].specified){if(aNode[i].name == "width" || aNode[i].name == "height"){tMark = false;}}}
	if(tMark){if(_iWidth){setTimeout("resize()",500);}}
	this.resize = function(){if(_oObj.width > _iWidth){_oObj.width = _iWidth;}}
}

function ObjPage(){
	/*===================================================
		' File Explain:后台使用公共页面函数
		' Parameter   :
		' Start Date  :2005-10-10
		' Update Date :2006-05-09
	===================================================*/
	this.EndFlag=0;
	this.BlnOut=true;	//默认输出方式为直接写脚本 false时为拼接字符串
	this.Web_Path="";	//站点路径
	this.Web_Name=Web_Name;	//站点名称
	this.FileName=FileName;	//分页文件名称
	this.Max_Page=Max_Page;	//最大记录数量
	this.Page=Page;			//当前页码
	this.Num_Page=Num_Page;	//分页总数，总页数

	var Web_Name="";
	var FileName="";
	var Max_Page=12;
	var Page=1;
	var Num_Page=0;

	this.SelectDel=function SelectDel(Str_File){
		question = confirm("您确定要删除此记录吗？");
		if (question != "0"){
			window.location=Str_File;
		}
	}

	this.Show_Hide=function Show_Hide(obj,obj2,str_index){
		if (this.EndFlag==0){alert("网页未下载完成,请稍候...");return;}
		if ($(obj).style.display!='block'){
			$(obj).style.display="block";
			$(obj2).src=this.Web_Path+"images/menu_open.gif";
			if($(obj2).loaded=="no"){$("TD"+obj).innerHTML="&nbsp; &nbsp; 数据下载中...&nbsp; &nbsp; ";document.frames["hiddenframe"].location.replace(str_index+"Int_Id="+obj);}
		}else{
			$(obj).style.display="none";
			$(obj2).src=this.Web_Path+"images/menu_close.gif";
		}
	}

	this.Show_Hide2=function Show_Hide2(obj,obj2){
		if ($(obj).style.display!='block'){
			$(obj).style.display="block";
			$(obj2).src=this.Web_Path+"images/menu_open.gif";
		}else{
			$(obj).style.display="none";
			$(obj2).src=this.Web_Path+"images/menu_close.gif";
		}
	}

	this.Show_Title=function Show_Title(Str_Number,Str_Text,Bln_Type,Show_Mode){
		//表格标题
		var Arr_Number=Str_Number.split(",");
		var Arr_Text=Str_Text.split(",");
		var Int_Rows=Arr_Number.length;
		if(Int_Rows!=Arr_Text.length){return;}
		if(Bln_Type){
			dw("<span id=System_Data_List><table width='98%' class=TableList align=center><tr class=tr_title>");
			for(var i=0;i<Int_Rows;i++){
				dw("<td class=td_Title noWrap width='"+Arr_Number[i]+"%'>"+Arr_Text[i]+"</td>");
			}
			if(Show_Mode==null){dw("<td class=td_Title noWrap width='20%' colspan=2>操作</td>");}
			dw("</tr>");
		}else{
			var Str_Temp="<table width='98%' class=TableList align=center><tr class=tr_title>";
			for(var i=0;i<Int_Rows;i++){
				Str_Temp+="<td class=td_Title noWrap width='"+Arr_Number[i]+"%'>"+Arr_Text[i]+"</td>";
			}
			if(Show_Mode==null){Str_Temp+="<td class=td_Title noWrap width='20%' colspan=2>操作</td>";}
			Str_Temp+="</tr>"
			return Str_Temp;
		}
	}

	this.Show_FenYe=function Show_FenYe(Bln_Span){
		dw("<table width='98%' class=tablelist><tr class=Listrow1_1><td align=left>&nbsp; ");
		this.Showpages("3366FF");
		dw("</td></tr></table>");
		if(isNull(Bln_Span))dw("</span>");
	}

	this.To_Fill=function To_Fill(Int_Rows,Int_Col){
		//补充完空白行
		var Int_Temp=this.Max_Page-Int_Rows;
		var Str_Text="";
		if(Int_Temp>=0){
			for(var i=0;i<Int_Temp;i+=1){
				Str_Text+="<tr class=Listrow1_1>";
				for(var y=0;y<Int_Col;y+=1){
					Str_Text+="<td class=td_Row></td>";
				}
				Str_Text+="</tr>";
			}
		}
		Str_Text+="</table>";
		return Str_Text;
	}

	this.MainWindows=function MainWindows(Str_Title,i,Str_Note){
		//显示大类
		dw("<div class=tab-page id=tabPage"+i+">");
		dw("	<h2 class=tab>"+Str_Title+"</h2>");
		dw("	<table style='Width:90%;height:90%;' border=0 cellpadding=0 cellspacing=0>");
		dw(Str_Note);
		dw("	</table>");
		dw("</div>");
	}
	this.MainWindows2=function MainWindows2(Str_Title,i){dw("<div class=tab-page id=tabPage"+i+"><h2 class=tab>"+Str_Title+"</h2>");}
	this.MainWindows3=function MainWindows3(){dw("</div>");}
	this.MainWindows4=function MainWindows4(Str_Form,Str_Form_Width1,Str_Form_Width2,Str_Note,Str_Form2,Str_OnChick,Bln_Disabled){
		//添加表单
		dw("<table align=center width="+Str_Form_Width1+" class=Main_windows><tr><td>"+Str_Form);
		dw("<table width="+Str_Form_Width2+" border=0 cellpadding=0 cellspacing=0 style='Margin:5px 5px 5px 5px'>");
		dw(Str_Note);
		dw("<tr height=50><td colspan=2 align=center>");
        dw(Str_Form2);
		dw("<input type=reset value=' 重 设 ' class=bha>　　<input type=submit value=' 确 定 ' class=bha");
		if(!isNull(Str_OnChick)){dw(" onclick=\""+Str_OnChick+"();\"");}
		if(!isNull(Bln_Disabled)){dw(" disabled=true");}
		dw("></td></tr></table></td></form></tr></table>");
	}

	this.Project=function Project(Str_Title,Str_Note,Bln_Type,Str_ID){
		//显示内容
		var Str_Temp="";
		var Str_Star="";
		if(!isNull(Str_ID)){Str_ID="name="+Str_ID+" id="+Str_ID+" style='DISPLAY:none'";}else{Str_ID="";}
		if(Bln_Type==1){Str_Star="(<span class=red>*</span>)";}
		Str_Temp="<tr class=InputFrameLine "+Str_ID+">"
			+"	<td class=InputLabelCell Style='width:120px;'>"+Str_Title+Str_Star+"</td>"
			+"	<td class=InputAreaCell width=*>"+Str_Note+"</td>"
			+"</tr>"
		return Str_Temp;
	}

	this.AdminForma=function AdminForma(Str_Title,Str_Message,Str_Botton,Str_Form){
		//后台管理标题栏
	    dw("<div align=left class=titlebar>"+this.Web_Name+"系统 > "+Str_Title+"</div>");
		dw("<table width='98%'class=tabletoolbar border=0 align=center>");
		dw("<tr><td><div class=TableTitleText>"+Str_Message+"</div></td>");
		if(!isNull(Str_Form)){dw(Str_Form);}
		if(!isNull(Str_Botton)){
			var Arr_Botton=Str_Botton.split(",");
			for(var i=0;i<Arr_Botton.length;i++){
				dw("<td width='10%' align=right>"+Arr_Botton[i]+"</td>");
			}
		}
		if(Str_Form!=null){dw("</form>");}
		dw("</tr></table>");
	}

	/*===================================================
		' File Explain:前台使用函数
		' Parameter   :
		' Start Date  :2006-02-15
		' Update Date :
	===================================================*/

	this.Art_Pages=function Art_Pages(Str_FileName,Max_Page,Page){
		//三个输入参数
		//Str_FileName是指文件名
		//Max_Page是指最大页数
		//Page是指当前的页数
		if(Max_Page=="1"){return "<br>";}
		var Open_Page;	//开始显示页码
		var End_Page;	//结束显示页码
		var num_display=10; //最多显示的页码
		if(Page<0){Page=1;}
		if((Page % num_display)==0){
			Open_Page=Page-num_display+1;
			End_Page=Page
		}else{
			Open_Page=Math.floor(Page/num_display)*num_display+1;
			End_Page=Math.floor(Page/num_display)*num_display+num_display;
			if(End_Page>Max_Page){
				End_Page=Max_Page;
			}
		}
		//设置输出字符串
		var KY_New_FileName=Str_FileName.substr(0,Str_FileName.indexOf("."));	//算出文件名的第一部分
		var Str_FileSuffix=Str_FileName.substr(Str_FileName.indexOf("."),Str_FileName.length);
		var Str_Temp="<EM>&nbsp;"+Max_Page+"&nbsp;</EM>";
		if(Open_Page>5){
			Str_Temp+="<a href="+Str_FileName+">1</a><a href="+KY_New_FileName+"_"+(Open_Page-1)+Str_FileSuffix+"><<</a>";
		}
		for(i=Open_Page;i<=End_Page;i++){
			if(i==Page){
				Str_Temp+="<STRONG>"+i+"</STRONG>";
			}else{
				if(i==1){
					Str_Temp+="<a href="+Str_FileName+">"+i+"</a>";
				}else{
					Str_Temp+="<a href="+KY_New_FileName+"_"+i+Str_FileSuffix+">"+i+"</a>";
				}
			}
		}
		//处理结束
		if(Page<Max_Page){Str_Temp+="<A class=next href="+KY_New_FileName+"_"+(Page+1)+Str_FileSuffix+">&#8250;&#8250;</A>";}
		if(End_Page<Max_Page){
			Str_Temp+="<a href="+KY_New_FileName+"_"+(End_Page+1)+Str_FileSuffix+" title=\"下"+num_display+"页\">>></a><a href="+KY_New_FileName+"_"+Max_Page+Str_FileSuffix+" title='到末页' class=last>"+Max_Page+"</a>";
		}
		Str_Temp+="<KBD><INPUT onkeydown=\"if(event.keyCode==13) {window.location='"+KY_New_FileName+"_'+this.value+'"+Str_FileSuffix+"'; return false;}\" size=3 name=custompage></KBD>";
		//返回字符串
		return Str_Temp;
	}

	/*===================================================
		公共函数
	===================================================*/
	this.outDate=function outDate(){
		var today=new Date(); 
		var d=new Array("日","一","二","三","四","五","六");
		var strDate="<font color=#ffffff style='font-size:9pt;font-family:宋体;'> ";
		strDate+=today.getYear()+"年";
		strDate+=(today.getMonth()+1)+"月";
		strDate+=today.getDate()+"日 ";
		strDate+="星期"+d[today.getDay()]+"</font>";
		dw(strDate);
	}

	this.Showpages=function Showpages(font_color){
		//分页代码
		//page		当前页码
		//max_page　最大页码，显示时不可能超过最大页码
		//str_index	处理分页显示的页面
		var display_font="Arial Black";		//显示用的字体
		var str_font="<font color=#"+font_color+" Style='font-size:12px;font-family:"+display_font+";'>";
		var str_font2="<font Style='font-size:12px;font-family:"+display_font+";' color=red>";
		var num_display=10;
		var i;
		var open_page;
		var top_Page;
		var str_temp;
		if(this.Page<0){this.Page=1;}
		if((this.Page % num_display)==0){
			//整除时
			top_Page=this.Page;
			open_page=Math.floor(this.Page)-num_display+1;
		}else{
			//非整除时
			open_page=Math.floor(this.Page/num_display)*num_display+1;
			top_Page=Math.floor(this.Page/num_display)*num_display+num_display;
			if(top_Page>this.Num_Page){
				top_Page=this.Num_Page;
			}
		}
		//设置输出字符串
		str_temp="<font color=#"+font_color+">分页 [ ";
		if(open_page>num_display){
			str_temp+="<a href="+this.FileName+"page=1 title='到首页'>"+str_font+"<u>1</u></font></a> ··· <a href="+this.FileName+"page="+(open_page-1)+" title=\"上"+num_display+"页\">"+str_font+"<<</font></a> ";
		}else{
			str_temp+="<a href=\"#\" title=\"刷新本页\">"+str_font+"<<</font></a> ";
		}
		for(i=open_page;i<=top_Page;i++){
			if(i==this.Page){
				str_temp+="<a href=\"#\"  title=\"刷新本页\">"+str_font2+i+"</font></a> ";
			}else{
				str_temp+="<a href="+this.FileName+"page="+i+" title='第"+i+"页'>"+str_font+"<u>"+i+"</u></font></a> ";
			}
		}
		//对页数不整齐的处理
		if((open_page+num_display-1)>top_Page){
			for(i=top_Page+1;i<=(open_page+num_display-1);i++){
				str_temp+="<a href=\"#\"  title=\"刷新本页\">"+str_font+i+"</font></a> ";
			}
		}
		//处理结束
		if(top_Page<this.Num_Page){
			str_temp+="<a href="+this.FileName+"page="+(top_Page+1)+" title=\"下"+num_display+"页\">"+str_font+">></font></a> ··· <a href="+this.FileName+"page="+this.Num_Page+" title='到末页'><u>"+str_font+this.Num_Page+"</u></font></a> ";
		}else{
			str_temp+="<a href=\"#\" title=\"刷新本页\">"+str_font+">></font></a> ";
		}
		str_temp+="]</font>";
		//返回字符串
		dw(str_temp);
	//	return str_temp;
	}

	this.StrToArr=function StrToArr(Str_Text){
		//把传入的字符串转变成数组
		var Arr_D1=Str_Text.split("|");
		var Arr_D2=eval("new Array("+Arr_D1.length+");");
		var Str_Temp="";
		var Arr_Temp;
		var Int_Rows;
		for(var i=0;i<Arr_D1.length;i++){
			Arr_Temp=Arr_D1[i].split(",");
			if(i==0){Int_Rows=Arr_Temp.length;}
			Str_Temp="";
			for(var y=0;y<Int_Rows;y++){
				if(y>0){Str_Temp+=",";}
				Str_Temp+="'"+Arr_Temp[y]+"'";
			}
			Arr_D2[i]=eval("new Array("+Str_Temp+");");
		}
		return Arr_D2;
	}

	this.StrSelectOption=function StrSelectOption(para1,IntValue){
		//把传入的字符串转变成数组
		var StrOption="";
		var isSelect="";
		var Arr_Data=this.StrToArr(para1);
		for(var j=0;j<Arr_Data.length;j++){
			if(Arr_Data[j][0]==IntValue){
				isSelect=" selected";
			}else{
				isSelect="";
			}
			StrOption+="<option value="+Arr_Data[j][0]+" "+isSelect+">"+Arr_Data[j][1]+"</option>";
		}
		return StrOption;
	}
	
	this.toScript=function toScript(val){
        val.value = "document.writeln(\""+val.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")" 
    }

	this.Show_Time=function Show_Time(Dtm_Date){
		//转换显示时间
		Dtm_Date=Dtm_Date.substr(0,Dtm_Date.indexOf(" "));
		return Dtm_Date;
	}

	this.checkall=function checkall(form, prefix, checkall){
		var checkall = checkall ? checkall : 'chkall';
		for(var i = 0; i < form.elements.length; i++) {
			var e = form.elements[i];
			if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
				e.checked = form.elements(checkall).checked;;
			}
		}
	}

	this.Show_Select=function Show_Select(Str_Selected,Str_Text,Str_SelectName,Str_Default)
	{
		//显示选项框
		var Str_Temp="<Select name="+Str_SelectName+" class=smallselect Style='Width:200px;'>";
		var Arr_Data=Str_Text.split(",");
		var Int_Rows=Arr_Data.length;
		//用户未进行选择时，使用默认值
		if(isNull(Str_Selected)){Str_Selected=Str_Default;}
		for(var i=0;i<Int_Rows;i++)
		{
			Str_Temp+="<option value='"+Arr_Data[i]+"'";
			if(Arr_Data[i]==Str_Selected){Str_Temp+=" Selected=true";}
			Str_Temp+=">"+Arr_Data[i]+"</option>";
		}
		Str_Temp+="</Select>";
		return Str_Temp;
	}
	this.AJAXSP=function AJAXSP(font_color){
		//基于AJAX技术的静态分页技术
		var display_font="Arial";
		var str_font="<font color=#"+font_color+" Style='font-size:12px;font-family:"+display_font+";'>";
		var str_font2="<font Style='font-size:12px;font-family:"+display_font+";' color=red>";
		if(this.Page<0){this.Page=1;}
		var str_temp="<font Style='font-size:12px;font-family:Arial;' color=#"+font_color+">当前第 <u><span id=ShowPageNow>"+this.Page+"</span></u> 页 [ ";
		for(var i=1;i<=this.Num_Page;i++)
		{
			str_temp+="<a href="+this.FileName+"page="+i+" title='到第"+i+"页' target=hiddenframe>"+str_font2+i+"</font></a> ";
		}
		str_temp+="]</font>";
		dw(str_temp);
	}
	this.AutoSubStr=function AutoSubStr(Str_Title,Int_FontNumber,Bln_Type)
	{
		//截取要显示的字符串
		//Bln_Type 显示方式，缺省为后面加三个点，为1时中间省略
		var Int_Rows=Str_Title.length;
		if(Int_Rows>Int_FontNumber)
		{
			if(isNull(Bln_Type))
			{
				Str_Title=Str_Title.substr(0,Int_FontNumber)+"...";
			}
			else
			{
				Str_Title=Str_Title.substr(0,(Int_FontNumber-5))+"..."+Str_Title.substr(Int_Rows-3);
			}
		}
		return Str_Title;
	}
	this.Tips=function Tips(event,thisobj,txt,Int_Width,Int_Height)
	{
		evt=event?event:window.event;
		var x=evt.clientX;
		var y=evt.clientY;
		if($("tipdiv")){document.body.removeChild($("tipdiv"));}
		if(isNull(Int_Width)){Int_Width=250;}
		if(isNull(Int_Height)){Int_Height=40;}
		var tipdiv=document.createElement("DIV");
		tipdiv.setAttribute("id","tipdiv");
		tipdiv.style.left = x + document.body.scrollLeft + "px";
		tipdiv.style.top =  y + document.body.scrollTop - 80 + "px";
		tipdiv.style.width =Int_Width+"px";
		tipdiv.style.height=Int_Height+"px";
		tipdiv.style.zIndex='15';
		tipdiv.style.position='absolute';
		tipdiv.style.textalign="left";
		document.body.appendChild(tipdiv);
		$("tipdiv").innerHTML="<div style='border:1px solid #23A3EC;padding:5px;background:#E5F2F8'>"+txt+"</div>";
		this.hide_tipdiv=function(){if($("tipdiv")!=null)document.body.removeChild($("tipdiv"));}
		if(!document.all)
		{
			window.document.addEventListener("click",this.hide_tipdiv,false);
			thisobj.addEventListener("mouseout",this.hide_tipdiv,false);
		}else{
			window.document.attachEvent("onclick",this.hide_tipdiv);
			thisobj.attachEvent("onmouseout",this.hide_tipdiv);
		}
	}
}
