/*
=================== 版　权　声　明 ===================
模块设计: Landers 	QQ:13582702　Email：13582702@qq.com
模块特点：由于采用类模块设计，有效地避免变量命名的冲突问题，多个实例互不影响
	如果您在使用过程有什么好的意见或建议，请发Email给作者。
	本模块您可以任意复制、传播、修改，但修改后麻烦请转发一份至 13582702@qq.com，谢谢合作！
	限于作者水平，如有不足之处，还望高手指点


=================== 使　用　范　例 ===================
详见ScrollDemo.htm代码及注释说明
*/



//TheDiv 	: Div的Name和Id
//IsRepeat	: 是否允许重复创建
//DivContent: Div中的内容
//IsShow	:　是否显示
function CreateDiv(TheDiv,IsShow,IsRepeat,DivContent,Position,Zindex,Width,Height,Alpha){
	var ObjDiv,IsNew
	//建立Div
	if (typeof(TheDiv)=="object"){
		ObjDiv = TheDiv
		IsNew  = false;
	}else{
		if (document.getElementsByName(TheDiv).length != 0){
			if (IsRepeat){
				ObjDiv  = document.createElement("div")
				IsNew	= true;
			}else{
				ObjDiv 	= document.getElementById(TheDiv)
				IsNew	= false;
			}
		}else{
			ObjDiv 		= document.createElement("div")
			IsNew	 	= true;
		}
	}
	
	//给Div设属性
	if (IsNew){
		TheDiv 		 	= BuildTheDiv(TheDiv)
		ObjDiv.name 	= TheDiv
		ObjDiv.id		= TheDiv
	}
	ObjDiv.style.position = "absolute";
	if (DivContent!=null && DivContent!="") ObjDiv.innerHTML = DivContent
	if (IsShow) { ObjDiv.style.display	= ""; }else{ ObjDiv.style.display	= "none"; }
	if (Width  != null) { ObjDiv.style.width  = Width; }else{ Width  = 0 }
	if (Height != null) { ObjDiv.style.height = Height }else{ Height = 0 }
	if (Zindex != null) { ObjDiv.style.zIndex = Zindex }
	if (Alpha  != null && Alpha  != 100) { ObjDiv.style.filter = "alpha(Opacity=" + Alpha + ")" }
	
	
	var tmpWidth,tmpHeight;
	if (ObjDiv.scrollWidth ==0) { tmpWidth  = Width  }else{ tmpWidth  = ObjDiv.scrollWidth  }
	if (ObjDiv.scrollHeight==0) { tmpHeight = Height }else{ tmpHeight = ObjDiv.scrollHeight }
	if (Position==null || Position=="") Position = 5
	LocalDivPos(ObjDiv,Position,tmpWidth,tmpHeight)
	//返回结果
	document.body.appendChild(ObjDiv);
	
	this.Show = function(){ObjDiv.style.display = ""}
	this.Hide = function(){ObjDiv.style.display = "none"}
	this.Divobj = function(){return ObjDiv}

	//生成TheDiv
	function BuildTheDiv(InitDivName){
		if (InitDivName=="" || 	InitDivName==null)	InitDivName = "LandersDivLayer"
		if (document.getElementsByName(InitDivName).length != 0) {
			var DivCount = 0
			while (document.getElementsByName(InitDivName+DivCount).length != 0 ){	DivCount++;}
			return (InitDivName + DivCount);
		}else{
			return (InitDivName);
		}
	}
}


