/*
This javascript file include script used for asp vbinc function. Which will be included for all site.
e.g. inlined windows, auto complete 
*/

// ================================================================
// Inlined window
// ================================================================

var InlineWindowUtils = new function(){
	
	this.enableSetOpacity = true;
	this.MWJ_winZind = 65535;	
	this.iframeId = 'popupFrame_iwin';
	this.defaultURL = '/vbinc/blank.asp';
	
	// minize it and show smallest
	this.resetWin = function( obj ){		
		var oMax, oMin, iframeId		
		iframeId	= this.iframeId;		
		oMax		= obj.maxName;
		oMin		= obj.minName;
		document.getElementById( iframeId ).src = this.defaultURL;
		//this.resizeWinEx(oMax,oMin,50,50, iframeId );
		//this.moveWin( oMax, oMin, 50, 50 );
	}
	
	//resizeWin( nameOfMaximisedWindow, nameOfMinimisedWindow, desiredWidth, desiredHeight )
	this.show = function( obj, url, title, width, height, xPos, yPos ){		
		
		this.showEx(obj, url, title, width, height, xPos, yPos, true)
	}
	
	this.showEx = function( obj, url, title, width, height, xPos, yPos, bShowScrollBar ){		
		
		obj = CreateDefaultIWinEx( obj, bShowScrollBar );
		
		if ( IsIWinLayer() ) {
			if ( window.parent && window.parent.iwin_def ) 
			{
				// current iwin url = next url, do not open a new inline window.
				if ( window.parent.document.getElementById( window.parent.iwin_def.iframeId ).src == url ) 	return false;
			}	
		}
		
		var oMax, oMin, iframeId
		//iframeId = obj.maxName + '_iframe'		
		
		iframeId = this.iframeId;		
		oMax = obj.maxName;
		oMin = obj.minName;
		
		// resize the 		
		this.setTitle(obj, title);
		this.resizeWinEx(oMax,oMin,width,height, iframeId );
		this.showMinWin(oMax, oMin);		
		
		// set the iframe url
		document.getElementById( iframeId ).src = url;
		
		this.moveWin( oMax, oMin, xPos, yPos );
	}
	
	this.setTitle = function ( obj, text ){
		document.getElementById( obj.maxName + '_title' ).innerHTML = text;
	}

	this.showAtCenter = function( obj, url, title, width, height ){		
		var x, y
		x= (screen.width)?(screen.width-width)/2:100;
		
		// Better usability
		x =5; y =5;
		x = x + document.body.scrollLeft;
		y = y + document.body.scrollTop ;		
		this.show( obj, url, title, width, height, x, y );
	}
	
	this.showAtCenterNoScroll = function( obj, url, title, width, height ){		
		var x, y
		x= (screen.width)?(screen.width-width)/2:100;
		
		// Better usability
		x =5; y =5;
		x = x + document.body.scrollLeft;
		y = y + document.body.scrollTop ;		
		this.showEx( obj, url, title, width, height, x, y, false );
	}
	
		
	this.resizeWin = function(oMax,oMin,y,z) {	
		oMax = [this.getRefToDivNest(oMax),this.getRefToDivNest(oMin)]; if( !oMax[0] ) { return; }
		if( oMax[0].getElementsByTagName && document.childNodes ) {
			var oTitlSiz = oMax[0].offsetHeight - oMax[0].getElementsByTagName('div')[1].parentNode.offsetHeight;
			z = z - oTitlSiz; this.doActualResize(oMax,y,z,oTitlSiz);
	} }	
	
	this.createIWinLayer = function(mainContent,oTitle,oLeft,oTop,barColour,mainColour,oLogo,oMin,oMax,oClose,oFull,oDrag,oVis,oFullDrag,anyExtra,oScroll) {

		if( typeof( oFullDrag ) == 'undefined' ) { window.alert( 'New mini window script incompatible.' ); return; }
		window.MWJ_MINIWINS = window.MWJ_MINIWINS ? ( window.MWJ_MINIWINS + 1 ) : 1;
		
		if (typeof(mainContent) == 'object') {
		
			//0px solid --> 1px solid
			var fColor = "#000000"
			
			var oMinimName	= 'IWinMIN' + window.MWJ_MINIWINS;
			var oMaximName	= 'IWinMAX' + window.MWJ_MINIWINS;
			//var iframeId	= oMaximName + '_iframe';
			var iframeId	= this.iframeId;
			
			// Create a container for title
			oTitle = '<font id="' + oMaximName + '_title" >' + oTitle + '</font>'

			//create a frame and a dummy place holder (used in resize/drag)
			var scrollBar = mainContent[4] ? '' : ' scrolling="no" ';			
			var winContent = '<iframe src="' + mainContent[1] + '" id="' + iframeId +'" name="' + iframeId +'" style=" width:' + mainContent[2] + 'px; height:' + mainContent[3] + 'px; padding:5px; " frameborder="0"' + scrollBar + '></iframe><div id="' + iframeId +'_DPH" name="' + iframeId +'_DPH" style="display:none; width:' + mainContent[2] + 'px; height:' + mainContent[3] + 'px"  ></div>';			
			var oWidth = mainContent[2];			
			oScroll = false;
			
			var iwinDiv			
			var theDragString = ' onmousedown="InlineWindowUtils.clickDiv(\'' + oMaximName + '\',\'' + oMinimName + '\',arguments[0],false,\'' + iframeId + '\');return false;" onselectstart="return false;" ondragstart="return false;"';
			iwinDiv = '<div id="' + oMaximName + '" style="width:'+oWidth+'px;position:absolute;left:'+oLeft+'px;top:'+oTop+'px;visibility:'+((oVis==1)?'visible':'hidden')+';"'+(oFullDrag?theDragString:'')+'>'+
				(document.childNodes?('<div style="position:absolute;right:2px;bottom:2px;">'+((oDrag&&!oFullDrag)?'<img src="'+oDrag+'" height="11" width="11" border="0" alt="Resize." title="Resize." onmousedown="InlineWindowUtils.clickDiv(\'' + oMaximName + '\',\'IWinMIN'+window.MWJ_MINIWINS+
				'\',arguments[0],true,\'' + iframeId + '\');return false;" onselectstart="return false;" ondragstart="return false;" style="cursor:se-resize;" onmouseover="window.status=\'Drag to resize the mini window\';return true;" onmouseout="window.status=\'\';return true;">':'')+
				'</div>'):'')+'<table border="0" cellpadding="0" cellspacing="0" style="background-color:' + fColor + ';border-left:0px solid #dfdfdf;border-top:0px solid #dfdfdf;border-right:0px solid black;border-bottom:0px solid black;" width="100%"><tr>'+
				'<td style="background-color:' + fColor + ';border-left:0px solid white;border-top:0px solid white;border-right:0px solid #7f7f7f;border-bottom:0px solid #7f7f7f;">'+
				'<table border="0" cellpadding="0" cellspacing="1" width="100%" style="border:0px solid ' + fColor + ';"><tr><td>'+
				'<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' +
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' +
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close"></a></td>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" style="color:#ffffff;font-family:Arial,Sans-Serif;font-weight:bold;font-size:12px;cursor:default;" '+
				'onmouseover="window.status=\'Drag here to move the mini window\';return true;" onmouseout="window.status=\'\';return true;"'+
				(oFullDrag?'':theDragString)+' nowrap>'+oTitle+'</td><td bgcolor="'+barColour+'" align="right" valign="middle" width="34"><nobr>'+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'' + oMinimName + '\',\'' + oMaximName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to minimise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Minimise.">'+
				'<img src="'+oMin+'" border="0" height="16" width="16" alt="Minimise."></a>'+
				((oFull&&oDrag&&document.childNodes&&!oFullDrag)?'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.maximiseWin(\'' + oMaximName + '\',\'' + oMinimName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to maximise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Maximise.">'+
				'<img src="'+oFull+'" border="0" height="16" width="16" alt="Maximise."></a>':'')+
				'<a style="text-decoration:none;cursor:default;" ' + 				
				' onclick=" InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' +				
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></nobr></td></tr></table>'+
				'</td></tr><tr><td>'+((anyExtra&&document.childNodes)?anyExtra:'')+
				'<table border="0" cellpadding="4" cellspacing="0" style="'+
				'border-left:0px solid #7f7f7f;border-top:0px solid #7f7f7f;border-right:0px solid white;border-bottom:0px solid white;" width="100%">'+
				'<tr><td style="border-left:0px solid black;border-top:0px solid black;border-right:0px solid #dfdfdf;border-bottom:0px solid #dfdfdf;background-color:'+
				mainColour+';padding:0px;" valign="top">' + 
				'<div style="'+((oScroll&&document.childNodes&&!(!window.ActiveXObject&&!navigator.taintEnabled&&document.all)&&!(navigator.product=='Gecko'&&navigator.taintEnabled&&typeof(document.textContent)=='undefined')&&!(window.ActiveXObject&&!navigator.__ice_version&&window.ScriptEngineMajorVersion&&(ScriptEngineMajorVersion()+(0.1*ScriptEngineMinorVersion()))<5.5))?'overflow:auto;height:100%;':'')+'padding:0px;">'+
				winContent+'</div></td></tr></table></td></tr></table></td></tr></table></div>';
			iwinDiv = iwinDiv + '<div id="' + oMinimName + '" style="width:'+oWidth+'px;position:absolute;left:'+oLeft+'px;top:'+oTop+'px;visibility:'+((oVis==2)?'visible':'hidden')+';"'+(oFullDrag?theDragString:'')+'>'+
				'<table border="0" cellpadding="0" cellspacing="0" style="background-color:' + fColor + ';border-left:0px solid #dfdfdf;border-top:0px solid #dfdfdf;border-right:0px solid black;border-bottom:0px solid black;" width="100%"><tr>'+
				'<td style="background-color:' + fColor + ';border-left:0px solid white;border-top:0px solid white;border-right:0px solid #7f7f7f;border-bottom:0px solid #7f7f7f;">'+
				'<table border="0" cellpadding="0" cellspacing="1" width="100%" style="border:0px solid ' + fColor + ';"><tr><td>'+
				'<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' +
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close."></a></td>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" style="color:#ffffff;font-family:Arial,Sans-Serif;font-weight:bold;font-size:12px;cursor:default;" '+
				'onmouseover="window.status=\'Drag here to move the mini window\';return true;" onmouseout="window.status=\'\';return true;"'+
				(oFullDrag?'':theDragString)+' nowrap>'+oTitle+'</td><td bgcolor="'+barColour+'" align="right" valign="middle" width="34"><nobr>'+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'' + oMaximName + '\',\'' + oMinimName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to restore the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Restore.">'+
				'<img src="'+oMax+'" border="0" height="16" width="16" alt="Restore."></a>'+
				((oFull&&oDrag&&document.childNodes&&!oFullDrag)?'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'' + oMaximName + '\',\'' + oMinimName + '\');InlineWindowUtils.maximiseWin(\'' + oMaximName + '\',\'' + oMinimName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to maximise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Maximise.">'+
				'<img src="'+oFull+'" border="0" height="16" width="16" alt="Maximise."></a>':'')+
				'<a style="text-decoration:none;cursor:default;" ' +
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMinimName + '\'); return false" ' +
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></nobr></td></tr></table>'+
				'</td></tr></table></td></tr></table></div>' ;
		}
		else if( document.layers && !document.childNodes ) {
			var theDragString = ' onmouseover="this.captureEvents(Event.MOUSEDOWN);this.onmousedown = function () { InlineWindowUtils.clickDiv(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\',arguments[0]);return false; };"';
			iwinDiv = iwinDiv + '<layer bgcolor="' + fColor + '" name="IWinMAX'+window.MWJ_MINIWINS+'" width="'+oWidth+'" left="'+oLeft+'" top="'+oTop+'" visibility="'+((oVis==1)?'show':'hide')+'"'+(oFullDrag?theDragString:'')+'>'+
				'<table border="2" cellpadding="2" cellspacing="2" width="100%"><tr><td bgcolor="'+barColour+'">'+
				'<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>'+
				'<td align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close."></a></td>'+
				'<td align="left" valign="middle">'+(oFullDrag?'':'<ilayer width="'+(oWidth-74)+'" height="16" left="0" top="0"><layer width="'+(oWidth-74)+'" height="16" left="0" top="0"'+theDragString+'>')+
				'<font color="#ffffff" face="Arial" size="-1"><b>'+oTitle+
				'</b></font>'+(oFullDrag?'':'</layer></ilayer>')+'</td><td align="right" valign="middle" width="32">'+
				'<a ' + 
				' onclick="InlineWindowUtils.showMinWin(\'IWinMIN'+window.MWJ_MINIWINS+'\',\'IWinMAX'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to minimise the mini window\';return true;" onmouseout="window.status=\'\';return true;">'+
				'<img src="'+oMin+'" border="0" height="16" width="16" alt="Minimise."></a>'+
				'<a href="javascript:" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'IWinMAX'+window.MWJ_MINIWINS+'\');return false;" ' + 
				' onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></td></tr></table>'+
				'</td></tr><tr><td bgcolor="'+mainColour+'">'+mainContent+'</td></tr></table></layer>';
			iwinDiv = iwinDiv + '<layer bgcolor="' + fColor + '" name="IWinMIN'+window.MWJ_MINIWINS+'" width="'+oWidth+'" left="'+oLeft+'" top="'+oTop+'" visibility="'+((oVis==2)?'show':'hide')+'"'+(oFullDrag?theDragString:'')+'>'+
				'<table border="2" cellpadding="2" cellspacing="2" width="100%"><tr><td bgcolor="'+barColour+'">'+
				'<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>'+
				'<td align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;"' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close."></a></td>'+
				'<td align="left" valign="middle">'+(oFullDrag?'':'<ilayer width="'+(oWidth-74)+'" height="16" left="0" top="0"><layer width="100%" left="0" top="0"'+theDragString+'>')+
				'<font color="#ffffff" face="Arial" size="-1"><b>'+oTitle+
				'</b></font>'+(oFullDrag?'':'</layer></ilayer>')+'</td><td align="right" valign="middle" width="32">'+
				'<a ' + 
				' onclick="InlineWindowUtils.showMinWin(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to minimise the mini window\';return true;" onmouseout="window.status=\'\';return true;">'+
				'<img src="'+oMin+'" border="0" height="16" width="16" alt="Maximise."></a>'+
				'<a ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></td></tr></table>'+
				'</td></tr></table></layer>';
		} else {
			var theDragString = ' onmousedown="InlineWindowUtils.clickDiv(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\',arguments[0]);return false;" onselectstart="return false;" ondragstart="return false;"';
			iwinDiv = iwinDiv +
				'<div id="IWinMAX'+window.MWJ_MINIWINS+'" style="width:'+oWidth+'px;position:absolute;left:'+oLeft+'px;top:'+oTop+'px;visibility:'+((oVis==1)?'visible':'hidden')+';"'+(oFullDrag?theDragString:'')+'>'+
				(document.childNodes?('<div style="position:absolute;right:2px;bottom:2px;">'+((oDrag&&!oFullDrag)?'<img src="'+oDrag+'" height="11" width="11" border="0" alt="Resize." title="Resize." onmousedown="InlineWindowUtils.clickDiv(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+
				'\',arguments[0],true);return false;" onselectstart="return false;" ondragstart="return false;" style="cursor:se-resize;" onmouseover="window.status=\'Drag to resize the mini window\';return true;" onmouseout="window.status=\'\';return true;">':'')+
				'</div>'):'')+'<table border="0" cellpadding="0" cellspacing="0" style="background-color:' + fColor + ';border-left:0px solid #dfdfdf;border-top:0px solid #dfdfdf;border-right:0px solid black;border-bottom:0px solid black;" width="100%"><tr>'+
				'<td style="background-color:' + fColor + ';border-left:0px solid white;border-top:0px solid white;border-right:0px solid #7f7f7f;border-bottom:0px solid #7f7f7f;">'+
				'<table border="0" cellpadding="0" cellspacing="1" width="100%" style="border:0px solid ' + fColor + ';"><tr><td>'+
				'<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close."></a></td>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" style="color:#ffffff;font-family:Arial,Sans-Serif;font-weight:bold;font-size:12px;cursor:default;" '+
				'onmouseover="window.status=\'Drag here to move the mini window\';return true;" onmouseout="window.status=\'\';return true;"'+
				(oFullDrag?'':theDragString)+' nowrap>'+oTitle+'</td><td bgcolor="'+barColour+'" align="right" valign="middle" width="34"><nobr>'+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'IWinMIN'+window.MWJ_MINIWINS+'\',\'IWinMAX'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to minimise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Minimise.">'+
				'<img src="'+oMin+'" border="0" height="16" width="16" alt="Minimise."></a>'+
				((oFull&&oDrag&&document.childNodes&&!oFullDrag)?'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.maximiseWin(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to maximise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Maximise.">'+
				'<img src="'+oFull+'" border="0" height="16" width="16" alt="Maximise."></a>':'')+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'IWinMAX'+window.MWJ_MINIWINS+'\'); return false;" ' +
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></nobr></td></tr></table>'+
				'</td></tr><tr><td>'+((anyExtra&&document.childNodes)?anyExtra:'')+'<table border="0" cellpadding="4" cellspacing="0" style="'+
				'border-left:0px solid #7f7f7f;border-top:0px solid #7f7f7f;border-right:0px solid white;border-bottom:0px solid white;" width="100%">'+
				'<tr><td style="border-left:0px solid black;border-top:0px solid black;border-right:0px solid #dfdfdf;border-bottom:0px solid #dfdfdf;background-color:'+
				mainColour+';padding:0px;" valign="top"><div style="'+((oScroll&&document.childNodes&&!(!window.ActiveXObject&&!navigator.taintEnabled&&document.all)&&!(navigator.product=='Gecko'&&navigator.taintEnabled&&typeof(document.textContent)=='undefined')&&!(window.ActiveXObject&&!navigator.__ice_version&&window.ScriptEngineMajorVersion&&(ScriptEngineMajorVersion()+(0.1*ScriptEngineMinorVersion()))<5.5))?'overflow:auto;height:100%;':'')+'padding:2px;">'+mainContent+'</div></td></tr></table></td></tr></table></td></tr></table></div>' ;
			iwinDiv = iwinDiv +
				'<div id="IWinMIN'+window.MWJ_MINIWINS+'" style="width:'+oWidth+'px;position:absolute;left:'+oLeft+'px;top:'+oTop+'px;visibility:'+((oVis==2)?'visible':'hidden')+';"'+(oFullDrag?theDragString:'')+'>'+
				'<table border="0" cellpadding="0" cellspacing="0" style="background-color:' + fColor + ';border-left:0px solid #dfdfdf;border-top:0px solid #dfdfdf;border-right:0px solid black;border-bottom:0px solid black;" width="100%"><tr>'+
				'<td style="background-color:' + fColor + ';border-left:0px solid white;border-top:0px solid white;border-right:0px solid #7f7f7f;border-bottom:0px solid #7f7f7f;">'+
				'<table border="0" cellpadding="0" cellspacing="1" width="100%" style="border:0px solid ' + fColor + ';"><tr><td>'+
				'<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" height="16" width="20">'+
				'<a style="text-decoration:none;cursor:hand;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'' + oMaximName + '\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oLogo+'" border="0" height="16" width="16" alt="Close."></a></td>'+
				'<td bgcolor="'+barColour+'" align="left" valign="middle" style="color:#ffffff;font-family:Arial,Sans-Serif;font-weight:bold;font-size:12px;cursor:default;" '+
				'onmouseover="window.status=\'Drag here to move the mini window\';return true;" onmouseout="window.status=\'\';return true;"'+
				(oFullDrag?'':theDragString)+' nowrap>'+oTitle+'</td><td bgcolor="'+barColour+'" align="right" valign="middle" width="34"><nobr>'+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to restore the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Restore.">'+
				'<img src="'+oMax+'" border="0" height="16" width="16" alt="Restore."></a>'+
				((oFull&&oDrag&&document.childNodes&&!oFullDrag)?'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.showMinWin(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\');InlineWindowUtils.maximiseWin(\'IWinMAX'+window.MWJ_MINIWINS+'\',\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' +
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to maximise the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Maximise.">'+
				'<img src="'+oFull+'" border="0" height="16" width="16" alt="Maximise."></a>':'')+
				'<a style="text-decoration:none;cursor:default;" ' + 
				' onclick="InlineWindowUtils.hideMinWin(\'IWinMIN'+window.MWJ_MINIWINS+'\'); return false;" ' + 
				' href="javascript:" onfocus="this.blur()" onmouseover="window.status=\'Click to close the mini window\';return true;" onmouseout="window.status=\'\';return true;" title="Close.">'+
				'<img src="'+oClose+'" border="0" height="16" width="16" alt="Close."></a></nobr></td></tr></table>'+
				'</td></tr></table></td></tr></table></div>';
		}
		var tempOb = new Object(); 
		tempOb.maxName = 'IWinMAX'+window.MWJ_MINIWINS; 
		tempOb.minName = 'IWinMIN'+window.MWJ_MINIWINS; 		
		tempOb.iframeId = iframeId;
		tempOb.iwinDiv = iwinDiv;
		tempOb.bShowScrollBar = mainContent[4];
		return tempOb;
	}

	this.getRefToDivNest = function( divID, oDoc ) {
		if( !oDoc ) { oDoc = document; }
		if( document.layers ) {
			if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
				for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
					y = this.getRefToDivNest(divID,oDoc.layers[x].document); }
				return y; } }
		if( document.getElementById ) { return document.getElementById(divID); }
		if( document.all ) { return document.all[divID]; }
		return document[divID];
	}

	this.winMousePos = function(e) {
		//get the position of the mouse
		if( !e ) { e = window.event; } if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) { return [0,0]; }
		if( typeof( e.pageX ) == 'number' ) { var xcoord = e.pageX; var ycoord = e.pageY; } else {
			var xcoord = e.clientX; var ycoord = e.clientY;
			if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
				if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
					xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
				} else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
					xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop; } } }
		return [xcoord,ycoord];
	}

	this.clickDiv = function(div1,div2,e,isRes,iFrameChildName) {
		//make note of starting positions and detect mouse movements
		//use Inner Frame (save the name)
		window.storeUIF = iFrameChildName;
		if (iFrameChildName) {
			var innerFrame = (document.getElementById ? document.getElementById(iFrameChildName) : (document.all ? document.all[iFrameChildName] : false));
			var dummyPlaceHolder = (document.getElementById ? document.getElementById(iFrameChildName + '_DPH') : (document.all ? document.all[iFrameChildName + '_DPH'] : false));
			if (innerFrame) {				
				innerFrame.style.display = 'none';
				dummyPlaceHolder.style.display = '';
				if ( InlineWindowUtils.enableSetOpacity ) InlineWindowUtils.setOpacity( $(iwin_def.maxName), 50 );
			}
		}

		if ( ( !window.ActiveXObject || navigator.userAgent.indexOf('Mac') == -1 || navigator.__ice_version ) && document.onmousemove == this.winIsMove ) { 
			document.onmousemove = window.storeMOUSEMOVE; 
			document.onmouseup = window.storeMOUSEUP; 
			
			if (innerFrame) {
				innerFrame.style.display = '';
				dummyPlaceHolder.style.display = 'none';
			}
			return; 
		}
		if ( ( e && ( e.which > 1 || e.button > 1 ) ) || ( window.event && ( window.event.which > 1 || window.event.button > 1 ) ) ) { 
			return; 
		}
		this.MWJ_winZind += 2;
		div1 = this.getRefToDivNest(div1); 
		div2 = this.getRefToDivNest(div2); 
		if( !div2 ) { 
			return; 
		} 
		window.msStartCoord = this.winMousePos(e);
		div1.currentMWJAction = isRes ? true : false;
		if( isRes ) { 
			window.lyStartCoord = [div1.offsetWidth,div1.getElementsByTagName('div')[1].parentNode.offsetHeight,div1.offsetHeight - div1.getElementsByTagName('div')[1].parentNode.offsetHeight];
		} 
		else { 
			window.lyStartCoord = div1.style ? [parseInt(div1.style.left),parseInt(div1.style.top)] : [parseInt(div1.left),parseInt(div1.top)]; 
		}
		if( div1.style ) { 
			div1.style.zIndex = this.MWJ_winZind; 
			div2.style.zIndex = this.MWJ_winZind + 1; 
		} 
		else { 
			div1.zIndex = this.MWJ_winZind; 
			div2.zIndex = this.MWJ_winZind + 1; 
		}
		if( document.captureEvents && Event.MOUSEMOVE ) { 
			document.captureEvents(Event.MOUSEMOVE); 
			document.captureEvents(Event.MOUSEUP); 
		}
		if( !window.ActiveXObject || navigator.userAgent.indexOf('Mac') == -1 || navigator.__ice_version ) { 
			window.storeMOUSEMOVE = document.onmousemove; 
			window.storeMOUSEUP = document.onmouseup; 
		}
		window.storeLayer = [div1,div2]; 
		document.onmousemove = this.winIsMove; 
		document.onmouseup = this.winIsMove;
	}


	this.winIsMove = function(e) {
		//move the layer to its newest position
		var uIF = window.storeUIF;
		var msMvCo = InlineWindowUtils.winMousePos(e); 
		if( !e ) { 
			e = window.event ? window.event : ( new Object() ); 
		}
		e.cancelBubble = true; 
		if( e.stopPropagation ) 
			e.stopPropagation();
		var newX = window.lyStartCoord[0] + ( msMvCo[0] - window.msStartCoord[0] );
		var newY = window.lyStartCoord[1] + ( msMvCo[1] - window.msStartCoord[1] );
		//reset the mouse monitoring as before - delay needed by Gecko to stop jerky response (hence two functions instead of one)
		//as long as the Gecko user does not release one window then click on another within 1ms (!) this will cause no problems
		if( e.type && e.type.toLowerCase() == 'mouseup' ) { 
			document.onmousemove = window.storeMOUSEMOVE; 
			document.onmouseup = window.storeMOUSEUP; 

			if (uIF) {
				var innerFrame = (document.getElementById ? document.getElementById(uIF) : (document.all ? document.all[uIF] : false));
				var dummyPlaceHolder = (document.getElementById ? document.getElementById(uIF + '_DPH') : (document.all ? document.all[uIF + '_DPH'] : false));
				if (innerFrame) {
					if ( InlineWindowUtils.enableSetOpacity ) InlineWindowUtils.setOpacity( $(iwin_def.maxName), 100 );
					innerFrame.style.display = '';
					dummyPlaceHolder.style.display = 'none';
				}
			}
		} 	
		if( navigator.product == 'Gecko' ) { 
			window.setTimeout('InlineWindowUtils.winIsMove2('+newX+','+newY+',\'' + uIF+ '\');',1); 
		}
		else { 
			InlineWindowUtils.winIsMove2(newX,newY, uIF); 
		}
	}

	this.winIsMove2 = function(y,z,uIF) {	
		if( window.storeLayer[0].currentMWJAction ) { 
			this.doActualResize(window.storeLayer,y,z,window.lyStartCoord[2], uIF);
		} 
		else { 
			for( var x = 0, oPix = ( document.childNodes ? 'px' : 0 ); x < 2; x++ ) {
				var theLayer = window.storeLayer[x].style ? window.storeLayer[x].style : window.storeLayer[x]; 
				theLayer.left = y + oPix; 
				theLayer.top = z + oPix; 
			}
		}
	}

	this.doActualResize = function(oDivs,y,z,offSet,uIF) {
	
		//resize - first to what you want, then again to what was possible (stops the drag handle moving inside the window)
		if (uIF) {
			var innerFrame = (document.getElementById ? document.getElementById(uIF) : (document.all ? document.all[uIF] : false));
			var dummyPlaceHolder = (document.getElementById ? document.getElementById(uIF + '_DPH') : (document.all ? document.all[uIF + '_DPH'] : false));
			if (innerFrame) {
				innerFrame.style.width = y - 0 + 'px';
				innerFrame.style.height = z - 0 + 'px';
				dummyPlaceHolder.style.width = y - 0 + 'px';
				dummyPlaceHolder.style.height = z - 0 + 'px';
			}
		}
		for( var x = 0; x < 2; x++ ) {
			var theLayer = oDivs[x];
			if( y < 0 ) { 
				y = 0;
			}
			if( !x && theLayer.getElementsByTagName('div')[1].style.overflow == 'auto' && navigator.product=='Gecko' && navigator.taintEnabled ) {
				//gecko bug (otherwise cannot make it get narrower and the drag handle moves wrong)
				var ppDv = theLayer.getElementsByTagName('div')[1];
				if( !ppDv.tmpDiv ) { ppDv.tmpDiv = document.createElement('div');
					ppDv.appendChild( ppDv.tmpDiv );
					while( ppDv.childNodes[0] != ppDv.tmpDiv ) { 
						ppDv.tmpDiv.appendChild( ppDv.childNodes[0] );
					} 
				}
				ppDv.tmpDiv.style.display = 'none';
				ppDv.style.overflow = '';
				ppDv.style.height = '';
			}
			theLayer.style.width = y + 'px';
			if( !x ) {
				y = theLayer.getElementsByTagName('div')[1].parentNode.offsetWidth + 10;
				theLayer.style.width = y + 'px';
				if( z < 20 ) { 
					z = 20;
				} 
				theLayer.getElementsByTagName('div')[1].parentNode.style.height = z + 'px';
				if( !window.ActiveXObject && !navigator.taintEnabled ) { 
					theLayer.getElementsByTagName('div')[1].style.height = ( z - 4 ) + 'px';
				}
				z = theLayer.getElementsByTagName('div')[1].parentNode.offsetHeight;
				if( !window.ActiveXObject && !navigator.taintEnabled ) { 
					theLayer.getElementsByTagName('div')[1].style.height = ( z - 4 ) + 'px';
					z += 2;
				}
				theLayer.getElementsByTagName('div')[1].parentNode.style.height = z + 'px';
				theLayer.style.height = ( z + offSet ) + 'px';
				if( theLayer.getElementsByTagName('div')[1].tmpDiv ) {
					ppDv.tmpDiv.style.display = 'block';
					ppDv.style.overflow = 'auto';
					ppDv.style.height = this.doNumMax(96+(ppDv.parentNode.offsetHeight/500))+'%';
				}
			}
		} 
		if (innerFrame) {
			innerFrame.style.width = y - 0 + 'px';
			innerFrame.style.height = z - 0 + 'px';
			dummyPlaceHolder.style.width = y - 0 + 'px';
			dummyPlaceHolder.style.height = z - 0 + 'px';
		}
	}
	this.doNumMax = function(oNm) { return ( oNm > 99 ) ? 99 : oNm; }
	
	this.reWriteWin = function(theWin,minName,newContent) {
		//rewrite the window content if possible
		var theWin = this.getRefToDivNest(theWin), minName = this.getRefToDivNest(minName); if( theWin && document.childNodes && theWin.getElementsByTagName && theWin.getElementsByTagName('div')[1] ) {
			if( !window.ActiveXObject && !navigator.taintEnabled ) { theWin.getElementsByTagName('div')[1].style.height = ( theWin.getElementsByTagName('div')[1].offsetHeight - 4 ) + 'px'; }
			theWin.getElementsByTagName('div')[1].parentNode.style.height = theWin.getElementsByTagName('div')[1].parentNode.offsetHeight + 'px';
			if( window.ActiveXObject && navigator.platform.indexOf( 'Mac' ) + 1 && !navigator.__ice_version ) {
				var theOffset = theWin.offsetHeight - theWin.getElementsByTagName('div')[1].parentNode.offsetHeight;
			} else { var theOffset = theWin.offsetHeight - theWin.getElementsByTagName('div')[1].offsetHeight; }
			theWin.getElementsByTagName('div')[1].innerHTML = newContent;
			if( window.ActiveXObject && navigator.platform.indexOf( 'Mac' ) + 1 && !navigator.__ice_version ) {
				theWin.style.height = ( theWin.getElementsByTagName('div')[1].parentNode.offsetHeight + theOffset ) + 'px';
			} else { theWin.style.height = ( theWin.getElementsByTagName('div')[1].offsetHeight + theOffset ) + 'px'; }
			theWin.style.width = theWin.offsetWidth + 'px'; minName.style.width = theWin.offsetWidth + 'px';
	} }

	// Change the opacity of a layer
	this.setOpacity = function( element, opacity )
	{
		if ( !element && !element.style ) return;

		// See if we're using W3C opacity, MSIE filter, or just toggling visiblity
		if(typeof element.style.opacity != 'undefined') 
		{
			//this._updateOpacity = this._updateOpacityW3c;
			element.style.opacity = opacity/100;
		}
		else if(typeof element.style.filter != 'undefined') 
		{	
			// If there's not an alpha filter on the element already, add one
			if (element.style.filter.indexOf("alpha") == -1) 
			{ 	
				var existingFilters="";
				if (element.style.filter) { existingFilters = element.style.filter+" "; }
				element.style.filter = existingFilters+"alpha(opacity="+opacity+")";
			}
			
			//this._updateOpacity = this._updateOpacityMSIE;
			element.filters.alpha.opacity = opacity;    
		} 
		  
		if (opacity > 0)
			element.style.visibility = 'visible';
		else
			element.style.visibility = 'hidden';  
	}
	
	// ===============================
	// Change the window bgcolor
	// ===============================
	this.changeWinBG = function(winName,newBG) {
		var theWin = this.getRefToDivNest(winName); if( theWin && theWin.parentNode && theWin.getElementsByTagName && theWin.getElementsByTagName('div')[1] ) {
			theWin.getElementsByTagName('div')[1].parentNode.style.backgroundColor = newBG;
	} }

	this.moveWin = function(oMax,oMin,x,y) {
		oMax = this.getRefToDivNest(oMax); oMin = this.getRefToDivNest(oMin); if( !oMax ) { return; }
		if( oMax.style ) { oMax = oMax.style; oMin = oMin.style; } var oPix = document.childNodes ? 'px' : 0;
		oMax.left = x + oPix; oMin.left = x + oPix; oMax.top = y + oPix; oMin.top = y + oPix;
	}

	// resize window
	this.resizeWin = function(oMax,oMin,y,z) {
		oMax = [this.getRefToDivNest(oMax),this.getRefToDivNest(oMin)]; if( !oMax[0] ) { return; }		
		if( oMax[0].getElementsByTagName && document.childNodes ) {		
			var oTitlSiz = oMax[0].offsetHeight - oMax[0].getElementsByTagName('div')[1].parentNode.offsetHeight;
			z = z - oTitlSiz; this.doActualResize(oMax,y,z,oTitlSiz);
	} }
	
	this.resizeWinEx = function(oMax,oMin,y,z, iframeId ) {
		oMax = [this.getRefToDivNest(oMax),this.getRefToDivNest(oMin)]; if( !oMax[0] ) { return; }		
		if( oMax[0].getElementsByTagName && document.childNodes ) {		
			var oTitlSiz = oMax[0].offsetHeight - oMax[0].getElementsByTagName('div')[1].parentNode.offsetHeight;
			z = z - oTitlSiz; this.doActualResize(oMax,y,z,oTitlSiz, iframeId);
	} }
	

	// maximium the window
	this.maximiseWin = function( oMax, oMin ) {
		var div1 = this.getRefToDivNest(oMax), div2 = this.getRefToDivNest(oMin); if( !div2 ) { return; } this.MWJ_winZind += 2;
		if( div1.style ) { div1.style.zIndex = this.MWJ_winZind; div2.style.zIndex = this.MWJ_winZind + 1; } else { div1.zIndex = this.MWJ_winZind; div2.zIndex = this.MWJ_winZind + 1; }
		var newSet = this.findMaxSize();
		this.moveWin(oMax,oMin,newSet[0],newSet[1]);
		this.resizeWinEx(oMax,oMin,newSet[2],newSet[3], this.iframeId );		
	}

	this.findMaxSize = function() {
		if( typeof( window.pageXOffset ) == 'number' ) { var x = window.pageXOffset, y = window.pageYOffset;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			var x = document.documentElement.scrollLeft, y = document.documentElement.scrollTop;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			var x = document.body.scrollLeft, y = document.body.scrollTop;
		} else { var x = 0, y = 0; }
		if( window.innerWidth ) { var w = window.innerWidth, h = window.innerHeight;
		} else if( document.documentElement && document.documentElement.clientWidth ) {
			var w = document.documentElement.clientWidth, h = document.documentElement.clientHeight;
		} else if( document.body && document.body.clientWidth ) {
			var w = document.body.clientWidth, h = document.body.clientHeight;
		} else { var w = 400, h = 400; } if( window.opera || ( navigator.product == 'Gecko' && navigator.taintEnabled ) ) { w -= 16; }
		if( !window.ActiveXObject && !navigator.taintEnabled ) { h -= 4; }
		// adjust the size of maximized window
		return [x + 5 ,y + 5 ,w-22, h-20 ]
	}

	this.hideMinWin = function(thisDiv) {
	
		//this function hides the div
		thisDiv = this.getRefToDivNest(thisDiv); if( !thisDiv ) { return; }
		if( thisDiv.style ) 
			thisDiv.style.visibility = 'hidden'; 			
		else
			thisDiv.visibility = 'hide'; 
		
		// hide the iframe		
		if ( document.getElementById( this.iframeId ) ) document.getElementById( this.iframeId ).src = this.defaultURL;	
	}

	this.showMinWin = function(thisDiv,thatDiv) {
		//this function shows the div and hides the old one if necessary
		thisDiv = this.getRefToDivNest(thisDiv); if( thatDiv ) { this.hideMinWin(thatDiv); } if( !thisDiv ) { return; }
		this.MWJ_winZind += 2; if( thisDiv.style ) { thisDiv.style.visibility = 'visible'; thisDiv.style.zIndex = this.MWJ_winZind;
		} else { thisDiv.visibility = 'show'; thisDiv.zIndex = this.MWJ_winZind; }
	}
	
	// Close both the window
	this.hideMe = function (){		
		this.hideMinWin( this.maxName );
		this.hideMinWin( this.minName );
	}
}


