<!--	
var urlPath="https://www.visa4uk.fco.gov.uk/";
//var urlPath="";
var ChildWindow;
var HelpWindow;
var mX = 0;
var mY = 0;
var IE = document.all?true:false;

function catchClick(e) {
	if (IE) {
		mX = event.clientX;
		mY = event.clientY;
	}
	else {
		mX = e.pageX;
		mY = e.pageY;
	}
}

var HelpPanel;

function closeHelp() {
	HelpPanel=document.getElementById("divHelpPanel");
	HelpPanel.style.display = 'none';
}

function popuphelp(helpindex) {
		
	var HelpItem;
	var HelpItems;
			
	HelpPanel=document.getElementById("divHelpPanel");
	HelpItems=document.getElementById("divHelpItems");
	HelpItem=document.getElementById("divHlp" + helpindex);
	
	for(var i=0; i<HelpItems.childNodes.length; i++){
		HelpItems.childNodes[i].style.display = 'none';
	}
	
	HelpItem.style.display = 'block';
	HelpPanel.style.display = 'block';
}

function GWFValidateDDL(source, arguments) {
	arguments.IsValid = arguments.Value != '0';
}

var strAllowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@/-_, ";

function GWFValidateKey(myfield,e) {
	var allowed=strAllowedChars;
	var isIE = document.all?true:false;
	var key = (isIE) ? window.event.keyCode : e.which;
	if (isIE) {
		if ((key==8) || (allowed.indexOf(String.fromCharCode(key))>-1)) return true;
		return false;
	}
	else {
		if ((key==8) || (key==0) || (allowed.indexOf(String.fromCharCode(key))>-1)) return true;
		return false;
	}
}

function IsValidChar(c) {
	var allowed=strAllowedChars;
	if (allowed.indexOf(c)>-1) return true;
	else return false;
}

function checkTXT (thisobj) {
	var i;
	var chkstr = thisobj.value;
	var newstr = "";
	
	for (i=0; i<chkstr.length; i++) {
		if (IsValidChar(chkstr.charAt(i))) {
			newstr=newstr + chkstr.charAt(i);
		}
	}
	thisobj.value = newstr;
}

function OpenAppWindow(webform) {
	var Nav5 = ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>=5));
	var day=new Date();
	var id=day.getTime();
	id = "VR";
	var w=640/3, h=480/3, cw=w/2, ch=h/2;
	w=740;//w=710;
	h=Math.floor((screen.availHeight)-100);
	cw=Math.floor((screen.availWidth-w)/2);
	ch=20;
	
	if (Nav5) {
		var attr="toolbar=0,alwaysRaised=1,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width="+w+",height="+h+",screenY="+ch+",screenX="+cw
	} else {
		var attr="toolbar=0,alwaysRaised=1,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width="+w+",height="+h+",top="+ch+",left="+cw
	}
	return window.open(urlPath+webform,id,attr); 
}

function clickIE() {
	if (event.button==2) return false;
}

function clickNS(e) {
	if (e.which==3 && e.target.tagName=="IMG") {
		return false;
	}
	if (document.layers || document.getElementById && !document.all) {
		if (e.which==2 || e.which==3) return false;
	}
}

function ignoremenu() {
	return false;
}

function DisableClick() {
	if (document.layers) {
		document.captureEvents(event.MOUSEDOWN);
		document.onmousedown=clickNS; 
	}
	else if (document.all && !document.getElementById) {
		document.onmousedown=clickIE();
	}
	document.oncontextmenu = ignoremenu;
}

function CheckAccept() {
	if (document.form1.chkAcknowledgement.checked==false) {
		window.alert('Please confirm that you have read all relevant guidance before continuing.');
		document.form1.chkAcknowledgement.focus();
		event.returnValue=false;
	} else {
		if (document.getElementById("hdnAcceptApplications").value == '1') {
				ChildWindow = OpenAppWindow("AppProcess/s_ApplicationSecurity.aspx?check=true");
				ChildWindow.focus();
		} else {
			if (IE) {
				document.location="SiteOffline.aspx";
			} else {
				window.open("SiteOffline.aspx");
			}
			event.returnValue=false;
		}
	}
}

function ValidBrowser() {

	if (document.getElementById) {
		//Supports W3C DOM
		return true;
		}
	else {
		return false;
	}
}

function applyNow() {

	if (ValidBrowser()) {
		document.location="ApplyNow.aspx";
	}
	else {
		document.location="Browsers.htm";
	}

}


function existingLogin() {

	if (ValidBrowser()) {
		OpenAppWindow('AppProcess/s_Login.aspx');
	}
	else {
		document.location="Browsers.htm";
	}
}