function LocalDivPos(TheDiv,nPos,objWidth,objHeight){
	var ObjDiv
	if (typeof(TheDiv)=="object") ObjDiv = TheDiv
	if (typeof(TheDiv)=="string") ObjDiv = document.getElementById(TheDiv)
	if (typeof(ObjDiv)!="object") {alert("函数参数有误!");return null;}
	if (objWidth==null) objWidth = ObjDiv.scrollWidth 
	if (objHeight==null) objHeight = ObjDiv.scrollHeight
	switch (nPos){
		case 1:
			ObjDiv.style.left = 0
			ObjDiv.style.top  = 0
			break;
		case 2:
			ObjDiv.style.left = (document.body.clientWidth - objWidth ) /2
			ObjDiv.style.top  = 0
			break;
		case 3:
			ObjDiv.style.left = document.body.clientWidth - objWidth - 2
			ObjDiv.style.top  = 0
			break;
		case 4:
			ObjDiv.style.left = 0
			ObjDiv.style.top  = (document.body.clientHeight- objHeight) /2
			break;
		case 5:
			ObjDiv.style.left = (document.body.clientWidth - objWidth ) /2
			ObjDiv.style.top  = (document.body.clientHeight- objHeight) /2
			break;
		case 6:
			ObjDiv.style.left = document.body.clientWidth - objWidth - 2
			ObjDiv.style.top  = (document.body.clientHeight- objHeight) /2
			break;
		case 7:
			ObjDiv.style.left = 0
			ObjDiv.style.top  = document.body.clientHeight- objHeight
			break;
		case 8:
			ObjDiv.style.left = (document.body.clientWidth - objWidth ) /2
			ObjDiv.style.top  = document.body.clientHeight- objHeight
			break;
		case 9:
			ObjDiv.style.left = document.body.clientWidth - objWidth - 2
			ObjDiv.style.top  = document.body.clientHeight- objHeight
			break;
	}
}


function CenterDiv(TheDiv,Width,Height,Zindex,Alpha){
	var ObjDiv,DivName
	//识别TheDiv参数数据类型
	if (typeof(TheDiv)=="object"){				//Div对象
		ObjDiv = TheDiv
	}else if (typeof(TheDiv)=="string"){ 		//Div标识名称
		ObjDiv = document.getElementsByName(TheDiv)
		if (ObjDiv.length<=0){
			alert("页面中不存在"+TheDiv+"对象!")
			return null;
		}else if(ObjDiv.length==1){
			ObjDiv = document.getElementById(TheDiv)
		}else{
			alert("页面中存在多个"+TheDiv+"对象!")
			return null;
		}
	}else{
		alert("参数数据类型错误！")
		return null;
	}
	ObjDiv.style.display = "inline"
	ObjDiv.style.position = "absolute"
	if (Width  != null) { ObjDiv.style.width  = Width  }
	if (Height != null) { ObjDiv.style.height = Height }
	if (Zindex != null) { ObjDiv.style.zIndex = Zindex }
	if (Alpha  != null) { ObjDiv.style.filter = "alpha(Opacity=" + Alpha + ")" }
	ObjDiv.style.left = (document.body.clientWidth-ObjDiv.scrollWidth)  /2
	ObjDiv.style.top  = (document.body.clientHeight-ObjDiv.scrollHeight)/2
}