var iwin_def = null
// Create only when need
function CreateDefaultIWin( iwin_obj ){
	
	return CreateDefaultIWinEx( iwin_obj, true )
}

function CreateDefaultIWinEx( iwin_obj, bShowScrollBar ){
	
	if ( iwin_obj != null && iwin_obj.bShowScrollBar == bShowScrollBar ) {		
		iwin_def = iwin_obj;
		return iwin_obj;	
	}

	iwin_obj = InlineWindowUtils.createIWinLayer( ['iwin_iframe_def', 
		'/vbinc/blank.asp', 10, 10, bShowScrollBar ], '', 0, 0, '#699CC2', '#FFFFFF', 
		'/vbinc/images/inlined_window/iwin_logo.gif', 
		'/vbinc/images/inlined_window/min.gif', 
		'/vbinc/images/inlined_window/restore.gif', 
		'/vbinc/images/inlined_window/cross.gif', 
		'/vbinc/images/inlined_window/max.gif', 
		'/vbinc/images/inlined_window/handle_classic.gif', 0, false, '', false ); 

	iwin_def = iwin_obj;

	AddIWINDivIfNotExist( 'MTG_IWIN_HOOK', iwin_obj.iwinDiv );	
	return iwin_obj;
}



function AddIWINDivIfNotExist(divID, innerString)
{
	var div = document.getElementById(divID);
	if(!div) {
		div = document.createElement("DIV");
		div.id = divID;
	}
	div.innerHTML = innerString;	
	if ( document && document.body ) document.body.insertBefore(div, document.body.lastChild);
}


