﻿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;
		}
	}
}
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 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 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 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 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;
}