function FloatDiv(targetStr, position, fixedX, fixedY){
	//targetStr 浮动物件的 HTML 元素标签的 id，字符串类型
	//position 样式属性，决定 fixedX 和 fixedY 使用的是绝对位置还是相对位置，可选值 absolute 和 relative
	//fixedX 浮动物件 X 方向开始位置
	//fixedY 浮动物件 Y 方向开始位置
	//floatDelay 是可选参数，浮动延迟时间，单位毫秒，默认值是 30	
	var FLOATADS_INSTRUCTION_NONE	= 0;
	var FLOATADS_INSTRUCTION_RUN	= 1;
	var FLOATADS_INSTRUCTION_PAUSE	= 2;

	this.target = GetObj(targetStr);
	this.target.style.position = position;
	this.fixedX = fixedX;
	if (this.fixedX >= 0) this.target.style.left = this.fixedX + "px";
	this.fixedY = fixedY;
	if (this.fixedY >= 0) this.target.style.top = this.fixedY + "px";
	this.floatDelay = (arguments.length>=6)?arguments[5]:30;
	this.instruction = FLOATADS_INSTRUCTION_NONE;
	this.timer = null;
	this.StartFloat = FloatAds_StartFloat; //启用浮动
	this.PauseFloat = FloatAds_PauseFloat; //暂停浮动
	this.ResumeFloat = FloatAds_ResumeFloat; //从暂停恢复浮动
	this.FloatX = FloatAds_FloatX; //在 X 方向浮动，被 this.StartFloat 调用
	this.FloatY = FloatAds_FloatY; //在 Y 方向浮动，被 this.StartFloat 调用

	//启用浮动
	function FloatAds_StartFloat(){
		if (this.instruction == FLOATADS_INSTRUCTION_PAUSE) return; //不能由暂停指令开始
		if (this.fixedX >= 0) this.FloatX();
		if (this.fixedY >= 0) this.FloatY();
		this.instruction = FLOATADS_INSTRUCTION_RUN;
		var me = this;
		this.timer = setTimeout(function () { me.StartFloat(); }, me.floatDelay);
	}

	function FloatAds_PauseFloat(){
		if (this.instruction != FLOATADS_INSTRUCTION_RUN) return;	//只能由运行指令开始
		this.instruction = FLOATADS_INSTRUCTION_PAUSE;
		clearTimeout(this.timer);
	}

	function FloatAds_ResumeFloat(){
		if (this.instruction != FLOATADS_INSTRUCTION_PAUSE) return; //只能由暂停指令开始
		this.instruction = FLOATADS_INSTRUCTION_RUN;
		this.StartFloat();
	}

	//在 X 方向浮动，被 this.StartFloat 调用
	function FloatAds_FloatX(){
		if (this.instruction != FLOATADS_INSTRUCTION_RUN) return; //不是运行指令，退出
		var stepX = 10;
		var offsetX = (document.documentElement.scrollLeft || document.body.scrollLeft) + this.fixedX - parseInt(this.target.style.left);
		var newX = parseInt(this.target.style.left);
		if (offsetX > 0){
			newX += (offsetX>stepX)?parseInt(offsetX/stepX):1;
			this.target.style.left = newX + "px";
		}else if (offsetX < 0){
			newX += (-offsetX>stepX)?parseInt(offsetX/stepX):-1;
			this.target.style.left = newX + "px";
		}
	}

	//在 Y 方向浮动，被 this.StartFloat 调用
	function FloatAds_FloatY(){
		if (this.instruction != FLOATADS_INSTRUCTION_RUN) return; //不是运行指令，退出
		var stepY = 10;
		var offsetY = (document.documentElement.scrollTop || document.body.scrollTop) + this.fixedY - parseInt(this.target.style.top);
		var newY = parseInt(this.target.style.top);
		if (offsetY > 0){
			newY += (offsetY>stepY)?parseInt(offsetY/stepY):1;
			this.target.style.top = newY + "px";
		}else if (offsetY < 0){
			newY += (-offsetY>stepY)?parseInt(offsetY/stepY):-1;
			this.target.style.top = newY + "px";
		}
	}	
}