// Hide the inline window
function HideIWin(){	
	if ( iwin_def )
	{
		InlineWindowUtils.hideMinWin(iwin_def.maxName);
		InlineWindowUtils.hideMinWin(iwin_def.minName);	
		InlineWindowUtils.resetWin(iwin_def);
		
		if(typeof(InlinedWindowCloseCB) == 'function') {
			InlinedWindowCloseCB();
		}
	}	
}

function HideIWinEx( iwinObj ){
	//iwinObj = CreateDefaultIWin( iwinObj );
	InlineWindowUtils.hideMinWin(iwinObj.maxName);
	InlineWindowUtils.hideMinWin(iwinObj.minName);	
	InlineWindowUtils.resetWin(iwinObj);
}

// Maximize the inlined window
function MaxIWin(){
	InlineWindowUtils.maximiseWin( iwin_def.maxName, iwin_def.minName )
}


// ================================================================
// auto complete text
// ================================================================

var isOpera = navigator.userAgent.indexOf("Opera") > -1; 
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; 
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera; 

function ac_textboxSelect(oTextbox, iStart, iEnd) { 

   switch(arguments.length) { 
       case 1: 
           oTextbox.select(); 
           break; 

       case 2: 
           iEnd = oTextbox.value.length; 
           /* falls through */ 
            
       case 3:          
           if (isIE) { 
               var oRange = oTextbox.createTextRange(); 
               oRange.moveStart("character", iStart); 
               oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
               oRange.select();                                              
           } else if (isMoz){ 
               oTextbox.setSelectionRange(iStart, iEnd); 
           }                     
   } 

   oTextbox.focus(); 
} 

