//suppress back button
//window.history.forward(1);

function attachSearchEvent(searchButtonObj)
{
	searchButtonObj.onclick = checkSearchInput;
}

function checkSearchInput()
{
	if(searchInputObj = document.getElementById("searchInput"))
	{
		if(searchErrorObj = document.getElementById("emptySearchError"))
		{
			if(searchInputObj.value=="")
			{
				alert(searchErrorObj.value);
				searchInputObj.focus();
				return false;
			}
			else
			{
				searchErrorObj.value = "";
			}
		}
	}
}

function do_onload()
{
	if(document.getElementById("jsSecondaryFunctionality"))
	{
		document.getElementById("jsSecondaryFunctionality").style.display = "block";
	}
	if(searchButtonObj = document.getElementById("searchSubmitButton"))
	{
		attachSearchEvent(searchButtonObj);
	}
}

//
// trigger onLoad function (do_onload)
//
if (window.addEventListener)
{
	window.addEventListener("load", do_onload, false);
}
else
{
	if (window.attachEvent)
	{
		window.attachEvent("onload", do_onload);
	}
	else
	{
	if (document.getElementById)
		{
			window.onload = do_onload;
		}
	}
}

//
// Popup window
//
if (navigator.childWin == null)
{
   navigator.childWin = new Array();
}
var childWin = navigator.childWin;


function showChild(ID, ChildHTMLFile, Rules)
{
  if (!Rules)
    childWin[ID] = window.open(ChildHTMLFile,ID,'dependent=yes,resizable=yes,width=640,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=yes');
  else
    childWin[ID] = window.open(ChildHTMLFile,ID,Rules);
	
  return childWin[ID];
}

function closeChild(ID)
{
  if (childWin[ID] != null)
  {
    childWin[ID].close();
    childWin[ID] = null;
  }
}

function closeAll()
{
  closeChild(1);
  closeChild(2);
  closeChild(3);
  closeChild(4);
  closeChild(5);
  closeChild(6);
  closeChild(7);
  closeChild(8);
  closeChild(9);
  closeChild(10);
  closeChild('help');
  closeChild('Timer'); 
  closeChild('Alert');  
  closeChild('OneG');
}

