// 客户端网页用JS函数
//setTimeout("write_htm()",1000); //毫秒  延时调用程序
//<body onload="onload_function()">当页面完成后就执行指定的js function
//全局变量，确定窗口是程序

//var browser=get_brower();
//将相关指定元素内的所有图片调整到指定的大小,参数说明obj_name：元素名称,width：调整指定的宽度

//检测客户端的方式;
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

//将PNG图片转换成透明方式
function fixPNG(img,width,height){
	//alert(myImage.width);
	//return;
if (version >= 5.5) 
{
	var imgID = (img.id) ? "id='" + img.id + "' " : "";
	var imgClass = (img.className) ? "class='" + img.className + "' " : "";
	var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
	var imgStyle = "display:inline-block;" ;
	if (img.style.cssText!="") imgStyle =imgStyle + img.style.cssText + ";";
	if (img.align == "left") imgStyle = "float:left;" + imgStyle;
	if (img.align == "right") imgStyle = "float:right;" + imgStyle;
	if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
	var strNewHTML = "<span " + imgID + imgClass + imgTitle	+ " style=\"" + "width:" + width + "px; height:" + height + "px; " + imgStyle+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+ "(src=\'" + img.src + "\', sizingMethod='scale');\">"
	img.outerHTML = strNewHTML;
//alert(img.style.cssText);
}
}


function picSizeFixer(obj_name,widths)
{
  var doc=document.getElementById(obj_name).getElementsByTagName("img");
  for (i=0;i<doc.length;i++){
    if (doc[i].width>widths){
      doc[i].width=widths;
      var imgLink=doc[i].src;
      if (navigator.appName=="Microsoft Internet Explorer"){
        doc[i].setAttribute("alt","点击查看原图");
        doc[i].onclick=function(){window.open(this.src);}
        doc[i].onmouseover=function(){this.style.cursor="hand";}  }
      else {  doc[i].setAttribute("onclick",'window.open("'+imgLink+'","")');  } } }
  }

function get_brower()
{
	var dom = document.getElementById ? true:false;
	var nn4 = document.layers ? true:false;
	var ie4 = document.all ? true:false;
	if (ie4){return "ie";}else{if (nn4){return "nn";}else{if (dom){return "dom";}else{return "";}}}
}

//取得对象的二维座标：左上角X/Y座标，右下角X/Y座标
function get_obj_stat(obj,stat)
{
	var obj_top,obj_left,obj_w,obj_h,body_top,body_left,scr_top,scr_left;
	with(obj)	{obj_top=getBoundingClientRect().top;obj_left=getBoundingClientRect().left;obj_w=clientWidth;obj_h=clientHeight;}
	with(document.body)	{body_top=getBoundingClientRect().top;body_left=getBoundingClientRect().left;scr_top=scrollTop;scr_left=scrollLeft;}
	//alert(body_left);
	switch(stat)
	{
	case "Width":
		return obj_w;
	case "Height":	
		return obj_h;
	case "left_X":
		return obj_left-body_left+scr_left;
	case "left_Y":	
		return obj_top;//+scr_top;
	case "right_X":
		return obj_left+obj_w;//+scr_left;
	case "right_Y":	
		return obj_top+obj_h;//+scr_top;
	}
}
//将复制一个对象的位置及大小给另外一个对象 
function cp_obj_stat(s_obj,d_obj,d_obj_type)
{
	var tops,lefts,widths,heights,str;
	//alert("");
	tops=s_obj.getBoundingClientRect().top;
	lefts=s_obj.getBoundingClientRect().left;
	widths=s_obj.clientWidth;
	heights=s_obj.clientHeight;
	
	switch(d_obj_type)
	{
		case "style":
			d_obj.style.pixelHeight=heights;
			d_obj.style.pixelWidth=widths;
			d_obj.style.pixelLeft=lefts;
			d_obj.style.pixelTop=tops;
		default:
			//alert(d_obj.clientWidth);
			//d_obj.getBoundingClientRect().top=s_obj.getBoundingClientRect().top;
			//d_obj.getBoundingClientRect().left=s_obj.getBoundingClientRect().left;
			d_obj.width=widths;
			d_obj.height=heights;
	}
}

//以name内容取得对象
function get_obj(name,types)
{  	switch(types)
	{	case "top":
			return window.top.document.getElementById(name);
		case "opener":
			return window.opener.document.getElementById(name);
		default :
			return window.document.getElementById(name); }
			
}
//更换object内style对象内容
function set_style_cont(object,contents,types)
{
   if (object.style==null) {return ;}
   if (contents!=""){ 
       with (object.style){
		switch (types)	  
		{
		 case "left":
				pixelLeft=contents;break;
		 case "height":
				pixelHeight=contents;break;
		 case "top":
				pixelTop=contents;break;
		 case "border":
				pixelWidth=contents;break;
		 default:
		 		return;		
		}}}
}