function AutoCompleteText(oTextbox, oEvent, arrValues) { 
	
   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           return true; 
           break; 

       default: 
           ac_textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
           var iLen = oTextbox.value.length; 

           var sMatch = ac_match(oTextbox.value, arrValues); 

           if (sMatch != null) { 
               oTextbox.value = sMatch; 
               ac_textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }  
           
           return false; 
   } 
} 

function ac_textboxReplaceSelect(oTextbox, sText) { 

   if (isIE) { 
       var oRange = document.selection.createRange(); 
       oRange.text = sText; 
       oRange.collapse(true); 
       oRange.select();                                 
   } else if (isMoz) { 
       var iStart = oTextbox.selectionStart; 
       oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length); 
       oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length); 
   } 

   oTextbox.focus(); 
} 

function ac_match(sText, arrValues) { 

   for (var i=0; i < arrValues.length; i++) { 
       if (arrValues[i].toLowerCase().indexOf(sText.toLowerCase()) == 0) { 
           return arrValues[i]; 
       } 
   } 

   return null; 
} 

// ================================================================
// auto time
// ================================================================


//this function should be called at the onchange
function validate_time(element_name, bShowSecond )
{
	var value = document.getElementById(element_name).value;
	if (value.length == 0)
		return;

	var temp = time_str_to_int( value );
	document.getElementById(element_name).value = time_int_to_str(temp, bShowSecond);
}

