//This file is used in default.aspx and all other public pages
var parentWnd = self.opener;
var clickObj = null

var pageName = 'default.aspx';

function process_form(action) {
	var msg = "";

    GetElementByClientId("action").value = action
	//document.forms[0].ctl00_action.value=action

	if (msg=="")
		document.forms[0].submit();
	else
		alert(msg);
}
function CallSearch(ArticleID, ModuleID, OpenInNewWindow)
{

	//NB: Note added by tracey on 3rd April 2006. Please note that this function is duplicated in the common.js
	//file. Any change you make to this function must also be made in that file.
	var strEval
	strEval = GetElementByClientId('Module' + ModuleID + '_strSearchKeyword' + ModuleID).value;

	
	if (isblank(strEval))
	{
		alert ("Please enter your keywords");
		return;
	}




	// Add by Summer 1/May/2006 Cater for define the pop up window style
	// Add by Summer 14/March/2006 Cater for insite, across site and web search
	//modified by tracey on 5th Sept 2006. Always open in new window for Google so set height and width, scrollbars etc
	var objSearchOpRadio_0 = GetElementByClientId('Module' + ModuleID + '_radioSearchOption_0'); 
	var objSearchOpRadio_1 = GetElementByClientId('Module' + ModuleID + '_radioSearchOption_1');
	var objSearchOpRadio_2 = GetElementByClientId('Module' + ModuleID + '_radioSearchOption_2');

	if(objSearchOpRadio_2)
	{
		if(objSearchOpRadio_2.checked)
		{
            OpenInNewWindow=1
        }
    }        
	var windowStyle = "''";
	if(OpenInNewWindow==1)
	{

		var objWHeight = GetElementByClientId('Module' + ModuleID + '_textNewWindowHeight');
		var objWWidth = GetElementByClientId('Module' + ModuleID + '_textNewWindowWidth');
		var objWResize = GetElementByClientId('Module' + ModuleID + '_textNewWindiwResize');
		var scrollBars = 0;
		windowStyle = "'toolbar=yes"; //= "'height=600,width=800,status=1,resizeable=0,scrollbars=1'";

		if(objWHeight){
			if(IsNumber(objWHeight.value))
			{
				windowStyle = windowStyle + ",height=" + objWHeight.value;
				scrollBars = 1;
			}
		}
		if(objWWidth){
			if(IsNumber(objWWidth.value))
			{
				windowStyle = windowStyle + ",width=" + objWWidth.value;
				scrollBars = 1;
			}
		}
		if(objWResize){
			if(objWResize.value=="True")
			{
				windowStyle = windowStyle + ",resizable=yes";
				scrollBars = 1;
			}
			else if(objWResize.value=="False")
			{
				windowStyle = windowStyle + ",resizable=no";
				scrollBars = 1;
			}
		}
		if(scrollBars == 1)
		{
			windowStyle = windowStyle + ",scrollbars=1"
		}
		
	}
	
	if(objSearchOpRadio_2)
	{
		if(objSearchOpRadio_2.checked)
		{
			windowStyle = windowStyle + ",toolbar=1,menubar=1,titlebar=1,location=1'";
			url = "http://www.google.com.au/search?hl=en&q=" + escape(encodeMyHtml(strEval)) + "&meta=cr%3DcountryAU";
			window.open(url,'_blank',windowStyle,'true');
			return;
		} 
	}

	if(OpenInNewWindow==1)
	{
		windowStyle = windowStyle + "'";
	}	

	// End Add by Summer 14/March/2006
	
	//Added by Tracey on 24th May 2005. Cater for user friendly URLs
	var baseObj = GetElementByClientId('BaseDefault');
	var baseRef;
	if (baseObj) {
		baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'PerformSearch.aspx';
	} else {
		//Modified By Kevin L. on 22 Mar 06
		//Change to use the <script> tag and look for the src and find the correct root path
		//N.B. src attribute is case sensitive
		//baseRef = location.href.substring(0, location.href.lastIndexOf("/") + 1) + 'PerformSearch.aspx';
		var arrJSScript = document.getElementsByTagName('script');
		var jsSrc = '';
		baseRef = '';
		
		if (arrJSScript.length > 0) {
		  for (var i=0; i<arrJSScript.length; i++) {
		  
		    if (arrJSScript[i].getAttribute && arrJSScript[i].getAttribute('src')) {
		      jsSrc = arrJSScript[i].getAttribute('src');
		      if (jsSrc.toLowerCase().indexOf(pageName) >= 0) {
		        //N.B. default.js ALWAYS store in include/js, ../../ will neutralize the path structure
		        baseRef = jsSrc.substring(0, jsSrc.length-(pageName).length) + '../../PerformSearch.aspx';
		        break;
		      }
		    }
		  }
		}
		
		//Extreme case, hopefully will NEVER need this
		if (baseRef == '')
		  baseRef = '/PerformSearch.aspx';
	}

	//Added by Tracey on 15th Jan 2006. Cater for section of site to search
	var SiteSectionObj = document.getElementById(GetClientId('Module' + ModuleID + '_selSearchSection'));
	var SiteSectionValue;
	var SiteSectionDescr;
	if (SiteSectionObj && SiteSectionObj.selectedIndex >=0 ) {
		SiteSectionValue = SiteSectionObj.options[SiteSectionObj.selectedIndex].value;
		SiteSectionDescr = SiteSectionObj.options[SiteSectionObj.selectedIndex].text;
	} else {
		SiteSectionValue = '';
		SiteSectionDescr = '';
	}

	//////////// Add by Summer 14/March/2006 Cater for insite, across site and web search
	if(objSearchOpRadio_0)
	{
		if(objSearchOpRadio_0.checked)
		{
			if (OpenInNewWindow == 1)
			{
				window.open(baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr)) + "&multiSite=false",'_blank',windowStyle,'true');
			}	
			else
			{
				location.href = baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr)) + "&multiSite=false";		
			}
			return;
		}
	}
	// -------------------
	if(objSearchOpRadio_1)
	{
		if(objSearchOpRadio_1.checked)
		{
			if (OpenInNewWindow == 1)
			{
				window.open(baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr)) + "&multiSite=true",'_blank',windowStyle,'true');
			}	
			else
			{
				location.href = baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr))+ "&multiSite=true";		
			}
			return;
		}
	}
	// -------------------
	if (OpenInNewWindow == 1)
	{
		window.open(baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr)),'_blank',windowStyle,'true');
	}	
	else
	{
		location.href = baseRef + "?ArticleID=" + ArticleID + "&ModuleID=" + ModuleID + "&Keywords=" + escape(encodeMyHtml(strEval)) + "&SiteSection=" + escape(encodeMyHtml(SiteSectionValue))  + "&SiteSectionDescr=" + escape(encodeMyHtml(SiteSectionDescr));		
	}
	///////////// End Add by Summer 14/March/2006 Cater for insite, across site and web search
}

