function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function WindowOpen1()
 {
  window.open('sec-code.asp', 'Window1', 'resizable=yes,height=200,width=200,scrollbars=no');
 }


function showsubnav(id)
{
            var elem;
            var i = 1;           
            while(elem = document.getElementById('subnav_' + i))
            {
              elem.style.display = 'none';
              i++;
            }
            document.getElementById('subnav_' + id).style.display = 'block';
}

function hidesubnav()
{
            
            document.getElementById('subnav_1').style.display = 'none';
            document.getElementById('subnav_2').style.display = 'none';
            document.getElementById('subnav_3').style.display = 'none';
            document.getElementById('subnav_4').style.display = 'none';

}

function valregister(theForm)
{


	if (theForm.forename.value == "")
	{
	alert("Please enter your forename");
	theForm.forename.focus();
	return false;
	}
	
	if (theForm.surname.value == "")
	{
	alert("Please enter your surname");
	theForm.surname.focus();
	return false;
	}

if (theForm.address.value == "")
	{
	alert("Please enter your address");
	theForm.address.focus();
	return false;
	}
	
	if (theForm.postcode.value == "")
	{
	alert("Please enter your post code");
	theForm.postcode.focus();
	return false;
	}
	
	if (theForm.hometel.value == "")
	{
	alert("Please enter your home telephone");
	theForm.hometel.focus();
	return false;
	}
	
	if (theForm.email.value == "")
	{
	alert("Please enter your email");
	theForm.email.focus();
	return false;
	}
	
	var checkEmail = "@.";
	var checkStr = theForm.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
	if (ch == checkEmail.charAt(j) && ch == "@")
	EmailAt = true;
	if (ch == checkEmail.charAt(j) && ch == ".")
	EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}

	if (EmailAt && EmailPeriod)
	{
			EmailValid = true
			break;
		}
	}

if (!EmailValid)
	{
	alert("Please enter a valid email address.");
	theForm.email.focus();
	return (false);
	}
	

	if (theForm.uname.value == "")
	{
	alert("Please enter a username");
	theForm.uname.focus();
	return false;
	}

	if (theForm.passw.value == "")
	{
	alert("Please enter your password");
	theForm.passw.focus();
	return false;
	}

	
	if (theForm.cpassw.value == "")
	{
	alert("Please confirm your password");
	theForm.cpassw.focus();
	return false;
	}
	
	if (theForm.cpassw.value != theForm.passw.value)
	{
	alert("Passwords dont match");
	theForm.cpassw.focus();
	return false;
	}

	if (!theForm.agree.checked) {
	alert("Please tick the above checkbox to confirm you have read our codes of conduct.")
	return false
	}
	else
	{
	 theForm.submitbutton.disabled = true;	
	}


}

// JavaScript Document

var xmlHttp;
var blankImage = new Image();
blankImage.src = 'blank.gif';

var locks = new Object();

locks.amount = 0;
locks.table = new Array();

function loginverify(form)
{ 

	if(form.emailaddress.value == '')
	{
		alert("Please enter your username");
		form.emailaddress.focus();
		return false;	
	}
	
	if(form.password.value == '')
	{
		alert("Please enter your password");
		form.password.focus();
		return false;	
	}
	
	
//addLock('loginasp');
	
var url="loginverify.asp?un=" + form.emailaddress.value + "&pw=" + form.password.value;
xmlHttp=GetXmlHttpObject(stateChanged);
xmlHttp.open("GET", url , true);
//window.open(url);
xmlHttp.send(null);
} 

function stateChanged() 
{ 



if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 

//removeLock('loginasp');

var resp = xmlHttp.responseXML; 

var stat = resp.getElementsByTagName('stat')[0].firstChild.data;
//alert(stat);


	if (stat == "Logged In")
	{
		var redi = resp.getElementsByTagName('redirecto')[0].firstChild.data;
		window.location.href = redi;
	}
	else
	{
	alert(stat);
	}

} 
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This site doesn't work with Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX/Javascript might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 





function addLock(name)
{
	if(locks.amount == 0)
		lockScreen();
	
	if(!locks[name] || locks[name] == '')
	{
		locks.table[name] = locks.length;
		locks.amount++;
	}
};

function removeLock(name)
{
	if(locks.table[name] != '')
	{
		locks.table[name] = '';
		locks.amount--;
	}

	if(locks.amount == 0)
		unlockScreen();
};

function lockScreen()
{
	document.getElementById('page_cover').style.display = 'block';
	document.getElementById('loadTable').style.display = 'block';

};

function unlockScreen()
{
	document.getElementById('page_cover').style.backgroundImage = "url('semi-transparent.gif')";
	document.getElementById('loadTable').style.display = 'block';
	document.getElementById('page_cover').style.display = 'none';
};


