function bourseCodeLookUp(ASXCode, type, strUrl, strLoginUrl)
{
	document.location.href = 'MembersArea-InvCentreGoTo.aspx?goto=' + strUrl;
}

function bourseGoToUrl(strUrl, strLoginUrl)
{
	document.getElementById('frmContent').src = strUrl;
}

function openCalc(url)
{
	var win = window.open(url, "calcPopUp", "width=500,height=250,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no");
}


// Image rollover scripts
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ----------------------------------------------------------------------
//Check whether the current form is dirty
function isDirty()
{
	var eForm = document.forms[0];
	
	var iNumElems = eForm.elements.length;
	for (var i=0; i<iNumElems; i++)
	{
		var eElem = eForm.elements[i];
		//alert(eElem.type);
		if ("text" == eElem.type || "TEXTAREA" == eElem.tagName || "hidden" == eElem.type || "file" == eElem.type)
		{
			//Below we have removed carrage returns chr(13) from the text box values
			//This is because a hidden field populate from the server side will use carrage return/line feed
			//but the defualt value ignores carrage return and only has line feed.
			//so to get around this problem for each type of text box we remove carrage returns
			//from both the default value and the current value
			if (eElem.value.replace(/\n/g, '') != eElem.defaultValue.replace(/\n/g, '')) 
			{
				//alert(eElem.name);
				return true;
			}
		}
		else if ("checkbox" == eElem.type || "radio" == eElem.type)
		{
			if (eElem.checked != eElem.defaultChecked)
			{
				//alert(eElem.name);
				return true;
			}
		}
		else if ("SELECT" == eElem.tagName)
		{
			var cOpts = eElem.options;
			var iNumOpts = cOpts.length;
			for (var j=0; j<iNumOpts; j++)
			{
				var eOpt = cOpts[j];
				if (eOpt.selected != eOpt.defaultSelected)
				{
					//alert(eElem.name);
					return true;
				}
			}
		}
	} return false;
}
// ----------------------------------------------------------------------
//Determine whether or not to check for changes to the form
function validateChanges()
{
	var blnCheckForChanges = true; //Default all pages to be validated for changes
	var theForm = document.forms[0];
	
	//Determine whether the current form requeries validation 
	//on changes before leaving the current page
	if (theForm.txtValidateFormChanges != null)
	{
		if (theForm.txtValidateFormChanges.value == '1')
		{
			//Proceed with validating changes to the form
			blnCheckForChanges = true;
		}
		else if (theForm.txtValidateFormChanges.value == '0')
		{
			//Do not proceed with validating changes to the form
			blnCheckForChanges = false;
		}	
	}
	
	return blnCheckForChanges;
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
//Check whether the page is dirty and display an alert. 
//if they choose ok, they will be redirected to the passed URL.
function checkLinkPageIsDirty(strUrl)
{
	var blnCheckForChanges = true; //Default all pages to be validated for changes
	var theForm = document.forms[0];
	var blnContinue = true;
	
	blnCheckForChanges = validateChanges();
	//alert(blnCheckForChanges);
	if (blnCheckForChanges)
	{	//alert(isDirty());
		if (isDirty())
		{
			//The page is dirty
			if (!confirm('Changes have been made to the page. Do you wish to continue and lose any changes made?'))
			{
				var blnContinue = false;
			}
		}
	}
	
	if (blnContinue == true && strUrl != '' && strUrl != null)
	{
		document.location.href = strUrl;
	}
	
	return blnContinue;
}
// ----------------------------------------------------------------------
//Copies the passed text to the clip board
function setClipBoard(strField)
{
		bResult = window.clipboardData.setData("Text",strField);
}
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
//----------------------------------------------------------------------------------
function Today(field)
{
	var now = new Date();
	var monthday = now.getDate();
	var monthnumber = now.getMonth() + 1;
	var year = now.getYear();
	var todaysDate = monthday + '/' + monthnumber + '/' + year
	document.forms[0][field].value=todaysDate;
}

function checkDate(strDate)
{
	if (strDate == '')
		return false;
	
	var arrDate = strDate.split('/');

	//Check whether there is 3 parts to the date
	if (arrDate.length != 3)
		return false;
	
		//Get the 3 parts of the date
		var strYear = arrDate[2];
		var strMonth = arrDate[1];
		var strDay = arrDate[0];
		
		//check each part has a value
		if (strYear == '')
			return false;
			
		if (strMonth == '')
			return false;
		
		if (strDay == '')
			return false;
			
		//check data type of each part
		if (!NumbersOnly(strYear))
			return false;
		
		if (!NumbersOnly(strMonth))
			return false;
		
		if (!NumbersOnly(strDay))
			return false;
		
		var intYear;
		var intDay;
		var intMonth;
		
		intDay = parseFloat(strDay);
		if (intDay < 1 || intDay > 31)
		{
			return false;
		}
		
		intMonth = parseFloat(strMonth);
		if (intMonth < 1 ||intMonth > 12)
		{
			return false;
		}
		
		if (strYear.length == 0 || strYear.length == 3 || strYear.length > 4)
			return false;
			
		if (parseFloat(strYear) >= 1900 && parseFloat(strYear) <= 2100)
		{
			//4 digit year entered
			intYear = parseFloat(strYear);
		}
		else
		{
			//Convert year into 4 digit year
			if (parseFloat(strYear) > 50)
			{
				intYear = 1900 + parseFloat(strYear);
			}
			else
			{
				intYear = 2000 + parseFloat(strYear);
			}
		}
		
		//Check whether the date is a valid date
		if (!validateDate(strDay, strMonth, intYear))
			return false;
			
	return true;
}
// ----------------------------------------------------------------------
//	Confirms Date is actually a true date
function validateDate(DateD,DateM,DateY) { 
	var ARNormalYear = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
	var ARLeapYear = new Array(31,29,31,30,31,30,31,31,30,31,30,31)
	if(DateY%4 == 0) { 
		if(DateD > ARLeapYear[DateM-1]) { return false;	} 
	} else {
		if(DateD > ARNormalYear[DateM-1]) { return false; } 
	}
	return true;
}

// ----------------------------------------------------------------------

// generic positive number decimal formatting function
function dollarize(expr, decplaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) {
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

// ----------------------------------------------------------------------	

// only allows numeric characters 
function NumbersOnly(inputVal) {
if(inputVal == '') { return false; }
	oneDecimal = false
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if ((oneChar < '0' || oneChar > '9')){ // && (oneChar != ' ' && oneChar != "." && oneChar != "-" && oneChar != "(" && oneChar != ")" && oneChar != "+")) {
			return false
		}
	}
	return true
}

// ----------------------------------------------------------------------
// only allows numeric characters and spaces
function checkPhoneNumber(inputVal) {
if(inputVal == '') { return false; }
	oneDecimal = false
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if ((oneChar < '0' || oneChar > '9') && oneChar != ' '){ // && (oneChar != ' ' && oneChar != "." && oneChar != "-" && oneChar != "(" && oneChar != ")" && oneChar != "+")) {
			return false
		}
	}
	return true
}

