//'------------------------------------------------------------------------------------------
//' js-shell.js (Shell)
//' Version 1.7
//'------------------------------------------------------------------------------------------
//' Copyright Surfocracy Ltd, 2010, Contact: info@surfocracy.com
//'------------------------------------------------------------------------------------------
//' Description: Shell javascript functions.
//'------------------------------------------------------------------------------------------
// 
// Global declarations
var confirmProceed               // Confirms if operation should continue    
var nextFreeAuthor               // The next free slot for the author
var currentAuthorInstance        // The current instance of the selected author
var nextFreeSubjectCode          // The next free slot for the subject code
var currentSubjectCodeInstance   // The current instance of the selected subject code
var nextFreeScrollerBook         // The next free slot for the scroller book
var currentScrollerBookInstance  // The current instance of the scroller book
var currentBooksByISBN13Instance // The current instance of the book by ISBN13
var currentBooksByTitleInstance  // The current instance of the book by Title

// ------------------------------------------------------------------------
// This JS function pops up an alert if the given Meeting code is already being
// used by another exhibitions. It checks the response from the server side function.
// ------------------------------------------------------------------------
function IsMeetingCodeUnique_Response()
{
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="notunique")
	{
     alert ("Meeting code already in use, please choose another");
     return;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side script to check if the Meeting code
// is still being used in another exhibition record.
// ------------------------------------------------------------------------
function IsMeetingCodeUnique(MeetingCode,IgnoreID)
{
  // Check for blank input
  if (MeetingCode.length!=0)
    {  
		// Create the request object
		xmlhttp=GetXmlHttpObject();

        // THIS IS WHERE THE ASP PAGE IS CALLED
		var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=IsMeetingCodeUnique&MeetingCode="+MeetingCode+"&IgnoreID="+IgnoreID+"&sid="+Math.random();  // Create the URL to the server sideASP file passing in the value and a cache killer
        xmlhttp.onreadystatechange=IsMeetingCodeUnique_Response;  // Set up the JS function to be called once the server response is returned
		// ##### IMPORTANT : set to ASYNCHRONOUS (true) as we are not interested in the return value.
		xmlhttp.open("GET",url,true);                         // Set up the connection using GET method. Passing the URL and indicate it is asynchronous
		xmlhttp.send(null);                                   // Send request to the server.
   }
}

// ------------------------------------------------------------------------
// This JS function checks the status of the partial authorise by looking at
// the output string in the form:
// Order line ID##Order status##Authorise response
// ------------------------------------------------------------------------
function SagePayPartialAuthorise_Response()
{	
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText!="")
	{var splitResult=xmlhttp.responseText;
     var splitResult=splitResult.split("##");
	 
//     alert (xmlhttp.responseText + "\n");
//     alert (splitResult[0] + "\n");
//     alert (splitResult[1] + "\n");
//     alert (splitResult[2] + "\n");
	 
	 document.getElementById("partialauthorise"+splitResult[0]).innerHTML=splitResult[2];
	 document.getElementById("orderstatus").innerHTML=splitResult[1];  // Update the order status
	 
	 if (document.getElementById("chargefull")!==null) {
	 document.getElementById("chargefull").style.display='none';       // Disable link to charge entire order as no longer relevant
	 }
     return;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side script authorise a partial payment for
// the given Transaction ID.
//
// ForTransactionID : The main transaction ID of this order
// ------------------------------------------------------------------------
function SagePayPartialAuthorise(ForTransactionID,ForOrderLineID)
{
  // Check for blank input
  if (ForTransactionID.length!=0)
    {  
		// Create the request object
		xmlhttp=GetXmlHttpObject();

        // THIS IS WHERE THE ASP PAGE IS CALLED
		var url="/secure/AJAX-sagepay-authorise.asp?TransactionID="+ForTransactionID+"&AuthoriseType=partial"+"&OrderLineID="+ForOrderLineID+"&sid="+Math.random();  // Create the URL to the server side ASP file passing in the value and a cache killer
        xmlhttp.onreadystatechange=SagePayPartialAuthorise_Response;  // Set up the JS function to be called once the server response is returned
		// ##### IMPORTANT : set to ASYNCHRONOUS (true) as we are not interested in the return value.
		xmlhttp.open("GET",url,true);                         // Set up the connection using GET method. Passing the URL and indicate it is asynchronous
		xmlhttp.send(null);                                   // Send request to the server.
   }
}

// ------------------------------------------------------------------------
// This JS function checks the status of the full authorise
// ------------------------------------------------------------------------
function SagePayFullAuthorise_Response()
{
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText!="")
	{var splitResult=xmlhttp.responseText;
     var splitResult=splitResult.split("##");
	 
     //alert (xmlhttp.responseText);
	 document.getElementById("orderstatus").innerHTML=splitResult[0];  // Update the order status
	 document.getElementById("chargefull").innerHTML=splitResult[1];
     return;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side script authorise a full payment for
// the given Transaction ID.
//
// ForTransactionID : The main transaction ID of this order
// ------------------------------------------------------------------------
function SagePayFullAuthorise(ForTransactionID)
{
  // Check for blank input
  if (ForTransactionID.length!=0)
    {  
		// Create the request object
		xmlhttp=GetXmlHttpObject();

        // THIS IS WHERE THE ASP PAGE IS CALLED
		var url="/secure/AJAX-sagepay-authorise.asp?TransactionID="+ForTransactionID+"&AuthoriseType=full&sid="+Math.random();  // Create the URL to the server sideASP file passing in the value and a cache killer
        xmlhttp.onreadystatechange=SagePayFullAuthorise_Response;  // Set up the JS function to be called once the server response is returned
		// ##### IMPORTANT : set to ASYNCHRONOUS (true) as we are not interested in the return value.
		xmlhttp.open("GET",url,true);                         // Set up the connection using GET method. Passing the URL and indicate it is asynchronous
		xmlhttp.send(null);                                   // Send request to the server.
   }
}


// ------------------------------------------------------------------------
// This JS function checks the status of the teleorder single order line request
// ------------------------------------------------------------------------
function TeleorderSingleOrderLine_Response()
{
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText!="")
	{var splitResult=xmlhttp.responseText;
	 var splitResult=splitResult.split("##");
	 
	 //alert (xmlhttp.responseText);
	 
	 if (splitResult[1]=="Sent")
	 {
	 document.getElementById("teleorderbutton"+splitResult[0]).style.display='none';         // Disable link to send teleorder as it is already sent
 	 document.getElementById("teleorderstatement"+splitResult[0]).innerHTML=splitResult[1];  // Update the status
 	 document.getElementById("teleorderstatement"+splitResult[0]).title=splitResult[2];      // Update the title attribute with the file reference
	 } else {
 	 document.getElementById("teleorderstatement"+splitResult[0]).innerHTML="<br />"+splitResult[1];  // Update the status but new line so it is under the button
 	 document.getElementById("teleorderstatement"+splitResult[0]).title=splitResult[2];               // Update the title attribute with the reason for the error
	 }
     return;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side script to send a single order line
// teleorder
//
// ForOrderLineID : The order line ID to send
// ------------------------------------------------------------------------
function TeleorderSingleOrderLine(ForOrderLineID)
{
  // Check for blank input
  if (ForOrderLineID.length!=0)
    {  
		// Create the request object
		xmlhttp=GetXmlHttpObject();

        // THIS IS WHERE THE ASP PAGE IS CALLED
		var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=TeleorderSingleOrderLine&OrderLineID="+ForOrderLineID+"&IsAjaxCall=yes&sid="+Math.random();  // Create the URL to the server sideASP file passing in the value and a cache killer
        xmlhttp.onreadystatechange=TeleorderSingleOrderLine_Response;  // Set up the JS function to be called once the server response is returned
		// ##### IMPORTANT : set to ASYNCHRONOUS (true) as we are not interested in the return value.
		xmlhttp.open("GET",url,true);                         // Set up the connection using GET method. Passing the URL and indicate it is asynchronous
		xmlhttp.send(null);                                   // Send request to the server.
   }
}


// ------------------------------------------------------------------------
// This function is called if the original .jpg journal image does not exist.
// It then tries to load the .gif version and if this does not exist the
// noimage.jpg image is displayed.
// ------------------------------------------------------------------------
function ReplaceJournalListingImage(source,ISSN)
{    
  var oImg=new Image; 
  oImg.onload=function(){source.src=oImg.src} 
  oImg.onerror=function(){source.src="/images/journals/NoImage.jpg"} 
  oImg.src="/images/journals/" + ISSN + ".gif";             
  return true;
}

// ------------------------------------------------------------------------
// This function is called by the onload event to make the delivery address
// section in checkout 1 invisible and the button to enable it visible.
// ------------------------------------------------------------------------
function HideDeliveryAddressSection()
{
  var differentaddress=document.getElementById('differentaddress');
  var AddDeliveryAddress=document.getElementById('AddDeliveryAddress');

  if (differentaddress!==null) {
      differentaddress.style.display="none"
  }

  if (AddDeliveryAddress!==null) {
      AddDeliveryAddress.style.display=""
  }

}
// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested authors.
// ------------------------------------------------------------------------
function showAuthors_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try another author");
     return;
	}
	else
	{
	 document.getElementById("AuthorHint"+currentAuthorInstance).style.display='';	
	 document.getElementById("AuthorHint"+currentAuthorInstance).innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested authors.
// ------------------------------------------------------------------------
function showAuthors(str,instance)
{
  currentAuthorInstance = instance;
  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("AuthorHint"+currentAuthorInstance).innerHTML="";
	 document.getElementById("AuthorHint"+currentAuthorInstance).style.display='none';
	 document.getElementById("AuthorSelected"+currentAuthorInstance).value=""
     return;
  }
 
  // Create the request object
  xmlhttp=GetXmlHttpObject();
	
  // THIS IS WHERE THE ASP PAGE IS CALLED
  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowAuthors&q="+str+"&instance="+instance+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
  xmlhttp.onreadystatechange=showAuthors_Response;  // Set up the JS function to be called once the server response is returned
  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
  xmlhttp.send(null);                                     // Send request to the server.
 
}


// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested subject codes.
// ------------------------------------------------------------------------
function showBICCodes_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try another author");
     return;
	}
	else
	{
	 document.getElementById("SubjectCodeHint"+currentSubjectCodeInstance).style.display='';	
	 document.getElementById("SubjectCodeHint"+currentSubjectCodeInstance).innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested subject codes.
// ------------------------------------------------------------------------
function showBICCodes(str,instance)
{
  currentSubjectCodeInstance = instance;
  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("SubjectCodeHint"+currentSubjectCodeInstance).innerHTML="";
	 document.getElementById("SubjectCodeHint"+currentSubjectCodeInstance).style.display='none';
	 document.getElementById("SubjectCodeSelected"+currentSubjectCodeInstance).value=""
     return;
  }
 
  // Create the request object
  xmlhttp=GetXmlHttpObject();
	
  // THIS IS WHERE THE ASP PAGE IS CALLED
  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowBICCodes&q="+str+"&instance="+instance+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
  xmlhttp.onreadystatechange=showBICCodes_Response;  // Set up the JS function to be called once the server response is returned
  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
  xmlhttp.send(null);                                     // Send request to the server.
 
}
// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested publishers.
// ------------------------------------------------------------------------
function showPublishers_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try another publisher");
     return;
	}
	else
	{
	 document.getElementById("PublisherHint").style.display='';	
	 document.getElementById("PublisherHint").innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested publishers.
// ------------------------------------------------------------------------
function showPublishers(str)
{  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("PublisherHint").innerHTML="";
	 document.getElementById("PublisherHint").style.display='none';
	 document.getElementById("PublisherSelected").value=""
     return;
  }
 
  // Create the request object
  xmlhttp=GetXmlHttpObject();
	
  // THIS IS WHERE THE ASP PAGE IS CALLED
  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowPublishers&q="+str+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
  xmlhttp.onreadystatechange=showPublishers_Response;  // Set up the JS function to be called once the server response is returned
  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
  xmlhttp.send(null);                                     // Send request to the server.
 
}
// ------------------------------------------------------------------------
// This JS function pops up an alert if the given Meeting code is already being
// used by another exhibitions. It checks the response from the server side function.
// ------------------------------------------------------------------------
function DoesISBN13Exist_Response()
{
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="exists")
	{
     alert ("ISBN13 already exists");
     return;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side script to check if the ISBN13
// already exists.
// ------------------------------------------------------------------------
function DoesISBN13Exist(ISBN13)
{
  // Check for blank input
  if (ISBN13.length!=0)
    {  
		// Create the request object
		xmlhttp=GetXmlHttpObject();

        // THIS IS WHERE THE ASP PAGE IS CALLED
		var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=DoesISBN13Exist&ISBN13="+ISBN13+"&sid="+Math.random();  // Create the URL to the server sideASP file passing in the value and a cache killer
        xmlhttp.onreadystatechange=DoesISBN13Exist_Response;  // Set up the JS function to be called once the server response is returned
		// ##### IMPORTANT : set to ASYNCHRONOUS (true) as we are not interested in the return value.
		xmlhttp.open("GET",url,true);                         // Set up the connection using GET method. Passing the URL and indicate it is asynchronous
		xmlhttp.send(null);                                   // Send request to the server.
   }
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested books based on their ISBN13.
// ------------------------------------------------------------------------
function showScrollerBooks_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try another book");
     return;
	}
	else
	{
	 document.getElementById("BookHint"+currentScrollerBookInstance).style.display='';	
	 document.getElementById("BookHint"+currentScrollerBookInstance).innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested books.
// ------------------------------------------------------------------------
function showScrollerBooks(str,instance)
{
  currentScrollerBookInstance = instance;
  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("BookHint"+currentScrollerBookInstance).innerHTML="";
	 document.getElementById("BookHint"+currentScrollerBookInstance).style.display='none';
	 document.getElementById("BookSelected"+currentScrollerBookInstance).value=""
     return;
  }
 
  if (str.length>5) {
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowScrollerBooks&q="+str+"&instance="+instance+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showScrollerBooks_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of customers based on their last name.
// ------------------------------------------------------------------------
function showCustomersByLastName_Response()
{
if (xmlhttp.readyState==4)
  {
	//alert("response");
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try again");
     return;
	}
	else
	{
		
	 // alert(xmlhttp.responseText);
	 document.getElementById("CustomerLNHint").style.display='';	
	 document.getElementById("CustomerLNHint").innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of customer based on their last name.
// ------------------------------------------------------------------------
function showCustomersByLastName(str)
{  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("CustomerLNHint").innerHTML="";
	 document.getElementById("CustomerLNHint").style.display='none';
	 document.getElementById("CustomerLNSelected").value=""
     return;
  }
 
  if (str.length>0) {
	  
	  //alert(str);
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=showCustomersByLastName&q="+str+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showCustomersByLastName_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of customers based on their email.
// ------------------------------------------------------------------------
function showCustomersByEmail_Response()
{
if (xmlhttp.readyState==4)
  {
	//alert("response");
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try again");
     return;
	}
	else
	{
		
	 // alert(xmlhttp.responseText);
	 document.getElementById("CustomerEmailHint").style.display='';	
	 document.getElementById("CustomerEmailHint").innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of customer based on their email.
// ------------------------------------------------------------------------
function showCustomersByEmail(str)
{  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("CustomerEmailHint").innerHTML="";
	 document.getElementById("CustomerEmailHint").style.display='none';
	 document.getElementById("CustomerEmailSelected").value=""
     return;
  }
 
  if (str.length>0) {
	  
	  //alert(str);
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=showCustomersByEmail&q="+str+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showCustomersByEmail_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of customers based on their organisation.
// ------------------------------------------------------------------------
function showCustomersByOrganisation_Response()
{
if (xmlhttp.readyState==4)
  {
	//alert("response");
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try again");
     return;
	}
	else
	{
		
	 // alert(xmlhttp.responseText);
	 document.getElementById("CustomerOrganisationHint").style.display='';	
	 document.getElementById("CustomerOrganisationHint").innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of customer based on their organisation.
// ------------------------------------------------------------------------
function showCustomersByOrganisation(str)
{  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("CustomerOrganisationHint").innerHTML="";
	 document.getElementById("CustomerOrganisationHint").style.display='none';
	 document.getElementById("CustomerOrganisationSelected").value=""
     return;
  }
 
  if (str.length>0) {
	  
	  //alert(str);
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=showCustomersByOrganisation&q="+str+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showCustomersByOrganisation_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the full
// customer record
// ------------------------------------------------------------------------
function PopulateCustomerRecord_Response()
{
if (xmlhttp.readyState==4)
  {

    if (xmlhttp.responseText !== "")
	{
     //alert (xmlhttp.responseText);
	 //document.getElementById("Email").value=xmlhttp.responseText;
	 var SplitCustomerData = xmlhttp.responseText;
	 var mySplitResult = SplitCustomerData.split("##");

     document.getElementById("TheTitle").value = mySplitResult[0];
     document.getElementById("FirstName").value = mySplitResult[1];
     document.getElementById("LastName").value = mySplitResult[2];
     document.getElementById("LastNameLookup").value = mySplitResult[2];
	 
     document.getElementById("Email").value = mySplitResult[3];
     document.getElementById("EmailLookup").value = mySplitResult[3];
     document.getElementById("Telephone").value = mySplitResult[4];
	 
     document.getElementById("Organisation").value = mySplitResult[5];
     document.getElementById("OrganisationLookup").value = mySplitResult[5];
     document.getElementById("VATRegistration").value = mySplitResult[6];
     document.getElementById("CompanyNumber").value = mySplitResult[7];

     document.getElementById("Address1").value = mySplitResult[8];
     document.getElementById("Address2").value = mySplitResult[9];
     document.getElementById("Address3").value = mySplitResult[10];
     document.getElementById("TownCity").value = mySplitResult[11];
     document.getElementById("Region").value = mySplitResult[12];
     document.getElementById("PostCode").value = mySplitResult[13];
     document.getElementById("Country").value = mySplitResult[14];
	 
	 // Boplean returned from database is a string so needs to be converted to boolean
	 if (mySplitResult[15] == "True") {
        document.getElementById("mailinglist").checked = true
	 } else {
        document.getElementById("mailinglist").checked = false
	 }
		
     document.getElementById("AccountID").value = mySplitResult[16];

     return;
	}

  }
}

// ------------------------------------------------------------------------
// This JS function populates the customer details
// ------------------------------------------------------------------------
function PopulateCustomerRecord(customerID)
{ 
  //alert("PopulateCustomerRecord: " + customerID);
  
  if (customerID > -1) {
	  
	  //alert(str);
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=populateCustomerRecord&id="+customerID+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=PopulateCustomerRecord_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
  
}

// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested books based on their ISBN13.
// ------------------------------------------------------------------------
function showBooksByISBN13_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     alert ("Please try another book");
     return;
	}
	else
	{
	 document.getElementById("BookHint"+currentBooksByISBN13Instance).style.display='';	
	 document.getElementById("BookHint"+currentBooksByISBN13Instance).innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested books.
// ------------------------------------------------------------------------
function showBooksByISBN13(str,instance)
{
  currentBooksByISBN13Instance = instance;
  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("BookHint"+currentBooksByISBN13Instance).innerHTML="";
	 document.getElementById("BookHint"+currentBooksByISBN13Instance).style.display='none';
	 document.getElementById("BookSelected"+currentBooksByISBN13Instance).value=""
     return;
  }
 
  if (str.length>5) {
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowBooksByISBN13&q="+str+"&instance="+instance+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showBooksByISBN13_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}
// ------------------------------------------------------------------------
// This JS function reads the response from the server side function and
// carries out any necessary processing. In this case it returns the drop
// down list of suggested books based on their title.
// ------------------------------------------------------------------------
function showBooksByTitle_Response()
{
if (xmlhttp.readyState==4)
  {
    if (xmlhttp.responseText=="no suggestion")
	{
     // disable alert so can keep typing
     //alert ("Please try another book");
     return;
	}
	else
	{
	 document.getElementById("BookByTitleHint"+currentBooksByTitleInstance).style.display='';	
	 document.getElementById("BookByTitleHint"+currentBooksByTitleInstance).innerHTML=xmlhttp.responseText;
	}
  }
}

// ------------------------------------------------------------------------
// This JS function calls a server side routine to generate a drop down list
// of suggested books.
// ------------------------------------------------------------------------
function showBooksByTitle(str,instance)
{
  currentBooksByTitleInstance = instance;
  
  // Clear the output if nothing is entered in the text field.
  if (str.length==0)
  {
     document.getElementById("BookByTitleHint"+currentBooksByTitleInstance).innerHTML="";
	 document.getElementById("BookByTitleHint"+currentBooksByTitleInstance).style.display='none';
	 document.getElementById("BookSelected"+currentBooksByTitleInstance).value=""
     return;
  }
 
  if (str.length>4) {
	  
	  // Create the request object
	  xmlhttp=GetXmlHttpObject();
		
	  // THIS IS WHERE THE ASP PAGE IS CALLED
	  var url="/AdminCentre/2-Shell/AJAX-shell.asp?command=ShowBooksByTitle&q="+str+"&instance="+instance+"&sid="+Math.random(); // Create the URL to the server side ASP file passing in the value and a cache killer
	  xmlhttp.onreadystatechange=showBooksByTitle_Response;  // Set up the JS function to be called once the server response is returned
	  // ##### IMPORTANT : set to ASYNCHRONOUS (true)
	  xmlhttp.open("GET",url,true);                           // Set up the connection using GET method. Passing the URL and indicate it is SYNCHRONOUS
	  xmlhttp.send(null);                                     // Send request to the server.
  
  }
 
}

