// JavaScript Document

	var xmlHttp
	var xmlHttp_OfferCode
	
	function showHint(str)
	{
		if (str.length==0)
		  { 
		  //document.getElementById("txtHint").innerHTML="";
		  document.getElementById("txtHint").innerHTML="<img src='/graphics/consumer/pageimages/fail.gif' alt='Invalid'/>";
		  document.getElementById("btnSubmit").style.display="none";
		  document.getElementById("btnSubmitGrey").style.display="block";
		  document.getElementById("CardFailMsg").innerHTML='Enter a valid Advantage Card number';
		  return;
		  }
		if ((str.length < 9) || (!IsNumeric(str)))
		  { 
		  document.getElementById("txtHint").innerHTML="<img src='/graphics/consumer/pageimages/fail.gif' alt='Invalid'/>";
		  document.getElementById("btnSubmit").style.display="none";
		  document.getElementById("btnSubmitGrey").style.display="block";
		  document.getElementById("CardFailMsg").innerHTML='Enter a valid Advantage Card number';
		  return;
		  }


		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="validateCardNum.asp";
		url=url+"?cardNo="+str;
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} 

	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
			if (xmlHttp.responseText.indexOf("pass.gif") == -1)
			{
				document.getElementById("btnSubmit").style.display="none";
				document.getElementById("btnSubmitGrey").style.display="block";
				document.getElementById("CardFailMsg").innerHTML='Enter a valid Advantage Card number';
			}
			else
			{
				document.getElementById("btnSubmit").style.display="block";
				document.getElementById("btnSubmitGrey").style.display="none";
				document.getElementById("CardFailMsg").innerHTML='<span style="color:green;">Your Advantage Card number is valid</span>';
			}
		}
		else
		{
		document.getElementById("txtHint").innerHTML='';
		}
	}
	
	function GetXmlHttpObject()
	{
		var xmlHttp=null;
		document.getElementById("CardFailMsg").innerHTML="<span style='color:#2405AB;'>Validating card, please wait...</span>";
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		  catch (e)
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  }
		return xmlHttp;
	}

	function IsNumeric(sText)
	{
	   var ValidChars = "0123456789";
	   var IsNumber=true;
	   var Char;
		 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
	   
	}

