﻿// JavaScript Document
function SetClass(Obj,Class){
	if(Obj!=null){
		Obj.className=Class;
	}
}



function CheckEmail(value){
	var reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;//验证Mail的正则表达式,^[a-zA-Z0-9_-]:开头必须为字母,下划线,数字,
	if(value.match(reg)!=null){
			return true;
	}else{
			return false;
	}
}

function IsEn(value){
	if(value.match(/[\W]/g)!=null || value.trim()==''){
		return false;
	}else{
		return true;
	}
}


//
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}

function QueryString(item)
{ 
       var sValue=location.search.match(new RegExp("[?&]"+item+"=([^&]*)(&?)","i")) 
       return sValue?sValue[1]:sValue 
}

function regok(id){
    document.all.returnBox.innerHTML="<img src='images/pros1.gif' style='padding-left:10px;'>";
     var ajax=new AJAXRequest("utf-8");
    ajax.post("RegisterOk.aspx",id,function(obj){document.all.returnBox.innerHTML=obj.responseText;});
}


function isNumber(oNum)
   {
  if(!oNum) return false;
  var strP=/^\d+(\.\d+)?$/;
  if(!strP.test(oNum)) return false;
  try{
  if(parseFloat(oNum)!=oNum) return false;
  }
  catch(ex)
  {
   return false;
  }
  return true;
   } 

function GetEle(id){	if(document.getElementById)	{	return document.getElementById(id);	}	else if(document.all)	{	return document.all[id];	}	else if(document.layers)	{	return document.layers[id];	}} function ChkDateTime(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})( (\d{1,2}):(\d{1,2}):(\d{1,2}))?$/; 
   var r = str.match(reg); 
   if(r==null)return false; 
   return true;
} 

function CheckAddNews(form){
	var s=false;
	if(GBLength(form.title.value.trim())<1 || GBLength(form.title.value.trim())>200){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>文章标题长度必须在1-200个字符以内，当前长度为："+GBLength(form.title.value.trim()));
        return false;
	}
	
	if(form.title2!=null){
	    if(GBLength(form.title2.value.trim())>200){
		    ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>文章副题长度必须在0-100个字符以内，当前长度为："+GBLength(form.title2.value.trim()));
            return false;
	    }
	}
	
	if(!ChkDateTime(form.otime.value)){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>发布日期必须为有效的日期格式，如2008-1-1 8:58:58");;
	    return false;
	}
	
	if(GBLength(form.source.value.trim())>50){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>文章来源必须在0-50个字符以内，当前长度为："+GBLength(form.source.value.trim()));
        return false;
	}

	
	if(GBLength(form.author.value.trim())>20){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>文章来源必须在0-20个字符以内，当前长度为："+GBLength(form.author.value.trim()));
        return false;
	}
	
	if(GBLength(form.keyword.value.trim())>200){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>推广关键字必须在0-200个字符以内，当前长度为："+GBLength(form.keyword.value.trim()));
        return false;
	}
	
	var cont='';
    var obj=window.frames["Dvbbs_Composition"];
    cont=obj.document.body.innerHTML;
    
    if(GBLength(cont.trim())<1 || GBLength(cont.trim())>100000){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>文章内容长度必须在1-100000个字符以内，当前长度为："+GBLength(cont.trim()));
        return false;
	}
	return true;
}


function CheckAddDoctor(form){
	var s=false;
	if(form.uName.value.trim()==''){
		ShowMsg("<img src='http://"+SiteUrl+"/images/msg.gif' style='padding-left:10px;'>医师名称不能为空！");
        return false;
	}
	
	return true;
}



function ChangeImage(obj){
    GetEle('Imgshowbox').src=obj;
}

function Up(){
    var obj=GetEle('NvBox1');
    obj.scrollTop=obj.scrollTop-79;
}

function Down(){
    var obj=GetEle('NvBox1');
    obj.scrollTop=obj.scrollTop+79;
}

var tmpvalue=0;
function NumPress(obj){
    if (event.keyCode<45 || event.keyCode > 57){event.returnValue = false;}
}

function NumFocus(obj){
    tmpvalue=obj.value;
    obj.select();
}

function NumBlur(obj){
    if(obj.value=='' || isNaN(obj.value)){
        obj.value=tmpvalue;
    }
}

