//===========================================================
//==         qq:93333147,Email:zhangyuanjun@126.com        ==
//==               Code By Arjun                           ==
//===========================================================
/**
显示在中中间边框透明的窗口，可带确认取消按扭 **/

function CenterWindow()
	{
		this.ID="CenterWindow";
		this.Width=400; //窗口宽度
		this.Title="";
		this.THeight=30;
		this.TColor="#000"; //标题颜色
		this.TBgColor="#CFDEF8";
		this.Content="";
		this.CColor="#000000"; //内容颜色
		this.CBgColor="#ffffff"; ///内容背景颜色
		this.Bottom="";
		this.BColor="#000000";
		this.BBgColor="#E3E3E6";
		this.BTopBorderColor="#89848A";
		this.BHeight=30;
		this.alphaWidth=8; //透明边框宽度
//		this.TClassName="CenterWindowTitle"; //标题栏样式名称
        this.TClassName=""; //标题栏样式名称
		this.Confirm=function()
		{
			
		}
		this.Cancle=function()
		{
			
		}
		this.ConfirmButton="确定";
		this.CancleButton="取消";
		var ID=this.ID;
		this.Close=function()
		{
			var div=document.getElementById(ID);
			if(div)
			{
				div.parentNode.removeChild(div);
			}
			var aDiv=document.getElementById("a"+ID);
			if(aDiv)
			{
				aDiv.parentNode.removeChild(aDiv);
			}
		}
		this.Create=function()
		{
		    this.Close();
			var HTML='';
			var bottomHTML='';
			if(this.ConfirmButton!="")
			{
				bottomHTML+='<input type="button" class=\"f-button\" value="'+this.ConfirmButton+'" id="centerwindowconfirm"/>';
			}
			if(this.CancleButton!="")
			{
				bottomHTML+='&nbsp;&nbsp;<input type="button" class=\"f-reset\" 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;">';
			
			if(this.TClassName==""||this.TClassName==null||this.TClassName==undefined)
			{
			    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;padding-right:10px;" class="'+this.TClassName+'"><table style="width:100%"><tr><td>'+this.Title+'</td><td align="right"><img id="centerwindowclose" src="../../template/images/close_05.gif" style="cursor:hand" /></td></tr></table></div>';
			}
			else
			{
			    HTML +=' 				<div style="height:'+this.THeight+'px;font-weight:600;line-height:'+this.THeight+'px;padding-left:10px;padding-right:10px;" class="'+this.TClassName+'"><table style="width:100%"><tr><td>'+this.Title+'</td><td align="right"><img id="centerwindowclose" src="../../template/images/close_05.gif" style="cursor:hand" /></td></tr></table></div>';
			}
			HTML +=' 			</div>';
			HTML +=' 			<div style="height:100%;color:'+this.CColor+';background-color:'+this.CBgColor+';padding-top:'+this.THeight+'px;padding-bottom:'+this.BHeight+'px">';
			HTML +=' 				<div style="padding:5px;"><div>';
			HTML +=' 				'+this.Content+'';
			HTML +=' 				</div></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+"px";
			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.documentElement.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="#243768";
			aDiv.style.zIndex="10";
			var w=this.Width+this.alphaWidth*2;
			var h=div.offsetHeight+this.alphaWidth*2;
			var x=(left-this.alphaWidth);
			var y=(top-this.alphaWidth);
			aDiv.style.width=w+"px";
			aDiv.style.height=h+"px";
			aDiv.style.top=y+"px";
			aDiv.style.left=x+"px"

			aDiv.style.filter="alpha(opacity=50);";
			aDiv.setAttribute("style","position:absolute;width:"+w+"px;height:"+h+"px;top:"+y+"px;left:"+x+"px;z-index:10;background-color:#243768;-moz-opacity:0.55;opacity: 0.55;");

			var Confirm=this.Confirm;
			var Cancle=this.Cancle;
			var Clo=this.Close;
			if(this.ConfirmButton!=""&&document.getElementById("centerwindowconfirm"))
			{
				document.getElementById("centerwindowconfirm").onclick=Confirm;
			}
			if(this.CancleButton!=""&&document.getElementById("centerwindowcancle"))
			{
				document.getElementById("centerwindowcancle").onclick=Cancle;
			}
			document.getElementById("centerwindowclose").onclick=Clo;
		}
	}
//-------用法--------------
//var wi=new CenterWindow();
//wi.Title="你确定要这样操作吗？";
//wi.TColor="#ffffff";
//wi.Content="fdsfsdfsd";
//wi.Confirm=function()
//{
//	alert("确定");
//}
//wi.Cancle=function()
//{
//	wi.Close();
//}
//wi.Create();


function WinTip(title,msg)
{
    var wi=new CenterWindow();
    wi.Title=title;
    wi.Content=msg;
    wi.CancleButton="";
    wi.ConfirmButton="确定";
    wi.Confirm=function()
    {
	    wi.Close();
    }
    wi.Create();
    return wi;
}


//运行 ajax 
//f 函数名称, 
//param 参数以|分隔
//callbak 回调函数
function runAjax(f,param,callbak)
{
    var  options={  
    method:"post",  
    parameters:"action="+f+"&param="+param,  
    onComplete:function(transport)
    {  
            var returnvalue=transport.responseText;
            callbak(returnvalue);
        }  
    }; 
    new Ajax.Request("ajax/ajax.aspx?iiii="+Math.random(),options);  
    return false;
}

///删除应用
function deleteApp(id)
{
    var a=confirm("确定要删除此应用吗？");
    if(!a)
    {
        return false;
    }
    WinTip("提示信息","正在删除应用...！");
    runAjax("deleteApp",id,function(text)
    {
        var n=parseInt(text);
        if(n>0)
        {
            WinTip("提示信息","删除成功！");
            var obj=$("tr"+id);
            if(obj)
            {
                obj.parentNode.removeChild(obj);
            }
        }
        else
        {
            WinTip("提示信息","删除失败！");
        }
    }
    );
}
function AddApp(id)
{
    WinTip("提示信息","正在添加应用...！");
    runAjax("AddApp",id,function(text)
    {
        var n=parseInt(text);
        if(n>0)
        {
            WinTip("提示信息","添加成功！");
            setTimeout(function(){location.href='applist.aspx';},300);
        }
        else
        {
            if(n---3)
            {
                WinTip("提示信息","此应用还没有经过审核！");
            }
            WinTip("提示信息","添加失败！");
        }
    });
}