function encodeMyHtml(strValue)
{
var  encodedHtml = strValue; 
encodedHtml = stringreplace(encodedHtml, "=", "%3D");
encodedHtml = stringreplace(encodedHtml, "+", "%2B");
encodedHtml = stringreplace(encodedHtml, "?", "%3F");
encodedHtml = stringreplace(encodedHtml, "&", "%26");
encodedHtml = stringreplace(encodedHtml, "@", "%40");
return encodedHtml;
}

function CallNews(ArticleID, OpenInNewWindow)
{
	//Added by Tracey on 24th May 2005. Cater for user friendly URLs
	var baseObj = document.getElementById(GetClientId('BaseDefault'));
	var baseRef;
	if (baseObj) {
		baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + pageName;
	} else {
		baseRef = location.href;
	}

	if (OpenInNewWindow == 1)
		window.open(baseRef + "?ArticleID=" + ArticleID);		
	else
		location.href = baseRef + "?ArticleID=" + ArticleID ;		
}

function CallNewsUserFriendly(strURL, OpenInNewWindow)
{
	//Added by Tracey on 24th May 2005. Cater for user friendly URLs
	var baseObj = document.getElementById(GetClientId('BaseDefault'));
	var baseRef;
	if (baseObj) {
		baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1);
	} else {
		baseRef = location.href;
	}
	if (OpenInNewWindow == 1)
		window.open(baseRef + strURL);		
	else
		location.href = baseRef + strURL;		
}

function CallAdvert(strURL)
{
	window.open(strURL);		
}

function SetAction(action)
{
    GetElementByClientId('action').value = action;
	//document.forms[0].action.value=action
}

function ResubmitFormWithEdit(ArticleID)
{
	location.href = pageName + "?Mode=BusyEditing&ArticleID=" + ArticleID
}
function ResubmitForm(ArticleID)
{
	location.href = pageName + "?ArticleID=" + ArticleID
}

