/************************************************************************
FUNCTION: openNewWindow(url, width, height)
Open a new window with specified height and width.
************************************************************************/
function openNewWindow(url, width, height) {
     window.open(url, 'AAT', 'width=' + width + ', height=' + height + ', resizable=yes, scrollbars=yes');
}

/************************************************************************
FUNCTION:  toggleRowOnCheckBox(checkBoxId, rowId, textAreaId)
************************************************************************/
function toggleRowOnCheckBox(checkBoxId, rowId, textAreaId) {
	if (document.getElementById(checkBoxId).checked == true) {
		document.getElementById(rowId).style.display = '';
	} else {
		document.getElementById(rowId).style.display = 'none';
		document.getElementById(textAreaId).value = '';
	}
}

/************************************************************************
FUNCTION:  toggleRowAndTextAreaOnRadio(formName, radioName, rowId, textAreaId, expectedValue)
Show the row with given id if radio button has been clicked and its value 
is expectedValue otherwise hide it.
************************************************************************/
function toggleRowAndTextAreaOnRadio(formName, radioName, rowId, textAreaId, expectedValue) {
	var form = document.getElementById(formName);
	var radioElement = form[radioName];
	
	for(var i = 0; i < radioElement.length; i++) {
		if(radioElement[i].checked) {
			if (radioElement[i].value == expectedValue){
				document.getElementById(rowId).style.display = '';
			} else {
				document.getElementById(rowId).style.display = 'none';
				document.getElementById(textAreaId).value = '';
			}
		}
	}
}

/************************************************************************
FUNCTION:  toggleRowOnRadio(formName, radioName, rowId, expectedValue)
Show the row with given id if radio button has been clicked and its value 
is expectedValue otherwise hide it.
(Style=display:none only works for divs (see toggleDisplayAreaOnRadio)
A row can be hidden by setting its class to "hidden".)
************************************************************************/
function toggleRowOnRadio(formName, radioName, rowId, expectedValue) {
	var form = document.getElementById(formName);
	var radioElement = form[radioName];
	
	for (var i = 0; i < radioElement.length; i++) {
		if (radioElement[i].checked) {
			if (radioElement[i].value == expectedValue){
				document.getElementById(rowId).className = '';
			} else {
				document.getElementById(rowId).className = 'hidden';
			}
		}
	}
}

/************************************************************************
FUNCTION:  toggleRowsOnRadio(formName, radioName, rowIdOn, textAreaIdOn, rowIdOff, textAreaIdOff, expectedValue)
************************************************************************/
function toggleRowsOnRadio(formName, radioName, rowIdOn, textAreaIdOn, rowIdOff, textAreaIdOff, expectedValue) {
	var form = document.getElementById(formName);
	var radioElement = form[radioName];
	
	for(var i = 0; i < radioElement.length; i++) {
		if(radioElement[i].checked) {
			if (radioElement[i].value == expectedValue){
				document.getElementById(rowIdOn).style.display = '';
				document.getElementById(rowIdOff).style.display = 'none';
				document.getElementById(textAreaIdOff).value = '';
			} else {
				document.getElementById(rowIdOn).style.display = 'none';
				document.getElementById(rowIdOff).style.display = '';
				document.getElementById(textAreaIdOn).value = '';
			}
		}
	}
}


/************************************************************************
FUNCTION:  
toggleDisplayAreaOnRadio(formName, radioName, displayAreaId, expectedValue)
Show displayArea if radio button has been clicked and its value is 
expectedValue else hide displayArea. 
************************************************************************/
function toggleDisplayAreaOnRadio(formName, radioName, displayAreaId, expectedValue) {
	var form = document.getElementById(formName);
	var radioElement = form[radioName];
	
	for (var i = 0; i < radioElement.length; i++) {
		if (radioElement[i].checked) {
			if (radioElement[i].value == expectedValue){
				document.getElementById(displayAreaId).style.display = '';
			}
			else {
				document.getElementById(displayAreaId).style.display = 'none';
			}
		}
	}
}

