//对HTML代码的转义操作

function HTMLEncode(str)
{
	var s = "";
	if(str.length == 0)
		return "";
	s = str.replace(/&/g, "&amp;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/ /g, "&nbsp;");
	s = s.replace(/\'/g, "&#39;");
	s = s.replace(/\"/g, "&quot;");
	s = s.replace(/\r/g, "");
	s = s.replace(/\n/g, "<br>");
	return s;
}

function HTMLDecode(str)
{
	var s = "";
	if(str.length == 0)
		return "";
	s = str.replace(/&amp;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, " ");
	s = s.replace(/&#39;/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}

//对URL字符串的转义操作

function URLDecode(strInput)
{
//	strInput = strInput.toLowerCase();
	strInput = strInput.replace(/\+/g, ' ');
	strInput = strInput.replace(/\%40/g, '@');
	strInput = strInput.replace(/\%23/g, '#');
	strInput = strInput.replace(/\%24/g, '$');
	strInput = strInput.replace(/\%26/g, '&');
	strInput = strInput.replace(/\%2b/g, '+');
	strInput = strInput.replace(/\%2B/g, '+');
	strInput = strInput.replace(/\%3d/g, '=');
	strInput = strInput.replace(/\%3D/g, '=');
	strInput = strInput.replace(/\%3b/g, ';');
	strInput = strInput.replace(/\%3B/g, ';');
	strInput = strInput.replace(/\%3a/g, ':');
	strInput = strInput.replace(/\%3A/g, ':');
	strInput = strInput.replace(/\%2f/g, '/');
	strInput = strInput.replace(/\%2F/g, '/');
	strInput = strInput.replace(/\%3f/g, '?');
	strInput = strInput.replace(/\%3F/g, '?');
	strInput = strInput.replace(/\%2c/g, ',');
	strInput = strInput.replace(/\%2C/g, ',');
	return decodeURI(strInput);
}

function URLEncode(strInput)
{
	strTmp = encodeURI(strInput);
	strTmp = strTmp.replace(/\ /g, '+');
	strTmp = strTmp.replace(/\@/g, '%40');
	strTmp = strTmp.replace(/\#/g, '%23');
	strTmp = strTmp.replace(/\$/g, '%24');
	strTmp = strTmp.replace(/\&/g, '%26');
	strTmp = strTmp.replace(/\+/g, '%2B');
	strTmp = strTmp.replace(/\=/g, '%3D');
	strTmp = strTmp.replace(/\;/g, '%3B');
	strTmp = strTmp.replace(/\:/g, '%3A');
	strTmp = strTmp.replace(/\//g, '%2F');
	strTmp = strTmp.replace(/\?/g, '%3F');
	strTmp = strTmp.replace(/\,/g, '%2C');
	return strTmp;
}

function CloseDialog(id)
{
	if(document.getElementById(id + "_bg") != null)
		document.getElementById(id + "_bg").style.display = "none";
	if(document.getElementById(id + "_dlg") != null)
		document.getElementById(id + "_dlg").style.display = "none";
	return false;
}

function ShowPicDialog(id, url, w, h)
{
	if(document.getElementById(id + "_bg") == null)
	{
		var bgObj=document.createElement("div"); 
		bgObj.frameBorder = "0";
		bgObj.setAttribute('id', id + "_bg"); 
		bgObj.style.position="absolute"; 
		bgObj.style.top="0"; 
//		bgObj.src = "about:blank";
		bgObj.style.background="#FFFFFF"; 
		bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=50)"; 
		bgObj.style.opacity="0.5"; 
		bgObj.style.left="0"; 
		bgObj.style.width="100%"; 
//		alert("document.documentElement.clientWidth:" + document.documentElement.clientWidth);
		bgObj.style.height= (document.documentElement.scrollHeight <document.documentElement.clientHeight?document.documentElement.clientHeight:document.documentElement.scrollHeight) + "px"; 
		bgObj.style.zIndex = "10000"; 
		bgObj.onclick = function () {
			if(document.getElementById(this.id) != null)
				document.getElementById(this.id).style.display = "none";
			if(document.getElementById(this.id.replace("_bg", "") + "_dlg") != null)
				document.getElementById(this.id.replace("_bg", "") + "_dlg").style.display = "none";
		}
		
		document.body.appendChild(bgObj); 
		
		var dlgObj = document.createElement("div");
		dlgObj.setAttribute("id", id + "_dlg");
		dlgObj.style.position="absolute"; 
		dlgObj.style.top="50%"; 
		dlgObj.style.background="#EEE"; 
		dlgObj.style.left="50%"; 
		dlgObj.style.width= w + "px"; 
		dlgObj.style.height= h + "px"; 
		dlgObj.style.marginLeft = "-" + w/2 + "px";
		dlgObj.style.marginTop = "-" + h/2 + "px";
		dlgObj.style.zIndex = "10001";
		dlgObj.style.border = "1px solid #CCCCCC";
		
		dlgObj.innerHTML = "<iframe src=\""+url+"\"scrolling=\"no\" frameborder=\"0\" style=\"width:"+(w-6)+"px;height:"+(h-6)+"px;margin:3px;\" />";
		 
		document.body.appendChild(dlgObj); 
	}
	else
	{
		document.getElementById(id + "_bg").style.display = "";
		document.getElementById(id + "_dlg").style.display = "";
	}
	return false;
}

function ShowDialog(id, url, w, h)
{ 
	if(document.getElementById(id + "_bg") == null)
	{
		var bgObj=document.createElement("iframe"); 
		bgObj.frameBorder = "0";
		bgObj.setAttribute('id', id + "_bg"); 
		bgObj.style.position="absolute"; 
		bgObj.style.top="0"; 
		bgObj.src = "about:blank";
		bgObj.style.background="#FFFFFF"; 
		bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=50)"; 
		bgObj.style.opacity="0.5"; 
		bgObj.style.left="0"; 
		bgObj.style.width="100%"; 
//		alert("document.documentElement.clientWidth:" + document.documentElement.clientWidth);
		bgObj.style.height= (document.documentElement.scrollHeight <document.documentElement.clientHeight?document.documentElement.clientHeight:document.documentElement.scrollHeight) + "px"; 
		bgObj.style.zIndex = "10000"; 
		
		document.body.appendChild(bgObj); 
		
		var dlgObj = document.createElement("div");
		dlgObj.setAttribute("id", id + "_dlg");
		dlgObj.style.position="absolute"; 
		dlgObj.style.top="50%"; 
		dlgObj.style.background="#FFFFFF"; 
		dlgObj.style.left="50%"; 
		dlgObj.style.width= w + "px"; 
		dlgObj.style.height= h + "px"; 
		dlgObj.style.marginLeft = "-" + w/2 + "px";
		dlgObj.style.marginTop = "-" + h/2 + "px";
		dlgObj.style.zIndex = "10001";
		dlgObj.style.border = "1px solid #CCCCCC";
		
		dlgObj.innerHTML = "<iframe src=\""+url+"\"scrolling=\"no\" frameborder=\"0\" style=\"width:"+(w-6)+"px;height:"+(h-6)+"px;margin:3px;\" />";
		 
		document.body.appendChild(dlgObj); 
	}
	else
	{
		document.getElementById(id + "_bg").style.display = "";
		document.getElementById(id + "_dlg").style.display = "";
	}
	return false;
} 

