var BROWS_DOM = document.getElementById ? true : false;
var BROWS_IE  = document.all ? true : false;
var BROWS_NS4 = document.layers ? true : false;
var m_dToday = new Date();
var obj_ExpandableIcon_Off = new Image();
var obj_ExpandableIcon_On = new Image();
obj_ExpandableIcon_Off.src = "/images/gr_linkArrowBodyTxtW.gif";
obj_ExpandableIcon_On.src = "/images/gr_linkArrowBodyExpanded.gif";


// ###############################################################################################################################################################################################################
// FUNCTION NAME:	set font size
// PASSED VALUES:	
// CREATED BY:		Karen Dai
// DATE CREATED:	17/06/08
// COMMENTS: 		seting font size function
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	
var minFont=8;
var maxFont=12;
var normalFont = 9;


var fontCookie = "fontCookie";






// ###############################################################################################################################################################################################################
// FUNCTION NAME:	increaseFontSize and decreaseFontSize
// PASSED VALUES:	
// CREATED BY:		Karen Dai
// DATE CREATED:	17/06/08
// COMMENTS: 		seting font size function
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function increaseFontSizeIntegrated() {
   var p = document.getElementById('container');
   var s;
    
      if((getCookie(fontCookie)=="") || (getCookie(fontCookie)==null))
		{
		s = normalFont;	
	
		}
		else
		{
		 s = parseInt(getCookie(fontCookie))
		
		}
      
      
      if(s!=maxFont) {
         s += 1;
      }
      //$("body").css("fontSize",s+"pt");
      p.style.fontSize = s+"pt"
      setCookie (fontCookie, s);
  
}

function setFontSizeIntegrated() {
   var p = document.getElementById('container');
   var s;
   
  
      /*if(p.style.fontSize) {
         var s = parseInt(p.style.fontSize.replace("pt",""));
      } else {
         var s = normalFont;
      }*/
      if((getCookie(fontCookie)=="") || (getCookie(fontCookie)==null))
		{
		s = normalFont;	
	
		}
		else
		{
		 s = parseInt(getCookie(fontCookie))
		
		}

     //$("body").css("fontSize","14pt");
      p.style.fontSize = s+"pt"
     
      setCookie (fontCookie, s);
  
}



function decreaseFontSizeIntegrated() {
   var p = document.getElementById('container');
   var s;
    if((getCookie(fontCookie)=="") || (getCookie(fontCookie)==null))
		{
		s = normalFont;	
			
		}
		else
		{
		 s = getCookie(fontCookie)
		}
      if(s!=minFont) {
         s -= 1;
      }
      
       //$("body").css("fontSize",s+"pt");
      p.style.fontSize = s+"pt"
     
      setCookie (fontCookie, s);
}


// ###############################################################################################################################################################################################################
// FUNCTION NAME:	setCookie
// PASSED VALUES:	cookieName - String
// 					cookieValue - String
// 					expires (optional) - Date Object
// 					path (optional) - String containing the path defines the part of the document tree on the server that the cookie is valid for.
// 					domain (optional) - The domain argument allows multiple server hosts to be used.
// 					secure (optional) - The secure value is boolean and only applicable for use with HTTPS: connections.
// CREATED BY:		Stephen Phillips
// DATE CREATED:	17/03/05
// COMMENTS: 		A function that sets cookie values properly
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	function setCookie(cookieName, cookieValue, expires, path, domain, secure)
	{
		path='/'
		
		document.cookie = escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
			+ (path ? '; PATH=' + path : '')
			+ (domain ? '; DOMAIN=' + domain : '')
			+ (secure ? '; SECURE' : '');
	}


// ###############################################################################################################################################################################################################
// FUNCTION NAME:	getCookie
// PASSED VALUES:	cookieName - The name of the cookie to be used
// CREATED BY:		Stephen Phillips
// DATE CREATED:	17/03/05
// COMMENTS: 		A complementary function to unwrap a cookie.
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	function getCookie(cookieName)
	{
		var cookieValue = null;
		var posName = document.cookie.indexOf(escape(cookieName) + '=');
		
		if (posName != -1)
		{
			var posValue = posName + (escape(cookieName) + '=').length;
			var endPos = document.cookie.indexOf(';', posValue);
			endPos != -1 ? cookieValue = unescape(document.cookie.substring(posValue, endPos)) : cookieValue = unescape(document.cookie.substring(posValue));
		}
		return cookieValue;
	}





function setFormFocus(obj_Document)
{
	obj_Document.forms[0].elements[0].focus();
}

function popNewWindow(name,url,height,width)
{
	options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',copyhistory=no,left=0,right=0';
    window.open(url,name,options);
}

function popBankingWindow(name,url,height,width)
{
	options = 'toolbar=no,location=no,directories=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',copyhistory=no,left=0,right=0';
    window.open(url,name,options);
}

function popNewStandardWindow(name,url,height,width,bln_options)
{
	options = 'toolbar='+bln_options+',location='+bln_options+',directories='+bln_options+',status='+bln_options+',menubar='+bln_options+',status='+bln_options+',scrollbars='+bln_options+',resizable='+bln_options+',width=' + width + ',height=' + height + ',copyhistory=no,left=0,right=0';
	window.open(url,name,options);
}

function popWebinar(m_sName, m_sUrl, m_sHeight, m_sWidth, m_sScroll)
{
	m_sOptions = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=' + m_sWidth + ',height=' + m_sHeight + ',copyhistory=no';
    window.open(m_sUrl,m_sName,m_sOptions);
}

