window.name="G_QLibraryWin";
var g_QBookShelf = null;
var g_QBook = null;
var g_SysReq = null;
var g_ReqLoad = 0;
var g_TestReport = null;
var g_PrintQbook = null;
var g_WinHelp=null;

var CookieTxt = document.cookie;
var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000); // plus 28 days
//function to check Cookie active or deactive
function getCookie(name) { // use: getCookie("name");
	var index = CookieTxt.indexOf(name + "=");
	if (index == -1) return null;
	index = CookieTxt.indexOf("=", index) + 1;
	var endstr = CookieTxt.indexOf(";", index);
	if (endstr == -1) endstr = CookieTxt.length;
	return unescape(CookieTxt.substring(index, endstr));
}
		
//function to active or deactive Cookie 
function setCookie(name, value) { // use: setCookie("name", value);
	if (getCookie(name)==null){
		document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
		CookieTxt = document.cookie; // update CookieTxt
	}
	else
	{			
		if (value != null && value != "")
		{
			if(getCookie(name).indexOf(value) == -1)
			{
				var expirycookie = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000)
				value = getCookie(name) + value;
				document.cookie=name + "=" + escape(value) + "; expires=" + expirycookie.toGMTString();
				CookieTxt = document.cookie; // expiry CookieTxt*/
			}
	    }
	}
}	
//function to active or deactive Cookie 
function UpdateCookie(name, value) { // use: setCookie("name", value);
	if (getCookie(name)==null){
	}
	else
	{			
		if (value != null && value != "")
		{
			if(getCookie(name).indexOf(value) == -1)
			{
				var expirycookie = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000)
				var NewValue = getCookie(name).replace(value,"");
				document.cookie=name + "=" + escape(NewValue) + "; expires=" + expirycookie.toGMTString();
				CookieTxt = document.cookie; // expiry CookieTxt*/
			}
	    }
	}
}	
function setExpireCookie(name) { // use: setExpireCookie("name");
	var value="";
	var expirycookie = new Date(today.getTime()- 24 * 60 * 60 * 1000)
	document.cookie=name + "=" + escape(value) + "; expires=" + expirycookie.toGMTString();
	CookieTxt = document.cookie; // expiry CookieTxt
}	

function fnSysReqWin(childURL,childName,childFeatures) { //v2.0
	if (g_SysReq == null || g_SysReq.closed)
	{
		g_SysReq = window.open(childURL, childName, childFeatures);
		if(g_SysReq==null||typeof(g_SysReq)=="undefined") 
		{
			alert("Please enable popups.");
			return;
		}
	}
	g_SysReq.focus();
}


function fnTerminateSysReqWin()
{
	if (g_SysReq != null) {
		if (!g_SysReq.closed) {
			g_SysReq.close()
		}
	}
}

function fnPrintQbookWin(childURL,childName,childFeatures) { //v2.0
	if (g_PrintQbook == null || g_PrintQbook.closed || g_ReqLoad==1)
	{
		g_PrintQbook = window.open(childURL, childName, childFeatures);
		if(g_PrintQbook==null||typeof(g_PrintQbook)=="undefined") 
		{
			alert("Please enable popups.");
			return;
		}
		g_ReqLoad=0;
	}
	g_PrintQbook.focus();
}