function DisplayReplyNote(id){
    var obj=GetEle('Reply'+id);
    if(obj!=null){
        if(obj.parentNode.style.display=='none'){
            obj.parentNode.style.display='';
        }else{
            obj.parentNode.style.display='none';
        }
    }
    if(parent.dyniframesize!=null){
        parent.dyniframesize('notebook');
    }
}




 function SelectNewsCheck(){        
      if (event.keyCode == 13 && event.ctrlKey) 
        { 
          var eles=document.getElementsByTagName("input")
              for(var i=0;i<eles.length;i++){
            if(eles[i].type=='checkbox'){
                eles[i].checked=true;
            }
          } 
          event.returnValue=false;   
          return   false;   
        } 
   
  }
  
  
 function ToSelectCheck(bol){        
          var eles=document.getElementsByTagName("input")
              for(var i=0;i<eles.length;i++){
            if(eles[i].type=='checkbox'){
                eles[i].checked=bol;
            }
          }   
  }
  
 function ChangePayMethod(si){
    for(var i=1;i<5;i++){
        if(i==si){
            GetEle("pay_hide"+i).style.display='';
        }else{
            GetEle("pay_hide"+i).style.display='none';
        }
    }
 }    

  /*用相对不规则的字符串来创建日期对象,不规则的含义为:顺序包含年月日三个数值串,有间隔*/   
  String.prototype.createDate   =   function(){   
  var   reg   =   /^\D*(\d{2,4})\D+(\d{1,2})\D+(\d{1,2})\D*$/;   
  var   str   =   this.replace(/\s/g,"");   
  str   =   str.replace(reg,"$1/$2/$3");   
  var   date   =   new   Date(str);   
  if(isNaN(date)) return   new   Date();   
  else   return   date;   
  }   
    
  /*   
    *   功能:根据输入表达式返回日期字符串   
    *   参数:dateFmt:字符串,由以下结构组成           
    *             yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,   
    *             mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.   
    *             isFmtWithZero   :   是否用0进行格式化,true   or   false   
  */   
  Date.prototype.parseString   =   function(dateFmt,isFmtWithZero){   
  dateFmt   =   (dateFmt   ==   null?"yy-mm-dd"   :   dateFmt);   
  isFmtWithZero   =   (isFmtWithZero   ==   null?true   :   isFmtWithZero);   
  if(typeof(dateFmt)   !=   "string"   )   
  throw   (new   Error(-1,   'parseString()方法需要字符串类型参数!'));   
  var   weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],   
      ["SUN","MON","TUR","WED","THU","FRI","SAT"]];   
  var   monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];   
  var   str=dateFmt;   
  str   =   str.replace(/yy/g,this.getFullYear());   
  str   =   str.replace(/YY/g,this.getYear());   
  str   =   str.replace(/mm/g,(this.getMonth()+1).toString().fmtWithZero(isFmtWithZero));   
  str   =   str.replace(/MM/g,monthArr[this.getMonth()]);   
  str   =   str.replace(/dd/g,this.getDate().toString().fmtWithZero(isFmtWithZero));   
  str   =   str.replace(/hh/g,this.getHours().toString().fmtWithZero(isFmtWithZero));   
  str   =   str.replace(/mi/g,this.getMinutes().toString().fmtWithZero(isFmtWithZero));   
  str   =   str.replace(/ss/g,this.getSeconds().toString().fmtWithZero(isFmtWithZero));   
  str   =   str.replace(/ms/g,this.getMilliseconds().toString().fmtWithZeroD(isFmtWithZero));   
  str   =   str.replace(/we/g,weekArr[0][this.getDay()]);   
  str   =   str.replace(/WE/g,weekArr[1][this.getDay()]);   
  return   str;   
  }   
  /*将一位数字格式化成两位,如:   9   to   09*/   
  String.prototype.fmtWithZero   =   function(isFmtWithZero){   
  if(isFmtWithZero)   
  return   (this<10?"0"+this:this);   
  else   return   this;   
  }   
  String.prototype.fmtWithZeroD   =   function(isFmtWithZero){   
  if(isFmtWithZero)   
  return   (this<10?"00"+this:(this<100?"0"+this:this));   
  else   return   this;   
  }   
    
  /*   功能   :   返回与某日期相距N天(N个24小时)的日期   
    *   参数   :   num   number类型   可以为正负整数或者浮点数,默认为1;   
    *                 type   0(秒)   or   1(天),默认为秒   
    *   返回   :   新的PowerDate类型   
    */   
  Date.prototype.dateAfter=function(num,type){   
  num   =   (num   ==   null?1:num);   
  if(typeof(num)!="number")   throw   new   Error(-1,"dateAfterDays(num,type)的num参数为数值类型.");   
  type   =   (type==null?0:type);   
  var   arr   =   [1000,86400000];   
  var   dd   =   this.valueOf();   
  dd   +=   num*arr[type];   
  return   new   Date(dd);   
  }   
    
  //判断是否是闰年,返回true   或者   false   
  Date.prototype.isLeapYear   =   function   (){   
  var   year   =   this.getFullYear();   
  return   (0==year%4   &&   ((year   %   100   !=   0)||(year   %   400   ==   0)));   
  }   
    
  //返回该月天数   
  Date.prototype.getDaysOfMonth   =   function   (){   
  return   (new   Date(this.getFullYear(),this.getMonth()+1,0)).getDate();   
  }   
    
  //转换成大写日期(中文)   
  Date.prototype.getChinaDate   =     function(){   
  var   year   =   this.getFullYear().toString();   
  var   month=   this.getMonth()+1;   
  var   day   =   this.getDate();   
  var   arrNum   =   ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];   
  var   strTmp="";   
  for(var   i=0,j=year.length;i<j;i++){   
  strTmp   +=   arrNum[year.charAt(i)];   
  }   
  strTmp   +=   "年";   
  strTmp   +=   arrNum[month]+"月";   
  if(day<10)   
  strTmp   +=   arrNum[day];   
  else   if   (day   <20)   
  strTmp   +=   "十"+arrNum[day-10];   
  else   if   (day   <30   )   
  strTmp   +=   "二十"+arrNum[day-20];   
  else     
  strTmp   +=   "三十"+arrNum[day-30];   
  strTmp   +=   "日";   
  return   strTmp;   
  }   
  //日期比较函数,参数date:为Date类型,如this日期晚于参数:1,相等:0   早于:   -1   
  Date.prototype.dateCompare   =   function(date){   
  if(typeof(date)   !=   "object"   ||   !(/Date/.test(date.constructor)))   
    throw   new   Error(-1,"dateCompare(date)的date参数为Date类型.");   
  var   d   =   this.getTime()   -   date.getTime();   
  return   d>0?1:(d==0?0:-1);   
  }   
    
  /*功能:返回两日期之差   
    *参数:pd       PowerDate对象   
    *         type:   返回类别标识.yy:年,mm:月,ww:周,dd:日,hh:小时,mi:分,ss:秒,ms:毫秒   
    *         intOrFloat   :返回整型还是浮点型值   0:整型,不等于0:浮点型   
    *         output   :   输出提示,如:时间差为#周!   
    */   
  Date.prototype.calDateDistance   =   function   (date,type,intOrFloat,output){   
  if(typeof(date)   !=   "object"   ||   !(/Date/.test(date.constructor)))   
    throw   new   Error(-1,"calDateDistance(date,type,intOrFloat)的date参数为Date类型.");   
  type   =   (type==null?'dd':type);   
  if(!((new   RegExp(type+",","g")).test("yy,mm,ww,dd,hh,mi,ss,ms,")))   
    throw   new   Error(-1,"calDateDistance(pd,type,intOrFloat,output)的type参数为非法.");   
  var   iof   =   (intOrFloat==null?0:intOrFloat);   
  var   miSecMain   =   this.valueOf();   
  var   miSecSub     =   date.valueOf();   
  var   num=0;   
  switch(type){   
  case   "yy":   num   =   this.getFullYear()   -   pd.getFullYear();   break;   
  case   "mm":   num   =   (this.getFullYear()   -   pd.getFullYear())*12+this.getMonth()-pd.getMonth();   break;   
  case   "ww":   num   =   ((miSecMain-miSecSub)/7/86400000).fmtRtnVal(iof);   break;   
  case   "dd":   num   =   ((miSecMain-miSecSub)/86400000).fmtRtnVal(iof);   break;   
  case   "hh":   num   =   ((miSecMain-miSecSub)/3600000).fmtRtnVal(iof);   break;   
  case   "mi":   num   =   ((miSecMain-miSecSub)/60000).fmtRtnVal(iof);   break;   
  case   "ss":   num   =   ((miSecMain-miSecSub)/1000).fmtRtnVal(iof);   break;   
  case   "ms":   num   =   (miSecMain-miSecSub);break;   
  default:     break;   
  }   
  if(output)   
  return   output.replace(/#/g,num);   
  else   return   num;   
  }   
  //返回整数或者两位小数的浮点数   
  Number.prototype.fmtRtnVal   =   function   (intOrFloat){   
 // return   (intOrFloat   ==   0   ?   Math.floor(this)   :   parseInt(this*100)/100);  
  return   (intOrFloat   ==   0   ?   Math.floor(this)   :   parseInt(this*10000)/10000);    
  }   
  
  
  function ShowAfterDiff(sdate,obj){
     var   date   =   sdate.createDate();   
      var s=date.calDateDistance(new Date(),"dd",1,"#");
      var d=s.substring(0,s.indexOf('.'))
      var th=(s.substring(s.indexOf('.')+1)*0.0024)+'';
      var h=th.substring(0,th.indexOf('.'));
      var m=parseInt(('0.'+th.substring(th.indexOf('.')+1))*60);
      eval(obj).innerHTML= ('限时特价，仅剩：<span class="info2">'+d+'</span>天，<span class="info2">'+h+'</span>小时')

      window.setTimeout("ShowAfterDiff('"+sdate+"','"+obj+"')",2000);
  }
  
  
 function ShowNewsComments(id,type){
    window.open("ShowNewsComments.aspx?ID="+ id +"&type="+type,"_blank","scrollbars=1,width=550,height=460,left=250,top=70");
 }
 
 
 function Ask(Msg){
    return confirm(Msg);
 }
 
 function loadimage(){
            var now = new Date();
            if(arguments.length==0){
	            document.getElementById("vcimage").src = "HImage.aspx?t="+now.toLocaleString();
	        }else{
	            arguments[0].src = "HImage.aspx?t="+now.toLocaleString();
	        }
}



function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');  

}

var popUpWin=0;
function popUpWindow(URLStr,width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+(window.screen.width/2-width/2)+', top='+(window.screen.height/2-height/2)+',screenX='+(window.screen.width/2-width/2)+',screenY='+(window.screen.height/2-height/2)+'');  

}

