﻿function $(a){return document.getElementById(a);}
function hidden_div(obj){$(obj).style.display='none';}
//透明层
function showMask(){
	if($("tianyi-Mask"))
	{var oMask=$("tianyi-Mask");}
	else 
	{
		var oMask=document.createElement("DIV");
			oMask.id="tianyi-Mask";
			oMask.style.cssText = "position:absolute;left:0px;top:0px;background:#000;filter:Alpha(opacity=60);opacity:0.6";
		document.body.appendChild(oMask);
	}
		oMask.style.display = "block";
		oMask.style.width =  document.documentElement.scrollWidth + "px";
		oMask.style.height =  document.documentElement.scrollHeight + "px";
}

function showajaxdiv(obj,content,width,height,sty)
{
	if($("tianyi-"+obj))
	{
		var oDiv=$("tianyi-"+obj);
	}
	else 
	{
		var oDiv=document.createElement("DIV");
			oDiv.id="tianyi-"+obj;
			oDiv.className="ajaxdiv";
		document.body.appendChild(oDiv);
	}
	var st = window.pageYOffset || document.documentElement.scrollTop;
	var sl = window.pageXOffset || document.documentElement.scrollLeft;
	var bt = document.documentElement.clientHeight-height;
	var bl = document.documentElement.clientWidth-width;
	var top=(bt/2)+st-5;
	var left=(bl/2)+sl;
	var oDivStyle=oDiv.style;
		oDivStyle.display="";
		oDivStyle.width=width+"px";
		oDivStyle.top=top+"px";
		oDivStyle.left=left+"px";
		oDivStyle.position='absolute';
		oDivStyle.fontSize='12px';
		if (sty==1)
		{
			oDivStyle.padding='8px';
			oDivStyle.backgroundColor='#FFFBDF';
			oDivStyle.color='#f10';
			oDivStyle.border='1 solid #EF9B8F';
		}
		else
		{
			oDivStyle.padding='5px';
			oDivStyle.backgroundColor='#AAA';
			oDivStyle.color='#fff';
			oDivStyle.border='0';
		}
		oDivStyle.textAlign='center';
		oDiv.innerHTML=content;
}
//提示
function Msg(content){
	showajaxdiv("msg",content,200,30,1)
	setTimeout("hidden_div('tianyi-msg');",2000);
}

function showimg(url) {
var wx=document.documentElement.clientWidth-40
var hx=document.documentElement.clientHeight-40
var img = new Image();
	img.src = url;
	showajaxdiv("imgline","图片加载中……",200,30);
	img.complete?ImgOK():img.onload=ImgOK;
	function ImgOK(){
		showMask()
		var width=img.width;
		var height=img.height;
		if(width>wx){height=(wx/width)*height;width=wx;}
		if(height>hx){width=(hx/height)*width;height=hx;}
		$("tianyi-imgline").style.display='none';
		var pstr="<a href="+url+" target=\"_blank\"><img src=\"images/newwindow.gif\" title=\"查看原图\" style=\"cursor:pointer;border:0px;position:absolute;right:15px;top:15px;\"></a>"
		showajaxdiv("img",pstr+"<img src="+url+" onclick=\"hidden_div('tianyi-Mask');hidden_div('tianyi-img');\" style=\"cursor:pointer;width:"+width+"px;height:"+height+"px;\" title=\"点击关闭\">",width,height,0);return;}
}