function showOneGeneration(nextPage)
{
	showChild('OneG', nextPage, 'scrollbars=yes,width=800,height=600,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}

function showProductSpecificInterestRateInquiry(url, productType, currency)
{
	if ((currency > 0) && (productType > 0))
	{

   	showChild(1, (url+'&accountType='+productType+'&depositCurrency='+currency), 'dependent=yes,width=480,height=510,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
	return false;
	}
	else
	{

		return true;
	}
}

function showInterestRateInquiry(url)
{
	showChild(1, url, 'scrollbars=yes,dependent=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}


function showCheckBalance(url, debitAccountIndex)
{ 
  return showChild(6, url+'&debitAccountIndex='+debitAccountIndex, 'dependent=yes,width=480,height=510,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}  


function showAcHistoryPrint(url)
{
  return showChild(9, url, 'scrollbars=yes,dependent=yes,width=700,height=500,screenX=0,screenY=0,left=0,top=0');
}

function showCheckBalance(url)
{
  return showChild(6, url, 'scrollbars=yes,dependent=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0');
}



function showProductFeatures(nextPage)
{
	showChild(2, nextPage, 'scrollbars=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}


function showHelp(url)
{
	showChild('help', url, ' width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showTimeout(url)
{

	showChild('Timer', url, 'dependent=yes,width=390,height=330,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=yes, hotkeys=no');
}

function showAlert(url)
{
	return showChild('Alert', url, 'dependent=yes,resizable=no,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=no');
}


function showPdf(pdfIndex, form)
{
	var id = 10;
	form.pdfDwnldIndex.value = pdfIndex;
	form.target=id;
	var rules = 'menubar=no, toolbar=no,directories=no,location=no,scrollbars=no,status=yes,copyhistory=0, height=700,width=700,left=300,top=10';
	childWin[id] = window.open("", id, rules);

}

function showLogonHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/Logon.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/Logon.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showOrAckHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/OrAck.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/OrAck.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showTermsAndConditionsHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/TermsAndConditions.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/TermsAndConditions.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showCalendar()
{
top.newWin=showChild(4, 'javascript:document.write(parent.opener.calDocAll);self.focus();', 'dependent=yes,width=390,height=700,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=yes');
  return top.newWin;
}

function showCalendarPortlet(url)
{
  top.newWin=showChild(4, url, 'dependent=yes,width=390,height=700,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=yes');
  return top.newWin;
}

function showDisclaimer(disclaimerPath)
{
    return showChild(5, disclaimerPath, 'resizable=yes,width=700,height=500,left=0,top=0,scrollbars=yes');
}

function toLogon(url) 
{
  if (confirm('You have decided to reject the terms and conditions for using the Internet Banking service.  Click OK to exit from the registration process or click Cancel to resume your registration process.'))
    {
		window.open(url,'PreLogon');
    }
}

function logonAgain(url) 
{
	window.open(url,'PreLogon');
}

/*function killSession(url)
{
    if (window.event)
    {
        if ((window.event.clientX < -5000 && window.event.clientY < -5000) || 
            (window.event.clientX > 5000 && window.event.clientY > 5000))
        {
            window.open(url, "KillSession", "width=1,height=1,top=30000,left=30000,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=no, hotkeys=no");
        }
    }
}*/

var alertTimer;
var alertwin;

var accHistoryPrintTimer;
var accHistoryPrintWin;

var openPdfFileTimer;
var openPdfFileWin;

function closewin()
{
	killSession();

	if (alertwin)
	{
		alertwin.close();
		alertwin = null;
		clearTimeout(alertTimer);
	}
		
	closeAll();
}

function closewin()
{
	killSession();

	if (alertwin)
	{
		alertwin.close();
		alertwin = null;
		clearTimeout(alertTimer);
	}

	if(accHistoryPrintWin)
	{
	 	accHistoryPrintWin.close();
		accHistoryPrintWin = null;
	 	clearTimeout(accHistoryPrintTimer);
	}

	if(openPdfFileWin)
	{
	 	openPdfFileWin.close();
		openPdfFileWin = null;
	 	clearTimeout(openPdfFileTimer);
	}

	closeAll();
}

function killSession(url)
{
    if (window.event)
    {
        if ((window.event.clientX < -5000 && window.event.clientY < -5000) || 
            (window.event.clientX > 5000 && window.event.clientY > 5000))
        {
        	//SGHPWS002
        	if (url==null) {
	            window.open("/1/2/IDV/HUB_PIB_KILLSESSION", "KillSession", "width=1,height=1,top=30000,left=30000,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=no, hotkeys=no");
        	} else {
        	//SGHPWS002 end
	            window.open(url, "KillSession", "width=1,height=1,top=30000,left=30000,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=no, hotkeys=no");
        	}
        }
    }
}

function pws_popupPdf(pdfUrl ,windowName, winProperties) {

var targetUrl=it_fullContextPath.substring(0,it_fullContextPath.length-1) + pdfUrl;
var hsbcheader='\n'
+ '    <html>\n'
+ '	    <script language="JavaScript" src="' + wt_header_url +'"><\/script>\n'
+ '	    <SCRIPT LANGUAGE="JavaScript">\n'
+ '		HSBC.SITE.rgn="Asia Pacific";\n'
+ '		HSBC.SITE.subrgn="Rest of Asia Pacific";\n'
+ '		HSBC.SITE.cnty="Australia";\n'
+ '	        HSBC.SITE.ent="HSBC Bank Australia Limited";\n'
+ '             HSBC.LOG.dcsuri="' + pdfUrl + '";\n'
+ '		HSBC.SITE.brand="HSBC";\n'
+ '  	  	HSBC.DCS.ID="dcsoerk141000004jdy7sftrk_3m8z";\n'
+ '    <\/SCRIPT>\n'
+ '    <script language="JavaScript" src="' + wt_footer_url + '"><\/SCRIPT>'
+ '     <body onload="window.location=\'' + targetUrl + '\';"><\/body>'
+ '    </html>\n'
+ '    \n';

   var popWin;
   if(winProperties != null && winProperties.length>0){   
   	popWin = window.open('','_blank',winProperties);   	
   } else {   
   	popWin = window.open('');   	
   }
  	popWin.document.write(hsbcheader);
   	popWin.document.close(); 	
	popWin.history.go(0); 
	popWin.focus();		 
	
}