/************************************************************************
FUNCTION:  
toggleDisplayAreaOnDropDown(dropDownName, displayAreaId, expectedValues)
Show displayArea if dropdown value has been selected and its value is 
in expectedValues array else hide displayArea.
************************************************************************/
function toggleDisplayAreaOnDropDown(dropDownName, displayAreaId, expectedValues) {
	var dropDownObj = document.getElementById(dropDownName);
	var matchFound = false;
	var i = 0;
	
	while (! matchFound && expectedValues.length > i) {
		if (expectedValues[i] == dropDownObj.value) {
			matchFound = true;
			document.getElementById(displayAreaId).style.display = '';
		}
		i++;
	}
	
	// if no match was found then hide display area
	if (! matchFound) {
		document.getElementById(displayAreaId).style.display = 'none';
	}
}

/*********************************************************
FUNCTION: townChange(type)
Called when the user changes the town.
Sets the text for the labels.
Hides the county row if town is London.
*********************************************************/
function townChange(formName, elementPrefix) {
  
  if (document.getElementById(elementPrefix + '.country').value == 'UK') {
    hideCountyIfTownIsLondon(formName, elementPrefix);
  }
}

/*********************************************************
FUNCTION: countryChange(type)
Called when the user changes the country. 
Sets the text for the labels.
Hides the county row if not UK or town is London.
**********************************************************/
function countryChange(formName, elementPrefix) {

  if (document.getElementById(elementPrefix + '.country').value == 'UK') {
     hideCountyIfTownIsLondon(formName, elementPrefix);
  } else {
     document.getElementById('townlabel').innerHTML = 'Town/Region <span class="mandatory">*</span>';
     document.getElementById('postcodelabel').innerHTML = 'Postal Code';
     document.getElementById('countyRow').className = 'hidden';
  }
}

/*********************************************************
FUNCTION: hideCountyIfTownIsLondon(formName, elementPrefix)
This should only be called if the selected country is UK.
(ie this is a "private" function that should only be called
from another function)
*********************************************************/
function hideCountyIfTownIsLondon(formName, elementPrefix) {

	document.getElementById('townlabel').innerHTML = 'Town <span class="mandatory">*</span>';
	document.getElementById('postcodelabel').innerHTML = 'Postcode <span class="mandatory">*</span>';
	
	if (document.getElementById(elementPrefix + '.town').value.toUpperCase() == 'LONDON') {
       document.getElementById('countyRow').className = 'hidden';
     } else {
     	document.getElementById('countyRow').className = '';
    }  
}

/*********************************************************
FUNCTION: fillpostcodeandsubmit(type)
This is used by the vyre UserEditPortlet for adding address
details in the StudentRegistration portlet. 'type' is either
home or work
*********************************************************/
function fillpostcodeandsubmit(type) {
  var a;
  if(document.getElementById('aatUserEditForm'))
    a = document.getElementById('aatUserEditForm');
  else
    a = document.forms[document.forms.length-1];
  if (eval('a.' + type + 'country').value == 'UK')
  {
    var postcodestring = '';
    postcodestring = eval('a.' + type + 'postcode1.value');
    postcodestring = postcodestring + ' ';
    postcodestring = postcodestring + eval('a.' + type + 'postcode2.value');
    eval('a.' + type + 'postcode.value = postcodestring');
  }
  a.submit();
}

/*********************************************************
FUNCTION: fillukpostcode(type,postcodestring)
This is used by the vyre UserEditPortlet for adding address
details in the StudentRegistration portlet. 'type' is either
home or work
*********************************************************/
function fillukpostcode(type,postcodestring)
{
  var a;
  if(document.getElementById('aatUserEditForm'))
    a = document.getElementById('aatUserEditForm');
  else
    a = document.forms[document.forms.length-1];
  var postcodestring1 = postcodestring.substring(0,postcodestring.length - 4);
  var postcodestring2 = postcodestring.substring(postcodestring.length - 3,postcodestring.length);
  eval('a.' + type + 'postcode1.value = postcodestring1');
  eval('a.' + type + 'postcode2.value = postcodestring2');
}

