﻿//===========================================================
//==               (c)2008  NETSNS 1.0                     ==
//==            website:www.aspxcms.com                    ==
//==         qq:93333147,Email:zhangyuanjun@126.com        ==
//==               Code By Arjun                           ==
//===========================================================
/**
一些页面显示效果控件


**/
function getEvent(){     //同时兼容ie和ff的写法
         if(document.all)    return window.event;        
         func=getEvent.caller;            
         while(func!=null){    
             var arg0=func.arguments[0];
             if(arg0){
                 if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
                     || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    
                     return arg0;
                 }
             }
             func=func.caller;
         }
         return null;
 }

try
{
	HTMLElement.prototype.__defineGetter__("children",
	function () {
	var returnValue = new Object();
	var number = 0;
	for (var i=0; i<this.childNodes.length; i++) {
	if (this.childNodes[i].nodeType == 1) {
	returnValue[number] = this.childNodes[i];
	number++;
	}
	}
	returnValue.length = number;
	return returnValue;
	}
	);
}
catch(e){}


var ajControl=
{
    //在一个层上显示漂浮的内容
    overContent:function(obj,innerHTML)
    {
        var o=typeof(obj)=="object"?obj:document.getElementById(obj);
	    if (window.attachEvent)
	    {
		    o.attachEvent("onmousemove",mousemove); 
	    }
	    if (window.addEventListener)
	    {
		    o.addEventListener("mousemove",mousemove,false);
	    } 

	    if (window.attachEvent)
	    {
		    o.attachEvent("onmouseout",mouseout); 
	    }
	    if (window.addEventListener)
	    {
		    o.addEventListener("mouseout",mouseout,false);
	    } 
        

	    function mousemove()
	    {
		    var event=getEvent();
		    var x=event.clientX;
		    var scrollTop=document.body.scrollTop;
		    if(scrollTop==0)
		    {
		        scrollTop=document.documentElement.scrollTop;
		    }
		    var y=event.clientY+scrollTop+10;
		    var div=document.getElementById("OverFloatDiv");
		    if(!div)
		    {
			    div=document.createElement("div");
			    div.setAttribute("id","OverFloatDiv");
			    document.body.appendChild(div);
		    }
		    div.innerHTML=innerHTML;
		    div.style.position="absolute";
		    div.style.left=x+"px";
		    div.style.top=y+"px";
	    }

	    function mouseout()
	    {
		    var div=document.getElementById("OverFloatDiv");
		    if(div)
		    {
			    document.body.removeChild(div);
		    }
	    } 
    },
    //移动层对象
    dragObj:function(obj)
	{
		var o=getObj(obj);
		var XY=getXY(o);
		o.setAttribute("moveable","false");
		var cx=0;
		var cy=0;
		try
		{
			cx=arguments[1];
			cy=arguments[2];
		}
		catch (e)
		{
		}
		var x0=0;
		var y0=0;
		o.onmousedown=function()
		{
			var event=getEvent();
			var XY=getXY(o);
			x0=event.clientX-XY.X;
			y0=event.clientY-XY.Y;
			o.setAttribute("moveable","true");
		}
		o.onmouseup=function()
		{
			o.setAttribute("moveable","false");
		}

		o.onmousemove=function()
		{
			var availableMove=false;
			try
			{
				availableMove=eval(o.getAttribute("moveable"));
			}
			catch (e){}
			if(!availableMove)
				return;
			var event=getEvent();
			var x=event.clientX-x0;
			var y=event.clientY-y0;
			o.style.position="absolute";
			o.style.display="block";
			o.style.left=x+"px";
			o.style.top=y+"px";
		}
		function getXY(obj)
		{
			var o=obj;
			var x=o.offsetLeft;
			var y=o.offsetTop;
			while(o=o.offsetParent)
			{
				x+=o.offsetLeft;
				y+=o.offsetTop;
			}
			return {X:x,Y:y}
		}

		function getEvent(){
				 if(document.all)    return window.event;        
				 func=getEvent.caller;            
				 while(func!=null){    
					 var arg0=func.arguments[0];
					 if(arg0){
						 if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
							 || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    
							 return arg0;
						 }
					 }
					 func=func.caller;
				 }
				 return null;
		 }
		function getObj(obj)
		{
			var o;
			if(typeof(obj)=="string")
			{
				o=document.getElementById(obj);
			}
			else
			{
				o=obj;
			}
			return o;
		}
	},
	///缩小obj区域中的图片大小
	smallInnerImg:function(obj,width,height)
    {
	    var value=[];
	    var o=getObj(obj);
    	
	    LoadAllEvent();

	    function getrunelement(obj)
	    {
		    try
		    {
			    if(obj.children.length>0)
			    {
				    for(var i=0;i<obj.children.length;i++)
				    {
					    var o=obj.children[i];
    					
					    if(o.tagName=="IMG")
					    {
						    value[value.length]=o;
					    }
					    getrunelement(o);
				    }
			     }
		    }
		    catch(e){}
	    }
    	
	    function getRunElement()
	    {
		    value=[];
		    getrunelement(o);
		    return value;
	    }
	    function LoadAllEvent()
	    {
		    var elements=getRunElement();
		    var obj=null;
		    for(var i=0;i<elements.length;i++)
		    {
			    obj=elements[i];
			    if(obj.width>width||obj.height>height)
			    {
				    obj.width=width;
				    obj.height=height;
				    obj.style.width=width+"px";
				    obj.style.height=height+"px";
			    }
		    }
	    }
    	

	    function getObj(obj)
	    {
		    var o;
		    if(typeof(obj)=="string")
		    {
			    o=document.getElementById(obj);
		    }
		    else
		    {
			    o=obj;
		    }
		    return o;
	    }
    },
    //替换ID为id内容器的所有字符
    ReplaceText:function(id,text,replaceText)
	{		
		var objs=[];
		var obj;
		if(typeof(id)=="string")
		{
			obj=document.getElementById(id);
		}
		else
		{
			obj=id;
		}
		getObjs(obj);
		for(var i=0;i<objs.length;i++)
		{
			var o=objs[i];
			if(o.tagName!="A")
			{
			    o.innerHTML=o.innerHTML.replace(eval("/"+text+"/gi"),replaceText);
			}
		}
		function getObjs(obj)
		{
			if(obj.nodeType==1)
			{
				objs[objs.length++]=obj;
			}
			if(obj.childNodes.length>0)
			{
				for(var i=0;i<obj.childNodes.length;i++)
				{					
					if(obj.childNodes[i].nodeType!=1)
						continue;					
					getObjs(obj.childNodes[i]);
				}
			}
		}
	},
	//在屏幕中间显示的窗口
	CenterWindow:function()
	{
		this.ID="CenterWindow";
		this.Width=400;
		this.Title="";
		this.THeight=30;
		this.TColor="#ffffff";
		this.TBgColor="#73B1E6";
		this.Content="";
		this.CColor="#000000";
		this.CBgColor="#ffffff";
		this.Bottom="";
		this.BColor="#000000";
		this.BBgColor="#E3E3E6";
		this.BTopBorderColor="#89848A";
		this.BHeight=30;
		this.alphaWidth=10;
		this.Confirm=function()
		{
			
		}
		this.Cancle=function()
		{
			
		}
		this.ConfirmButton="确定";
		this.CancleButton="取消";
		this.Close=function()
		{
			var div=document.getElementById(this.ID);
			if(div)
			{
				div.parentNode.removeChild(div);
			}
			var aDiv=document.getElementById("a"+this.ID);
			if(aDiv)
			{
				aDiv.parentNode.removeChild(aDiv);
			}
		}
		this.Create=function()
		{
			var HTML='';
			var bottomHTML='';
			if(this.ConfirmButton!="")
			{
				bottomHTML+='<input type="button" value="'+this.ConfirmButton+'" id="centerwindowconfirm"/>';
			}
			if(this.CancleButton!="")
			{
				bottomHTML+='&nbsp;&nbsp;<input type="button" value="'+this.CancleButton+'" id="centerwindowcancle"/>';
			}
			HTML +=' 	<div style="position:relative;text-align:left;padding:0px;height:100%">';
			HTML +=' 		<div>';
			HTML +=' 			<div style=width:100%;"position:absolute;top:0px;">';
			HTML +=' 				<div style="height:'+this.THeight+'px;background-color:'+this.TBgColor+';font-weight:600;line-height:'+this.THeight+'px;color:'+this.TColor+';padding-left:10px">'+this.Title+'</div>';
			HTML +=' 			</div>';
			HTML +=' 			<div style="height:100%;color:'+this.CColor+';background-color:'+this.CBgColor+';padding-bottom:'+this.BHeight+'px">';
			HTML +=' 				<div style="padding:5px;">';
			HTML +=' 				'+this.Content+'';
			HTML +=' 				</div>';
			HTML +='			</div>';
			HTML +='			<div style="width:100%;position:absolute;bottom:0px;">';
			HTML +='				<div style="height:'+this.BHeight+'px;background-color:'+this.BBgColor+';line-height:'+this.BHeight+'px;text-align:right;padding-right:10px;border-width:1px 0px 0px 0px;border-style:solid;border-color:'+this.BTopBorderColor+'">'+bottomHTML+'</div>';
			HTML +='			</div>';
			HTML +='		</div>';
			HTML +='	</div>';
			var div=document.getElementById(this.ID);
			if(!div)
			{
				div=document.createElement("div");
				div.setAttribute("id",this.ID);
				document.body.appendChild(div);
			}			
			div.innerHTML=HTML;
			div.style.position="absolute";
			div.style.zIndex="11";
			div.style.width=this.Width;
			var scrolltop=document.documentElement.scrollTop;
			if(scrolltop==0)
			{
				scrolltop=document.body.scrollTop;
			}
			var top=(document.documentElement.clientHeight)/2-div.offsetHeight/2+document.documentElement.scrollTop;
			var left=document.body.offsetWidth/2-div.offsetWidth/2;

			
			div.style.top=top+"px";
			div.style.left=left+"px";
			var aDiv=document.getElementById("a"+this.ID);
			if(!aDiv)
			{
				aDiv=document.createElement("div");
				aDiv.setAttribute("id","a"+this.ID);
				document.body.appendChild(aDiv);
			}	
			aDiv.style.position="absolute";
			aDiv.style.backgroundColor="#000000";
			aDiv.style.zIndex="10";
			aDiv.style.width=this.Width+this.alphaWidth*2;
			aDiv.style.height=div.offsetHeight+this.alphaWidth*2;
			aDiv.style.top=(top-this.alphaWidth)+"px";
			aDiv.style.left=(left-this.alphaWidth)+"px"
			aDiv.style.filter="alpha(opacity=58);";
			aDiv.setAttribute("style","-moz-opacity:0.55;opacity: 0.55;");

			var Confirm=this.Confirm;
			var Cancle=this.Cancle;
			if(this.ConfirmButton!=""&&document.getElementById("centerwindowconfirm"))
			{
				document.getElementById("centerwindowconfirm").onclick=Confirm;
			}
			if(this.CancleButton!=""&&document.getElementById("centerwindowcancle"))
			{
				document.getElementById("centerwindowcancle").onclick=Cancle;
			}
		}
	}
}