function AbsLocalDiv(TheDiv){
	//变量声明、初始化
	var ObjAbsLocalDiv
	var DivAbsLocalTimerId = ""
	self.onError=null;
	currentX = currentY = 0; 
	whichIt = null; 
	lastScrollX = 0; lastScrollY = 0;
	NS = (document.layers) ? 1 : 0;
	IE = (document.all) ? 1: 0;

	//层不存在，退出
	if (typeof(TheDiv)=="object") ObjAbsLocalDiv = TheDiv
	if (typeof(TheDiv)=="string"){
		if (document.getElementsByName(TheDiv).length==0) return 0
		if(IE) ObjAbsLocalDiv = document.getElementById(TheDiv);
		if(NS) ObjAbsLocalDiv = document.getElementById.all.TheDiv;
	}
	ObjAbsLocalDiv.style.display	= '';
	if(NS || IE) DivAbsLocalTimerId	= window.setInterval(AbsLocalDivAction,30);
	
	//让层绝对定位
	function AbsLocalDivAction(){
		if (ObjAbsLocalDiv.style.display!=''){clearInterval(DivAbsLocalTimerId); }
		
		if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
		if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
		if(diffY != lastScrollY) {
			percent = .1 * (diffY - lastScrollY);
			if(percent > 0)
				percent = Math.ceil(percent);
			else
				percent = Math.floor(percent);
			if(IE) ObjAbsLocalDiv.style.pixelTop += percent;
			if(NS) ObjAbsLocalDiv.top += percent; 
			lastScrollY = lastScrollY + percent;
		}
		if(diffX != lastScrollX) {
			 percent = .1 * (diffX - lastScrollX);
			 if(percent > 0) percent = Math.ceil(percent);
			 else percent = Math.floor(percent);
			 if(IE) ObjAbsLocalDiv.style.pixelLeft += percent;
			 if(NS) ObjAbsLocalDiv.left += percent;
			 lastScrollX = lastScrollX + percent;
		}
	}
}