/*********************************************************
FUNCTION: filltowncounty(type)
This is used by the vyre UserEditPortlet for adding address
details in the StudentRegistration portlet. 'type' is either
home or work. TO DO: change the UserEditPortlet to use the
system file key way of populating drop downs.
*********************************************************/
function filltowncounty(type) {
  var a;
  if(document.getElementById('aatUserEditForm'))
    a = document.getElementById('aatUserEditForm');
  else
    a = document.forms[document.forms.length-1];
  if (eval('a.' + type + 'country.value') == 'UK')
  {
     if (eval('a.' + type + 'town.value').toUpperCase() == 'LONDON')
     {
       document.getElementById('townlabel').innerHTML = '<label class="portlet-form-label for="' + type + 'town">Town</label> <span id="dot">*</span>';
       document.getElementById('countylabel').innerHTML = '';
       document.getElementById('countyfield').innerHTML = '<input type="hidden" name="' + type + 'county" value="" /> ';
       document.getElementById('postcodelabel').innerHTML = '<label class="portlet-form-label for="' + type + 'postcode">Postcode</label> <span id="dot">*</span>';
     document.getElementById('postcodefield').innerHTML = '<input type="text" name="' + type + 'postcode1" maxlength="4" value="" size="13" /><input type="text" name="' + type + 'postcode2" maxlength="3" value="" size="12" /><input type="hidden" name="' + type + 'postcode" value=""/>';
     }
     else
     {
     document.getElementById('townlabel').innerHTML = '<label class="portlet-form-label for="' + type + 'town">Town</label> <span id="dot">*</span>';
     document.getElementById('countylabel').innerHTML = '<label class="portlet-form-label for="' + type + 'county">County</label> <span id="dot">*</span>';
     document.getElementById('countyfield').innerHTML = '<select name="' + type + 'county"><option value="" selected="selected"></option><option value="Aberdeenshire">Aberdeenshire</option><option value="Alderney">Alderney</option><option value="Angus">Angus</option><option value="Argyll">Argyll</option><option value="Avon">Avon</option><option value="Ayrshire">Ayrshire</option><option value="Banffshire">Banffshire</option><option value="Bedfordshire">Bedfordshire</option><option value="Berkshire">Berkshire</option><option value="Berwickshire">Berwickshire</option><option value="Borders">Borders</option><option value="Brecknockshire">Brecknockshire</option><option value="Buckinghamshire">Buckinghamshire</option><option value="Bute-Shire">Bute-Shire</option><option value="Caernarfonshire">Caernarfonshire</option><option value="Caithness">Caithness</option><option value="Cambridgeshire">Cambridgeshire</option><option value="Cardiganshire">Cardiganshire</option><option value="Carmarthenshire">Carmarthenshire</option><option value="Central">Central</option><option value="Channel Islands">Channel Islands</option><option value="Cheshire">Cheshire</option><option value="Clackmannanshire">Clackmannanshire</option><option value="Cleveland">Cleveland</option><option value="Clwyd">Clwyd</option><option value="Cornwall">Cornwall</option><option value="County Antrim">County Antrim</option><option value="County Armagh">County Armagh</option><option value="County Down">County Down</option><option value="County Durham">County Durham</option><option value="County Fermanagh">County Fermanagh</option><option value="County Londonderry">County Londonderry</option><option value="County Tyrone">County Tyrone</option><option value="Cumberland">Cumberland</option><option value="Cumbria">Cumbria</option><option value="Denbighshire">Denbighshire</option><option value="Derbyshire">Derbyshire</option><option value="Devon">Devon</option><option value="Dorset">Dorset</option><option value="Dumfriesshire">Dumfriesshire</option><option value="Dunbartonshire">Dunbartonshire</option><option value="Dyfed">Dyfed</option><option value="East Lothian">East Lothian</option><option value="East Sussex">East Sussex</option><option value="East Yorkshire">East Yorkshire</option><option value="Essex">Essex</option><option value="Fife">Fife</option><option value="Flintshire">Flintshire</option><option value="Gloucestershire">Gloucestershire</option><option value="Grampian">Grampian</option><option value="Greater Manchester">Greater Manchester</option><option value="Guernsey">Guernsey</option><option value="Gwent">Gwent</option><option value="Gwynedd">Gwynedd</option><option value="Hampshire">Hampshire</option><option value="Herefordshire">Herefordshire</option><option value="Hertfordshire">Hertfordshire</option><option value="Highlands">Highlands</option><option value="Huntingdonshire">Huntingdonshire</option><option value="Inverness-shire">Inverness-shire</option><option value="Isle of Arran">Isle of Arran</option><option value="Isle of Barra">Isle of Barra</option><option value="Isle of Benbecula">Isle of Benbecula</option><option value="Isle of Bute">Isle of Bute</option><option value="Isle of Harris">Isle of Harris</option><option value="Isle of Islay">Isle of Islay</option><option value="Isle of Lewis">Isle of Lewis</option><option value="Isle of Man">Isle of Man</option><option value="Isle of North Uist">Isle of North Uist</option><option value="Isle of Scalpay">Isle of Scalpay</option><option value="Isles of Scilly">Isles of Scilly</option><option value="Isle of Skye">Isle of Skye</option><option value="Isle of South Uist">Isle of South Uist</option><option value="Isle of Wight">Isle of Wight</option><option value="Jersey">Jersey</option><option value="Kent">Kent</option><option value="Kincardineshire">Kincardineshire</option><option value="Kinross-shire">Kinross-shire</option><option value="Kirkcudbrightshire">Kirkcudbrightshire</option><option value="Lanarkshire">Lanarkshire</option><option value="Lancashire">Lancashire</option><option value="Leicestershire">Leicestershire</option><option value="Lincolnshire">Lincolnshire</option><option value="Lothian">Lothian</option><option value="Merioneth">Merioneth</option><option value="Merseyside">Merseyside</option><option value="Mid Glamorgan">Mid Glamorgan</option><option value="Middlesex">Middlesex</option><option value="Midlothian">Midlothian</option><option value="Monmouthshire">Monmouthshire</option><option value="Montgomeryshire">Montgomeryshire</option><option value="Morayshire">Morayshire</option><option value="Nairnshire">Nairnshire</option><option value="Norfolk">Norfolk</option><option value="North Humberside">North Humberside</option><option value="North Yorkshire">North Yorkshire</option><option value="Northamptonshire">Northamptonshire</option><option value="Northumberland">Northumberland</option><option value="Nottinghamshire">Nottinghamshire</option><option value="Orkney">Orkney</option><option value="Oxfordshire">Oxfordshire</option><option value="Peebleshire">Peebleshire</option><option value="Pembrokeshire">Pembrokeshire</option><option value="Perthshire">Perthshire</option><option value="Powys">Powys</option><option value="Radnorshire">Radnorshire</option><option value="Renfrewshire">Renfrewshire</option><option value="Ross-shire">Ross-shire</option><option value="Roxburghshire">Roxburghshire</option><option value="Rutland">Rutland</option><option value="Sark">Sark</option><option value="Selkirkshire">Selkirkshire</option><option value="Shetland">Shetland</option><option value="Shropshire">Shropshire</option><option value="Somerset">Somerset</option><option value="South Glamorgan">South Glamorgan</option><option value="South Humberside">South Humberside</option><option value="South Yorkshire">South Yorkshire</option><option value="Staffordshire">Staffordshire</option><option value="Stirlingshire">Stirlingshire</option><option value="Strathclyde">Strathclyde</option><option value="Suffolk">Suffolk</option><option value="Surrey">Surrey</option><option value="Sutherland">Sutherland</option><option value="Tayside">Tayside</option><option value="Tyne and Wear">Tyne and Wear</option><option value="Warwickshire">Warwickshire</option><option value="West Glamorgan">West Glamorgan</option><option value="West Lothian">West Lothian</option><option value="West Midlands">West Midlands</option><option value="West Sussex">West Sussex</option><option value="West Yorkshire">West Yorkshire</option><option value="Western Isles">Western Isles</option><option value="Westmoreland">Westmoreland</option><option value="Wigtownshire">Wigtownshire</option><option value="Wiltshire">Wiltshire</option><option value="Worcestershire">Worcestershire</option><option value="Vale of Glamorgan">Vale of Glamorgan</option></select> ';
     document.getElementById('postcodelabel').innerHTML = '<label class="portlet-form-label for="' + type + 'postcode">Postcode</label> <span id="dot">*</span>';
     document.getElementById('postcodefield').innerHTML = '<div><input type="text" name="' + type + 'postcode1" maxlength="4" value="" size="13" /> <input type="text" name="' + type + 'postcode2" maxlength="3" value="" size="12" /><input type="hidden" name="' + type + 'postcode" value=""/></div>';
    }  
  }
  else
  {
     document.getElementById('townlabel').innerHTML = '<label class="portlet-form-label for="' + type + 'town">Town/Region:</label><span id="dot">*</span>';
     document.getElementById('countylabel').innerHTML = '';
     document.getElementById('countyfield').innerHTML = '<input type="hidden" name="' + type + 'county" value="" /> ';
     document.getElementById('postcodelabel').innerHTML = '<label class="portlet-form-label for="' + type + 'postcode">Postal Code</label><span id="dot">*</span>';
     document.getElementById('postcodefield').innerHTML = '<div><input type="text" name="' + type + 'postcode" maxlength="9" value="" size="30" /></div>';
  }
}