function PrintForm(sURL)
{
	var oWnd = window;	
	var oDoc = oWnd.document;	
	var strIFrame = "<iframe id='printHiddenFrame' name='printHiddenFrame' width='0' height='0'></iframe>";
	var strHFrame = "<frameset name=test onload='printMe.focus();printMe.print();' rows=\"100%\">" +
				"<frame name=printMe src=\""+sURL+"\">" +
				"</frameset>";

	if( oWnd.printHiddenFrame == null){
	  if (document.body.insertAdjacentHTML) {
	    //IE only
        oDoc.body.insertAdjacentHTML("beforeEnd", strIFrame);
         var framedoc = oWnd.printHiddenFrame.document;
         framedoc.open();
         framedoc.write(strHFrame);
         framedoc.close();
      } else if( typeof( document.body.innerHTML ) != 'undefined' ) {
         document.body.innerHTML += strIFrame;
         var framedoc = oWnd.printHiddenFrame.document;
         framedoc.open();
         framedoc.write(strHFrame);
         framedoc.close();
      } else {
        //use the old code
        var wndPrint = window.open(sURL, 'Print', 'toolbar=no,width=700,height=600,resizable, scrollbars');
        wndPrint.setTimeout('window.print();window.close();',1000);
      }
    } else {
      oWnd.printHiddenFrame.focus();
      oWnd.printHiddenFrame.print();
    }
}

function CheckKey(evt)
{
	if (evt.keyCode == 13)
	{
		if (!document.all && document.getElementById) {
			evt.preventDefault();
			evt.stopPropagation();
		}
		evt.cancelBubble = true;
		evt.returnValue = false;
		return false;
	}
}

function HandleSearch(evt, ArticleID, ModuleID, OpenInNewWindow)
{
	//NB: Note added by tracey on 3rd April 2006. Please note that this function is duplicated in the common.js
	//file. Any change you make to this function must also be made in that file.
	if (evt.keyCode == 13)
	{
		CallSearch(ArticleID, ModuleID, OpenInNewWindow)
		if (!document.all && document.getElementById) {
			evt.preventDefault();
			evt.stopPropagation();
		}
		evt.cancelBubble = true;
		evt.returnValue = false;
		return false;
	}
}
function CallLogin(ModuleID, CurrentPage) {

    var strUID;
    strUID = document.getElementById(GetClientId('Module' + ModuleID + '_strLoginName' + ModuleID)).value;

    var strPassword;
    strPassword = document.getElementById(GetClientId('Module' + ModuleID + '_strPassword')).value;

    var strUserType;
    if (document.getElementById(GetClientId('Module' + ModuleID + '_selUserType')) != null) {
        strUserType = document.getElementById(GetClientId('Module' + ModuleID + '_selUserType')).value;
    }

    //Added by Tracey on 28th Nov 2005. Cater for remember me cookie
    var strRememberMe;
    var strRememberMeURL = "";
    var strRememberMePassword = "";
    if (document.getElementById(GetClientId('Module' + ModuleID + '_chkRememberMe'))) {
        strRememberMe = document.getElementById(GetClientId('Module' + ModuleID + '_chkRememberMe')).checked;
        if (strRememberMe) {
            strRememberMeURL = '&RemCook=Yes';
        }
    }

    //Added by Tracey on 24th May 2005. Cater for user friendly URLs
    var baseObj = document.getElementById(GetClientId('BaseDefault'));
    var baseRef;

    //Added by WAN on 1 Oct 2008.  This will tell to login form to action when accessed CM Sub site.  eShop cannot use baseRef .
    var objAction = document.getElementById(GetClientId('hidSiteName'));
    
    //added by GJ 18/12/08 to look for hidSiteName in master.master page
    if (objAction==null)
        objAction=document.getElementById(GetClientId('ctl00$hidSiteName'));
        
    var strRef = ''
    if (objAction) {

        if (objAction.value != '') {
            strRef = objAction.value + '/Login.aspx';
        }
    }


    if (baseObj) {
        baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'Login.aspx';
    } else {
        baseRef = location.href;

    }


    if (document.getElementById) {
        
        var Redirect_param = getURLparameter('RedirectURL');
        if (Redirect_param) {
            CurrentPage = Redirect_param;
        }
        else {
            CurrentPage = window.location.href;
        }
        
    if (strRef == '')
	{
		if(document.getElementById(GetClientId('form2')).action == '') 
		{        
		    document.getElementById(GetClientId('form2')).action =  'login.aspx?PublicPage=Yes' + strRememberMeURL + '&RedirectURL=' + CurrentPage;
		}
		else
		{

            //21 Jan 2009 Added by wan to prevent duplicated querystrings.
            var strRedirect = document.getElementById(GetClientId('form2')).action
            if (strRedirect.toLowerCase().indexOf('&redirecturl') > 0)
                document.getElementById(GetClientId('form2')).action = strRedirect
            else
                document.getElementById(GetClientId('form2')).action = strRedirect + '?PublicPage=Yes' + strRememberMeURL + '&RedirectURL=' + CurrentPage;

//		    document.getElementById(GetClientId('form2').action = document.getElementById(GetClientId('form2').action + '?PublicPage=Yes' + strRememberMeURL + '&RedirectURL=' + CurrentPage;
		}
	}
        else
            document.getElementById(GetClientId('form2')).action = strRef + '?PublicPage=Yes' + strRememberMeURL + '&RedirectURL=' + CurrentPage;

        document.getElementById(GetClientId('form2')).UID.value = strUID;
        document.getElementById(GetClientId('form2')).PWD.value = strPassword;
        
        if (document.getElementById(GetClientId('form2')).selUserType != null) {
            document.getElementById(GetClientId('form2')).selUserType.value = strUserType;
        }
        document.getElementById(GetClientId('form2')).submit();
    }
    return false;
}