// ----------------------------------------------------------------------

function isNumber(inputVal) {
	oneDecimal = false
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-") {
			continue
		}
		if (oneChar == "." && !oneDecimal) {
			oneDecimal = true
			continue
		}
		if (oneChar < "0" || oneChar > "9") {
			return false
		}
	}
	return true
}
// ----------------------------------------------------------------------

function validateEmail(email) {
	invalidChars = " /:,;"

	for (i=0; i<invalidChars.length; i++) {// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)  // there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {  // and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {  // and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length) {  // must be at least 2 characters after the "."
		return false
	}
	return true;
}
// ----------------------------------------------------------------------
//Validate a comma separated list of email address from a customer validator control
function cvalEmailAddresses(source, arguments)
{
	//Validate the comma separated list of email addresses
	//This function can ONLY be used with a CustomerValidator control
	if (arguments.Value != '')
	{
		var arrEmail = arguments.Value.split(',');
		var i;
		var blnValid = true;
		
		for (i = 0; i < arrEmail.length; i++)
		{
			//Validate the individual email addresses
			if (!validateEmail(arrEmail[i]))
			{
				blnValid = false;
				break;
			}
		}
			
		arguments.IsValid=blnValid;
	}
	else
		arguments.IsValid=true;
}
	
// ----------------------------------------------------------------------
//Validate a single email address from a Customer Validator control
function cvalEmailAddress(source, arguments)
{
	if (arguments.Value != '')
	{
		if (!validateEmail(arguments.Value))
		{
			arguments.IsValid=false;
		}
		else
			arguments.IsValid=true;
	}
	else
		arguments.IsValid=true;
}
// ----------------------------------------------------------------------
function doHTTPGet(strUrl)
{
	//alert(strUrl);
	var strUrl = strUrl;
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.Open("Get",strUrl,false);
   	xmlhttp.send();
	
   	var s =  xmlhttp.responseText;
   	xmlhttp = null;
   	
   	return s;
}
// ----------------------------------------------------------------------
//Remove all items from the passed drop down
function removeAllDropDownItems(cbo)
{
	var i;
	
	for (i = cbo.options.length; i > -1; i--)
	{	//alert('t');
		cbo.options.remove(i);
	}
}
// ----------------------------------------------------------------------
//Add an item to the passed drop down
function addDropDownItem(cbo, strText, strValue)
{
	cbo.options[cbo.length] = new Option(strText, strValue);
}


