﻿

function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}
function getA(o,name){
	return o.getAttribute(name);
}
function $(o){
   var elements = new Array();
   for(var i = 0; i < arguments.length; i ++ ){
      var element = arguments[i];
      if(typeof element == 'string')element = document.getElementById(element);
      if(arguments.length == 1)return element;
      elements.push(element)
   };
   return elements
}
function elemShow(o){
	$(o).style.display = "";
}
function elemClose(o){
	$(o).style.display = "none";
}
function setCs(o,value){
	o = $(o);
	for(var i=0;i<o.options.length;i++){
		if(o.options[i].text == value){
			o.options[i].selected = true;
		}
	}
}
//设置radio，checkbox对象的值
function setR(name,value){
	value = value + "";
	var vs = value.split(",");
	var objs = document.getElementsByName(name);
	for(var i=0;i<vs.length;i++){
		for(var j=0;j<objs.length;j++){
			if(vs[i]==objs[j].value){
				objs[j].checked = true;
			}
		}
	}
};
function getC(o){
	o = $(o);
	var j=0;
	var val = "";
	for(var i=0;i<o.options.length;i++){
		if(o.options[i].selected){
			if(j==0){
				val = o.options[i].value;
			}else{
				val += "," + o.options[i].value;
			}
			j++;
		}
	}
	return val;
}
function SubString(title,len,sp){
	if(title.length>len){
		return title.substring(0,len)+sp;
	}
	return title;
}
function getR(o){
	var val = "";
	o = document.getElementsByName(o);
	var j=0;
	for(var i=0;i<o.length;i++){
		if(o[i].checked){
			if(j==0){
				val = o[i].value;
			}else{
				val += "," + o[i].value;
			}
			j++;
		}
	}
	return val;
}
function removeElem(element){
	if(element){
		element.parentNode.removeChild(element);
	}
}
function tabit(name,id,total){
	for(var i=0;i<total;i++){
		if(i==id)continue;
		$(name+"_btn"+i).className = "tab_off";
		elemClose(name+"_div"+i);
	}
	$(name+"_btn"+id).className = "tab_on";
	elemShow(name+"_div"+id);
}
function tabit2(name,id,total){
	for(var i=0;i<total;i++){
		if(i==id)continue;
		elemClose(name+"_div"+i);
	}
	elemShow(name+"_div"+id);
}
function openWindow(url,title,width,height){
	var top =300;
	var left = 150;
	if(window.screen){
    	top = (window.screen.width - width)/2;
		left = (window.screen.height - height)/2;
	}
	window.open(url,title,'height='+height+',width='+width+',top='+top+',left='+left+',toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no'); 
} 

