function TWSRequest(_target, _method, _callback)
{
    var requestObject = null;
    if (window.XMLHttpRequest) // Firefox, Opera 8.0+, Safari
    {
        requestObject = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
    	{
        	requestObject = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
    	{
    		requestObject = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    }
    
    if (requestObject)
    {
        requestObject.open(_method, _target, true);
        requestObject.onreadystatechange = function()
        {
            if (requestObject.readyState == 4)
            {
                if(requestObject.status == 200)
               	{
	                if(requestObject.responseText)
	                	_callback(requestObject.responseText);
	                delete requestObject;
	            }
            }
        }
        requestObject.send(null);
    }
}


var _bgId, _contentId; 
var _retValId, _width, _height, _callback, _title;

// create <div> on the fly
// note: cannot use it inside table tag (IE)
function init_twspopup(width, height)
{
	_width  = eval(width);
	_height = eval(height);
	
	if(!bgBox)
	{
		bgBox = document.createElement('div');
	   	bgBox.setAttribute('id','bg_twspopup');
	   	bgBox.style.filter = "alpha(opacity=15)";
		bgBox.style.opacity = "0.15";
		bgBox.style.position='absolute';
		bgBox.style.backgroundColor='#000000';
		bgBox.innerHTML='&nbsp;';
		document.body.appendChild(bgBox);
	}	
	
	if(!contentBox)
	{
		contentBox = document.createElement('div');
		contentBox.setAttribute('id','box_twspopup');
		contentBox.setAttribute('align','center');
		contentBox.style.position='absolute';     
		contentBox.style.backgroundColor='#000000';
		contentBox.style.visibility='visible';
		document.body.appendChild(contentBox);			
	}	
	close_twspopup();
}

// call this when you have defined the <div> tag
function init_twspopup(bgId, contentId, width, height)
{
	_width  = eval(width);
	_height = eval(height);
	_bgId   = bgId;
	_contentId = contentId;
		
	bgBox = document.getElementById(_bgId);
	if(bgBox)
	{
	   	bgBox.setAttribute("style","z-index: 500; filter: alpha(opacity=15); opacity: 0.15; position: absolute; background-color: #000000; left: 0; top: 0; width: 0; height: 0; visibility: hidden");
	   	bgBox.innerHTML='&nbsp;';
	}
	
	contentBox = document.getElementById(_contentId);
	if(contentBox)
	{
		contentBox.setAttribute("style","z-index: 500; position: absolute; background-color: #000000; left: 0; top: 0; width: 0; height: 0; visibility: hidden");
		contentBox.innerHTML='&nbsp;';
	}	
	close_twspopup();
}


function centerWin_twspopup() 
{   
	contentBox = document.getElementById(_contentId);
	if(contentBox)
	{
		var sw = document.body.scrollWidth;	
		var sh = window.screen.availHeight;
		contentBox.style.left=(sw-_width)/2;
		contentBox.style.top=document.body.scrollTop+(sh-_height)/4;
	}	
}

function showBg_twspopup(isShow) 
{
	bgBox = document.getElementById(_bgId);
	if(bgBox)
	{
		if(isShow)
		{
			bgBox.style.left='0';
			bgBox.style.top='0';
			var w = document.body.scrollWidth;
			var h = document.documentElement.clientHeight;
			if(!h)
				h = document.body.scrollHeight;
			bgBox.style.width=w;
			bgBox.style.height=h;
			bgBox.style.visibility='visible';
		}else{
			bgBox.style.left='0';
			bgBox.style.top='0';
			bgBox.style.width='0';
			bgBox.style.height='0';
			bgBox.style.visibility='hidden';
		}	
	}	
}

function exec_twspopup(title, url, retValId, callback) 
{
	_retValId = retValId;
	_callback = callback;
	_title	  = title;	
	TWSRequest(url, "GET", content_twspopup);	
}

function close_twspopup() 
{
	showBg_twspopup(false);
	contentBox = document.getElementById(_contentId); 	
	if(contentBox)
	{
		contentBox.style.left='0';
		contentBox.style.top='0';
		contentBox.style.width='0';
		contentBox.style.height='0';
		contentBox.style.visibility='hidden';
	}	
}

function sendValue_twspopup() 
{
	var cRetVal = document.getElementById(_retValId);
	if(cRetVal)
	{
		var type = cRetVal.getAttributeNode('type').nodeValue;
		var retVal = "";
		if(type.toLowerCase()=="radio")
		{
			var f = document.getElementsByName(_retValId);
			for(var iIndex=0;iIndex<f.length;iIndex++)
			{
				if(f[iIndex].checked)
					retVal = f[iIndex].value;
			}
		}
		else
		{
			retVal = cRetVal.value; 
		}		
		_callback(retVal);	
	}
	close_twspopup();	
}

function content_twspopup(msg)
{
	contentBox = document.getElementById(_contentId);
	if(contentBox)
	{
		contentBox.style.width=_width;
		contentBox.style.height=_height;
		centerWin_twspopup();
		contentBox.innerHTML= '<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0" style="border: 3px solid #fb7303">'+
					   		  '<tr><td width="100%" align="center" style="background-color: #fb7303;border-bottom: 3px solid #fb7303; padding: 5px;"><font style="arial" size="2" color="#FFFFFF"><B>'+_title+'</B></font></td>'+
					   		  '<td width="10" align="center" style="background-color: #001932; border-bottom: 3px solid #fb7303; padding: 5px;">'+
					   		  '<a href="javascript:close_twspopup();" style="text-decoration: none;"><font style="arial" size="2" color="#FFFFFF"><B>X</B></font></a></td></tr>'+
					   		  '<tr><td colspan="2" align="center">'+msg+'</td></tr></table>';					   		  
		contentBox.style.visibility='visible';
		showBg_twspopup(true);
	}
}
