
//************************************************/
//特效处理层
//************************************************/
function MsPrintDiv(Type,Msg,url){
	MsPrintDivDel();//删除已存在的处理层
	var div = document.createElement("SPAN");
	div.id = "MsPrintDiv";
	$(div).attr("class","MsPrintDiv");
	div.style.position = "absolute";
	div.style.zIndex = "999";
	div.style.display = "block";
    div.style.padding = "8px 10px 8px 30px";   
	switch (Type) {
        case "success":
            div.style.border = "1px solid #CCF9C1";
            div.style.color = "#009900";
            div.style.background = "url('/Power/Images/correct.gif') 8px center no-repeat #F1FEF2";
            break;
        case "error":
            div.style.border = "1px solid #F9F2B7";
            div.style.color = "#FF0000";
            div.style.background = "url(/Power/Images/disable.gif) 8px center no-repeat #FDF8E8";
            break;
        default:
            div.style.border = "1px solid #FAF4B8";
            div.style.color = "#C52716";
            div.style.background = "url(/Power/Images/warning.gif) 8px center no-repeat #FEFDE9";
            break;
    }
	if(document.all)	//设置IE浏览器上半透明
		div.style.filter = "alpha(opacity=85)";
	else	//设置FF浏览器上半透明
		div.style.opacity = "0.85";
	var page = new getPageInfo();
	div.style.top = (page.height/3 + page.scrollHeight()) + "px";
	div.style.left = (page.width/3+60) + "px";
	div.innerHTML = Msg;
	setTimeout(function(){$("body").append(div);},100);
	setTimeout("MsPrintDivMove()",100);
	setTimeout(function(){
	    $(".MsPrintDiv").show();
        $(".MsPrintDiv").fadeOut(600);
	},800);
	setTimeout(function() {	   
        //如果动画结束则删除节点        
        url = url.toString();
        $(".MsPrintDiv").remove();
         //转向URL
        if (url == "back") {
            window.history.back(-1);
        } else if (url != ""&&url&&url!="undefined") {
            document.location.href = url;
        }        
    }, 1300);
}

//************************************************/
//0.5秒后把处理层移至底部
//************************************************/
function MsPrintDivMove(){
	var div = $(".MsPrintDiv");
	if(div.length==0){return;}
	var page = new getPageInfo();
	div.css("top",(page.height/3 + page.scrollHeight()) + "px");
	setTimeout("MsPrintDivMove()",100);
}

//************************************************/
//删除处理层
//************************************************/
function MsPrintDivDel(){
	$(".MsPrintDiv").remove();
}


//***********************************************/
//重新设置父窗口Iframe的高度
//IframeName:父窗口Iframe的名称
//***********************************************/
function ResetIframeH(){
	var ParentIframe = parent.document.getElementsByTagName("IFRAME");
	if(!ParentIframe.length){return;}
	for(var i = 0; i < ParentIframe.length; i++){
		if(ParentIframe[i].contentWindow == window){
			ParentIframe[i].style.height = document.body.scrollHeight+"px";
			break;
		}
	}
}


//单击超级连接选中单选或者多选按钮
function CheckedButton(Tag,Values)
{
	//alert(Tag)
	var obj=document.getElementsByName(Tag);
	//alert(obj.length)
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].value==Values){obj[i].click();}	
	}
}