var prevKey = 0;			
function IEKeyFilter(e) {
	var currKey = event.keyCode;
	if (event.ctrlKey) {
		prevKey = currKey;
		return true;
	}
	if (currKey == 8 || currKey == 27 || currKey == 112 || currKey == 114 || currKey == 117 || currKey == 93 || (event.altKey && (currKey == 37 || currKey == 39)) || (event.ctrlKey && currKey == 82) || currKey == 116 || currKey == 121 || currKey == 122) {
 		if (prevKey == 18 && (currKey == 37 || currKey == 39)) {
			event.keyCode = 0;
			prevKey = 0;
			return false;
		}
		if (prevKey == 16 && currKey == 121) {
			prevKey = currKey;
			return false;
		}
		prevKey = currKey;
		if ((currKey == 93) || (currKey > 111 && currKey < 124)) {
			event.keyCode = 0;
			return false;
		}
		if (currKey != 8 || (currKey == 8 && event.srcElement.type != "text")) {
			if (currKey == 8 && event.srcElement.type == "textarea" ) {
				return true;
			}
			else {
				return false;
			}
		}
	}
	prevKey = currKey;
	return true;
 }

function NSKeyFilter(e) {

	if (e) {
		var currKey = e.keyCode;
		var srcEle = e.target.type;
		
		if (currKey == 8 && (srcEle != "text" && srcEle != "textarea" && srcEle != "password")) {
			cancelKey(e);
		}
		else if (e.ctrlKey) {
			if (currKey == 78 || currKey == 82) {
				cancelKey(e);
			}
		}
		else if (e.altKey && (currKey == 37 || currKey == 39)) {
			cancelKey(e);
		}
	}
}

function cancelKey(e) {
	if (e.preventDefault) {
		e.preventDefault();
		return false;
	}
	else {
		e.keyCode = 0;
		e.returnValue = false;
	}
}

function maxlength(source, max) {
	if (source.value.length >= max) {
		source.value = source.value.substring(0, max);
	}
}


function ddlSubmission_onchange() {
	var s = document.getElementById('ddlSubmission').selectedIndex;
		
		var pc = document.getElementById('hdnPostageCosts').value;
		var apc = pc.split(':');
		if (apc[s] > 0) {
			updateCosts(true);
		} else {
			updateCosts(false);
		}
}


function updateCosts(blnAddPostage) {
	var s = document.getElementById('ddlSubmission').selectedIndex;
	var fc = document.getElementById('hdnTotalCost').value;
	var afc = fc.split(':');
	var c = afc[0];
	var vc = document.getElementById('hdnVisaCost').value;
	var pc = document.getElementById('hdnPostageCosts').value;
	var apc = pc.split(':');
	var npc = (blnAddPostage) ? apc[s] : 0;	
	var ntc = Math.floor(vc) + Math.floor(npc);
	document.getElementById('lblPostageFee').innerHTML = FormatCurrency(c, npc);
	document.getElementById('lblTotal').innerHTML = FormatCurrency(c, ntc);
	document.getElementById('hdnTotalCost').value = c + ':' + ntc;
}


function s_FinalisePageLoad() {
	ddlSubmission_onchange();	
}


function CCExpDateVal1(source, args) {
	var selMonth = document.getElementById("ddlExpMonth").selectedIndex;
	var selYear = document.getElementById("ddlExpYear").selectedIndex;
	
	if ((selMonth == 0) || (selYear == 0)) {
		args.IsValid = false;
	} else {
		args.IsValid = true;
	}
}

function CCExpDateVal2(source, args) {
	var selMonth = document.getElementById("ddlExpMonth").selectedIndex;
	var selYear = document.getElementById("ddlExpYear").selectedIndex;
	var expYear = document.getElementById("ddlExpYear").options[selYear].value;
	
	var today = new Date();
	var curMonth = today.getMonth() + 1;	
	var curYear = today.getFullYear();
	var rtn = true;
	
	if (expYear == curYear) {
		if (selMonth < curMonth) {
			rtn = false;
		}
	}
	args.IsValid = rtn;
}


function confirmPaymentPolicy(){
	var chk = document.getElementById("chkOnlinePayment").checked;
	
	if (!chk) {
		window.alert('Please confirm that you have read all relevant guidance before continuing.');
		chk.focus();
		event.returnValue=false;
	}
	else {
		document.getElementById("divPleaseWait").style.visibility = "visible";
		document.getElementById("divPaymentForm").style.display = "none";
		document.body.style.cursor='wait';
		window.scrollTo(0,0);
	}
}


function btnSubmitPayment_OnClick() {
	var validated = true;
	if (typeof(Page_ClientValidate) == 'function') {
		validated = Page_ClientValidate();
	}
	if (validated) {	
		document.getElementById("divPleaseWait").style.visibility = "visible";
		document.getElementById("divPaymentForm").style.display = "none";
		document.body.style.cursor='wait';
		window.scrollTo(0,0);
		return true;
	}
	else	{	
		return false;
	}
}