/*Div弹出框*/
function DivMsgBox(TheDiv,sPostion,strMsgTitle,strMsgContent,sBgC,sBdC,sTitleBgC,nWidth,nHeight,Zindex,nAlpha){
	if (sPostion==null) sPostion = 5
	var TheDivHeadID,TheDivBodyID
	
	//浮动框模板
	var TheDivHeadID = TheDiv + "_Head"
	var TheDivBodyID = TheDiv + "_Body"
	var strTemplate	 = "<div ID='"+TheDiv+"_Main'>"
	strTemplate		+= "<div ID='"+TheDivHeadID+"' stle='background-color:"+sTitleBgC+";'>"+strMsgTitle+"</div>"
	strTemplate		+= "<div ID='"+TheDivBodyID+"'>"+strMsgContent+"</div>"
	strTemplate		+= "<div ID='"+TheDiv+"_Btns'>"
	strTemplate		+= "</div>"
	strTemplate		+= "</div>"

	if (typeof(TheDiv)=="object") strTemplate = ""
	var ObjDiv = new CreateDiv(TheDiv,false,false,strTemplate,sPostion,Zindex,nWidth,nHeight,nAlpha)

	//类属性
	this.ObjDiv	= ObjDiv.Divobj()
	
	
	//简单初始化
	try{
		if (sBgC!="" && sBgC!="") this.ObjDiv.style.backgroundColor	= sBgC
		if (sBdC!=null && sBdC!=""){
			this.ObjDiv.style.border	= "1px "+sBdC+" solid"
			this.ObjDiv.style.color		= sBdC
		}
		var ObjHead	= document.getElementById(TheDivHeadID)
		if (strMsgTitle==""){ObjHead.style.display = "none";}else{	ObjHead.style.backgroundColor = sTitleBgC}
		var ObjBody	= document.getElementById(TheDivBodyID)
	}catch(e){}
	
	//类方法
	//获取方法
	this.getContent	= function(){return (ObjBody.innerHTML)}
	this.getLeft	= function(){return Number(this.ObjDiv.style.left.replace("px",""))	}
	this.getWidth	= function(){return Number(this.ObjDiv.style.width.replace("px",""))	}
	this.getTop		= function(){return Number(this.ObjDiv.style.top.replace("px",""))	}
	this.getHeight	= function(){return Number(this.ObjDiv.style.height.replace("px",""))}

	//设置方法
	this.Show	= function(strMsg,IsFlat,objBB){
		if (strMsg!=null && strMsg !="") this.ObjDiv.innerHTML = strMsg
		this.ObjDiv.style.display	= ""
		var Tmp = this
		if (IsFlat){
			AbsLocalDiv(this.ObjDiv)
			//Tmp = new FloatDiv(this.ObjDiv, "absolute", 50, 0)
			//Tmp.StartFloat()
		}
		if (objBB!=null) objBB.Show()
		return Tmp
	}
	this.Hide		= function(){ this.ObjDiv.style.display = "none"}
	this.Marquee	= function(sdirection,sBehavior,nAmount){
		if (sdirection==null) sdirection = ""
		if (sBehavior==null) sBehavior = ""
		if (nAmount<1 || nAmount==null) nAmount = 2
		var Ori_Html = ObjBody.innerHTML
		var Ret
		Ret  = "<marquee width='100%' direction='"+sdirection+"' behavior='"+sBehavior+"' scrollamount='"+nAmount+"'>"
		Ret += Ori_Html
		Ret += "</marquee>"
		ObjBody.innerHTML = Ret
	}
	this.setTop		= function(nTop)	{this.ObjDiv.style.top	= Number(nTop)}
	this.setLeft	= function(nLeft)	{this.ObjDiv.style.left	= Number(nLeft)}
	this.moveTop	= function(y){	this.ObjDiv.style.top = Number(this.ObjDiv.style.top.replace("px","")) - Number(y)}
	this.moveBottom	= function(y){	this.ObjDiv.style.top = Number(this.ObjDiv.style.top.replace("px","")) + Number(y)}
	this.moveUp		= function(y){	this.ObjDiv.style.top = Number(this.ObjDiv.style.top.replace("px","")) - Number(y)}
	this.moveDown	= function(y){	this.ObjDiv.style.top = Number(this.ObjDiv.style.top.replace("px","")) + Number(y)}
	this.moveLeft	= function(x){	this.ObjDiv.style.left = Number(this.ObjDiv.style.left.replace("px","")) - Number(x)}
	this.moveRight	= function(x){	this.ObjDiv.style.left = Number(this.ObjDiv.style.left.replace("px","")) + Number(x)}
	this.addWidth	= function(x){	this.ObjDiv.style.width = Number(this.ObjDiv.style.width.replace("px","")) + Number(x)}
	this.subWidth	= function(x){	this.ObjDiv.style.width = Number(this.ObjDiv.style.width.replace("px","")) - Number(x)}
	this.addHeight	= function(y){	this.ObjDiv.style.height = Number(this.ObjDiv.style.height.replace("px","")) + Number(y)}
	this.subHeight	= function(y){	this.ObjDiv.style.height = Number(this.ObjDiv.style.height.replace("px","")) - Number(y)}
	this.setPadding	= function(nL,nR,nT,nB){
		if (nL!=null) this.ObjDiv.style.paddingLeft	= Number(nL)
		if (nR!=null) this.ObjDiv.style.paddingRight	= Number(nR)
		if (nT!=null) this.ObjDiv.style.paddingTop		= Number(nT)
		if (nB!=null) this.ObjDiv.style.paddingBottom	= Number(nB)
	}
	this.setAlign	= function(sDir)		{this.ObjDiv.style.textAlign = sDir}
	this.setPos		= function(nPos)		{LocalDivPos(this.ObjDiv,nPos)}
	this.setSize	= function(nW,nH)		{
		if (nW!=null) this.ObjDiv.style.width = Number(nW);
		if (nH!=null) this.ObjDiv.style.height = Number(nH);
	}
	this.setFont	= function(Size,Bold,Color,Family,Spacing){
		if (Size!=null) this.ObjDiv.style.fontSize = Size
		if (Bold!=null){
			if(Bold){this.ObjDiv.style.fontWeight = "bold"}else{this.ObjDiv.style.fontWeight = 100}
		}
		if (Color!=null) this.ObjDiv.style.color = Color
		if (Family!=null) this.ObjDiv.style.family = Family
		if (Spacing!=null)this.ObjDiv.style.letterSpacing = Spacing
	}	
	this.setBgc		= function(myBgc)		{this.ObjDiv.style.backgroundColor = myBgc}
	this.setBdc		= function(myBdc)		{this.ObjDiv.style.border = "1px "+myBdc+" solid"}
	this.setAlpha	= function(nAlpha)		{this.ObjDiv.style.filter = "alpha(Opacity=" + nAlpha + ")"}
	this.setContent	= function(sContent,IsAppend){
		if (IsAppend==true)
			ObjBody.innerHTML += sContent
		else
			ObjBody.innerHTML = sContent
	}
	this.loadContent	= function(strFile){Ajax().get(strFile,function(RetString){ObjBody.innerHTML = UrlDecode1(RetString)})}
	this.setClass		= function(myClass){this.className = myClass}
	this.setTitleBgc	= function(myBgc)	{ObjHead.style.backgroundColor = myBgc}
	this.Remove			= function()		{this.ObjDiv.parentNode.removeChild(this.ObjDiv)}
}

