// Has to have some code, otherwise it will throw an error
// General functions for use with HTML form validation and other client-side calculations.
// Some of this code has been adapted (and simplified/made non-browser specific) from
// an article by Carl Nolan in the January 1999 issue of Microsoft Interactive Developer.
// Refer to: http://www.microsoft.com/mind/0199/inthisissue0199.htm

//Default values
var strLanguage = 'en';
var blnAuthoringMode=false;
var isGraphic=false;
var isIE5=false;
var isFirefox = (window.navigator.userAgent.indexOf('Firefox') > 0);
var SIA_FocusControl = null;
var SIA_FocusOnLoad = true;
var SIA_PageInit = false;
var SIA_DisableEnterKey = true;
var SIA_DefaultButton = null;


function SIA_PageLoad()
{
	SIA_Init();
	SIA_PageInit = true;
}

function SIA_Init()
{
	if (!SIA_PageInit)
	{
		if (document.forms.length > 0)
			for (i = 0; i < document.forms[0].elements.length; i++)
			{
				var control = document.forms[0].elements[i];
				
				// Sets the default button to be the first input button on the page
				if ((SIA_DefaultButton == null) && (control.tagName == 'INPUT'))
					if (control.type == 'submit')
						SIA_DefaultButton = control;
				
				// Binds any input or password control to the KeyPress event
				if ((control.tagName == 'INPUT') && ((control.type == 'text') || (control.type == 'password') || control.type == 'checkbox'))
				{
					control.onkeypress = SIA_KeyPress;
				}
			
				if ((SIA_FocusControl == null) &&
					(typeof(control.focus) != 'undefined') &&
					((typeof(control.style) != 'undefined') && (control.style.visibility != 'hidden')) &&
					(!control.disabled) &&
					((control.type == 'text') || (control.type == 'radio') || (control.type == 'checkbox') || (control.tagName == 'SELECT') || (control.tagName == 'TEXTAREA')))
				{
					SIA_FocusControl = control;
				}
			}
			
		// Focus on the FocusControl
		if ((SIA_FocusControl != null) && (SIA_FocusOnLoad) &&
			 ((typeof(MessageBox) == 'undefined') || (typeof(MessageBox.FocusControl) == 'undefined') || (MessageBox.FocusControl == ''))) 
		{
			try
			{
				SIA_FocusControl.focus();
			}
			catch(e)
			{
				// Do nothing... focus will have failed
			}
		}
	}

}


// This function ignores the enter key 
function SIA_KeyPress(e)
{

  if (typeof(e) == 'undefined')
    e = window.event;
    
    
	if (e.keyCode == 13)
	{
		
		if (!SIA_DisableEnterKey)
		{
			SIA_DefaultButton.focus();
			SIA_DefaultButton.click();
		}
		
		// This is the only way to avoid the default event handler for the enter key press
		// to fire and submit the form
		if ((typeof(e.cancelBubble) != 'undefined') && !isFirefox)
		{
			e.cancelBubble = true;
			e.keyCode = 0;
		}

		return false;
	}
}

function __SIAdoPostBack(eventTarget, eventArgument) 
{
		var theform;
		theform = document.forms[0];
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
}


// Function used to find a control, given the control id
function Sia_FindControl(controlID)
{
	var control;
	
	if (typeof(controlID) != 'string')
		return null;

	if (typeof(document.getElementById) != 'undefined')
		control = document.getElementById(controlID);

	if (control == null)
	{
		control = null;
		var name = Sia_ReplaceText(controlID, '_', ':');
		var temp = Sia_FindControl2(name, document);
		if (typeof(temp) != 'undefined')
			control = temp;
		else
			control = Sia_FindFirstControl(controlID);
	}
	
	return control;
}


function Sia_FindControl2(name, doc) { //v4.0
  var pos,i,result;
  if(!doc) doc=document;
  if((pos=name.indexOf("?")) > 0 && parent.frames.length)
  {
    doc = parent.frames[name.substring(pos+1)].document;
    name = name.substring(0,pos);
  }
  
  if(!(result=doc[name]) && doc.all)
		result = doc.all[name];
		
	for (i=0; !result && i < doc.forms.length; i++)
	  result = doc.forms[i][name];
	  
  for (i=0; !result && doc.layers && i < doc.layers.length; i++)
    result = Sia_FindControl2(name, doc.layers[i].document);
  
  if (!result && document.getElementById)
    result = document.getElementById(name);
    
  return result;
}