// Various date functions
	function Mod(a, b) 
	{ 
	return a-Math.floor(a/b)*b
	}

	function printWeek(form, dtStart, dtEnd) 
	{
	var now = new Date();
	var nowDayOfWeek = now.getDay();
	var iDay = now.getDate();
	var iMonth = now.getMonth();
	var iYr = now.getYear();
	iYr += (iYr < 2000) ? 1900 : 0;

	iStartDay = iDay - nowDayOfWeek + 1


	iEndDay = iDay + (7 - nowDayOfWeek)
	if (iMonth == 1 && iEndDay > 28) 
	{
		if ( Mod(iYr,4) == 0) 
		{
			iEndDay = 29
		}
		else
		{
			iEndDay = 28
		}
	}


	var startdt = new Date(iYr, iMonth, iStartDay);
	var enddt = new Date(iYr, iMonth, iEndDay);

	form[dtStart].value =    fix_date(startdt)
	form[dtEnd].value =    fix_date(enddt)
	//document.write("Current Week:  " + fix_date(weekStartDate) + " - " + fix_date(weekEndDate));
	}
	function fix_date(dtDate)
	{

	var now = new Date()
	var nowDayOfWeek = dtDate.getDay();
	var nowDay = dtDate.getDate();
	var Month = dtDate.getMonth();
	var nowYear = dtDate.getYear();
	var sMonth
	if (Month == 0) { sMonth = "Jan"} else  
	if (Month == 1) { sMonth = "Feb"} else
	if (Month == 2) { sMonth = "Mar"} else 
	if (Month == 3) { sMonth = "Apr"} else 
	if (Month == 4) { sMonth = "May"} else 
	if (Month == 5) { sMonth = "Jun"} else  
	if (Month == 6) { sMonth = "Jul"} else 
	if (Month == 7) { sMonth = "Aug"} else 
	if (Month == 8) { sMonth = "Sep"} else 
	if (Month == 9) { sMonth = "Oct"} else 
	if (Month == 10) { sMonth = "Nov"} else 
	if (Month == 11) { sMonth = "Dec"}
	//alert(dtDate)
	return nowDay + " " + sMonth +  " " + nowYear
	}

	function jsget_financialYr_dates(form)
	{

	var now = new Date();
	var nowDayOfWeek = now.getDay();
	var nowDay = now.getDate();
	var iMonth = now.getMonth();
	var iYr = now.getYear();

	if ((iMonth >= 7 )&& (iMonth <= 12 ))
	{
		iStartyr = iYr
		iEndyr = iYr + 1 
	}
	else
	{
		iStartyr = iYr - 1
		iEndyr = iYr 
	}
	var startdt = new Date(iStartyr, 6, 1);
	var enddt = new Date(iEndyr, 5, 30);

	form[dtStart].value =    fix_date(startdt)
	form[dtEnd].value =    fix_date(enddt)
	}

	function jsget_calendarYr_dates(form)
	{

	var now = new Date();
	var nowDayOfWeek = now.getDay();
	var nowDay = now.getDate();
	var iMonth = now.getMonth();
	var iYr = now.getYear();

	var startdt = new Date(iYr, 0, 1);
	var enddt = new Date(iYr, 11, 31);

	form[dtStart].value =  fix_date(startdt)
	form[dtEnd].value =   fix_date(enddt)
	}


	function jsget_today_dates(form, dtStart, dtEnd)
	{
	var now = new Date();

	form[dtStart].value =  fix_date(now)
	form[dtEnd].value =   fix_date(now)
	}

	function jsget_month(form, dtStart, dtEnd)
	{

	var now = new Date();
	var iMonth = now.getMonth();
	var iYr = now.getYear();

	iMonthEnd = get_month_dates(iMonth,iYr,form,dtStart,dtEnd)


	}

	function get_month_dates(iMonth,iYr,form,dtStart,dtEnd)
	{

	if ( Mod(iYr,4) == 0) 
	{
		iFeb = 29
	}
	else
	{
		iFeb = 28
	}

	ArrMonth = new Array(30,iFeb,31,30,31,30,31,31,30,31,30,31)
	dtMonth = ArrMonth[iMonth]

	var startdt = new Date(iYr, iMonth, 1);
	var enddt =  new Date(iYr, iMonth, dtMonth);
	form[dtStart].value =  fix_date(startdt)
	form[dtEnd].value =   fix_date(enddt)

	}

	function jsget_all_dates(form)
	{

	form[dtStart].value =   "01 Jan 1900"
	form[dtEnd].value =    "01 Jan 2010"
	}
	//==============================================
function popURL(url,x,y){popupWin = window.open(url,'remote','dependent,scrollbars,width='+x+',height='+y+',left=10,top=10')}