function linkRollover(str_lnkId,str_imgId,str_ClassName,str_state)
{
	objImg = eval(str_imgId);
	objLnk = eval(str_lnkId);
	if(objLnk && objImg)
	{
		// Image Object and Link object are valid
		imgSwap(str_imgId,str_state);
		str_state=="1"?objLnk.className = str_ClassName + "On":objLnk.className = str_ClassName + "Off";
	}
	else if(objLnk)
	{
		// Only the Link object is valid
		str_state=="1"?objLnk.className = str_ClassName + "On":objLnk.className = str_ClassName + "Off";
	}
}

function imgSwap(id,state)
{
	var m_sSource = new String(eval(id).src);
	if(state)
	{
		var myRegExp = /_off/gi;
		eval(id).src = m_sSource.replace(myRegExp, "_on");
		//alert("Original src: " + eval(id).src + "\nChanged src: " + m_sSource.replace(myRegExp, "_on"));
	}
	else
	{
		var myRegExp = /_on/gi;
		eval(id).src = m_sSource.replace(myRegExp, "_off");
	}
}

function showHide_Section(elList,str_image,str_textLink)
{
	if(!(BROWS_DOM||BROWS_IE||BROWS_NS4)) return true;
	if(BROWS_NS4&&(toggleBy=="tag")) return true;
	for(var i=0; i<elList.length; i++)
	{
		var ElementsToToggle = [0];
		var obj_image = eval(str_image);
		var obj_textLink = eval(str_textLink);
		ElementsToToggle[0] = (BROWS_DOM) ? document.getElementById(elList[i]) : (BROWS_IE) ? document.all(elList[i]) : document.layers[elList[i]];
		for(var j=0; j<ElementsToToggle.length; j++)
		{
			var theElement = ElementsToToggle[j];
			if(!theElement) continue;
			if(BROWS_DOM||BROWS_IE)
			{
				if(theElement.style.visibility != "hidden")
				{
					theElement.style.visibility = "hidden";
					theElement.style.display = "none";
					if(obj_textLink)
					{
						obj_textLink.className="linkOff";
					}
					obj_image.src = obj_ExpandableIcon_Off.src;
					obj_image.style.visibility = "visible";
					obj_image.style.display = "inline";
				}

				else
				{
					theElement.style.visibility = "visible";
					theElement.style.display = "inline";
					if(obj_textLink)
					{
						obj_textLink.className="linkOn";
					}
					obj_image.src = obj_ExpandableIcon_On.src;
					obj_image.style.visibility = "visible";
					obj_image.style.display = "inline";
				}

			}
			else
			{
				if(theElement.visibility == "hide")
				{
					theElement.visibility = "inherit";
					theElement.display = "inline";
					if(obj_textLink)
					{
						obj_textLink.className="linkOn";
					}
					obj_image.src = obj_ExpandableIcon_Off.src;
					obj_image.visibility = "inherit";
					obj_image.display = "inline";
				}
				else
				{
					theElement.visibility = "hide";
					theElement.display = "none";
					if(obj_textLink)
					{
						obj_textLink.className="linkOff";
					}
					obj_image.src = obj_ExpandableIcon_On.src;
					obj_image.visibility = "visible";
					obj_image.display = "inline";
				}
			}
		}
	}
	return true;
}

function getImageXfromLeft(imgID) {
  if (BROWS_NS4) return eval(imgID).x
  else return getRealLeft(imgID);
}

function getImageYfromTop(imgID) {
  if (BROWS_NS4) return eval(imgID).y;
  else return getRealTop(imgID);
}

function getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

// Form Validation
function blankInput(objField)
{
	return objField.value=="" || objField.value==null;
}

// Email Validation
function validEmail(strValue)
{
	return strValue.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i)>-1;
}

// Form Authentication
function authenticateForm(objForm)	// objForm is a reference to the form object
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
			xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		{
		
		    //alert(xmlHttp.responseText)
		
			if(xmlHttp.responseText=="True")
			{
			    if(objForm.comments && objForm.comments.value !="")
			    objForm.comments.value = checkValidInputCharacters(objForm.comments.value)
				//FIrefox wasn't finding the objForm.				
				objForm.submit();
				
				
			}
			else
			{
				alert("Authentication details are incorrect. Please try again.")
 				//Recaptcha.reload();
 				//window.location.reload(false);
 				changeBGImage();
 				return false;
			}
			
		}
	}
	strRechallenge = document.getElementById('strCAPTCHA').value;
	//strResponse = document.getElementById('recaptcha_response_field').value;
	strURL = "/authentication.asp?chal=" + strRechallenge
	xmlHttp.open("GET",strURL,true);
	xmlHttp.send(null);
}

function changeBGImage(){
if (navigator.appVersion.indexOf("MSIE")!=-1){
    if (document.getElementById('reload_img'))
        document.getElementById('reload_img').src='/captcha.asp';
}else window.location.reload(false);
}

function checkValidInputCharacters(str_Value)
{
	if(window.RegExp)
	{
		var str_Value = new String(str_Value);
		str_Value = str_Value.replace(/[\<]/g, "&lt;"); // replaces all < with the Ascii character code equivelant
		str_Value = str_Value.replace(/[\>]/g, "&gt;"); // replaces all > with the Ascii character code equivelant
		str_Value = str_Value.replace(/[\r\t>]/g, ""); // replaces all Carriage return and Line feed with blank
		str_Value = str_Value.replace(/[;>]/g, ""); // removes all Semi-colon characters
        
        str_Value=str_Value.replace(/\n/g,' ');
        str_Value=str_Value.replace(/\s/g,' ').replace(/  ,/g,' ');  
		
		
	}
	
	return str_Value;
}

function swapImage(imgN,imgU){
if(document.images)document.images[imgN].src=imgU;
}