function btnSubmitToPost() {
	window.alert("btnSubmitToPost")
	var count = 0;
	var validated = true;
	if (typeof(Page_ClientValidate) == 'function') {
		validated = Page_ClientValidate();
	}
	if (validated) {
		count = document.getElementById('hdnCount').value;
		document.getElementById('hdnCount').value = count + 1;
		if (count == 0) {
			document.body.style.cursor='wait';
			return true;
		} else {
			return false;
		}
	}
	return false;
}

function FormatCurrency(currency, num) {
	var sign;
	var cents;
	if (isNaN(num)) {
		num = 0;
	} 
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents<10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
		num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	}
	return (((sign)?'':'-') + currency + ' ' + num + '.' + cents);
}

//==============================================================
if (!IE) document.captureEvents(Event.CLICK|Event.MOUSEMOVE);
document.onclick = catchClick;

if (navigator.appName == 'Netscape') {
	document.addEventListener("keypress",NSKeyFilter,false);
	document.onkeydown = NSKeyFilter;	
}
else {
	document.onkeydown = IEKeyFilter;
}

//**************************************************************
//GWF2.0 Email Control Amendment

//Prevent page turning (called by blur event of Email Address field in EMC control)
function setHdnCount1() {
	var count = 0;
	//hdnCount already used in GWF form Click events to prevent page turning if set to 1
	document.getElementById('hdnCount').value = count + 1;
}
//Allow page turning
function setHdnCount0() {
	var count = 0;
	document.getElementById('hdnCount').value = count;
}

//Called by AppProcess Next/Previous
function btnNext_OnClick() {
	//check if Conf Email control used on page and execute check
	isEMC();
	//call the original GWF page validation
	var isPgValid;	
	isPgValid = pgValidate();
	if (isPgValid){
		return true;
	}else{
		return false;
	}
}

function isEMC(){
	var emc = new Array();
	//Find EMC input elements on the page
	var els = document.getElementsByTagName("input");
	for(var i = 0; i < els.length; i++){
		if (els[i].id.indexOf("EMC") !== -1){
			emc.push(els[i]);
		}
	}
	//If EMC inputs found, pass first 2 elements
	if (emc.length > 0){
		confirmEmail(emc[0], emc[1]);
		return true;
	}else{
		return false;
	}
}

function confirmEmail(emc1, emc2) {
	//EMC elements passed in if EMC controls present
	//divEMConf contained within EMC control 
	
	var divEMConf;
	
	divEMConf = document.getElementById('divEMConf');
	
	divEMConf.style.visibility = 'hidden';
			
	//If Email field 1 empty validator will capture
	if (emc1.value.length !== 0){
		//If Email field 2 empty prevent page turn, show label	
		if (emc2.value.length == 0){
			setHdnCount1();
			divEMConf.style.visibility = 'visible';
		}else{
			setHdnCount0();
			divEMConf.style.visibility = 'hidden';
		}
	}
	return;
}

//This was the original GWF Next/Previous function
function pgValidate(){
	var count = 0;
		var validated = true;
		if (typeof(Page_ClientValidate) == 'function') {
			validated = Page_ClientValidate();
		}
		if (validated) {
			count = document.getElementById('hdnCount').value;
			document.getElementById('hdnCount').value = count + 1;
			if (count == 0) {
				document.body.style.cursor='wait';
				return true;
			} else {
				return false;
			}
		} else {
			document.getElementById('hdnCount').value = 0;
			return false;
		}
}

//Function taken from VisaAppointments for use with v3.0 of Visa4UK
function ValidateSlots(source, arguments) {
	arguments.IsValid = !document.getElementById('rblSlots').disabled;
}

//Check number of chars of a textbox
function ValidateLength1000(source,arguments) {
	arguments.IsValid = (arguments.Value.length <=1000);
}

//Rendom image generator for v3.1 site banner
function getRandomBanner() {
	var NumberOfLogos	= 5;
	
	var LogoToUse		= Math.floor(Math.random() * (NumberOfLogos - 1)) + 1
	var LogoString		= LogoToUse.toString();
	if (LogoString.length < 2) {
		LogoString	= "0" + LogoString;
	}	
	
	document.write('<span id="banner" class="banner' + LogoString + '"></span>');
}

function confirmCancelAppointment() {
	
		var x=window.confirm('You have chosen to change your appointment.\nYour current appointment will be cancelled if you continue.\n\nPress OK to confirm you wish to continue and book a new appointment.');
		if(x){
			return true;
		}
		else {
			return false;		
		}
}