function HandleLogin(evt, ModuleID, CurrentPage)
{
	if (evt.keyCode == 13)
	{
		CallLogin(ModuleID, CurrentPage)
		
		if (!document.all && document.getElementById) {
			evt.preventDefault();
			evt.stopPropagation();
		}
		evt.cancelBubble = true;
		evt.returnValue = false;
		return false;

	}
}
function getURLparameter(name)
{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS, "i" );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
		return results[1];
}

function ReferFriendOpen(strURL, intArticleID, strPageToOpen)
{
	window.open(strPageToOpen + '?Article=' + intArticleID + '&' + strURL, 'Help', 'toolbar=no,width=580,height=420,resize=no, scrollbar=no');
}


/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!

  This is used when embedding the shopping site inside an iframe.
  Use these function to allow the iframe to resize depending on the size
  of the shopping page so that scroll bars do not show.
*************************************************************************/

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  
if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) {
		docHt = Math.max(sh, oh);
	}
	else if (!sh && oh) {
		docHt = oh;
	}
	else if (sh && !oh) {
		docHt = sh;
	}

}
  return docHt;
}

function getDocWidth(doc) {
  var docWt = 0, sw, ow;

if (doc.body) {
    if (doc.body.scrollWidth) docWt = sw = doc.body.scrollWidth;
    if (doc.body.offsetWidth) docWt = ow = doc.body.offsetWidth;
    if (sw && ow) {
		docWt = Math.max(sw, ow);
	}
    else if (!sw && ow) {
		docWt = ow
    }
    else if (sw && !ow) {
		docWt = sw;
    }
  }
  return docWt;
}

function ResizeParentFrame(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(GetClientId(iframeName)): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
  
    //iframeEl.style.height = "30px";
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
	var docHt 
    var docWt 
	if (iframeEl.contentDocument != null) {
		docHt = getDocHeight(iframeEl.contentDocument);
		docWt = getDocWidth(iframeEl.contentDocument);
	}
	else if (iframeEl.Document) {
		docHt = getDocHeight(iframeEl.Document);
		docWt = getDocWidth(iframeEl.Document);
	}    
    
    
    
    
    if (docHt) iframeEl.style.height = docHt + "px";
    if (docWt) iframeEl.style.width = docWt + "px";
   //alert("height" + docHt + "px");
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}

function ExecParentWndScript(sScript, close) {

if (! parentWnd)
  return;

if (parentWnd.closed)
  return;

if (parentWnd.execScript) {
parentWnd.execScript (sScript);
}
else
{
window.parent.eval(sScript);
}

 if (close)
  setTimeout ("window.close", 2000);

}

function CallArticle(ArticleID) 
{
    location.href = pageName + "?ArticleID=" + ArticleID;
}

function CallURL(strURL) 
{
	location.href = (strURL)
}
function isvalidemail(s) {

		if (s.length > 0) {
			if (s.indexOf("@")!=-1 && s.indexOf(".")!=-1)  {
				//email is valid
				return true;	
			}
			else {
				//email is not valid
				return false;
			}			
		}
		else {
			//if string is empty just return true as we assume 
			//the field is not mandatory.
			return true;
		}
		
}
function is_checked(sele) 
{
			var i;
			var num_of_selection;
			
			if 	(!sele)
				return false
				
			if (sele.length) {
				num_of_selection = sele.length;
				for (i = 0; i < num_of_selection; i++) 
					if  (sele[i].checked) 
						return true;
			}
			else
				return sele.checked
}