function fnQBookShelfWin(childURL,childName,childFeatures) { //v2.0
	if (g_QBookShelf == null || g_QBookShelf.closed || g_ReqLoad==1)
	{
		g_QBookShelf = window.open(childURL, childName, childFeatures);
		if(g_QBookShelf==null||typeof(g_QBookShelf)=="undefined") 
		{
			alert("Please enable popups.");
			return;
		}
		g_ReqLoad=0;
	}
	g_QBookShelf.focus();
}
function fnTerminateQBookShelfWin()
{
	if (g_QBookShelf != null) {
		if (!g_QBookShelf.closed) {
			g_QBookShelf.close()
		}
	}
}
function fnQbookWin(childURL,childType) { //v2.0
	//var RepUrl="http://"+document.location.host;
	//childURL=childURL.replace(RepUrl,"");
	/*if(getCookie('QLibraryWinInfo') != null)
	{
		if(getCookie('QLibraryWinInfo').indexOf("33_web.swf") != -1)
		{
			g_QBook = window.open('','Qbookwin','');
			alert(g_QBook)//.QBookFlash.setVariable('pg','25');
			g_ReqLoad=0;
		}
	}
	else
	{*/
		if (g_QBook == null || g_QBook.closed || g_ReqLoad==1)
		{
			g_QBook = window.open(childURL, 'Qbookwin','toolbar=no, resizable=yes, directories=no, menubar=no, scrollbars=yes, width=900, height=660, Left=0, Top=0');
			if(g_QBook==null||typeof(g_QBook)=="undefined") 
			{
				alert("Please enable popups.");
				return;
			}
			g_ReqLoad=0;
		}
	//}
	if (g_QBook != null)
	{
	  g_QBook.focus();
	}
	//fnTerminateQBookShelfWin();
}
function fnTerminateQBookWin()
{
	if (g_QBook != null) {
		if (!g_QBook.closed) {
			g_QBook.close();
		}
	}
}
function fnTestReportWin(childURL,childName,childFeatures) { //v2.0
	if (g_TestReport == null || g_TestReport.closed)
	{
		g_TestReport = window.open(childURL, childName, childFeatures);
		if(g_TestReport==null||typeof(g_TestReport)=="undefined") 
		{
			alert("Please enable popups.");
			return;
		}
	}
	g_TestReport.focus();
}

function fnTerminateTestReportWin()
{
	//alert(g_TestReport)
	if (g_TestReport != null) {
		if (!g_TestReport.closed) {
			g_TestReport.close()
		}
	}
}
function fnHelpWin(childURL,childName,childFeatures) { //v2.0
	if (g_WinHelp == null || g_WinHelp.closed)
	{
		g_WinHelp = window.open(childURL, childName, childFeatures);
		if(g_WinHelp==null||typeof(g_WinHelp)=="undefined") 
		{
			alert("Please enable popups.");
			return;
		}
		
	}
	g_WinHelp.focus();
}

function fnTerminateHelpWin()
{
	//alert(g_TestReport)
	if (g_WinHelp != null) {
		if (!g_WinHelp.closed) {
			g_WinHelp.close()
		}
	}
}


/////////////////////////////////////////////////////////
// iframe coding
///////////////////////////////////////////////////////
function fnCallgetIframePos(objPos,ProType)
{ 
	if (top.location != self.location)
		objPos=parent.getIframePos(this.name,objPos,ProType);
	
	return objPos;
}

function getIframePos(ifrmid,objPos,ProType)
{
	if(ProType=='l')
		objPos=objPos+parseInt(document.getElementById(ifrmid).offsetLeft)-parseInt(document.body.scrollLeft);
	else
		objPos=objPos+parseInt(document.getElementById(ifrmid).offsetTop)-parseInt(document.body.scrollTop);

	if (top.location != self.location)
		objPos=parent.getIframePos(this.name,objPos,ProType)

	return objPos;
}