/*********************************************************
FUNCTION: GoToChosenCentre (centerCode)
This should called when a centre user select a centre from 
choose your sentre portlet
*********************************************************/
function GoToChosenCentre (centerCode)
  {
     document.getElementById("chosenCentre").value=centerCode
     document.chooseYourCentre.submit();
  }

/*********************************************************
FUNCTION: GoToChosenStatementAndAchievement(chosenRoute,chosenRouteName)
This should called when a user click on one of the statement of achievemnts 
in that page: /myaat/services/statementofachievement/
*********************************************************/
function GoToChosenStatementAndAchievement(chosenRoute,chosenRouteName)
{
     document.getElementById(chosenRouteName).value=chosenRoute
     document.statementofachievement.submit();

}

/************************************************************************
FUNCTION:  open_table_win( path)
************************************************************************/
function open_table_win(path) {
  open_custom( path,550,400);
}

var newwindow = '';


/************************************************************************
FUNCTION:  open_custom( path,width,height
************************************************************************/
function open_custom(path,width,height) {
        if (newwindow != '') newwindow.close();
	newwindow = window.open(path, 'aWindow',' width=' + width + ', height=' + height + ', menubar=no, location=no, resizable=yes, hotkeys=no, directories=no, scrollbars=yes, toolbar=no, titlebar=no, status=no');
}