function dyniframesize(iframename) {
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight=getFFVersion>=0.1? 16 : 0 
	var pTar = null;
   if (document.getElementById){
     pTar = document.getElementById(iframename);
   }
   else{
     eval('pTar = ' + iframename + ';');
   }
   if (pTar && !window.opera){
     //begin resizing iframe
     pTar.style.display="block"
    
     if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
       //ns6 syntax
       pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight; 
     }
     else if (pTar.Document && pTar.Document.body.scrollHeight){
       //ie5+ syntax
       pTar.height = pTar.Document.body.scrollHeight;
     }
   }
}
function checkAll(val){
    var objs = document.getElementsByTagName("input");
    for(var i=0;i<objs.length;i++){
        if(objs[i].type=="checkbox"){
            objs[i].checked = val;
        }
    }
}
function writeCookie(name, value, m){
  var expire = "";
  if(m != null){
    expire = new Date((new Date()).getTime() + m * 60000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.domain = "uldc.cn";
  document.cookie = name + "=" + escape(value) + expire;
}
function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0){ 
    offset = document.cookie.indexOf(search);
    if (offset != -1){ 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function ShowWelCome()
{
	now = new Date(),hour = now.getHours() 
	if (hour <11){document.write("上午好！")} 
	else if (hour <14){document.write("中午好！")} 
	else if (hour <18){document.write("下午好！")} 
	else if (hour <24){document.write("晚上好！")} 
}
function ShowDate(){
	var day="";
	var month="";
	var ampm="";
	var ampmhour="";
	var myweekday="";
	var year="";
	mydate=new Date();
	myweekday=mydate.getDay();
	mymonth=mydate.getMonth()+1;
	myday= mydate.getDate();
	myyear= mydate.getYear();
	year=(myyear > 200) ? myyear : 1900 + myyear;
	if(myweekday == 0)
	weekday=" 星期日 ";
	else if(myweekday == 1)
	weekday=" 星期一 ";
	else if(myweekday == 2)
	weekday=" 星期二 ";
	else if(myweekday == 3)
	weekday=" 星期三 ";
	else if(myweekday == 4)
	weekday=" 星期四 ";
	else if(myweekday == 5)
	weekday=" 星期五 ";
	else if(myweekday == 6)
	weekday=" 星期六 ";
	document.write(year+"年"+mymonth+"月"+myday+"日 "+weekday);
}


function verifyCompatibleBrowser(){ 
	this.ver=navigator.appVersion ;
	this.dom=document.getElementById?1:0 ;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
	this.ie4=(document.all && !this.dom)?1:0; 
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0; 
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) ;
	return this ;
} 
var bw=new verifyCompatibleBrowser() 
function ConstructObject(box,ob){
	var self = this;
	this.speed = 50;
	this.loop = null;
	this.timer = null;
	this.init = function(obj,nest){
		var me = this;
		nest=(!nest) ? '':'document.'+nest+'.' ;
		this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
		this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
		this.scrollWidth=bw.ns4?this.css.document.width:this.el.offsetWidth ;
		this.clipWidth=bw.ns4?this.css.clip.width:this.el.offsetWidth ;
		this.MoveArea=function(x,y){
			me.x=x;me.y=y;
			me.css.left=me.x+"px";
			me.css.top=me.y+"px";
		}; 
		this.up=function(move){
			if(this.x<0){ 
				me.MoveArea(this.x-move,0) 
				if(self.loop){
					self.timer = setTimeout(this.obj+".up("+move+")",self.speed);
				}
			} 
		};
		this.down=function(move){
			if(me.x>-me.scrollWidth+self.objContainer.clipWidth){ 
				me.MoveArea(me.x-move,0) ;
				if(self.loop){
					self.timer = setTimeout(me.obj+".down("+move+")",self.speed)
				} 
			} 
		}; 
		this.x;
		this.y; 
		this.obj = obj + "Object" ;
		eval(this.obj + "=this") ;
	};
	this.objContainer = new this.init(box);
	this.objScroller = new this.init(ob,box);
	this.objScroller.MoveArea(0,0);
	this.objContainer.css.visibility='visible';
	this.initialised=true; 
	this.PerformScroll = function(speed){ 
		if(self.initialised){ 
			self.loop=true; 
			if(speed>0){
				self.objScroller.down(speed);
			} else {
				self.objScroller.up(speed) 
			}
		} 
	};
	this.CeaseScroll = function(){ 
		self.loop=false ;
		if(self.timer){
			clearTimeout(self.timer) 
		}
	};
}

function getViewportInfo() {
	var w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;    
	var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;     
	return {w:w,h:h}; 
}
function elemToCenter(elem){
	elem = $(elem);
	var viewport = getViewportInfo();
	var position = getPosition(elem);
	elem.style.top = (viewport.h-position.offsetHeight)/2+document.documentElement.scrollTop+'px';
	elem.style.left = (viewport.w-position.offsetWidth)/2+document.documentElement.scrollLeft+'px';
}
function getPosition(element) {
	var offsetTop = element.offsetTop; 
	var offsetLeft = element.offsetLeft; 
	var offsetWidth = element.offsetWidth; 
	var offsetHeight = element.offsetHeight; 
	while( element = element.offsetParent ) { 
		offsetTop += element.offsetTop;
		offsetLeft += element.offsetLeft; 
	} 
   	return { absoluteTop: offsetTop, absoluteLeft: offsetLeft, offsetWidth: offsetWidth, offsetHeight: offsetHeight }; 
}
var xheight = 0;
function resetHeight(){
	if($("bright").offsetHeight>$("bleft").offsetHeight){
		$("lheight").style.height = $("lheight").offsetHeight+$("bright").offsetHeight-$("bleft").offsetHeight+"px";
	}else {
		$("rheight").style.height = $("rheight").offsetHeight+$("bleft").offsetHeight-$("bright").offsetHeight+"px";
	}
}
function addDay(str,num){   
  var d = new Date(str);   
  d.setDate(d.getDate()+num);   
  return  d.getFullYear() + "-" +("0"+(1+d.getMonth())).slice(-2) +"-"+("0"+d.getDate()).slice(-2);   
}

//重置对象大小
function reSize(obj,maxWidth,maxHeight){
	var sw = obj.width;
	var sh = obj.height;
	var mw = maxWidth;
	var mh = maxHeight;
	if ( sw < mw && sh < mh ){
		w = sw;
		h = sh;
	}else if ( (sw/sh) > (mw/mh) ){
		w = maxWidth;
		h = (w * sh)/sw;
	}else{
		h = maxHeight;
		w = (h * sw)/sh;
	}
	obj.width = w;
	obj.height = h;
	obj = null;
}

//重置对象大小
function reSizex(obj,nobj,maxWidth,maxHeight){
	var sw = obj.width;
	var sh = obj.height;
	var mw = maxWidth;
	var mh = maxHeight;
	if ( sw < mw && sh < mh ){
		w = sw;
		h = sh;
	}else if ( (sw/sh) > (mw/mh) ){
		w = maxWidth;
		h = (w * sh)/sw;
	}else{
		h = maxHeight;
		w = (h * sw)/sh;
	}
	nobj.width = w;
	nobj.height = h;
	nobj = obj = null;
}

function showAdBox(width,height,top,left,title,str){
    document.write('<div id="showimage" style="z-index:99999;position: absolute; width: '+width+'px;left:'+left+'px; top:'+top+'px;">');
    document.write('<table CLASS="alpht" width="100%" border="1" bgcolor="#555555" cellspacing="0" cellpadding="2">');
    document.write('<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="2">');
    document.write('<tr><td CLASS="alpht" onMousedown="initializedragie()" style="cursor: move" ><font size="2">');            
    document.write('<ilayer onSelectStart="return false">');
    document.write('<layer width="100%" onMouseover="dragswitch=1;drag_dropns(showimage)" onMouseout="dragswitch=0"></layer></ilayer>');
    document.write('<font color="f5f5f5">◎'+title+'</font></font></td><td style="cursor: hand" height="1" >');
    document.write('<p align="right"><a href="#" onClick="hidebox();return false"><font size="2" color="#FFFFFF">關閉</font></a></p></td></tr>');
    document.write('<tr><td CLASS="alpht" bgcolor="#ffffff" colspan="2" height="'+height+'" valign="top">');
    document.write(str);
    document.write('</td>');
    document.write('</tr>');
    document.write('</table></table></div>');
}            
var dragswitch=0                 
var nsx                 
var nsy                 
var nstemp        
function drag_dropns(name){                 
	temp=eval(name)                 
	temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)                 
	temp.onmousedown=gons                 
	temp.onmousemove=dragns                 
	temp.onmouseup=stopns                 
}                 
                 
function gons(e){                 
	temp.captureEvents(Event.MOUSEMOVE)                 
	nsx=e.x                 
	nsy=e.y                 
}                 
function dragns(e){                 
	if (dragswitch==1){                 
		temp.moveBy(e.x-nsx,e.y-nsy)                 
		return false                 
	}                 
}                 
                 
function stopns(){                 
	temp.releaseEvents(Event.MOUSEMOVE)                 
}                 
                 
//drag drop function for IE 4+////                 
                 
var dragapproved=false                 
                 
function drag_dropie(){                 
	if (dragapproved==true){                 
		document.all.showimage.style.pixelLeft=tempx+event.clientX-iex                 
		document.all.showimage.style.pixelTop=tempy+event.clientY-iey                 
		return false                 
	}                 
}                 
                 
function initializedragie(){                 
	iex=event.clientX                 
	iey=event.clientY                 
	tempx=showimage.style.pixelLeft                 
	tempy=showimage.style.pixelTop                 
	dragapproved=true                 
	document.onmousemove=drag_dropie                 
}                 
                 
if (document.all){                 
	document.onmouseup=new Function("dragapproved=false")                 
}       
////drag drop functions end here//////                 
                 
function hidebox(){                 
	if (document.all)                 
	showimage.style.visibility="hidden";              
	else if (document.layers)                 
	document.showimage.visibility="hide";                 
}    

         