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');
 }


// 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.username.value == '')
	{
		alert("Please enter your email address");
		form.username.focus();
		return false;	
	}
	
	if(form.password.value == '')
	{
		alert("Please enter your password");
		form.password.focus();
		return false;	
	}
	
	
//addLock('loginasp');
	
var url="loginverifytop.asp?un=" + form.username.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;

function valpromo(form)
{
	if (form.promocode.value == "")
	{
	alert("Please enter your promotion code");
	return false;
	}

	var url="checkcode.asp?un=" + form.promocode.value;
	xmlHttp=GetXmlHttpObject(codecheck);
	xmlHttp.open("GET", url , true);
	//window.open(url);
	xmlHttp.send(null);
}

function codecheck() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	var resp = xmlHttp.responseXML; 
	var stat = resp.getElementsByTagName('stat')[0].firstChild.data;
	var ss = document.getElementById('msg')
	ss.innerHTML = stat;
	} 
} 