		var strOcc;
		var strFor;
		var strType;
		var strRange;
		var nCurrentCard;
		var nCurrentCardBatch;
		var bCardNavigationMovingUp;
		var NUM_PER_PAGE = 9;
		
		function GetCardList( nLastCardNumber, bFreshSearch, bWait )
		{ 
			document.getElementById('CardList').innerHTML = "<table cellspacing='0' width='410'><tr><td ></td></tr><tr><td align='center' ><br><br><br><br><br><br><br><br><br><br><br><br><b>LOADING CARD PICTURES...</b><br><br><br><br><br><br><br><br><br><br><br><br></td></tr><tr><td>&nbsp;</td></tr><tr></table>";
			//alert('1');
			if(!bFreshSearch)
			{
				//the next or previous button has been pressed and the search carries on from the next batch
				if(nCurrentCardBatch > nLastCardNumber)
				{
					//previous
					nCurrentCard = nLastCardNumber;
				}
				else
				{
					//next
					nCurrentCard = nCurrentCardBatch + 1;
				}
			}
			else
			{
				//the find button has been pressed
				//just in case the range value is set change it to blank
				/****************uncomment the next 3 lines if move back to old way*******/
				//var hidobjRange;
				//hidobjRange = document.SearchForm.hiddenRange
				//hidobjRange.value = "";
				//////////////**************************/////////////////////////
				
				//and the search must begin from card 1
				nCurrentCard = 1;
			}
			//the current batch becomes the parameter nLastCardNumber		
			nCurrentCardBatch = nLastCardNumber;
			
			//This function is an ajax call
			//to get the card picture list
			getCurrentSelections();
			//call the remote file to populate the card pictures
			var url = requestURL + "GetCardListPictures.asp?lastCard=" + nLastCardNumber + "&occ=" + strOcc + "&Type=" + strType + "&For=" + strFor + "&Range=" + strRange + "&datacd=" + Math.floor(Math.random()*1000);
	            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(CardListStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			if(bWait)
			{
				xmlHttp_Get(xmlHttp, url, false);
			}
			else
			{
				xmlHttp_Get(xmlHttp, url, true); 
			}

		}
		
		function CardListStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					document.getElementById('CardList').innerHTML = str;
					
					//show the first card of this batch
					if( null == document.getElementById(nCurrentCard))
					{
					//this would only be the case if we have wrapped round to the start
						nCurrentCard = 1;
					}
					var strCardCd = document.getElementById(nCurrentCard).name;
					GetCardInfo(strCardCd, nCurrentCard);
				}
				else
				{
					document.getElementById('CardList').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently access the card information" + strErrorMessageEnd;
				}
			} 
		} 

		
		
		function GetCardInfo( strCardCd, cardNumber )
		{ 
			objInnerCardDetails = document.getElementById('innerCardDetails');
			if( objInnerCardDetails != null )
			{
				objInnerCardDetails.innerHTML = "<table width='100%' height='338'><tr><td align='center'> Loading the card details. </td></tr></table>";
			}
			nCurrentCard = cardNumber;
			//Append the name to search for to the requestURL 
			var url = requestURL + "GetCardInfo.asp?cardcd=" + strCardCd + "&datacd=" + Math.floor(Math.random()*1000); 
	            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(CardInfoStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			xmlHttp_Get(xmlHttp, url, true); 

		}
		
		function CardInfoStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				//if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					
					document.getElementById('CardDetails').innerHTML = str; 
				}
				//else
				{
					//document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently display the information for this greeting card" + strErrorMessageEnd;
				}
			} 
		} 

/*----------------------------------------------------------------------------------------*/

		function GetAddressForm( strCardCd, strSendDirect, nItemId )
		{ 
			var url;
			//Append the name to search for to the requestURL 
			url = requestURL + "GetAddressFormRemote.asp?cardcd=" + strCardCd +"&SendDirect="+strSendDirect+"&ItemId="+nItemId+"&datacd=" + Math.floor(Math.random()*1000);
			            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(AddressFormStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			xmlHttp_Get(xmlHttp, url, true); 

		}
		
		function AddressFormStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				//if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					
					document.getElementById('CardDetails').innerHTML = str; 
				}
				//else
				{
				//	document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently display the information for this greeting card" + strErrorMessageEnd;
				}
			} 
		} 
		
/*----------------------------------------------------------------------------------------*/
		function getCardWritingForm( strCardCd )
				{ 
			//debugger;
			var url;
			//Append the name to search for to the requestURL 
			url = requestURL + "GetCardWriteRemote.asp?cardcd=" + strCardCd +"&datacd=" + Math.floor(Math.random()*1000);
			
	            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(CardWritingFormStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			xmlHttp_Get(xmlHttp, url, true); 

		}
		
		function CardWritingFormStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					
					document.getElementById('CardDetails').innerHTML = str; 
				}
				else
				{
					document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently display the form to write this card" + strErrorMessageEnd; 
				}
			} 
		} 