// str should be in the format hh:mm:ss or in hh:mm, if start_time > end_time, the function will auto + 24*60*60(ie one day)
// return -1 for abnormal condition
function FindDuration(start_time_str, end_time_str)
{
	var start_time	= time_str_to_int(start_time_str);
	var end_time	= time_str_to_int(end_time_str);
	
	if (start_time < 0 || end_time < 0)
		return -1;
	
	if (end_time - start_time < 0)
		return end_time - start_time + 24*60*60;
	else return end_time - start_time;
}

//it takes a sting in hh*mm*ss or hh*mm or hh format 
//returns a integer in second of the day
//return -1  if the str is not in correct format
function time_str_to_int(str)
{
	var re = /[^0-9]/ ;

	var array = str.split(re);
	var hh,mm,ss;
	
	if(array.length < 1 || array.length > 3 )
		return -1;
	
	//be careful that there maybe leading zero, thus MUST set the radix = 10
	//otherwise it treat as octex(like C language......)
	hh = parseInt(array[0],10);
	if(array.length >= 2)
		mm = parseInt(array[1],10);
	else mm = 0;
	
	if(array.length == 3)
		ss = parseInt(array[2], 10);
	else ss = 0;
	
	if(hh < 0 || hh >= 24 || isNaN(hh))
		return -1;
	if(mm < 0 || mm >= 60 || isNaN(mm))
		return -1;
	if(ss < 0 || ss >= 60 || isNaN(ss))
		return -1;
		
	
	return ((hh * 60 + mm) * 60) + ss;
}

