/*
2008-8-9 修正 Xcover 在ie6 下不能遮住select的bug



*/

function fGetViewportSizeX() 
{/* shawl.qiu code, return object */
 var myWidth = 0, myHeight = 0;
 if(typeof(window.innerWidth ) == 'number' ) 
 {/* Non-IE */
  myWidth = window.innerWidth; myHeight = window.innerHeight;
 } 
 else if 
 (
  document.documentElement && 
  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) 
  ) 
 {/* IE 6 */
  myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
 } 
 else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
 {/* IE 4 */
  myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
 }
 return {
          Width:myWidth
          , Height:myHeight
          , MaxWidth: myWidth+document.documentElement.scrollLeft
          , MaxHeight: myHeight+document.documentElement.scrollTop
        };
}
function Xcover(color,num){/*color:遮罩的背景色 eg: red/#cbcbcb, num:1-100内的整数*/
    var cDiv=document.createElement("div");
		document.body.appendChild(cDiv);
	this.Div=cDiv;
	this.color=color;
	this.num=num;
	//this.start=function(){
	//	document.documentElement.style.overflow='hidden';	
		with(cDiv.style)
				{
					position="absolute";
					top="0px";
					left="0px";
					zIndex=100;
					width="0px";
					margin="0px auto";
					background=this.color;
					display='none';
					filter="Alpha(Opacity="+this.num+")";
					opacity=this.num/100;
					width=fGetViewportSizeX().MaxWidth+"px";
					height="5000px";
					//height=fGetViewportSizeX().MaxHeight+"px";
				}

	//	};
	this.hidden=function(){
		SelectDisplayCtrl('visible');
		cDiv.style.display="none";
		document.documentElement.style.overflow='';
	}
	this.show=function(){
		SelectDisplayCtrl('hidden');
		cDiv.style.display="block";
		document.documentElement.style.overflow='hidden';
	}
	this.stop=function(){
		SelectDisplayCtrl('visible');
		cDiv.parentNode.removeChild(cDiv);
		document.documentElement.style.overflow='';

	};
	window.onresize=function(){
			cDiv.style.width=fGetViewportSizeX().MaxWidth+"px";
			cDiv.style.height="2000px";//fGetViewportSizeX().MaxHeight+"
		};

	function SelectDisplayCtrl(type){
		var selects=document.getElementsByTagName('select');
		if(selects.length>0){
			for(var i=0;i<selects.length;i++){
				selects[i].style.visibility=type;
			
			}
		}
	
	}
}
/*
@className Xdrag
@param     drag_body 被拖动的dom节点
@param     drag_bar  触发拖动的节点 应为drag_body内的，如果需要整体响应拖动 设置为 false；
@param     box       被拖动的范围 可选
*/
var DragZIndexNum=1000;
function Xdrag(drag_body,drag_bar,box){
        //var mask=0;//设置监听是否鼠标按下
		var obj=drag_body;
		var drag_obj=drag_bar?drag_bar:obj;
		drag_obj.style.cursor="move";
	    obj.mask=0;
        
        var Ow=obj.offsetWidth;//获取拖动对象的宽高
        var Oh=obj.offsetHeight;
		

	   if(box){  
		var Bw=box.offsetWidth;//获取拖动容器的宽高
		var Bh=box.offsetHeight;
		}
		try{
        obj.onmousedown=function(e){
				this.style.zIndex=DragZIndexNum++;
				var Ol=obj.offsetLeft;
				var Ot=obj.offsetTop;
				this.style.position="absolute";
				this.style.left=Ol+"px";
				this.style.top=Ot+"px";
                var e=e||window.event;
                drag_obj.onselectstart=function(){return false;}
                var eSrc=e.srcElement||e.target;
				if(eSrc==drag_obj||eSrc.parentNode==drag_obj){
                this.mask=1;
                XCapture(drag_obj,"start");
			    Ex=XmouseCoords(e).x-XgetPosition(this).x;
                Ey=XmouseCoords(e).y-XgetPosition(this).y;

				document.onmousemove=function(e){
				var e=e||window.event;
                if(obj.mask==1){
                  var Ox=XmouseCoords(e).x-Ex;
                  var Oy=XmouseCoords(e).y-Ey;
                  if(box){
                        var Bx=XgetPosition(box).x;
                        var By=XgetPosition(box).y;
                        if(Ox<Bx){
                                Ox=Bx;
                        }
                        else if(Ox>Bx+Bw-Ow){
                                Ox=Bx+Bw+-Ow;
                        }
                        if(Oy<By){
                                Oy=By;
                        }
                        else if(Oy>By+Bh-Oh){
                            Oy=By+Bh-Oh;
                        
                        }
                  }
                 obj.style.left=Ox+"px";
                 obj.style.top=Oy+"px";
                }
				
			}
		  }
        }

        
		obj.onmouseup=function(){
              this.mask=0;
              XCapture(drag_obj,"end");
        
        }
		}
		catch(e){}


}
/*获取鼠标位置*/
function XmouseCoords(ev){
        if(ev.pageX || ev.pageY){
                return {x:ev.pageX, y:ev.pageY};
        }
        return {
                x:ev.clientX + document.documentElement.scrollLeft,
                y:ev.clientY + document.documentElement.scrollTop
        };
}
/*设置事件捕获
*function  XCapture
@param o, 捕获事件的对象
@param mak，状态 "start" or "end"
*/
function XCapture(o,mak){
    if(mak=="start"){
          if(o.setCapture){o.setCapture();}
          else if(window.captureEvents)
                         {window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);}
        }
        if(mak=="end"){
          if(o.releaseCapture){o.releaseCapture();}
          else if(window.captureEvents)
                        {window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);}
         }
        
}
/*获取指定节点的坐标*/
function XgetPosition(e){
        var left = 0;
        var top  = 0;

        while(e.offsetParent){
                left += e.offsetLeft;
                top  += e.offsetTop;
                e= e.offsetParent;
        }

        left += e.offsetLeft;
        top  += e.offsetTop;

        return {x:left, y:top};
}
function fSetStyle(XEle, sStyle)
{/* shawl.qiu code, return default */
  if(!sStyle)return;
  if(window.HTMLElement) return XEle.setAttribute("style", sStyle);
  else return XEle.style.cssText = sStyle;
}