var CommonTip1
function ShowCommonTip(str){
	CommonTip1	= new DivMsgBox("Common_Tip1",5,"","","#3A6EA5","#FFFFFF","#FF0000",300,40,1,100)
	CommonTip1.setPadding(null,null,12,null)
	CommonTip1.setContent(str)
	CommonTip1.Show()
	AbsLocalDiv(CommonTip1.ObjDiv)
	setTimeout("CommonTip1.Remove()",3000)
}


//86148850

/*Div特效*/
function DivEffects(TheObj,EffNo,ArrPara,Delay){
	var ObjDiv
	if (typeof(TheObj)=="object") ObjDiv = TheObj
	if (typeof(TheObj)=="string") ObjDiv = document.getElementById(TheObj)
	if (typeof(ObjDiv)!="object"){alert("函数参数有误!");return null;}
	var MyTimer1 = null
	var MyAlpha
	
	if (Delay==null || Delay<0) Delay = 100
	switch(EffNo){ 
		case 1: //渐现：ArrPara(初始值，步长，终止值)
			if (ArrPara.length!=3) {alert("EffNo:"+EffNo+"　参数错误：ArrPara(初始值，步长，终止值)！");return null;}
			if (ArrPara[0]==null) ArrPara[0] = 0
			MyAlpha = ArrPara[0]
			ObjDiv.style.filter		= "alpha(Opacity="+MyAlpha+")";
			ObjDiv.style.display	= ""
			Eff1();	break;
		case 2: //渐隐：ArrPara(步长，终止值)
			if (ArrPara.length!=2) {alert("EffNo:"+EffNo+"　参数错误：ArrPara(初始值，步长，终止值)！");return null;}
			var MyAlpha = GetAlpha(ObjDiv.style.filter)
			Eff2();
			break;
	}

	//渐隐渐现
	function Eff1(){MyTimer1 = setInterval(Eff1Action,Delay);}
	function Eff1Action(){
		if (MyAlpha<=ArrPara[2]){
			ObjDiv.style.filter = "alpha(Opacity="+MyAlpha+")";
			MyAlpha+=ArrPara[1];
		}else{
			clearInterval(MyTimer1)
		}
	}
	
	//渐现渐隐
	function Eff2(){MyTimer1 = setInterval(Eff2Action,Delay);}
	function Eff2Action(){
		if (MyAlpha>=ArrPara[1]){
			ObjDiv.style.filter = "alpha(Opacity="+MyAlpha+")";
			MyAlpha+=ArrPara[0];
		}else{
			clearInterval(MyTimer1)
			ObjDiv.style.display	= "none"
		}
	}
	
	//从ObjDiv.style.filter中取出alpha的值
	function GetAlpha(strFlter){
		var ArrTmp = strFlter.split("=")
		return Number(ArrTmp[1].replace(")",""))
	}
}