function fnChangeDisplay(objId,objPro)
{
	if(objPro.toUpperCase()=='H')
		document.getElementById(objId).style.display = 'none';
	else
		document.getElementById(objId).style.display = '';
}
function fnCheckIframe(vObjName)
{
	var vExistIframe = false;
	IFrameArr=document.getElementsByTagName("IFRAME");
	for(IF=0; IF<IFrameArr.length; IF++)
	{
		if(IFrameArr[IF].name==vObjName)
		{
			var vExistIframe = true;
			break;
		}
	}

	return vExistIframe;
}
var opencaseWin=false;
function fnLoadIfrm(titleText, openUrl, winName, wWidth, wHeight, sScroll)
{
	//if(fnCheckIframe(winName))
	if(opencaseWin)
	{
		
		//if(eval(winName).location.href.indexOf(openUrl) == -1)
		//	eval(winName+".document.getElementById('Body"+winName+"')").src=openUrl;
			
		//fnChangeDisplay(winName,'S');
	}
	else
	{
		
		windowX = Math.ceil( (document.body.scrollWidth  - wWidth) / 2 );
		windowY = Math.ceil( (document.body.scrollHeight - wHeight) / 2 );
		if(windowX < 0 )
			 windowX = 0;
		if(windowY < 0 )
			 windowY = 0;
			 
		var ifr = document.createElement('iframe');
		ifr.setAttribute('id',winName);
		ifr.setAttribute('name',winName);
		ifr.style.position = 'absolute';
		ifr.style.top = windowY + 'px';
		ifr.style.left = windowX + 'px';
		ifr.style.width = wWidth + 'px';
		ifr.style.height = wHeight + 'px';
		ifr.frameBorder = 0;
		ifr.scrolling = 'no';		
		document.body.appendChild(ifr);
		setTimeout("fnCreateIFrame('"+titleText+"','"+openUrl+"','"+winName+"',"+wWidth+","+wHeight+",'"+sScroll+"');",100);
		//fnCreateIFrame('"+titleText+"','"+openUrl+"','"+winName+"',"+wWidth+","+wHeight+",'"+sScroll+"');
		opencaseWin=true;
	}
}
function fnCreateIFrame(titleText, openUrl, winName, wWidth, wHeight,sScroll)
{
	jsArr=document.getElementsByTagName("SCRIPT");
	jsPath="js/common_win.js";
	relPath="";
	
	for(j=0; j<jsArr.length; j++)
		if(jsArr[j].src.indexOf(jsPath) > -1)
			relPath=jsArr[j].src.replace(jsPath,"");

 HTML = '<html><head><title>Inline frame</title>';
 //HTML += '<script>var PageReload=0;function fnCloseIframe(){if(PageReload==0){parent.fnChangeDisplay(\''+winName+'\',\'H\');}else{parent.window.location.reload();}}</script>';
 HTML += '<script>var PageReload=0;function fnCloseIframe(){if(PageReload==0){parent.fnChangeDisplay(\''+winName+'\',\'H\');}}</script>';
 HTML += '<script language="JavaScript" type="text/javascript" src="'+relPath+jsPath+'"></script>';
 HTML += '<link href="'+relPath+'css/style_ie.css" rel="stylesheet" type="text/css"></head>';
 HTML += '<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="window.name=\''+winName+'\';if(parent&amp;&amp;parent.addHandle) { parent.addHandle(document.getElementById(\'toolbar\'), window); parent.addHandle(document.getElementById(\'handle\'), window); }">';
 HTML += '<div class="Window">';
 HTML += '<div id="toolbar" class="TitleBar">';
 HTML += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
 HTML += '<tr class="TitleBar">';
 HTML += '<td width="90%" align="left" class="TitleBar"><span >'+titleText+'</span><span id="handle">&nbsp;&nbsp;</span></td>';
 HTML += '<td width="10%" align="right">';
 HTML += '<a href="javascript:void(0);" onClick="fnCloseIframe();return false;"><img style="CURSOR: hand" src="'+relPath+'images/icon_close.gif" name="imgWinButton" border="0" WIDTH="14" HEIGHT="14"></a>';
 HTML += '</td>';
 HTML += '</tr>';
 HTML += '</table>';
 HTML += '</div>'; 
 HTML += '<div id="BodyArea" class="ClientArea" style="width:100%">'; 
 HTML += '<table width="100%" border="0" cellspacing="0" cellpadding="0">'; 
 HTML += '<tr>'; 
 HTML += '<td align="center">'; 
 HTML += '<iframe name="Body'+winName+'" id="Body'+winName+'" src="'+openUrl+'" height="'+(wHeight-34)+'" width="100%" scrolling="'+sScroll+'" frameborder="0" ></iframe>'; 
 HTML += '</td>'; 
 HTML += '</tr>'; 
 HTML += '</table>'; 
 HTML += '</div>'; 
 HTML += '</div>'; 
 HTML += ''; 
 HTML += '</body></html>';
  
 oFrame = document.getElementById(winName);

 if (oFrame.contentDocument) 
 	d=oFrame.contentDocument; 
 else if (oFrame.contentWindow) 
 	d=oFrame.contentWindow.document;

 d.open();
 d.write(HTML);
 d.close();
}