function Sia_FindFirstControl(controlID) { //NS4
	var i, result, form, temp, name;
	result = null;
	name = Sia_ReplaceText(controlID, '_', ':');
	for (i=0; !result && i < document.forms.length; i++)
	{
		form = document.forms[i];
		for (j=0; !result && j < form.elements.length; j++)
		{
			temp = form.elements[j];
			if (typeof(temp.name) != 'undefined')
				if (temp.name.search(name) > -1)
					result = temp;
		}
	}
    
  return result;
}

function Sia_ReplaceText(text, oldValue, newValue)
{
	var a = text;
	var b = a.replace(oldValue, newValue);
	while (b != a)
	{
		a = b;
    b = a.replace(oldValue, newValue);
	}
	return b;
}



function msieversion() {
	// This function returns Internet Explorer's major version number,
	// or 0 for other browsers. It works by finding the "MSIE " string and
	// extracting the version number following the space, up to the decimal
	// point, ignoring the minor version number.
	
	var ua = window.navigator.userAgent;
	var msie = ua.indexOf ( "MSIE " );
	if ( msie > 0 )      // If IE, return version number
		return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
	else                 // If another browser, return 0
		return 0;
}


function display_name(item) {
	var strDisplay = "";
	var version = msieversion();
	// If using IE 4.0 or later, use the value of the TITLE tag as the error display name.
	if (version >= 4)
		strDisplay = item.getAttribute("TITLE", 0); 	
	else {
		// use name, chop off 3-char variable type, split into separate words
		// e.g. "lstPostalMailingMethod" -> "Postal Mailing Method"
		var strName = item.name;  		
		if (strName.length > 3) {
			strName = strName.substring(3, strName.length);  // chop off "lst", "opt", etc.
			for (var i=0; i < strName.length; i++) { 
				var strChar = strName.charAt(i);
				if (strChar == strChar.toUpperCase())  //capital letter, so new word
					strDisplay = strDisplay + " ";
				strDisplay = strDisplay + strChar;
			}
		}
	}		
	if (strDisplay==null || strDisplay=="")	
		strDisplay="The indicated field";
	return strDisplay;
}


function default_value(item) {
	var strDefault = item.defaultValue;
	if (strDefault==null || strDefault=="")
		strDefault="";
	return strDefault;
}


function trim_string() {
	var ichar, icount;
	var strValue = this;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	
	// Replace any Tab Characters with a space.	
	var strRemoveCharacter = "\u0009"; // Tab Character.
	while (strValue.indexOf(strRemoveCharacter,0) > -1)
		strValue = strValue.replace(strRemoveCharacter," ");	
	return strValue;
}


function date_toSimpleForm() {
	var toSimpleForm = new String;
	toSimpleForm = this.toLocaleString();
	toSimpleForm = toSimpleForm.substring(0,toSimpleForm.indexOf(' '));  // Remove time stamp.
	return toSimpleForm;
}