// ##################################################################################################################
// Following is used by the offer code validation.
//
	function showOfferCodeHint(str)
	{
		// Function used by the offer code validation
		if (str.length==0)
		  { 
		  document.getElementById("txtOfferCodeHint").innerHTML="";
		  document.getElementById("OfferCodeFailMsg").innerHTML="";
		  //document.getElementById("txtOfferCodeHint").innerHTML="<img src='/graphics/consumer/pageimages/fail.gif' alt='Invalid'/>";
		  //document.getElementById("OfferCodeFailMsg").innerHTML='Your code entered is not valid. You may continue but you will not receive any promotion benefits with this code.';
		  return;
		  }
		if (str.length != 6)
		  { 
		  document.getElementById("txtOfferCodeHint").innerHTML="";
		  document.getElementById("OfferCodeFailMsg").innerHTML="";
		  //document.getElementById("txtOfferCodeHint").innerHTML="<img src='/graphics/consumer/pageimages/fail.gif' alt='Invalid'/>";
		  //document.getElementById("OfferCodeFailMsg").innerHTML='Your code entered is not valid. You may continue but you will not receive any promotion benefits with this code.';
		  return;
		  }


		xmlHttp_OfferCode=GetXmlHttpObject_OfferCode();
		if (xmlHttp_OfferCode==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="validateOfferCode.asp";
		url=url+"?offer="+str;
		xmlHttp_OfferCode.onreadystatechange=stateChanged_OfferCode;
		xmlHttp_OfferCode.open("GET",url,true);
		xmlHttp_OfferCode.send(null);
	} 

	function stateChanged_OfferCode() 
	{ 
		if (xmlHttp_OfferCode.readyState==4)
		{ 
		document.getElementById("txtOfferCodeHint").innerHTML=xmlHttp_OfferCode.responseText;
			if (xmlHttp_OfferCode.responseText.indexOf("pass") == -1)
			{
			  document.getElementById("OfferCodeFailMsg").innerHTML='Your code entered is not valid.';
			  document.frmProcess.offerCode.value = "";
			}
			else
			{
				if (xmlHttp_OfferCode.responseText.indexOf("pass_100.gif") != -1)
				{
			  		document.getElementById("OfferCodeFailMsg").innerHTML='<span style="color:green;">Code validated, 100 extra Points offer.</span>';
				}
				else if (xmlHttp_OfferCode.responseText.indexOf("pass_50.gif") != -1)
				{
					document.getElementById("OfferCodeFailMsg").innerHTML='<span style="color:green;">Code validated, 50 extra Points offer.</span>';
				}
				else if (xmlHttp_OfferCode.responseText.indexOf("pass_200.gif") != -1)
				{
					document.getElementById("OfferCodeFailMsg").innerHTML='<span style="color:green;">Code validated, 200 extra Points offer.</span>';
				}
				else
				{
					document.getElementById("OfferCodeFailMsg").innerHTML='<span style="color:green;">Code validated</span>';	
				}
			}
		}
		else
		{
		document.getElementById("txtOfferCodeHint").innerHTML='';
		}
	}

	function GetXmlHttpObject_OfferCode()
	{
		var xmlHttp_OfferCode=null;
		document.getElementById("OfferCodeFailMsg").innerHTML="<span style='color:#2405AB;'>Validating code, please wait...</span>";
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp_OfferCode=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
			{
			xmlHttp_OfferCode=new ActiveXObject("Msxml2.XMLHTTP");
			}
		  catch (e)
			{
			xmlHttp_OfferCode=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  }
		return xmlHttp_OfferCode;
	}

	
// #####################################################################################


	var account_code='REDEE11114';
	var license_code='FK99-AN38-DX97-PB42';
		
	function pcaFastAddressBegin()
	   {
		   if ((document.frmProcess.houseNumber.value == "") || (document.frmProcess.searchpostcode.value == ""))
		   {
			   if ((document.frmProcess.houseNumber.value == "") && (document.frmProcess.searchpostcode.value == ""))
			   {
				    alert('Please supply a house number/name and postcode');
					return false;   
			   }
			   if (document.frmProcess.houseNumber.value == "")
			   {
			   alert('Please supply a house number / name');
			   return false;
			   }
			   if (document.frmProcess.searchpostcode.value == "")
			   {
			   alert('Please supply a postcode');
			   return false;
			   }
		   }
		   else
		   {
			  var postcode = document.frmProcess.searchpostcode.value;
			  var building = ""; //document.frmProcess.searchbuilding.value;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";
		      
		      //Build the url
		      strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
		      strUrl += "&action=fetch";
		      strUrl += "&postcode=" + escape(postcode);
		      strUrl += "&building=" + escape(building);
		      strUrl += "&account_code=" + escape(account_code);
		      strUrl += "&license_code=" + escape(license_code);
		      strUrl += "&callback=pcaFastAddressEnd";
		      
		      //Make the request
		      if (scriptTag)
		         {
		            //The following 2 lines perform the same function and should be interchangeable
		            headTag.removeChild(scriptTag);
		            //scriptTag.parentNode.removeChild(scriptTag);
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      headTag.appendChild(scriptTag);
		   }
	   }

	function pcaFastAddressEnd()
	   {
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  alert("Sorry, no matching items found");
		               }
		            else
		               {
	 				      document.getElementById("addressData").style.display="block";
						  
					  	  document.frmProcess.Address1.value = '' + document.frmProcess.houseNumber.value + ' ' + pca_line1[0];
						  document.frmProcess.Address2.value = '' + pca_line2[0];
						  document.frmProcess.Towncity.value = '' + pca_post_town[0];
						  document.frmProcess.Postcode.value = '' + pca_postcode[0];					  
						  
						  document.frmProcess.searchpostcode.value = '';
						  //document.frmProcess.houseNumber.value = '';
		               }
		         }
	   }