//变更选择状态图形（选择与未选择）
//效果图片sel_img/no_img，img_types为"select"/"no",type为"bg"/"img"
function change_img(obj,sel_img,no_img,img_types,types)
{
	var img,t;
		if (obj==null){return;}					//对象不存在时不执行程序
		//以上功能等同 :if (document.all.item(objname)==null) {return;} 
		switch (types)	  
		{case "select":
		    	img=sel_img;break;
		 case "no":
		 		img=no_img;break;
		 default:
		    	img=no_img;break;
		}
		switch (img_types)	  
		{case "bg":
		    	obj.background=img;break;
		 case "img":
		 		obj.src=img;break;
		 default:
		    	obj.src=img;break;
		}
		//alert(no_img);
}

//取得styleSheet_obj指定名称rules_name所在的位置号
function get_styleSheet_rules_num(styleSheet_obj,rules_name)
{
	var sr,num;
	num=-1
	if(!styleSheet_obj){return num;}
	for (sr=0 ; sr < styleSheet_obj.rules.length; sr++) { if (styleSheet_obj.rules(sr).selectorText == rules_name) { num=sr;} } 
	return num;
}
//向指定页面提交内容
function submit_data(frame_name,form,url)
{
	form.action=url;	form.target=frame_name;	//form.submit();
	//alert(url);
}

//打开新窗口
function open_sizewin(url,width,height,state)
{	
	if(state=="new"){window.open(url,"_blank","fullscreen=0,status=no,scrollbars=1,resizable=1,width="+width+",height="+height+"");}
	else{window.resizeTo(width,height);}
}

//跳转网页
function go_url(url,types) 
{
	if (url!="")
	{
		if (types=="opener")	{window.opener.location.href=url;return;}
		if (types=="top")		{window.top.location.href=url;return;}
		if (types=="")			{window.location.href=url;return;}
		if (types=="new")		{window.open(url);return;}
	}
}

//检测所指定的内容是否合符长度限制及格式是否正确 *注：需与js_func.js内的函数
function alert_str(obj,obj_name,types,mixlen,maxlen)
{
	var chk;
	chk=chk_obj(obj.value,types,mixlen,maxlen);
	if (chk!="")
	{ alert(obj_name+chk); obj.focus(); return false;	}
	else{return true;}
}

//检测str所在OBJS（options选项）的位置,lstat为-1时，值相等时设置;为>-1时，包含位置小于或等于值时设置
function setselect(objs,str,lstat)
{
	var num=0,i,len;
		if (!objs){return false};
		//alert();
		len=objs.options.length;
		if (len<1){return false;}
		for (i=0;i < len; i++)
		{
			if((lstat==-1)&&(objs.options[i].value == str))
			{num=i;	break;}
			if((lstat>0)&&(objs.options[i].value.indexOf(str)<=lstat))
			{num=i;	break;} 
		};
		objs.options[num].selected=true;
		return true;
}


//返回上下页num
function creat_page_url(total,pagesize,pagenum,state)
{
	var all_pagenum,last_num;
	all_pagenum=all_page_num(total,pagesize);
	if (pagenum=="") {return 1;}
	if (pagenum<1) {return 1;}
	if (pagenum>all_pagenum){return all_pagenum;}
	//alert(pagenum);
	//return "";
	switch (state)	  
	{
	 case "first":
		return 1;
	 case "last":
		return all_pagenum;
	 case "next":
		if (pagenum<all_pagenum) {return pagenum+1;}else{return all_pagenum;} 	
	 case "pre": 
		if (pagenum>1) { return pagenum-1;}else{return 1;} 
	 default :
	 	if (isUnsignedInteger(state)){return state;}
		else{return 1};
	 }
}

//上下翻页
function go_page(total,pagsize,pagenum,state,url,from_name){	var forms,pagenums=creat_page_url(total,pagsize,pagenum,state);	if (pagenums==""){pagenums=1};forms=get_obj(from_name,"top");forms.page_num.value=pagenums;if(url!=""){forms.action=url};forms.submit();}	
//确认提示
function checkclick(msg){if(confirm(msg)){event.returnValue=true;}else{event.returnValue=false;}return event.returnValue;}