function IsBlank(item) {
	var strErrorMsg = display_name(item) + " cannot be blank.";
	item.value=item.value.Trim();
	if (item.value.length==0) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function IsNoTextEnteredForRadio(txtItem, optRadioCollection, strRadioToCheck) {
	// Purpose:		Returns true if no text is entered when a given radio is selected. 
	// Author:		Todd McFarlane-Smith
	// Parameters: 
	// - txtItem:				the textbox (input object) containing text.
	// - optRadioCollection:	the collection of radio buttons with same id.
	// - strRadioToCheck:		the value of the radio button that is to be checked.
 	for (var i=0; i<optRadioCollection.length; i++) {		
		if (optRadioCollection[i].value == strRadioToCheck) {
			if (optRadioCollection[i].checked) {
				if (IsBlank(txtItem))
					return true;
			}
		}
	}
	return false;
}


function IsNotInteger(item) {
	var strErrorMsg = display_name(item);
	var strValue = item.value.Trim();
	
	if (/[,]+/.test(strValue)) {
		item.focus();
		alert(strErrorMsg + " must not contain any commas.");
		return true;
	}
	
	var intValue = parseInt(strValue,10);  //Convert to integer base 10.
	if (isNaN(intValue)) {
		item.focus();
		alert(strErrorMsg + " must be a valid integer.");
		return true;
		}
	else {
		item.value = intValue;		
	}
	return false;
}

/* WARNING! - IsNotNumber() will only return true (Is Not a Number) if the ENTIRE
   value is NOT numeric.  If any portion contains a number, it will extract this
   numeric portion and check that portion only. So, if the value contains a character 
   (eg 123Q4), this will be a valid number (123). */
   
function IsNotNumber(item) {
	var strErrorMsg = display_name(item) + " must be a valid number.";
	var intValue = parseInt(item.value);			// Convert to integer.
	var realValue = parseFloat(item.value);		// Convert to floating point.
	if (isNaN(intValue) || isNaN(realValue)) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function IsNotInRange(item, intLow, intHigh) {
	var strErrorMsg = display_name(item);
	if (IsNotNumber(item))
		return true;
	var itemValue = new Number(item.value);
	if ((itemValue < intLow || itemValue > intHigh)) {
		item.focus();
		alert(strErrorMsg + " can only have values between " + intLow + " and " + intHigh+ ".");
		return true;
	}
	return false;
}


function IsNotLength(item, intLength) {
	var strErrorMsg = display_name(item);
	item.value=item.value.Trim();
	if (item.value.length != intLength) {
		item.focus();
		alert(strErrorMsg + " must have exactly " + intLength + " characters.");
		return true;
	}
	return false;
}


function IsShort(item, intLength) {
	var strErrorMsg = display_name(item);
	item.value=item.value.Trim();
	if (item.value.length < intLength) {
		item.focus();
		alert(strErrorMsg + " must be at least " + intLength + " characters long.");
		return true;
	}
	return false;
}


function IsLong(item, intLength) {
	var strErrorMsg = display_name(item);
	item.value=item.value.Trim();
	if (item.value.length > intLength) {
		item.focus();
		alert(strErrorMsg + " must not be greater than " + intLength + " characters long.");
		return true;
	}
	return false;
}


function IsNotStrongPassword(item) {
	// Function to check is a password is 'strong' ie contains:
	//		(a)	Upper and lower case characters;
	//		(b)	At least one numeric character; and
	//		(c)	At least one special character (eg !, @, # etc). 
	var strErrorMsg = display_name(item);
	item.value=item.value.Trim();
	var strPassword = item.value;

	if (!(/[A-Z]+/.test(strPassword))) {
		item.focus();
		alert(strErrorMsg + " must contain a mixture of UPPER and lower case characters.");
		return true;
	}

	if (!(/[a-z]+/.test(strPassword))) {
		item.focus();
		alert(strErrorMsg + " must contain a mixture of UPPER and lower case characters.");
		return true;
	} 
	
	if (!(/\d+/.test(strPassword))) {
		item.focus();
		alert(strErrorMsg + " must contain at least one numeric character (eg 0,1,2,3,4,5,6,7,8 or 9).");
		return true;
	}
	
	if (!(/[\~,!,@,#,$,%,\^,&,*,(,),-,+,=,\[,\]]+/.test(strPassword))) {
		item.focus();
		alert(strErrorMsg + " must contain least one special character e.g. ~,!,@,#,$,%,^,&,*,(,),-,+,],[ or =.");
		return true;
	}
	return false;
}


function IsNotValidDate(item) {
	//  Checks for a valid date as:
	//  DD/MM/YYYY or DD-MM-YYYY

	var strErrorMsg = display_name(item);
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = item.value.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert(strErrorMsg + " must be a valid date (eg 29/10/2000).");
		item.focus();
		return true;
	}
	day = matchArray[1];				// parse date into variables
	month = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert(strErrorMsg + " is an invalid date.  The month must be between 1 and 12.");
		item.focus();
		return true;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert(strErrorMsg + " is an invalid date.  For month " + month + " the day must be between 1 and 30 - not 31.");
		item.focus();
		return true;
	}
	if (month == 2) { // check for February 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert(strErrorMsg + " is an invalid date.  February in the year " + year + " doesn't have " + day + " days.");
			item.focus();
			return true;
		}
	}
	if (day < 1 || day > 31) {
		alert(strErrorMsg + " is an invalid date. The day must be between 1 and 31.");
		item.focus();
		return true;
	}
	if (year < 1900) {
		alert(strErrorMsg + " is an invalid date. The year must be greater than or equal to 1900.");
		item.focus();
		return true;
	}
	return false;  // date is valid
}


function ConvertDate(strDate) {
	// Function to convert a date from dd/mm/yyyy to American mm/dd/yyy format.
	var strAmericanDate = "";
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = strDate.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Error: Could not convert date " + strDate + " to American date format (eg MM/DD/YYYY).");
		return strDate;
	} 
	day = matchArray[1];		// parse date into variables.
	month = matchArray[3];
	year = matchArray[4];
	
	strAmericanDate = month + "/" + day + "/" + year;
	return strAmericanDate;
}