//if the second is -1
//give the current_time,
//if bSecond = true, return str in hh:mm:ss
//else return str in hh:mm
function time_int_to_str(second, bSecond)
{
	var hh, mm, ss;
	
	if (second < 0)
	{
		var date = new Date();
		hh = date.getHours() ;
		mm = date.getMinutes();
		ss = date.getSeconds();
	}
	else
	{
		ss = second % 60;
		second = (second - ss) / 60;
		mm = second % 60;
		second = (second - mm) / 60;
		hh = second % 24;
	}
	//if time is in correct format
	if (hh < 10)
		hh = "0" + hh
	if (mm < 10)
		mm = "0" + mm
	if (ss < 10)
		ss = "0" + ss
	if (bSecond == true)
		return hh + ":" + mm + ":" + ss;
	else return hh + ":" + mm;
}

function time_short_cut(element_name, bShowSecond )
{
	var value = document.getElementById(element_name).value;
	if (value.length == 0)
		return;
		
	var input = value.charAt(value.length - 1);
	var allowedchar = "0123456789:-/."
	if ( allowedchar.search(input) == -1) {
		document.getElementById(element_name).value = time_int_to_str(-1, bShowSecond);
		FormUtils.FocusNextElement( document.getElementById(element_name) );
	}
}

function displayPopup(url, name, width, height, properties, bCenter)
{
	var leftprop, topprop, screenX, screenY

	if(navigator.appName == "Microsoft Internet Explorer")
	{
		screenY = document.body.offsetHeight
		screenX = window.screen.availWidth
	}
	else
	{		// Navigator coordinates
		screenY = screen.height;
		screenX = screen.width;
	}

	leftvar = (screenX - width) / 2
	rightvar = (screenY - height) / 2
		
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		leftprop = leftvar
		topprop = rightvar
	}
	else
	{ // adjust Netscape coordinates for scrolling
		leftprop = (leftvar - pageXOffset)
		topprop = (rightvar - pageYOffset)
	}

	properties = properties+",left="+leftprop
	properties = properties+",top="+topprop

	popupHandle = open(url,name,properties)
}

