function printThisPage(strScriptPath, width, height) 
{ 
	var w=550;
	var h=600;
	if (width>0) { w=width; }
	if (height>0) { h=height; }
	var l=2;
	var t=2;	
	l=(screen.availWidth-w)/2;
	t=(screen.availHeight-h)/2;
	var sOption="toolbar=no,location=no,directories=no,menubar=yes,status=yes,scrollbars=yes,width="+ w  +",height="+ h +",left="+ l +",top="+ t +""; 			   
	var winprint=window.open(strScriptPath,"wHOP3Print",sOption); 			 
	winprint.focus(); 
}

function getPrintContent()
{     
	var PrintDiv =  document.getElementById('divPrintContent');
	var PrintTitleDiv = "";
	try { PrintTitleDiv = window.opener.document.getElementById('divPrintTitle'); } catch(errC) {}
	var SummaryDiv = "";
	try { SummaryDiv = window.opener.document.getElementById('article_summary'); } catch(errC) {}
	var ContentDiv =  "";
	try { ContentDiv = window.opener.document.getElementById('divPrintFriendlyContent'); } catch(errC) {}
	var SubContentDiv =  "";
	try { SubContentDiv = window.opener.document.getElementById('divPrintFriendlySubContent'); } catch(errC) {}
	var Parent_Title =  window.opener.document.title;
	document.title=Parent_Title;

	PrintDiv.innerHTML = "";
	if (PrintTitleDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div class='clear'>" + PrintTitleDiv.innerHTML + "</div><hr/>"; }
	if (SummaryDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div id='article_summary' class='clear'>" + SummaryDiv.innerHTML + "</div><hr/>"; }
	if (window.opener.document.getElementById('divPrintFriendlySubContent'))
	{ 
		if (window.opener.document.getElementById('content_wleft')) {
			if (SubContentDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div id='content'>" + SubContentDiv.innerHTML + "</div>"; }
		}
		else {
			if (SubContentDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div id='content_wleft'>" + SubContentDiv.innerHTML + "</div>"; }
		}
	}            
	else
	{ 
		if (window.opener.document.getElementById('content_wleft')) {
			if (ContentDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div id='content_wleft'>" + ContentDiv.innerHTML + "</div>"; }
		}
		else {
			if (ContentDiv) { PrintDiv.innerHTML = PrintDiv.innerHTML + "<div id='content'>" + ContentDiv.innerHTML + "</div>"; }
		}
	}            
	var ai=0;
	for(ai=0;ai<document.getElementsByTagName('a').length;ai++)
	{
		if ((document.getElementsByTagName('a')[ai].id!='hyperlinkPrint')&&(document.getElementsByTagName('a')[ai].id!='hyperlinkClose'))
		{
			document.getElementsByTagName('a')[ai].href='#';
			document.getElementsByTagName('a')[ai].onclick='return false;';
			document.getElementsByTagName('a')[ai].target='_self';            
		}
	}
	try
	{
	    for(ai=0;ai<document.getElementsByTagName('div').length;ai++)
	    {
		    if ((document.getElementsByTagName('div')[ai].id=='divSelfHelpTools')||(document.getElementsByTagName('div')[ai].id=='divCurrentRating'))
		    {
			    document.getElementsByTagName('div')[ai].innerHTML='';
			    document.getElementsByTagName('div')[ai].style.display='none';
		    }
	    }
	}
	catch(errC)
	{}
	
}

function setPrintStyleSheet()
{
    var strLayout = getContentStyleSheet("Layout");
    var strTypography = getContentStyleSheet("Typography");
    var strBody = getContentStyleSheet("Body");
    
    //document.getElementById("htmllinkcssLayout").href=strLayout;
    document.getElementById("htmllinkcssTypography").href=strTypography;
    document.getElementById("htmllinkcssBody").href=strBody;
}

function getContentStyleSheet(strNamePattern) 
{
    try 
    {
      var i, a;
          for(i=0; (a = window.opener.document.getElementsByTagName("link")[i]); i++) 
          {
            if (a.getAttribute("rel").indexOf("style") != -1 )  
            { if (a.getAttribute("id").indexOf(strNamePattern) != -1 ) 
              { return a.getAttribute("href"); }       
            }
          }         
      return null;       
   }
   catch(errC)
   { return null; }
}


function preloadImages()
{
	var imgPreload;
	imgPreload = new Image(); imgPreload.src = "/static/images/general/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/general/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/general/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/cancer/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/cancer/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/cancer/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/chronicdiseases/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/chronicdiseases/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/chronicdiseases/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/eyecare/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/eyecare/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/eyecare/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/foodforhealth/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/foodforhealth/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/foodforhealth/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/healthscreening/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthscreening/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthscreening/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyageing/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyageing/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyageing/tab_recommended_sel.gif";	
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyliving/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyliving/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/healthyliving/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/infectiousdiseases/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/infectiousdiseases/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/infectiousdiseases/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/mentalhealth/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/mentalhealth/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/mentalhealth/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/oralhealth/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/oralhealth/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/oralhealth/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/physicalactivity/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/physicalactivity/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/physicalactivity/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/pregnancyparenting/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/pregnancyparenting/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/pregnancyparenting/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/sexualhealth/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/sexualhealth/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/sexualhealth/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/smokefreeliving/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/smokefreeliving/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/smokefreeliving/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/studenthealth/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/studenthealth/tab_mostviewed_sel.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/studenthealth/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/substanceabuse/tab_recent.gif"; 
	imgPreload = new Image(); imgPreload.src = "/static/images/substanceabuse/tab_mostviewed_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/substanceabuse/tab_recommended_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/weightmanagement/tab_recent.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/weightmanagement/tab_mostviewed_sel.gif";
	imgPreload = new Image(); imgPreload.src = "/static/images/weightmanagement/tab_recommended_sel.gif";	
}

function getXmlHttpRequest()
{ 	var httpRequest=null;
	try
	{ httpRequest=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e)
	{
		try
		{ httpRequest=new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e)
		{ httpRequest=null; }
	}
	if(!httpRequest&&typeof XMLHttpRequest!="undefined")
	{ httpRequest=new XMLHttpRequest(); }
	return httpRequest;
}

function postURL(url, data, async, stateChangeCallback)
{
	var xmlHttpReq = getXmlHttpRequest();
	if (!xmlHttpReq)
		return;
	xmlHttpReq.open("POST", url, async);
	xmlHttpReq.onreadystatechange=function()
	{ stateChangeCallback(xmlHttpReq); };
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.send(data);	
}

function postURLWithCallbackID(id, url, data, async, stateChangeCallback)
{
	var xmlHttpReq = getXmlHttpRequest();
	if (!xmlHttpReq)
		return;
	xmlHttpReq.open("POST", url, async);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.send(data);	
	xmlHttpReq.onreadystatechange=function()
	{ stateChangeCallback(xmlHttpReq, id); };
}


function processReqChange(req)
{ 
	if (req.readyState==4||req.readyState=='complete')
	{
		if (req.status==200)
		{ }
	
	}
}


function HOP3SelectBodyStyleSheet(strBodyStyleSheet, strLinkID)
{
	var ehtmllinkcssBody = document.getElementById(strLinkID);
	ehtmllinkcssBody.setAttribute("href", strBodyStyleSheet);
	setCookie("EktHOP3HTMLLinkCSSBody", strBodyStyleSheet);
	
}

function setCookie(name,value,days)
{

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";

	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function getCookie(name) 
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf(prefix);
	if (begin == -1)
		return null;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function checkBoxListSelect(cbControl, state)
{   
       var chkBoxList = document.getElementById(cbControl);
        var chkBoxCount= chkBoxList.getElementsByTagName("input");
        for(var i=0;i<chkBoxCount.length;i++)
        {
            chkBoxCount[i].checked = state;
        }
       
        return false; 
}


function LTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
	var j=0, i = s.length;

	while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	j++;

	s = s.substring(j, i);
	}
	return s;
}

function RTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	var i = s.length - 1;       // Get length of string

	while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
	i--;

	s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str)
{
	return RTrim(LTrim(str));
}
  
function validateEmail(str)
{
	var emailExp = new RegExp("[A-Za-z0-9\-\_\+\.][A-Za-z0-9]+@[A-Za-z0-9\-\_][A-Za-z0-9]+\.[A-Za-z][A-Za-z\-\.]*$");
	if ( (Trim(str) == "") || (!emailExp.test(str)) || (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Trim(str)) ) )  
	{  return false; }        
	else
	{ return true; }
}  

function validateNRIC(str)
{
    var bValid = true;
	
    if (Trim(str) != "")
    {
	    // these variables used for NRIC checks
	    weight = new Array("2","7","6","5","4","3","2");
	    u_reftb = new Array("A","B","C","D","E","F","G","H","I","Z","J");
	    f_reftb = new Array("K","L","M","N","P","Q","R","T","U","W","X");
	    var i=0, prod=0, sum=0, rem = 0 ;
	    var pfx, chkdgt;

        if (str.length!=9)
        { bValid = false; }
        
        if (bValid)
        {
	        pfx    = Trim(str).charAt(0).toUpperCase();
	        chkdgt = Trim(str).charAt(8).toUpperCase();

	        if (pfx != 'I' && pfx != 'S' && pfx != 'T' &&
	        pfx != 'F' && pfx != 'G')
	        { bValid = false; }
	        for(i=0; i<7; i++)
	        {
		        prod = weight[i] * Trim(str).charAt(i+1);
		        sum +=prod;
	        }
	        if(pfx == 'T' || pfx == 'G')
	        {
		        sum +=4;
	        }
	        rem = sum % 11;
	        if (pfx == 'I' || pfx == 'S' || pfx == 'T')
	        {
		        if (chkdgt == u_reftb[(11-rem) -1])
		        { bValid = true; }
		        else
		        { bValid = false; }
	        }
	        else
	        {
		        if (chkdgt == f_reftb[(11-rem) -1])
		        { bValid = true; }
		        else
		        { bValid = false;	}
	        }
	   }
    }
    return bValid
}