function DateDiff(strStartDate, strEndDate, strInterval) {
	// Calculates the difference between two dates in
	// Days, Weeks or Years (depending on the value of
	// the strInterval parameter).
	
	var oneMinute = 60 * 1000;
	var oneHour = oneMinute * 60;
	var oneDay = oneHour * 24;
	var oneWeek = oneDay * 7;
	var oneYear = oneWeek * 52.25;
	
	// Convert dates to American MM/DD/YYYY format.
	
	var strUSStartDate = ConvertDate(strStartDate);
	var strUSEndDate = ConvertDate(strEndDate);
	
	// Convert string dates to milliseconds...

	var dteStartDate = Date.parse(strUSStartDate);
	var dteEndDate = Date.parse(strUSEndDate);
	
	Difference = dteEndDate - dteStartDate;
	
	switch (strInterval) {
		case "D":	// Want difference in Days.
			Difference = Difference / oneDay;
			break;
		case "W":	// Want difference in Weeks.
			Difference = Difference / oneWeek;
			break;	
		case "Y":	// Want difference in Years.
			Difference = Difference / oneYear;
	}
	Difference = Math.round(Difference);
	return Difference;
}


function DateLater(Date1, Date2) {
	var strErrorMsg = display_name(Date1) + " must be earlier than " +
	display_name(Date2) + ".";
	if (DateDiff(Date1.value, Date2.value, "D") < 0) {
		Date1.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function ItemNotSelected(item) {
	var strErrorMsg = display_name(item) + " must be a valid selection.";
	if (item.selectedIndex==0) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function RadioNotSelected(item) {
	// returns false if a radio item has not been selected.
	var strErrorMsg = "Please select one of the " + display_name(item[0]) + " options.";
	for (var i=0; i < item.length; i++) {
		if (item[i].checked) {
			return false;
		}
	}
	item[0].focus();
	alert(strErrorMsg);
	return true;
}

function CheckBoxNotSelected(item) {
	// returns false if at least one CheckBox item has not been selected.
	var strErrorMsg = "Please select at least one of the " + display_name(item[0]) + " options.";
	for (var i=0; i < item.length; i++) {
		if (item[i].checked) {
			return false;
		}
	}
	item[0].focus();
	alert(strErrorMsg);
	return true;
}

function IsNotValidPostcode(item) {
	item.value=item.value.Trim();
	if (IsNotLength(item, 4))
		return true;
	var strValue = item.value;
	var intValue;
	for (var i=0; i<strValue.length; i++) {
		intValue = parseInt(strValue.charAt(i));  //Convert to integer base 10.
		if (isNaN(intValue)) {
			item.focus();
			alert(display_name(item) + " must be between 0001 and 9999.");
			return true;
		}
	}
	return false;
}


function IsNotValidPhone(item) {
	var strErrorMsg = display_name(item) + " must be of the form 9999-9999.";
	item.value=item.value.Trim();
	if (!(/^\d{4}-\d{4}$/.test(item.value))) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function IsNotValidACN(item) {
	var strErrorMsg = display_name(item) + " must be of the form 999999999.";
	item.value=item.value.Trim();
	if (item.value.length==0) return false; // Don't check if no ACN specified.
	if (!(/^\d{9}$/.test(item.value))) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function IsNotValidABN(item) {
	var strErrorMsg = display_name(item) + " is invalid.";
	var ABN = item.value.Trim();
	if (ABN.length==0) return false;		// Don't check if no ABN specified.
	if (!(/^\d{11}$/.test(ABN))) {
		alert (strErrorMsg + "  An ABN must be an 11 digit integer.");
		item.focus();
		return true;
	} else {
		var checksum = 0;
		var weightArray = new Array(10,1,3,5,7,9,11,13,15,17,19);
		
		var FirstABNDigit = ABN.charAt(0);
		FirstABNDigit = FirstABNDigit - 1;
		ABN = FirstABNDigit + ABN.substr(1,10);
		for (var i=0;i < 11;i++) {
			checksum += ABN.charAt(i)* weightArray[i];
		}
		checksum = checksum % 89;
		if (checksum != 0) {
			alert(strErrorMsg + "  Please check that you have typed all of the ABN digits correctly.");
			item.focus();
			return true;
		}
	}
	return false;
}


function IsNotValidEmail(item) {
	var strErrorMsg = display_name(item) + " is not a valid email address.";
	item.value=item.value.Trim();
	if (item.value.length==0) return false;
	if (!(/^[\w-~!#$%\^\'&*()-_\+\.]+@+[\w-~!#$%\^\'&*()-_\+\.]+$/.test(item.value))) {
		item.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function IsNotValidEmailList(item) {
	var strErrorMsg = display_name(item) + " does not contain a valid list of email addresses.";
	var Email = new Array();
	var i, pos, a;
	item.value=item.value.Trim();
	if (item.value.length==0)  return false;
	for (i = 0; i < 100; i++) Email[i] = '';
	i = 0;
	pos = 0;
	while (pos < item.value.length) {
		a = item.value.substring(pos, ++pos);
		if (a != ',')
			 Email[i] = Email[i] + a
		else
			 i++;
	}
	for (pos=0; pos <= i; pos++) {
		Email[pos] = Email[pos].Trim();
		if (!(/^[\w-~!#$%\^\'&*()-_\+\.]+@+[\w-~!#$%\^\'&*()-_\+\.]+$/.test(Email[pos]))) {
			item.focus();
			alert(strErrorMsg);
			return true;
		}
	}
	return false;
}

function IsNotWithoutBlanks(item) {
	var strErrorMsg = display_name(item) + " cannot contain any blank characters.";
	item.value=item.value.Trim();	
	if (item.value.length==0) return false;	
    if(/[\ ]/.test(item.value)) {
        item.focus();
        alert(strErrorMsg);
        return true;
    }
    return false;
}

function IsNotEqual(item1,item2) {
	var strErrorMsg = display_name(item1) + " is not equal to " + display_name(item2);
	item1.value=item1.value.Trim();
	item2.value=item2.value.Trim();
	if (item1.value != item2.value) {
		item1.focus();
		alert(strErrorMsg);
		return true;
	}
	return false;
}


function TitleCase(item) {
	// Function to convert a string to Title Case (first
	// character upper-case - all the rest lower case
	var strOutput = "";
	var strInput = item.value.Trim().toLowerCase();
		
	if (strInput.length >= 1) {
		var strChar;
		var strPChar;
		var strOutput = strInput.charAt(0).toUpperCase();
		for (var i=1;i <= (strInput.length);i++) {
			strChar = strInput.charAt(i);
			strPChar = strInput.charAt(i-1);
			if (strPChar == "'" || strPChar == " " || strPChar == "-")
				strChar = strChar.toUpperCase();
			strOutput = strOutput + strChar;
		} 
		item.value = strOutput;
	}
}


function UpperCase(item) {
	// Function to convert a string to Upper Case characters
	var strInput = item.value.Trim();
	if (strInput.length >= 1)
		item.value = strInput.toUpperCase();
}


// Extend the string object to include a trim function
String.prototype.Trim = trim_string;
// Extend the date object to include a simple form string conversion
Date.prototype.toSimpleForm = date_toSimpleForm;

// This set of function are for processing the key press event
// Used to restrict input on numerics and pure textual fields

function kpIsInteger() {
	if ((event.keyCode < 48 || event.keyCode > 57))
		event.returnValue = false;
}


function kpIsNumeric() {
	if ((event.keyCode != 46) && (event.keyCode < 48 || event.keyCode > 57))
		event.returnValue = false;
	if (event.keyCode == 46) {
		if (event.srcElement.value.indexOf(".") > -1)
			event.returnValue = false;
	}
}


function kpIsCharacter() {
	if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122))
		event.returnValue = false;
}


function kpConvertToUppercase() {
	if ((event.keyCode >= 97 && event.keyCode <= 122))
		event.keyCode -= 32;
}


function kpConvertToLowercase() {
	if ((event.keyCode >= 65 && event.keyCode <= 90))
		event.keyCode += 32;
}


function kpSetup() {
	this.Integer = kpIsInteger;
	this.Numeric = kpIsNumeric;
	this.Character = kpIsCharacter;
	this.ConvertToUpperCase = kpConvertToUppercase;
	this.ConvertLowerCase = kpConvertToLowercase;
	return this;
}

var keyPressInput = new Object;
keyPressInput = kpSetup();


function SetRadioItem(optCollection, strOptionToSet, blnChecked) {
	// Purpose:		Sets a specified radio button (in a group) ON (.checked=true) or OFF.
	// Parameters: 
	// - optCollection: the collection of radio buttons with same id.
	// - strOptionToSet: the value of the radio button that is to be set. 
	// - blnChecked: true if want to turn radio button ON (.checked=true), false if want OFF.
	for (var i=0; i<optCollection.length; i++) {		
		if (optCollection[i].value == strOptionToSet) {
			optCollection[i].checked = blnChecked;
			break;
		}
	}
	return true;
}


function GetCheckedRadioValue(optCollection) {
	// Purpose:	Retrieves value of currently checked radio button (in a group) 
	// Parameters: 
	// - optCollection: the collection of radio buttons with same id.
	// Returns:	Value of the radio button that is CHECKED (on).
	var strValue = "";
	for (var i=0; i<optCollection.length; i++) {
		if (optCollection[i].checked) {
			strValue = optCollection[i].value;
			break;
		}
	}
	return strValue;
}	


function GetSelectedListboxValue(lstBox) {
	// Retrieves value of currently selected option of listbox
	return lstBox.options[lstBox.selectedIndex].value;
}

function GetSelectedListboxText(lstBox) {
	// Retrieves text of currently selected option of listbox
	return lstBox.options[lstBox.selectedIndex].text;
}


function ShowHelp(strLocation) {
	// Function to display the HTML or ASP page nominated by the strLocation parameter
	// in a separate child window...
	var height;
	var width;
	height = (screen.height);
	width = (screen.width-7);
	
	if (strLocation != "") {
		//open(strLocation,"","fullscreen=no,channelmode=no,toolbar=yes,location=yes,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=yes,height=" + height +",width=" + width +",top=0,left=0");
		window.open(strLocation);
	}
}

function IsNotValidText(objText)
{
	var ch;
	var strText;
	var bBefore;
	var checkit1 = new RegExp("[a-z]");
	var checkit2 = new RegExp("[A-Z]");
	var checkit3 = new RegExp("[ ]");

	strText = objText.value
	
	for (i = 0;  i < strText.length;  i++)
	{
		ch = strText.charAt(i);
		
		if ((checkit1.test(ch) == false) && (checkit2.test(ch) == false) && (checkit3.test(ch) == false))
				 
		{
			if ((ch != "-") && (ch != "'") || (strText.length <= 1) || bBefore) 
			{ 
				alert(objText.title + " must have valid characters");
				return(true);
			}
			bBefore = true
		}
	}
	return(false);
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function ReloadMain()
{
	if (opener)
		if (!opener.closed)
			opener.Reload();
}

function Reload()
{
  if (typeof(__doPostBack) == 'function')
		__doPostBack('', '');
}

function OpenDialog(Child, Target, Name, intW, intH, blnCentered, blnScroll, blnReload) {
	var W;
	var x,y;
	var strScroll;
	if (blnScroll)
		{ strScroll = 'yes'; }
	else
		{ strScroll = 'no'; }
	if (blnCentered)
	{
		y = parseInt((screen.height - intH) / 2);
		x = parseInt((screen.width - intW) / 2);
	}
	else
	{
		y = 0;
		x = 0;
	}
	if ((Child) && (!Child.closed))
	{
		Child.focus();
	} else {
		window.name = 'SIAMAIN';		
		W = window.open(Target, Name, 'toolbars=no,scrollbars='+strScroll+',location=no,statusbars=no,menubars=no,resizable=no,width='+intW+',height='+intH+',top='+y+',left='+x);
		if (W == null)
		{
		  alert('The window could not opened because you have a pop-up blocker installed on your browser.\n\nPlease refer to your pop-up blocker documentation to see how you may deactivate it when you wish to allow a website to open a new window.');
		  return;
		}
		W.focus();
		Child = W;
		if (blnReload)
			Reload();
		return W;
	}
}

function callInteractiveMap()
{
	CallInteractiveMap();
}

function CallInteractiveMap()
{
	try 
	{
		if (typeof(window.MapWindow) != 'undefined')
		{
			window.MapWindow.focus();
			return;
		}
	}
	catch(e)
	{
	}

	var Target;
	Target = '/Sia/' + strLanguage + '/Tools/InteractiveMap.asp';
	if (blnAuthoringMode)
	{
		window.MapWindow = OpenDialog(window.MapWindow, Target, 'SIAMAP', 900, 480, true, true, false);
	}
	else
	{
		if (isGraphic)
			window.MapWindow = OpenDialog(window.MapWindow, Target, 'SIAMAP', 800, 650, true, false, false);
		else
			window.MapWindow = OpenDialog(window.MapWindow, Target, 'SIAMAP', 800, 650, true, true, false);
	}
}

function SetMapChild()
{
			Wait(2000);
			try
			{
				if (window.opener != null)
				{
					window.opener.MapWindow = window;
				}
			}
			catch(e)
			{
			}
}

function callStudyWizard()
{
	callstudywizard();
}

function callstudywizard() {
	var Target;
	Target = '/Sia/StudyWizard/Login.aspx?Language='+ strLanguage;
	if (blnAuthoringMode)
	{
		OpenDialog(window.WizardWindow, Target, 'SIAWIZ', (window.screen.width - 7), (window.screen.height - 60), false, true, false);
	}
	else
	{
		OpenDialog(window.WizardWindow, Target, 'SIAWIZ', (window.screen.width - 7), (window.screen.height - 60), false, true, false);
	}
}

function callPrintWindow(urlPrintTarget) {
    OpenDialog(window.WizardWindow, urlPrintTarget, 'SIAWIZ', (800), (window.screen.height - 60), false, true, false);
}


function CallSuccessStory(Id) {
	var Target;
	Target = '/Sia/' + strLanguage + '/SuccessStory/SuccessStory.htm?Id=' + Id;
	Target = '/Sia/' + strLanguage + '/Tools/SuccessStoryDialog.htm?Id=' + Id;
	if (blnAuthoringMode)
	{
		OpenDialog(window.StoryWindow, Target, 'SIASTORY', 900, 420, true, true, false);
	}
	else
	{
		OpenDialog(window.StoryWindow, Target, 'SIASTORY', 530, 420, true, true, false);
	}
}

function CallGoAustralia() {
	var Target;
	Target = '/Sia/' + strLanguage + '/Tools/GoAustralia.html';
	if (blnAuthoringMode)
	{
		OpenDialog(window.StoryWindow, Target, 'SIAGO', 900, 420, true, true, false);
	}
	else
	{
		OpenDialog(window.StoryWindow, Target, 'SIAGO', 500, 280, true, false, false);
	}
}

function callGoAustralia2() {
	var Target;
	Target = '/Sia/' + strLanguage + '/Tools/GoAustralia.html';
	if (blnAuthoringMode)
	{
		OpenDialog(window.StoryWindow, Target, 'SIAGO', 900, 420, true, true, false);
	}
	else
	{
		OpenDialog(window.StoryWindow, Target, 'SIAGO', 500, 280, true, false, false);
	}
}

function callInstDetails(OID) {
	if (window.opener)
		if (!window.opener.closed)
		{
			window.opener.location = '/Sia/' + strLanguage + '/CourseSearch/OrganisationDetails.aspx?Origin=Map&OrgId=' + OID;
 			window.opener.focus();
 			
 			SetMapChild();
		}
}

function AddToFav() {
	url = "http://studyinaustralia.gov.au/";
	title = "Study in Australia!";
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite (url,title);
	}
	else
	{
		var msg = "Sorry! This feature is only available on IE4 and above. You will have to bookmark the page manually.";
		alert(msg);
	}
}

function CheckWizardWindow() {
  if (window.name != "SIAWIZ") {
    alert("The wizard can only be accessed by clicking on the wizard link in the study in Australia website!"); 
    document.location="/Sia/Default.html";
  }
}

function OpenInMain(page)
{
    if (window.opener)
    {
    	if (!window.opener.closed)
		{
			window.opener.location = page;
 			window.opener.focus();
		}

    } else
    {
	    var MainWindow;
	    MainWindow = window.open(page, 'SIAMAIN', '');
	    if (MainWindow) MainWindow.focus();
	}
}

function Redirect(page)
{
  window.location=page;
}


function openPageTurner() 
{
    var url = '/Sia/flash/PageTurner/SIAGuide_PTurner_003.html';
	var HelpWindow;
	var thisWidth = (window.screen.width - 7);
	var thisHeight = (window.screen.height - 60);
	window.name = 'SIAMAIN';		
	HelpWindow = window.open(url, 'SIAHELP', 'toolbars=no,scrollbars=yes,location=no,statusbars=yes,menubars=no,resizable=yes,width='+thisWidth+',height='+thisHeight+',top=0,left=0');
	if (HelpWindow) HelpWindow.focus();
}

function OpenHelp(url) 
{
	var HelpWindow;
	var thisWidth = (window.screen.width - 7);
	var thisHeight = (window.screen.height - 60);
	window.name = 'SIAMAIN';		
	HelpWindow = window.open(url, 'SIAHELP', 'toolbars=no,scrollbars=yes,location=no,statusbars=yes,menubars=no,resizable=yes,width='+thisWidth+',height='+thisHeight+',top=0,left=0');
	if (HelpWindow) HelpWindow.focus();
}

function CheckSearchForm(theForm) {
	if (theForm.qu.value == "") {
		alert("Please type the keywords (or a phrase) that you want to search for.");
		theForm.qu.focus();
		return (false);
	}
	return (true);
}

function Wait(milliseconds)
{
	var now = new Date();
	var target = new Date(now.valueOf() + milliseconds);
	while (now < target)
	{
		now = new Date();
	}
}


function TCProcess(IDstr)
{
	var txtObj = document.getElementById('T_' + IDstr)
	var imgObj = document.getElementById('I_' + IDstr)

	if (txtObj.style.display == 'none')
	{
	  txtObj.style.display = '';
	  imgObj.src = '/Sia/Images/Wizard/minus.gif';
	}
	else
	{
	  txtObj.style.display = 'none';
	  imgObj.src = '/Sia/Images/Wizard/plus.gif';
	}
}

function printPage()
{
	window.print();
}

function SIA_SetCookie(doc, sName, sValue)
{
  doc.cookie = sName + "=" + escape(sValue);
}

function SIA_GetCookie(doc, sName)
{
  // cookies are separated by semicolons
  var aCookie = doc.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }
}

function callCameraIconLink(target) {
    OpenDialog(window.WizardWindow, target, 'vividas', 935, 770, false, true, false);
}

function callOtherGovernment()
{
    var linkWindow;
    var thisWidth = (window.screen.width - 7);
    var thisHeight = (window.screen.height - 60);
    window.name = 'SIAMAIN';		
    linkWindow = window.open('/Sia/en/Links/GovernmentLinks.htm', 'Links', '');
    if (linkWindow) linkWindow.focus();
}


function callEndeavour()
{
    var linkWindow;
    var thisWidth = (window.screen.width - 7);
    var thisHeight = (window.screen.height - 60);
    window.name = 'SIAMAIN';		
    linkWindow = window.open('http://www.endeavour.dest.gov.au/', 'Links', '');
    if (linkWindow) linkWindow.focus();
}


function callScholarships()
{
    var linkWindow;
    var thisWidth = (window.screen.width - 7);
    var thisHeight = (window.screen.height - 60);
    window.name = 'SIAMAIN';		
    linkWindow = window.open('http://www.australianscholarships.gov.au/', 'Links', '');
    if (linkWindow) linkWindow.focus();
}