function FixPotoSize(image,maxWidth,maxHeight)
{
	if(image.width>maxWidth)
	{
		image.height=image.height*(maxWidth/image.width);
		image.width=maxWidth;
	}
	if(image.height>maxHeight)
	{
		image.width=image.width*(maxHeight/image.height);
		image.height=maxHeight;
	}
}

function DeleteRowByControlInCell(control)
{
	var table;
	var row;
	for(table=control;table.tagName!="TABLE";table=table.parentElement)
		if(table.tagName=="TR")
			row=table;
	table.deleteRow(row.rowIndex);
}

function GetCookieVal(offset)
//获得Cookie解码后的值
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie(name, value)
//设定Cookie值
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}

function DelCookie(name)
//删除Cookie
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function GetCookie(name)
//获得Cookie的原始值
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

function ShowDialog(html,width,height)
{
	var logindivWidth,logindivHeight;
	logindivWidth = document.body.offsetWidth;
	if( document.body.clientHeight >= screen.height )
		logindivHeight = document.body.clientHeight;
	else
		logindivHeight = document.body.scrollHeight ;
	//生成全屏的DIV层
	var bgObj1=document.createElement("div");
	bgObj1.setAttribute('id','CoverLayer');
	bgObj1.style.position = "absolute";
	bgObj1.style.top = "0";
	bgObj1.style.background = "#fff";
	bgObj1.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=100,finishOpacity=90)";
	bgObj1.style.opacity = "0.6";
	bgObj1.style.left = "0";
	bgObj1.style.width = logindivWidth + "px";
	bgObj1.style.height = logindivHeight + "px";
	bgObj1.style.zIndex = "1";
	document.body.appendChild( bgObj1 );
	
	var layer=window.document.createElement("div");
	// style='border: 2 navy solid;display:none;z-index:1000;position:absolute;left:150px;top:50px'>
	layer.style.width=width;
	layer.style.zIndex=1000;
	layer.style.position="absolute";
	layer.style.left=(logindivWidth-width)/2;
	layer.style.top= (logindivHeight-height)/2;
	layer.style.border="2 #404040 solid";

	var contentLayer=window.document.createElement("div");
	contentLayer.style.width=width;
	contentLayer.style.height=height;
	contentLayer.innerHTML=html;
	layer.appendChild(contentLayer);
	var closeLink=window.document.createElement("a");
	closeLink.href="JavaScript:HideDialog()";
	closeLink.innerText="关闭";
	closeLink.style.width="100%";
	closeLink.style.textAlign="right";
	layer.insertBefore(closeLink,contentLayer);
	
	bgObj1.appendChild(layer);
	//DialogTable.style.display="";
}
function HideDialog()
{
	window.document.body.removeChild(CoverLayer);
	//DialogTable.style.display="none";
}

function PrintImage(imageUrl)
{
	var frame=window.document.createElement("iframe");
	frame.id="PrintFrame";
	frame.style.display="none";
	window.document.body.appendChild(frame);
	PrintFrame.document.write("<style type=text/css>body{margin:0;}</style>");
	PrintFrame.document.write("<img src="+imageUrl+" />");
	PrintFrame.document.close();
	PrintFrame.print();
	window.document.body.removeChild(frame);
}