/************************************************************************
FUNCTION:  open_email_win( path) 
************************************************************************/
function open_email_win( path) {
  open_custom( path,810,400);
}

/************************************************************************
FUNCTION:  toggleRowById( rowId) 
************************************************************************/
function toggleRowById(rowId) 
{

         if(document.layers){	// Netscape 4+
		dom = document.layers[rowId].style;
	}else if(document.getElementById){	// Netscape 6+, gecko, IE 5+
		dom = document.getElementById(rowId).style;
	}else if(document.all){	// IE 4+
		dom = document.all[rowId].style;
	}else{	// Browser unknown; do nothing
		return ;
	}

    if (dom.display == "none")
       dom.display = "block";
    else
      dom.display = "none";
}

/************************************************************************
FUNCTION:  toggleOpenAll() 
************************************************************************/
function toggleOpenAll(divId) 
{
  var i;
  var y = document.getElementById(divId);
  alert(y);
  var x = y.document.getElementsByTagName('table');
  for (i=0;i<x.length;i++)
  {
    if (x[i].className.indexOf('displayTable')!=-1)
    {
       x[i].style.display='block';
    }
  }
}


/************************************************************************
FUNCTION:  cancelButton( url) 
************************************************************************/
function cancelButton(url) 
{
    window.location.href = url;
   
}

function getURL()
{
	var url = window.location.href;

	if (url=='http://www.accountingtechnician.co.uk/'||url=='http://www.accountingtechnician.co.uk') {
		url = 'http://www.accountingtechnician.co.uk/atonline/';
	}

	if (url=='http://www.aat.org.uk'||url=='http://www.aat.org.uk/'||url=='https://www.aat.org.uk'||url=='https://www.aat.org.uk/') {
		url = 'http://www.aat.org.uk/home/';
	}

	if (url=='http://intranet.aat.org.uk'||url=='http://intranet.aat.org.uk/') {
		url = 'http://intranet.aat.org.uk/intranet/home/';
	}
}

function gotoanchorlink(url)
{
    document.location.href = url;
}