//****************************************************/
//获取页面信息,包括:宽度、高度、滚动高度。
//****************************************************/
function getPageInfo(){
	//页面的宽度
	this.width = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
	//页面的高度
	this.height = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	//页面的滚动高度
	this.scrollHeight = function(){return (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;}
	//this.scrollHeight = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;
}

//************************************************/
//Powered by ECENCO.COM-Tech2  2009年1月10日星期六
//创建一个<script>对象
//************************************************/
function createJavascript(ID,url){
	var js = document.getElementById(ID);
	if(js)
		document.body.removeChild(js);
	var js = document.createElement("SCRIPT");
	js.id = ID;
	js.src = url;
	document.body.appendChild(js);
}

//检查同名的checkbox中有没有被选中,有返回true，没有返回false
function selectIsCheck(name){
	var obj = document.getElementsByName(name);
	for (var i = 0; i < obj.length; i++){
		if (obj[i].checked){
			return true;	
		}	
	}
	return false;
}
function selectAll(state,name) {   
    var ids = document.getElementsByName(name);   
    for (var i = 0; i < ids.length; i++){          
            ids[i].checked = state;   
    }   
}

//************************************************/
//初始化单选/复选框值
//obj:单选/复选框对象
//val:选中的值,以逗号分隔
//************************************************/
function setupRCSelect(obj,val){
	if(!obj){return;}
	val = val.replace(/true/gi,"1");
	val = val.replace(/false/gi,"0");

	if(typeof(obj.length) == "undefined"){
		if(obj.tagName.toUpperCase() == "INPUT" && obj.type.toLowerCase() == "radio" && val.length == 0)
			val = "0";
		obj.checked = false;
		if(("," + val + ",").indexOf("," + obj.value + ",") != -1)
			obj.click();
	}else if(obj.length != 0){
		if(obj[0].tagName.toUpperCase() == "OPTION"){
			obj = obj.options;
			for(var i = 0; i < obj.length; i++){
				if(("," + val + ",").indexOf("," + obj[i].value + ",") != -1)
					obj[i].selected = true;
			}
		}else if(obj[0].tagName.toUpperCase() == "INPUT"){
			val = (obj[0].type.toLowerCase() == "radio" && val.length == 0) ? "0" : val;
			for(var i = 0; i < obj.length; i++){
				obj[i].checked = false;
				if(("," + val + ",").indexOf("," + obj[i].value + ",") != -1)
					obj[i].click();
			}
		}
	}
}

//************************************************/
//创建半透明层
//Color:半透明层的颜色
//Opacity:不透明程度	0(完全透明)-10(不透明)
//************************************************/
function CreateAlpahaDiv(Color,Opacity){
	var CheckAlpahaDiv=document.getElementById("AlpahaDiv");
	if(CheckAlpahaDiv){document.body.removeChild(CheckAlpahaDiv);}	//如果已经创建半透明层,则删之
	
	var IE_Opacity=String(Opacity*10);
	var FF_Opacity=String(Opacity/10);
	//页面的宽度
	var PageW = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;	
	var AlpahaDiv=document.createElement("div");
	AlpahaDiv.id="AlpahaDiv";
	AlpahaDiv.style.position="absolute";
	AlpahaDiv.style.left="0px";
	AlpahaDiv.style.top="0px";
	AlpahaDiv.style.background=Color;
	if(document.all){
		AlpahaDiv.style.filter="alpha(opacity="+IE_Opacity+")";
	}else{
		AlpahaDiv.style.opacity=FF_Opacity;
	}
	AlpahaDiv.style.zIndex="109";
	AlpahaDiv.style.width=PageW+"px";
	AlpahaDiv.style.height=document.body.scrollHeight+"px";
 	document.body.appendChild(AlpahaDiv);
}
//************************************************/
//删除半透明层
//************************************************/
function DelAlpahaDiv(){
	var CheckAlpahaDiv=document.getElementById("AlpahaDiv");
	if(CheckAlpahaDiv){document.body.removeChild(CheckAlpahaDiv);}
}

//***********************************************/
//把时间转换成14位数字,不够14位用0补够
//***********************************************/
function dateTurnNum(Time){
	var re=/-|\/| |:/ig;
	var Time=Time.replace(re,",");
	var TimeArr=Time.split(",");
	for(var i=0;i < TimeArr.length;i++){
		if(parseInt(TimeArr[i]) < 10 && TimeArr[i].indexOf("0")==-1){
			TimeArr[i]="0"+TimeArr[i];
		}
	}
	var TimeStr=TimeArr.join("");
	if(TimeStr.length < 14){
		var TimeStrLen=14-TimeStr.length;
		for(var i=0;i < TimeStrLen;i++){
			TimeStr+="0";
		}
	}
	return parseInt(TimeStr);
}

//************************************************/
//Ajax异步执行
//************************************************/
function newAjax(url,fuc){
	url += "&rTime=" + new Date().getTime();
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){CallBack(fuc);};
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("If-Modified-Since","0"); 	//用户防止IE缓存
	xmlHttp.send(null);
    
    function createXMLHttpRequest(){
        if(window.ActiveXObject)
            return new ActiveXObject("Microsoft.XMLHTTP");
        else if(window.XMLHttpRequest)
            return new XMLHttpRequest();
    };
	
    function CallBack(fuc){		
        if(xmlHttp.readyState == 4){
            if(xmlHttp.status == 200){
				eval((fuc.substring(0,fuc.length -1) + ",xmlHttp.responseText)").replace("(,","("))
			}else
                alert("Not able to retrieve description" + xmlHttp.statusText);
        }
    };
}

//***********************************************/
//检测对象是否数组
//obj:数组对象
//***********************************************/
function isArray(obj){
	if(Object.prototype.toString.apply(obj) == "[object Array]")
		return true;
	else
		return false;
}

//************************************************/
//弹出居中的固定大小的窗口,统一使用
//使用例子:oW("index.htm","c_",{W:500,H:400,TB:'no',MB:'no'})
//************************************************/
function oW(url,id,o){
	var ary = new Array();
	var s = "";
	(o.W) ? ary.push("width=" + o.W) : o.W = 500;
	(o.H) ? ary.push("height=" + o.H) : o.H = 400;
	ary.push("left=" + ((screen.width - o.W) / 2));
	ary.push("top=" + ((screen.height - o.H) / 2));
	(o.TB) ? ary.push("toolbar=" + o.TB) : "";//是否显示工具栏
	(o.MB) ? ary.push("menubar=" + o.MB) : "";//是否显示菜单栏
	(o.SB) ? ary.push("scrollbars=" + o.SB) : "";
	(o.S) ? ary.push("status=" + o.S) : "";//是否显示状态栏内的信息
	window.open(url,id,ary.join(","));
}

//***********************************************/
//图片自动适应
//***********************************************/
function DrawImage(ImgD,W,H){
  var flag=false; 
  var image=new Image(); 
  var h=H
  image.src=ImgD.src; 
  if(image.width>0 && image.height>0){ 
    flag=true; 
    if(image.width/image.height>= W/H){
		H=(image.height*W)/image.width;
  		ImgD.style.marginTop=(h-H)/2+"px";
	}else{
		W=(image.width*H)/image.height;ImgD.style.marginTop="0px";
	}  
 	ImgD.width=W;
	ImgD.height=H; 
  }else{
	ImgD.style.marginTop=(H-image.height)/2+"px";
  } 
}