function isblank(s) {
		for( var i = 0; i < s.length; i++ ) {
			var c = s.charAt(i);
			if ( (c != ' ') && (c != '\n') && (c != '\t') )
				return false;
		}
		return true;
}
function ShowTopMenuDisclaimer(strHref, strDisclaimerText)
{
	if (confirm(strDisclaimerText))
	{
		location.href = strHref;
	}

}
var newWnd = null;
function menuOpenWnd(sURL, sWnd, sFeature)
{
	if (newWnd != null)
		newWnd.close();
	newWnd = window.open(sURL, sWnd, sFeature);
	newWnd.focus();
	return;
}

function menuChangeImage(imgElmName, imgVarName)
{
	if (!document.images[imgElmName])
	return;
	document.images[imgElmName].src = imgVarName.src;
}

function menuChangeBGImage(elmName, imgVarName)
{

	if (!document.getElementById(GetClientId(elmName)))
	return;
	if (!document.getElementById(GetClientId(elmName)).style)
	return;

	document.getElementById(GetClientId(elmName)).style.backgroundImage = 'url(' + imgVarName.src + ')';
}

//Added by Tracey on 19th May 2005.
function stringreplace(checkMe,toberep,repwith)
{

	var temp = checkMe;
	var i = temp.indexOf(toberep);
	while(i > -1)
	{
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}		
//**************************************************************************************************
// Session Timer Functions
//**************************************************************************************************
//You need to paste the following code in the body tag of the page you have included this file in
//onLoad="formTimer()"
//You also need to ensure that the following pages are in the same directory as the page you are adding the timer function to
//AbandonSession.asp and SessionExtension.asp
var sessionwindow=null;
var Stimer=null;
var oNewDoc;
var sessionState = "";
var TimeInMSec = 0;
var sessionTimeout = 0;
var TimeTillWarning;
var SessionSaveContent=0; // SessionSaveContent=1 currently in article edit mode. Note, this is different to
						  // radEditMode=true which means RAD editor is in edit mode.
						  // SessionSaveContent=0 not in edit mode.

function formTimer(TimeoutInMin, bSaveContent, strTimeoutURL){

	SessionSaveContent=bSaveContent;

	if (!Stimer) {
		//alert('timer on')
		window.clearTimeout(Stimer)
	}
	//alert('state==' + sessionState);
	if (sessionState =="") {
		//session has just begun, so set the state to 'Current'
		sessionState = "Current";
		sessionTimeout = TimeoutInMin;
		if (sessionTimeout>4) {
			//display popup window 4 minutes before session expires
			TimeTillWarning=sessionTimeout-4;
		}
		else {
			TimeTillWarning = sessionTimeout
		}
		
		TimeInMSec = 1000*60*TimeTillWarning
		Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ", '" + strTimeoutURL + "')", TimeInMSec) 
	}
	else if (sessionState=="Current") {
		
		//session is about to expire, so set the state to 'AboutToExpire'
		sessionState = "AboutToExpire"
		
		//display the popup window if not currently displayed
		if (!sessionwindow||sessionwindow.closed) {
			sessionwindow = window.open('','','toolbar=no,width=330,height=210,titlebar=no');
			if (sessionwindow != null) {

				if (!sessionwindow.opener) {
					sessionwindow.opener = window
				}

				oNewDoc = sessionwindow.document.open();

				var baseObj = document.getElementById(GetClientId('BaseDefault'));
				var baseRef;
				if (baseObj) {
					baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'SessionExtension.aspx';
				} else {
					baseRef = location.href.substring(0, location.href.lastIndexOf("/") + 1) + 'SessionExtension.aspx';
				}

				//write out html now!!!
				formcontent = '<html>'
				
				formcontent += '<body background="' + strTimeoutURL + '/images/extend_bg_elcom.jpg">'
				formcontent += '<table><tr><td colspan=2><img src="' + strTimeoutURL + '/images/trans.gif" width=100 height=110 /></td></tr><tr><td><img src="' + strTimeoutURL + '/images/trans.gif" width=100 height=10></td><td valign=middle align=right>'
				formcontent += '<tr><td colspan=2><font color=white face=verdana size=1><b>There has been no activity for an extended period. Click here to extend the session or it will expire in 2 minutes.</b></font></td></tr><tr><td><img src="' + strTimeoutURL + '/images/trans.gif" width=100 height=10 /></td><td valign=middle align=right>'
				formcontent += '<a href="' + baseRef + '"><img src="' + strTimeoutURL + '/images/click_extend.gif" border="0" align=right /></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				formcontent += '</td></tr></table>'
				formcontent += '</body>'
				formcontent += '</html>'

				oNewDoc.write(formcontent);
				oNewDoc.close();
			}
		}
		else {
			//popup window already displayed, so just show it
			sessionwindow.focus();
		}	

		//give the user 2 more minutes before killing the session if they have not extended the session.
		TimeInMSec = 1000*60*2
		Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ", '" + strTimeoutURL + "')", TimeInMSec) 
	}
	else if (sessionState=="AboutToExpire") {
		//session has expired
		
		sessionState = ""

		if (!sessionwindow||sessionwindow.closed) {
			//popup window is closed, do nothing
		}
		else {
			//popup window still open, so close it
			sessionwindow.close();
		}
		//Save the article content if required (function will check if RAD editor
		//is in edit mode. If so, the content will be saved).
		if (SessionSaveContent==1) {
			saveNoCheckIn();
		}
		//kill the session 
		//window.location.href = "SessionAbandon.aspx"
		var baseObj = document.getElementById(GetClientId('BaseDefault'));
		var baseRef;
		if (baseObj) {
			baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'SessionAbandon.aspx';
		} else {
			baseRef = location.href.substring(0, location.href.lastIndexOf("/") + 1) + 'SessionAbandon.aspx';
		}
		window.location = baseRef // "SessionAbandon.aspx"

	}
}