/*----------------------------------------------------------------------------------------*/

		function emailFriend( strCardCd )
		{ 
			var url;
			//Append the name to search for to the requestURL 
			url = requestURL + "GetEmailFriendFormRemote.asp?cardcd=" + strCardCd + "&datacd=" + Math.floor(Math.random()*1000);
			            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(emailFriendStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			xmlHttp_Get(xmlHttp, url, true); 

		}
		
		function emailFriendStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					
					document.getElementById('CardDetails').innerHTML = str; 
				}
				else
				{
					document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently display the information for this greeting card" + strErrorMessageEnd;
				}
			} 
		} 	
/*----------------------------------------------------------------------------------------*/

		function sendEmail( strCardCd )
		{ 
			var strPostValue = getFormValues(document.frmEmail);	//get form values in ajaxcd.js
			//add the card cd
			strPostValue += "&cardcd=" + strCardCd;
			var url;
			alert(strPostValue);
			//Append the name to search for to the requestURL 
			url = requestURL + "SendEmailToFriendRemote.asp?" + strPostValue + "&datacd=" + Math.floor(Math.random()*1000);
			            
			//Create the xmlHttp object to use in the request 
			//stateChangeHandler will fire when the state has changed, i.e. data is received back 
			// This is non-blocking (asynchronous) 
			xmlHttp = GetXmlHttpObject(sendEmailStateChangeHandler); 
	            
			//Send the xmlHttp get to the specified url 
			xmlHttp_Get(xmlHttp, url, true); 

		}
		
		function sendEmailStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 

					//Populate the innerHTML of the div with the results
					
					document.getElementById('CardDetails').innerHTML = str; 
				}
				else
				{
					document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we cannot currently display the information for this greeting card" + strErrorMessageEnd;
				}
			} 
		} 	
/*----------------------------------------------------------------------------------------*/
		function sendAddressToServer( strPostValue )
		{
			var url;
			url = requestURL + "WriteAddressToDatabase.asp"
			xmlHttp = GetXmlHttpObject(sendAddressToServerStateChangeHandler); 
			xmlHttp_Post(xmlHttp, url, strPostValue, true); 
		}
		
		//to do 
		// and refresh the basket count
		function sendAddressToServerStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 
					//Populate the innerHTML of the div with the results
					document.getElementById('CardDetails').innerHTML = str; 
				}
				else
				{
					document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we have not been able to receive this address.  Please try again." + strErrorMessageEnd;
				}
			} 
		} 
		
/*--------------------------------------------------------------------------------------*/		
		function sendMessageToServer( strPostMessage )
		{
			var url;
			url = requestURL + "WriteCardMessageToDatabase.asp"
			xmlHttp = GetXmlHttpObject(sendMessageToServerStateChangeHandler); 
			xmlHttp_Post(xmlHttp, url, strPostMessage, true); 
		}
		
		function sendMessageToServerStateChangeHandler() 
		{ 
			//readyState of 4 or 'complete' represents that data has been returned 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
			{ 
				if(xmlHttp.status == 200)
				{
					//Gather the results from the callback 
					var str = xmlHttp.responseText; 
					//Populate the innerHTML of the div with the results
					document.getElementById('CardDetails').innerHTML = str; 
				}
				else
				{
					document.getElementById('CardDetails').innerHTML = strErrorMessageStart + "Sorry due to a system error we have not been able to receive the message for this card.  Try to edit this information in the shopping basket." + strErrorMessageEnd;
				}
			} 
		} 
/*--------------------------------------------------------------------------------------*/

		function getNextCard()
		{
			if(nCurrentCard == nCurrentCardBatch)
			{
				GetCardList(nCurrentCardBatch + NUM_PER_PAGE);
			}
			else
			{
				if(nCurrentCard > 0)
				{
					nCurrentCard++;
				}
				else
				{
					nCurrentCard = 2;
				}
				if( null != document.getElementById(nCurrentCard) )
				{
					var strCardCd = document.getElementById(nCurrentCard).name;
					GetCardInfo(strCardCd, nCurrentCard);
				}
				else
				{
					//we must be at the end of the cards so can start at the beginning
					GetCardList( NUM_PER_PAGE , true );
				}
			}
		}
		
		function getPreviousCard()
		{
			if(nCurrentCard == nCurrentCardBatch - NUM_PER_PAGE + 1)
			{
				if(nCurrentCard > 1)
				{
					GetCardList(nCurrentCardBatch - NUM_PER_PAGE);
				}
			}
			else
			{
				if(nCurrentCard > 1)
				{
					nCurrentCard--;
				}
				var strCardCd = document.getElementById(nCurrentCard).name;
				GetCardInfo(strCardCd, nCurrentCard);
			}
		}