function is_ok(str){	exp=/[^0-9a-zA-Z_]/g;	if(str.search(exp) != -1)	{return false;	}	return true;}
function is_zw(str){	exp=/[0-9a-zA-Z_]/g;	if(str.search(exp) != -1)	{return false;	}	return true;}
function is_number(str){	exp=/[^0-9()-]/g;	if(str.search(exp) != -1)	{return false;	}	return true;}
function is_code(str){	exp=/[^0-9]/g;	if(str.search(exp) != -1)	{return false;	}	return true;}
function msg_chk(o_str,names){	var str=o_str;	if(str.length>0) {alert("["+names+"]"+str); return false;}	else{return true;}	}
function countDown(secs,obj){obj.innerText=secs;if(--secs>0) setTimeout("countDown("+secs+")",1000);}

function today_hello()
{
var noon; 
var time=new Date();
var hour=time.getHours(); 
var minute=time.getMinutes();
var today=new Date;
var week=new Array(7);
week[0]="天";
week[1]="一";
week[2]="二"; 
week[3]="三";
week[4]="四";
week[5]="五";
week[6]="六";
if (hour<5) noon="凌晨"; 
if (hour>4 & hour<8) noon="早上";
if (hour>7 & hour<12) noon="上午";
if (hour==12) noon="中午";
if (hour>12 & hour<19) noon="下午";
if (hour>18 & hour<23) noon="晚上";
if (hour>22) noon="深夜"; 
if (hour>12) hour=hour-12;
if (hour<10) hour="0"+hour;
if (minute<10) minute="0"+minute;
document.write( today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 星期"+week[today.getDay()]+" "+noon+"好! ");
}
//点击显示对象（显示/隐藏）
function click_display(obj)
{
	if( obj.style.display=="") {obj.style.display="none"}
	else{obj.style.display=""}

}

function url_left_str(str,cstrs)
{
	
	var sts=str+"";
	var cstr=cstrs+"";
	//alert(cstr);
	//alert(sts);
	var num=sts.length;
	var num1=cstr.length;
	if ((num<num1) || (num<0)){return str;}
	
	num=sts.indexOf(cstr);
	if (num<0){return str;}
	sts=sts.substring(0,num)
	return sts
}
//将str截取substrs前的字符串
function str_substring(str,substrs)
{
	var s=str;
	var num=s.indexOf(substrs);
	//alert(s.substring(0,num-1));
	if(num>1) {return s.substring(0,num);}else{return s;}
}
//将str从substrs开始截取之后的字符串
function rstr_substring(str,substrs)
{
	var s=str;
	var num=s.indexOf(substrs);
	//alert(s.substring(0,num-1));
	if(num>1) {return s.substring(num,s.length);}else{return s;}
}
//删除无效参数“&_varnot_=1”尾随内容后，刷新网页
function go_reload(type)
{
	//alert();
	var s="&_varnot_=1";
	var s1="#";
	var s2='';
	if(type=="location"){location.href=url_left_str(str_substring(location.href,s1),s) ;}
	else if(type=="top"){top.location.href=url_left_str(str_substring(top.location.href,s1),s);}
	else if(type=="opener"){opener.location.href=url_left_str(str_substring(opener.location.href,s1),s);}
	else if(type==""){window.top.location.href=url_left_str(str_substring(window.top.location.href,s1),s);}
	else{location.href=url_left_str(str_substring(location.href,s1),s)+type;}
}
//增加page的OPtion,50页内全显示，否则显示前后25页
function addpageOPtion(obj,thisnum,maxnum)
{
	var endnum=0;
	var startnum=maxnum;
	if (maxnum>50){
	startnum=thisnum-25;
	if(startnum<1){startnum=1}
	endnum=thisnum+50-startnum;
	if(endnum>maxnum){endnum=maxnum}
	}
	for(var  i=startnum-1;i<endnum;i++){
		var  n1=opener.document.createElement("OPTION")  
		n1,value=i; 
		n1.text=i+"";  
		obj.add(n1)  }  
}

//取对象所在位置
function get_obj_sate(obj,type)
{
	var length;
	switch (type)
		{
		case "left"://对象在窗口上左起始位置
			length=obj.getBoundingClientRect().left+window.top.document.body.scrollLeft+obj.clientWidth;
			break;
		case "top"://对象在窗口上起始位置
			length=obj.getBoundingClientRect().top+window.top.document.body.scrollTop
			break;
		case "width"://对象长度
			length=obj.clientWidth;
			break;
		case "height"://对象高度
			length=obj.clientHeight;
			break;
		default: //其它情况
			length=0;
			break;
		}
	return length;
}