function resetTimer(strTimeoutURL)
{
	//user has extended the session so reset the timer
	window.clearTimeout(Stimer)
	sessionState = "Current"
	TimeInMSec = 1000*60*TimeTillWarning
 	Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ", '" + strTimeoutURL + "')",TimeInMSec) 

}

function BodyOnLoadJS() {
	goSetHeightinCMDefault();
}

function goSetHeightinCMDefault() {
	if (parent == window) {
		return;
	}
	else {
		parent.setIframeHeightinCMDefault('AnotherWebsiteFrame');
		
	}
}
function setIframeHeightinCMDefault(iframeName) {
		//var iframeWin = window.frames[iframeName];
		//var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
		var iframeEl;// = document.getElementById(iframeName);
		var doc;



		if (document.getElementById(GetClientId(iframeName)) != null) {
			iframeEl = document.getElementById(GetClientId(iframeName));
		}
		else if (parent.document.getElementById(GetClientId(iframeName)) != null) {
			iframeEl = parent.document.getElementById(GetClientId(iframeName));
		}
		else {
		   var pWnd = parent.parent;
		   iframeEl = pWnd.document.getElementById(GetClientId(iframeName))
		   while (pWnd != top && iframeEl != null){
				iframeEl = pWnd.document.getElementById(GetClientId(iframeName))
				pWnd  = pWnd.parent;
			}
		}

	if (iframeEl) {
		if (iframeEl.contentDocument != null) {
			doc = iframeEl.contentDocument;
		}
		else if (iframeEl.Document) {
			doc = iframeEl.Document;
		}
		
		//if ( iframeEl && iframeWin ) {
		if (iframeEl) {

			var docHt = getDocHeight(doc);
			var docWt = getDocWidth(doc);

			if (docHt) iframeEl.height = docHt + "px";
			if (docWt) iframeEl.width = docWt + "px";

			}
	}
}

function HandleCreateWikiBlog(evt, strType, ArticleID, ModuleID, FolderID)
{
	if (evt.keyCode == 13)
	{
		CreateWikiBlog(strType, ArticleID, ModuleID, FolderID)
		if (!document.all && document.getElementById) {
			evt.preventDefault();
			evt.stopPropagation();
		}
		evt.cancelBubble = true;
		evt.returnValue = false;
		return false;
	}
}

function CreateWikiBlog(strType, ArticleID, ModuleID, FolderID)
{

	var strEval
	strEval = document.getElementById(GetClientId('Module' + ModuleID + '_strWikiBlogName' + ModuleID)).value;
	
	if (isblank(strEval))
	{
		if (strType == "W")
		{
			alert ("Please enter the name for your wiki");
		}
		else
		{
			alert ("Please enter the name for your blog");
		}
		return;
	}

	var baseObj = document.getElementById(GetClientId('BaseDefault'));
	var baseRef;
	if (baseObj) {
		baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'ContentCreateFolderForWikiBlog.aspx';
	} else {
		baseRef = location.href.substring(0, location.href.lastIndexOf("/") + 1) + 'ContentCreateFolderForWikiBlog.aspx';
	}

	location.href = baseRef + "?ArticleID=" + ArticleID + "&CreateFolderID=" + FolderID + "&ModuleID=" + ModuleID + "&Type=" + strType + "&Name=" + escape(encodeMyHtml(strEval));		

}

	function setActiveStyleSheet(title) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {

			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
			{
				a.disabled = true;
				if(a.getAttribute("title") == title)
				{ 
					a.disabled = false;
				}
			}
		}
	}

	function getActiveStyleSheet() {

		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	}
	
	function IsNumber(strString)
	{
	    var mNumRegex = new RegExp(/^[\d]+$/)
	    var blnResult = true;
	    if (!mNumRegex.test(strString)) { blnResult = false; }
	    return blnResult;
	}