function formCheck() 
{

	
// ---------- Endo of Include file -----------------

	formLocation.CardHolder.focus()
    if (formLocation.CardHolder.value == "")
    {
      alert("Please enter your name as it appears on your card");
      return false;
    }

	formLocation.postcode.focus();

	if (formLocation.postcode.value == "" ) {
		alert("Please enter a postcode")
		return false
	}


//	if (!checkPostcode(formLocation.postcode)) 
//	{
//		return false;
//	}
	

	formLocation.cardno.focus()
    if (formLocation.cardno.value == "")
    {
      alert("Please enter your credit or debit card number");
      return false;
    }

	if ((formLocation.cardno.value.charAt(0) != "3") &&
		(formLocation.cardno.value.charAt(0) != "4") &&
		(formLocation.cardno.value.charAt(0) != "5") &&
		(formLocation.cardno.value.charAt(0) != "6")) {
    	alert("Please enter a valid credit or debit card number");
    	return false;
	}
	cardnolen = 0;
	cardnoNoSpc = "";
	for (i=0; i<22; i++) 
	{
		if ((formLocation.cardno.value.charAt(i) != ' ') && (formLocation.cardno.value.charAt(i) != '')) 
			{
			cardnoNoSpc = cardnoNoSpc + formLocation.cardno.value.charAt(i);
			cardnolen = cardnolen + 1;
			}
	}

if ((cardnolen < 13) || (cardnolen > 22)) {
    	alert("Please enter a valid credit or debit card number");
    	return false;
	}
	luhntotal = 0
	even = false
	for (i=cardnolen-1; i>=0 ; i--) {
		if (even) {
			testvalue = cardnoNoSpc.charAt(i) * 2
			if (testvalue > 9) {
				testvalue = testvalue - 9
			}
			luhntotal = luhntotal + parseInt(testvalue, 10)
		}
		else
		{
			luhntotal = luhntotal + parseInt(cardnoNoSpc.charAt(i), 10)
		}

		even = !even
	}
	if ((luhntotal % 10) != 0) {
    	alert("Please enter a valid credit or debit card number");
    	return false;
	}

	formLocation.cardno.value = cardnoNoSpc;

    if (formLocation.expirymonth.options[formLocation.expirymonth.selectedIndex].value == "MM")
    {
      alert("Please enter the month your credit or debit card expires");
      return false;
    }

    if (formLocation.expiryyear.options[formLocation.expiryyear.selectedIndex].value == "YY")
    {
      alert("Please enter the year your credit or debit card expires");
      return false;
    }

    if ((formLocation.startmonth.options[formLocation.startmonth.selectedIndex].value != "") && (formLocation.startyear.options[formLocation.startyear.selectedIndex].value == ""))
    {
      alert("Please enter the year of your switch card start date");
      return false;
    }

    if ((formLocation.startyear.options[formLocation.startyear.selectedIndex].value != "") && (formLocation.startmonth.options[formLocation.startmonth.selectedIndex].value == ""))
    {
      alert("Please enter the month of your switch card start date");
      return false;
    }


	formLocation.securitycode.focus()
    if (formLocation.securitycode.value == "")
    {
      alert("Please enter your three digit security code.");
      return false;
    }
	
	formLocation.securitycode.focus()
	if (formLocation.securitycode.value.length  < 3)
    {
      alert("Please enter your three digit security code.");
      return false;
    }
	else
	{
	 formLocation.makepaymentbutton.disabled = true;	
	}


}

function isNumber(strLetter) {
	if ("0123456789".indexOf(strLetter) == -1) {
		return false
	}
	else {	
		return true
	}
} //isNumber

function isLetter(strLetter) {
	if ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(strLetter) == -1) {
		return false
	}
	else {	
		return true
	}
} //isLetter


function checkPostcode(postcode){
	
	postcode.value = postcode.value.toUpperCase()

	if (postcode.value == "" ) {
		alert("Please enter a postcode")
		return false
	}

	postcodeNoSpc = new String
	for (i=0; i<8 ; i++) {
		if (postcode.value.charAt(i)!=" ") {
			postcodeNoSpc = postcodeNoSpc + postcode.value.charAt(i)
		}
	}

	//Check length is valid
	if ((postcodeNoSpc.length < 5) || (postcodeNoSpc.length > 7)) {
		alert("Invalid postcode entered - please re-enter")
		return false
	}

	//Validate the first character of the outcode
	if (!isLetter(postcodeNoSpc.charAt(0))) {
		alert("Invalid postcode entered - please re-enter")
		return false
	}

	//Validate the incode - which must be NAA
	if (!isNumber(postcodeNoSpc.charAt(postcodeNoSpc.length - 3))) {
		alert("Invalid postcode entered - please re-enter")
		return false
	}

	if (!isLetter(postcodeNoSpc.charAt(postcodeNoSpc.length - 2))) {
		alert("Invalid postcode entered - please re-enter")
		return false
	}

	if (!isLetter(postcodeNoSpc.charAt(postcodeNoSpc.length - 1))) {
		alert("Invalid postcode entered - please re-enter")
		return false
	}

	//Validate the rest of the outcode - three cases depending on length
	if (postcodeNoSpc.length == 5) { //case AN so second char must be N
		if (!isNumber(postcodeNoSpc.charAt(1))) {
			alert("Invalid postcode entered - please re-enter")
			return false
		}
	}

	if (postcodeNoSpc.length == 6) { //case ANN AAN ANA so cannot have second and third char both as A
		if ((isLetter(postcodeNoSpc.charAt(1))) && (isLetter(postcodeNoSpc.charAt(2)))) {
			alert("Invalid postcode entered - please re-enter")
			return false
		}
	}

	if (postcodeNoSpc.length == 7) { //case AANN AANA so second char must be A and third char must be N
		if (!isLetter(postcodeNoSpc.charAt(1))) {
			alert("Invalid postcode entered - please re-enter")
			return false
		}
		if (!isNumber(postcodeNoSpc.charAt(2))) {
			alert("Invalid postcode entered - please re-enter")
			return false
		}
	}

	validpostcode = new String
	for (i=0; i<8 ; i++) {
		validpostcode = validpostcode + postcodeNoSpc.charAt(i)
		if (i == (postcodeNoSpc.length - 4)) {
			validpostcode = validpostcode + ' '
		}
	}

	postcode.value = validpostcode

	return true
} //checkPostcode

function resizeTasks()
{
	try
	{
		document.getElementById('page_cover').style.height = document.documentElement.scrollHeight + 'px';
	}
	catch(e)
	{
		
	}
};

window.onresize = resizeTasks;