function IsAlphabets(strString) {
    var mAlphaRegex = new RegExp(/^[a-zA-Z\s]+$/)
    var blnResult = true;
    if (!mAlphaRegex.test(strString)) { blnResult = false; }
    return blnResult;
}

function IsAlphaNumeric(strString) {

    var mAlphaNumRegex = new RegExp(/^([\w\d\s]+)$/)
    var blnResult = true;
    if (!mAlphaNumRegex.test(strString)) { blnResult = false; }
    return blnResult;
}

function IsPersonName(strString) {
    var mPersonNameRegex = new RegExp(/^[a-zA-Z\-\'\s]+$/)
    var blnResult = true;
    if (!mPersonNameRegex.test(strString)) { blnResult = false; }
    return blnResult;

}
function DeleteArticleComment(objDiv,commentid){
		var ajaxClass = null;
		var ajaxClassName = null;
		ajaxClassName = location.pathname.substring(location.pathname.lastIndexOf('/')+ 1, location.pathname.length);
		var re = /\.aspx/gi;
		ajaxClassName = ajaxClassName.replace(re, '_aspx');
		ajaxClassName = 'default_aspx';//classname is case sensitive
		if (typeof(ASP) != 'undefined')
			ajaxClass = eval('ASP.' + ajaxClassName);
		else if (typeof(_ASP) != 'undefined')
			ajaxClass = eval('_ASP.' + ajaxClassName);
		if (ajaxClass == null)  {
		  alert('Failed to initialize AJAX class.');
		  return;
		}
		if(confirm("Are you sure you want to delete this comment?"))
		{
			ajaxClass.DeleteArticleComment(commentid, function(result) {
					objDiv.parentNode.removeChild(objDiv);
			});
		}	
}
function OpenEvent(EventID, EventDetailsType, StyleFolderID,PathLocation)
		{       // GJ 16/6/08 - Added new parameter PathLocation. Allows this function to be called in other
		        // projects (eg. MyAccounts) where the location of the pages to be redirected to (below) are 
		        // 1 folder level up.
		        
		        // GJ 16/6/08 - check if PathLocation is null
		        if (PathLocation==null) {
		            PathLocation='';
		        }
				if (EventDetailsType == 'B')
				{
					location.href = PathLocation + "EventViewBookingDetails.aspx?ReturnURL=MyAccount/MyCalendar.aspx&Bck=Y&EventID=" + EventID  + "&StyleFolder=" + StyleFolderID;
				}	
				else
				{	
					if (EventDetailsType == 'T')
					{
						location.href = PathLocation + "EventViewTrainingDetails.aspx?ReturnURL=MyAccount/MyCalendar.aspx&Bck=Y&EventID=" + EventID  + "&StyleFolder=" + StyleFolderID;
					}
					else
					{
						location.href = PathLocation + "EventView.aspx?ReturnURL=MyAccount/MyCalendar.aspx&Bck=Y&EventID=" + EventID  + "&StyleFolder=" + StyleFolderID;
					}	
				}		

		}

function openAddToFavourite(ArticleID, FolderID, EventID) {
	window.open('MyAccount/MyFavouritesAdd.aspx?AID=' + ArticleID + '&FID=' + FolderID + '&EID=' + EventID, 'Favourites', 'HEIGHT=200,WIDTH=300,TOOLBAR=NO,SCROLLBARS=NO');
}


function getRateImage(intID, strAction, strHTTP, strURL) {
    var strImage 
    //alert( window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1));
    //Images link will not work if this page is called from the sub levels.
    if (strAction == 'IN')  {
        strImage = strHTTP + '//' + strURL + '/images/starInput.gif';
    }
    else {
        strImage = strHTTP + '//' + strURL + '/images/starOff.gif';
    }   
        
     for (var i=1; i<6; i++) {   
        if (i <= intID) {
            document.getElementById(GetClientId('imgRate' + i)).src = strImage;
        }
      }
}

function ratePage(intValue, ArticleID, FolderID, URLID, strHTTP, strURL) {
         	window.open(strHTTP + '//' + strURL + '/RatingResults.aspx?V=' + intValue + '&AID=' + ArticleID + '&FID=' + FolderID + '&U=' + URLID, 'PageRate', 'HEIGHT=280,WIDTH=320,TOOLBAR=NO,SCROLLBARS=NO');
}

function addToFavourites(strURL, intArticleID, intFolderID) {
      window.open('http://' + strURL + '/MyAccount/MyFavouritesAdd.aspx?AID=' + intArticleID + '&FID=' + intFolderID, 'PageRate', 'HEIGHT=280,WIDTH=320,TOOLBAR=NO,SCROLLBARS=NO');
}

function OpenArticle(strURL, OpenInNewWindow)
{
	if (OpenInNewWindow == 1)
		    window.open(strURL);		
	    else
		    location.href = strURL;		
}

//added by balaji to compare url's on 12th december
function compareURL(url1,url2)
{      
    url1 = url1 + '/';
    url2 = url2 + '/';                           
    var  shortURL = new String();
    shortURL = url1;
    var  longURL = new String();         
    longURL = url2;         
            
        if(url1.toString().length > url2.toString().length){            
            shortURL = url2.toString();
            longURL = url1.toString();
        }                                     

    //url without http: or https:
    shortURL = shortURL.substring(shortURL.indexOf('//')+2);
    longURL = longURL.substring(longURL.indexOf('//')+2);

    //absolute path
    shortURL = shortURL.substring(0,shortURL.indexOf('/'));
    longURL = longURL.substring(0,longURL.indexOf('/'));
                     
        //alert(' short: ' + shortURL.toLowerCase() + ' long: ' + longURL.toLowerCase())                       
        return (shortURL.toLowerCase() == longURL.toLowerCase());
}
function CallForgottenPassword(ModuleID)
{
	var baseObj = document.getElementById(GetClientId('BaseDefault'));
	var baseRef;
	if (baseObj) {
		baseRef = baseObj.href.substring(0, baseObj.href.lastIndexOf("/") + 1) + 'ForgottenPassword.aspx';
	} else {
		//Modified By Kevin L. on 22 Mar 06
		//Change to use the <script> tag and look for the src and find the correct root path
		//N.B. src attribute is case sensitive
		//baseRef = location.href.substring(0, location.href.lastIndexOf("/") + 1) + 'PerformSearch.aspx';
		var arrJSScript = document.getElementsByTagName('script');
		var jsSrc = '';
		baseRef = '';
		if (arrJSScript.length > 0) {
		  for (var i=0; i<arrJSScript.length; i++) {
		  
		    if (arrJSScript[i].getAttribute && arrJSScript[i].getAttribute('src')) {
		      jsSrc = arrJSScript[i].getAttribute('src');
		      if (jsSrc.toLowerCase().indexOf(pageName) >= 0) {
		        //N.B. default.js ALWAYS store in include/js, ../../ will neutralize the path structure
		        baseRef = jsSrc.substring(0, jsSrc.length-(pageName).length) + '../../ForgottenPassword.aspx';
		        break;
		      }
		    }
		  }
		}
		
		//Extreme case, hopefully will NEVER need this
		if (baseRef == '')
		  baseRef = '/ForgottenPassword.aspx';
	}
	var objUserName = GetElementByClientId('Module' + ModuleID + '_strLoginName' + ModuleID);
	if(objUserName)
	{
		location.href = baseRef + "?UserName=" + objUserName.value;
	}        
	else
	{
		location.href = baseRef 
	}
}


function GetElementByClientId(ID) {
    return document.getElementById(GetClientId(ID));
}

function GetClientId(ID) {
    var prefix;

    var newID;

    newID = ID;
    if (document.getElementById(newID) != null) return newID;
    if (document.forms[0].elements["hdnMasterPageControl"] != null) {
        prefix = document.forms[0].elements["hdnMasterPageControl"].value;
        newID = prefix + "_" + ID;
        if (document.getElementById(newID) != null) return newID; 
    }

    if (document.forms[0].elements["hdnContentPlaceHolderMain"] != null) {
        prefix = document.forms[0].elements["hdnContentPlaceHolderMain"].value;
        newID = prefix + "_" + ID;
        if (document.getElementById(newID) != null) return newID;
    }

    if (document.forms[0].elements["hdnContentPlaceHolderMainNoAjax"] != null) {
        prefix = document.forms[0].elements["hdnContentPlaceHolderMainNoAjax"].value;
        newID = prefix + "_" + ID;
        if (document.getElementById(newID) != null) return newID;
    }
 
        prefix = "ctl00_ContentPlaceHolderMainNoAjax"
        newID = prefix + "_" + ID;
        if (document.getElementById(newID) != null) return newID;


        prefix = "ctl00_ContentPlaceHolderMain"
        newID = prefix + "_" + ID;
        if (document.getElementById(newID) != null) return newID;
  
}

